Skip to content

Commit

Permalink
Merge pull request #146 from catenax-ng/support_edc_0.4.1
Browse files Browse the repository at this point in the history
Support edc 0.4.1
  • Loading branch information
adityagajbhiye9 authored Jun 27, 2023
2 parents a697cf3 + 48977ff commit 5dd83cf
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 48 deletions.
1 change: 0 additions & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,3 @@ EXPOSE 8080

CMD ["java", "-jar", "./app.jar","--spring.config.location=file:/app/configuration.properties"]


Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ResponseEntity<Object> queryOnDataOffers(@RequestParam String providerUrl
if (offset == null) {
offset = 0;
}
return ok().body(consumerControlPanelService.queryOnDataOffers(providerUrl, limit, offset, null));
return ok().body(consumerControlPanelService.queryOnDataOffers(providerUrl, offset, limit, null));
}

@PostMapping(value = "/subscribe-data-offers")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

@FeignClient(value = "EDCFeignClientApi", url = "${edc.hostname}/${edc.managementpath:data/v2}", configuration = EDCDataProviderConfiguration.class)
@FeignClient(value = "EDCFeignClientApi", url = "${edc.hostname}${edc.managementpath:/data/v2}", configuration = EDCDataProviderConfiguration.class)
public interface EDCFeignClientApi {

@GetMapping(path = "/assets/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class AbstractEDCStepsHelper {

@Value("${edc.consumer.hostname}${edc.consumer.managementpath:/data/v2}")
protected String consumerHost;

@Value("${edc.consumer.hostname}")
protected String consumerHostWithoutDataPath;

@Value("${edc.consumer.apikeyheader}")
private String edcApiKeyHeader;
Expand All @@ -38,6 +41,9 @@ public class AbstractEDCStepsHelper {

@Value("${edc.hostname}${edc.managementpath:/data/v2}")
protected String providerHost;

@Value("${edc.hostname}")
protected String providerHostWithoutDataPath;

@Value("${edc.consumer.protocol.path:/api/v1/dsp}")
protected String protocolPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ public Map<String, Object> getAllContractOffers(String type, Integer limit, Inte

Map<String, Object> res = new HashMap<>();
if (UtilityFunctions.checkTypeOfConnector(type))
res.put("connector", providerHost);
res.put("connector", providerHostWithoutDataPath);
else
res.put("connector", consumerHost);
res.put("connector", consumerHostWithoutDataPath);

res.put("contracts", contractAgreementResponses);
return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,17 @@
import org.eclipse.tractusx.sde.edc.entities.request.contractdefinition.ContractDefinitionRequest;
import org.eclipse.tractusx.sde.edc.entities.request.policies.PolicyDefinitionRequest;
import org.eclipse.tractusx.sde.edc.exceptions.EDCGatewayException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;

import feign.FeignException;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

@Service
@RequiredArgsConstructor
@Slf4j
public class EDCGateway {

@Value(value = "${edc.hostname}")
private String edcHostname;

@Value(value = "${edc.managementpath:/data/v2}")
private String edcManagementPath;

@Value(value = "${edc.apiKeyHeader}")
private String apiKeyHeader;

@Value(value = "${edc.apiKey}")
private String apiKey;

private final EDCFeignClientApi edcFeignClientApi;

public boolean assetExistsLookup(String id) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.eclipse.tractusx.sde.edc.model.contractoffers;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -12,9 +11,6 @@
@Component
public class ContractOfferRequestFactory {

@Value("${edc.consumer.protocol.path:/api/v1/dsp}")
private String edcProviderProtocolPath;

@SneakyThrows
public ObjectNode getContractOfferRequest(String providerUrl, Integer limit, Integer offset,
String filterExpression) {
Expand All @@ -23,18 +19,21 @@ public ObjectNode getContractOfferRequest(String providerUrl, Integer limit, Int
filterExpression = String.format(", %s", filterExpression);
else
filterExpression = "";

String jsonString = String.format("""
{
"@context": {},
"protocol": "dataspace-protocol-http",
"providerUrl": "%s",
"querySpec": {
"offset": %s,
"limit": %s
%s
}
}""", providerUrl + edcProviderProtocolPath, offset, limit, filterExpression);

String formatSchema = """
{
"@context": {},
"protocol": "dataspace-protocol-http",
"providerUrl": "%s",
"querySpec": {
"offset": %s,
"limit": %s
%s
}
}
""";
String jsonString = String.format(formatSchema, providerUrl, offset, limit,
filterExpression);

return (ObjectNode) new ObjectMapper().readTree(jsonString);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ public List<QueryDataOfferModel> queryOnDataOffers(String providerUrl, Integer o

List<QueryDataOfferModel> queryOfferResponse = new ArrayList<>();

JsonNode contractOfferCatalog = contractOfferCatalogApiProxy.getContractOffersCatalog(
contractOfferRequestFactory.getContractOfferRequest(providerUrl, limit, offset, filterExpression));
JsonNode contractOfferCatalog = contractOfferCatalogApiProxy
.getContractOffersCatalog(contractOfferRequestFactory
.getContractOfferRequest(providerUrl + protocolPath, limit, offset, filterExpression));

JsonNode jOffer = contractOfferCatalog.get("dcat:dataset");
if (jOffer.isArray()) {
Expand All @@ -92,19 +93,21 @@ private QueryDataOfferModel buildContractOffer(String sproviderUrl, JsonNode con

JsonNode policy = offer.get("odrl:hasPolicy");

String edcstr = "edc:";

QueryDataOfferModel build = QueryDataOfferModel.builder()
.assetId(getFieldFromJsonNode(offer, EDCAssetConstant.ASSET_PROP_ID))
.assetId(getFieldFromJsonNode(offer, edcstr + EDCAssetConstant.ASSET_PROP_ID))
.connectorOfferUrl(sproviderUrl + File.separator + getFieldFromJsonNode(offer, "@id"))
.offerId(getFieldFromJsonNode(policy, "@id"))
.title(getFieldFromJsonNode(offer, EDCAssetConstant.ASSET_PROP_NAME))
.type(getFieldFromJsonNode(offer, EDCAssetConstant.ASSET_PROP_TYPE))
.description(getFieldFromJsonNode(offer, EDCAssetConstant.ASSET_PROP_DESCRIPTION))
.created(getFieldFromJsonNode(offer, EDCAssetConstant.ASSET_PROP_CREATED))
.modified(getFieldFromJsonNode(offer, EDCAssetConstant.ASSET_PROP_MODIFIED))
.publisher(getFieldFromJsonNode(offer, EDCAssetConstant.ASSET_PROP_PUBLISHER))
.version(getFieldFromJsonNode(offer, EDCAssetConstant.ASSET_PROP_VERSION))
.fileName(getFieldFromJsonNode(offer, EDCAssetConstant.ASSET_PROP_FILENAME))
.fileContentType(getFieldFromJsonNode(offer, EDCAssetConstant.ASSET_PROP_CONTENTTYPE))
.title(getFieldFromJsonNode(offer, edcstr + EDCAssetConstant.ASSET_PROP_NAME))
.type(getFieldFromJsonNode(offer, edcstr + EDCAssetConstant.ASSET_PROP_TYPE))
.description(getFieldFromJsonNode(offer, edcstr + EDCAssetConstant.ASSET_PROP_DESCRIPTION))
.created(getFieldFromJsonNode(offer, edcstr + EDCAssetConstant.ASSET_PROP_CREATED))
.modified(getFieldFromJsonNode(offer, edcstr + EDCAssetConstant.ASSET_PROP_MODIFIED))
.publisher(getFieldFromJsonNode(offer, edcstr + EDCAssetConstant.ASSET_PROP_PUBLISHER))
.version(getFieldFromJsonNode(offer, edcstr + EDCAssetConstant.ASSET_PROP_VERSION))
.fileName(getFieldFromJsonNode(offer, edcstr + EDCAssetConstant.ASSET_PROP_FILENAME))
.fileContentType(getFieldFromJsonNode(offer, edcstr + EDCAssetConstant.ASSET_PROP_CONTENTTYPE))
.connectorId(getFieldFromJsonNode(contractOfferCatalog, "edc:participantId")).build();

checkAndSetPolicyPermission(build, policy);
Expand Down

0 comments on commit 5dd83cf

Please sign in to comment.