Skip to content

Commit

Permalink
Merge pull request #1140 from ds-lcapellino/bug/1082-parts-not-update…
Browse files Browse the repository at this point in the history
…d-after-sync

bug: #1082 fix parts synchronization
  • Loading branch information
ds-mwesener authored Jul 3, 2024
2 parents 5c403de + d4c210e commit 21f78e4
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 45 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

@RequiredArgsConstructor
@Component
@Transactional
public class AssetAsBuiltRepositoryImpl implements AssetAsBuiltRepository, AssetCallbackRepository {

private final JpaAssetAsBuiltRepository jpaAssetAsBuiltRepository;
Expand All @@ -52,15 +53,13 @@ public class AssetAsBuiltRepositoryImpl implements AssetAsBuiltRepository, Asset
private EntityManager entityManager;

@Override
@Transactional
public AssetBase getAssetById(String assetId) {
return jpaAssetAsBuiltRepository.findById(assetId)
.map(AssetAsBuiltEntity::toDomain)
.orElseThrow(() -> new AssetNotFoundException("Asset with id %s was not found.".formatted(assetId)));
}

@Override
@Transactional
public boolean existsById(String assetId) {
return jpaAssetAsBuiltRepository.existsById(assetId);
}
Expand All @@ -85,29 +84,25 @@ public List<String> getFieldValues(String fieldName, String startWith, Integer r
}

@Override
@Transactional
public List<AssetBase> getAssets() {
return jpaAssetAsBuiltRepository.findAll().stream()
.map(AssetAsBuiltEntity::toDomain)
.toList();
}

@Override
@Transactional
public AssetBase save(AssetBase asset) {
return jpaAssetAsBuiltRepository.save(AssetAsBuiltEntity.from(asset)).toDomain();
}

@Override
@Transactional
public List<AssetBase> saveAll(List<AssetBase> assets) {
return jpaAssetAsBuiltRepository.saveAll(AssetAsBuiltEntity.fromList(assets)).stream()
.map(AssetAsBuiltEntity::toDomain)
.toList();
}

@Override
@Transactional
public List<AssetBase> saveAllIfNotInIRSSyncAndUpdateImportStateAndNote(List<AssetBase> assets) {
if (Objects.isNull(assets)) {
return List.of();
Expand All @@ -132,7 +127,6 @@ private boolean entityIsTransientOrNotExistent(AbstractMap.SimpleEntry<AssetBase
return assetBaseAssetBaseEntitySimpleEntry.getValue().getImportState() == ImportState.TRANSIENT;
}

@Transactional
@Override
public List<AssetBase> findByImportStateIn(ImportState... importStates) {
return jpaAssetAsBuiltRepository.findByImportStateIn(importStates).stream()
Expand All @@ -149,7 +143,6 @@ public void updateImportStateAndNoteForAssets(ImportState importState, String im
jpaAssetAsBuiltRepository.saveAll(assets);
}

@Transactional
@Override
public List<AssetBase> findAll() {
return jpaAssetAsBuiltRepository.findAll().stream()
Expand All @@ -162,7 +155,6 @@ public Optional<AssetBase> findById(String assetId) {
.map(AssetAsBuiltEntity::toDomain);
}

@Transactional
@Override
public long countAssets() {
return jpaAssetAsBuiltRepository.count();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

@RequiredArgsConstructor
@Component
@Transactional
public class AssetAsPlannedRepositoryImpl implements AssetAsPlannedRepository, AssetCallbackRepository {

private final JpaAssetAsPlannedRepository jpaAssetAsPlannedRepository;
Expand All @@ -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);
}
Expand All @@ -81,7 +80,6 @@ public AssetBase getAssetByChildId(String childId) {
.orElseThrow(() -> new AssetNotFoundException("Child Asset Not Found"));
}

@Transactional
@Override
public List<AssetBase> findAll() {
return jpaAssetAsPlannedRepository.findAll().stream()
Expand All @@ -97,25 +95,21 @@ public PageResult<AssetBase> getAssets(Pageable pageable, SearchCriteria searchC
}

@Override
@Transactional
public List<AssetBase> 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<AssetBase> saveAll(List<AssetBase> assets) {
return AssetAsPlannedEntity.toDomainList(jpaAssetAsPlannedRepository.saveAll(AssetAsPlannedEntity.fromList(assets)));
}

@Override
@Transactional
public List<AssetBase> saveAllIfNotInIRSSyncAndUpdateImportStateAndNote(List<AssetBase> assets) {
if (Objects.isNull(assets)) {
return List.of();
Expand Down Expand Up @@ -150,7 +144,6 @@ public Optional<AssetBase> findById(String assetId) {
.map(AssetAsPlannedEntity::toDomain);
}

@Transactional
@Override
public long countAssets() {
return jpaAssetAsPlannedRepository.count();
Expand All @@ -166,7 +159,6 @@ public List<String> getFieldValues(String fieldName, String startWith, Integer r
return CriteriaUtility.getDistinctAssetFieldValues(fieldName, startWith, resultLimit, owner, inAssetIds, AssetAsPlannedEntity.class, entityManager);
}

@Transactional
@Override
public List<AssetBase> findByImportStateIn(ImportState... importStates) {
return jpaAssetAsPlannedRepository.findByImportStateIn(importStates).stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,23 @@ public void handleJobFinishedCallback(String jobId, String state) {
}

void saveOrUpdateAssets(AssetCallbackRepository repository, AssetBase asset) {
Optional<AssetBase> 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<AssetBase> 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);
}
// }
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ void givenInvalidJobId_whenCallbackReceivedForAsPlanned_thenNothingSynchronized(
@Test
void givenAssetExist_whenCallbackReceived_thenUpdateIt() {
// given
assetsSupport.defaultAssetsStored();
bpnSupport.providesBpdmLookup();
oAuth2ApiSupport.oauth2ApiReturnsTechnicalUserToken();
irsApiSupport.irsApiReturnsJobDetails();
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" : [
{
Expand Down

0 comments on commit 21f78e4

Please sign in to comment.