Skip to content

Commit

Permalink
chore: TRACEFOSS-XXX update all shell descriptors by registry reload
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-lcapellino committed Oct 19, 2023
1 parent 033e82e commit 9e15540
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,37 @@ public List<ShellDescriptor> determineExistingShellDescriptorsAndUpdate(List<She
log.info("Starting update of {} shell ownShellDescriptors.", ownShellDescriptors.size());
Map<String, ShellDescriptor> existingDescriptors = shellDescriptorRepository.findAll().stream()
.collect(Collectors.toMap(ShellDescriptor::getGlobalAssetId, Function.identity()));
List<ShellDescriptor> descriptorsToSync = new ArrayList<>();
List<ShellDescriptor> newDescriptorsToSync = new ArrayList<>();
List<ShellDescriptor> existingDescriptorsToUpdate = new ArrayList<>();
ZonedDateTime now = ZonedDateTime.now();

for (ShellDescriptor descriptor : ownShellDescriptors) {
if (existingDescriptors.containsKey(descriptor.getGlobalAssetId())) {
shellDescriptorRepository.update(existingDescriptors.get(descriptor.getGlobalAssetId()));
existingDescriptorsToUpdate.add(existingDescriptors.get(descriptor.getGlobalAssetId()));
log.info("Updated existing shellDescriptor with id {}.", descriptor.getGlobalAssetId());
} else {
descriptorsToSync.add((descriptor));
newDescriptorsToSync.add((descriptor));
}
}
log.info("Updated new shellDescriptors list size {}.", descriptorsToSync.size());
descriptorsToSync.forEach(this::persistDescriptor);
log.info("Added new shellDescriptors list size {}.", newDescriptorsToSync.size());
newDescriptorsToSync.forEach(this::persistDescriptor);
existingDescriptorsToUpdate.forEach(this::updateDescriptor);
shellDescriptorRepository.removeDescriptorsByUpdatedBefore(now);

log.info("Finished update of {} shell descriptors.", ownShellDescriptors.size());

return descriptorsToSync;
//Merge those two lists to sync all relevant shell descriptors
newDescriptorsToSync.addAll(existingDescriptorsToUpdate);
return newDescriptorsToSync;
}

private void updateDescriptor(ShellDescriptor shellDescriptor) {
try {
shellDescriptorRepository.update(shellDescriptor);
} catch (DataIntegrityViolationException exception) {
log.warn("Failed to persist shellDescriptor with Id: {} With cause: {}", shellDescriptor.getId(), exception.getMessage());
}

}

private void persistDescriptor(ShellDescriptor shellDescriptor){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void saveAll(Collection<ShellDescriptor> values) {
}

@Override
@Transactional
public void save(ShellDescriptor descriptor) {
repository.save(ShellDescriptorEntity.newEntityFrom(descriptor));
}
Expand Down

0 comments on commit 9e15540

Please sign in to comment.