Skip to content

Commit

Permalink
feat(irs-api):[#357] Add capability to add SAMM models locally
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-jhartmann committed Apr 9, 2024
1 parent 3ca8844 commit d1fe5a1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ public List<AspectModel> 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;
Expand Down Expand Up @@ -182,11 +183,12 @@ private String getDecodedString(final String urnBase64) {

private Optional<AspectModel> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AspectModel> allAspectModels = testee.getAllAspectModels();

// Assert
assertThat(allAspectModels).hasSize(1).contains(serialPartTypization);
assertThat(allAspectModels).hasSize(2).contains(serialPartTypization).contains(singleLevelBomAsBuilt);
}

@Test
Expand Down

0 comments on commit d1fe5a1

Please sign in to comment.