From d1fe5a156015847b22765e94ea212402882fa0d8 Mon Sep 17 00:00:00 2001 From: Jaro Hartmann Date: Tue, 9 Apr 2024 13:03:19 +0200 Subject: [PATCH] feat(irs-api):[#357] Add capability to add SAMM models locally --- CHANGELOG.md | 2 ++ .../tractusx/irs/semanticshub/SemanticsHubClient.java | 8 +++++--- .../irs/semanticshub/SemanticsHubClientImplTest.java | 8 ++++++-- ...2FzX3BsYW5uZWQ6My4wLjAjU2luZ2xlTGV2ZWxCb21Bc1BsYW5uZWQ | 0 4 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 irs-api/src/test/resources/aspect-models/dXJuOnNhbW06aW8uY2F0ZW5heC5zaW5nbGVfbGV2ZWxfYm9tX2FzX3BsYW5uZWQ6My4wLjAjU2luZ2xlTGV2ZWxCb21Bc1BsYW5uZWQ diff --git a/CHANGELOG.md b/CHANGELOG.md index a472505553..867226cef4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ _**For better traceability add the corresponding GitHub issue number in each cha ## [UNRELEASED] ### Added +- SAMM models can now be added locally #488 +- Introduced new Cucumber Tests to cover Industry Core 2.0.0 compatibility #488 ### Changed diff --git a/irs-api/src/main/java/org/eclipse/tractusx/irs/semanticshub/SemanticsHubClient.java b/irs-api/src/main/java/org/eclipse/tractusx/irs/semanticshub/SemanticsHubClient.java index f376a6e7ac..88c71a2db5 100644 --- a/irs-api/src/main/java/org/eclipse/tractusx/irs/semanticshub/SemanticsHubClient.java +++ b/irs-api/src/main/java/org/eclipse/tractusx/irs/semanticshub/SemanticsHubClient.java @@ -109,7 +109,8 @@ public List getAllAspectModels() { @Profile({ "!local && !test" }) class SemanticsHubClientImpl implements SemanticsHubClient { - public static final String LOCAL_MODEL_TYPE = "BAMM"; + public static final String LOCAL_MODEL_TYPE_BAMM = "BAMM"; + public static final String LOCAL_MODEL_TYPE_SAMM = "SAMM"; public static final String LOCAL_MODEL_STATUS = "PROVIDED"; private static final String PLACEHOLDER_URN = "urn"; private final SemanticsHubConfiguration config; @@ -182,11 +183,12 @@ private String getDecodedString(final String urnBase64) { private Optional createAspectModel(final String urn) { log.debug("Extracting aspect information for urn: '{}'", urn); - final Matcher matcher = Pattern.compile("^urn:bamm:.*:(\\d\\.\\d\\.\\d)#(\\w+)$").matcher(urn); + final Matcher matcher = Pattern.compile("^urn:[sb]amm:.*:(\\d\\.\\d\\.\\d)#(\\w+)$").matcher(urn); if (matcher.find()) { final String version = matcher.group(1); final String name = matcher.group(2); - return Optional.of(new AspectModel(urn, version, name, LOCAL_MODEL_TYPE, LOCAL_MODEL_STATUS)); + final String localModelType = urn.contains("samm") ? LOCAL_MODEL_TYPE_SAMM : LOCAL_MODEL_TYPE_BAMM; + return Optional.of(new AspectModel(urn, version, name, localModelType, LOCAL_MODEL_STATUS)); } log.warn("Could not extract aspect information from urn: '{}'", urn); return Optional.empty(); diff --git a/irs-api/src/test/java/org/eclipse/tractusx/irs/semanticshub/SemanticsHubClientImplTest.java b/irs-api/src/test/java/org/eclipse/tractusx/irs/semanticshub/SemanticsHubClientImplTest.java index a1ef007142..3f570584f5 100644 --- a/irs-api/src/test/java/org/eclipse/tractusx/irs/semanticshub/SemanticsHubClientImplTest.java +++ b/irs-api/src/test/java/org/eclipse/tractusx/irs/semanticshub/SemanticsHubClientImplTest.java @@ -163,14 +163,18 @@ void shouldGetAllModelsFromFilesystemOnly() throws SchemaNotFoundException { final var testee = new SemanticsHubClientImpl(restTemplate, config("", new File(path).getPath())); final AspectModel serialPartTypization = new AspectModel( "urn:bamm:io.catenax.serial_part_typization:1.0.0#SerialPartTypization", "1.0.0", - "SerialPartTypization", SemanticsHubClientImpl.LOCAL_MODEL_TYPE, + "SerialPartTypization", SemanticsHubClientImpl.LOCAL_MODEL_TYPE_BAMM, + SemanticsHubClientImpl.LOCAL_MODEL_STATUS); + final AspectModel singleLevelBomAsBuilt = new AspectModel( + "urn:samm:io.catenax.single_level_bom_as_planned:3.0.0#SingleLevelBomAsPlanned", "3.0.0", + "SingleLevelBomAsPlanned", SemanticsHubClientImpl.LOCAL_MODEL_TYPE_SAMM, SemanticsHubClientImpl.LOCAL_MODEL_STATUS); // Act final List allAspectModels = testee.getAllAspectModels(); // Assert - assertThat(allAspectModels).hasSize(1).contains(serialPartTypization); + assertThat(allAspectModels).hasSize(2).contains(serialPartTypization).contains(singleLevelBomAsBuilt); } @Test diff --git a/irs-api/src/test/resources/aspect-models/dXJuOnNhbW06aW8uY2F0ZW5heC5zaW5nbGVfbGV2ZWxfYm9tX2FzX3BsYW5uZWQ6My4wLjAjU2luZ2xlTGV2ZWxCb21Bc1BsYW5uZWQ b/irs-api/src/test/resources/aspect-models/dXJuOnNhbW06aW8uY2F0ZW5heC5zaW5nbGVfbGV2ZWxfYm9tX2FzX3BsYW5uZWQ6My4wLjAjU2luZ2xlTGV2ZWxCb21Bc1BsYW5uZWQ new file mode 100644 index 0000000000..e69de29bb2