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

This commit is contained in:
Sofia Papacharalampous 2024-03-26 16:55:05 +02:00
commit fe323d9b6a
8 changed files with 112 additions and 20 deletions

View File

@ -50,12 +50,12 @@
<dependency> <dependency>
<groupId>gr.cite.opendmp</groupId> <groupId>gr.cite.opendmp</groupId>
<artifactId>common-models</artifactId> <artifactId>common-models</artifactId>
<version>0.0.5</version> <version>0.0.7</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>gr.cite.opendmp</groupId> <groupId>gr.cite.opendmp</groupId>
<artifactId>file-transformer-base</artifactId> <artifactId>file-transformer-base</artifactId>
<version>0.0.6</version> <version>0.0.10</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>gr.cite</groupId> <groupId>gr.cite</groupId>

View File

@ -0,0 +1,52 @@
package eu.eudat.model.builder.commonmodels;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commonmodels.models.DescriptionTemplateTypeModel;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.DescriptionTemplateTypeEntity;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Optional;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DescriptionTemplateTypeCommonModelBuilder extends BaseCommonModelBuilder<DescriptionTemplateTypeModel, DescriptionTemplateTypeEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public DescriptionTemplateTypeCommonModelBuilder(
ConventionService conventionService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionTemplateTypeCommonModelBuilder.class)));
}
public DescriptionTemplateTypeCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
protected List<CommonModelBuilderItemResponse<DescriptionTemplateTypeModel, DescriptionTemplateTypeEntity>> buildInternal(List<DescriptionTemplateTypeEntity> data) throws MyApplicationException {
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
if (data == null || data.isEmpty()) return new ArrayList<>();
List<CommonModelBuilderItemResponse<DescriptionTemplateTypeModel, DescriptionTemplateTypeEntity>> models = new ArrayList<>();
for (DescriptionTemplateTypeEntity d : data) {
DescriptionTemplateTypeModel m = new DescriptionTemplateTypeModel();
m.setId(d.getId());
m.setName(d.getName());
models.add(new CommonModelBuilderItemResponse<>(m, d));
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -66,7 +66,7 @@ public class PropertyDefinitionFieldSetItemModelCommonModelBuilder extends BaseC
if (d.getFields() != null && !d.getFields().isEmpty()) { if (d.getFields() != null && !d.getFields().isEmpty()) {
m.setFields(new HashMap<>()); m.setFields(new HashMap<>());
for (String key : d.getFields().keySet()){ for (String key : d.getFields().keySet()){
FieldEntity fieldEntity = fieldSetEntity != null ? fieldSetEntity.getAllField().stream().findFirst().orElse(null) : null; FieldEntity fieldEntity = fieldSetEntity != null ? fieldSetEntity.getFieldById(key).stream().findFirst().orElse(null) : null;
m.getFields().put(key, this.builderFactory.builder(FieldCommonModelBuilder.class).useSharedStorage(useSharedStorage).authorize(this.authorize).withFieldEntity(fieldEntity).build(d.getFields().get(key))); m.getFields().put(key, this.builderFactory.builder(FieldCommonModelBuilder.class).useSharedStorage(useSharedStorage).authorize(this.authorize).withFieldEntity(fieldEntity).build(d.getFields().get(key)));
} }
} }

View File

@ -1,16 +1,17 @@
package eu.eudat.model.builder.commonmodels.descriptiontemplate; package eu.eudat.model.builder.commonmodels.descriptiontemplate;
import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commonmodels.models.DescriptionTemplateTypeModel;
import eu.eudat.commonmodels.models.descriptiotemplate.DescriptionTemplateModel; import eu.eudat.commonmodels.models.descriptiotemplate.DescriptionTemplateModel;
import eu.eudat.commons.JsonHandlingService;
import eu.eudat.commons.XmlHandlingService; import eu.eudat.commons.XmlHandlingService;
import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity; import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity;
import eu.eudat.commons.types.dmp.DmpPropertiesEntity;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.data.DescriptionTemplateTypeEntity;
import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder; import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse; import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
import eu.eudat.model.builder.commonmodels.dmp.DmpPropertiesCommonModelBuilder; import eu.eudat.model.builder.commonmodels.DescriptionTemplateTypeCommonModelBuilder;
import eu.eudat.query.DescriptionTemplateTypeQuery;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyApplicationException;
@ -22,6 +23,7 @@ import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
@Component @Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@ -31,12 +33,14 @@ public class DescriptionTemplateCommonModelBuilder extends BaseCommonModelBuilde
private final XmlHandlingService xmlHandlingService; private final XmlHandlingService xmlHandlingService;
private final BuilderFactory builderFactory; private final BuilderFactory builderFactory;
private final QueryFactory queryFactory;
@Autowired @Autowired
public DescriptionTemplateCommonModelBuilder( public DescriptionTemplateCommonModelBuilder(
ConventionService conventionService, XmlHandlingService xmlHandlingService, BuilderFactory builderFactory) { ConventionService conventionService, XmlHandlingService xmlHandlingService, BuilderFactory builderFactory, QueryFactory queryFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionTemplateCommonModelBuilder.class))); super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionTemplateCommonModelBuilder.class)));
this.xmlHandlingService = xmlHandlingService; this.xmlHandlingService = xmlHandlingService;
this.builderFactory = builderFactory; this.builderFactory = builderFactory;
this.queryFactory = queryFactory;
} }
public DescriptionTemplateCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) { public DescriptionTemplateCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
@ -49,6 +53,7 @@ public class DescriptionTemplateCommonModelBuilder extends BaseCommonModelBuilde
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0)); this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
if (data == null || data.isEmpty()) return new ArrayList<>(); if (data == null || data.isEmpty()) return new ArrayList<>();
Map<UUID, DescriptionTemplateTypeModel> typeMap = this.collectDescriptionTemplateTypes(data);
List<CommonModelBuilderItemResponse<DescriptionTemplateModel, DescriptionTemplateEntity>> models = new ArrayList<>(); List<CommonModelBuilderItemResponse<DescriptionTemplateModel, DescriptionTemplateEntity>> models = new ArrayList<>();
for (DescriptionTemplateEntity d : data) { for (DescriptionTemplateEntity d : data) {
DescriptionTemplateModel m = new DescriptionTemplateModel(); DescriptionTemplateModel m = new DescriptionTemplateModel();
@ -63,6 +68,7 @@ public class DescriptionTemplateCommonModelBuilder extends BaseCommonModelBuilde
DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(DefinitionEntity.class, d.getDefinition()); DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(DefinitionEntity.class, d.getDefinition());
m.setDefinition(this.builderFactory.builder(DefinitionCommonModelBuilder.class).authorize(this.authorize).build(definition)); m.setDefinition(this.builderFactory.builder(DefinitionCommonModelBuilder.class).authorize(this.authorize).build(definition));
} }
if (typeMap != null && d.getTypeId() != null && typeMap.containsKey(d.getTypeId())) m.setType(typeMap.get(d.getTypeId()));
models.add(new CommonModelBuilderItemResponse<>(m, d)); models.add(new CommonModelBuilderItemResponse<>(m, d));
@ -73,4 +79,19 @@ public class DescriptionTemplateCommonModelBuilder extends BaseCommonModelBuilde
return models; return models;
} }
private Map<UUID, DescriptionTemplateTypeModel> collectDescriptionTemplateTypes(List<DescriptionTemplateEntity> data) throws MyApplicationException {
if (data.isEmpty())
return null;
this.logger.debug("checking related - {}", DescriptionTemplateTypeModel.class.getSimpleName());
Map<UUID, DescriptionTemplateTypeModel> itemMap;
DescriptionTemplateTypeQuery q = this.queryFactory.query(DescriptionTemplateTypeQuery.class).authorize(this.authorize).ids(data.stream().map(DescriptionTemplateEntity::getTypeId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(DescriptionTemplateTypeCommonModelBuilder.class).authorize(this.authorize).asForeignKey(q, DescriptionTemplateTypeEntity::getId);
return itemMap;
}
} }

View File

@ -36,6 +36,7 @@ public class ReferenceTypeDataCommonModelBuilder extends BaseFieldDataCommonMode
@Override @Override
protected void buildChild(ReferenceTypeDataEntity d, ReferenceTypeDataModel m) { protected void buildChild(ReferenceTypeDataEntity d, ReferenceTypeDataModel m) {
m.setMultipleSelect(d.getMultipleSelect());
if (d.getReferenceTypeId() != null) m.setReferenceType(this.builderFactory.builder(ReferenceTypeCommonModelBuilder.class).build(this.queryFactory.query(ReferenceTypeQuery.class).ids(d.getReferenceTypeId()).first())); //TODO: Optimize if (d.getReferenceTypeId() != null) m.setReferenceType(this.builderFactory.builder(ReferenceTypeCommonModelBuilder.class).build(this.queryFactory.query(ReferenceTypeQuery.class).ids(d.getReferenceTypeId()).first())); //TODO: Optimize
} }

View File

@ -238,7 +238,7 @@ public class VisibilityServiceImpl implements VisibilityService {
Boolean currentValue = this.visibility.getOrDefault(fieldKey, null); Boolean currentValue = this.visibility.getOrDefault(fieldKey, null);
if (currentValue == null){ if (currentValue == null){
this.visibility.put(fieldKey, true); this.visibility.put(fieldKey, true);
this.setDefaultSectionVisibility(sectionEntity); this.setDefaultSectionVisibility(subSectionEntity);
} }
} }
} }
@ -356,8 +356,7 @@ public class VisibilityServiceImpl implements VisibilityService {
} }
else if (eu.eudat.commons.enums.FieldType.isTextListType(fieldType) && field.getTextListValue() != null && !field.getTextListValue().isEmpty()) { else if (eu.eudat.commons.enums.FieldType.isTextListType(fieldType) && field.getTextListValue() != null && !field.getTextListValue().isEmpty()) {
return rule.getTextListValue() != null && return rule.getTextListValue() != null &&
new HashSet<>(field.getTextListValue()).containsAll(rule.getTextListValue()) && new HashSet<>(field.getTextListValue()).containsAll(rule.getTextListValue());
new HashSet<>(rule.getTextListValue()).containsAll(field.getTextListValue());
} }
else if (eu.eudat.commons.enums.FieldType.isReferenceType(fieldType)) { else if (eu.eudat.commons.enums.FieldType.isReferenceType(fieldType)) {
return rule.getTextListValue() != null && return rule.getTextListValue() != null &&

View File

@ -199,7 +199,7 @@
<dependency> <dependency>
<groupId>gr.cite.opendmp</groupId> <groupId>gr.cite.opendmp</groupId>
<artifactId>file-transformer-base</artifactId> <artifactId>file-transformer-base</artifactId>
<version>0.0.6</version> <version>0.0.10</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -119,9 +119,10 @@ public class DescriptionTemplateXmlMigrationService {
if (persist == null) if (persist == null)
return data; return data;
if (!this.conventionService.isListNullOrEmpty(persist.getPages())) { if (!this.conventionService.isListNullOrEmpty(persist.getPages())) {
Map<String, List<Section>> sectionPerPage = mapSectionsToPage(persist);
data.setPages(new ArrayList<>()); data.setPages(new ArrayList<>());
for (Page pagePersist : persist.getPages()) { for (Page pagePersist : persist.getPages()) {
data.getPages().add(this.buildPageEntity(pagePersist, persist.getSections(), referenceTypeEntityMap)); data.getPages().add(this.buildPageEntity(pagePersist, sectionPerPage.get(pagePersist.getId()), referenceTypeEntityMap));
} }
} }
@ -458,7 +459,7 @@ public class DescriptionTemplateXmlMigrationService {
private @NotNull PageEntity buildPageEntity(Page persist, List<Section> allSections, Map<String, ReferenceTypeEntity> referenceTypeEntityMap) throws URISyntaxException { private @NotNull PageEntity buildPageEntity(Page persist, List<Section> sections, Map<String, ReferenceTypeEntity> referenceTypeEntityMap) throws URISyntaxException {
PageEntity data = new PageEntity(); PageEntity data = new PageEntity();
if (persist == null) if (persist == null)
return data; return data;
@ -467,7 +468,6 @@ public class DescriptionTemplateXmlMigrationService {
data.setOrdinal(persist.getOrdinal()); data.setOrdinal(persist.getOrdinal());
data.setTitle(persist.getTitle()); data.setTitle(persist.getTitle());
List<Section> sections = allSections.stream().filter(x-> this.isInPage(x, persist)).toList();
if (!this.conventionService.isListNullOrEmpty(sections)) { if (!this.conventionService.isListNullOrEmpty(sections)) {
data.setSections(new ArrayList<>()); data.setSections(new ArrayList<>());
for (Section sectionPersist : sections) { for (Section sectionPersist : sections) {
@ -477,18 +477,37 @@ public class DescriptionTemplateXmlMigrationService {
return data; return data;
} }
private Map<String, List<Section>> mapSectionsToPage(ViewStyleModel persist){
List<String> mappedSectionsIds = new ArrayList<>();
Map<String, List<Section>> sectionPerPage = new HashMap<>();
if (persist == null || persist.getPages() == null || persist.getSections() == null) return sectionPerPage;
for (Page page :persist.getPages()){
sectionPerPage.put(page.getId(), new ArrayList<>());
for (Section section : persist.getSections()){
if (this.isInPage(section, page)){
if (mappedSectionsIds.contains(section.getId())) throw new MyApplicationException("Multiple page section found for page " + page.getId() + " section " + section.getId());
mappedSectionsIds.add(section.getId());
sectionPerPage.get(page.getId()).add(section);
}
}
}
for (Section section : persist.getSections()){
if (!mappedSectionsIds.contains(section.getId())) throw new MyApplicationException("Orphan section found " + section.getId());
}
return sectionPerPage;
}
private boolean isInPage(Section section, Page page){ private boolean isInPage(Section section, Page page){
try { try {
return UUID.fromString(section.getPage()).equals(UUID.fromString(page.getId())); return UUID.fromString(section.getPage()).equals(UUID.fromString(page.getId()));
} catch (Exception e){ } catch (Exception e){
if (section.getPage().toLowerCase(Locale.ROOT).equals(page.getId().toLowerCase(Locale.ROOT))) return true;
try {
return Integer.parseInt(section.getPage().replace("page_", "")) == page.getOrdinal();
} catch (Exception e1){
return section.getPage().toLowerCase(Locale.ROOT).equals(page.getId().toLowerCase(Locale.ROOT)); return section.getPage().toLowerCase(Locale.ROOT).equals(page.getId().toLowerCase(Locale.ROOT));
} }
} }
}
public ReferenceTypeEntity resolveReferenceTypeEntityAutoCompleteData(AutoCompleteData persist, Map<String, ReferenceTypeEntity> referenceTypeEntityMap) throws URISyntaxException { public ReferenceTypeEntity resolveReferenceTypeEntityAutoCompleteData(AutoCompleteData persist, Map<String, ReferenceTypeEntity> referenceTypeEntityMap) throws URISyntaxException {
ReferenceTypeDefinitionEntity definitionEntity = this.buildReferenceTypeDefinitionEntity(persist); ReferenceTypeDefinitionEntity definitionEntity = this.buildReferenceTypeDefinitionEntity(persist);