Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: #602 use digitalTwinType instead of semanticId #1151

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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