Merge branch 'dmp-refactoring' of https://code-repo.d4science.org/MaDgiK-CITE/argos into dmp-refactoring

This commit is contained in:
Sofia Papacharalampous 2024-05-29 14:59:53 +03:00
commit ae4595874b
3 changed files with 34 additions and 4 deletions

View File

@ -47,6 +47,7 @@ import org.opencdmp.commons.types.dmp.DmpBlueprintValueEntity;
import org.opencdmp.commons.types.dmp.DmpContactEntity; import org.opencdmp.commons.types.dmp.DmpContactEntity;
import org.opencdmp.commons.types.dmp.DmpPropertiesEntity; import org.opencdmp.commons.types.dmp.DmpPropertiesEntity;
import org.opencdmp.commons.types.dmp.importexport.*; import org.opencdmp.commons.types.dmp.importexport.*;
import org.opencdmp.commons.types.dmpblueprint.DescriptionTemplateEntity;
import org.opencdmp.commons.types.dmpblueprint.ExtraFieldEntity; import org.opencdmp.commons.types.dmpblueprint.ExtraFieldEntity;
import org.opencdmp.commons.types.dmpblueprint.ReferenceTypeFieldEntity; import org.opencdmp.commons.types.dmpblueprint.ReferenceTypeFieldEntity;
import org.opencdmp.commons.types.dmpblueprint.SectionEntity; import org.opencdmp.commons.types.dmpblueprint.SectionEntity;
@ -485,6 +486,11 @@ public class DmpServiceImpl implements DmpService {
this.entityManager.flush(); this.entityManager.flush();
if (model.getDescriptions() != null){ if (model.getDescriptions() != null){
DmpBlueprintEntity blueprintEntity = this.entityManager.find(DmpBlueprintEntity.class, model.getBlueprintId(), true);
if (blueprintEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getBlueprintId(), DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
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<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(); List<DescriptionEntity> descriptionEntities = this.queryFactory.query(DescriptionQuery.class).disableTracking().ids(model.getDescriptions().stream().map(NewVersionDmpDescriptionPersist::getDescriptionId).distinct().collect(Collectors.toList())).isActive(IsActive.Active).collect();
@ -513,6 +519,30 @@ 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(); this.entityManager.flush();

View File

@ -113,7 +113,7 @@ export class NewVersionDmpDialogComponent extends BaseComponent {
selectedBlueprintChanged(item: DmpBlueprint): void{ selectedBlueprintChanged(item: DmpBlueprint): void{
this.selectedBlueprintSections = item.definition?.sections?.filter(x => x.hasTemplates) || null; this.selectedBlueprintSections = item.definition?.sections?.filter(x => x.hasTemplates) || null;
if(this.selectedBlueprintSections && this.hasDescriptions()) { if(this.selectedBlueprintSections && this.hasDescriptions()) {
this.formGroup = this.editorModel.fromModel(this.dmp, item).buildForm(); this.formGroup = this.editorModel.fromModel(this.dmp, item, this.formGroup.get('label').value, this.formGroup.get('description').value).buildForm();
} }
} }

View File

@ -19,11 +19,11 @@ export class DmpNewVersionDialogEditorModel implements NewVersionDmpPersist {
constructor() { } constructor() { }
public fromModel(item: Dmp, blueprint: DmpBlueprint): DmpNewVersionDialogEditorModel { public fromModel(item: Dmp, blueprint: DmpBlueprint, label?: string, description?: string): DmpNewVersionDialogEditorModel {
if (item) { if (item) {
this.id = item.id; this.id = item.id;
this.label = this.label != undefined ? this.label : item.label; this.label = label != undefined ? label : item.label;
this.description = this.description != undefined ? this.description : item.description; this.description = description != undefined ? description : item.description;
this.blueprintId = blueprint?.id != undefined ? blueprint.id : item.blueprint.id; this.blueprintId = blueprint?.id != undefined ? blueprint.id : item.blueprint.id;
this.hash= item.hash; this.hash= item.hash;