Skip to content

Commit

Permalink
chore: semantic id updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ReneSchroederLJ committed Apr 25, 2024
1 parent 976bde7 commit 38eba8c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -172,28 +168,28 @@ 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());
}
return false;
}
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;
}
}
Expand Down Expand Up @@ -294,19 +290,19 @@ 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());
}
return false;
}
return true;
} catch (Exception e) {
log.error("Failed to register {} Submodel", submodelName, e);
log.error("Failed to register {} Submodel", semanticId, e);
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 38eba8c

Please sign in to comment.