forked from Fraunhofer-AISEC/ids-clearing-house-service
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCreateProcessDelegate.java
69 lines (58 loc) · 2.65 KB
/
CreateProcessDelegate.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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);
}
}