new version backend changes

This commit is contained in:
amentis 2024-06-19 15:58:41 +03:00
parent b9d2c00c88
commit 980e7fe40d
1 changed files with 42 additions and 40 deletions

View File

@ -466,21 +466,6 @@ public class DmpServiceImpl implements DmpService {
this.entityManager.persist(newReference);
}
Map<UUID, UUID> dmpDescriptionTemplateRemap = new HashMap<>();
for (DmpDescriptionTemplateEntity dmpDescriptionTemplate : dmpDescriptionTemplates) {
DmpDescriptionTemplateEntity newTemplate = new DmpDescriptionTemplateEntity();
newTemplate.setId(UUID.randomUUID());
newTemplate.setDmpId(newDmp.getId());
newTemplate.setDescriptionTemplateGroupId(dmpDescriptionTemplate.getDescriptionTemplateGroupId());
newTemplate.setSectionId(dmpDescriptionTemplate.getSectionId());
newTemplate.setCreatedAt(Instant.now());
newTemplate.setUpdatedAt(Instant.now());
newTemplate.setIsActive(IsActive.Active);
dmpDescriptionTemplateRemap.put(dmpDescriptionTemplate.getId(), newTemplate.getId());
this.entityManager.persist(newTemplate);
}
this.entityManager.flush();
if (model.getDescriptions() != null){
@ -489,21 +474,47 @@ public class DmpServiceImpl implements DmpService {
org.opencdmp.commons.types.dmpblueprint.DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(org.opencdmp.commons.types.dmpblueprint.DefinitionEntity.class, blueprintEntity.getDefinition());
List<DmpDescriptionTemplateEntity> dmpDescriptionTemplateEntities = this.queryFactory.query(DmpDescriptionTemplateQuery.class).disableTracking().dmpIds(newDmp.getId()).isActive(IsActive.Active).collect();
List<DescriptionEntity> descriptionEntities = this.queryFactory.query(DescriptionQuery.class).disableTracking().ids(model.getDescriptions().stream().map(NewVersionDmpDescriptionPersist::getDescriptionId).distinct().collect(Collectors.toList())).isActive(IsActive.Active).collect();
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 (!this.conventionService.isListNullOrEmpty(models)){
for (NewVersionDmpDescriptionPersist newVersionDmpDescriptionPersist : model.getDescriptions()) {
Description description = models.stream().filter(x -> x.getId().equals(newVersionDmpDescriptionPersist.getDescriptionId())).findFirst().orElse(null);
if (description != null){
DmpDescriptionTemplateEntity existingDmpDescriptionTemplateEntity = this.queryFactory.query(DmpDescriptionTemplateQuery.class).disableTracking().dmpIds(newDmp.getId()).isActive(IsActive.Active).sectionIds(newVersionDmpDescriptionPersist.getBlueprintSectionId()).descriptionTemplateGroupIds(description.getDescriptionTemplate().getGroupId()).first();
if (existingDmpDescriptionTemplateEntity == null){
DmpDescriptionTemplateEntity newTemplate = new DmpDescriptionTemplateEntity();
newTemplate.setId(UUID.randomUUID());
newTemplate.setDmpId(newDmp.getId());
newTemplate.setDescriptionTemplateGroupId(description.getDescriptionTemplate().getGroupId());
newTemplate.setSectionId(newVersionDmpDescriptionPersist.getBlueprintSectionId());
newTemplate.setCreatedAt(Instant.now());
newTemplate.setUpdatedAt(Instant.now());
newTemplate.setIsActive(IsActive.Active);
this.entityManager.persist(newTemplate);
this.entityManager.flush();
this.cloneDescription(newDmp.getId(), null, newVersionDmpDescriptionPersist.getDescriptionId(), newTemplate.getId());
} else{
this.cloneDescription(newDmp.getId(), null, newVersionDmpDescriptionPersist.getDescriptionId(), existingDmpDescriptionTemplateEntity.getId());
}
}
}
}
List<DmpDescriptionTemplateEntity> newDmpDescriptionTemplateEntities = this.queryFactory.query(DmpDescriptionTemplateQuery.class).disableTracking().dmpIds(newDmp.getId()).isActive(IsActive.Active).collect();
if (!oldDmpEntity.getBlueprintId().equals(blueprintEntity.getId())){
// add description templates if exists in new blueprint
List<SectionEntity> sections = definition.getSections().stream().filter(SectionEntity::getHasTemplates).collect(Collectors.toList());
if (!this.conventionService.isListNullOrEmpty(sections) && !this.conventionService.isListNullOrEmpty(dmpDescriptionTemplateEntities)){
if (!this.conventionService.isListNullOrEmpty(sections) && !this.conventionService.isListNullOrEmpty(newDmpDescriptionTemplateEntities)){
for (SectionEntity section: sections) {
if (!this.conventionService.isListNullOrEmpty(section.getDescriptionTemplates())){
for (DescriptionTemplateEntity blueprintDescriptionTemplate: section.getDescriptionTemplates()) {
if (model.getDescriptions().stream().map(NewVersionDmpDescriptionPersist::getBlueprintSectionId).toList().contains(section.getId())){
DmpDescriptionTemplateEntity existingBlueprintDescriptionTemplateEntity = dmpDescriptionTemplateEntities.stream().filter(x -> x.getSectionId().equals(section.getId()) && x.getDescriptionTemplateGroupId().equals(blueprintDescriptionTemplate.getDescriptionTemplateGroupId())).findFirst().orElse(null);
DmpDescriptionTemplateEntity existingBlueprintDescriptionTemplateEntity = newDmpDescriptionTemplateEntities.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());
@ -521,28 +532,19 @@ public class DmpServiceImpl implements DmpService {
}
}
}
}
} else {
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);
if (description != null){
DmpDescriptionTemplateEntity existingDmpDescriptionTemplateEntity = dmpDescriptionTemplateEntities.stream().filter(x -> x.getSectionId().equals(newVersionDmpDescriptionPersist.getBlueprintSectionId()) && x.getDescriptionTemplateGroupId().equals(description.getDescriptionTemplate().getGroupId())).findFirst().orElse(null);
if (existingDmpDescriptionTemplateEntity == null){
for (DmpDescriptionTemplateEntity oldDmpDescriptionTemplate : dmpDescriptionTemplates) {
if (newDmpDescriptionTemplateEntities.stream().filter(x -> x.getSectionId().equals(oldDmpDescriptionTemplate.getSectionId()) && x.getDescriptionTemplateGroupId().equals(oldDmpDescriptionTemplate.getDescriptionTemplateGroupId())).findFirst().orElse(null) == null){
DmpDescriptionTemplateEntity newTemplate = new DmpDescriptionTemplateEntity();
newTemplate.setId(UUID.randomUUID());
newTemplate.setDmpId(newDmp.getId());
newTemplate.setDescriptionTemplateGroupId(description.getDescriptionTemplate().getGroupId());
newTemplate.setSectionId(newVersionDmpDescriptionPersist.getBlueprintSectionId());
newTemplate.setDescriptionTemplateGroupId(oldDmpDescriptionTemplate.getDescriptionTemplateGroupId());
newTemplate.setSectionId(oldDmpDescriptionTemplate.getSectionId());
newTemplate.setCreatedAt(Instant.now());
newTemplate.setUpdatedAt(Instant.now());
newTemplate.setIsActive(IsActive.Active);
this.entityManager.persist(newTemplate);
this.entityManager.flush();
this.cloneDescription(newDmp.getId(), dmpDescriptionTemplateRemap, newVersionDmpDescriptionPersist.getDescriptionId(), newTemplate.getId());
} else{
this.cloneDescription(newDmp.getId(), dmpDescriptionTemplateRemap, newVersionDmpDescriptionPersist.getDescriptionId(), null);
}
}
}
}
@ -577,7 +579,7 @@ public class DmpServiceImpl implements DmpService {
newDescription.setStatus(DescriptionStatus.Draft);
newDescription.setProperties(existing.getProperties());
newDescription.setDmpId(dmpId);
if (newDmpDescriptionTemplateId == null) newDescription.setDmpDescriptionTemplateId(dmpDescriptionTemplateRemap.get(existing.getDmpDescriptionTemplateId()));
if (newDmpDescriptionTemplateId == null && dmpDescriptionTemplateRemap != null) newDescription.setDmpDescriptionTemplateId(dmpDescriptionTemplateRemap.get(existing.getDmpDescriptionTemplateId()));
else newDescription.setDmpDescriptionTemplateId(newDmpDescriptionTemplateId);
newDescription.setDescriptionTemplateId(existing.getDescriptionTemplateId());
newDescription.setCreatedById(this.userScope.getUserId());