Skip to content

Commit

Permalink
feature: #602 use digitalTwinType instead of semanticId
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-lcapellino committed Apr 8, 2024
1 parent 179c6b2 commit 22b613e
Show file tree
Hide file tree
Showing 2 changed files with 227 additions and 10 deletions.
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,8 @@ 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";

@Override
@Async(value = AssetsAsyncConfig.LOAD_SHELL_DESCRIPTORS_EXECUTOR)
Expand All @@ -76,11 +73,12 @@ public void synchronizeAssets() {
// 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.getName().equals(AS_BUILT_DIGITAL_TWIN_TYPE)).findFirst();
return first.isPresent();
}

private boolean isAsPlanned(AssetAdministrationShellDescriptor shellDescriptor) {
return !shellDescriptor.filterDescriptorsByAspectTypes(AS_PLANNED_ASPECT_TYPES).isEmpty();
return !isAsBuilt(shellDescriptor);
}
}

Loading

0 comments on commit 22b613e

Please sign in to comment.