forked from Fraunhofer-AISEC/ids-clearing-house-service
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from ids-basecamp/feat/edc-create-process
Feat/edc create process
- Loading branch information
Showing
20 changed files
with
604 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...dc/core/src/main/java/de/truzzt/clearinghouse/edc/app/delegate/CreateProcessDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (c) 2023 truzzt GmbH | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* truzzt GmbH - Initial implementation | ||
* | ||
*/ | ||
package de.truzzt.clearinghouse.edc.app.delegate; | ||
|
||
import de.truzzt.clearinghouse.edc.dto.*; | ||
import de.truzzt.clearinghouse.edc.types.TypeManagerUtil; | ||
import de.truzzt.clearinghouse.edc.types.clearinghouse.Context; | ||
import de.truzzt.clearinghouse.edc.types.clearinghouse.Header; | ||
import de.truzzt.clearinghouse.edc.types.clearinghouse.SecurityToken; | ||
import de.truzzt.clearinghouse.edc.types.clearinghouse.TokenFormat; | ||
import okhttp3.ResponseBody; | ||
|
||
public class CreateProcessDelegate implements AppSenderDelegate<CreateProcessResponse> { | ||
|
||
private final TypeManagerUtil typeManagerUtil; | ||
|
||
public CreateProcessDelegate(TypeManagerUtil typeManagerUtil) { | ||
this.typeManagerUtil = typeManagerUtil; | ||
} | ||
|
||
public String buildRequestUrl(String baseUrl, HandlerRequest handlerRequest) { | ||
return baseUrl + "/process/" + handlerRequest.getPid(); | ||
} | ||
|
||
public CreateProcessRequest buildRequestBody(HandlerRequest handlerRequest) { | ||
var header = handlerRequest.getHeader(); | ||
|
||
var multipartContext = header.getContext(); | ||
var context = new Context(multipartContext.getIds(), multipartContext.getIdsc()); | ||
|
||
var multipartSecurityToken = header.getSecurityToken(); | ||
var multipartTokenFormat = multipartSecurityToken.getTokenFormat(); | ||
var securityToken = SecurityToken.Builder.newInstance(). | ||
type(multipartSecurityToken.getType()). | ||
id(multipartSecurityToken.getId()). | ||
tokenFormat(new TokenFormat(multipartTokenFormat.getId())). | ||
tokenValue(multipartSecurityToken.getTokenValue()). | ||
build(); | ||
|
||
var requestHeader = Header.Builder.newInstance() | ||
.context(context) | ||
.id(header.getId()) | ||
.type(header.getType()) | ||
.securityToken(securityToken) | ||
.issuerConnector(header.getIssuerConnector()) | ||
.modelVersion(header.getModelVersion()) | ||
.issued(header.getIssued()) | ||
.senderAgent(header.getSenderAgent()) | ||
.build(); | ||
|
||
return new CreateProcessRequest(requestHeader, handlerRequest.getPayload()); | ||
} | ||
|
||
@Override | ||
public CreateProcessResponse parseResponseBody(ResponseBody responseBody) { | ||
return typeManagerUtil.parse(responseBody.byteStream(), CreateProcessResponse.class); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...ng-house-edc/core/src/main/java/de/truzzt/clearinghouse/edc/dto/CreateProcessRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) 2023 truzzt GmbH | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* truzzt GmbH - Initial implementation | ||
* | ||
*/ | ||
package de.truzzt.clearinghouse.edc.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import de.truzzt.clearinghouse.edc.types.clearinghouse.Header; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class CreateProcessRequest { | ||
|
||
@JsonProperty("header") | ||
@NotNull | ||
private final Header header; | ||
|
||
@JsonProperty("payload") | ||
@NotNull | ||
private final String payload; | ||
|
||
public CreateProcessRequest(@NotNull Header header, @NotNull String payload) { | ||
this.header = header; | ||
this.payload = payload; | ||
} | ||
} | ||
|
29 changes: 29 additions & 0 deletions
29
...g-house-edc/core/src/main/java/de/truzzt/clearinghouse/edc/dto/CreateProcessResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2023 truzzt GmbH | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* truzzt GmbH - Initial implementation | ||
* | ||
*/ | ||
package de.truzzt.clearinghouse.edc.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class CreateProcessResponse { | ||
|
||
@JsonProperty("pid") | ||
@NotNull | ||
private String pid; | ||
|
||
public String getPid() { | ||
return pid; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...use-edc/core/src/main/java/de/truzzt/clearinghouse/edc/handler/RequestMessageHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (c) 2023 truzzt GmbH | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* truzzt GmbH - Initial implementation | ||
* | ||
*/ | ||
package de.truzzt.clearinghouse.edc.handler; | ||
|
||
import de.truzzt.clearinghouse.edc.app.AppSender; | ||
import de.truzzt.clearinghouse.edc.app.delegate.CreateProcessDelegate; | ||
import de.truzzt.clearinghouse.edc.dto.AppSenderRequest; | ||
import de.truzzt.clearinghouse.edc.dto.HandlerRequest; | ||
import de.truzzt.clearinghouse.edc.dto.HandlerResponse; | ||
import de.truzzt.clearinghouse.edc.types.TypeManagerUtil; | ||
import org.eclipse.edc.protocol.ids.spi.types.IdsId; | ||
import org.eclipse.edc.spi.system.ServiceExtensionContext; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import static de.truzzt.clearinghouse.edc.util.ResponseUtil.createMultipartResponse; | ||
import static de.truzzt.clearinghouse.edc.util.ResponseUtil.messageProcessedNotification; | ||
import static de.truzzt.clearinghouse.edc.util.SettingsConstants.APP_BASE_URL_DEFAULT_VALUE; | ||
import static de.truzzt.clearinghouse.edc.util.SettingsConstants.APP_BASE_URL_SETTING; | ||
|
||
public class RequestMessageHandler implements Handler { | ||
|
||
private final IdsId connectorId; | ||
private final AppSender appSender; | ||
private final CreateProcessDelegate senderDelegate; | ||
|
||
private final ServiceExtensionContext context; | ||
|
||
public RequestMessageHandler(IdsId connectorId, | ||
TypeManagerUtil typeManagerUtil, | ||
AppSender appSender, | ||
ServiceExtensionContext context) { | ||
this.connectorId = connectorId; | ||
this.appSender = appSender; | ||
this.context = context; | ||
|
||
this.senderDelegate = new CreateProcessDelegate(typeManagerUtil); | ||
} | ||
|
||
@Override | ||
public boolean canHandle(@NotNull HandlerRequest handlerRequest) { | ||
return handlerRequest.getHeader().getType().equals("ids:RequestMessage"); | ||
} | ||
|
||
@Override | ||
public @NotNull HandlerResponse handleRequest(@NotNull HandlerRequest handlerRequest) { | ||
var baseUrl = context.getSetting(APP_BASE_URL_SETTING, APP_BASE_URL_DEFAULT_VALUE); | ||
var header = handlerRequest.getHeader(); | ||
|
||
var url = senderDelegate.buildRequestUrl(baseUrl, handlerRequest); | ||
var token = buildJWTToken(handlerRequest.getHeader().getSecurityToken(), context); | ||
var body = senderDelegate.buildRequestBody(handlerRequest); | ||
|
||
var request = AppSenderRequest.Builder.newInstance().url(url).token(token).body(body).build(); | ||
|
||
var response = appSender.send(request, senderDelegate); | ||
return createMultipartResponse(messageProcessedNotification(header, connectorId), response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.