dmp new version bug fix

This commit is contained in:
amentis 2024-06-10 13:02:50 +03:00
parent 24651aa1b0
commit b1497c108e
1 changed files with 29 additions and 24 deletions

View File

@ -500,6 +500,35 @@ public class DmpServiceImpl implements DmpService {
FieldSet fieldSet = new BaseFieldSet(Description._id, BaseFieldSet.asIndexer(Description._descriptionTemplate, DescriptionTemplate._groupId));
List<Description> models = this.builderFactory.builder(DescriptionBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermission).build(fieldSet, descriptionEntities);
if (!oldDmpEntity.getBlueprintId().equals(blueprintEntity.getId())){
// add description templates if exists in new blueprint
List<SectionEntity> sections = definition.getSections().stream().filter(x -> x.getHasTemplates()).collect(Collectors.toList());
if (!this.conventionService.isListNullOrEmpty(sections) && !this.conventionService.isListNullOrEmpty(dmpDescriptionTemplateEntities)){
for (SectionEntity section: sections) {
if (!this.conventionService.isListNullOrEmpty(section.getDescriptionTemplates())){
for (DescriptionTemplateEntity blueprintDescriptionTemplate: section.getDescriptionTemplates()) {
if (model.getDescriptions().stream().map(x -> x.getBlueprintSectionId()).collect(Collectors.toList()).contains(section.getId())){
DmpDescriptionTemplateEntity existingBlueprintDescriptionTemplateEntity = dmpDescriptionTemplateEntities.stream().filter(x -> x.getSectionId().equals(section.getId()) && x.getDescriptionTemplateGroupId().equals(blueprintDescriptionTemplate.getDescriptionTemplateGroupId())).findFirst().orElse(null);
if (existingBlueprintDescriptionTemplateEntity == null){
DmpDescriptionTemplateEntity newTemplate = new DmpDescriptionTemplateEntity();
newTemplate.setId(UUID.randomUUID());
newTemplate.setDmpId(newDmp.getId());
newTemplate.setDescriptionTemplateGroupId(blueprintDescriptionTemplate.getDescriptionTemplateGroupId());
newTemplate.setSectionId(section.getId());
newTemplate.setCreatedAt(Instant.now());
newTemplate.setUpdatedAt(Instant.now());
newTemplate.setIsActive(IsActive.Active);
this.entityManager.persist(newTemplate);
this.entityManager.flush();
}
}
}
}
}
}
}
if (!this.conventionService.isListNullOrEmpty(dmpDescriptionTemplateEntities) && !this.conventionService.isListNullOrEmpty(models)){
for (NewVersionDmpDescriptionPersist newVersionDmpDescriptionPersist : model.getDescriptions()) {
Description description = models.stream().filter(x -> x.getId().equals(newVersionDmpDescriptionPersist.getDescriptionId())).findFirst().orElse(null);
@ -523,30 +552,6 @@ public class DmpServiceImpl implements DmpService {
}
}
}
if (!oldDmpEntity.getBlueprintId().equals(blueprintEntity.getId())){
// add description templates if exists in new blueprint
List<SectionEntity> sections = definition.getSections().stream().filter(x -> x.getHasTemplates()).collect(Collectors.toList());
if (!this.conventionService.isListNullOrEmpty(sections)){
for (SectionEntity section: sections) {
if (!this.conventionService.isListNullOrEmpty(section.getDescriptionTemplates())){
for (DescriptionTemplateEntity blueprintDescriptionTemplate: section.getDescriptionTemplates()) {
if (model.getDescriptions().stream().map(x -> x.getBlueprintSectionId()).collect(Collectors.toList()).contains(section.getId())){
DmpDescriptionTemplateEntity newTemplate = new DmpDescriptionTemplateEntity();
newTemplate.setId(UUID.randomUUID());
newTemplate.setDmpId(newDmp.getId());
newTemplate.setDescriptionTemplateGroupId(blueprintDescriptionTemplate.getDescriptionTemplateGroupId());
newTemplate.setSectionId(section.getId());
newTemplate.setCreatedAt(Instant.now());
newTemplate.setUpdatedAt(Instant.now());
newTemplate.setIsActive(IsActive.Active);
this.entityManager.persist(newTemplate);
}
}
}
}
}
}
}
this.entityManager.flush();