diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/domain/model/SubmodelType.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/domain/model/SubmodelType.java index c5a08b18..ffef3e69 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/domain/model/SubmodelType.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/domain/model/SubmodelType.java @@ -23,8 +23,8 @@ public enum SubmodelType { DTR("none", "none"), ITEM_STOCK("urn:samm:io.catenax.item_stock:2.0.0#ItemStock", "$value"), - PRODUCTION("urn:samm:io.catenax.planned_production_output:2.0.0 ", "$value"), - DEMAND("urn:samm:io.catenax.short_term_material_demand:2.0.0 ", "$value"), + PRODUCTION("urn:samm:io.catenax.planned_production_output:2.0.0#PlannedProductionOutput", "$value"), + DEMAND("urn:samm:io.catenax.short_term_material_demand:1.0.0#ShortTermMaterialDemand", "$value"), DELIVERY("urn:samm:io.catenax.delivery_information:2.0.0#DeliveryInformation", "$value"), PART_TYPE_INFORMATION("urn:samm:io.catenax.part_type_information:1.0.0#PartTypeInformation", "$value"); diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/service/EdcAdapterService.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/service/EdcAdapterService.java index a152d53b..c3add604 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/service/EdcAdapterService.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/service/EdcAdapterService.java @@ -133,25 +133,21 @@ public boolean registerAssetsInitially() { log.info("Registration of DTR Asset successful {}", (assetRegistration = registerDtrAsset())); result &= assetRegistration; log.info("Registration of ItemStock 2.0.0 submodel successful {}", (assetRegistration = registerSubmodelAsset( - "ItemStock", variablesService.getItemStockSubmodelApiAssetId(), variablesService.getItemStockSubmodelEndpoint(), SubmodelType.ITEM_STOCK.URN_SEMANTIC_ID ))); log.info("Registration of Planned Production 2.0.0 submodel successful {}", (assetRegistration = registerSubmodelAsset( - "Planned Production", variablesService.getProductionSubmodelApiAssetId(), variablesService.getProductionSubmodelEndpoint(), SubmodelType.PRODUCTION.URN_SEMANTIC_ID ))); - log.info("Registration of Short Term Material Demand 2.0.0 submodel successful {}", (assetRegistration = registerSubmodelAsset( - "Short Term Material Demand", + log.info("Registration of Short Term Material Demand 1.0.0 submodel successful {}", (assetRegistration = registerSubmodelAsset( variablesService.getDemandSubmodelApiAssetId(), variablesService.getDemandSubmodelEndpoint(), SubmodelType.DEMAND.URN_SEMANTIC_ID ))); log.info("Registration of Delivery Information 2.0.0 submodel successful {}", (assetRegistration = registerSubmodelAsset( - "Delivery Information", variablesService.getDeliverySubmodelApiAssetId(), variablesService.getDeliverySubmodelEndpoint(), SubmodelType.DELIVERY.URN_SEMANTIC_ID @@ -172,20 +168,20 @@ public boolean registerAssetsInitially() { */ public boolean createPolicyAndContractDefForPartner(Partner partner) { boolean result = createPolicyDefinitionForPartner(partner); - result &= createSubmodelContractDefinitionForPartner("ItemStock", variablesService.getItemStockSubmodelApiAssetId(), partner); - result &= createSubmodelContractDefinitionForPartner("Planned Production", variablesService.getProductionSubmodelApiAssetId(), partner); - result &= createSubmodelContractDefinitionForPartner("Short Term Material Demand", variablesService.getDemandSubmodelApiAssetId(), partner); - result &= createSubmodelContractDefinitionForPartner("Delivery Information", variablesService.getDeliverySubmodelApiAssetId(), partner); + result &= createSubmodelContractDefinitionForPartner(SubmodelType.ITEM_STOCK.URN_SEMANTIC_ID, variablesService.getItemStockSubmodelApiAssetId(), partner); + result &= createSubmodelContractDefinitionForPartner(SubmodelType.PRODUCTION.URN_SEMANTIC_ID, variablesService.getProductionSubmodelApiAssetId(), partner); + result &= createSubmodelContractDefinitionForPartner(SubmodelType.DEMAND.URN_SEMANTIC_ID, variablesService.getDemandSubmodelApiAssetId(), partner); + result &= createSubmodelContractDefinitionForPartner(SubmodelType.DELIVERY.URN_SEMANTIC_ID, variablesService.getDeliverySubmodelApiAssetId(), partner); result &= createDtrContractDefinitionForPartner(partner); - return createSubmodelContractDefinitionForPartner("Part Type Information", variablesService.getPartTypeSubmodelApiAssetId(), partner) && result; + return createSubmodelContractDefinitionForPartner(SubmodelType.PART_TYPE_INFORMATION.URN_SEMANTIC_ID, variablesService.getPartTypeSubmodelApiAssetId(), partner) && result; } - private boolean createSubmodelContractDefinitionForPartner(String submodelName, String assetId, Partner partner) { + private boolean createSubmodelContractDefinitionForPartner(String semanticId, String assetId, Partner partner) { var body = edcRequestBodyBuilder.buildSubmodelContractDefinitionWithBpnRestrictedPolicy(assetId, partner); try (var response = sendPostRequest(body, List.of("v2", "contractdefinitions"))) { if (!response.isSuccessful()) { - log.warn("Contract definition registration failed for partner " + partner.getBpnl() + " and {} Submodel", submodelName); + log.warn("Contract definition registration failed for partner " + partner.getBpnl() + " and {} Submodel", assetId); if (response.body() != null) { log.warn("Response: \n" + response.body().string()); } @@ -193,7 +189,7 @@ private boolean createSubmodelContractDefinitionForPartner(String submodelName, } return true; } catch (Exception e) { - log.error("Contract definition registration failed for partner " + partner.getBpnl() + " and {} Submodel", submodelName); + log.error("Contract definition registration failed for partner " + partner.getBpnl() + " and {} Submodel", assetId); return false; } } @@ -294,11 +290,11 @@ private boolean registerPartTypeInfoSubmodelAsset() { } } - private boolean registerSubmodelAsset(String submodelName, String assetId, String endpoint, String semanticId) { + private boolean registerSubmodelAsset(String assetId, String endpoint, String semanticId) { var body = edcRequestBodyBuilder.buildSubmodelRegistrationBody(assetId, endpoint, semanticId); try (var response = sendPostRequest(body, List.of("v3", "assets"))) { if (!response.isSuccessful()) { - log.warn("{} Submodel Asset registration failed", submodelName); + log.warn("{} Submodel Asset registration failed", semanticId); if (response.body() != null) { log.warn("Response: \n" + response.body().string()); } @@ -306,7 +302,7 @@ private boolean registerSubmodelAsset(String submodelName, String assetId, Strin } return true; } catch (Exception e) { - log.error("Failed to register {} Submodel", submodelName, e); + log.error("Failed to register {} Submodel", semanticId, e); return false; } } diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/util/EdcRequestBodyBuilder.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/util/EdcRequestBodyBuilder.java index 24341500..962c15cb 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/util/EdcRequestBodyBuilder.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/util/EdcRequestBodyBuilder.java @@ -326,9 +326,9 @@ public JsonNode buildSubmodelRegistrationBody(String assetId, String endpoint, S propertiesObject.set("dct:type", dctTypeObject); dctTypeObject.put("@id", "cx-taxo:Submodel"); propertiesObject.put("cx-common:version", "3.0"); - var semanticIdPart = MAPPER.createObjectNode(); - propertiesObject.set("aas-semantics:semanticId", semanticIdPart); - semanticIdPart.put("@id", semanticId); + var semanticIdObject = MAPPER.createObjectNode(); + propertiesObject.set("aas-semantics:semanticId", semanticIdObject); + semanticIdObject.put("@id", semanticId); body.set("privateProperties", MAPPER.createObjectNode()); var dataAddress = MAPPER.createObjectNode();