diff --git a/CHANGELOG.md b/CHANGELOG.md index 214d428e6f..a95fb03149 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ _**For better traceability add the corresponding GitHub issue number in each cha - #884 Upgraded tractionBatteryCode from 1.0.0 to 2.0.0 - #786 Added alternative port (only accessible within same cluster) for application which is used for unsecured API endpoints. - #994 improved bpn edc configuration view uux +- #1082 fix update of parts when synchronizing with IRS ### Added - #832 added policymanagement list view, creator and editor diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asbuilt/repository/AssetAsBuiltRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asbuilt/repository/AssetAsBuiltRepositoryImpl.java index a7c1b89508..195a248774 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asbuilt/repository/AssetAsBuiltRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asbuilt/repository/AssetAsBuiltRepositoryImpl.java @@ -44,6 +44,7 @@ @RequiredArgsConstructor @Component +@Transactional public class AssetAsBuiltRepositoryImpl implements AssetAsBuiltRepository, AssetCallbackRepository { private final JpaAssetAsBuiltRepository jpaAssetAsBuiltRepository; @@ -52,7 +53,6 @@ public class AssetAsBuiltRepositoryImpl implements AssetAsBuiltRepository, Asset private EntityManager entityManager; @Override - @Transactional public AssetBase getAssetById(String assetId) { return jpaAssetAsBuiltRepository.findById(assetId) .map(AssetAsBuiltEntity::toDomain) @@ -60,7 +60,6 @@ public AssetBase getAssetById(String assetId) { } @Override - @Transactional public boolean existsById(String assetId) { return jpaAssetAsBuiltRepository.existsById(assetId); } @@ -85,7 +84,6 @@ public List getFieldValues(String fieldName, String startWith, Integer r } @Override - @Transactional public List getAssets() { return jpaAssetAsBuiltRepository.findAll().stream() .map(AssetAsBuiltEntity::toDomain) @@ -93,13 +91,11 @@ public List getAssets() { } @Override - @Transactional public AssetBase save(AssetBase asset) { return jpaAssetAsBuiltRepository.save(AssetAsBuiltEntity.from(asset)).toDomain(); } @Override - @Transactional public List saveAll(List assets) { return jpaAssetAsBuiltRepository.saveAll(AssetAsBuiltEntity.fromList(assets)).stream() .map(AssetAsBuiltEntity::toDomain) @@ -107,7 +103,6 @@ public List saveAll(List assets) { } @Override - @Transactional public List saveAllIfNotInIRSSyncAndUpdateImportStateAndNote(List assets) { if (Objects.isNull(assets)) { return List.of(); @@ -132,7 +127,6 @@ private boolean entityIsTransientOrNotExistent(AbstractMap.SimpleEntry findByImportStateIn(ImportState... importStates) { return jpaAssetAsBuiltRepository.findByImportStateIn(importStates).stream() @@ -149,7 +143,6 @@ public void updateImportStateAndNoteForAssets(ImportState importState, String im jpaAssetAsBuiltRepository.saveAll(assets); } - @Transactional @Override public List findAll() { return jpaAssetAsBuiltRepository.findAll().stream() @@ -162,7 +155,6 @@ public Optional findById(String assetId) { .map(AssetAsBuiltEntity::toDomain); } - @Transactional @Override public long countAssets() { return jpaAssetAsBuiltRepository.count(); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asplanned/repository/AssetAsPlannedRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asplanned/repository/AssetAsPlannedRepositoryImpl.java index 74c11bcb7a..a6d16091b7 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asplanned/repository/AssetAsPlannedRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asplanned/repository/AssetAsPlannedRepositoryImpl.java @@ -49,6 +49,7 @@ @RequiredArgsConstructor @Component +@Transactional public class AssetAsPlannedRepositoryImpl implements AssetAsPlannedRepository, AssetCallbackRepository { private final JpaAssetAsPlannedRepository jpaAssetAsPlannedRepository; @@ -57,14 +58,12 @@ public class AssetAsPlannedRepositoryImpl implements AssetAsPlannedRepository, A private EntityManager entityManager; @Override - @Transactional public AssetBase getAssetById(String assetId) { return jpaAssetAsPlannedRepository.findById(assetId).map(AssetAsPlannedEntity::toDomain) .orElseThrow(() -> new AssetNotFoundException("Asset with id %s was not found.".formatted(assetId))); } @Override - @Transactional public boolean existsById(String assetId) { return jpaAssetAsPlannedRepository.existsById(assetId); } @@ -81,7 +80,6 @@ public AssetBase getAssetByChildId(String childId) { .orElseThrow(() -> new AssetNotFoundException("Child Asset Not Found")); } - @Transactional @Override public List findAll() { return jpaAssetAsPlannedRepository.findAll().stream() @@ -97,25 +95,21 @@ public PageResult getAssets(Pageable pageable, SearchCriteria searchC } @Override - @Transactional public List getAssets() { return AssetAsPlannedEntity.toDomainList(jpaAssetAsPlannedRepository.findAll()); } @Override - @Transactional public AssetBase save(AssetBase asset) { return AssetAsPlannedEntity.toDomain(jpaAssetAsPlannedRepository.save(AssetAsPlannedEntity.from(asset))); } @Override - @Transactional public List saveAll(List assets) { return AssetAsPlannedEntity.toDomainList(jpaAssetAsPlannedRepository.saveAll(AssetAsPlannedEntity.fromList(assets))); } @Override - @Transactional public List saveAllIfNotInIRSSyncAndUpdateImportStateAndNote(List assets) { if (Objects.isNull(assets)) { return List.of(); @@ -150,7 +144,6 @@ public Optional findById(String assetId) { .map(AssetAsPlannedEntity::toDomain); } - @Transactional @Override public long countAssets() { return jpaAssetAsPlannedRepository.count(); @@ -166,7 +159,6 @@ public List getFieldValues(String fieldName, String startWith, Integer r return CriteriaUtility.getDistinctAssetFieldValues(fieldName, startWith, resultLimit, owner, inAssetIds, AssetAsPlannedEntity.class, entityManager); } - @Transactional @Override public List findByImportStateIn(ImportState... importStates) { return jpaAssetAsPlannedRepository.findByImportStateIn(importStates).stream() diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/JobRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/JobRepositoryImpl.java index 9d9dab73d8..4afbbcbfed 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/JobRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/JobRepositoryImpl.java @@ -108,22 +108,23 @@ public void handleJobFinishedCallback(String jobId, String state) { } void saveOrUpdateAssets(AssetCallbackRepository repository, AssetBase asset) { - Optional existingAssetOptional = repository.findById(asset.getId()); - if (existingAssetOptional.isPresent()) { - AssetBase existingAsset = existingAssetOptional.get(); - if (existingAsset.getOwner().equals(Owner.UNKNOWN)) { - existingAsset.setOwner(asset.getOwner()); - } - if (!asset.getParentRelations().isEmpty()) { - existingAsset.setParentRelations(asset.getParentRelations()); - } - existingAsset.setTombstone(asset.getTombstone() == null ? "" : asset.getTombstone()); - existingAsset.setImportState(ImportState.PERSISTENT); - existingAsset.setImportNote(ImportNote.PERSISTED); - repository.save(existingAsset); - } else { +// Optional existingAssetOptional = repository.findById(asset.getId()); +// if (existingAssetOptional.isPresent()) { +// AssetBase existingAsset = existingAssetOptional.get(); +// if (existingAsset.getOwner().equals(Owner.UNKNOWN)) { +// existingAsset.setOwner(asset.getOwner()); +// } +// if (!asset.getParentRelations().isEmpty()) { +// existingAsset.setParentRelations(asset.getParentRelations()); +// } +// existingAsset.setIdShort(asset.getIdShort()); +// existingAsset.setTombstone(asset.getTombstone() == null ? "" : asset.getTombstone()); +// existingAsset.setImportState(ImportState.PERSISTENT); +// existingAsset.setImportNote(ImportNote.PERSISTED); +// repository.save(existingAsset); +// } else { repository.save(asset); - } +// } } diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/assets/infrastructure/base/IrsCallbackControllerIT.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/assets/infrastructure/base/IrsCallbackControllerIT.java index c62e3e91de..d532610526 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/assets/infrastructure/base/IrsCallbackControllerIT.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/assets/infrastructure/base/IrsCallbackControllerIT.java @@ -151,6 +151,7 @@ void givenInvalidJobId_whenCallbackReceivedForAsPlanned_thenNothingSynchronized( @Test void givenAssetExist_whenCallbackReceived_thenUpdateIt() { // given + assetsSupport.defaultAssetsStored(); bpnSupport.providesBpdmLookup(); oAuth2ApiSupport.oauth2ApiReturnsTechnicalUserToken(); irsApiSupport.irsApiReturnsJobDetails(); @@ -169,21 +170,14 @@ void givenAssetExist_whenCallbackReceived_thenUpdateIt() { .log().all() .statusCode(200); - given() - .contentType(ContentType.JSON) - .log().all() - .when() - .param("id", jobId) - .param("state", jobState) - .get("/api/irs/job/callback") - .then() - .log().all() - .statusCode(200); - // then assertThat(bpnSupportRepository.findAll()).hasSize(1); assetsSupport.assertAssetAsBuiltSize(16); assetsSupport.assertAssetAsPlannedSize(0); + String updatedIdShort = assetsSupport.findById("urn:uuid:d387fa8e-603c-42bd-98c3-4d87fef8d2bb").getIdShort(); + assertThat(updatedIdShort).isEqualTo("vehicle_hybrid_v2.asm"); + //urn:uuid:d387fa8e-603c-42bd-98c3-4d87fef8d2bb + //vehicle_hybrid_v2.asm } @Test diff --git a/tx-backend/src/test/resources/stubs/irs/get/jobs/id/response_200.json b/tx-backend/src/test/resources/stubs/irs/get/jobs/id/response_200.json index f17ceff94a..1b6defa38f 100644 --- a/tx-backend/src/test/resources/stubs/irs/get/jobs/id/response_200.json +++ b/tx-backend/src/test/resources/stubs/irs/get/jobs/id/response_200.json @@ -280,7 +280,7 @@ } ], "globalAssetId" : "urn:uuid:d387fa8e-603c-42bd-98c3-4d87fef8d2bb", - "idShort" : "vehicle_hybrid.asm", + "idShort" : "vehicle_hybrid_v2.asm", "identification" : "urn:uuid:d387fa8e-603c-42bd-98c3-4d87fef8d2bb", "specificAssetIds" : [ {