Skip to content

Commit

Permalink
Merge pull request #112 from catenax-ng/CX_PI12_S5_02
Browse files Browse the repository at this point in the history
[feat|sde-backend] : Update edc asset api refactor for supported submodels.
  • Loading branch information
almadigabor authored Apr 8, 2024
2 parents fbda323 + 9963780 commit bc5706d
Show file tree
Hide file tree
Showing 18 changed files with 178 additions and 240 deletions.
File renamed without changes.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Added controller interface api's for Policy management.
- External EDC service interface api updated.
- Updated supported sub-model implementation classes.
- Dependency workflow added.
- EDC asset update refactored in supported submodels.
- Support for pcf v6.0.0 submodel.

## [2.3.6] - 2024-03-06
### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@
import org.eclipse.tractusx.sde.common.constants.CommonConstants;
import org.eclipse.tractusx.sde.common.entities.PolicyModel;
import org.eclipse.tractusx.sde.common.exception.CsvHandlerUseCaseException;
import org.eclipse.tractusx.sde.common.exception.ServiceException;
import org.eclipse.tractusx.sde.common.exception.NoDataFoundException;
import org.eclipse.tractusx.sde.common.submodel.executor.Step;
import org.eclipse.tractusx.sde.edc.entities.request.asset.AssetEntryRequest;
import org.eclipse.tractusx.sde.edc.entities.request.asset.AssetEntryRequestFactory;
import org.eclipse.tractusx.sde.edc.facilitator.CreateEDCAssetFacilator;
import org.eclipse.tractusx.sde.edc.facilitator.DeleteEDCFacilitator;
import org.eclipse.tractusx.sde.edc.gateways.external.EDCGateway;
import org.eclipse.tractusx.sde.submodels.apr.entity.AspectRelationshipEntity;
import org.eclipse.tractusx.sde.submodels.apr.model.AspectRelationship;
Expand All @@ -51,6 +52,7 @@ public class EDCAspectRelationshipHandlerUseCase extends Step {
private final EDCGateway edcGateway;
private final CreateEDCAssetFacilator createEDCAssetFacilator;
private final AspectRelationshipService aspectRelationshipService;
private final DeleteEDCFacilitator deleteEDCFacilitator;

@SneakyThrows
public AspectRelationship run(String submodel, AspectRelationship input, String processId, PolicyModel policy) {
Expand All @@ -61,36 +63,46 @@ public AspectRelationship run(String submodel, AspectRelationship input, String

AssetEntryRequest assetEntryRequest = assetFactory.getAssetRequest(submodel,
getSubmodelShortDescriptionOfModel(), shellId, subModelId, input.getParentUuid());

Map<String, String> eDCAsset = null;

if (!edcGateway.assetExistsLookup(assetEntryRequest.getId())) {

if (CommonConstants.UPDATED_Y.equals(input.getUpdated())
&& input.getOldSubmodelIdforUpdateCase() != null) {
deleteIfAnyReferenceExist(input.getOldSubmodelIdforUpdateCase());
deleteIfAnyReferenceExist(input, input.getOldSubmodelIdforUpdateCase());
}

edcProcessingforAspectRelationship(assetEntryRequest, input, policy);

eDCAsset = createEDCAssetFacilator.createEDCAsset(assetEntryRequest, policy);
} else {

deleteEDCFirstForUpdate(submodel, input, processId);
edcProcessingforAspectRelationship(assetEntryRequest, input, policy);
eDCAsset = createEDCAssetFacilator.updateEDCAsset(assetEntryRequest, policy);
input.setUpdated(CommonConstants.UPDATED_Y);
}

// EDC transaction information for DB
input.setAssetId(eDCAsset.get("assetId"));
input.setAccessPolicyId(eDCAsset.get("accessPolicyId"));
input.setUsagePolicyId(eDCAsset.get("usagePolicyId"));
input.setContractDefinationId(eDCAsset.get("contractDefinitionId"));

return input;
} catch (Exception e) {
throw new CsvHandlerUseCaseException(input.getRowNumber(), "EDC: " + e.getMessage());
}
}

private void deleteIfAnyReferenceExist(String oldSubModelId) {
private void deleteIfAnyReferenceExist(AspectRelationship input, String oldSubModelId) {
try {
AspectRelationshipEntity aspectRelationshipEntity = aspectRelationshipService
.readEntityBySubModelId(oldSubModelId);
aspectRelationshipService.deleteEDCAsset(aspectRelationshipEntity);
log.info(
"Deleted existing EDC asset in update case reference,so EDC end will be single asset for each submodel: "
+ oldSubModelId);
} catch (NoDataFoundException e) {
log.warn(
"In deleteIfAnyReferenceExist The EDC assetInfo not found in local database for delete, looking EDC connector and going to delete asset");
deleteEDCFacilitator.findEDCOfferInformation(input.getShellId(), input.getSubModelId());
} catch (Exception e) {
log.warn(
"Trying to delete existing EDC asset in update case reference,so EDC end will be single asset for each submodel: "
Expand All @@ -99,28 +111,4 @@ private void deleteIfAnyReferenceExist(String oldSubModelId) {

}

@SneakyThrows
private void deleteEDCFirstForUpdate(String submodel, AspectRelationship input, String processId) {
try {
AspectRelationshipEntity aspectRelationshipEntity = aspectRelationshipService
.readEntity(input.getChildUuid());
aspectRelationshipService.deleteEDCAsset(aspectRelationshipEntity);
} catch (Exception e) {
if (!e.getMessage().contains("404 Not Found")) {
throw new ServiceException("Exception in EDC delete request process: " + e.getMessage());
}
}
}

@SneakyThrows
private void edcProcessingforAspectRelationship(AssetEntryRequest assetEntryRequest, AspectRelationship input, PolicyModel policy) {

Map<String, String> createEDCAsset = createEDCAssetFacilator.createEDCAsset(assetEntryRequest, policy);

// EDC transaction information for DB
input.setAssetId(assetEntryRequest.getId());
input.setAccessPolicyId(createEDCAsset.get("accessPolicyId"));
input.setUsagePolicyId(createEDCAsset.get("usagePolicyId"));
input.setContractDefinationId(createEDCAsset.get("contractDefinitionId"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
import org.eclipse.tractusx.sde.common.constants.CommonConstants;
import org.eclipse.tractusx.sde.common.entities.PolicyModel;
import org.eclipse.tractusx.sde.common.exception.CsvHandlerUseCaseException;
import org.eclipse.tractusx.sde.common.exception.NoDataFoundException;
import org.eclipse.tractusx.sde.common.exception.ServiceException;
import org.eclipse.tractusx.sde.common.submodel.executor.Step;
import org.eclipse.tractusx.sde.edc.entities.request.asset.AssetEntryRequest;
import org.eclipse.tractusx.sde.edc.entities.request.asset.AssetEntryRequestFactory;
import org.eclipse.tractusx.sde.edc.facilitator.CreateEDCAssetFacilator;
import org.eclipse.tractusx.sde.edc.facilitator.DeleteEDCFacilitator;
import org.eclipse.tractusx.sde.edc.gateways.external.EDCGateway;
import org.eclipse.tractusx.sde.submodels.batch.entity.BatchEntity;
import org.eclipse.tractusx.sde.submodels.batch.model.Batch;
Expand All @@ -38,7 +40,9 @@

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

@Slf4j
@Service
@RequiredArgsConstructor
public class EDCBatchHandlerUseCase extends Step {
Expand All @@ -47,6 +51,7 @@ public class EDCBatchHandlerUseCase extends Step {
private final EDCGateway edcGateway;
private final CreateEDCAssetFacilator createEDCAssetFacilator;
private final BatchService batchDeleteService;
private final DeleteEDCFacilitator deleteEDCFacilitator;

@SneakyThrows
public Batch run(String submodel, Batch input, String processId, PolicyModel policy) {
Expand All @@ -57,15 +62,22 @@ public Batch run(String submodel, Batch input, String processId, PolicyModel pol

AssetEntryRequest assetEntryRequest = assetFactory.getAssetRequest(submodel,
getSubmodelShortDescriptionOfModel(), shellId, subModelId, input.getUuid());
if (!edcGateway.assetExistsLookup(assetEntryRequest.getId())) {
edcProcessingforBatch(assetEntryRequest, input, policy);

Map<String, String> eDCAsset = null;

if (!edcGateway.assetExistsLookup(assetEntryRequest.getId())) {
eDCAsset = createEDCAssetFacilator.createEDCAsset(assetEntryRequest, policy);
} else {
deleteEDCFirstForUpdate(submodel, input, processId);
edcProcessingforBatch(assetEntryRequest, input, policy);
eDCAsset = createEDCAssetFacilator.updateEDCAsset(assetEntryRequest, policy);
input.setUpdated(CommonConstants.UPDATED_Y);
}

// EDC transaction information for DB
input.setAssetId(eDCAsset.get("assetId"));
input.setAccessPolicyId(eDCAsset.get("accessPolicyId"));
input.setUsagePolicyId(eDCAsset.get("usagePolicyId"));
input.setContractDefinationId(eDCAsset.get("contractDefinitionId"));

return input;
} catch (Exception e) {
throw new CsvHandlerUseCaseException(input.getRowNumber(), "EDC: " + e.getMessage());
Expand All @@ -77,6 +89,10 @@ private void deleteEDCFirstForUpdate(String submodel, Batch input, String proces
try {
BatchEntity batchEntity = batchDeleteService.readEntity(input.getUuid());
batchDeleteService.deleteEDCAsset(batchEntity);
} catch (NoDataFoundException e) {
log.warn(
"The EDC assetInfo not found in local database for delete, looking EDC connector and going to delete asset");
deleteEDCFacilitator.findEDCOfferInformation(input.getShellId(), input.getSubModelId());
} catch (Exception e) {
if (!e.getMessage().contains("404 Not Found")) {
throw new ServiceException("Unable to delete EDC offer for update: " + e.getMessage());
Expand All @@ -95,4 +111,4 @@ private void edcProcessingforBatch(AssetEntryRequest assetEntryRequest, Batch in
input.setUsagePolicyId(createEDCAsset.get("usagePolicyId"));
input.setContractDefinationId(createEDCAsset.get("contractDefinitionId"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@
import org.eclipse.tractusx.sde.common.constants.CommonConstants;
import org.eclipse.tractusx.sde.common.entities.PolicyModel;
import org.eclipse.tractusx.sde.common.exception.CsvHandlerUseCaseException;
import org.eclipse.tractusx.sde.common.exception.ServiceException;
import org.eclipse.tractusx.sde.common.submodel.executor.Step;
import org.eclipse.tractusx.sde.edc.entities.request.asset.AssetEntryRequest;
import org.eclipse.tractusx.sde.edc.entities.request.asset.AssetEntryRequestFactory;
import org.eclipse.tractusx.sde.edc.facilitator.CreateEDCAssetFacilator;
import org.eclipse.tractusx.sde.edc.gateways.external.EDCGateway;
import org.eclipse.tractusx.sde.submodels.pap.entity.PartAsPlannedEntity;
import org.eclipse.tractusx.sde.submodels.pap.model.PartAsPlanned;
import org.eclipse.tractusx.sde.submodels.pap.services.PartAsPlannedService;
import org.springframework.stereotype.Service;

import lombok.RequiredArgsConstructor;
Expand All @@ -45,7 +42,6 @@ public class EDCPartAsPlannedHandlerStep extends Step {
private final AssetEntryRequestFactory assetFactory;
private final EDCGateway edcGateway;
private final CreateEDCAssetFacilator createEDCAssetFacilator;
private final PartAsPlannedService partAsPlannedService;

@SneakyThrows
public PartAsPlanned run(String submodel, PartAsPlanned input, String processId, PolicyModel policy) {
Expand All @@ -56,45 +52,26 @@ public PartAsPlanned run(String submodel, PartAsPlanned input, String processId,

AssetEntryRequest assetEntryRequest = assetFactory.getAssetRequest(submodel,
getSubmodelShortDescriptionOfModel(), shellId, subModelId, input.getUuid());

Map<String, String> eDCAsset = null;

if (!edcGateway.assetExistsLookup(assetEntryRequest.getId())) {
edcProcessingforPartAsPlanned(assetEntryRequest, input, policy);
eDCAsset = createEDCAssetFacilator.createEDCAsset(assetEntryRequest, policy);
} else {

deleteEDCFirstForUpdate(submodel, input, processId);
edcProcessingforPartAsPlanned(assetEntryRequest, input, policy);
eDCAsset = createEDCAssetFacilator.updateEDCAsset(assetEntryRequest, policy);
input.setUpdated(CommonConstants.UPDATED_Y);
}

return input;
} catch (Exception e) {
throw new CsvHandlerUseCaseException(input.getRowNumber(), "EDC: " + e.getMessage());
}
}
// EDC transaction information for DB
input.setAssetId(eDCAsset.get("assetId"));
input.setAccessPolicyId(eDCAsset.get("accessPolicyId"));
input.setUsagePolicyId(eDCAsset.get("usagePolicyId"));
input.setContractDefinationId(eDCAsset.get("contractDefinitionId"));

@SneakyThrows
private void deleteEDCFirstForUpdate(String submodel, PartAsPlanned input, String processId) {
try {
PartAsPlannedEntity partAsPlannedEntity = partAsPlannedService.readEntity(input.getUuid());
partAsPlannedService.deleteEDCAsset(partAsPlannedEntity);

return input;
} catch (Exception e) {
if (!e.getMessage().contains("404 Not Found")) {
throw new ServiceException("Unable to delete EDC offer for update: " + e.getMessage());
}
throw new CsvHandlerUseCaseException(input.getRowNumber(), "EDC: " + e.getMessage());
}
}

@SneakyThrows
private void edcProcessingforPartAsPlanned(AssetEntryRequest assetEntryRequest, PartAsPlanned input,
PolicyModel policy) {

Map<String, String> createEDCAsset = createEDCAssetFacilator.createEDCAsset(assetEntryRequest, policy);

// EDC transaction information for DB
input.setAssetId(assetEntryRequest.getId());
input.setAccessPolicyId(createEDCAsset.get("accessPolicyId"));
input.setUsagePolicyId(createEDCAsset.get("usagePolicyId"));
input.setContractDefinationId(createEDCAsset.get("contractDefinitionId"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@
import org.eclipse.tractusx.sde.common.constants.CommonConstants;
import org.eclipse.tractusx.sde.common.entities.PolicyModel;
import org.eclipse.tractusx.sde.common.exception.CsvHandlerUseCaseException;
import org.eclipse.tractusx.sde.common.exception.ServiceException;
import org.eclipse.tractusx.sde.common.submodel.executor.Step;
import org.eclipse.tractusx.sde.edc.entities.request.asset.AssetEntryRequest;
import org.eclipse.tractusx.sde.edc.entities.request.asset.AssetEntryRequestFactory;
import org.eclipse.tractusx.sde.edc.facilitator.CreateEDCAssetFacilator;
import org.eclipse.tractusx.sde.edc.gateways.external.EDCGateway;
import org.eclipse.tractusx.sde.submodels.psiap.entity.PartSiteInformationAsPlannedEntity;
import org.eclipse.tractusx.sde.submodels.psiap.model.PartSiteInformationAsPlanned;
import org.eclipse.tractusx.sde.submodels.psiap.services.PartSiteInformationAsPlannedService;
import org.springframework.stereotype.Service;

import lombok.RequiredArgsConstructor;
Expand All @@ -45,7 +42,6 @@ public class EDCPartSiteInformationAsPlannedHandlerStep extends Step {
private final AssetEntryRequestFactory assetFactory;
private final EDCGateway edcGateway;
private final CreateEDCAssetFacilator createEDCAssetFacilator;
private final PartSiteInformationAsPlannedService partSiteInformationAsPlannedService;

@SneakyThrows
public PartSiteInformationAsPlanned run(String submodel, PartSiteInformationAsPlanned input, String processId,
Expand All @@ -57,46 +53,25 @@ public PartSiteInformationAsPlanned run(String submodel, PartSiteInformationAsPl

AssetEntryRequest assetEntryRequest = assetFactory.getAssetRequest(submodel,
getSubmodelShortDescriptionOfModel(), shellId, subModelId, input.getUuid());

Map<String, String> eDCAsset = null;

if (!edcGateway.assetExistsLookup(assetEntryRequest.getId())) {
edcProcessingforPartAsPlanned(assetEntryRequest, input, policy);
eDCAsset = createEDCAssetFacilator.createEDCAsset(assetEntryRequest, policy);
} else {

deleteEDCFirstForUpdate(submodel, input, processId);
edcProcessingforPartAsPlanned(assetEntryRequest, input, policy);
eDCAsset = createEDCAssetFacilator.updateEDCAsset(assetEntryRequest, policy);
input.setUpdated(CommonConstants.UPDATED_Y);
}

// EDC transaction information for DB
input.setAssetId(eDCAsset.get("assetId"));
input.setAccessPolicyId(eDCAsset.get("accessPolicyId"));
input.setUsagePolicyId(eDCAsset.get("usagePolicyId"));
input.setContractDefinationId(eDCAsset.get("contractDefinitionId"));

return input;
} catch (Exception e) {
throw new CsvHandlerUseCaseException(input.getRowNumber(), "EDC: " + e.getMessage());
}
}

@SneakyThrows
private void deleteEDCFirstForUpdate(String submodel, PartSiteInformationAsPlanned input, String processId) {
try {
PartSiteInformationAsPlannedEntity partSiteInformationAsPlannedEntity = partSiteInformationAsPlannedService
.readEntity(input.getUuid());
partSiteInformationAsPlannedService.deleteEDCAsset(partSiteInformationAsPlannedEntity);

} catch (Exception e) {
if (!e.getMessage().contains("404 Not Found")) {
throw new ServiceException("Unable to delete EDC offer for update: " + e.getMessage());
}
}
}

@SneakyThrows
private void edcProcessingforPartAsPlanned(AssetEntryRequest assetEntryRequest, PartSiteInformationAsPlanned input,
PolicyModel policy) {

Map<String, String> createEDCAsset = createEDCAssetFacilator.createEDCAsset(assetEntryRequest, policy);

// EDC transaction information for DB
input.setAssetId(assetEntryRequest.getId());
input.setAccessPolicyId(createEDCAsset.get("accessPolicyId"));
input.setUsagePolicyId(createEDCAsset.get("usagePolicyId"));
input.setContractDefinationId(createEDCAsset.get("contractDefinitionId"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public class PcfEntity extends CommonPropEntity {
@Column(name = "extTFS_distributionStageDlucGhgEmissions")
private Double extTFSDistributionStageDlucGhgEmissions; // 1.0,
private Double distributionStagePcfIncludingBiogenic; // 0.0,
private Double distributionStageAircraftGhgEmissions; // 0,
private Double carbonContentBiogenic; // 0.0,
private String partialFullPcf;// Cradle-to-gate
private String productId;// urn:gtin:4712345060507
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ public JsonObject mapToResponse(PcfEntity entity) {

PcfSubmodelResponse build=PcfSubmodelResponse.builder()
.specVersion(entity.getSpecVersion())
.companyIds(List.of(CompanyIds.builder()
.companyId(entity.getCompanyId())
.build()))
.companyIds(List.of(entity.getCompanyId()))
.extWBCSDProductCodeCpc(entity.getExtWBCSDProductCodeCpc())
.created(entity.getCreated())
.companyName(entity.getCompanyName())
Expand All @@ -156,10 +154,7 @@ public JsonObject mapToResponse(PcfEntity entity) {
.productName(entity.getProductName())
.pcf(pcfResponse)
.partialFullPcf(entity.getPartialFullPcf())
.productIds(List.of(ProductIds.builder()
.productId(entity.getProductId())
.build()))

.productIds(List.of(entity.getProductId()))
.validityPeriodStart(entity.getValidityPeriodStart())
.comment(entity.getComment())
.id(entity.getId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public class Pcf {
@SerializedName("extTFS_distributionStageDlucGhgEmissions")
private Double extTFSDistributionStageDlucGhgEmissions; // 1.0,
private Double distributionStagePcfIncludingBiogenic; // 0.0,
private Double distributionStageAircraftGhgEmissions; // 0.0,
private Double carbonContentBiogenic; // 0.0,

}
Loading

0 comments on commit bc5706d

Please sign in to comment.