Skip to content

Commit

Permalink
Merge pull request #1151 from catenax-ng/feature/602-use-digitalTwinT…
Browse files Browse the repository at this point in the history
…ype-instead-of-semantic-id

feature: #602 use digitalTwinType instead of semanticId
  • Loading branch information
ds-mwesener authored Apr 9, 2024
2 parents 2f59c36 + a9ee648 commit 3d6a238
Show file tree
Hide file tree
Showing 3 changed files with 2,681 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ _**For better traceability add the corresponding GitHub issue number in each cha
## Changed
- #823 migrate to irs-helm 6.18.0
- #636 migrate to digital-twin-registry version 0.4.9 from 0.3.22
- #602 use digitalTwinType instead of semanticId to determine asBuilt or asPlanned assets


### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import lombok.extern.slf4j.Slf4j;
import org.eclipse.tractusx.irs.component.Shell;
import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor;
import org.eclipse.tractusx.irs.component.assetadministrationshell.IdentifierKeyValuePair;
import org.eclipse.tractusx.traceability.assets.domain.asbuilt.service.AssetAsBuiltServiceImpl;
import org.eclipse.tractusx.traceability.assets.domain.asplanned.service.AssetAsPlannedServiceImpl;
import org.eclipse.tractusx.traceability.assets.domain.base.model.ImportState;
Expand All @@ -36,11 +37,7 @@
import org.springframework.stereotype.Component;

import java.util.List;

import static org.eclipse.tractusx.traceability.assets.domain.base.model.SemanticDataModel.BATCH;
import static org.eclipse.tractusx.traceability.assets.domain.base.model.SemanticDataModel.JUSTINSEQUENCE;
import static org.eclipse.tractusx.traceability.assets.domain.base.model.SemanticDataModel.PARTASPLANNED;
import static org.eclipse.tractusx.traceability.assets.domain.base.model.SemanticDataModel.SERIALPART;
import java.util.Optional;

@RequiredArgsConstructor
@Slf4j
Expand All @@ -52,8 +49,9 @@ public class DecentralRegistryServiceImpl implements DecentralRegistryService {
private final TraceabilityProperties traceabilityProperties;
private final DecentralRegistryRepository decentralRegistryRepository;

private static final List<String> AS_BUILT_ASPECT_TYPES = List.of(SERIALPART.getValue(), BATCH.getValue(), JUSTINSEQUENCE.getValue());
private static final List<String> AS_PLANNED_ASPECT_TYPES = List.of(PARTASPLANNED.getValue());
private static final String DIGITAL_TWIN_TYPE = "digitalTwinType";
private static final String AS_BUILT_DIGITAL_TWIN_TYPE = "PartInstance";
private static final String AS_PLANNED_DIGITAL_TWIN_TYPE = "PartType";

@Override
@Async(value = AssetsAsyncConfig.LOAD_SHELL_DESCRIPTORS_EXECUTOR)
Expand All @@ -68,19 +66,23 @@ public void synchronizeAssets() {
List<String> asBuiltAssetsToSync = asBuiltAssetIds.stream().filter(assetId -> !existingAsBuiltInSyncAndTransientStates.contains(assetId)).toList();
List<String> asPlannedAssetsToSync = asPlannedAssetIds.stream().filter(assetId -> !existingAsPlannedInSyncAndTransientStates.contains(assetId)).toList();

log.info("Try to sync {} assets asBuilt", asBuiltAssetsToSync.size());
asBuiltAssetsToSync.forEach(assetAsBuiltService::synchronizeAssetsAsync);
log.info("Try to sync {} assets asPlanned", asPlannedAssetsToSync.size());
asPlannedAssetsToSync.forEach(assetAsPlannedService::synchronizeAssetsAsync);
}


// TODO: consider creating support method on AssetAdministrationShellDescriptor.is(BomLifecycle lifecycle) that will be usable on our code
// IRS already have BomLifecycle in their domain so we can use it there also
private boolean isAsBuilt(AssetAdministrationShellDescriptor shellDescriptor) {
return !shellDescriptor.filterDescriptorsByAspectTypes(AS_BUILT_ASPECT_TYPES).isEmpty();
Optional<IdentifierKeyValuePair> first = shellDescriptor.getSpecificAssetIds().stream().filter(item -> item.getName().equals(DIGITAL_TWIN_TYPE) && item.getValue().equals(AS_BUILT_DIGITAL_TWIN_TYPE)).findFirst();
return first.isPresent();
}

private boolean isAsPlanned(AssetAdministrationShellDescriptor shellDescriptor) {
return !shellDescriptor.filterDescriptorsByAspectTypes(AS_PLANNED_ASPECT_TYPES).isEmpty();
Optional<IdentifierKeyValuePair> first = shellDescriptor.getSpecificAssetIds().stream().filter(item -> item.getName().equals(DIGITAL_TWIN_TYPE) && item.getValue().equals(AS_PLANNED_DIGITAL_TWIN_TYPE)).findFirst();
return first.isPresent();
}
}

Loading

0 comments on commit 3d6a238

Please sign in to comment.