From 0530373c8380dd936c187c64691415e8cae8c557 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Mon, 4 Mar 2024 16:36:15 +0200 Subject: [PATCH] change to common models for Deposit --- dmp-backend/core/pom.xml | 7 +- .../BaseCommonModelBuilder.java} | 25 +- .../CommonModelBuilderItemResponse.java} | 6 +- .../DepositConfigurationBuilder.java | 11 +- .../DmpCommonModelBuilder.java} | 74 +-- .../DmpUserCommonModelBuilder.java} | 34 +- .../ReferenceTypeCommonModelBuilder.java | 53 ++ .../UserCommonModelBuilder.java} | 20 +- .../DescriptionCommonModelBuilder.java | 117 ++++ .../ExternalIdentifierCommonModelBuilder.java | 56 ++ .../description/FieldCommonModelBuilder.java | 97 ++++ .../PropertyDefinitionCommonModelBuilder.java | 65 +++ ...yDefinitionFieldSetCommonModelBuilder.java | 61 ++ ...onFieldSetItemModelCommonModelBuilder.java | 73 +++ .../DefinitionCommonModelBuilder.java | 59 ++ ...DescriptionTemplateCommonModelBuilder.java | 76 +++ .../FieldCommonModelBuilder.java | 86 +++ .../FieldSetCommonModelBuilder.java | 68 +++ .../MultiplicityCommonModelBuilder.java | 61 ++ .../PageCommonModelBuilder.java | 63 +++ .../RuleCommonModelBuilder.java | 55 ++ .../SectionCommonModelBuilder.java | 69 +++ .../BaseFieldDataCommonModelBuilder.java | 79 +++ ...AndMultiplicityDataCommonModelBuilder.java | 31 + .../LabelDataCommonModelBuilder.java | 31 + .../RadioBoxDataCommonModelBuilder.java | 80 +++ .../ReferenceTypeDataCommonModelBuilder.java | 42 ++ .../SelectDataCommonModelBuilder.java | 80 +++ .../UploadDataCommonModelBuilder.java | 80 +++ .../ReferenceCommonModelBuilder.java | 97 ++++ ...eferenceDefinitionCommonModelBuilder.java} | 24 +- .../ReferenceFieldCommonModelBuilder.java} | 22 +- .../deposit/DescriptionDepositBuilder.java | 101 ---- .../DescriptionFieldDepositBuilder.java | 112 ---- .../deposit/ReferenceDepositBuilder.java | 75 --- .../FieldBuilder.java | 9 +- .../fielddata/BaseFieldDataBuilder.java | 3 - .../BaseFileTransformerBuilder.java | 154 ++--- ...escriptionFieldFileTransformerBuilder.java | 535 +++++++++--------- .../DescriptionFileTransformerBuilder.java | 338 ++++++----- ...plateDefinitionFileTransformerBuilder.java | 474 ++++++++-------- ...riptionTemplateFileTransformerBuilder.java | 166 +++--- .../DmpBlueprintFileTransformerBuilder.java | 258 ++++----- .../DmpFileTransformerBuilder.java | 400 ++++++------- .../DmpUserFileTransformerBuilder.java | 170 +++--- .../EntityDoiFileTransformerBuilder.java | 68 +-- .../FileTransformerBuilderItemResponse.java | 38 +- ...renceDefinitionFileTransformerBuilder.java | 109 ++-- .../ReferenceFieldFileTransformerBuilder.java | 107 ++-- .../ReferenceFileTransformerBuilder.java | 160 +++--- .../TagFileTransformerBuilder.java | 118 ++-- .../UserFileTransformerBuilder.java | 151 +++-- .../service/deposit/DepositClientImpl.java | 4 +- .../service/deposit/DepositServiceImpl.java | 20 +- .../BaseFieldDataHelperService.java | 17 +- .../FieldDataHelperService.java | 4 + .../FieldDataHelperServiceProvider.java | 2 +- ...AndMultiplicityFieldDataHelperService.java | 24 +- .../LabelFieldDataHelperService.java | 22 +- .../RadioBoxFieldDataHelperService.java | 22 +- .../ReferenceTypeFieldDataHelperService.java | 19 +- .../SelectFieldDataHelperService.java | 22 +- .../UploadFieldDataHelperService.java | 24 +- .../transformer/FileTransformerService.java | 14 +- dmp-backend/web/pom.xml | 2 +- 65 files changed, 3477 insertions(+), 2067 deletions(-) rename dmp-backend/core/src/main/java/eu/eudat/model/builder/{deposit/BaseDepositBuilder.java => commonmodels/BaseCommonModelBuilder.java} (73%) rename dmp-backend/core/src/main/java/eu/eudat/model/builder/{deposit/DepositBuilderItemResponse.java => commonmodels/CommonModelBuilderItemResponse.java} (58%) rename dmp-backend/core/src/main/java/eu/eudat/model/builder/{deposit => commonmodels}/DepositConfigurationBuilder.java (89%) rename dmp-backend/core/src/main/java/eu/eudat/model/builder/{deposit/DmpDepositBuilder.java => commonmodels/DmpCommonModelBuilder.java} (65%) rename dmp-backend/core/src/main/java/eu/eudat/model/builder/{deposit/DmpUserDepositBuilder.java => commonmodels/DmpUserCommonModelBuilder.java} (64%) create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/ReferenceTypeCommonModelBuilder.java rename dmp-backend/core/src/main/java/eu/eudat/model/builder/{deposit/UserDepositBuilder.java => commonmodels/UserCommonModelBuilder.java} (63%) create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/description/DescriptionCommonModelBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/description/ExternalIdentifierCommonModelBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/description/FieldCommonModelBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/description/PropertyDefinitionCommonModelBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/description/PropertyDefinitionFieldSetCommonModelBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/description/PropertyDefinitionFieldSetItemModelCommonModelBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/DefinitionCommonModelBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/DescriptionTemplateCommonModelBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/FieldCommonModelBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/FieldSetCommonModelBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/MultiplicityCommonModelBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/PageCommonModelBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/RuleCommonModelBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/SectionCommonModelBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/BaseFieldDataCommonModelBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/LabelAndMultiplicityDataCommonModelBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/LabelDataCommonModelBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/RadioBoxDataCommonModelBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/ReferenceTypeDataCommonModelBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/SelectDataCommonModelBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/UploadDataCommonModelBuilder.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/reference/ReferenceCommonModelBuilder.java rename dmp-backend/core/src/main/java/eu/eudat/model/builder/{deposit/ReferenceDefinitionDepositBuilder.java => commonmodels/reference/ReferenceDefinitionCommonModelBuilder.java} (55%) rename dmp-backend/core/src/main/java/eu/eudat/model/builder/{deposit/ReferenceFieldDepositBuilder.java => commonmodels/reference/ReferenceFieldCommonModelBuilder.java} (58%) delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DescriptionDepositBuilder.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DescriptionFieldDepositBuilder.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/ReferenceDepositBuilder.java diff --git a/dmp-backend/core/pom.xml b/dmp-backend/core/pom.xml index 0b53b9d90..2f10987ea 100644 --- a/dmp-backend/core/pom.xml +++ b/dmp-backend/core/pom.xml @@ -45,7 +45,12 @@ gr.cite.opendmp repositorydepositbase - 2.0.0 + 2.0.1 + + + gr.cite.opendmp + common-models + 0.0.1 gr.cite.opendmp diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/BaseDepositBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/BaseCommonModelBuilder.java similarity index 73% rename from dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/BaseDepositBuilder.java rename to dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/BaseCommonModelBuilder.java index a45c1c847..c5be1eae2 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/BaseDepositBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/BaseCommonModelBuilder.java @@ -1,21 +1,20 @@ -package eu.eudat.model.builder.deposit; +package eu.eudat.model.builder.commonmodels; import eu.eudat.convention.ConventionService; import gr.cite.tools.data.builder.Builder; import gr.cite.tools.data.query.QueryBase; import gr.cite.tools.exception.MyApplicationException; -import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.logging.LoggerService; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; -public abstract class BaseDepositBuilder implements Builder { +public abstract class BaseCommonModelBuilder implements Builder { protected final LoggerService logger; protected final ConventionService conventionService; - public BaseDepositBuilder( + public BaseCommonModelBuilder( ConventionService conventionService, LoggerService logger ) { @@ -30,16 +29,16 @@ public abstract class BaseDepositBuilder implements Builder { M model = null; return null; //TODO } - List> models = this.buildInternal(List.of(data)); - return models.stream().map(DepositBuilderItemResponse::getModel).findFirst().orElse(null); //TODO + List> models = this.buildInternal(List.of(data)); + return models.stream().map(CommonModelBuilderItemResponse::getModel).findFirst().orElse(null); //TODO } public List build(List data) throws MyApplicationException{ - List> models = this.buildInternal(data); - return models == null ? null : models.stream().map(DepositBuilderItemResponse::getModel).collect(Collectors.toList()); + List> models = this.buildInternal(data); + return models == null ? null : models.stream().map(CommonModelBuilderItemResponse::getModel).collect(Collectors.toList()); } - protected abstract List> buildInternal(List data) throws MyApplicationException; + protected abstract List> buildInternal(List data) throws MyApplicationException; public Map asForeignKey(QueryBase query, Function keySelector) throws MyApplicationException { this.logger.trace("Building references from query"); @@ -50,9 +49,9 @@ public abstract class BaseDepositBuilder implements Builder { public Map asForeignKey(List data, Function keySelector) throws MyApplicationException { this.logger.trace("building references"); - List> models = this.buildInternal(data); + List> models = this.buildInternal(data); this.logger.debug("mapping {} build items from {} requested", Optional.ofNullable(models).map(List::size).orElse(0), Optional.ofNullable(data).map(List::size).orElse(0)); - return models == null ? new HashMap<>() : models.stream().collect(Collectors.toMap(x-> keySelector.apply(x.getData()), DepositBuilderItemResponse::getModel)); + return models == null ? new HashMap<>() : models.stream().collect(Collectors.toMap(x-> keySelector.apply(x.getData()), CommonModelBuilderItemResponse::getModel)); } public Map> asMasterKey(QueryBase query,Function keySelector) throws MyApplicationException { this.logger.trace("Building details from query"); @@ -63,11 +62,11 @@ public abstract class BaseDepositBuilder implements Builder { public Map> asMasterKey(List data, Function keySelector) throws MyApplicationException { this.logger.trace("building details"); - List> models = this.buildInternal(data); + List> models = this.buildInternal(data); this.logger.debug("mapping {} build items from {} requested", Optional.ofNullable(models).map(List::size).orElse(0), Optional.ofNullable(data).map(List::size).orElse(0)); Map> map = new HashMap<>(); if (models == null) return map; - for (DepositBuilderItemResponse model : models) { + for (CommonModelBuilderItemResponse model : models) { K key = keySelector.apply(model.getData()); if (!map.containsKey(key)) map.put(key, new ArrayList()); map.get(key).add(model.getModel()); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DepositBuilderItemResponse.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/CommonModelBuilderItemResponse.java similarity index 58% rename from dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DepositBuilderItemResponse.java rename to dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/CommonModelBuilderItemResponse.java index d2a45511e..64bcf6107 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DepositBuilderItemResponse.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/CommonModelBuilderItemResponse.java @@ -1,10 +1,10 @@ -package eu.eudat.model.builder.deposit; +package eu.eudat.model.builder.commonmodels; -public class DepositBuilderItemResponse{ +public class CommonModelBuilderItemResponse{ private final M model; private final D data; - public DepositBuilderItemResponse(M model, D data) { + public CommonModelBuilderItemResponse(M model, D data) { this.model = model; this.data = data; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DepositConfigurationBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/DepositConfigurationBuilder.java similarity index 89% rename from dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DepositConfigurationBuilder.java rename to dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/DepositConfigurationBuilder.java index b6014685a..886caae51 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DepositConfigurationBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/DepositConfigurationBuilder.java @@ -1,18 +1,10 @@ -package eu.eudat.model.builder.deposit; +package eu.eudat.model.builder.commonmodels; import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.convention.ConventionService; -import eu.eudat.data.TagEntity; -import eu.eudat.model.Tag; -import eu.eudat.model.User; import eu.eudat.model.builder.BaseBuilder; -import eu.eudat.model.builder.UserBuilder; import eu.eudat.model.deposit.DepositConfiguration; -import eu.eudat.query.UserQuery; -import gr.cite.tools.data.builder.BuilderFactory; -import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.exception.MyApplicationException; -import gr.cite.tools.fieldset.BaseFieldSet; import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.logging.DataLogEntry; import gr.cite.tools.logging.LoggerService; @@ -23,7 +15,6 @@ import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; import java.util.*; -import java.util.stream.Collectors; @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DmpDepositBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/DmpCommonModelBuilder.java similarity index 65% rename from dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DmpDepositBuilder.java rename to dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/DmpCommonModelBuilder.java index bc93e21a6..50bca1e72 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DmpDepositBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/DmpCommonModelBuilder.java @@ -1,12 +1,18 @@ -package eu.eudat.model.builder.deposit; +package eu.eudat.model.builder.commonmodels; import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.enums.DmpAccessType; +import eu.eudat.commonmodels.models.DmpModel; +import eu.eudat.commonmodels.models.DmpUserModel; +import eu.eudat.commonmodels.models.FileEnvelopeModel; +import eu.eudat.commonmodels.models.description.DescriptionModel; +import eu.eudat.commonmodels.models.reference.ReferenceModel; import eu.eudat.commons.enums.IsActive; import eu.eudat.convention.ConventionService; import eu.eudat.data.*; -import eu.eudat.depositinterface.enums.DmpAccessType; -import eu.eudat.depositinterface.models.*; import eu.eudat.model.*; +import eu.eudat.model.builder.commonmodels.description.DescriptionCommonModelBuilder; +import eu.eudat.model.builder.commonmodels.reference.ReferenceCommonModelBuilder; import eu.eudat.query.*; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.query.Ordering; @@ -25,66 +31,66 @@ import java.util.stream.Collectors; @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class DmpDepositBuilder extends BaseDepositBuilder { +public class DmpCommonModelBuilder extends BaseCommonModelBuilder { private final QueryFactory queryFactory; private final BuilderFactory builderFactory; - private FileEnvelope pdfFile; - private FileEnvelope rdaJsonFile; - private FileEnvelope supportingFilesZip; + private FileEnvelopeModel pdfFile; + private FileEnvelopeModel rdaJsonFile; + private FileEnvelopeModel supportingFilesZip; private String repositoryId; private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); @Autowired - public DmpDepositBuilder(ConventionService conventionService, - QueryFactory queryFactory, - BuilderFactory builderFactory) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpDepositBuilder.class))); + public DmpCommonModelBuilder(ConventionService conventionService, + QueryFactory queryFactory, + BuilderFactory builderFactory) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpCommonModelBuilder.class))); this.queryFactory = queryFactory; this.builderFactory = builderFactory; } - public DmpDepositBuilder authorize(EnumSet values) { + public DmpCommonModelBuilder authorize(EnumSet values) { this.authorize = values; return this; } - public DmpDepositBuilder setPdfFile(FileEnvelope pdfFile) { + public DmpCommonModelBuilder setPdfFile(FileEnvelopeModel pdfFile) { this.pdfFile = pdfFile; return this; } - public DmpDepositBuilder setRdaJsonFile(FileEnvelope rdaJsonFile) { + public DmpCommonModelBuilder setRdaJsonFile(FileEnvelopeModel rdaJsonFile) { this.rdaJsonFile = rdaJsonFile; return this; } - public DmpDepositBuilder setSupportingFilesZip(FileEnvelope supportingFilesZip) { + public DmpCommonModelBuilder setSupportingFilesZip(FileEnvelopeModel supportingFilesZip) { this.supportingFilesZip = supportingFilesZip; return this; } - public DmpDepositBuilder setRepositoryId(String repositoryId) { + public DmpCommonModelBuilder setRepositoryId(String repositoryId) { this.repositoryId = repositoryId; return this; } @Override - protected List> buildInternal(List data) throws MyApplicationException { + protected List> buildInternal(List 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> models = new ArrayList<>(); + List> models = new ArrayList<>(); - Map> dmpReferencesMap = this.collectReferences(data); + Map> dmpReferencesMap = this.collectReferences(data); - Map> dmpUsersMap = this.collectDmpUsers(data); + Map> dmpUsersMap = this.collectDmpUsers(data); - Map> descriptionsMap = this.collectDmpDescriptions(data); + Map> descriptionsMap = this.collectDmpDescriptions(data); for (DmpEntity d : data) { - DmpDepositModel m = new DmpDepositModel(); + DmpModel m = new DmpModel(); m.setId(d.getId()); m.setLabel(d.getLabel()); m.setVersion(d.getVersion()); @@ -104,7 +110,7 @@ public class DmpDepositBuilder extends BaseDepositBuilder(m, d)); + models.add(new CommonModelBuilderItemResponse<>(m, d)); } this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); @@ -128,18 +134,18 @@ public class DmpDepositBuilder extends BaseDepositBuilder> collectReferences(List data) throws MyApplicationException { + private Map> collectReferences(List data) throws MyApplicationException { if (data.isEmpty()) return null; this.logger.debug("checking related - {}", DmpReference.class.getSimpleName()); List dmpReferences = this.queryFactory.query(DmpReferenceQuery.class).isActives(IsActive.Active).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList())).collectAs(new BaseFieldSet().ensure(DmpReference._dmp).ensure(DmpReference._reference)); - Map> itemMap = new HashMap<>(); + Map> itemMap = new HashMap<>(); ReferenceQuery query = this.queryFactory.query(ReferenceQuery.class).authorize(this.authorize).isActive(IsActive.Active).ids(dmpReferences.stream().map(DmpReferenceEntity::getReferenceId).distinct().collect(Collectors.toList())); - Map referenceDepositModelMap = this.builderFactory.builder(ReferenceDepositBuilder.class).authorize(this.authorize).asForeignKey(query, ReferenceEntity::getId); - if (referenceDepositModelMap == null) return null; + Map referenceModelMap = this.builderFactory.builder(ReferenceCommonModelBuilder.class).authorize(this.authorize).asForeignKey(query, ReferenceEntity::getId); + if (referenceModelMap == null) return null; for (DmpReferenceEntity dmpReference : dmpReferences) { - ReferenceDepositModel model =referenceDepositModelMap.getOrDefault(dmpReference.getReferenceId(), null); + ReferenceModel model =referenceModelMap.getOrDefault(dmpReference.getReferenceId(), null); if (model == null) continue;; UUID key = dmpReference.getDmpId(); if (!itemMap.containsKey(key)) itemMap.put(key, new ArrayList<>()); @@ -149,23 +155,23 @@ public class DmpDepositBuilder extends BaseDepositBuilder> collectDmpUsers(List data) throws MyApplicationException { + private Map> collectDmpUsers(List data) throws MyApplicationException { this.logger.debug("checking related - {}", DmpUser.class.getSimpleName()); - Map> itemMap; + Map> itemMap; DmpUserQuery query = this.queryFactory.query(DmpUserQuery.class).isActives(IsActive.Active).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList())); - itemMap = this.builderFactory.builder(DmpUserDepositBuilder.class).authorize(this.authorize).asMasterKey(query, DmpUserEntity::getDmpId); + itemMap = this.builderFactory.builder(DmpUserCommonModelBuilder.class).authorize(this.authorize).asMasterKey(query, DmpUserEntity::getDmpId); return itemMap; } - private Map> collectDmpDescriptions(List data) throws MyApplicationException { + private Map> collectDmpDescriptions(List data) throws MyApplicationException { if (data.isEmpty()) return null; this.logger.debug("checking related - {}", Description.class.getSimpleName()); - Map> itemMap; + Map> itemMap; DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).isActive(IsActive.Active).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList())); - itemMap = this.builderFactory.builder(DescriptionDepositBuilder.class).authorize(this.authorize).asMasterKey(query, DescriptionEntity::getDmpId); + itemMap = this.builderFactory.builder(DescriptionCommonModelBuilder.class).authorize(this.authorize).asMasterKey(query, DescriptionEntity::getDmpId); return itemMap; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DmpUserDepositBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/DmpUserCommonModelBuilder.java similarity index 64% rename from dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DmpUserDepositBuilder.java rename to dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/DmpUserCommonModelBuilder.java index 8fb81b47e..385757c3c 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DmpUserDepositBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/DmpUserCommonModelBuilder.java @@ -1,13 +1,13 @@ -package eu.eudat.model.builder.deposit; +package eu.eudat.model.builder.commonmodels; import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.enums.DmpUserRole; +import eu.eudat.commonmodels.models.DmpUserModel; +import eu.eudat.commonmodels.models.UserModel; import eu.eudat.commons.enums.IsActive; import eu.eudat.convention.ConventionService; import eu.eudat.data.DmpUserEntity; import eu.eudat.data.UserEntity; -import eu.eudat.depositinterface.enums.DmpUserRole; -import eu.eudat.depositinterface.models.DmpUserDepositModel; -import eu.eudat.depositinterface.models.UserDepositModel; import eu.eudat.query.UserQuery; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.query.QueryFactory; @@ -24,7 +24,7 @@ import java.util.stream.Collectors; @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class DmpUserDepositBuilder extends BaseDepositBuilder { +public class DmpUserCommonModelBuilder extends BaseCommonModelBuilder { private final BuilderFactory builderFactory; @@ -33,51 +33,51 @@ public class DmpUserDepositBuilder extends BaseDepositBuilder authorize = EnumSet.of(AuthorizationFlags.None); @Autowired - public DmpUserDepositBuilder( + public DmpUserCommonModelBuilder( ConventionService conventionService, BuilderFactory builderFactory, QueryFactory queryFactory) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpUserDepositBuilder.class))); + super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpUserCommonModelBuilder.class))); this.builderFactory = builderFactory; this.queryFactory = queryFactory; } - public DmpUserDepositBuilder authorize(EnumSet values) { + public DmpUserCommonModelBuilder authorize(EnumSet values) { this.authorize = values; return this; } @Override - protected List> buildInternal(List data) throws MyApplicationException { + protected List> buildInternal(List data) throws MyApplicationException { this.logger.debug("building for {} items ", Optional.ofNullable(data).map(List::size).orElse(0)); if (data == null) return new ArrayList<>(); - Map userItemsMap = this.collectUsers(data); + Map userItemsMap = this.collectUsers(data); - List> models = new ArrayList<>(); + List> models = new ArrayList<>(); for (DmpUserEntity d : data) { - DmpUserDepositModel m = new DmpUserDepositModel(); + DmpUserModel m = new DmpUserModel(); switch (d.getRole()){ case User -> m.setRole(DmpUserRole.User); case Owner -> m.setRole(DmpUserRole.Owner); default -> throw new MyApplicationException("unrecognized type " + d.getRole().getValue()); } if (userItemsMap != null && userItemsMap.containsKey(d.getUserId())) m.setUser(userItemsMap.get(d.getUserId())); - models.add(new DepositBuilderItemResponse<>(m, d)); + models.add(new CommonModelBuilderItemResponse<>(m, d)); } this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); return models; } - private Map collectUsers(List data) throws MyApplicationException { + private Map collectUsers(List data) throws MyApplicationException { if (data.isEmpty()) return null; - this.logger.debug("checking related - {}", UserDepositModel.class.getSimpleName()); + this.logger.debug("checking related - {}", UserModel.class.getSimpleName()); - Map itemMap; + Map itemMap; UserQuery q = this.queryFactory.query(UserQuery.class).isActive(IsActive.Active).authorize(this.authorize).ids(data.stream().map(DmpUserEntity::getUserId).distinct().collect(Collectors.toList())); - itemMap = this.builderFactory.builder(UserDepositBuilder.class).authorize(this.authorize).asForeignKey(q, UserEntity::getId); + itemMap = this.builderFactory.builder(UserCommonModelBuilder.class).authorize(this.authorize).asForeignKey(q, UserEntity::getId); return itemMap; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/ReferenceTypeCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/ReferenceTypeCommonModelBuilder.java new file mode 100644 index 000000000..b25dbe49b --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/ReferenceTypeCommonModelBuilder.java @@ -0,0 +1,53 @@ +package eu.eudat.model.builder.commonmodels; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.reference.ReferenceTypeModel; +import eu.eudat.convention.ConventionService; +import eu.eudat.data.ReferenceTypeEntity; +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 ReferenceTypeCommonModelBuilder extends BaseCommonModelBuilder { + + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public ReferenceTypeCommonModelBuilder( + ConventionService conventionService) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceTypeCommonModelBuilder.class))); + } + + public ReferenceTypeCommonModelBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + protected List> buildInternal(List 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> models = new ArrayList<>(); + for (ReferenceTypeEntity d : data) { + ReferenceTypeModel m = new ReferenceTypeModel(); + m.setId(d.getId()); + m.setCode(d.getCode()); + 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; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/UserDepositBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/UserCommonModelBuilder.java similarity index 63% rename from dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/UserDepositBuilder.java rename to dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/UserCommonModelBuilder.java index 318020187..8ffcba7d8 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/UserDepositBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/UserCommonModelBuilder.java @@ -1,9 +1,9 @@ -package eu.eudat.model.builder.deposit; +package eu.eudat.model.builder.commonmodels; import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.UserModel; import eu.eudat.convention.ConventionService; import eu.eudat.data.UserEntity; -import eu.eudat.depositinterface.models.UserDepositModel; import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.logging.LoggerService; import org.slf4j.LoggerFactory; @@ -19,32 +19,32 @@ import java.util.Optional; @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class UserDepositBuilder extends BaseDepositBuilder { +public class UserCommonModelBuilder extends BaseCommonModelBuilder { private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); @Autowired - public UserDepositBuilder(ConventionService conventionService) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(UserDepositBuilder.class))); + public UserCommonModelBuilder(ConventionService conventionService) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(UserCommonModelBuilder.class))); } - public UserDepositBuilder authorize(EnumSet values) { + public UserCommonModelBuilder authorize(EnumSet values) { this.authorize = values; return this; } @Override - protected List> buildInternal(List data) throws MyApplicationException { + protected List> buildInternal(List data) throws MyApplicationException { this.logger.debug("building for {} items ", Optional.ofNullable(data).map(List::size).orElse(0)); if (data == null) return new ArrayList<>(); - List> models = new ArrayList<>(); + List> models = new ArrayList<>(); for (UserEntity d : data) { - UserDepositModel m = new UserDepositModel(); + UserModel m = new UserModel(); m.setName(d.getName()); - models.add(new DepositBuilderItemResponse<>(m, d)); + models.add(new CommonModelBuilderItemResponse<>(m, d)); } this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/description/DescriptionCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/description/DescriptionCommonModelBuilder.java new file mode 100644 index 000000000..76c54d36f --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/description/DescriptionCommonModelBuilder.java @@ -0,0 +1,117 @@ +package eu.eudat.model.builder.commonmodels.description; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.description.DescriptionModel; +import eu.eudat.commonmodels.models.descriptiotemplate.DescriptionTemplateModel; +import eu.eudat.commons.JsonHandlingService; +import eu.eudat.commons.XmlHandlingService; +import eu.eudat.commons.types.description.PropertyDefinitionEntity; +import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.data.DescriptionEntity; +import eu.eudat.data.DescriptionTemplateEntity; +import eu.eudat.model.DescriptionTemplate; +import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder; +import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse; +import eu.eudat.model.builder.commonmodels.descriptiontemplate.DescriptionTemplateCommonModelBuilder; +import eu.eudat.query.*; +import gr.cite.tools.data.builder.BuilderFactory; +import gr.cite.tools.data.query.QueryFactory; +import gr.cite.tools.exception.MyApplicationException; +import gr.cite.tools.fieldset.BaseFieldSet; +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.*; +import java.util.stream.Collectors; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class DescriptionCommonModelBuilder extends BaseCommonModelBuilder { + + private final QueryFactory queryFactory; + + private final BuilderFactory builderFactory; + private final JsonHandlingService jsonHandlingService; + private final XmlHandlingService xmlHandlingService; + + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public DescriptionCommonModelBuilder( + ConventionService conventionService, + QueryFactory queryFactory, + BuilderFactory builderFactory, JsonHandlingService jsonHandlingService, XmlHandlingService xmlHandlingService) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionCommonModelBuilder.class))); + this.queryFactory = queryFactory; + this.builderFactory = builderFactory; + this.jsonHandlingService = jsonHandlingService; + this.xmlHandlingService = xmlHandlingService; + } + + public DescriptionCommonModelBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + protected List> buildInternal(List data) throws MyApplicationException { + this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0)); + if (data == null || data.isEmpty()) return new ArrayList<>(); + + Map descriptionTemplates = this.collectDescriptionTemplates(data); + + Map definitionEntityMap = this.collectDescriptionTemplateDefinitions(data); + + List> models = new ArrayList<>(); + for (DescriptionEntity d : data) { + DescriptionModel m = new DescriptionModel(); + m.setLabel(d.getLabel()); + m.setDescription(d.getDescription()); + if (descriptionTemplates != null && d.getDescriptionTemplateId() != null && descriptionTemplates.containsKey(d.getDescriptionTemplateId())) m.setDescriptionTemplate(descriptionTemplates.get(d.getDescriptionTemplateId())); + if (d.getProperties() != null){ + //TODO Update with the new logic of property definition + PropertyDefinitionEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(PropertyDefinitionEntity.class, d.getProperties()); + m.setProperties(this.builderFactory.builder(PropertyDefinitionCommonModelBuilder.class).withDefinition(definitionEntityMap != null ? definitionEntityMap.getOrDefault(d.getDescriptionTemplateId(), null) : null).authorize(this.authorize).build(propertyDefinition)); + } + models.add(new CommonModelBuilderItemResponse<>(m, d)); + } + + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + + return models; + } + + private Map collectDescriptionTemplateDefinitions(List data) throws MyApplicationException { + if (data.isEmpty()) + return null; + this.logger.debug("checking related - {}", DefinitionEntity.class.getSimpleName()); + + Map itemMap = new HashMap<>(); + DescriptionTemplateQuery q = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(this.authorize).ids(data.stream().map(DescriptionEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList())); + List items = q.collectAs(new BaseFieldSet().ensure(eu.eudat.model.DescriptionTemplate._id).ensure(DescriptionTemplate._definition)); + for (DescriptionTemplateEntity item : items){ + DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(DefinitionEntity.class, item.getDefinition()); + itemMap.put(item.getId(), definition); + } + + return itemMap; + } + + private Map collectDescriptionTemplates(List data) throws MyApplicationException { + if (data.isEmpty()) + return null; + this.logger.debug("checking related - {}", DescriptionTemplateModel.class.getSimpleName()); + + Map itemMap; + DescriptionTemplateQuery q = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(this.authorize).ids(data.stream().map(DescriptionEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList())); + itemMap = this.builderFactory.builder(DescriptionTemplateCommonModelBuilder.class).authorize(this.authorize).asForeignKey(q, DescriptionTemplateEntity::getId); + + return itemMap; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/description/ExternalIdentifierCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/description/ExternalIdentifierCommonModelBuilder.java new file mode 100644 index 000000000..2ace1f64e --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/description/ExternalIdentifierCommonModelBuilder.java @@ -0,0 +1,56 @@ +package eu.eudat.model.builder.commonmodels.description; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.description.ExternalIdentifierModel; +import eu.eudat.commons.types.description.ExternalIdentifierEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder; +import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse; +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 ExternalIdentifierCommonModelBuilder extends BaseCommonModelBuilder { + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + @Autowired + public ExternalIdentifierCommonModelBuilder( + ConventionService conventionService + ) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(ExternalIdentifierCommonModelBuilder.class))); + } + + public ExternalIdentifierCommonModelBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + + @Override + protected List> buildInternal(List 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> models = new ArrayList<>(); + for (ExternalIdentifierEntity d : data) { + ExternalIdentifierModel m = new ExternalIdentifierModel(); + m.setIdentifier(d.getIdentifier()); + m.setType(d.getType()); + models.add(new CommonModelBuilderItemResponse<>(m, d)); + } + + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + + return models; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/description/FieldCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/description/FieldCommonModelBuilder.java new file mode 100644 index 000000000..15c6828d4 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/description/FieldCommonModelBuilder.java @@ -0,0 +1,97 @@ +package eu.eudat.model.builder.commonmodels.description; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.description.FieldModel; +import eu.eudat.commonmodels.models.reference.ReferenceModel; +import eu.eudat.commons.enums.FieldType; +import eu.eudat.commons.types.description.FieldEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.data.ReferenceEntity; +import eu.eudat.model.Reference; +import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder; +import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse; +import eu.eudat.model.builder.commonmodels.reference.ReferenceCommonModelBuilder; +import eu.eudat.query.ReferenceQuery; +import gr.cite.tools.data.builder.BuilderFactory; +import gr.cite.tools.data.query.QueryFactory; +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.*; +import java.util.stream.Collectors; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class FieldCommonModelBuilder extends BaseCommonModelBuilder { + private final BuilderFactory builderFactory; + private final QueryFactory queryFactory; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + private eu.eudat.commons.types.descriptiontemplate.FieldEntity fieldEntity; + @Autowired + public FieldCommonModelBuilder( + ConventionService conventionService, BuilderFactory builderFactory, QueryFactory queryFactory + ) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(FieldCommonModelBuilder.class))); + this.builderFactory = builderFactory; + this.queryFactory = queryFactory; + } + + public FieldCommonModelBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + public FieldCommonModelBuilder withFieldEntity(eu.eudat.commons.types.descriptiontemplate.FieldEntity fieldEntity) { + this.fieldEntity = fieldEntity; + return this; + } + @Override + protected List> buildInternal(List data) throws MyApplicationException { + this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0)); + if (data == null || data.isEmpty()) return new ArrayList<>(); + + FieldType fieldType = this.fieldEntity != null && this.fieldEntity.getData() != null ? this.fieldEntity.getData().getFieldType() : FieldType.FREE_TEXT; + + Map referenceItemsMap = FieldType.isReferenceType(fieldType) ? this.collectReferences(data) : null; + + List> models = new ArrayList<>(); + for (FieldEntity d : data) { + FieldModel m = new FieldModel(); + if (FieldType.isDateType(fieldType)) m.setDateValue(d.getDateValue()); + if (FieldType.isTextType(fieldType)) m.setTextValue(d.getTextValue()); + if (FieldType.isTextListType(fieldType)) m.setTextListValue(d.getTextListValue()); + if (FieldType.isReferenceType(fieldType) && referenceItemsMap != null && d.getTextListValue() != null && !d.getTextListValue().isEmpty()) { + m.setReferences(new ArrayList<>()); + for (UUID referenceId : d.getTextListValue().stream().map(UUID::fromString).toList()){ + if (referenceItemsMap.containsKey(referenceId)) m.getReferences().add(referenceItemsMap.get(referenceId)); + } + } + if (d.getExternalIdentifier() != null && FieldType.isExternalIdentifierType(fieldType)) m.setExternalIdentifier(this.builderFactory.builder(ExternalIdentifierCommonModelBuilder.class).authorize(this.authorize).build(d.getExternalIdentifier())); + + models.add(new CommonModelBuilderItemResponse<>(m, d)); + } + + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + + return models; + } + + private Map collectReferences(List data) throws MyApplicationException { + if (data.isEmpty()) + return null; + this.logger.debug("checking related - {}", Reference.class.getSimpleName()); + + Map itemMap; + + ReferenceQuery q = this.queryFactory.query(ReferenceQuery.class).authorize(this.authorize).ids(data.stream().map(FieldEntity::getTextListValue).flatMap(List::stream).map(UUID::fromString).distinct().collect(Collectors.toList())); + itemMap = this.builderFactory.builder(ReferenceCommonModelBuilder.class).authorize(this.authorize).asForeignKey(q, ReferenceEntity::getId); + + return itemMap; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/description/PropertyDefinitionCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/description/PropertyDefinitionCommonModelBuilder.java new file mode 100644 index 000000000..c64f667b4 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/description/PropertyDefinitionCommonModelBuilder.java @@ -0,0 +1,65 @@ +package eu.eudat.model.builder.commonmodels.description; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.description.PropertyDefinitionModel; +import eu.eudat.commons.types.description.PropertyDefinitionEntity; +import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity; +import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder; +import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse; +import gr.cite.tools.data.builder.BuilderFactory; +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.*; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class PropertyDefinitionCommonModelBuilder extends BaseCommonModelBuilder { + private final BuilderFactory builderFactory; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + private DefinitionEntity definition; + @Autowired + public PropertyDefinitionCommonModelBuilder( + ConventionService conventionService, BuilderFactory builderFactory + ) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(PropertyDefinitionCommonModelBuilder.class))); + this.builderFactory = builderFactory; + } + + public PropertyDefinitionCommonModelBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + public PropertyDefinitionCommonModelBuilder withDefinition(DefinitionEntity definition) { + this.definition = definition; + return this; + } + @Override + protected List> buildInternal(List 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> models = new ArrayList<>(); + for (PropertyDefinitionEntity d : data) { + PropertyDefinitionModel m = new PropertyDefinitionModel(); + m.setFieldSets(new HashMap<>()); + for (String key : d.getFieldSets().keySet()){ + FieldSetEntity fieldSetEntity = definition != null ? definition.getFieldSetById(key).stream().findFirst().orElse(null) : null; + m.getFieldSets().put(key, this.builderFactory.builder(PropertyDefinitionFieldSetCommonModelBuilder.class).authorize(this.authorize).withFieldSetEntity(fieldSetEntity).build(d.getFieldSets().get(key))); + } + models.add(new CommonModelBuilderItemResponse<>(m, d)); + } + + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + + return models; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/description/PropertyDefinitionFieldSetCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/description/PropertyDefinitionFieldSetCommonModelBuilder.java new file mode 100644 index 000000000..179b51737 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/description/PropertyDefinitionFieldSetCommonModelBuilder.java @@ -0,0 +1,61 @@ +package eu.eudat.model.builder.commonmodels.description; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.description.PropertyDefinitionFieldSetModel; +import eu.eudat.commons.types.description.PropertyDefinitionFieldSetEntity; +import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder; +import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse; +import gr.cite.tools.data.builder.BuilderFactory; +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.*; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class PropertyDefinitionFieldSetCommonModelBuilder extends BaseCommonModelBuilder { + private final BuilderFactory builderFactory; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + private FieldSetEntity fieldSetEntity; + @Autowired + public PropertyDefinitionFieldSetCommonModelBuilder( + ConventionService conventionService, BuilderFactory builderFactory + ) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(PropertyDefinitionFieldSetCommonModelBuilder.class))); + this.builderFactory = builderFactory; + } + + public PropertyDefinitionFieldSetCommonModelBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + + public PropertyDefinitionFieldSetCommonModelBuilder withFieldSetEntity(FieldSetEntity fieldSetEntity) { + this.fieldSetEntity = fieldSetEntity; + return this; + } + @Override + protected List> buildInternal(List 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> models = new ArrayList<>(); + for (PropertyDefinitionFieldSetEntity d : data) { + PropertyDefinitionFieldSetModel m = new PropertyDefinitionFieldSetModel(); + if (d.getItems() != null) m.setItems(this.builderFactory.builder(PropertyDefinitionFieldSetItemModelCommonModelBuilder.class).withFieldSetEntity(this.fieldSetEntity).authorize(this.authorize).build(d.getItems())); + models.add(new CommonModelBuilderItemResponse<>(m, d)); + } + + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + + return models; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/description/PropertyDefinitionFieldSetItemModelCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/description/PropertyDefinitionFieldSetItemModelCommonModelBuilder.java new file mode 100644 index 000000000..c3b22e580 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/description/PropertyDefinitionFieldSetItemModelCommonModelBuilder.java @@ -0,0 +1,73 @@ +package eu.eudat.model.builder.commonmodels.description; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.description.PropertyDefinitionFieldSetItemModel; +import eu.eudat.commons.types.description.PropertyDefinitionFieldSetItemEntity; +import eu.eudat.commons.types.descriptiontemplate.FieldEntity; +import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder; +import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse; +import gr.cite.tools.data.builder.BuilderFactory; +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.*; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class PropertyDefinitionFieldSetItemModelCommonModelBuilder extends BaseCommonModelBuilder { + private final BuilderFactory builderFactory; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + private FieldSetEntity fieldSetEntity; + @Autowired + public PropertyDefinitionFieldSetItemModelCommonModelBuilder( + ConventionService conventionService, BuilderFactory builderFactory + ) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(PropertyDefinitionFieldSetItemModelCommonModelBuilder.class))); + this.builderFactory = builderFactory; + } + + public PropertyDefinitionFieldSetItemModelCommonModelBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + + public PropertyDefinitionFieldSetItemModelCommonModelBuilder withFieldSetEntity(FieldSetEntity fieldSetEntity) { + this.fieldSetEntity = fieldSetEntity; + return this; + } + + + @Override + protected List> buildInternal(List 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> models = new ArrayList<>(); + for (PropertyDefinitionFieldSetItemEntity d : data) { + PropertyDefinitionFieldSetItemModel m = new PropertyDefinitionFieldSetItemModel(); + + m.setComment(d.getComment()); + m.setOrdinal(d.getOrdinal()); + if (d.getFields() != null && !d.getFields().isEmpty()) { + m.setFields(new HashMap<>()); + for (String key : d.getFields().keySet()){ + FieldEntity fieldEntity = fieldSetEntity != null ? fieldSetEntity.getAllField().stream().findFirst().orElse(null) : null; + m.getFields().put(key, this.builderFactory.builder(FieldCommonModelBuilder.class).authorize(this.authorize).withFieldEntity(fieldEntity).build(d.getFields().get(key))); + } + } + models.add(new CommonModelBuilderItemResponse<>(m, d)); + } + + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + + return models; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/DefinitionCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/DefinitionCommonModelBuilder.java new file mode 100644 index 000000000..e50711e14 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/DefinitionCommonModelBuilder.java @@ -0,0 +1,59 @@ +package eu.eudat.model.builder.commonmodels.descriptiontemplate; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.descriptiotemplate.DefinitionModel; +import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder; +import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse; +import eu.eudat.model.builder.descriptiontemplatedefinition.PageBuilder; +import gr.cite.tools.data.builder.BuilderFactory; +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 DefinitionCommonModelBuilder extends BaseCommonModelBuilder { + private final BuilderFactory builderFactory; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + @Autowired + public DefinitionCommonModelBuilder( + ConventionService conventionService, BuilderFactory builderFactory + ) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(DefinitionCommonModelBuilder.class))); + this.builderFactory = builderFactory; + } + + public DefinitionCommonModelBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + protected List> buildInternal(List 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> models = new ArrayList<>(); + for (DefinitionEntity d : data) { + DefinitionModel m = new DefinitionModel(); + if (d.getPages() != null) m.setPages(this.builderFactory.builder(PageCommonModelBuilder.class).authorize(this.authorize).build(d.getPages())); + + models.add(new CommonModelBuilderItemResponse<>(m, d)); + } + + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + + return models; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/DescriptionTemplateCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/DescriptionTemplateCommonModelBuilder.java new file mode 100644 index 000000000..ae75db44f --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/DescriptionTemplateCommonModelBuilder.java @@ -0,0 +1,76 @@ +package eu.eudat.model.builder.commonmodels.descriptiontemplate; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.descriptiotemplate.DescriptionTemplateModel; +import eu.eudat.commons.JsonHandlingService; +import eu.eudat.commons.XmlHandlingService; +import eu.eudat.convention.ConventionService; +import eu.eudat.data.DescriptionTemplateEntity; +import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder; +import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse; +import gr.cite.tools.data.builder.BuilderFactory; +import gr.cite.tools.data.query.QueryFactory; +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.*; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class DescriptionTemplateCommonModelBuilder extends BaseCommonModelBuilder { + + private final QueryFactory queryFactory; + + private final BuilderFactory builderFactory; + private final JsonHandlingService jsonHandlingService; + + private final XmlHandlingService xmlHandlingService; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public DescriptionTemplateCommonModelBuilder( + ConventionService conventionService, + QueryFactory queryFactory, + BuilderFactory builderFactory, JsonHandlingService jsonHandlingService, XmlHandlingService xmlHandlingService) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionTemplateCommonModelBuilder.class))); + this.queryFactory = queryFactory; + this.builderFactory = builderFactory; + this.jsonHandlingService = jsonHandlingService; + this.xmlHandlingService = xmlHandlingService; + } + + public DescriptionTemplateCommonModelBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + protected List> buildInternal(List 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> models = new ArrayList<>(); + for (DescriptionTemplateEntity d : data) { + DescriptionTemplateModel m = new DescriptionTemplateModel(); + m.setId(d.getId()); + m.setLabel(d.getLabel()); + m.setDescription(d.getDescription()); + m.setGroupId(d.getGroupId()); + m.setVersion(d.getVersion()); + m.setLanguage(d.getLanguage()); + + + models.add(new CommonModelBuilderItemResponse<>(m, d)); + } + + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + + return models; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/FieldCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/FieldCommonModelBuilder.java new file mode 100644 index 000000000..71a778c85 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/FieldCommonModelBuilder.java @@ -0,0 +1,86 @@ +package eu.eudat.model.builder.commonmodels.descriptiontemplate; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.descriptiotemplate.FieldModel; +import eu.eudat.commons.enums.FieldValidationType; +import eu.eudat.commons.types.descriptiontemplate.FieldEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder; +import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse; +import eu.eudat.service.fielddatahelper.FieldDataHelperService; +import eu.eudat.service.fielddatahelper.FieldDataHelperServiceProvider; +import gr.cite.tools.data.builder.BuilderFactory; +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 FieldCommonModelBuilder extends BaseCommonModelBuilder { + private final BuilderFactory builderFactory; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + private final FieldDataHelperServiceProvider fieldDataHelperServiceProvider; + @Autowired + public FieldCommonModelBuilder( + ConventionService conventionService, BuilderFactory builderFactory, FieldDataHelperServiceProvider fieldDataHelperServiceProvider + ) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(FieldCommonModelBuilder.class))); + this.builderFactory = builderFactory; + this.fieldDataHelperServiceProvider = fieldDataHelperServiceProvider; + } + + public FieldCommonModelBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + protected List> buildInternal(List 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> models = new ArrayList<>(); + for (FieldEntity d : data) { + FieldModel m = new FieldModel(); + m.setId(d.getId()); + m.setOrdinal(d.getOrdinal()); + m.setNumbering(d.getNumbering()); + m.setSchematics(d.getSchematics()); + m.setDefaultValue(d.getDefaultValue()); + m.setIncludeInExport(d.getIncludeInExport()); + if (!this.conventionService.isListNullOrEmpty(d.getValidations())){ + m.setValidations(new ArrayList<>()); + for (FieldValidationType fieldValidationType : d.getValidations()) { + switch (fieldValidationType){ + case Url -> m.getValidations().add(eu.eudat.commonmodels.enums.FieldValidationType.Url); + case None -> m.getValidations().add(eu.eudat.commonmodels.enums.FieldValidationType.None); + case Required -> m.getValidations().add(eu.eudat.commonmodels.enums.FieldValidationType.Required); + default -> throw new MyApplicationException("unrecognized type " + fieldValidationType); + } + + } + } + m.setNumbering(d.getNumbering()); + m.setNumbering(d.getNumbering()); + if (d.getVisibilityRules() != null) m.setVisibilityRules(this.builderFactory.builder(RuleCommonModelBuilder.class).authorize(this.authorize).build(d.getVisibilityRules())); + if (d.getData() != null){ + FieldDataHelperService fieldDataHelperService = this.fieldDataHelperServiceProvider.get(d.getData().getFieldType()); + m.setData(fieldDataHelperService.buildCommonModelOne(d.getData(), this.authorize)); + } + models.add(new CommonModelBuilderItemResponse<>(m, d)); + } + + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + + return models; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/FieldSetCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/FieldSetCommonModelBuilder.java new file mode 100644 index 000000000..551c3aad2 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/FieldSetCommonModelBuilder.java @@ -0,0 +1,68 @@ +package eu.eudat.model.builder.commonmodels.descriptiontemplate; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.descriptiotemplate.FieldSetModel; +import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder; +import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse; +import eu.eudat.model.builder.descriptiontemplatedefinition.FieldBuilder; +import eu.eudat.model.builder.descriptiontemplatedefinition.MultiplicityBuilder; +import gr.cite.tools.data.builder.BuilderFactory; +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 FieldSetCommonModelBuilder extends BaseCommonModelBuilder { + private final BuilderFactory builderFactory; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + @Autowired + public FieldSetCommonModelBuilder( + ConventionService conventionService, BuilderFactory builderFactory + ) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(FieldSetCommonModelBuilder.class))); + this.builderFactory = builderFactory; + } + + public FieldSetCommonModelBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + protected List> buildInternal(List 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> models = new ArrayList<>(); + for (FieldSetEntity d : data) { + FieldSetModel m = new FieldSetModel(); + m.setId(d.getId()); + m.setOrdinal(d.getOrdinal()); + m.setTitle(d.getTitle()); + m.setNumbering(d.getNumbering()); + m.setDescription(d.getDescription()); + m.setExtendedDescription(d.getExtendedDescription()); + m.setAdditionalInformation(d.getAdditionalInformation()); + m.setHasCommentField(d.getHasCommentField()); + if (d.getMultiplicity() != null) m.setMultiplicity(this.builderFactory.builder(MultiplicityCommonModelBuilder.class).authorize(this.authorize).build(d.getMultiplicity())); + if (d.getFields() != null) m.setFields(this.builderFactory.builder(FieldCommonModelBuilder.class).authorize(this.authorize).build(d.getFields())); + models.add(new CommonModelBuilderItemResponse<>(m, d)); + } + + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + + return models; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/MultiplicityCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/MultiplicityCommonModelBuilder.java new file mode 100644 index 000000000..435bf43bb --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/MultiplicityCommonModelBuilder.java @@ -0,0 +1,61 @@ +package eu.eudat.model.builder.commonmodels.descriptiontemplate; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.descriptiotemplate.MultiplicityModel; +import eu.eudat.commons.types.descriptiontemplate.MultiplicityEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder; +import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse; +import eu.eudat.model.descriptiontemplatedefinition.Multiplicity; +import gr.cite.tools.data.builder.BuilderFactory; +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 MultiplicityCommonModelBuilder extends BaseCommonModelBuilder { + private final BuilderFactory builderFactory; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + @Autowired + public MultiplicityCommonModelBuilder( + ConventionService conventionService, BuilderFactory builderFactory + ) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(MultiplicityCommonModelBuilder.class))); + this.builderFactory = builderFactory; + } + + public MultiplicityCommonModelBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + protected List> buildInternal(List 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> models = new ArrayList<>(); + for (MultiplicityEntity d : data) { + MultiplicityModel m = new MultiplicityModel(); + m.setMin(d.getMin()); + m.setMax(d.getMax()); + m.setPlaceholder(d.getPlaceholder()); + m.setTableView(d.getTableView()); + models.add(new CommonModelBuilderItemResponse<>(m, d)); + } + + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + + return models; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/PageCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/PageCommonModelBuilder.java new file mode 100644 index 000000000..43f89cdb7 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/PageCommonModelBuilder.java @@ -0,0 +1,63 @@ +package eu.eudat.model.builder.commonmodels.descriptiontemplate; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.descriptiotemplate.PageModel; +import eu.eudat.commons.types.descriptiontemplate.PageEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder; +import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse; +import eu.eudat.model.builder.descriptiontemplatedefinition.SectionBuilder; +import eu.eudat.model.descriptiontemplatedefinition.Page; +import gr.cite.tools.data.builder.BuilderFactory; +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 PageCommonModelBuilder extends BaseCommonModelBuilder { + private final BuilderFactory builderFactory; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + @Autowired + public PageCommonModelBuilder( + ConventionService conventionService, BuilderFactory builderFactory + ) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(PageCommonModelBuilder.class))); + this.builderFactory = builderFactory; + } + + public PageCommonModelBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + protected List> buildInternal(List 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> models = new ArrayList<>(); + for (PageEntity d : data) { + PageModel m = new PageModel(); + m.setId(d.getId()); + m.setOrdinal(d.getOrdinal()); + m.setTitle(d.getTitle()); + m.setSections(this.builderFactory.builder(SectionCommonModelBuilder.class).authorize(this.authorize).build(d.getSections())); + + models.add(new CommonModelBuilderItemResponse<>(m, d)); + } + + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + + return models; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/RuleCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/RuleCommonModelBuilder.java new file mode 100644 index 000000000..aec73984c --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/RuleCommonModelBuilder.java @@ -0,0 +1,55 @@ +package eu.eudat.model.builder.commonmodels.descriptiontemplate; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.descriptiotemplate.RuleModel; +import eu.eudat.commons.types.descriptiontemplate.RuleEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder; +import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse; +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 RuleCommonModelBuilder extends BaseCommonModelBuilder { + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + @Autowired + public RuleCommonModelBuilder( + ConventionService conventionService + ) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(RuleCommonModelBuilder.class))); + } + + public RuleCommonModelBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + protected List> buildInternal(List 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> models = new ArrayList<>(); + for (RuleEntity d : data) { + RuleModel m = new RuleModel(); + m.setTarget(d.getTarget()); + m.setValue(d.getValue()); + models.add(new CommonModelBuilderItemResponse<>(m, d)); + } + + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + + return models; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/SectionCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/SectionCommonModelBuilder.java new file mode 100644 index 000000000..cc42614d7 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/SectionCommonModelBuilder.java @@ -0,0 +1,69 @@ +package eu.eudat.model.builder.commonmodels.descriptiontemplate; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.descriptiotemplate.SectionModel; +import eu.eudat.commons.types.descriptiontemplate.SectionEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder; +import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse; +import eu.eudat.model.builder.descriptiontemplatedefinition.FieldSetBuilder; +import eu.eudat.model.builder.descriptiontemplatedefinition.SectionBuilder; +import eu.eudat.model.descriptiontemplatedefinition.Section; +import gr.cite.tools.data.builder.BuilderFactory; +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 SectionCommonModelBuilder extends BaseCommonModelBuilder { + private final BuilderFactory builderFactory; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + @Autowired + public SectionCommonModelBuilder( + ConventionService conventionService, BuilderFactory builderFactory + ) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(SectionCommonModelBuilder.class))); + this.builderFactory = builderFactory; + } + + public SectionCommonModelBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + protected List> buildInternal(List 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> models = new ArrayList<>(); + for (SectionEntity d : data) { + SectionModel m = new SectionModel(); + m.setId(d.getId()); + m.setDescription(d.getDescription()); + m.setOrdinal(d.getOrdinal()); + m.setDefaultVisibility(d.isDefaultVisibility()); + m.setMultiplicity(d.getMultiplicity()); + m.setNumbering(d.getNumbering()); + m.setTitle(d.getTitle()); + m.setExtendedDescription(d.getExtendedDescription()); + if (d.getSections() != null) m.setSections(this.builderFactory.builder(SectionCommonModelBuilder.class).authorize(this.authorize).build(d.getSections())); + if (d.getFieldSets() != null) m.setFieldSets(this.builderFactory.builder(FieldSetCommonModelBuilder.class).authorize(this.authorize).build(d.getFieldSets())); + models.add(new CommonModelBuilderItemResponse<>(m, d)); + } + + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + + return models; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/BaseFieldDataCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/BaseFieldDataCommonModelBuilder.java new file mode 100644 index 000000000..fb89c66c7 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/BaseFieldDataCommonModelBuilder.java @@ -0,0 +1,79 @@ +package eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.enums.FieldType; +import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.BaseFieldDataModel; +import eu.eudat.commons.types.descriptiontemplate.fielddata.BaseFieldDataEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder; +import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse; +import gr.cite.tools.exception.MyApplicationException; +import gr.cite.tools.logging.LoggerService; +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 abstract class BaseFieldDataCommonModelBuilder extends BaseCommonModelBuilder { + protected EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + @Autowired + public BaseFieldDataCommonModelBuilder( + ConventionService conventionService, + LoggerService logger) { + super(conventionService, logger); + } + + public BaseFieldDataCommonModelBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + protected abstract Model getInstance(); + + protected abstract void buildChild(Entity d, Model m); + + + @Override + protected List> buildInternal(List 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> models = new ArrayList<>(); + for (Entity d : data) { + Model m = this.getInstance(); + m.setLabel(d.getLabel()); + switch (d.getFieldType()){ + case SELECT -> m.setFieldType(FieldType.SELECT); + case BOOLEAN_DECISION -> m.setFieldType(FieldType.BOOLEAN_DECISION); + case RADIO_BOX -> m.setFieldType(FieldType.RADIO_BOX); + case INTERNAL_ENTRIES_DMPS -> m.setFieldType(FieldType.INTERNAL_ENTRIES_DMPS); + case INTERNAL_ENTRIES_DESCRIPTIONS -> m.setFieldType(FieldType.INTERNAL_ENTRIES_DESCRIPTIONS); + case CHECK_BOX -> m.setFieldType(FieldType.CHECK_BOX); + case FREE_TEXT -> m.setFieldType(FieldType.FREE_TEXT); + case TEXT_AREA -> m.setFieldType(FieldType.TEXT_AREA); + case RICH_TEXT_AREA -> m.setFieldType(FieldType.RICH_TEXT_AREA); + case UPLOAD -> m.setFieldType(FieldType.UPLOAD); + case DATE_PICKER -> m.setFieldType(FieldType.DATE_PICKER); + case TAGS -> m.setFieldType(FieldType.TAGS); + case REFERENCE_TYPES -> m.setFieldType(FieldType.REFERENCE_TYPES); + case DATASET_IDENTIFIER -> m.setFieldType(FieldType.DATASET_IDENTIFIER); + case CURRENCY -> m.setFieldType(FieldType.CURRENCY); + case VALIDATION -> m.setFieldType(FieldType.VALIDATION); + default -> throw new MyApplicationException("unrecognized type " + d.getFieldType()); + } + this.buildChild(d, m); + models.add(new CommonModelBuilderItemResponse<>(m, d)); + } + + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + + return models; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/LabelAndMultiplicityDataCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/LabelAndMultiplicityDataCommonModelBuilder.java new file mode 100644 index 000000000..6660bf7f0 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/LabelAndMultiplicityDataCommonModelBuilder.java @@ -0,0 +1,31 @@ +package eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata; + +import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.LabelAndMultiplicityDataModel; +import eu.eudat.commons.types.descriptiontemplate.fielddata.LabelAndMultiplicityDataEntity; +import eu.eudat.convention.ConventionService; +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; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class LabelAndMultiplicityDataCommonModelBuilder extends BaseFieldDataCommonModelBuilder { + @Autowired + public LabelAndMultiplicityDataCommonModelBuilder( + ConventionService conventionService + ) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(LabelAndMultiplicityDataCommonModelBuilder.class))); + } + + protected LabelAndMultiplicityDataModel getInstance() { + return new LabelAndMultiplicityDataModel(); + } + + @Override + protected void buildChild(LabelAndMultiplicityDataEntity d, LabelAndMultiplicityDataModel m) { + m.setMultipleSelect(d.getMultipleSelect()); + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/LabelDataCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/LabelDataCommonModelBuilder.java new file mode 100644 index 000000000..15a47dab7 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/LabelDataCommonModelBuilder.java @@ -0,0 +1,31 @@ +package eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata; + +import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.LabelDataModel; +import eu.eudat.commons.types.descriptiontemplate.fielddata.LabelDataEntity; +import eu.eudat.convention.ConventionService; +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; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class LabelDataCommonModelBuilder extends BaseFieldDataCommonModelBuilder { + @Autowired + public LabelDataCommonModelBuilder( + ConventionService conventionService + ) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(LabelDataCommonModelBuilder.class))); + } + + protected LabelDataModel getInstance() { + return new LabelDataModel(); + } + + @Override + protected void buildChild(LabelDataEntity d, LabelDataModel m) { + + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/RadioBoxDataCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/RadioBoxDataCommonModelBuilder.java new file mode 100644 index 000000000..f1da3fd12 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/RadioBoxDataCommonModelBuilder.java @@ -0,0 +1,80 @@ +package eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.RadioBoxDataModel; +import eu.eudat.commons.types.descriptiontemplate.fielddata.RadioBoxDataEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder; +import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse; +import gr.cite.tools.data.builder.BuilderFactory; +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 RadioBoxDataCommonModelBuilder extends BaseFieldDataCommonModelBuilder { + private final BuilderFactory builderFactory; + @Autowired + public RadioBoxDataCommonModelBuilder( + ConventionService conventionService, BuilderFactory builderFactory + ) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(RadioBoxDataCommonModelBuilder.class))); + this.builderFactory = builderFactory; + } + + protected RadioBoxDataModel getInstance() { + return new RadioBoxDataModel(); + } + + @Override + protected void buildChild(RadioBoxDataEntity d, RadioBoxDataModel m) { + m.setOptions(this.builderFactory.builder(RadioBoxOptionCommonModelBuilder.class).authorize(this.authorize).build(d.getOptions())); + } + + @Component + @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class RadioBoxOptionCommonModelBuilder extends BaseCommonModelBuilder { + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + @Autowired + public RadioBoxOptionCommonModelBuilder( + ConventionService conventionService + ) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(RadioBoxOptionCommonModelBuilder.class))); + } + + public RadioBoxOptionCommonModelBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + + @Override + protected List> buildInternal(List 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> models = new ArrayList<>(); + for (RadioBoxDataEntity.RadioBoxDataOptionEntity d : data) { + RadioBoxDataModel.RadioBoxOptionModel m = new RadioBoxDataModel.RadioBoxOptionModel(); + m.setLabel(d.getLabel()); + m.setValue(d.getValue()); + models.add(new CommonModelBuilderItemResponse<>(m, d)); + } + + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + + return models; + } + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/ReferenceTypeDataCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/ReferenceTypeDataCommonModelBuilder.java new file mode 100644 index 000000000..a2e86e7d5 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/ReferenceTypeDataCommonModelBuilder.java @@ -0,0 +1,42 @@ +package eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata; + +import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.ReferenceTypeDataModel; +import eu.eudat.commons.types.descriptiontemplate.fielddata.ReferenceTypeDataEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.builder.ReferenceTypeBuilder; +import eu.eudat.model.builder.commonmodels.ReferenceTypeCommonModelBuilder; +import eu.eudat.query.ReferenceTypeQuery; +import gr.cite.tools.data.builder.BuilderFactory; +import gr.cite.tools.data.query.QueryFactory; +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; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class ReferenceTypeDataCommonModelBuilder extends BaseFieldDataCommonModelBuilder { + + private final QueryFactory queryFactory; + private final BuilderFactory builderFactory; + @Autowired + public ReferenceTypeDataCommonModelBuilder( + ConventionService conventionService, QueryFactory queryFactory, BuilderFactory builderFactory + ) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceTypeDataCommonModelBuilder.class))); + this.queryFactory = queryFactory; + this.builderFactory = builderFactory; + } + + protected ReferenceTypeDataModel getInstance() { + return new ReferenceTypeDataModel(); + } + + @Override + protected void buildChild(ReferenceTypeDataEntity d, ReferenceTypeDataModel m) { + if (d.getReferenceTypeId() != null) m.setReferenceType(this.builderFactory.builder(ReferenceTypeCommonModelBuilder.class).build(this.queryFactory.query(ReferenceTypeQuery.class).ids(d.getReferenceTypeId()).first())); //TODO: Optimize + + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/SelectDataCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/SelectDataCommonModelBuilder.java new file mode 100644 index 000000000..dfed396f9 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/SelectDataCommonModelBuilder.java @@ -0,0 +1,80 @@ +package eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.SelectDataModel; +import eu.eudat.commons.types.descriptiontemplate.fielddata.SelectDataEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder; +import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse; +import gr.cite.tools.data.builder.BuilderFactory; +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 SelectDataCommonModelBuilder extends BaseFieldDataCommonModelBuilder { + private final BuilderFactory builderFactory; + @Autowired + public SelectDataCommonModelBuilder( + ConventionService conventionService, BuilderFactory builderFactory + ) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(SelectDataCommonModelBuilder.class))); + this.builderFactory = builderFactory; + } + + protected SelectDataModel getInstance() { + return new SelectDataModel(); + } + + @Override + protected void buildChild(SelectDataEntity d, SelectDataModel m) { + m.setOptions(this.builderFactory.builder(SelectOptionCommonModelBuilder.class).authorize(this.authorize).build(d.getOptions())); + } + + @Component + @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class SelectOptionCommonModelBuilder extends BaseCommonModelBuilder { + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + @Autowired + public SelectOptionCommonModelBuilder( + ConventionService conventionService + ) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(SelectOptionCommonModelBuilder.class))); + } + + public SelectOptionCommonModelBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + + @Override + protected List> buildInternal(List 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> models = new ArrayList<>(); + for (SelectDataEntity.OptionEntity d : data) { + SelectDataModel.OptionModel m = new SelectDataModel.OptionModel(); + m.setLabel(d.getLabel()); + m.setValue(d.getValue()); + models.add(new CommonModelBuilderItemResponse<>(m, d)); + } + + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + + return models; + } + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/UploadDataCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/UploadDataCommonModelBuilder.java new file mode 100644 index 000000000..1a7674192 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/descriptiontemplate/fielddata/UploadDataCommonModelBuilder.java @@ -0,0 +1,80 @@ +package eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.UploadDataModel; +import eu.eudat.commons.types.descriptiontemplate.fielddata.UploadDataEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder; +import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse; +import gr.cite.tools.data.builder.BuilderFactory; +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 UploadDataCommonModelBuilder extends BaseFieldDataCommonModelBuilder { + private final BuilderFactory builderFactory; + @Autowired + public UploadDataCommonModelBuilder( + ConventionService conventionService, BuilderFactory builderFactory + ) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(UploadDataCommonModelBuilder.class))); + this.builderFactory = builderFactory; + } + + protected UploadDataModel getInstance() { + return new UploadDataModel(); + } + + @Override + protected void buildChild(UploadDataEntity d, UploadDataModel m) { + m.setTypes(this.builderFactory.builder(UploadOptionCommonModelBuilder.class).authorize(this.authorize).build(d.getTypes())); + } + + @Component + @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class UploadOptionCommonModelBuilder extends BaseCommonModelBuilder { + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + @Autowired + public UploadOptionCommonModelBuilder( + ConventionService conventionService + ) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(UploadOptionCommonModelBuilder.class))); + } + + public UploadOptionCommonModelBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + + @Override + protected List> buildInternal(List 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> models = new ArrayList<>(); + for (UploadDataEntity.UploadDataOptionEntity d : data) { + UploadDataModel.UploadOptionModel m = new UploadDataModel.UploadOptionModel(); + m.setLabel(d.getLabel()); + m.setValue(d.getValue()); + models.add(new CommonModelBuilderItemResponse<>(m, d)); + } + + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + + return models; + } + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/reference/ReferenceCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/reference/ReferenceCommonModelBuilder.java new file mode 100644 index 000000000..7e931e992 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/reference/ReferenceCommonModelBuilder.java @@ -0,0 +1,97 @@ +package eu.eudat.model.builder.commonmodels.reference; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.enums.ReferenceSourceType; +import eu.eudat.commonmodels.models.reference.ReferenceModel; +import eu.eudat.commonmodels.models.reference.ReferenceTypeModel; +import eu.eudat.commons.XmlHandlingService; +import eu.eudat.commons.types.reference.DefinitionEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.data.ReferenceTypeEntity; +import eu.eudat.data.ReferenceEntity; +import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder; +import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse; +import eu.eudat.model.builder.commonmodels.ReferenceTypeCommonModelBuilder; +import eu.eudat.query.ReferenceTypeQuery; +import gr.cite.tools.data.builder.BuilderFactory; +import gr.cite.tools.data.query.QueryFactory; +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.*; +import java.util.stream.Collectors; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class ReferenceCommonModelBuilder extends BaseCommonModelBuilder { + + private final BuilderFactory builderFactory; + private final QueryFactory queryFactory; + private final XmlHandlingService xmlHandlingService; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public ReferenceCommonModelBuilder( + ConventionService conventionService, + BuilderFactory builderFactory, QueryFactory queryFactory, XmlHandlingService xmlHandlingService) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceCommonModelBuilder.class))); + this.builderFactory = builderFactory; + this.queryFactory = queryFactory; + this.xmlHandlingService = xmlHandlingService; + } + + public ReferenceCommonModelBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + protected List> buildInternal(List data) throws MyApplicationException { + this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0)); + if (data == null || data.isEmpty()) return new ArrayList<>(); + + Map typeMap = this.collectReferenceTypes(data); + List> models = new ArrayList<>(); + for (ReferenceEntity d : data) { + ReferenceModel m = new ReferenceModel(); + m.setId(d.getId()); + m.setLabel(d.getLabel()); + if (d.getDefinition() != null){ + DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(DefinitionEntity.class, d.getDefinition()); + m.setDefinition(this.builderFactory.builder(ReferenceDefinitionCommonModelBuilder.class).authorize(this.authorize).build(definition)); + } + m.setReference(d.getReference()); + m.setAbbreviation(d.getAbbreviation()); + m.setDescription(d.getDescription()); + m.setSource(d.getSource()); + switch (d.getSourceType()){ + case Internal -> m.setSourceType(ReferenceSourceType.Internal); + case External -> m.setSourceType(ReferenceSourceType.External); + default -> throw new MyApplicationException("unrecognized type " + d.getSourceType().getValue()); + } + if (typeMap != null && d.getTypeId() != null && typeMap.containsKey(d.getTypeId())) m.setType(typeMap.get(d.getTypeId())); + + models.add(new CommonModelBuilderItemResponse<>(m, d)); + } + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + return models; + } + + + private Map collectReferenceTypes(List data) throws MyApplicationException { + if (data.isEmpty()) + return null; + this.logger.debug("checking related - {}", ReferenceTypeModel.class.getSimpleName()); + + Map itemMap; + ReferenceTypeQuery q = this.queryFactory.query(ReferenceTypeQuery.class).authorize(this.authorize).ids(data.stream().map(ReferenceEntity::getTypeId).distinct().collect(Collectors.toList())); + itemMap = this.builderFactory.builder(ReferenceTypeCommonModelBuilder.class).authorize(this.authorize).asForeignKey(q, ReferenceTypeEntity::getId); + + return itemMap; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/ReferenceDefinitionDepositBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/reference/ReferenceDefinitionCommonModelBuilder.java similarity index 55% rename from dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/ReferenceDefinitionDepositBuilder.java rename to dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/reference/ReferenceDefinitionCommonModelBuilder.java index 98dd0e8b3..c954e5f0a 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/ReferenceDefinitionDepositBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/reference/ReferenceDefinitionCommonModelBuilder.java @@ -1,9 +1,11 @@ -package eu.eudat.model.builder.deposit; +package eu.eudat.model.builder.commonmodels.reference; import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.reference.ReferenceDefinitionModel; import eu.eudat.commons.types.reference.DefinitionEntity; import eu.eudat.convention.ConventionService; -import eu.eudat.depositinterface.models.reference.DefinitionDepositModel; +import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder; +import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.logging.LoggerService; @@ -15,33 +17,33 @@ import org.springframework.context.annotation.Scope; import java.util.*; @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class ReferenceDefinitionDepositBuilder extends BaseDepositBuilder { +public class ReferenceDefinitionCommonModelBuilder extends BaseCommonModelBuilder { private final BuilderFactory builderFactory; private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); @Autowired - public ReferenceDefinitionDepositBuilder( + public ReferenceDefinitionCommonModelBuilder( ConventionService conventionService, BuilderFactory builderFactory) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceDefinitionDepositBuilder.class))); + super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceDefinitionCommonModelBuilder.class))); this.builderFactory = builderFactory; } - public ReferenceDefinitionDepositBuilder authorize(EnumSet values) { + public ReferenceDefinitionCommonModelBuilder authorize(EnumSet values) { this.authorize = values; return this; } @Override - protected List> buildInternal(List data) throws MyApplicationException { + protected List> buildInternal(List 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> models = new ArrayList<>(); + List> models = new ArrayList<>(); for (DefinitionEntity d : data) { - DefinitionDepositModel m = new DefinitionDepositModel(); - if (d.getFields() != null) m.setFields(this.builderFactory.builder(ReferenceFieldDepositBuilder.class).authorize(this.authorize).build(d.getFields())); - models.add(new DepositBuilderItemResponse<>(m, d)); + ReferenceDefinitionModel m = new ReferenceDefinitionModel(); + if (d.getFields() != null) m.setFields(this.builderFactory.builder(ReferenceFieldCommonModelBuilder.class).authorize(this.authorize).build(d.getFields())); + models.add(new CommonModelBuilderItemResponse<>(m, d)); } this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); return models; diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/ReferenceFieldDepositBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/reference/ReferenceFieldCommonModelBuilder.java similarity index 58% rename from dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/ReferenceFieldDepositBuilder.java rename to dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/reference/ReferenceFieldCommonModelBuilder.java index 592ac76fe..c5481b0e3 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/ReferenceFieldDepositBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/reference/ReferenceFieldCommonModelBuilder.java @@ -1,9 +1,11 @@ -package eu.eudat.model.builder.deposit; +package eu.eudat.model.builder.commonmodels.reference; import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.reference.ReferenceFieldModel; import eu.eudat.commons.types.reference.FieldEntity; import eu.eudat.convention.ConventionService; -import eu.eudat.depositinterface.models.reference.FieldDepositModel; +import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder; +import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse; import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.logging.LoggerService; import org.slf4j.LoggerFactory; @@ -17,33 +19,33 @@ import java.util.List; import java.util.Optional; @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class ReferenceFieldDepositBuilder extends BaseDepositBuilder { +public class ReferenceFieldCommonModelBuilder extends BaseCommonModelBuilder { private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); @Autowired - public ReferenceFieldDepositBuilder( + public ReferenceFieldCommonModelBuilder( ConventionService conventionService) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceFieldDepositBuilder.class))); + super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceFieldCommonModelBuilder.class))); } - public ReferenceFieldDepositBuilder authorize(EnumSet values) { + public ReferenceFieldCommonModelBuilder authorize(EnumSet values) { this.authorize = values; return this; } @Override - protected List> buildInternal(List data) throws MyApplicationException { + protected List> buildInternal(List 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> models = new ArrayList<>(); + List> models = new ArrayList<>(); for (FieldEntity d : data) { - FieldDepositModel m = new FieldDepositModel(); + ReferenceFieldModel m = new ReferenceFieldModel(); m.setCode(d.getCode()); m.setValue(d.getValue()); - models.add(new DepositBuilderItemResponse<>(m, d)); + models.add(new CommonModelBuilderItemResponse<>(m, d)); } this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); return models; diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DescriptionDepositBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DescriptionDepositBuilder.java deleted file mode 100644 index 70d8e9d93..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DescriptionDepositBuilder.java +++ /dev/null @@ -1,101 +0,0 @@ -package eu.eudat.model.builder.deposit; - -import eu.eudat.authorization.AuthorizationFlags; -import eu.eudat.commons.JsonHandlingService; -import eu.eudat.commons.XmlHandlingService; -import eu.eudat.commons.enums.IsActive; -import eu.eudat.commons.types.description.PropertyDefinitionEntity; -import eu.eudat.convention.ConventionService; -import eu.eudat.data.DescriptionEntity; -import eu.eudat.data.DescriptionTemplateEntity; -import eu.eudat.depositinterface.models.DescriptionDepositModel; -import eu.eudat.model.*; -import eu.eudat.model.builder.*; -import eu.eudat.model.builder.descriptionpropertiesdefinition.PropertyDefinitionBuilder; -import eu.eudat.query.*; -import gr.cite.tools.data.builder.BuilderFactory; -import gr.cite.tools.data.query.QueryFactory; -import gr.cite.tools.exception.MyApplicationException; -import gr.cite.tools.fieldset.BaseFieldSet; -import gr.cite.tools.fieldset.FieldSet; -import gr.cite.tools.logging.DataLogEntry; -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.*; -import java.util.stream.Collectors; - -@Component -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class DescriptionDepositBuilder extends BaseDepositBuilder { - - private final QueryFactory queryFactory; - - private final BuilderFactory builderFactory; - private final JsonHandlingService jsonHandlingService; - - private final XmlHandlingService xmlHandlingService; - private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - - @Autowired - public DescriptionDepositBuilder( - ConventionService conventionService, - QueryFactory queryFactory, - BuilderFactory builderFactory, JsonHandlingService jsonHandlingService, XmlHandlingService xmlHandlingService) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionDepositBuilder.class))); - this.queryFactory = queryFactory; - this.builderFactory = builderFactory; - this.jsonHandlingService = jsonHandlingService; - this.xmlHandlingService = xmlHandlingService; - } - - public DescriptionDepositBuilder authorize(EnumSet values) { - this.authorize = values; - return this; - } - - @Override - protected List> buildInternal(List data) throws MyApplicationException { - this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0)); - if (data == null || data.isEmpty()) return new ArrayList<>(); - - Map definitionMap = this.collectDescriptionTemplates(data); - - List> models = new ArrayList<>(); - for (DescriptionEntity d : data) { - DescriptionDepositModel m = new DescriptionDepositModel(); - m.setLabel(d.getLabel()); - m.setDescription(d.getDescription()); - if (d.getProperties() != null){ - //TODO Update with the new logic of property definition -// PropertyDefinitionEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(PropertyDefinitionEntity.class, d.getProperties()); -// if (definitionMap != null && definitionMap.containsKey(d.getDescriptionTemplateId()) && propertyDefinition != null && !this.conventionService.isListNullOrEmpty(propertyDefinition.getFields())) m.setFields(this.builderFactory.builder(DescriptionFieldDepositBuilder.class).authorize(this.authorize).setDefinition(definitionMap.get(d.getDescriptionTemplateId())).build(propertyDefinition.getFields())); - } - models.add(new DepositBuilderItemResponse<>(m, d)); - } - - this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); - - return models; - } - - private Map collectDescriptionTemplates(List data) throws MyApplicationException { - if (data.isEmpty()) - return null; - this.logger.debug("checking related - {}", DescriptionTemplate.class.getSimpleName()); - - List descriptionTemplateEntities = this.queryFactory.query(DescriptionTemplateQuery.class).isActive(IsActive.Active).authorize(this.authorize).ids(data.stream().map(DescriptionEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList())).collectAs(new BaseFieldSet().ensure(DescriptionTemplate._id).ensure(DescriptionTemplate._definition)); - MapitemMap = new HashMap<>(); - - for (DescriptionTemplateEntity descriptionTemplateEntity : descriptionTemplateEntities){ - eu.eudat.commons.types.descriptiontemplate.DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(eu.eudat.commons.types.descriptiontemplate.DefinitionEntity.class, descriptionTemplateEntity.getDefinition()); - itemMap.put(descriptionTemplateEntity.getId(), definition); - } - return itemMap; - } - -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DescriptionFieldDepositBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DescriptionFieldDepositBuilder.java deleted file mode 100644 index 209c4935a..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/DescriptionFieldDepositBuilder.java +++ /dev/null @@ -1,112 +0,0 @@ -package eu.eudat.model.builder.deposit; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import eu.eudat.authorization.AuthorizationFlags; -import eu.eudat.commons.types.description.FieldEntity; -import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity; -import eu.eudat.convention.ConventionService; -import eu.eudat.depositinterface.enums.FieldType; -import eu.eudat.depositinterface.models.DescriptionFieldDepositModel; -import eu.eudat.service.fielddatahelper.FieldDataHelperServiceProvider; -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 DescriptionFieldDepositBuilder extends BaseDepositBuilder { - - private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - private eu.eudat.commons.types.descriptiontemplate.DefinitionEntity definition; - private final FieldDataHelperServiceProvider fieldDataHelperServiceProvider; - @Autowired - public DescriptionFieldDepositBuilder( - ConventionService conventionService, FieldDataHelperServiceProvider fieldDataHelperServiceProvider - ) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionFieldDepositBuilder.class))); - this.fieldDataHelperServiceProvider = fieldDataHelperServiceProvider; - } - - public DescriptionFieldDepositBuilder authorize(EnumSet values) { - this.authorize = values; - return this; - } - - public DescriptionFieldDepositBuilder setDefinition(DefinitionEntity definition) { - this.definition = definition; - return this; - } - - @Override - protected List> buildInternal(List 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> models = new ArrayList<>(); - ObjectMapper objectMapper = new ObjectMapper(); - for (FieldEntity d : data) { - DescriptionFieldDepositModel m = new DescriptionFieldDepositModel(); - if (definition != null){ - - //TODO Update with the new logic of property definition - //List fieldEntities = definition.getFieldById(d.getKey()); - List fieldEntities = new ArrayList<>(); - if (!this.conventionService.isListNullOrEmpty(fieldEntities)){ - eu.eudat.commons.types.descriptiontemplate.FieldEntity field = fieldEntities.getFirst(); - m.setSchematics(field.getSchematics()); - if (field.getData() != null) { - boolean isMultiValue = fieldDataHelperServiceProvider.get(field.getData().getFieldType()).isMultiValue(field.getData()); - if (!isMultiValue) m.setValues(List.of(d.getTextValue())); - else { - try { - //TODO: Find better Solution - List values = objectMapper.readValue(d.getTextValue(), new TypeReference>() {}); - m.setValues(values); - } catch (JsonProcessingException e) { - throw new RuntimeException(e); - } - - } - - switch (field.getData().getFieldType()) { - case SELECT -> m.setFieldType(FieldType.WORD_LIST); - case BOOLEAN_DECISION -> m.setFieldType(FieldType.BOOLEAN_DECISION); - case RADIO_BOX -> m.setFieldType(FieldType.RADIO_BOX); - case INTERNAL_ENTRIES_DMPS -> m.setFieldType(FieldType.INTERNAL_DMP_ENTRIES_DMPS); - case INTERNAL_ENTRIES_DESCRIPTIONS -> m.setFieldType(FieldType.INTERNAL_DMP_ENTRIES_DATASETS); - case CHECK_BOX -> m.setFieldType(FieldType.CHECK_BOX); - case FREE_TEXT -> m.setFieldType(FieldType.FREE_TEXT); - case TEXT_AREA -> m.setFieldType(FieldType.TEXT_AREA); - case RICH_TEXT_AREA -> m.setFieldType(FieldType.RICH_TEXT_AREA); - case UPLOAD -> m.setFieldType(FieldType.UPLOAD); - case DATE_PICKER -> m.setFieldType(FieldType.DATE_PICKER); -// case REFERENCE_TYPES -> m.setFieldType(FieldType.REFERENCE_TYPES); //TODO new reference logic - case TAGS -> m.setFieldType(FieldType.TAGS); - case DATASET_IDENTIFIER -> m.setFieldType(FieldType.DATASET_IDENTIFIER); - case CURRENCY -> m.setFieldType(FieldType.CURRENCY); - case VALIDATION -> m.setFieldType(FieldType.VALIDATION); - default -> throw new MyApplicationException("unrecognized type " + field.getData().getFieldType()); - } - } - } - } - models.add(new DepositBuilderItemResponse<>(m, d)); - } - - this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); - - return models; - } - -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/ReferenceDepositBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/ReferenceDepositBuilder.java deleted file mode 100644 index 0c9896a89..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/deposit/ReferenceDepositBuilder.java +++ /dev/null @@ -1,75 +0,0 @@ -package eu.eudat.model.builder.deposit; - -import eu.eudat.authorization.AuthorizationFlags; -import eu.eudat.commons.XmlHandlingService; -import eu.eudat.commons.types.reference.DefinitionEntity; -import eu.eudat.convention.ConventionService; -import eu.eudat.data.ReferenceEntity; -import eu.eudat.depositinterface.enums.ReferenceSourceType; -import eu.eudat.depositinterface.models.ReferenceDepositModel; -import gr.cite.tools.data.builder.BuilderFactory; -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 ReferenceDepositBuilder extends BaseDepositBuilder { - - private final BuilderFactory builderFactory; - private final XmlHandlingService xmlHandlingService; - private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - - @Autowired - public ReferenceDepositBuilder( - ConventionService conventionService, - BuilderFactory builderFactory, XmlHandlingService xmlHandlingService) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceDepositBuilder.class))); - this.builderFactory = builderFactory; - this.xmlHandlingService = xmlHandlingService; - } - - public ReferenceDepositBuilder authorize(EnumSet values) { - this.authorize = values; - return this; - } - - @Override - protected List> buildInternal(List 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> models = new ArrayList<>(); - for (ReferenceEntity d : data) { - ReferenceDepositModel m = new ReferenceDepositModel(); - m.setId(d.getId()); - m.setLabel(d.getLabel()); - if (d.getDefinition() != null){ - DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(DefinitionEntity.class, d.getDefinition()); - m.setDefinition(this.builderFactory.builder(ReferenceDefinitionDepositBuilder.class).authorize(this.authorize).build(definition)); - } - m.setReference(d.getReference()); - m.setAbbreviation(d.getAbbreviation()); - m.setDescription(d.getDescription()); - m.setSource(d.getSource()); - switch (d.getSourceType()){ - case Internal -> m.setSourceType(ReferenceSourceType.Internal); - case External -> m.setSourceType(ReferenceSourceType.External); - default -> throw new MyApplicationException("unrecognized type " + d.getSourceType().getValue()); - } -// m.setType(d.getTypeId()); //TODO new reference logic - models.add(new DepositBuilderItemResponse<>(m, d)); - } - this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); - return models; - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptiontemplatedefinition/FieldBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptiontemplatedefinition/FieldBuilder.java index a5eda1d26..e4da9b38e 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptiontemplatedefinition/FieldBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptiontemplatedefinition/FieldBuilder.java @@ -65,13 +65,8 @@ public class FieldBuilder extends BaseBuilder { if (fields.hasField(this.asIndexer(Field._numbering))) m.setNumbering(d.getNumbering()); if (!visibilityRulesFields.isEmpty() && d.getVisibilityRules() != null) m.setVisibilityRules(this.builderFactory.builder(RuleBuilder.class).authorize(this.authorize).build(visibilityRulesFields, d.getVisibilityRules())); if (!dataFields.isEmpty() && d.getData() != null){ - try { - FieldDataHelperService fieldDataHelperService = this.fieldDataHelperServiceProvider.get(d.getData().getFieldType()); - m.setData(fieldDataHelperService.buildOne(dataFields, d.getData(), this.authorize)); - - } catch (Exception e){ - throw e; - } + FieldDataHelperService fieldDataHelperService = this.fieldDataHelperServiceProvider.get(d.getData().getFieldType()); + m.setData(fieldDataHelperService.buildOne(dataFields, d.getData(), this.authorize)); } models.add(m); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptiontemplatedefinition/fielddata/BaseFieldDataBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptiontemplatedefinition/fielddata/BaseFieldDataBuilder.java index b5191451c..d518a3988 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptiontemplatedefinition/fielddata/BaseFieldDataBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/descriptiontemplatedefinition/fielddata/BaseFieldDataBuilder.java @@ -10,9 +10,6 @@ import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.logging.DataLogEntry; import gr.cite.tools.logging.LoggerService; 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.*; diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/BaseFileTransformerBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/BaseFileTransformerBuilder.java index c794bd2bb..1728b5756 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/BaseFileTransformerBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/BaseFileTransformerBuilder.java @@ -1,77 +1,77 @@ -package eu.eudat.model.builder.filetransformer; - -import eu.eudat.convention.ConventionService; -import gr.cite.tools.data.builder.Builder; -import gr.cite.tools.data.query.QueryBase; -import gr.cite.tools.exception.MyApplicationException; -import gr.cite.tools.logging.LoggerService; - -import java.util.*; -import java.util.function.Function; -import java.util.stream.Collectors; - -public abstract class BaseFileTransformerBuilder implements Builder { - protected final LoggerService logger; - protected final ConventionService conventionService; - - public BaseFileTransformerBuilder( - ConventionService conventionService, - LoggerService logger - ) { - this.conventionService = conventionService; - this.logger = logger; - } - - public M build(D data) throws MyApplicationException { - if (data == null) { - //this.logger.Debug(new MapLogEntry("requested build for null item requesting fields").And("fields", directives)); -// return default(M); - M model = null; - return null; //TODO - } - List> models = this.buildInternal(List.of(data)); - return models.stream().map(FileTransformerBuilderItemResponse::getModel).findFirst().orElse(null); //TODO - } - - public List build(List data) throws MyApplicationException{ - List> models = this.buildInternal(data); - return models == null ? null : models.stream().map(FileTransformerBuilderItemResponse::getModel).collect(Collectors.toList()); - } - - protected abstract List> buildInternal(List data) throws MyApplicationException; - - public Map asForeignKey(QueryBase query, Function keySelector) throws MyApplicationException { - this.logger.trace("Building references from query"); - List data = query.collect(); - this.logger.debug("collected {} items to build", Optional.ofNullable(data).map(List::size).orElse(0)); - return this.asForeignKey(data, keySelector); - } - - public Map asForeignKey(List data, Function keySelector) throws MyApplicationException { - this.logger.trace("building references"); - List> models = this.buildInternal(data); - this.logger.debug("mapping {} build items from {} requested", Optional.ofNullable(models).map(List::size).orElse(0), Optional.ofNullable(data).map(List::size).orElse(0)); - return models == null ? new HashMap<>() : models.stream().collect(Collectors.toMap(x-> keySelector.apply(x.getData()), FileTransformerBuilderItemResponse::getModel)); - } - public Map> asMasterKey(QueryBase query,Function keySelector) throws MyApplicationException { - this.logger.trace("Building details from query"); - List data = query.collect(); - this.logger.debug("collected {} items to build", Optional.ofNullable(data).map(List::size).orElse(0)); - return this.asMasterKey(data, keySelector); - } - - public Map> asMasterKey(List data, Function keySelector) throws MyApplicationException { - this.logger.trace("building details"); - List> models = this.buildInternal(data); - this.logger.debug("mapping {} build items from {} requested", Optional.ofNullable(models).map(List::size).orElse(0), Optional.ofNullable(data).map(List::size).orElse(0)); - Map> map = new HashMap<>(); - if (models == null) return map; - for (FileTransformerBuilderItemResponse model : models) { - K key = keySelector.apply(model.getData()); - if (!map.containsKey(key)) map.put(key, new ArrayList()); - map.get(key).add(model.getModel()); - } - return map; - } -} - +//package eu.eudat.model.builder.filetransformer; +// +//import eu.eudat.convention.ConventionService; +//import gr.cite.tools.data.builder.Builder; +//import gr.cite.tools.data.query.QueryBase; +//import gr.cite.tools.exception.MyApplicationException; +//import gr.cite.tools.logging.LoggerService; +// +//import java.util.*; +//import java.util.function.Function; +//import java.util.stream.Collectors; +// +//public abstract class BaseFileTransformerBuilder implements Builder { +// protected final LoggerService logger; +// protected final ConventionService conventionService; +// +// public BaseFileTransformerBuilder( +// ConventionService conventionService, +// LoggerService logger +// ) { +// this.conventionService = conventionService; +// this.logger = logger; +// } +// +// public M build(D data) throws MyApplicationException { +// if (data == null) { +// //this.logger.Debug(new MapLogEntry("requested build for null item requesting fields").And("fields", directives)); +//// return default(M); +// M model = null; +// return null; //TODO +// } +// List> models = this.buildInternal(List.of(data)); +// return models.stream().map(FileTransformerBuilderItemResponse::getModel).findFirst().orElse(null); //TODO +// } +// +// public List build(List data) throws MyApplicationException{ +// List> models = this.buildInternal(data); +// return models == null ? null : models.stream().map(FileTransformerBuilderItemResponse::getModel).collect(Collectors.toList()); +// } +// +// protected abstract List> buildInternal(List data) throws MyApplicationException; +// +// public Map asForeignKey(QueryBase query, Function keySelector) throws MyApplicationException { +// this.logger.trace("Building references from query"); +// List data = query.collect(); +// this.logger.debug("collected {} items to build", Optional.ofNullable(data).map(List::size).orElse(0)); +// return this.asForeignKey(data, keySelector); +// } +// +// public Map asForeignKey(List data, Function keySelector) throws MyApplicationException { +// this.logger.trace("building references"); +// List> models = this.buildInternal(data); +// this.logger.debug("mapping {} build items from {} requested", Optional.ofNullable(models).map(List::size).orElse(0), Optional.ofNullable(data).map(List::size).orElse(0)); +// return models == null ? new HashMap<>() : models.stream().collect(Collectors.toMap(x-> keySelector.apply(x.getData()), FileTransformerBuilderItemResponse::getModel)); +// } +// public Map> asMasterKey(QueryBase query,Function keySelector) throws MyApplicationException { +// this.logger.trace("Building details from query"); +// List data = query.collect(); +// this.logger.debug("collected {} items to build", Optional.ofNullable(data).map(List::size).orElse(0)); +// return this.asMasterKey(data, keySelector); +// } +// +// public Map> asMasterKey(List data, Function keySelector) throws MyApplicationException { +// this.logger.trace("building details"); +// List> models = this.buildInternal(data); +// this.logger.debug("mapping {} build items from {} requested", Optional.ofNullable(models).map(List::size).orElse(0), Optional.ofNullable(data).map(List::size).orElse(0)); +// Map> map = new HashMap<>(); +// if (models == null) return map; +// for (FileTransformerBuilderItemResponse model : models) { +// K key = keySelector.apply(model.getData()); +// if (!map.containsKey(key)) map.put(key, new ArrayList()); +// map.get(key).add(model.getModel()); +// } +// return map; +// } +//} +// diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DescriptionFieldFileTransformerBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DescriptionFieldFileTransformerBuilder.java index 3a21cec3d..14e5f351c 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DescriptionFieldFileTransformerBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DescriptionFieldFileTransformerBuilder.java @@ -1,270 +1,265 @@ -package eu.eudat.model.builder.filetransformer; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import eu.eudat.authorization.AuthorizationFlags; -import eu.eudat.commons.types.description.FieldEntity; -import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity; -import eu.eudat.convention.ConventionService; -import eu.eudat.depositinterface.enums.FieldType; -import eu.eudat.depositinterface.models.DescriptionFieldDepositModel; -import eu.eudat.file.transformer.models.descriptiontemplate.DescriptionTemplateFileTransformerModel; -import eu.eudat.file.transformer.models.descriptiontemplate.definition.*; -import eu.eudat.service.fielddatahelper.FieldDataHelperServiceProvider; -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.*; - -@Component -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class DescriptionFieldFileTransformerBuilder extends BaseFileTransformerBuilder { - - private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - private DescriptionTemplateFileTransformerModel definition; - private final FieldDataHelperServiceProvider fieldDataHelperServiceProvider; - - @Autowired - public DescriptionFieldFileTransformerBuilder( - ConventionService conventionService, FieldDataHelperServiceProvider fieldDataHelperServiceProvider - ) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionFieldFileTransformerBuilder.class))); - this.fieldDataHelperServiceProvider = fieldDataHelperServiceProvider; - } - - public DescriptionFieldFileTransformerBuilder authorize(EnumSet values) { - this.authorize = values; - return this; - } - - public DescriptionFieldFileTransformerBuilder setDefinition(DescriptionTemplateFileTransformerModel definition) { - this.definition = definition; - return this; - } - - @Override - protected List> buildInternal(List 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> models = new ArrayList<>(); - ObjectMapper objectMapper = new ObjectMapper(); - for (FieldEntity d : data) { - // DescriptionFieldDepositModel m = new DescriptionFieldDepositModel(); - if (definition != null){ - //TODO Update with the new logic of property definition -// FieldFileTransformerModel fieldEntity = findFieldById(d.getKey()); - FieldFileTransformerModel fieldEntity = new FieldFileTransformerModel(); - if (fieldEntity != null){ - //m.setSchematics(fieldEntity.getSchematics()); - if (fieldEntity.getData() != null) { - /*boolean isMultiValue = fieldDataHelperServiceProvider.get(eu.eudat.commons.enums.FieldType.of(fieldEntity.getData().getFieldType().getValue())).isMultiValue(fieldEntity.getData()); - if (!isMultiValue) fieldEntity.getData().setValue(List.of(d.getValue()); - else { - fieldEntity.getData().setValue(d.getValue()); - } - */ - /*switch (field.getData().getFieldType()) { - case AUTO_COMPLETE -> m.setFieldType(FieldType.AUTO_COMPLETE); - case WORD_LIST -> m.setFieldType(FieldType.WORD_LIST); - case BOOLEAN_DECISION -> m.setFieldType(FieldType.BOOLEAN_DECISION); - case RADIO_BOX -> m.setFieldType(FieldType.RADIO_BOX); - case INTERNAL_DMP_ENTRIES_RESEARCHERS -> m.setFieldType(FieldType.INTERNAL_DMP_ENTRIES_RESEARCHERS); - case INTERNAL_DMP_ENTRIES_DMPS -> m.setFieldType(FieldType.INTERNAL_DMP_ENTRIES_DMPS); - case INTERNAL_DMP_ENTRIES_DATASETS -> m.setFieldType(FieldType.INTERNAL_DMP_ENTRIES_DATASETS); - case CHECK_BOX -> m.setFieldType(FieldType.CHECK_BOX); - case FREE_TEXT -> m.setFieldType(FieldType.FREE_TEXT); - case TEXT_AREA -> m.setFieldType(FieldType.TEXT_AREA); - case RICH_TEXT_AREA -> m.setFieldType(FieldType.RICH_TEXT_AREA); - case UPLOAD -> m.setFieldType(FieldType.UPLOAD); - case DATE_PICKER -> m.setFieldType(FieldType.DATE_PICKER); - case EXTERNAL_DATASETS -> m.setFieldType(FieldType.EXTERNAL_DATASETS); - case DATA_REPOSITORIES -> m.setFieldType(FieldType.DATA_REPOSITORIES); - case JOURNAL_REPOSITORIES -> m.setFieldType(FieldType.JOURNAL_REPOSITORIES); - case PUB_REPOSITORIES -> m.setFieldType(FieldType.PUB_REPOSITORIES); - case LICENSES -> m.setFieldType(FieldType.LICENSES); - case PUBLICATIONS -> m.setFieldType(FieldType.PUBLICATIONS); - case REGISTRIES -> m.setFieldType(FieldType.REGISTRIES); - case SERVICES -> m.setFieldType(FieldType.SERVICES); - case TAGS -> m.setFieldType(FieldType.TAGS); - case RESEARCHERS -> m.setFieldType(FieldType.RESEARCHERS); - case ORGANIZATIONS -> m.setFieldType(FieldType.ORGANIZATIONS); - case DATASET_IDENTIFIER -> m.setFieldType(FieldType.DATASET_IDENTIFIER); - case CURRENCY -> m.setFieldType(FieldType.CURRENCY); - case VALIDATION -> m.setFieldType(FieldType.VALIDATION); - case TAXONOMIES -> m.setFieldType(FieldType.TAXONOMIES); - default -> throw new MyApplicationException("unrecognized type " + field.getData().getFieldType()); - }*/ - } - } - } - //models.add(new FileTransformerBuilderItemResponse<>(m, d)); - } - - for (PageFileTransformerModel page : definition.getDefinition().getPages()) { - page.setSections(calculateSectionVisibility(page.getSections())); - } - - this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); - - return List.of(new FileTransformerBuilderItemResponse<>(definition, data.get(0))); - } - - private FieldFileTransformerModel findFieldById(String id) { - FieldFileTransformerModel result = null; - List pages = definition.getDefinition().getPages(); - for (PageFileTransformerModel page: pages) { - if (page.getSections() != null && !page.getSections().isEmpty()) { - result = findSectionFieldById(id, page.getSections()); - if (result != null) { - break; - } - } - } - return result; - } - - private FieldFileTransformerModel findSectionFieldById(String id, List sections) { - FieldFileTransformerModel result = null; - for (SectionFileTransformerModel section: sections) { - if (section.getSections() != null && !section.getSections().isEmpty()) { - result = findSectionFieldById(id, section.getSections()); - } - if (result == null) { - List fieldSets = section.getFieldSets(); - if (fieldSets != null && !fieldSets.isEmpty()) { - for (FieldSetFileTransformerModel fieldSet : fieldSets) { - List fields = fieldSet.getFields(); - if (fields != null && !fields.isEmpty()) { - for (FieldFileTransformerModel field : fields) { - if (field.getId().equals(id)) { - result = field; - break; - } - } - } - if (result != null) { - break; - } - } - } - } - } - return result; - } - - private List calculateSectionVisibility(List sections) { - List result = new ArrayList<>(); - - for (SectionFileTransformerModel section : sections) { - if (section.getSections() != null && !section.getSections().isEmpty()) { - section.setSections(calculateSectionVisibility(section.getSections())); - } - - if (section.getFieldSets() != null && !section.getFieldSets().isEmpty()) { - section.setFieldSets(calculateFieldSetVisibility(section.getFieldSets())); - } - - if ((section.getSections() != null && !section.getSections().isEmpty()) || (section.getFieldSets() != null && !section.getFieldSets().isEmpty())) { - result.add(section); - } - } - - return result; - } - - private List calculateFieldSetVisibility(List fieldSets) { - List result = new ArrayList<>(); - for (FieldSetFileTransformerModel fieldSet : fieldSets) { - if (fieldSet.getFields() != null && !fieldSet.getFields().isEmpty()) { - fieldSet.setFields(calculateFieldVisibility(fieldSet.getFields())); - if (fieldSet.getFields() != null && !fieldSet.getFields().isEmpty()) { - result.add(fieldSet); - } - } - } - return result; - } - - private List calculateFieldVisibility(List fields) { - List result = new ArrayList<>(); - for (FieldFileTransformerModel field : fields) { - if (field.getVisibilityRules() != null && !field.getVisibilityRules().isEmpty()) { - Integer maxChecks = field.getVisibilityRules().size(); - Integer successfulChecks = 0; - for (RuleFileTransformerModel rule : field.getVisibilityRules()) { - FieldFileTransformerModel targetField = findFieldByPages(definition.getDefinition().getPages(), rule.getTarget()); - if (targetField.getData() != null ) { - successfulChecks = targetField.getData().getValue().equals(rule.getValue()) ? successfulChecks + 1 : successfulChecks; - } - } - if (successfulChecks.equals(maxChecks)) { - result.add(field); - } - } else { - result.add(field); - } - } - return result; - } - - private FieldFileTransformerModel findFieldByPages(List pages, String fieldId) { - FieldFileTransformerModel result = null; - for (PageFileTransformerModel page : pages) { - result = findFieldBySections(page.getSections(), fieldId); - if (result != null) { - break; - } - } - return result; - } - - private FieldFileTransformerModel findFieldBySections(List sections, String fieldId) { - FieldFileTransformerModel result = null; - for (SectionFileTransformerModel section : sections) { - if (section.getSections() != null && !section.getSections().isEmpty()) { - result = findFieldBySections(section.getSections(), fieldId); - if (result != null) { - break; - } - } - - if (section.getFieldSets() != null && !section.getFieldSets().isEmpty()) { - result = findFieldByFieldSets(section.getFieldSets(), fieldId); - if (result != null) { - break; - } - } - } - return result; - } - - private FieldFileTransformerModel findFieldByFieldSets(List fieldSets, String fieldId) { - FieldFileTransformerModel result = null; - for (FieldSetFileTransformerModel fieldSet: fieldSets) { - result = findField(fieldSet.getFields(), fieldId); - if (result != null) { - break; - } - } - return result; - } - - private FieldFileTransformerModel findField(List fields, String fieldId) { - FieldFileTransformerModel result = null; - for (FieldFileTransformerModel field: fields) { - if (field.getId().equals(fieldId)) { - result = field; - break; - } - } - return result; - } - -} +//package eu.eudat.model.builder.filetransformer; +// +//import com.fasterxml.jackson.databind.ObjectMapper; +//import eu.eudat.authorization.AuthorizationFlags; +//import eu.eudat.commons.types.description.FieldEntity; +//import eu.eudat.convention.ConventionService; +//import eu.eudat.file.transformer.models.descriptiontemplate.DescriptionTemplateFileTransformerModel; +//import eu.eudat.file.transformer.models.descriptiontemplate.definition.*; +//import eu.eudat.service.fielddatahelper.FieldDataHelperServiceProvider; +//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.*; +// +//@Component +//@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +//public class DescriptionFieldFileTransformerBuilder extends BaseFileTransformerBuilder { +// +// private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); +// private DescriptionTemplateFileTransformerModel definition; +// private final FieldDataHelperServiceProvider fieldDataHelperServiceProvider; +// +// @Autowired +// public DescriptionFieldFileTransformerBuilder( +// ConventionService conventionService, FieldDataHelperServiceProvider fieldDataHelperServiceProvider +// ) { +// super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionFieldFileTransformerBuilder.class))); +// this.fieldDataHelperServiceProvider = fieldDataHelperServiceProvider; +// } +// +// public DescriptionFieldFileTransformerBuilder authorize(EnumSet values) { +// this.authorize = values; +// return this; +// } +// +// public DescriptionFieldFileTransformerBuilder setDefinition(DescriptionTemplateFileTransformerModel definition) { +// this.definition = definition; +// return this; +// } +// +// @Override +// protected List> buildInternal(List 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> models = new ArrayList<>(); +// ObjectMapper objectMapper = new ObjectMapper(); +// for (FieldEntity d : data) { +// // DescriptionFieldDepositModel m = new DescriptionFieldDepositModel(); +// if (definition != null){ +// //TODO Update with the new logic of property definition +//// FieldFileTransformerModel fieldEntity = findFieldById(d.getKey()); +// FieldFileTransformerModel fieldEntity = new FieldFileTransformerModel(); +// if (fieldEntity != null){ +// //m.setSchematics(fieldEntity.getSchematics()); +// if (fieldEntity.getData() != null) { +// /*boolean isMultiValue = fieldDataHelperServiceProvider.get(eu.eudat.commons.enums.FieldType.of(fieldEntity.getData().getFieldType().getValue())).isMultiValue(fieldEntity.getData()); +// if (!isMultiValue) fieldEntity.getData().setValue(List.of(d.getValue()); +// else { +// fieldEntity.getData().setValue(d.getValue()); +// } +// */ +// /*switch (field.getData().getFieldType()) { +// case AUTO_COMPLETE -> m.setFieldType(FieldType.AUTO_COMPLETE); +// case WORD_LIST -> m.setFieldType(FieldType.WORD_LIST); +// case BOOLEAN_DECISION -> m.setFieldType(FieldType.BOOLEAN_DECISION); +// case RADIO_BOX -> m.setFieldType(FieldType.RADIO_BOX); +// case INTERNAL_DMP_ENTRIES_RESEARCHERS -> m.setFieldType(FieldType.INTERNAL_DMP_ENTRIES_RESEARCHERS); +// case INTERNAL_DMP_ENTRIES_DMPS -> m.setFieldType(FieldType.INTERNAL_DMP_ENTRIES_DMPS); +// case INTERNAL_DMP_ENTRIES_DATASETS -> m.setFieldType(FieldType.INTERNAL_DMP_ENTRIES_DATASETS); +// case CHECK_BOX -> m.setFieldType(FieldType.CHECK_BOX); +// case FREE_TEXT -> m.setFieldType(FieldType.FREE_TEXT); +// case TEXT_AREA -> m.setFieldType(FieldType.TEXT_AREA); +// case RICH_TEXT_AREA -> m.setFieldType(FieldType.RICH_TEXT_AREA); +// case UPLOAD -> m.setFieldType(FieldType.UPLOAD); +// case DATE_PICKER -> m.setFieldType(FieldType.DATE_PICKER); +// case EXTERNAL_DATASETS -> m.setFieldType(FieldType.EXTERNAL_DATASETS); +// case DATA_REPOSITORIES -> m.setFieldType(FieldType.DATA_REPOSITORIES); +// case JOURNAL_REPOSITORIES -> m.setFieldType(FieldType.JOURNAL_REPOSITORIES); +// case PUB_REPOSITORIES -> m.setFieldType(FieldType.PUB_REPOSITORIES); +// case LICENSES -> m.setFieldType(FieldType.LICENSES); +// case PUBLICATIONS -> m.setFieldType(FieldType.PUBLICATIONS); +// case REGISTRIES -> m.setFieldType(FieldType.REGISTRIES); +// case SERVICES -> m.setFieldType(FieldType.SERVICES); +// case TAGS -> m.setFieldType(FieldType.TAGS); +// case RESEARCHERS -> m.setFieldType(FieldType.RESEARCHERS); +// case ORGANIZATIONS -> m.setFieldType(FieldType.ORGANIZATIONS); +// case DATASET_IDENTIFIER -> m.setFieldType(FieldType.DATASET_IDENTIFIER); +// case CURRENCY -> m.setFieldType(FieldType.CURRENCY); +// case VALIDATION -> m.setFieldType(FieldType.VALIDATION); +// case TAXONOMIES -> m.setFieldType(FieldType.TAXONOMIES); +// default -> throw new MyApplicationException("unrecognized type " + field.getData().getFieldType()); +// }*/ +// } +// } +// } +// //models.add(new FileTransformerBuilderItemResponse<>(m, d)); +// } +// +// for (PageFileTransformerModel page : definition.getDefinition().getPages()) { +// page.setSections(calculateSectionVisibility(page.getSections())); +// } +// +// this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); +// +// return List.of(new FileTransformerBuilderItemResponse<>(definition, data.get(0))); +// } +// +// private FieldFileTransformerModel findFieldById(String id) { +// FieldFileTransformerModel result = null; +// List pages = definition.getDefinition().getPages(); +// for (PageFileTransformerModel page: pages) { +// if (page.getSections() != null && !page.getSections().isEmpty()) { +// result = findSectionFieldById(id, page.getSections()); +// if (result != null) { +// break; +// } +// } +// } +// return result; +// } +// +// private FieldFileTransformerModel findSectionFieldById(String id, List sections) { +// FieldFileTransformerModel result = null; +// for (SectionFileTransformerModel section: sections) { +// if (section.getSections() != null && !section.getSections().isEmpty()) { +// result = findSectionFieldById(id, section.getSections()); +// } +// if (result == null) { +// List fieldSets = section.getFieldSets(); +// if (fieldSets != null && !fieldSets.isEmpty()) { +// for (FieldSetFileTransformerModel fieldSet : fieldSets) { +// List fields = fieldSet.getFields(); +// if (fields != null && !fields.isEmpty()) { +// for (FieldFileTransformerModel field : fields) { +// if (field.getId().equals(id)) { +// result = field; +// break; +// } +// } +// } +// if (result != null) { +// break; +// } +// } +// } +// } +// } +// return result; +// } +// +// private List calculateSectionVisibility(List sections) { +// List result = new ArrayList<>(); +// +// for (SectionFileTransformerModel section : sections) { +// if (section.getSections() != null && !section.getSections().isEmpty()) { +// section.setSections(calculateSectionVisibility(section.getSections())); +// } +// +// if (section.getFieldSets() != null && !section.getFieldSets().isEmpty()) { +// section.setFieldSets(calculateFieldSetVisibility(section.getFieldSets())); +// } +// +// if ((section.getSections() != null && !section.getSections().isEmpty()) || (section.getFieldSets() != null && !section.getFieldSets().isEmpty())) { +// result.add(section); +// } +// } +// +// return result; +// } +// +// private List calculateFieldSetVisibility(List fieldSets) { +// List result = new ArrayList<>(); +// for (FieldSetFileTransformerModel fieldSet : fieldSets) { +// if (fieldSet.getFields() != null && !fieldSet.getFields().isEmpty()) { +// fieldSet.setFields(calculateFieldVisibility(fieldSet.getFields())); +// if (fieldSet.getFields() != null && !fieldSet.getFields().isEmpty()) { +// result.add(fieldSet); +// } +// } +// } +// return result; +// } +// +// private List calculateFieldVisibility(List fields) { +// List result = new ArrayList<>(); +// for (FieldFileTransformerModel field : fields) { +// if (field.getVisibilityRules() != null && !field.getVisibilityRules().isEmpty()) { +// Integer maxChecks = field.getVisibilityRules().size(); +// Integer successfulChecks = 0; +// for (RuleFileTransformerModel rule : field.getVisibilityRules()) { +// FieldFileTransformerModel targetField = findFieldByPages(definition.getDefinition().getPages(), rule.getTarget()); +// if (targetField.getData() != null ) { +// successfulChecks = targetField.getData().getValue().equals(rule.getValue()) ? successfulChecks + 1 : successfulChecks; +// } +// } +// if (successfulChecks.equals(maxChecks)) { +// result.add(field); +// } +// } else { +// result.add(field); +// } +// } +// return result; +// } +// +// private FieldFileTransformerModel findFieldByPages(List pages, String fieldId) { +// FieldFileTransformerModel result = null; +// for (PageFileTransformerModel page : pages) { +// result = findFieldBySections(page.getSections(), fieldId); +// if (result != null) { +// break; +// } +// } +// return result; +// } +// +// private FieldFileTransformerModel findFieldBySections(List sections, String fieldId) { +// FieldFileTransformerModel result = null; +// for (SectionFileTransformerModel section : sections) { +// if (section.getSections() != null && !section.getSections().isEmpty()) { +// result = findFieldBySections(section.getSections(), fieldId); +// if (result != null) { +// break; +// } +// } +// +// if (section.getFieldSets() != null && !section.getFieldSets().isEmpty()) { +// result = findFieldByFieldSets(section.getFieldSets(), fieldId); +// if (result != null) { +// break; +// } +// } +// } +// return result; +// } +// +// private FieldFileTransformerModel findFieldByFieldSets(List fieldSets, String fieldId) { +// FieldFileTransformerModel result = null; +// for (FieldSetFileTransformerModel fieldSet: fieldSets) { +// result = findField(fieldSet.getFields(), fieldId); +// if (result != null) { +// break; +// } +// } +// return result; +// } +// +// private FieldFileTransformerModel findField(List fields, String fieldId) { +// FieldFileTransformerModel result = null; +// for (FieldFileTransformerModel field: fields) { +// if (field.getId().equals(fieldId)) { +// result = field; +// break; +// } +// } +// return result; +// } +// +//} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DescriptionFileTransformerBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DescriptionFileTransformerBuilder.java index bfa133dfd..95b62c927 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DescriptionFileTransformerBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DescriptionFileTransformerBuilder.java @@ -1,171 +1,167 @@ -package eu.eudat.model.builder.filetransformer; - -import eu.eudat.authorization.AuthorizationFlags; -import eu.eudat.commons.JsonHandlingService; -import eu.eudat.commons.XmlHandlingService; -import eu.eudat.commons.enums.IsActive; -import eu.eudat.commons.types.description.PropertyDefinitionEntity; -import eu.eudat.convention.ConventionService; -import eu.eudat.data.*; -import eu.eudat.depositinterface.models.DescriptionDepositModel; -import eu.eudat.file.transformer.enums.DescriptionStatus; -import eu.eudat.file.transformer.models.description.DescriptionFileTransformerModel; -import eu.eudat.file.transformer.models.description.DescriptionReferenceFileTransformerModel; -import eu.eudat.file.transformer.models.description.DescriptionTagFileTransformerModel; -import eu.eudat.file.transformer.models.descriptiontemplate.DescriptionTemplateFileTransformerModel; -import eu.eudat.file.transformer.models.dmp.DmpFileTransformerModel; -import eu.eudat.file.transformer.models.dmp.DmpReferenceFileTransformerModel; -import eu.eudat.file.transformer.models.reference.ReferenceFileTransformerModel; -import eu.eudat.file.transformer.models.tag.TagFileTransformerModel; -import eu.eudat.file.transformer.models.user.UserFileTransformerModel; -import eu.eudat.model.DescriptionReference; -import eu.eudat.model.DescriptionTemplate; -import eu.eudat.model.DmpReference; -import eu.eudat.model.Tag; -import eu.eudat.model.builder.TagBuilder; -import eu.eudat.query.*; -import gr.cite.tools.data.builder.BuilderFactory; -import gr.cite.tools.data.query.QueryFactory; -import gr.cite.tools.exception.MyApplicationException; -import gr.cite.tools.fieldset.BaseFieldSet; -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.*; -import java.util.stream.Collectors; - -@Component -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class DescriptionFileTransformerBuilder extends BaseFileTransformerBuilder { - - private final QueryFactory queryFactory; - - private final BuilderFactory builderFactory; - private final JsonHandlingService jsonHandlingService; - - private final XmlHandlingService xmlHandlingService; - private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - - @Autowired - public DescriptionFileTransformerBuilder( - ConventionService conventionService, - QueryFactory queryFactory, - BuilderFactory builderFactory, JsonHandlingService jsonHandlingService, XmlHandlingService xmlHandlingService) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionFileTransformerBuilder.class))); - this.queryFactory = queryFactory; - this.builderFactory = builderFactory; - this.jsonHandlingService = jsonHandlingService; - this.xmlHandlingService = xmlHandlingService; - } - - public DescriptionFileTransformerBuilder authorize(EnumSet values) { - this.authorize = values; - return this; - } - - @Override - protected List> buildInternal(List 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 definitionMap = this.collectDescriptionTemplates(data); - Map> referenceMap = collectReferences(data); - Map> tagMap = collectTags(data); - - - DmpFileTransformerModel dmp = this.getDmp(data.get(0).getDmpId()); - - - List> models = new ArrayList<>(); - for (DescriptionEntity d : data) { - DescriptionFileTransformerModel m = new DescriptionFileTransformerModel(); - m.setId(d.getId()); - m.setLabel(d.getLabel()); - m.setDescription(d.getDescription()); - m.setCreatedAt(d.getCreatedAt()); - m.setFinalizedAt(d.getFinalizedAt()); - m.setUpdatedAt(d.getUpdatedAt()); - m.setStatus(DescriptionStatus.of(d.getStatus().getValue())); - if (d.getProperties() != null){ - PropertyDefinitionEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(PropertyDefinitionEntity.class, d.getProperties()); - - //TODO Update with the new logic of property definition -// if (definitionMap != null && definitionMap.stream().anyMatch(dt -> dt.getId().equals(d.getDescriptionTemplateId())) && propertyDefinition != null && !this.conventionService.isListNullOrEmpty(propertyDefinition.getFields())) m.setDescriptionTemplate(this.builderFactory.builder(DescriptionFieldFileTransformerBuilder.class).authorize(this.authorize).setDefinition(definitionMap.stream().filter(dm -> dm.getId().equals(d.getDescriptionTemplateId())).findFirst().get()).build(propertyDefinition.getFields()).get(0)); - } - if (referenceMap != null && !referenceMap.isEmpty() && referenceMap.containsKey(d.getId())) m.setDescriptionReferenceFileTransformerModels(referenceMap.get(d.getId())); - if (tagMap != null && !tagMap.isEmpty() && tagMap.containsKey(d.getId())) m.setDescriptionTagFileTransformerModels(tagMap.get(d.getId())); - - m.setDmp(dmp); - models.add(new FileTransformerBuilderItemResponse<>(m, d)); - } - - this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); - - return models; - } - - private DmpFileTransformerModel getDmp(UUID id) { - DmpQuery query = queryFactory.query(DmpQuery.class).authorize(authorize).isActive(IsActive.Active).ids(id); - return builderFactory.builder(DmpFileTransformerBuilder.class).ignoreDescriptions(true).authorize(authorize).build(query.first()); - } - - private List collectDescriptionTemplates(List data) throws MyApplicationException { - if (data.isEmpty()) - return null; - this.logger.debug("checking related - {}", DescriptionTemplate.class.getSimpleName()); - - List descriptionTemplateEntities = this.queryFactory.query(DescriptionTemplateQuery.class).isActive(IsActive.Active).authorize(this.authorize).ids(data.stream().map(DescriptionEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList())).collectAs(new BaseFieldSet().ensure(DescriptionTemplate._id).ensure(DescriptionTemplate._definition)); - - return this.builderFactory.builder(DescriptionTemplateFileTransformerBuilder.class).authorize(authorize).build(descriptionTemplateEntities); - } - - private Map> collectReferences(List data) throws MyApplicationException { - if (data.isEmpty()) return null; - this.logger.debug("checking related - {}", DmpReference.class.getSimpleName()); - - List descriptionReferences = this.queryFactory.query(DescriptionReferenceQuery.class).authorize(this.authorize).descriptionIds(data.stream().map(DescriptionEntity::getId).distinct().collect(Collectors.toList())).collectAs(new BaseFieldSet().ensure(DescriptionReference._description).ensure(DescriptionReference._reference)); - - Map> itemMap = new HashMap<>(); - ReferenceQuery query = this.queryFactory.query(ReferenceQuery.class).authorize(this.authorize).isActive(IsActive.Active).ids(descriptionReferences.stream().map(DescriptionReferenceEntity::getReferenceId).distinct().collect(Collectors.toList())); - Map referenceDepositModelMap = this.builderFactory.builder(ReferenceFileTransformerBuilder.class).authorize(this.authorize).asForeignKey(query, ReferenceEntity::getId); - if (referenceDepositModelMap == null) return null; - for (DescriptionReferenceEntity descriptionReference : descriptionReferences) { - DescriptionReferenceFileTransformerModel descriptionReferenceFileTransformerModel = new DescriptionReferenceFileTransformerModel(); - descriptionReferenceFileTransformerModel.setId(descriptionReference.getId()); - descriptionReferenceFileTransformerModel.setReference(referenceDepositModelMap.getOrDefault(descriptionReference.getReferenceId(), null)); - DescriptionReferenceFileTransformerModel model = descriptionReferenceFileTransformerModel; - if (model == null) continue; - UUID key = descriptionReference.getDescriptionId(); - if (!itemMap.containsKey(key)) itemMap.put(key, new ArrayList<>()); - itemMap.get(key).add(model); - } - return itemMap; - } - - private Map> collectTags(List data) { - if (data.isEmpty()) return null; - - List descriptionTags = this.queryFactory.query(DescriptionTagQuery.class).authorize(this.authorize).descriptionIds(data.stream().map(DescriptionEntity::getId).distinct().toList()).collect(); - - Map> itemMap = new HashMap<>(); - TagQuery query = this.queryFactory.query(TagQuery.class).authorize(this.authorize).isActive(IsActive.Active).ids(descriptionTags.stream().map(DescriptionTagEntity::getTagId).distinct().toList()); - Map tagMap = this.builderFactory.builder(TagFileTransformerBuilder.class).asForeignKey(query, TagEntity::getId); - for (DescriptionTagEntity descriptionTag : descriptionTags) { - DescriptionTagFileTransformerModel descriptionTagFileTransformerModel = new DescriptionTagFileTransformerModel(); - descriptionTagFileTransformerModel.setId(descriptionTag.getId()); - descriptionTagFileTransformerModel.setTagFileTransformerModel(tagMap.getOrDefault(descriptionTag.getTagId(), null)); - DescriptionTagFileTransformerModel model = descriptionTagFileTransformerModel; - if (model == null) continue; - UUID key = descriptionTag.getDescriptionId(); - if (!itemMap.containsKey(key)) itemMap.put(key, new ArrayList<>()); - itemMap.get(key).add(model); - } - - return itemMap; - } - -} +//package eu.eudat.model.builder.filetransformer; +// +//import eu.eudat.authorization.AuthorizationFlags; +//import eu.eudat.commons.JsonHandlingService; +//import eu.eudat.commons.XmlHandlingService; +//import eu.eudat.commons.enums.IsActive; +//import eu.eudat.commons.types.description.PropertyDefinitionEntity; +//import eu.eudat.convention.ConventionService; +//import eu.eudat.data.*; +//import eu.eudat.file.transformer.enums.DescriptionStatus; +//import eu.eudat.file.transformer.models.description.DescriptionFileTransformerModel; +//import eu.eudat.file.transformer.models.description.DescriptionReferenceFileTransformerModel; +//import eu.eudat.file.transformer.models.description.DescriptionTagFileTransformerModel; +//import eu.eudat.file.transformer.models.descriptiontemplate.DescriptionTemplateFileTransformerModel; +//import eu.eudat.file.transformer.models.dmp.DmpFileTransformerModel; +//import eu.eudat.file.transformer.models.reference.ReferenceFileTransformerModel; +//import eu.eudat.file.transformer.models.tag.TagFileTransformerModel; +//import eu.eudat.model.DescriptionReference; +//import eu.eudat.model.DescriptionTemplate; +//import eu.eudat.model.DmpReference; +//import eu.eudat.query.*; +//import gr.cite.tools.data.builder.BuilderFactory; +//import gr.cite.tools.data.query.QueryFactory; +//import gr.cite.tools.exception.MyApplicationException; +//import gr.cite.tools.fieldset.BaseFieldSet; +//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.*; +//import java.util.stream.Collectors; +// +//@Component +//@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +//public class DescriptionFileTransformerBuilder extends BaseFileTransformerBuilder { +// +// private final QueryFactory queryFactory; +// +// private final BuilderFactory builderFactory; +// private final JsonHandlingService jsonHandlingService; +// +// private final XmlHandlingService xmlHandlingService; +// private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); +// +// @Autowired +// public DescriptionFileTransformerBuilder( +// ConventionService conventionService, +// QueryFactory queryFactory, +// BuilderFactory builderFactory, JsonHandlingService jsonHandlingService, XmlHandlingService xmlHandlingService) { +// super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionFileTransformerBuilder.class))); +// this.queryFactory = queryFactory; +// this.builderFactory = builderFactory; +// this.jsonHandlingService = jsonHandlingService; +// this.xmlHandlingService = xmlHandlingService; +// } +// +// public DescriptionFileTransformerBuilder authorize(EnumSet values) { +// this.authorize = values; +// return this; +// } +// +// @Override +// protected List> buildInternal(List 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 definitionMap = this.collectDescriptionTemplates(data); +// Map> referenceMap = collectReferences(data); +// Map> tagMap = collectTags(data); +// +// +// DmpFileTransformerModel dmp = this.getDmp(data.get(0).getDmpId()); +// +// +// List> models = new ArrayList<>(); +// for (DescriptionEntity d : data) { +// DescriptionFileTransformerModel m = new DescriptionFileTransformerModel(); +// m.setId(d.getId()); +// m.setLabel(d.getLabel()); +// m.setLabel(d.getLabel()); +// m.setDescription(d.getDescription()); +// m.setCreatedAt(d.getCreatedAt()); +// m.setFinalizedAt(d.getFinalizedAt()); +// m.setUpdatedAt(d.getUpdatedAt()); +// m.setStatus(DescriptionStatus.of(d.getStatus().getValue())); +// if (d.getProperties() != null){ +// PropertyDefinitionEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(PropertyDefinitionEntity.class, d.getProperties()); +// +// //TODO Update with the new logic of property definition +//// if (definitionMap != null && definitionMap.stream().anyMatch(dt -> dt.getId().equals(d.getDescriptionTemplateId())) && propertyDefinition != null && !this.conventionService.isListNullOrEmpty(propertyDefinition.getFields())) m.setDescriptionTemplate(this.builderFactory.builder(DescriptionFieldFileTransformerBuilder.class).authorize(this.authorize).setDefinition(definitionMap.stream().filter(dm -> dm.getId().equals(d.getDescriptionTemplateId())).findFirst().get()).build(propertyDefinition.getFields()).get(0)); +// } +// if (referenceMap != null && !referenceMap.isEmpty() && referenceMap.containsKey(d.getId())) m.setDescriptionReferenceFileTransformerModels(referenceMap.get(d.getId())); +// if (tagMap != null && !tagMap.isEmpty() && tagMap.containsKey(d.getId())) m.setDescriptionTagFileTransformerModels(tagMap.get(d.getId())); +// +// m.setDmp(dmp); +// models.add(new FileTransformerBuilderItemResponse<>(m, d)); +// } +// +// this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); +// +// return models; +// } +// +// private DmpFileTransformerModel getDmp(UUID id) { +// DmpQuery query = queryFactory.query(DmpQuery.class).authorize(authorize).isActive(IsActive.Active).ids(id); +// return builderFactory.builder(DmpFileTransformerBuilder.class).ignoreDescriptions(true).authorize(authorize).build(query.first()); +// } +// +// private List collectDescriptionTemplates(List data) throws MyApplicationException { +// if (data.isEmpty()) +// return null; +// this.logger.debug("checking related - {}", DescriptionTemplate.class.getSimpleName()); +// +// List descriptionTemplateEntities = this.queryFactory.query(DescriptionTemplateQuery.class).isActive(IsActive.Active).authorize(this.authorize).ids(data.stream().map(DescriptionEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList())).collectAs(new BaseFieldSet().ensure(DescriptionTemplate._id).ensure(DescriptionTemplate._definition)); +// +// return this.builderFactory.builder(DescriptionTemplateFileTransformerBuilder.class).authorize(authorize).build(descriptionTemplateEntities); +// } +// +// private Map> collectReferences(List data) throws MyApplicationException { +// if (data.isEmpty()) return null; +// this.logger.debug("checking related - {}", DmpReference.class.getSimpleName()); +// +// List descriptionReferences = this.queryFactory.query(DescriptionReferenceQuery.class).authorize(this.authorize).descriptionIds(data.stream().map(DescriptionEntity::getId).distinct().collect(Collectors.toList())).collectAs(new BaseFieldSet().ensure(DescriptionReference._description).ensure(DescriptionReference._reference)); +// +// Map> itemMap = new HashMap<>(); +// ReferenceQuery query = this.queryFactory.query(ReferenceQuery.class).authorize(this.authorize).isActive(IsActive.Active).ids(descriptionReferences.stream().map(DescriptionReferenceEntity::getReferenceId).distinct().collect(Collectors.toList())); +// Map referenceDepositModelMap = this.builderFactory.builder(ReferenceFileTransformerBuilder.class).authorize(this.authorize).asForeignKey(query, ReferenceEntity::getId); +// if (referenceDepositModelMap == null) return null; +// for (DescriptionReferenceEntity descriptionReference : descriptionReferences) { +// DescriptionReferenceFileTransformerModel descriptionReferenceFileTransformerModel = new DescriptionReferenceFileTransformerModel(); +// descriptionReferenceFileTransformerModel.setId(descriptionReference.getId()); +// descriptionReferenceFileTransformerModel.setReference(referenceDepositModelMap.getOrDefault(descriptionReference.getReferenceId(), null)); +// DescriptionReferenceFileTransformerModel model = descriptionReferenceFileTransformerModel; +// if (model == null) continue; +// UUID key = descriptionReference.getDescriptionId(); +// if (!itemMap.containsKey(key)) itemMap.put(key, new ArrayList<>()); +// itemMap.get(key).add(model); +// } +// return itemMap; +// } +// +// private Map> collectTags(List data) { +// if (data.isEmpty()) return null; +// +// List descriptionTags = this.queryFactory.query(DescriptionTagQuery.class).authorize(this.authorize).descriptionIds(data.stream().map(DescriptionEntity::getId).distinct().toList()).collect(); +// +// Map> itemMap = new HashMap<>(); +// TagQuery query = this.queryFactory.query(TagQuery.class).authorize(this.authorize).isActive(IsActive.Active).ids(descriptionTags.stream().map(DescriptionTagEntity::getTagId).distinct().toList()); +// Map tagMap = this.builderFactory.builder(TagFileTransformerBuilder.class).asForeignKey(query, TagEntity::getId); +// for (DescriptionTagEntity descriptionTag : descriptionTags) { +// DescriptionTagFileTransformerModel descriptionTagFileTransformerModel = new DescriptionTagFileTransformerModel(); +// descriptionTagFileTransformerModel.setId(descriptionTag.getId()); +// descriptionTagFileTransformerModel.setTagFileTransformerModel(tagMap.getOrDefault(descriptionTag.getTagId(), null)); +// DescriptionTagFileTransformerModel model = descriptionTagFileTransformerModel; +// if (model == null) continue; +// UUID key = descriptionTag.getDescriptionId(); +// if (!itemMap.containsKey(key)) itemMap.put(key, new ArrayList<>()); +// itemMap.get(key).add(model); +// } +// +// return itemMap; +// } +// +//} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DescriptionTemplateDefinitionFileTransformerBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DescriptionTemplateDefinitionFileTransformerBuilder.java index 6a53778b6..737c68302 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DescriptionTemplateDefinitionFileTransformerBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DescriptionTemplateDefinitionFileTransformerBuilder.java @@ -1,243 +1,243 @@ -package eu.eudat.model.builder.filetransformer; - -import eu.eudat.authorization.AuthorizationFlags; -import eu.eudat.commons.JsonHandlingService; -import eu.eudat.commons.XmlHandlingService; -import eu.eudat.commons.types.descriptiontemplate.*; -import eu.eudat.commons.types.descriptiontemplate.fielddata.*; -import eu.eudat.convention.ConventionService; -import eu.eudat.file.transformer.enums.FieldDataExternalDatasetType; -import eu.eudat.file.transformer.enums.FieldType; -import eu.eudat.file.transformer.enums.FieldValidationType; -import eu.eudat.file.transformer.models.descriptiontemplate.definition.*; -import eu.eudat.file.transformer.models.descriptiontemplate.definition.fielddata.*; -import gr.cite.tools.data.builder.BuilderFactory; -import gr.cite.tools.data.query.QueryFactory; -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 DescriptionTemplateDefinitionFileTransformerBuilder extends BaseFileTransformerBuilder { - - private final QueryFactory queryFactory; - - private final BuilderFactory builderFactory; - private final JsonHandlingService jsonHandlingService; - - private final XmlHandlingService xmlHandlingService; - private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - - @Autowired - public DescriptionTemplateDefinitionFileTransformerBuilder( - ConventionService conventionService, - QueryFactory queryFactory, - BuilderFactory builderFactory, JsonHandlingService jsonHandlingService, XmlHandlingService xmlHandlingService) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionTemplateDefinitionFileTransformerBuilder.class))); - this.queryFactory = queryFactory; - this.builderFactory = builderFactory; - this.jsonHandlingService = jsonHandlingService; - this.xmlHandlingService = xmlHandlingService; - } - - public DescriptionTemplateDefinitionFileTransformerBuilder authorize(EnumSet values) { - this.authorize = values; - return this; - } - - @Override - protected List> buildInternal(List 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> models = new ArrayList<>(); - for (DefinitionEntity d : data) { - DefinitionFileTransformerModel m = new DefinitionFileTransformerModel(); - m.setPages(collectPages(d.getPages())); - models.add(new FileTransformerBuilderItemResponse<>(m, d)); - } - - this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); - - return models; - } - - private List collectPages(List data) { - List result = new ArrayList<>(); - for (PageEntity d: data) { - PageFileTransformerModel m = new PageFileTransformerModel(); - m.setId(d.getId()); - m.setOrdinal(d.getOrdinal()); - m.setTitle(d.getTitle()); - if (d.getSections() != null) m.setSections(collectSections(d.getSections())); - result.add(m); - } - - return result; - } - - private List collectSections(List data) { - List result = new ArrayList<>(); - for (SectionEntity d : data) { - SectionFileTransformerModel m = new SectionFileTransformerModel(); - m.setId(d.getId()); - m.setDescription(d.getDescription()); - m.setTitle(d.getTitle()); - m.setOrdinal(d.getOrdinal()); - m.setDefaultVisibility(d.isDefaultVisibility()); - m.setExtendedDescription(d.getExtendedDescription()); - m.setMultiplicity(d.getMultiplicity()); - m.setNumbering(d.getNumbering()); - if (d.getSections() != null && !d.getSections().isEmpty()) { - m.setSections(collectSections(d.getSections())); - } - if (d.getFieldSets() != null && !d.getFieldSets().isEmpty()) { - m.setFieldSets(collectFieldSet(d.getFieldSets())); - } - result.add(m); - } - return result; - } - - private List collectFieldSet(List data) { - List result = new ArrayList<>(); - for (FieldSetEntity d : data) { - FieldSetFileTransformerModel m = new FieldSetFileTransformerModel(); - m.setId(d.getId()); - m.setDescription(d.getDescription()); - m.setExtendedDescription(d.getExtendedDescription()); - m.setAdditionalInformation(d.getAdditionalInformation()); - m.setHasCommentField(d.getHasCommentField()); - m.setNumbering(d.getNumbering()); - m.setOrdinal(d.getOrdinal()); - m.setTitle(d.getTitle()); - //m.setMultiplicity(); //TODO: No multiplicity in this code (yet) - m.setFields(convertFields(d.getFields())); - result.add(m); - } - return result; - } - - private List convertFields(List data) { - List result = new ArrayList<>(); - for (FieldEntity d : data) { - FieldFileTransformerModel m = new FieldFileTransformerModel(); - m.setId(d.getId()); - m.setSchematics(d.getSchematics()); - m.setNumbering(d.getNumbering()); - m.setOrdinal(d.getOrdinal()); - m.setDefaultValue(d.getDefaultValue()); - m.setIncludeInExport(d.getIncludeInExport()); - m.setValidations(d.getValidations().stream().map(fieldValidationType -> FieldValidationType.of(fieldValidationType.getValue())).toList()); - if (d.getVisibilityRules() != null && !d.getVisibilityRules().isEmpty()) { - m.setVisibilityRules(convertVisibilityRules(d.getVisibilityRules())); - } - m.setData(convertData(d.getData())); - result.add(m); - } - return result; - } - - public List convertVisibilityRules(List data) { - List result = new ArrayList<>(); - for (RuleEntity d : data) { - RuleFileTransformerModel m = new RuleFileTransformerModel(); - m.setTarget(d.getTarget()); - m.setValue(d.getValue()); - result.add(m); - } - return result; - } - - public BaseFieldDataFileTransformerModel convertData (BaseFieldDataEntity data) { - BaseFieldDataFileTransformerModel m; - switch (data) { //TODO new reference logic -// case ExternalSelectDataEntity d -> { -// m = new ExternalSelectDataFileTransformerModel(); +//package eu.eudat.model.builder.filetransformer; +// +//import eu.eudat.authorization.AuthorizationFlags; +//import eu.eudat.commons.JsonHandlingService; +//import eu.eudat.commons.XmlHandlingService; +//import eu.eudat.commons.types.descriptiontemplate.*; +//import eu.eudat.commons.types.descriptiontemplate.fielddata.*; +//import eu.eudat.convention.ConventionService; +//import eu.eudat.file.transformer.enums.FieldDataExternalDatasetType; +//import eu.eudat.file.transformer.enums.FieldType; +//import eu.eudat.file.transformer.enums.FieldValidationType; +//import eu.eudat.file.transformer.models.descriptiontemplate.definition.*; +//import eu.eudat.file.transformer.models.descriptiontemplate.definition.fielddata.*; +//import gr.cite.tools.data.builder.BuilderFactory; +//import gr.cite.tools.data.query.QueryFactory; +//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 DescriptionTemplateDefinitionFileTransformerBuilder extends BaseFileTransformerBuilder { +// +// private final QueryFactory queryFactory; +// +// private final BuilderFactory builderFactory; +// private final JsonHandlingService jsonHandlingService; +// +// private final XmlHandlingService xmlHandlingService; +// private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); +// +// @Autowired +// public DescriptionTemplateDefinitionFileTransformerBuilder( +// ConventionService conventionService, +// QueryFactory queryFactory, +// BuilderFactory builderFactory, JsonHandlingService jsonHandlingService, XmlHandlingService xmlHandlingService) { +// super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionTemplateDefinitionFileTransformerBuilder.class))); +// this.queryFactory = queryFactory; +// this.builderFactory = builderFactory; +// this.jsonHandlingService = jsonHandlingService; +// this.xmlHandlingService = xmlHandlingService; +// } +// +// public DescriptionTemplateDefinitionFileTransformerBuilder authorize(EnumSet values) { +// this.authorize = values; +// return this; +// } +// +// @Override +// protected List> buildInternal(List 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> models = new ArrayList<>(); +// for (DefinitionEntity d : data) { +// DefinitionFileTransformerModel m = new DefinitionFileTransformerModel(); +// m.setPages(collectPages(d.getPages())); +// models.add(new FileTransformerBuilderItemResponse<>(m, d)); +// } +// +// this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); +// +// return models; +// } +// +// private List collectPages(List data) { +// List result = new ArrayList<>(); +// for (PageEntity d: data) { +// PageFileTransformerModel m = new PageFileTransformerModel(); +// m.setId(d.getId()); +// m.setOrdinal(d.getOrdinal()); +// m.setTitle(d.getTitle()); +// if (d.getSections() != null) m.setSections(collectSections(d.getSections())); +// result.add(m); +// } +// +// return result; +// } +// +// private List collectSections(List data) { +// List result = new ArrayList<>(); +// for (SectionEntity d : data) { +// SectionFileTransformerModel m = new SectionFileTransformerModel(); +// m.setId(d.getId()); +// m.setDescription(d.getDescription()); +// m.setTitle(d.getTitle()); +// m.setOrdinal(d.getOrdinal()); +// m.setDefaultVisibility(d.isDefaultVisibility()); +// m.setExtendedDescription(d.getExtendedDescription()); +// m.setMultiplicity(d.getMultiplicity()); +// m.setNumbering(d.getNumbering()); +// if (d.getSections() != null && !d.getSections().isEmpty()) { +// m.setSections(collectSections(d.getSections())); +// } +// if (d.getFieldSets() != null && !d.getFieldSets().isEmpty()) { +// m.setFieldSets(collectFieldSet(d.getFieldSets())); +// } +// result.add(m); +// } +// return result; +// } +// +// private List collectFieldSet(List data) { +// List result = new ArrayList<>(); +// for (FieldSetEntity d : data) { +// FieldSetFileTransformerModel m = new FieldSetFileTransformerModel(); +// m.setId(d.getId()); +// m.setDescription(d.getDescription()); +// m.setExtendedDescription(d.getExtendedDescription()); +// m.setAdditionalInformation(d.getAdditionalInformation()); +// m.setHasCommentField(d.getHasCommentField()); +// m.setNumbering(d.getNumbering()); +// m.setOrdinal(d.getOrdinal()); +// m.setTitle(d.getTitle()); +// //m.setMultiplicity(); //TODO: No multiplicity in this code (yet) +// m.setFields(convertFields(d.getFields())); +// result.add(m); +// } +// return result; +// } +// +// private List convertFields(List data) { +// List result = new ArrayList<>(); +// for (FieldEntity d : data) { +// FieldFileTransformerModel m = new FieldFileTransformerModel(); +// m.setId(d.getId()); +// m.setSchematics(d.getSchematics()); +// m.setNumbering(d.getNumbering()); +// m.setOrdinal(d.getOrdinal()); +// m.setDefaultValue(d.getDefaultValue()); +// m.setIncludeInExport(d.getIncludeInExport()); +// m.setValidations(d.getValidations().stream().map(fieldValidationType -> FieldValidationType.of(fieldValidationType.getValue())).toList()); +// if (d.getVisibilityRules() != null && !d.getVisibilityRules().isEmpty()) { +// m.setVisibilityRules(convertVisibilityRules(d.getVisibilityRules())); +// } +// m.setData(convertData(d.getData())); +// result.add(m); +// } +// return result; +// } +// +// public List convertVisibilityRules(List data) { +// List result = new ArrayList<>(); +// for (RuleEntity d : data) { +// RuleFileTransformerModel m = new RuleFileTransformerModel(); +// m.setTarget(d.getTarget()); +// m.setValue(d.getValue()); +// result.add(m); +// } +// return result; +// } +// +// public BaseFieldDataFileTransformerModel convertData (BaseFieldDataEntity data) { +// BaseFieldDataFileTransformerModel m; +// switch (data) { //TODO new reference logic +//// case ExternalSelectDataEntity d -> { +//// m = new ExternalSelectDataFileTransformerModel(); +//// m.setLabel(d.getLabel()); +//// m.setFieldType(FieldType.of(d.getFieldType().getValue())); +//// ((ExternalSelectDataFileTransformerModel)m).setMultipleSelect(d.getMultipleSelect()); +//// ((ExternalSelectDataFileTransformerModel) m).setSources(convertAutoCompleteSingleData(d.getSources())); +//// } +//// case ExternalDatasetDataEntity d -> { +//// m = new ExternalDatasetDataFileTransformerModel(); +//// m.setLabel(d.getLabel()); +//// m.setFieldType(FieldType.of(d.getFieldType().getValue())); +//// ((ExternalDatasetDataFileTransformerModel)m).setType(FieldDataExternalDatasetType.of(d.getType().getValue())); +//// } +// case RadioBoxDataEntity d -> { +// m = new RadioBoxDataFileTransformerModel(); // m.setLabel(d.getLabel()); // m.setFieldType(FieldType.of(d.getFieldType().getValue())); -// ((ExternalSelectDataFileTransformerModel)m).setMultipleSelect(d.getMultipleSelect()); -// ((ExternalSelectDataFileTransformerModel) m).setSources(convertAutoCompleteSingleData(d.getSources())); +// ((RadioBoxDataFileTransformerModel) m).setOptions(convertRadioBoxOptions(d.getOptions())); // } -// case ExternalDatasetDataEntity d -> { -// m = new ExternalDatasetDataFileTransformerModel(); +// case UploadDataEntity d -> { +// m = new UploadDataFileTransformerModel(); // m.setLabel(d.getLabel()); // m.setFieldType(FieldType.of(d.getFieldType().getValue())); -// ((ExternalDatasetDataFileTransformerModel)m).setType(FieldDataExternalDatasetType.of(d.getType().getValue())); +// ((UploadDataFileTransformerModel) m).setMaxFileSizeInMB(d.getMaxFileSizeInMB()); +// ((UploadDataFileTransformerModel) m).setTypes(convertUploadDataOptions(d.getTypes())); // } - case RadioBoxDataEntity d -> { - m = new RadioBoxDataFileTransformerModel(); - m.setLabel(d.getLabel()); - m.setFieldType(FieldType.of(d.getFieldType().getValue())); - ((RadioBoxDataFileTransformerModel) m).setOptions(convertRadioBoxOptions(d.getOptions())); - } - case UploadDataEntity d -> { - m = new UploadDataFileTransformerModel(); - m.setLabel(d.getLabel()); - m.setFieldType(FieldType.of(d.getFieldType().getValue())); - ((UploadDataFileTransformerModel) m).setMaxFileSizeInMB(d.getMaxFileSizeInMB()); - ((UploadDataFileTransformerModel) m).setTypes(convertUploadDataOptions(d.getTypes())); - } - case SelectDataEntity d -> { - m = new SelectDataFileTransformerModel(); - m.setLabel(d.getLabel()); - m.setFieldType(FieldType.of(d.getFieldType().getValue())); - ((SelectDataFileTransformerModel) m).setMultipleSelect(d.getMultipleSelect()); - ((SelectDataFileTransformerModel) m).setOptions(d.getOptions().stream().map(this::convertComboBoxOption).toList()); - } - case LabelAndMultiplicityDataEntity d -> { - m = new LabelAndMultiplicityDataFileTransformerModel(); - m.setLabel(d.getLabel()); - m.setFieldType(FieldType.of(d.getFieldType().getValue())); - ((LabelAndMultiplicityDataFileTransformerModel)m).setMultipleSelect(d.getMultipleSelect()); - } - default -> { - m = new LabelDataFileTransformerModel(); - m.setLabel(data.getLabel()); - m.setFieldType(FieldType.of(data.getFieldType().getValue())); - } - } - return m; - } - - private List convertRadioBoxOptions(List data) { - List result = new ArrayList<>(); - for (RadioBoxDataEntity.RadioBoxDataOptionEntity d : data) { - RadioBoxDataFileTransformerModel.RadioBoxDataOptionFileTransformerModel m = new RadioBoxDataFileTransformerModel.RadioBoxDataOptionFileTransformerModel(); - m.setLabel(d.getLabel()); - m.setValue(d.getValue()); - result.add(m); - } - return result; - } - - private SelectDataFileTransformerModel.OptionFileTransformerModel convertComboBoxOption(SelectDataEntity.OptionEntity data) { - SelectDataFileTransformerModel.OptionFileTransformerModel m = new SelectDataFileTransformerModel.OptionFileTransformerModel(); - m.setLabel(data.getLabel()); - m.setValue(data.getValue()); - return m; - } - - private List convertUploadDataOptions(List data) { - List result = new ArrayList<>(); - for (UploadDataEntity.UploadDataOptionEntity d : data) { - UploadDataFileTransformerModel.UploadDataOptionFileTransformerModel m = new UploadDataFileTransformerModel.UploadDataOptionFileTransformerModel(); - m.setLabel(d.getLabel()); - m.setValue(d.getValue()); - result.add(m); - } - return result; - } - - -} +// case SelectDataEntity d -> { +// m = new SelectDataFileTransformerModel(); +// m.setLabel(d.getLabel()); +// m.setFieldType(FieldType.of(d.getFieldType().getValue())); +// ((SelectDataFileTransformerModel) m).setMultipleSelect(d.getMultipleSelect()); +// ((SelectDataFileTransformerModel) m).setOptions(d.getOptions().stream().map(this::convertComboBoxOption).toList()); +// } +// case LabelAndMultiplicityDataEntity d -> { +// m = new LabelAndMultiplicityDataFileTransformerModel(); +// m.setLabel(d.getLabel()); +// m.setFieldType(FieldType.of(d.getFieldType().getValue())); +// ((LabelAndMultiplicityDataFileTransformerModel)m).setMultipleSelect(d.getMultipleSelect()); +// } +// default -> { +// m = new LabelDataFileTransformerModel(); +// m.setLabel(data.getLabel()); +// m.setFieldType(FieldType.of(data.getFieldType().getValue())); +// } +// } +// return m; +// } +// +// private List convertRadioBoxOptions(List data) { +// List result = new ArrayList<>(); +// for (RadioBoxDataEntity.RadioBoxDataOptionEntity d : data) { +// RadioBoxDataFileTransformerModel.RadioBoxDataOptionFileTransformerModel m = new RadioBoxDataFileTransformerModel.RadioBoxDataOptionFileTransformerModel(); +// m.setLabel(d.getLabel()); +// m.setValue(d.getValue()); +// result.add(m); +// } +// return result; +// } +// +// private SelectDataFileTransformerModel.OptionFileTransformerModel convertComboBoxOption(SelectDataEntity.OptionEntity data) { +// SelectDataFileTransformerModel.OptionFileTransformerModel m = new SelectDataFileTransformerModel.OptionFileTransformerModel(); +// m.setLabel(data.getLabel()); +// m.setValue(data.getValue()); +// return m; +// } +// +// private List convertUploadDataOptions(List data) { +// List result = new ArrayList<>(); +// for (UploadDataEntity.UploadDataOptionEntity d : data) { +// UploadDataFileTransformerModel.UploadDataOptionFileTransformerModel m = new UploadDataFileTransformerModel.UploadDataOptionFileTransformerModel(); +// m.setLabel(d.getLabel()); +// m.setValue(d.getValue()); +// result.add(m); +// } +// return result; +// } +// +// +//} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DescriptionTemplateFileTransformerBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DescriptionTemplateFileTransformerBuilder.java index bb504f395..d6038f986 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DescriptionTemplateFileTransformerBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DescriptionTemplateFileTransformerBuilder.java @@ -1,83 +1,83 @@ -package eu.eudat.model.builder.filetransformer; - -import eu.eudat.authorization.AuthorizationFlags; -import eu.eudat.commons.JsonHandlingService; -import eu.eudat.commons.XmlHandlingService; -import eu.eudat.convention.ConventionService; -import eu.eudat.data.DescriptionTemplateEntity; -import eu.eudat.file.transformer.models.descriptiontemplate.DescriptionTemplateFileTransformerModel; -import eu.eudat.query.DescriptionTemplateQuery; -import gr.cite.tools.data.builder.BuilderFactory; -import gr.cite.tools.data.query.QueryFactory; -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 DescriptionTemplateFileTransformerBuilder extends BaseFileTransformerBuilder { - - private final QueryFactory queryFactory; - - private final BuilderFactory builderFactory; - private final JsonHandlingService jsonHandlingService; - - private final XmlHandlingService xmlHandlingService; - private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - - @Autowired - public DescriptionTemplateFileTransformerBuilder( - ConventionService conventionService, - QueryFactory queryFactory, - BuilderFactory builderFactory, JsonHandlingService jsonHandlingService, XmlHandlingService xmlHandlingService) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionTemplateFileTransformerBuilder.class))); - this.queryFactory = queryFactory; - this.builderFactory = builderFactory; - this.jsonHandlingService = jsonHandlingService; - this.xmlHandlingService = xmlHandlingService; - } - - public DescriptionTemplateFileTransformerBuilder authorize(EnumSet values) { - this.authorize = values; - return this; - } - - @Override - protected List> buildInternal(List data) throws MyApplicationException { - this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0)); - if (data == null || data.isEmpty()) return new ArrayList<>(); - - data = queryFactory.query(DescriptionTemplateQuery.class).ids(data.stream().map(DescriptionTemplateEntity::getId).toList()).collect(); - List> models = new ArrayList<>(); - for (DescriptionTemplateEntity d : data) { - - DescriptionTemplateFileTransformerModel m = new DescriptionTemplateFileTransformerModel(); - m.setId(d.getId()); - m.setLabel(d.getLabel()); - m.setDescription(d.getDescription()); - m.setLanguage(d.getLanguage()); - m.setVersion(d.getVersion()); - m.setDefinition(this.builderFactory.builder(DescriptionTemplateDefinitionFileTransformerBuilder.class).authorize(authorize).build(collectDescriptionTemplates(d))); - - models.add(new FileTransformerBuilderItemResponse<>(m, d)); - } - - this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); - - return models; - } - - private eu.eudat.commons.types.descriptiontemplate.DefinitionEntity collectDescriptionTemplates(DescriptionTemplateEntity data) throws MyApplicationException { - return this.xmlHandlingService.fromXmlSafe(eu.eudat.commons.types.descriptiontemplate.DefinitionEntity.class, data.getDefinition()); - } - -} +//package eu.eudat.model.builder.filetransformer; +// +//import eu.eudat.authorization.AuthorizationFlags; +//import eu.eudat.commons.JsonHandlingService; +//import eu.eudat.commons.XmlHandlingService; +//import eu.eudat.convention.ConventionService; +//import eu.eudat.data.DescriptionTemplateEntity; +//import eu.eudat.file.transformer.models.descriptiontemplate.DescriptionTemplateFileTransformerModel; +//import eu.eudat.query.DescriptionTemplateQuery; +//import gr.cite.tools.data.builder.BuilderFactory; +//import gr.cite.tools.data.query.QueryFactory; +//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 DescriptionTemplateFileTransformerBuilder extends BaseFileTransformerBuilder { +// +// private final QueryFactory queryFactory; +// +// private final BuilderFactory builderFactory; +// private final JsonHandlingService jsonHandlingService; +// +// private final XmlHandlingService xmlHandlingService; +// private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); +// +// @Autowired +// public DescriptionTemplateFileTransformerBuilder( +// ConventionService conventionService, +// QueryFactory queryFactory, +// BuilderFactory builderFactory, JsonHandlingService jsonHandlingService, XmlHandlingService xmlHandlingService) { +// super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionTemplateFileTransformerBuilder.class))); +// this.queryFactory = queryFactory; +// this.builderFactory = builderFactory; +// this.jsonHandlingService = jsonHandlingService; +// this.xmlHandlingService = xmlHandlingService; +// } +// +// public DescriptionTemplateFileTransformerBuilder authorize(EnumSet values) { +// this.authorize = values; +// return this; +// } +// +// @Override +// protected List> buildInternal(List data) throws MyApplicationException { +// this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0)); +// if (data == null || data.isEmpty()) return new ArrayList<>(); +// +// data = queryFactory.query(DescriptionTemplateQuery.class).ids(data.stream().map(DescriptionTemplateEntity::getId).toList()).collect(); +// List> models = new ArrayList<>(); +// for (DescriptionTemplateEntity d : data) { +// +// DescriptionTemplateFileTransformerModel m = new DescriptionTemplateFileTransformerModel(); +// m.setId(d.getId()); +// m.setLabel(d.getLabel()); +// m.setDescription(d.getDescription()); +// m.setLanguage(d.getLanguage()); +// m.setVersion(d.getVersion()); +// m.setDefinition(this.builderFactory.builder(DescriptionTemplateDefinitionFileTransformerBuilder.class).authorize(authorize).build(collectDescriptionTemplates(d))); +// +// models.add(new FileTransformerBuilderItemResponse<>(m, d)); +// } +// +// this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); +// +// return models; +// } +// +// private eu.eudat.commons.types.descriptiontemplate.DefinitionEntity collectDescriptionTemplates(DescriptionTemplateEntity data) throws MyApplicationException { +// return this.xmlHandlingService.fromXmlSafe(eu.eudat.commons.types.descriptiontemplate.DefinitionEntity.class, data.getDefinition()); +// } +// +//} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DmpBlueprintFileTransformerBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DmpBlueprintFileTransformerBuilder.java index 9e07b29f9..590cf07df 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DmpBlueprintFileTransformerBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DmpBlueprintFileTransformerBuilder.java @@ -1,129 +1,129 @@ -package eu.eudat.model.builder.filetransformer; - -import com.fasterxml.jackson.core.JsonProcessingException; -import eu.eudat.authorization.AuthorizationFlags; -import eu.eudat.commons.JsonHandlingService; -import eu.eudat.commons.XmlHandlingService; -import eu.eudat.commons.types.dmpblueprint.*; -import eu.eudat.convention.ConventionService; -import eu.eudat.data.DmpBlueprintEntity; -import eu.eudat.file.transformer.enums.DmpBlueprintExtraFieldDataType; -import eu.eudat.file.transformer.enums.DmpBlueprintSystemFieldType; -import eu.eudat.file.transformer.models.dmpblueprint.DmpBlueprintFileTransformerModel; -import eu.eudat.file.transformer.models.dmpblueprint.definition.*; -import eu.eudat.query.DmpBlueprintQuery; -import gr.cite.tools.data.builder.BuilderFactory; -import gr.cite.tools.data.query.QueryFactory; -import gr.cite.tools.exception.MyApplicationException; -import gr.cite.tools.logging.LoggerService; -import org.apache.commons.lang3.NotImplementedException; -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.*; - -@Component -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class DmpBlueprintFileTransformerBuilder extends BaseFileTransformerBuilder { - - private final QueryFactory queryFactory; - - private final BuilderFactory builderFactory; - private final JsonHandlingService jsonHandlingService; - - private final XmlHandlingService xmlHandlingService; - private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - - @Autowired - public DmpBlueprintFileTransformerBuilder( - ConventionService conventionService, - QueryFactory queryFactory, - BuilderFactory builderFactory, JsonHandlingService jsonHandlingService, XmlHandlingService xmlHandlingService) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpBlueprintFileTransformerBuilder.class))); - this.queryFactory = queryFactory; - this.builderFactory = builderFactory; - this.jsonHandlingService = jsonHandlingService; - this.xmlHandlingService = xmlHandlingService; - } - - public DmpBlueprintFileTransformerBuilder authorize(EnumSet values) { - this.authorize = values; - return this; - } - - @Override - protected List> buildInternal(List data) throws MyApplicationException { - this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0)); - if (data == null || data.isEmpty()) return new ArrayList<>(); - - data = queryFactory.query(DmpBlueprintQuery.class).ids(data.stream().map(DmpBlueprintEntity::getId).toList()).collect(); - List> models = new ArrayList<>(); - for (DmpBlueprintEntity d : data) { - - DmpBlueprintFileTransformerModel m = new DmpBlueprintFileTransformerModel(); - m.setId(d.getId()); - m.setLabel(d.getLabel()); - try { - m.setDefinitionFileTransformerModel(getDefinition(d.getDefinition())); - } catch (JsonProcessingException e) { - logger.error(e.getMessage(), e); - } - models.add(new FileTransformerBuilderItemResponse<>(m, d)); - } - - this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); - - return models; - } - - private DefinitionFileTransformerModel getDefinition(String source) throws JsonProcessingException { - DefinitionFileTransformerModel result = new DefinitionFileTransformerModel(); - result.setSections(new ArrayList<>()); - DefinitionEntity parsedDefinition = xmlHandlingService.fromXmlSafe(DefinitionEntity.class, source); - List sections = parsedDefinition.getSections(); - sections.forEach(section -> { - SectionFileTransformerModel m = new SectionFileTransformerModel(); - m.setId(section.getId()); - m.setLabel(section.getLabel()); - m.setOrdinal(section.getOrdinal()); - m.setDescription(section.getDescription()); - if (section.getFields() != null && !section.getFields().isEmpty()) { - m.setFields(mapFields(section.getFields())); - } - m.setHasTemplates(section.getHasTemplates()); - result.getSections().add(m); - }); - - return result; - } - - private List mapFields(List fieldEntities) { - List result = new ArrayList<>(); - fieldEntities.forEach(fieldEntity -> { - FieldFileTransformerModel m = switch (fieldEntity.getCategory()) { - case System -> new SystemFieldFileTransformerModel(); - case Extra -> new ExtraFieldFileTransformerModelFileTransformerModel(); - case ReferenceType -> throw new NotImplementedException("ReferenceFieldFileTransformerModel"); - default -> throw new MyApplicationException("unrecognized type " + fieldEntity.getCategory()); - }; - m.setId(fieldEntity.getId()); - m.setLabel(fieldEntity.getLabel()); - m.setDescription(fieldEntity.getDescription()); - m.setOrdinal(fieldEntity.getOrdinal()); - m.setPlaceholder(fieldEntity.getPlaceholder()); - m.setRequired(fieldEntity.isRequired()); - switch (m) { - case SystemFieldFileTransformerModel sm -> sm.setSystemFieldType(DmpBlueprintSystemFieldType.of(((SystemFieldEntity)fieldEntity).getType().getValue())); - case ExtraFieldFileTransformerModelFileTransformerModel sm -> sm.setDataType(DmpBlueprintExtraFieldDataType.of(((ExtraFieldEntity)fieldEntity).getType().getValue())); -// case ReferenceFieldFileTransformerModelFileTransformerModel sm -> sm.setReferenceTypeId(((ReferenceFieldEntity)fieldEntity).getReferenceTypeId()); - default -> throw new MyApplicationException("unrecognized type " + fieldEntity.getCategory()); - } - result.add(m); - }); - return result; - } - -} +//package eu.eudat.model.builder.filetransformer; +// +//import com.fasterxml.jackson.core.JsonProcessingException; +//import eu.eudat.authorization.AuthorizationFlags; +//import eu.eudat.commons.JsonHandlingService; +//import eu.eudat.commons.XmlHandlingService; +//import eu.eudat.commons.types.dmpblueprint.*; +//import eu.eudat.convention.ConventionService; +//import eu.eudat.data.DmpBlueprintEntity; +//import eu.eudat.file.transformer.enums.DmpBlueprintExtraFieldDataType; +//import eu.eudat.file.transformer.enums.DmpBlueprintSystemFieldType; +//import eu.eudat.file.transformer.models.dmpblueprint.DmpBlueprintFileTransformerModel; +//import eu.eudat.file.transformer.models.dmpblueprint.definition.*; +//import eu.eudat.query.DmpBlueprintQuery; +//import gr.cite.tools.data.builder.BuilderFactory; +//import gr.cite.tools.data.query.QueryFactory; +//import gr.cite.tools.exception.MyApplicationException; +//import gr.cite.tools.logging.LoggerService; +//import org.apache.commons.lang3.NotImplementedException; +//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.*; +// +//@Component +//@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +//public class DmpBlueprintFileTransformerBuilder extends BaseFileTransformerBuilder { +// +// private final QueryFactory queryFactory; +// +// private final BuilderFactory builderFactory; +// private final JsonHandlingService jsonHandlingService; +// +// private final XmlHandlingService xmlHandlingService; +// private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); +// +// @Autowired +// public DmpBlueprintFileTransformerBuilder( +// ConventionService conventionService, +// QueryFactory queryFactory, +// BuilderFactory builderFactory, JsonHandlingService jsonHandlingService, XmlHandlingService xmlHandlingService) { +// super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpBlueprintFileTransformerBuilder.class))); +// this.queryFactory = queryFactory; +// this.builderFactory = builderFactory; +// this.jsonHandlingService = jsonHandlingService; +// this.xmlHandlingService = xmlHandlingService; +// } +// +// public DmpBlueprintFileTransformerBuilder authorize(EnumSet values) { +// this.authorize = values; +// return this; +// } +// +// @Override +// protected List> buildInternal(List data) throws MyApplicationException { +// this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0)); +// if (data == null || data.isEmpty()) return new ArrayList<>(); +// +// data = queryFactory.query(DmpBlueprintQuery.class).ids(data.stream().map(DmpBlueprintEntity::getId).toList()).collect(); +// List> models = new ArrayList<>(); +// for (DmpBlueprintEntity d : data) { +// +// DmpBlueprintFileTransformerModel m = new DmpBlueprintFileTransformerModel(); +// m.setId(d.getId()); +// m.setLabel(d.getLabel()); +// try { +// m.setDefinitionFileTransformerModel(getDefinition(d.getDefinition())); +// } catch (JsonProcessingException e) { +// logger.error(e.getMessage(), e); +// } +// models.add(new FileTransformerBuilderItemResponse<>(m, d)); +// } +// +// this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); +// +// return models; +// } +// +// private DefinitionFileTransformerModel getDefinition(String source) throws JsonProcessingException { +// DefinitionFileTransformerModel result = new DefinitionFileTransformerModel(); +// result.setSections(new ArrayList<>()); +// DefinitionEntity parsedDefinition = xmlHandlingService.fromXmlSafe(DefinitionEntity.class, source); +// List sections = parsedDefinition.getSections(); +// sections.forEach(section -> { +// SectionFileTransformerModel m = new SectionFileTransformerModel(); +// m.setId(section.getId()); +// m.setLabel(section.getLabel()); +// m.setOrdinal(section.getOrdinal()); +// m.setDescription(section.getDescription()); +// if (section.getFields() != null && !section.getFields().isEmpty()) { +// m.setFields(mapFields(section.getFields())); +// } +// m.setHasTemplates(section.getHasTemplates()); +// result.getSections().add(m); +// }); +// +// return result; +// } +// +// private List mapFields(List fieldEntities) { +// List result = new ArrayList<>(); +// fieldEntities.forEach(fieldEntity -> { +// FieldFileTransformerModel m = switch (fieldEntity.getCategory()) { +// case System -> new SystemFieldFileTransformerModel(); +// case Extra -> new ExtraFieldFileTransformerModelFileTransformerModel(); +// case ReferenceType -> throw new NotImplementedException("ReferenceFieldFileTransformerModel"); +// default -> throw new MyApplicationException("unrecognized type " + fieldEntity.getCategory()); +// }; +// m.setId(fieldEntity.getId()); +// m.setLabel(fieldEntity.getLabel()); +// m.setDescription(fieldEntity.getDescription()); +// m.setOrdinal(fieldEntity.getOrdinal()); +// m.setPlaceholder(fieldEntity.getPlaceholder()); +// m.setRequired(fieldEntity.isRequired()); +// switch (m) { +// case SystemFieldFileTransformerModel sm -> sm.setSystemFieldType(DmpBlueprintSystemFieldType.of(((SystemFieldEntity)fieldEntity).getType().getValue())); +// case ExtraFieldFileTransformerModelFileTransformerModel sm -> sm.setDataType(DmpBlueprintExtraFieldDataType.of(((ExtraFieldEntity)fieldEntity).getType().getValue())); +//// case ReferenceFieldFileTransformerModelFileTransformerModel sm -> sm.setReferenceTypeId(((ReferenceFieldEntity)fieldEntity).getReferenceTypeId()); +// default -> throw new MyApplicationException("unrecognized type " + fieldEntity.getCategory()); +// } +// result.add(m); +// }); +// return result; +// } +// +//} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DmpFileTransformerBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DmpFileTransformerBuilder.java index d87455315..e7e97dc20 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DmpFileTransformerBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DmpFileTransformerBuilder.java @@ -1,200 +1,200 @@ -package eu.eudat.model.builder.filetransformer; - -import eu.eudat.authorization.AuthorizationFlags; -import eu.eudat.commons.enums.IsActive; -import eu.eudat.convention.ConventionService; -import eu.eudat.data.*; -import eu.eudat.file.transformer.enums.DmpAccessType; -import eu.eudat.file.transformer.enums.DmpStatus; -import eu.eudat.file.transformer.enums.DmpVersionStatus; -import eu.eudat.file.transformer.models.description.DescriptionFileTransformerModel; -import eu.eudat.file.transformer.models.dmp.DmpFileTransformerModel; -import eu.eudat.file.transformer.models.dmp.DmpReferenceFileTransformerModel; -import eu.eudat.file.transformer.models.dmp.DmpUserFileTransformerModel; -import eu.eudat.file.transformer.models.dmpblueprint.DmpBlueprintFileTransformerModel; -import eu.eudat.file.transformer.models.dmpblueprint.definition.SectionFileTransformerModel; -import eu.eudat.file.transformer.models.entitydoi.EntityDoiFileTransformerModel; -import eu.eudat.file.transformer.models.reference.ReferenceFileTransformerModel; -import eu.eudat.file.transformer.models.user.UserFileTransformerModel; -import eu.eudat.model.*; -import eu.eudat.model.builder.DmpReferenceBuilder; -import eu.eudat.query.*; -import gr.cite.tools.data.builder.BuilderFactory; -import gr.cite.tools.data.query.Ordering; -import gr.cite.tools.data.query.QueryFactory; -import gr.cite.tools.exception.MyApplicationException; -import gr.cite.tools.fieldset.BaseFieldSet; -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.time.Instant; -import java.util.*; -import java.util.stream.Collectors; - -@Component -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class DmpFileTransformerBuilder extends BaseFileTransformerBuilder { - - private final QueryFactory queryFactory; - private final BuilderFactory builderFactory; - private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - - private Boolean ignoreDescriptions = false; - - @Autowired - public DmpFileTransformerBuilder(ConventionService conventionService, - QueryFactory queryFactory, - BuilderFactory builderFactory) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpFileTransformerBuilder.class))); - this.queryFactory = queryFactory; - this.builderFactory = builderFactory; - } - - public DmpFileTransformerBuilder authorize(EnumSet values) { - this.authorize = values; - return this; - } - - public DmpFileTransformerBuilder ignoreDescriptions(Boolean ignoreDescriptions) { - this.ignoreDescriptions = ignoreDescriptions; - return this; - } - - @Override - protected List> buildInternal(List 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> models = new ArrayList<>(); - - Map> dmpReferencesMap = this.collectReferences(data); - - Map> dmpUsersMap = this.collectDmpUsers(data); - - Map> descriptionsMap = null; - if (!ignoreDescriptions) { - descriptionsMap = this.collectDmpDescriptions(data); - } - - Map> doiMap = this.collectEntityDois(data); - Map creatorMap = this.collectCreators(data); - Map blueprintMap = this.collectBlueprints(data); - - for (DmpEntity d : data) { - DmpFileTransformerModel m = new DmpFileTransformerModel(); - m.setId(d.getId()); - m.setLabel(d.getLabel()); - m.setVersion(d.getVersion()); - m.setDescription(d.getDescription()); - m.setFinalizedAt(d.getFinalizedAt()); - m.setCreatedAt(d.getCreatedAt()); - if (d.getPublicAfter() != null && d.getPublicAfter().isAfter(Instant.now())) { - m.setPublishedAt(d.getPublicAfter()); - } - switch (d.getAccessType()){ - case Public -> m.setAccessType(DmpAccessType.Public); - case Restricted -> m.setAccessType(DmpAccessType.Restricted); - case null -> m.setAccessType(null); - default -> throw new MyApplicationException("unrecognized type " + d.getAccessType().getValue()); - } - - m.setProperties(d.getProperties()); - m.setUpdatedAt(d.getUpdatedAt()); - m.setLanguage(d.getLanguage()); - m.setStatus(DmpStatus.of(d.getStatus().getValue())); - m.setVersionStatus(DmpVersionStatus.of(d.getVersionStatus().getValue())); - if (dmpReferencesMap != null && !dmpReferencesMap.isEmpty() && dmpReferencesMap.containsKey(d.getId())) m.setDmpReferences(dmpReferencesMap.get(d.getId())); - if (dmpUsersMap != null && !dmpUsersMap.isEmpty() && dmpUsersMap.containsKey(d.getId())) m.setDmpUsers(dmpUsersMap.get(d.getId())); - if (descriptionsMap != null && !descriptionsMap.isEmpty() && descriptionsMap.containsKey(d.getId())) m.setDescriptions(descriptionsMap.get(d.getId())); - if (doiMap != null && !doiMap.isEmpty() && doiMap.containsKey(d.getId())) m.setEntityDois(doiMap.get(d.getId())); - if (creatorMap != null && !creatorMap.isEmpty() && creatorMap.containsKey(d.getId())) m.setCreator(creatorMap.get(d.getId())); - if (blueprintMap != null && !blueprintMap.isEmpty() && blueprintMap.containsKey(d.getBlueprintId())) m.setBlueprint(blueprintMap.get(d.getBlueprintId())); - - SectionFileTransformerModel templateSection = m.getBlueprint().getDefinitionFileTransformerModel().getSections().stream().filter(SectionFileTransformerModel::getHasTemplates).findFirst().orElse(null); - if (templateSection != null && m.getDescriptions() != null && !m.getDescriptions().isEmpty()) { - m.getDescriptions().forEach(description -> { - description.setSectionId(templateSection.getId()); - description.setCreatedBy(m.getCreator()); - }); - } - - models.add(new FileTransformerBuilderItemResponse<>(m, d)); - } - this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); - - return models; - } - - private Map> collectReferences(List data) throws MyApplicationException { - if (data.isEmpty()) return null; - this.logger.debug("checking related - {}", DmpReference.class.getSimpleName()); - - List dmpReferences = this.queryFactory.query(DmpReferenceQuery.class).isActives(IsActive.Active).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList())).collectAs(new BaseFieldSet().ensure(DmpReference._dmp).ensure(DmpReference._reference)); - - Map> itemMap = new HashMap<>(); - ReferenceQuery query = this.queryFactory.query(ReferenceQuery.class).authorize(this.authorize).isActive(IsActive.Active).ids(dmpReferences.stream().map(DmpReferenceEntity::getReferenceId).distinct().collect(Collectors.toList())); - Map referenceDepositModelMap = this.builderFactory.builder(ReferenceFileTransformerBuilder.class).authorize(this.authorize).asForeignKey(query, ReferenceEntity::getId); - if (referenceDepositModelMap == null) return null; - for (DmpReferenceEntity dmpReference : dmpReferences) { - DmpReferenceFileTransformerModel dmpReferenceFileTransformerModel = new DmpReferenceFileTransformerModel(); - dmpReferenceFileTransformerModel.setId(dmpReference.getId()); - dmpReferenceFileTransformerModel.setData(dmpReference.getData()); - dmpReferenceFileTransformerModel.setReference(referenceDepositModelMap.getOrDefault(dmpReference.getReferenceId(), null)); - DmpReferenceFileTransformerModel model = dmpReferenceFileTransformerModel; - if (model == null) continue; - UUID key = dmpReference.getDmpId(); - if (!itemMap.containsKey(key)) itemMap.put(key, new ArrayList<>()); - itemMap.get(key).add(model); - } - return itemMap; - } - - - private Map> collectDmpUsers(List data) throws MyApplicationException { - this.logger.debug("checking related - {}", DmpUser.class.getSimpleName()); - - Map> itemMap; - DmpUserQuery query = this.queryFactory.query(DmpUserQuery.class).isActives(IsActive.Active).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList())); - itemMap = this.builderFactory.builder(DmpUserFileTransformerBuilder.class).authorize(this.authorize).asMasterKey(query, DmpUserEntity::getDmpId); - - return itemMap; - } - - private Map> collectDmpDescriptions(List data) throws MyApplicationException { - if (data.isEmpty()) return null; - this.logger.debug("checking related - {}", Description.class.getSimpleName()); - - Map> itemMap; - DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).isActive(IsActive.Active).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList())); - itemMap = this.builderFactory.builder(DescriptionFileTransformerBuilder.class).authorize(this.authorize).asMasterKey(query, DescriptionEntity::getDmpId); - - return itemMap; - } - - private Map collectCreators(List data) { - DmpUserQuery query = this.queryFactory.query(DmpUserQuery.class).isActives(IsActive.Active).authorize(this.authorize).userIds(data.stream().map(DmpEntity::getCreatorId).toList()); - return this.builderFactory.builder(DmpUserFileTransformerBuilder.class).authorize(this.authorize).asMasterKey(query, DmpUserEntity::getDmpId) - .entrySet().stream().map(uuidListEntry -> Map.entry(uuidListEntry.getKey(), uuidListEntry.getValue().get(0).getUser())) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - } - - private Map collectBlueprints(List data) { - DmpBlueprintQuery query = this.queryFactory.query(DmpBlueprintQuery.class).isActive(IsActive.Active).authorize(this.authorize).ids(data.stream().map(DmpEntity::getBlueprintId).toList()); - return this.builderFactory.builder(DmpBlueprintFileTransformerBuilder.class).authorize(this.authorize).asMasterKey(query, DmpBlueprintEntity::getId) - .entrySet().stream().map(uuidListEntry -> Map.entry(uuidListEntry.getKey(), uuidListEntry.getValue().get(0))) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - } - - private Map> collectEntityDois(List data) { - if (data.isEmpty()) return null; - Map> result; - EntityDoiQuery query = this.queryFactory.query(EntityDoiQuery.class).isActive(IsActive.Active).authorize(authorize).entityIds(data.stream().map(DmpEntity::getId).distinct().toList()); - result = builderFactory.builder(EntityDoiFileTransformerBuilder.class).asMasterKey(query, EntityDoiEntity::getEntityId); - return result; - } - -} +//package eu.eudat.model.builder.filetransformer; +// +//import eu.eudat.authorization.AuthorizationFlags; +//import eu.eudat.commons.enums.IsActive; +//import eu.eudat.convention.ConventionService; +//import eu.eudat.data.*; +//import eu.eudat.file.transformer.enums.DmpAccessType; +//import eu.eudat.file.transformer.enums.DmpStatus; +//import eu.eudat.file.transformer.enums.DmpVersionStatus; +//import eu.eudat.file.transformer.models.description.DescriptionFileTransformerModel; +//import eu.eudat.file.transformer.models.dmp.DmpFileTransformerModel; +//import eu.eudat.file.transformer.models.dmp.DmpReferenceFileTransformerModel; +//import eu.eudat.file.transformer.models.dmp.DmpUserFileTransformerModel; +//import eu.eudat.file.transformer.models.dmpblueprint.DmpBlueprintFileTransformerModel; +//import eu.eudat.file.transformer.models.dmpblueprint.definition.SectionFileTransformerModel; +//import eu.eudat.file.transformer.models.entitydoi.EntityDoiFileTransformerModel; +//import eu.eudat.file.transformer.models.reference.ReferenceFileTransformerModel; +//import eu.eudat.file.transformer.models.user.UserFileTransformerModel; +//import eu.eudat.model.*; +//import eu.eudat.model.builder.DmpReferenceBuilder; +//import eu.eudat.query.*; +//import gr.cite.tools.data.builder.BuilderFactory; +//import gr.cite.tools.data.query.Ordering; +//import gr.cite.tools.data.query.QueryFactory; +//import gr.cite.tools.exception.MyApplicationException; +//import gr.cite.tools.fieldset.BaseFieldSet; +//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.time.Instant; +//import java.util.*; +//import java.util.stream.Collectors; +// +//@Component +//@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +//public class DmpFileTransformerBuilder extends BaseFileTransformerBuilder { +// +// private final QueryFactory queryFactory; +// private final BuilderFactory builderFactory; +// private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); +// +// private Boolean ignoreDescriptions = false; +// +// @Autowired +// public DmpFileTransformerBuilder(ConventionService conventionService, +// QueryFactory queryFactory, +// BuilderFactory builderFactory) { +// super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpFileTransformerBuilder.class))); +// this.queryFactory = queryFactory; +// this.builderFactory = builderFactory; +// } +// +// public DmpFileTransformerBuilder authorize(EnumSet values) { +// this.authorize = values; +// return this; +// } +// +// public DmpFileTransformerBuilder ignoreDescriptions(Boolean ignoreDescriptions) { +// this.ignoreDescriptions = ignoreDescriptions; +// return this; +// } +// +// @Override +// protected List> buildInternal(List 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> models = new ArrayList<>(); +// +// Map> dmpReferencesMap = this.collectReferences(data); +// +// Map> dmpUsersMap = this.collectDmpUsers(data); +// +// Map> descriptionsMap = null; +// if (!ignoreDescriptions) { +// descriptionsMap = this.collectDmpDescriptions(data); +// } +// +// Map> doiMap = this.collectEntityDois(data); +// Map creatorMap = this.collectCreators(data); +// Map blueprintMap = this.collectBlueprints(data); +// +// for (DmpEntity d : data) { +// DmpFileTransformerModel m = new DmpFileTransformerModel(); +// m.setId(d.getId()); +// m.setLabel(d.getLabel()); +// m.setVersion(d.getVersion()); +// m.setDescription(d.getDescription()); +// m.setFinalizedAt(d.getFinalizedAt()); +// m.setCreatedAt(d.getCreatedAt()); +// if (d.getPublicAfter() != null && d.getPublicAfter().isAfter(Instant.now())) { +// m.setPublishedAt(d.getPublicAfter()); +// } +// switch (d.getAccessType()){ +// case Public -> m.setAccessType(DmpAccessType.Public); +// case Restricted -> m.setAccessType(DmpAccessType.Restricted); +// case null -> m.setAccessType(null); +// default -> throw new MyApplicationException("unrecognized type " + d.getAccessType().getValue()); +// } +// +// m.setProperties(d.getProperties()); +// m.setUpdatedAt(d.getUpdatedAt()); +// m.setLanguage(d.getLanguage()); +// m.setStatus(DmpStatus.of(d.getStatus().getValue())); +// m.setVersionStatus(DmpVersionStatus.of(d.getVersionStatus().getValue())); +// if (dmpReferencesMap != null && !dmpReferencesMap.isEmpty() && dmpReferencesMap.containsKey(d.getId())) m.setDmpReferences(dmpReferencesMap.get(d.getId())); +// if (dmpUsersMap != null && !dmpUsersMap.isEmpty() && dmpUsersMap.containsKey(d.getId())) m.setDmpUsers(dmpUsersMap.get(d.getId())); +// if (descriptionsMap != null && !descriptionsMap.isEmpty() && descriptionsMap.containsKey(d.getId())) m.setDescriptions(descriptionsMap.get(d.getId())); +// if (doiMap != null && !doiMap.isEmpty() && doiMap.containsKey(d.getId())) m.setEntityDois(doiMap.get(d.getId())); +// if (creatorMap != null && !creatorMap.isEmpty() && creatorMap.containsKey(d.getId())) m.setCreator(creatorMap.get(d.getId())); +// if (blueprintMap != null && !blueprintMap.isEmpty() && blueprintMap.containsKey(d.getBlueprintId())) m.setBlueprint(blueprintMap.get(d.getBlueprintId())); +// +// SectionFileTransformerModel templateSection = m.getBlueprint().getDefinitionFileTransformerModel().getSections().stream().filter(SectionFileTransformerModel::getHasTemplates).findFirst().orElse(null); +// if (templateSection != null && m.getDescriptions() != null && !m.getDescriptions().isEmpty()) { +// m.getDescriptions().forEach(description -> { +// description.setSectionId(templateSection.getId()); +// description.setCreatedBy(m.getCreator()); +// }); +// } +// +// models.add(new FileTransformerBuilderItemResponse<>(m, d)); +// } +// this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); +// +// return models; +// } +// +// private Map> collectReferences(List data) throws MyApplicationException { +// if (data.isEmpty()) return null; +// this.logger.debug("checking related - {}", DmpReference.class.getSimpleName()); +// +// List dmpReferences = this.queryFactory.query(DmpReferenceQuery.class).isActives(IsActive.Active).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList())).collectAs(new BaseFieldSet().ensure(DmpReference._dmp).ensure(DmpReference._reference)); +// +// Map> itemMap = new HashMap<>(); +// ReferenceQuery query = this.queryFactory.query(ReferenceQuery.class).authorize(this.authorize).isActive(IsActive.Active).ids(dmpReferences.stream().map(DmpReferenceEntity::getReferenceId).distinct().collect(Collectors.toList())); +// Map referenceDepositModelMap = this.builderFactory.builder(ReferenceFileTransformerBuilder.class).authorize(this.authorize).asForeignKey(query, ReferenceEntity::getId); +// if (referenceDepositModelMap == null) return null; +// for (DmpReferenceEntity dmpReference : dmpReferences) { +// DmpReferenceFileTransformerModel dmpReferenceFileTransformerModel = new DmpReferenceFileTransformerModel(); +// dmpReferenceFileTransformerModel.setId(dmpReference.getId()); +// dmpReferenceFileTransformerModel.setData(dmpReference.getData()); +// dmpReferenceFileTransformerModel.setReference(referenceDepositModelMap.getOrDefault(dmpReference.getReferenceId(), null)); +// DmpReferenceFileTransformerModel model = dmpReferenceFileTransformerModel; +// if (model == null) continue; +// UUID key = dmpReference.getDmpId(); +// if (!itemMap.containsKey(key)) itemMap.put(key, new ArrayList<>()); +// itemMap.get(key).add(model); +// } +// return itemMap; +// } +// +// +// private Map> collectDmpUsers(List data) throws MyApplicationException { +// this.logger.debug("checking related - {}", DmpUser.class.getSimpleName()); +// +// Map> itemMap; +// DmpUserQuery query = this.queryFactory.query(DmpUserQuery.class).isActives(IsActive.Active).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList())); +// itemMap = this.builderFactory.builder(DmpUserFileTransformerBuilder.class).authorize(this.authorize).asMasterKey(query, DmpUserEntity::getDmpId); +// +// return itemMap; +// } +// +// private Map> collectDmpDescriptions(List data) throws MyApplicationException { +// if (data.isEmpty()) return null; +// this.logger.debug("checking related - {}", Description.class.getSimpleName()); +// +// Map> itemMap; +// DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).isActive(IsActive.Active).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList())); +// itemMap = this.builderFactory.builder(DescriptionFileTransformerBuilder.class).authorize(this.authorize).asMasterKey(query, DescriptionEntity::getDmpId); +// +// return itemMap; +// } +// +// private Map collectCreators(List data) { +// DmpUserQuery query = this.queryFactory.query(DmpUserQuery.class).isActives(IsActive.Active).authorize(this.authorize).userIds(data.stream().map(DmpEntity::getCreatorId).toList()); +// return this.builderFactory.builder(DmpUserFileTransformerBuilder.class).authorize(this.authorize).asMasterKey(query, DmpUserEntity::getDmpId) +// .entrySet().stream().map(uuidListEntry -> Map.entry(uuidListEntry.getKey(), uuidListEntry.getValue().get(0).getUser())) +// .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); +// } +// +// private Map collectBlueprints(List data) { +// DmpBlueprintQuery query = this.queryFactory.query(DmpBlueprintQuery.class).isActive(IsActive.Active).authorize(this.authorize).ids(data.stream().map(DmpEntity::getBlueprintId).toList()); +// return this.builderFactory.builder(DmpBlueprintFileTransformerBuilder.class).authorize(this.authorize).asMasterKey(query, DmpBlueprintEntity::getId) +// .entrySet().stream().map(uuidListEntry -> Map.entry(uuidListEntry.getKey(), uuidListEntry.getValue().get(0))) +// .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); +// } +// +// private Map> collectEntityDois(List data) { +// if (data.isEmpty()) return null; +// Map> result; +// EntityDoiQuery query = this.queryFactory.query(EntityDoiQuery.class).isActive(IsActive.Active).authorize(authorize).entityIds(data.stream().map(DmpEntity::getId).distinct().toList()); +// result = builderFactory.builder(EntityDoiFileTransformerBuilder.class).asMasterKey(query, EntityDoiEntity::getEntityId); +// return result; +// } +// +//} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DmpUserFileTransformerBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DmpUserFileTransformerBuilder.java index 3baebe971..355a12bfd 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DmpUserFileTransformerBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/DmpUserFileTransformerBuilder.java @@ -1,85 +1,85 @@ -package eu.eudat.model.builder.filetransformer; - -import eu.eudat.authorization.AuthorizationFlags; -import eu.eudat.commons.enums.IsActive; -import eu.eudat.convention.ConventionService; -import eu.eudat.data.DmpUserEntity; -import eu.eudat.data.UserEntity; -import eu.eudat.file.transformer.enums.DmpUserRole; -import eu.eudat.file.transformer.models.dmp.DmpUserFileTransformerModel; -import eu.eudat.file.transformer.models.user.UserFileTransformerModel; -import eu.eudat.query.UserQuery; -import gr.cite.tools.data.builder.BuilderFactory; -import gr.cite.tools.data.query.QueryFactory; -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.*; -import java.util.stream.Collectors; - -@Component -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class DmpUserFileTransformerBuilder extends BaseFileTransformerBuilder { - - private final BuilderFactory builderFactory; - - private final QueryFactory queryFactory; - - private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - - @Autowired - public DmpUserFileTransformerBuilder( - ConventionService conventionService, - BuilderFactory builderFactory, QueryFactory queryFactory) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpUserFileTransformerBuilder.class))); - this.builderFactory = builderFactory; - this.queryFactory = queryFactory; - } - - public DmpUserFileTransformerBuilder authorize(EnumSet values) { - this.authorize = values; - return this; - } - - @Override - protected List> buildInternal(List data) throws MyApplicationException { - this.logger.debug("building for {} items ", Optional.ofNullable(data).map(List::size).orElse(0)); - if (data == null) - return new ArrayList<>(); - - - Map userItemsMap = this.collectUsers(data); - - List> models = new ArrayList<>(); - for (DmpUserEntity d : data) { - DmpUserFileTransformerModel m = new DmpUserFileTransformerModel(); - m.setId(d.getId()); - switch (d.getRole()){ - case User -> m.setRole(DmpUserRole.User); - case Owner -> m.setRole(DmpUserRole.Owner); - default -> throw new MyApplicationException("unrecognized type " + d.getRole().getValue()); - } - if (userItemsMap != null && userItemsMap.containsKey(d.getUserId())) m.setUser(userItemsMap.get(d.getUserId())); - models.add(new FileTransformerBuilderItemResponse<>(m, d)); - } - this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); - return models; - } - - private Map collectUsers(List data) throws MyApplicationException { - if (data.isEmpty()) - return null; - this.logger.debug("checking related - {}", UserFileTransformerModel.class.getSimpleName()); - - Map itemMap; - UserQuery q = this.queryFactory.query(UserQuery.class).isActive(IsActive.Active).authorize(this.authorize).ids(data.stream().map(DmpUserEntity::getUserId).distinct().collect(Collectors.toList())); - itemMap = this.builderFactory.builder(UserFileTransformerBuilder.class).authorize(this.authorize).asForeignKey(q, UserEntity::getId); - return itemMap; - } - -} +//package eu.eudat.model.builder.filetransformer; +// +//import eu.eudat.authorization.AuthorizationFlags; +//import eu.eudat.commons.enums.IsActive; +//import eu.eudat.convention.ConventionService; +//import eu.eudat.data.DmpUserEntity; +//import eu.eudat.data.UserEntity; +//import eu.eudat.file.transformer.enums.DmpUserRole; +//import eu.eudat.file.transformer.models.dmp.DmpUserFileTransformerModel; +//import eu.eudat.file.transformer.models.user.UserFileTransformerModel; +//import eu.eudat.query.UserQuery; +//import gr.cite.tools.data.builder.BuilderFactory; +//import gr.cite.tools.data.query.QueryFactory; +//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.*; +//import java.util.stream.Collectors; +// +//@Component +//@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +//public class DmpUserFileTransformerBuilder extends BaseFileTransformerBuilder { +// +// private final BuilderFactory builderFactory; +// +// private final QueryFactory queryFactory; +// +// private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); +// +// @Autowired +// public DmpUserFileTransformerBuilder( +// ConventionService conventionService, +// BuilderFactory builderFactory, QueryFactory queryFactory) { +// super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpUserFileTransformerBuilder.class))); +// this.builderFactory = builderFactory; +// this.queryFactory = queryFactory; +// } +// +// public DmpUserFileTransformerBuilder authorize(EnumSet values) { +// this.authorize = values; +// return this; +// } +// +// @Override +// protected List> buildInternal(List data) throws MyApplicationException { +// this.logger.debug("building for {} items ", Optional.ofNullable(data).map(List::size).orElse(0)); +// if (data == null) +// return new ArrayList<>(); +// +// +// Map userItemsMap = this.collectUsers(data); +// +// List> models = new ArrayList<>(); +// for (DmpUserEntity d : data) { +// DmpUserFileTransformerModel m = new DmpUserFileTransformerModel(); +// m.setId(d.getId()); +// switch (d.getRole()){ +// case User -> m.setRole(DmpUserRole.User); +// case Owner -> m.setRole(DmpUserRole.Owner); +// default -> throw new MyApplicationException("unrecognized type " + d.getRole().getValue()); +// } +// if (userItemsMap != null && userItemsMap.containsKey(d.getUserId())) m.setUser(userItemsMap.get(d.getUserId())); +// models.add(new FileTransformerBuilderItemResponse<>(m, d)); +// } +// this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); +// return models; +// } +// +// private Map collectUsers(List data) throws MyApplicationException { +// if (data.isEmpty()) +// return null; +// this.logger.debug("checking related - {}", UserFileTransformerModel.class.getSimpleName()); +// +// Map itemMap; +// UserQuery q = this.queryFactory.query(UserQuery.class).isActive(IsActive.Active).authorize(this.authorize).ids(data.stream().map(DmpUserEntity::getUserId).distinct().collect(Collectors.toList())); +// itemMap = this.builderFactory.builder(UserFileTransformerBuilder.class).authorize(this.authorize).asForeignKey(q, UserEntity::getId); +// return itemMap; +// } +// +//} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/EntityDoiFileTransformerBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/EntityDoiFileTransformerBuilder.java index 69b64f5b3..b24a728fe 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/EntityDoiFileTransformerBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/EntityDoiFileTransformerBuilder.java @@ -1,34 +1,34 @@ -package eu.eudat.model.builder.filetransformer; - -import eu.eudat.convention.ConventionService; -import eu.eudat.data.EntityDoiEntity; -import eu.eudat.file.transformer.models.entitydoi.EntityDoiFileTransformerModel; -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.stereotype.Component; - -import java.util.ArrayList; -import java.util.List; - -@Component -public class EntityDoiFileTransformerBuilder extends BaseFileTransformerBuilder{ - @Autowired - public EntityDoiFileTransformerBuilder(ConventionService conventionService) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpFileTransformerBuilder.class))); - } - - @Override - protected List> buildInternal(List data) throws MyApplicationException { - List> result = new ArrayList<>(); - for (EntityDoiEntity d : data) { - EntityDoiFileTransformerModel m = new EntityDoiFileTransformerModel(); - m.setId(d.getId()); - m.setDoi(d.getDoi()); - m.setRepositoryId(d.getRepositoryId()); - result.add(new FileTransformerBuilderItemResponse<>(m, d)); - } - return result; - } -} +//package eu.eudat.model.builder.filetransformer; +// +//import eu.eudat.convention.ConventionService; +//import eu.eudat.data.EntityDoiEntity; +//import eu.eudat.file.transformer.models.entitydoi.EntityDoiFileTransformerModel; +//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.stereotype.Component; +// +//import java.util.ArrayList; +//import java.util.List; +// +//@Component +//public class EntityDoiFileTransformerBuilder extends BaseFileTransformerBuilder{ +// @Autowired +// public EntityDoiFileTransformerBuilder(ConventionService conventionService) { +// super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpFileTransformerBuilder.class))); +// } +// +// @Override +// protected List> buildInternal(List data) throws MyApplicationException { +// List> result = new ArrayList<>(); +// for (EntityDoiEntity d : data) { +// EntityDoiFileTransformerModel m = new EntityDoiFileTransformerModel(); +// m.setId(d.getId()); +// m.setDoi(d.getDoi()); +// m.setRepositoryId(d.getRepositoryId()); +// result.add(new FileTransformerBuilderItemResponse<>(m, d)); +// } +// return result; +// } +//} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/FileTransformerBuilderItemResponse.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/FileTransformerBuilderItemResponse.java index 0ad27c1cd..5236852d0 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/FileTransformerBuilderItemResponse.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/FileTransformerBuilderItemResponse.java @@ -1,19 +1,19 @@ -package eu.eudat.model.builder.filetransformer; - -public class FileTransformerBuilderItemResponse{ - private final M model; - private final D data; - - public FileTransformerBuilderItemResponse(M model, D data) { - this.model = model; - this.data = data; - } - - public D getData() { - return data; - } - - public M getModel() { - return model; - } -} +//package eu.eudat.model.builder.filetransformer; +// +//public class FileTransformerBuilderItemResponse{ +// private final M model; +// private final D data; +// +// public FileTransformerBuilderItemResponse(M model, D data) { +// this.model = model; +// this.data = data; +// } +// +// public D getData() { +// return data; +// } +// +// public M getModel() { +// return model; +// } +//} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/ReferenceDefinitionFileTransformerBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/ReferenceDefinitionFileTransformerBuilder.java index 43d2e3604..651371389 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/ReferenceDefinitionFileTransformerBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/ReferenceDefinitionFileTransformerBuilder.java @@ -1,55 +1,54 @@ -package eu.eudat.model.builder.filetransformer; - -import eu.eudat.authorization.AuthorizationFlags; -import eu.eudat.commons.types.reference.DefinitionEntity; -import eu.eudat.convention.ConventionService; -import eu.eudat.depositinterface.models.reference.DefinitionDepositModel; -import eu.eudat.file.transformer.models.reference.DefinitionFileTransformerModel; -import gr.cite.tools.data.builder.BuilderFactory; -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 ReferenceDefinitionFileTransformerBuilder extends BaseFileTransformerBuilder { - - private final BuilderFactory builderFactory; - private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - - @Autowired - public ReferenceDefinitionFileTransformerBuilder( - ConventionService conventionService, BuilderFactory builderFactory) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceDefinitionFileTransformerBuilder.class))); - this.builderFactory = builderFactory; - } - - public ReferenceDefinitionFileTransformerBuilder authorize(EnumSet values) { - this.authorize = values; - return this; - } - - @Override - protected List> buildInternal(List 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> models = new ArrayList<>(); - for (DefinitionEntity d : data) { - DefinitionFileTransformerModel m = new DefinitionFileTransformerModel(); - if (d.getFields() != null) m.setFields(this.builderFactory.builder(ReferenceFieldFileTransformerBuilder.class).authorize(this.authorize).build(d.getFields())); - models.add(new FileTransformerBuilderItemResponse<>(m, d)); - } - this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); - return models; - } -} +//package eu.eudat.model.builder.filetransformer; +// +//import eu.eudat.authorization.AuthorizationFlags; +//import eu.eudat.commons.types.reference.DefinitionEntity; +//import eu.eudat.convention.ConventionService; +//import eu.eudat.file.transformer.models.reference.DefinitionFileTransformerModel; +//import gr.cite.tools.data.builder.BuilderFactory; +//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 ReferenceDefinitionFileTransformerBuilder extends BaseFileTransformerBuilder { +// +// private final BuilderFactory builderFactory; +// private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); +// +// @Autowired +// public ReferenceDefinitionFileTransformerBuilder( +// ConventionService conventionService, BuilderFactory builderFactory) { +// super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceDefinitionFileTransformerBuilder.class))); +// this.builderFactory = builderFactory; +// } +// +// public ReferenceDefinitionFileTransformerBuilder authorize(EnumSet values) { +// this.authorize = values; +// return this; +// } +// +// @Override +// protected List> buildInternal(List 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> models = new ArrayList<>(); +// for (DefinitionEntity d : data) { +// DefinitionFileTransformerModel m = new DefinitionFileTransformerModel(); +// if (d.getFields() != null) m.setFields(this.builderFactory.builder(ReferenceFieldFileTransformerBuilder.class).authorize(this.authorize).build(d.getFields())); +// models.add(new FileTransformerBuilderItemResponse<>(m, d)); +// } +// this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); +// return models; +// } +//} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/ReferenceFieldFileTransformerBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/ReferenceFieldFileTransformerBuilder.java index e4f554190..77623cee6 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/ReferenceFieldFileTransformerBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/ReferenceFieldFileTransformerBuilder.java @@ -1,54 +1,53 @@ -package eu.eudat.model.builder.filetransformer; - -import eu.eudat.authorization.AuthorizationFlags; -import eu.eudat.commons.types.reference.FieldEntity; -import eu.eudat.convention.ConventionService; -import eu.eudat.depositinterface.models.reference.FieldDepositModel; -import eu.eudat.file.transformer.models.reference.FieldFileTransformerModel; -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 ReferenceFieldFileTransformerBuilder extends BaseFileTransformerBuilder { - - private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - - @Autowired - public ReferenceFieldFileTransformerBuilder( - ConventionService conventionService) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceFieldFileTransformerBuilder.class))); - } - - public ReferenceFieldFileTransformerBuilder authorize(EnumSet values) { - this.authorize = values; - return this; - } - - @Override - protected List> buildInternal(List 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> models = new ArrayList<>(); - for (FieldEntity d : data) { - FieldFileTransformerModel m = new FieldFileTransformerModel(); - m.setCode(d.getCode()); - m.setValue(d.getValue()); - - models.add(new FileTransformerBuilderItemResponse<>(m, d)); - } - this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); - return models; - } -} +//package eu.eudat.model.builder.filetransformer; +// +//import eu.eudat.authorization.AuthorizationFlags; +//import eu.eudat.commons.types.reference.FieldEntity; +//import eu.eudat.convention.ConventionService; +//import eu.eudat.file.transformer.models.reference.FieldFileTransformerModel; +//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 ReferenceFieldFileTransformerBuilder extends BaseFileTransformerBuilder { +// +// private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); +// +// @Autowired +// public ReferenceFieldFileTransformerBuilder( +// ConventionService conventionService) { +// super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceFieldFileTransformerBuilder.class))); +// } +// +// public ReferenceFieldFileTransformerBuilder authorize(EnumSet values) { +// this.authorize = values; +// return this; +// } +// +// @Override +// protected List> buildInternal(List 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> models = new ArrayList<>(); +// for (FieldEntity d : data) { +// FieldFileTransformerModel m = new FieldFileTransformerModel(); +// m.setCode(d.getCode()); +// m.setValue(d.getValue()); +// +// models.add(new FileTransformerBuilderItemResponse<>(m, d)); +// } +// this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); +// return models; +// } +//} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/ReferenceFileTransformerBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/ReferenceFileTransformerBuilder.java index 072870999..da5e0e178 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/ReferenceFileTransformerBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/ReferenceFileTransformerBuilder.java @@ -1,80 +1,80 @@ -package eu.eudat.model.builder.filetransformer; - -import eu.eudat.authorization.AuthorizationFlags; -import eu.eudat.commons.XmlHandlingService; -import eu.eudat.commons.types.reference.DefinitionEntity; -import eu.eudat.convention.ConventionService; -import eu.eudat.data.ReferenceEntity; -import eu.eudat.file.transformer.enums.ReferenceSourceType; -import eu.eudat.file.transformer.enums.ReferenceType; -import eu.eudat.file.transformer.models.description.DescriptionReferenceFileTransformerModel; -import eu.eudat.file.transformer.models.dmp.DmpReferenceFileTransformerModel; -import eu.eudat.file.transformer.models.reference.ReferenceFileTransformerModel; -import gr.cite.tools.data.builder.BuilderFactory; -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 ReferenceFileTransformerBuilder extends BaseFileTransformerBuilder { - - private final BuilderFactory builderFactory; - private final XmlHandlingService xmlHandlingService; - private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - - @Autowired - public ReferenceFileTransformerBuilder( - ConventionService conventionService, - BuilderFactory builderFactory, XmlHandlingService xmlHandlingService) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceFileTransformerBuilder.class))); - this.builderFactory = builderFactory; - this.xmlHandlingService = xmlHandlingService; - } - - public ReferenceFileTransformerBuilder authorize(EnumSet values) { - this.authorize = values; - return this; - } - - @Override - protected List> buildInternal(List 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> models = new ArrayList<>(); - for (ReferenceEntity d : data) { - ReferenceFileTransformerModel m = new ReferenceFileTransformerModel(); - m.setId(d.getId()); - m.setLabel(d.getLabel()); - if (d.getDefinition() != null){ - DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(DefinitionEntity.class, d.getDefinition()); - m.setDefinition(this.builderFactory.builder(ReferenceDefinitionFileTransformerBuilder.class).authorize(this.authorize).build(definition)); - } - m.setReference(d.getReference()); - m.setAbbreviation(d.getAbbreviation()); - m.setDescription(d.getDescription()); - m.setSource(d.getSource()); - switch (d.getSourceType()){ - case Internal -> m.setSourceType(ReferenceSourceType.Internal); - case External -> m.setSourceType(ReferenceSourceType.External); - default -> throw new MyApplicationException("unrecognized type " + d.getSourceType().getValue()); - } - - //m.setType(d.getTypeId()); //TODO new reference logic - - models.add(new FileTransformerBuilderItemResponse<>(m, d)); - } - this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); - return models; - } -} +//package eu.eudat.model.builder.filetransformer; +// +//import eu.eudat.authorization.AuthorizationFlags; +//import eu.eudat.commons.XmlHandlingService; +//import eu.eudat.commons.types.reference.DefinitionEntity; +//import eu.eudat.convention.ConventionService; +//import eu.eudat.data.ReferenceEntity; +//import eu.eudat.file.transformer.enums.ReferenceSourceType; +//import eu.eudat.file.transformer.enums.ReferenceType; +//import eu.eudat.file.transformer.models.description.DescriptionReferenceFileTransformerModel; +//import eu.eudat.file.transformer.models.dmp.DmpReferenceFileTransformerModel; +//import eu.eudat.file.transformer.models.reference.ReferenceFileTransformerModel; +//import gr.cite.tools.data.builder.BuilderFactory; +//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 ReferenceFileTransformerBuilder extends BaseFileTransformerBuilder { +// +// private final BuilderFactory builderFactory; +// private final XmlHandlingService xmlHandlingService; +// private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); +// +// @Autowired +// public ReferenceFileTransformerBuilder( +// ConventionService conventionService, +// BuilderFactory builderFactory, XmlHandlingService xmlHandlingService) { +// super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceFileTransformerBuilder.class))); +// this.builderFactory = builderFactory; +// this.xmlHandlingService = xmlHandlingService; +// } +// +// public ReferenceFileTransformerBuilder authorize(EnumSet values) { +// this.authorize = values; +// return this; +// } +// +// @Override +// protected List> buildInternal(List 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> models = new ArrayList<>(); +// for (ReferenceEntity d : data) { +// ReferenceFileTransformerModel m = new ReferenceFileTransformerModel(); +// m.setId(d.getId()); +// m.setLabel(d.getLabel()); +// if (d.getDefinition() != null){ +// DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(DefinitionEntity.class, d.getDefinition()); +// m.setDefinition(this.builderFactory.builder(ReferenceDefinitionFileTransformerBuilder.class).authorize(this.authorize).build(definition)); +// } +// m.setReference(d.getReference()); +// m.setAbbreviation(d.getAbbreviation()); +// m.setDescription(d.getDescription()); +// m.setSource(d.getSource()); +// switch (d.getSourceType()){ +// case Internal -> m.setSourceType(ReferenceSourceType.Internal); +// case External -> m.setSourceType(ReferenceSourceType.External); +// default -> throw new MyApplicationException("unrecognized type " + d.getSourceType().getValue()); +// } +// +// //m.setType(d.getTypeId()); //TODO new reference logic +// +// models.add(new FileTransformerBuilderItemResponse<>(m, d)); +// } +// this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); +// return models; +// } +//} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/TagFileTransformerBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/TagFileTransformerBuilder.java index b69d6b818..0a4ce8a38 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/TagFileTransformerBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/TagFileTransformerBuilder.java @@ -1,59 +1,59 @@ -package eu.eudat.model.builder.filetransformer; - -import eu.eudat.authorization.AuthorizationFlags; -import eu.eudat.commons.XmlHandlingService; -import eu.eudat.convention.ConventionService; -import eu.eudat.data.TagEntity; -import eu.eudat.file.transformer.models.tag.TagFileTransformerModel; -import gr.cite.tools.data.builder.BuilderFactory; -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 TagFileTransformerBuilder extends BaseFileTransformerBuilder { - - private final BuilderFactory builderFactory; - private final XmlHandlingService xmlHandlingService; - private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - - @Autowired - public TagFileTransformerBuilder( - ConventionService conventionService, - BuilderFactory builderFactory, XmlHandlingService xmlHandlingService) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(TagFileTransformerBuilder.class))); - this.builderFactory = builderFactory; - this.xmlHandlingService = xmlHandlingService; - } - - public TagFileTransformerBuilder authorize(EnumSet values) { - this.authorize = values; - return this; - } - - @Override - protected List> buildInternal(List 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> models = new ArrayList<>(); - for (TagEntity d : data) { - TagFileTransformerModel m = new TagFileTransformerModel(); - m.setId(d.getId()); - m.setLabel(d.getLabel()); - models.add(new FileTransformerBuilderItemResponse<>(m, d)); - } - this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); - return models; - } -} +//package eu.eudat.model.builder.filetransformer; +// +//import eu.eudat.authorization.AuthorizationFlags; +//import eu.eudat.commons.XmlHandlingService; +//import eu.eudat.convention.ConventionService; +//import eu.eudat.data.TagEntity; +//import eu.eudat.file.transformer.models.tag.TagFileTransformerModel; +//import gr.cite.tools.data.builder.BuilderFactory; +//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 TagFileTransformerBuilder extends BaseFileTransformerBuilder { +// +// private final BuilderFactory builderFactory; +// private final XmlHandlingService xmlHandlingService; +// private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); +// +// @Autowired +// public TagFileTransformerBuilder( +// ConventionService conventionService, +// BuilderFactory builderFactory, XmlHandlingService xmlHandlingService) { +// super(conventionService, new LoggerService(LoggerFactory.getLogger(TagFileTransformerBuilder.class))); +// this.builderFactory = builderFactory; +// this.xmlHandlingService = xmlHandlingService; +// } +// +// public TagFileTransformerBuilder authorize(EnumSet values) { +// this.authorize = values; +// return this; +// } +// +// @Override +// protected List> buildInternal(List 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> models = new ArrayList<>(); +// for (TagEntity d : data) { +// TagFileTransformerModel m = new TagFileTransformerModel(); +// m.setId(d.getId()); +// m.setLabel(d.getLabel()); +// models.add(new FileTransformerBuilderItemResponse<>(m, d)); +// } +// this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); +// return models; +// } +//} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/UserFileTransformerBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/UserFileTransformerBuilder.java index d3d46cf52..3196b7581 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/UserFileTransformerBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/UserFileTransformerBuilder.java @@ -1,76 +1,75 @@ -package eu.eudat.model.builder.filetransformer; - -import eu.eudat.authorization.AuthorizationFlags; -import eu.eudat.convention.ConventionService; -import eu.eudat.data.UserContactInfoEntity; -import eu.eudat.data.UserEntity; -import eu.eudat.depositinterface.models.UserDepositModel; -import eu.eudat.file.transformer.enums.ContactInfoType; -import eu.eudat.file.transformer.models.user.UserContactInfoFileTransformerModel; -import eu.eudat.file.transformer.models.user.UserFileTransformerModel; -import eu.eudat.query.UserContactInfoQuery; -import gr.cite.tools.data.query.QueryFactory; -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.*; - -@Component -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class UserFileTransformerBuilder extends BaseFileTransformerBuilder { - - private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - private final QueryFactory queryFactory; - - @Autowired - public UserFileTransformerBuilder(ConventionService conventionService, QueryFactory queryFactory) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(UserFileTransformerBuilder.class))); - this.queryFactory = queryFactory; - } - - public UserFileTransformerBuilder authorize(EnumSet values) { - this.authorize = values; - return this; - } - - @Override - protected List> buildInternal(List data) throws MyApplicationException { - this.logger.debug("building for {} items ", Optional.ofNullable(data).map(List::size).orElse(0)); - if (data == null) - return new ArrayList<>(); - - List> models = new ArrayList<>(); - - for (UserEntity d : data) { - UserFileTransformerModel m = new UserFileTransformerModel(); - m.setId(d.getId()); - m.setName(d.getName()); - m.setContacts(mapContactInfo(d.getId())); - models.add(new FileTransformerBuilderItemResponse<>(m, d)); - } - this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); - - return models; - } - - private List mapContactInfo(UUID userId) { - List result = new ArrayList<>(); - UserContactInfoQuery query = this.queryFactory.query(UserContactInfoQuery.class).userIds(userId); - List contactInfos = query.collect(); - contactInfos.forEach(contactInfo -> { - UserContactInfoFileTransformerModel m = new UserContactInfoFileTransformerModel(); - m.setId(contactInfo.getId()); - m.setOrdinal(contactInfo.getOrdinal()); - m.setType(ContactInfoType.of(contactInfo.getType().getValue())); - m.setValue(contactInfo.getValue()); - result.add(m); - }); - return result; - } - -} +//package eu.eudat.model.builder.filetransformer; +// +//import eu.eudat.authorization.AuthorizationFlags; +//import eu.eudat.convention.ConventionService; +//import eu.eudat.data.UserContactInfoEntity; +//import eu.eudat.data.UserEntity; +//import eu.eudat.file.transformer.enums.ContactInfoType; +//import eu.eudat.file.transformer.models.user.UserContactInfoFileTransformerModel; +//import eu.eudat.file.transformer.models.user.UserFileTransformerModel; +//import eu.eudat.query.UserContactInfoQuery; +//import gr.cite.tools.data.query.QueryFactory; +//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.*; +// +//@Component +//@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +//public class UserFileTransformerBuilder extends BaseFileTransformerBuilder { +// +// private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); +// private final QueryFactory queryFactory; +// +// @Autowired +// public UserFileTransformerBuilder(ConventionService conventionService, QueryFactory queryFactory) { +// super(conventionService, new LoggerService(LoggerFactory.getLogger(UserFileTransformerBuilder.class))); +// this.queryFactory = queryFactory; +// } +// +// public UserFileTransformerBuilder authorize(EnumSet values) { +// this.authorize = values; +// return this; +// } +// +// @Override +// protected List> buildInternal(List data) throws MyApplicationException { +// this.logger.debug("building for {} items ", Optional.ofNullable(data).map(List::size).orElse(0)); +// if (data == null) +// return new ArrayList<>(); +// +// List> models = new ArrayList<>(); +// +// for (UserEntity d : data) { +// UserFileTransformerModel m = new UserFileTransformerModel(); +// m.setId(d.getId()); +// m.setName(d.getName()); +// m.setContacts(mapContactInfo(d.getId())); +// models.add(new FileTransformerBuilderItemResponse<>(m, d)); +// } +// this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); +// +// return models; +// } +// +// private List mapContactInfo(UUID userId) { +// List result = new ArrayList<>(); +// UserContactInfoQuery query = this.queryFactory.query(UserContactInfoQuery.class).userIds(userId); +// List contactInfos = query.collect(); +// contactInfos.forEach(contactInfo -> { +// UserContactInfoFileTransformerModel m = new UserContactInfoFileTransformerModel(); +// m.setId(contactInfo.getId()); +// m.setOrdinal(contactInfo.getOrdinal()); +// m.setType(ContactInfoType.of(contactInfo.getType().getValue())); +// m.setValue(contactInfo.getValue()); +// result.add(m); +// }); +// return result; +// } +// +//} diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositClientImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositClientImpl.java index 8df39caf1..246eea95f 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositClientImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositClientImpl.java @@ -1,6 +1,6 @@ package eu.eudat.service.deposit; -import eu.eudat.depositinterface.models.DmpDepositModel; +import eu.eudat.commonmodels.models.DmpModel; import eu.eudat.depositinterface.repository.DepositClient; import eu.eudat.depositinterface.repository.DepositConfiguration; import org.springframework.core.ParameterizedTypeReference; @@ -16,7 +16,7 @@ public class DepositClientImpl implements DepositClient { @Override - public String deposit(DmpDepositModel dmpDepositModel, String repositoryAccessToken) throws Exception { + public String deposit(DmpModel dmpDepositModel, String repositoryAccessToken) throws Exception { return depositClient.post().uri("/", uriBuilder -> uriBuilder.queryParam("authToken", repositoryAccessToken).build()).bodyValue(dmpDepositModel).exchangeToMono(mono -> mono.bodyToMono(String.class)).block(); } diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositServiceImpl.java index 70dbb1a1e..c56a8c72e 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositServiceImpl.java @@ -2,22 +2,22 @@ package eu.eudat.service.deposit; import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.Permission; +import eu.eudat.commonmodels.models.DmpModel; +import eu.eudat.commonmodels.models.FileEnvelopeModel; import eu.eudat.configurations.deposit.DepositProperties; import eu.eudat.data.DmpEntity; -import eu.eudat.depositinterface.models.DmpDepositModel; -import eu.eudat.depositinterface.models.FileEnvelope; import eu.eudat.depositinterface.repository.DepositClient; import eu.eudat.depositinterface.repository.DepositConfiguration; import eu.eudat.model.EntityDoi; -import eu.eudat.model.builder.deposit.DepositConfigurationBuilder; -import eu.eudat.model.builder.deposit.DmpDepositBuilder; +import eu.eudat.model.builder.commonmodels.DepositConfigurationBuilder; +import eu.eudat.model.builder.commonmodels.DmpCommonModelBuilder; import eu.eudat.model.persist.deposit.DepositAuthenticateRequest; import eu.eudat.model.persist.deposit.DepositRequest; import eu.eudat.model.persist.EntityDoiPersist; import eu.eudat.query.DmpQuery; import eu.eudat.service.entitydoi.EntityDoiService; -import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.commons.web.oidc.filter.webflux.TokenExchangeCacheService; +import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.commons.web.oidc.filter.webflux.TokenExchangeFilterFunction; import gr.cite.commons.web.oidc.filter.webflux.TokenExchangeModel; import gr.cite.tools.data.builder.BuilderFactory; @@ -130,10 +130,10 @@ public class DepositServiceImpl implements DepositService { //GK: Forth make the required files to be uploaded with the deposit //TODO: Properly create required files - FileEnvelope docEnvelope = new FileEnvelope(); - FileEnvelope pdfEnvelope = new FileEnvelope(); - FileEnvelope jsonEnvelope = new FileEnvelope(); - FileEnvelope zip = new FileEnvelope(); + FileEnvelopeModel docEnvelope = new FileEnvelopeModel(); + FileEnvelopeModel pdfEnvelope = new FileEnvelopeModel(); + FileEnvelopeModel jsonEnvelope = new FileEnvelopeModel(); + FileEnvelopeModel zip = new FileEnvelopeModel(); //TODO: Create Files // File zip = new File(environment.getProperty("temp.temp") + UUID.randomUUID() + ".zip"); // try { @@ -151,7 +151,7 @@ public class DepositServiceImpl implements DepositService { // } //GK: Fifth Transform them to the DepositModel - DmpDepositModel depositModel = this.builderFactory.builder(DmpDepositBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic) + DmpModel depositModel = this.builderFactory.builder(DmpCommonModelBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic) .setRepositoryId(dmpDepositModel.getRepositoryId()).setPdfFile(pdfEnvelope).setRdaJsonFile(jsonEnvelope).setSupportingFilesZip(zip).build(dmpEntity); //GK: Sixth Perform the deposit diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/BaseFieldDataHelperService.java b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/BaseFieldDataHelperService.java index 7c0a56bfe..409220b8d 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/BaseFieldDataHelperService.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/BaseFieldDataHelperService.java @@ -1,6 +1,7 @@ package eu.eudat.service.fielddatahelper; import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.BaseFieldDataModel; import eu.eudat.commons.enums.FieldType; import eu.eudat.commons.types.descriptiontemplate.fielddata.BaseFieldDataEntity; import eu.eudat.commons.types.descriptiontemplate.importexport.fielddata.BaseFieldDataImportExport; @@ -12,19 +13,21 @@ import java.util.EnumSet; import java.util.List; import java.util.stream.Collectors; -public abstract class BaseFieldDataHelperService implements FieldDataHelperService { +public abstract class BaseFieldDataHelperService implements FieldDataHelperService { protected FieldType fieldType; protected abstract D newDataInstanceInternal(); protected abstract M newModelInstanceInternal(); protected abstract PM newPersistModelInstanceInternal(); protected abstract IE newImportExportInstanceInternal(); + protected abstract CM newCommonModelInstanceInternal(); protected abstract List buildInternal(FieldSet fieldSet, List data, EnumSet authorizationFlags); protected abstract D applyPersistInternal(PM persist, D data); protected abstract PM importExportMapDataToPersistInternal(IE data, PM persist); protected abstract IE dataToImportExportXmlInternal(D data, IE xml); protected abstract boolean isMultiValueInternal(D data); + protected abstract List buildCommonModelInternal(List data, EnumSet authorizationFlags); @Override public FieldType getFieldType() { @@ -45,6 +48,11 @@ public abstract class BaseFieldDataHelperService authorizationFlags){ + List models = this.buildCommonModelInternal(List.of((D) data), authorizationFlags).stream().map(x-> (CM)x).collect(Collectors.toList()); + if (models == null || models.isEmpty()) return null; + return models.getFirst(); + } + @Override public List build(FieldSet fieldSet, List data, EnumSet authorizationFlags) { return this.buildInternal(fieldSet, data.stream().map(x-> (D) x).collect(Collectors.toList()), authorizationFlags).stream().map(x-> (M)x).collect(Collectors.toList()); diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/FieldDataHelperService.java b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/FieldDataHelperService.java index 13db58186..009160aa4 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/FieldDataHelperService.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/FieldDataHelperService.java @@ -1,6 +1,7 @@ package eu.eudat.service.fielddatahelper; import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.BaseFieldDataModel; import eu.eudat.commons.enums.FieldType; import eu.eudat.commons.types.descriptiontemplate.fielddata.BaseFieldDataEntity; import eu.eudat.commons.types.descriptiontemplate.importexport.fielddata.BaseFieldDataImportExport; @@ -16,15 +17,18 @@ public interface FieldDataHelperService { FieldType getFieldType(); BaseFieldDataEntity newDataInstance(); BaseFieldData newModelInstance(); + BaseFieldDataModel newCommonModelInstance(); BaseFieldDataPersist newPersistModelInstance(); BaseFieldDataImportExport newImportExportInstance(); Class getDataClass(); Class getModelClass(); Class getPersistModelClass(); + Class getCommonModelClass(); Class getImportExportClass(); Validator getPersistModelValidator(); List build(gr.cite.tools.fieldset.FieldSet fieldSet, List data, EnumSet authorizationFlags); BaseFieldData buildOne(FieldSet fieldSet, BaseFieldDataEntity data, EnumSet authorizationFlags); + BaseFieldDataModel buildCommonModelOne(BaseFieldDataEntity data, EnumSet authorizationFlags); BaseFieldDataEntity applyPersist(BaseFieldDataPersist persist); BaseFieldDataEntity applyPersist(BaseFieldDataPersist persist, BaseFieldDataEntity data); BaseFieldDataPersist importExportMapDataToPersist(BaseFieldDataImportExport xml); diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/FieldDataHelperServiceProvider.java b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/FieldDataHelperServiceProvider.java index 969435922..cb4f40023 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/FieldDataHelperServiceProvider.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/FieldDataHelperServiceProvider.java @@ -12,7 +12,7 @@ public class FieldDataHelperServiceProvider { private ApplicationContext applicationContext; public FieldDataHelperService get(FieldType type){ - BaseFieldDataHelperService item = null; + BaseFieldDataHelperService item = null; switch (type) { case INTERNAL_ENTRIES_DESCRIPTIONS: diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/LabelAndMultiplicityFieldDataHelperService.java b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/LabelAndMultiplicityFieldDataHelperService.java index 2f0bf5b42..e082832a4 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/LabelAndMultiplicityFieldDataHelperService.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/LabelAndMultiplicityFieldDataHelperService.java @@ -1,8 +1,11 @@ package eu.eudat.service.fielddatahelper; import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.BaseFieldDataModel; +import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.LabelAndMultiplicityDataModel; import eu.eudat.commons.types.descriptiontemplate.fielddata.LabelAndMultiplicityDataEntity; import eu.eudat.commons.types.descriptiontemplate.importexport.fielddata.LabelAndMultiplicityDataImportExport; +import eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata.LabelAndMultiplicityDataCommonModelBuilder; import eu.eudat.model.builder.descriptiontemplatedefinition.fielddata.LabelAndMultiplicityDataBuilder; import eu.eudat.model.descriptiontemplatedefinition.fielddata.LabelAndMultiplicityData; import eu.eudat.model.persist.descriptiontemplatedefinition.fielddata.LabelAndMultiplicityDataPersist; @@ -16,7 +19,7 @@ import java.util.EnumSet; import java.util.List; @Component -public class LabelAndMultiplicityFieldDataHelperService extends BaseFieldDataHelperService { +public class LabelAndMultiplicityFieldDataHelperService extends BaseFieldDataHelperService { private final BuilderFactory builderFactory; @@ -46,6 +49,11 @@ public class LabelAndMultiplicityFieldDataHelperService extends BaseFieldDataHel return new LabelAndMultiplicityDataImportExport(); } + @Override + protected LabelAndMultiplicityDataModel newCommonModelInstanceInternal() { + return new LabelAndMultiplicityDataModel(); + } + @Override public Class getDataClass() { return LabelAndMultiplicityDataEntity.class; @@ -63,6 +71,11 @@ public class LabelAndMultiplicityFieldDataHelperService extends BaseFieldDataHel public Class getImportExportClass() { return LabelAndMultiplicityDataImportExport.class; } + + @Override + public Class getCommonModelClass() { + return LabelAndMultiplicityDataModel.class; + } @Override public Validator getPersistModelValidator() { @@ -73,7 +86,12 @@ public class LabelAndMultiplicityFieldDataHelperService extends BaseFieldDataHel public List buildInternal(FieldSet fieldSet, List data, EnumSet authorizationFlags){ return this.builderFactory.builder(LabelAndMultiplicityDataBuilder.class).authorize(authorizationFlags).build(fieldSet, data); } - + + @Override + protected List buildCommonModelInternal(List data, EnumSet authorizationFlags) { + return this.builderFactory.builder(LabelAndMultiplicityDataCommonModelBuilder.class).authorize(authorizationFlags).build(data); + } + @Override protected LabelAndMultiplicityDataEntity applyPersistInternal(LabelAndMultiplicityDataPersist persist, LabelAndMultiplicityDataEntity data) { data.setMultipleSelect(persist.getMultipleSelect()); @@ -96,4 +114,6 @@ public class LabelAndMultiplicityFieldDataHelperService extends BaseFieldDataHel protected boolean isMultiValueInternal(LabelAndMultiplicityDataEntity data) { return data.getMultipleSelect(); } + + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/LabelFieldDataHelperService.java b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/LabelFieldDataHelperService.java index 290e11321..3b3a141e2 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/LabelFieldDataHelperService.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/LabelFieldDataHelperService.java @@ -1,8 +1,13 @@ package eu.eudat.service.fielddatahelper; import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.LabelAndMultiplicityDataModel; +import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.LabelDataModel; +import eu.eudat.commons.types.descriptiontemplate.fielddata.LabelAndMultiplicityDataEntity; import eu.eudat.commons.types.descriptiontemplate.fielddata.LabelDataEntity; import eu.eudat.commons.types.descriptiontemplate.importexport.fielddata.LabelDataImportExport; +import eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata.LabelAndMultiplicityDataCommonModelBuilder; +import eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata.LabelDataCommonModelBuilder; import eu.eudat.model.builder.descriptiontemplatedefinition.fielddata.LabelDataBuilder; import eu.eudat.model.descriptiontemplatedefinition.fielddata.LabelData; import eu.eudat.model.persist.descriptiontemplatedefinition.fielddata.LabelDataPersist; @@ -16,7 +21,7 @@ import java.util.EnumSet; import java.util.List; @Component -public class LabelFieldDataHelperService extends BaseFieldDataHelperService { +public class LabelFieldDataHelperService extends BaseFieldDataHelperService { private final BuilderFactory builderFactory; private final ValidatorFactory validatorFactory; @@ -46,6 +51,11 @@ public class LabelFieldDataHelperService extends BaseFieldDataHelperService getDataClass() { return LabelDataEntity.class; @@ -63,6 +73,11 @@ public class LabelFieldDataHelperService extends BaseFieldDataHelperService getImportExportClass() { return LabelDataImportExport.class; } + + @Override + public Class getCommonModelClass() { + return LabelDataModel.class; + } @Override public Validator getPersistModelValidator() { @@ -74,6 +89,11 @@ public class LabelFieldDataHelperService extends BaseFieldDataHelperService buildCommonModelInternal(List data, EnumSet authorizationFlags) { + return this.builderFactory.builder(LabelDataCommonModelBuilder.class).authorize(authorizationFlags).build(data); + } + @Override protected LabelDataEntity applyPersistInternal(LabelDataPersist persist, LabelDataEntity data) { return data; diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/RadioBoxFieldDataHelperService.java b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/RadioBoxFieldDataHelperService.java index ad4e4ddbf..12ccdf7b2 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/RadioBoxFieldDataHelperService.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/RadioBoxFieldDataHelperService.java @@ -1,9 +1,14 @@ package eu.eudat.service.fielddatahelper; import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.LabelAndMultiplicityDataModel; +import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.RadioBoxDataModel; +import eu.eudat.commons.types.descriptiontemplate.fielddata.LabelAndMultiplicityDataEntity; import eu.eudat.commons.types.descriptiontemplate.fielddata.RadioBoxDataEntity; import eu.eudat.commons.types.descriptiontemplate.importexport.fielddata.RadioBoxDataImportExport; import eu.eudat.convention.ConventionService; +import eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata.LabelAndMultiplicityDataCommonModelBuilder; +import eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata.RadioBoxDataCommonModelBuilder; import eu.eudat.model.builder.descriptiontemplatedefinition.fielddata.RadioBoxDataBuilder; import eu.eudat.model.descriptiontemplatedefinition.fielddata.RadioBoxData; import eu.eudat.model.persist.descriptiontemplatedefinition.fielddata.*; @@ -19,7 +24,7 @@ import java.util.EnumSet; import java.util.List; @Component -public class RadioBoxFieldDataHelperService extends BaseFieldDataHelperService { +public class RadioBoxFieldDataHelperService extends BaseFieldDataHelperService { private final ConventionService conventionService; private final BuilderFactory builderFactory; @@ -52,6 +57,11 @@ public class RadioBoxFieldDataHelperService extends BaseFieldDataHelperService getDataClass() { return RadioBoxDataEntity.class; @@ -70,6 +80,11 @@ public class RadioBoxFieldDataHelperService extends BaseFieldDataHelperService getCommonModelClass() { + return RadioBoxDataModel.class; + } + @Override public Validator getPersistModelValidator() { return this.validatorFactory.validator(RadioBoxDataPersist.RadioBoxDataPersistValidator.class); @@ -80,6 +95,11 @@ public class RadioBoxFieldDataHelperService extends BaseFieldDataHelperService buildCommonModelInternal(List data, EnumSet authorizationFlags) { + return this.builderFactory.builder(RadioBoxDataCommonModelBuilder.class).authorize(authorizationFlags).build(data); + } + @Override protected RadioBoxDataEntity applyPersistInternal(RadioBoxDataPersist persist, RadioBoxDataEntity data) { if (!this.conventionService.isListNullOrEmpty(persist.getOptions())){ diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/ReferenceTypeFieldDataHelperService.java b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/ReferenceTypeFieldDataHelperService.java index aa9bfca35..b98964973 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/ReferenceTypeFieldDataHelperService.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/ReferenceTypeFieldDataHelperService.java @@ -1,8 +1,10 @@ package eu.eudat.service.fielddatahelper; import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.ReferenceTypeDataModel; import eu.eudat.commons.types.descriptiontemplate.fielddata.ReferenceTypeDataEntity; import eu.eudat.commons.types.descriptiontemplate.importexport.fielddata.ReferenceTypeDataImportExport; +import eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata.ReferenceTypeDataCommonModelBuilder; import eu.eudat.model.builder.descriptiontemplatedefinition.fielddata.ReferenceTypeDataBuilder; import eu.eudat.model.descriptiontemplatedefinition.fielddata.ReferenceTypeData; import eu.eudat.model.persist.descriptiontemplatedefinition.fielddata.ReferenceTypeDataPersist; @@ -16,7 +18,7 @@ import java.util.EnumSet; import java.util.List; @Component -public class ReferenceTypeFieldDataHelperService extends BaseFieldDataHelperService { +public class ReferenceTypeFieldDataHelperService extends BaseFieldDataHelperService { private final BuilderFactory builderFactory; @@ -46,6 +48,11 @@ public class ReferenceTypeFieldDataHelperService extends BaseFieldDataHelperServ return new ReferenceTypeDataImportExport(); } + @Override + protected ReferenceTypeDataModel newCommonModelInstanceInternal() { + return new ReferenceTypeDataModel(); + } + @Override public Class getDataClass() { return ReferenceTypeDataEntity.class; @@ -63,6 +70,11 @@ public class ReferenceTypeFieldDataHelperService extends BaseFieldDataHelperServ public Class getImportExportClass() { return ReferenceTypeDataImportExport.class; } + + @Override + public Class getCommonModelClass() { + return ReferenceTypeDataModel.class; + } @Override public Validator getPersistModelValidator() { @@ -74,6 +86,11 @@ public class ReferenceTypeFieldDataHelperService extends BaseFieldDataHelperServ return this.builderFactory.builder(ReferenceTypeDataBuilder.class).authorize(authorizationFlags).build(fieldSet, data); } + @Override + protected List buildCommonModelInternal(List data, EnumSet authorizationFlags) { + return this.builderFactory.builder(ReferenceTypeDataCommonModelBuilder.class).authorize(authorizationFlags).build(data); + } + @Override protected ReferenceTypeDataEntity applyPersistInternal(ReferenceTypeDataPersist persist, ReferenceTypeDataEntity data) { data.setMultipleSelect(persist.getMultipleSelect()); diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/SelectFieldDataHelperService.java b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/SelectFieldDataHelperService.java index d5fd8ca66..7d7b543cb 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/SelectFieldDataHelperService.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/SelectFieldDataHelperService.java @@ -1,9 +1,14 @@ package eu.eudat.service.fielddatahelper; import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.LabelAndMultiplicityDataModel; +import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.SelectDataModel; +import eu.eudat.commons.types.descriptiontemplate.fielddata.LabelAndMultiplicityDataEntity; import eu.eudat.commons.types.descriptiontemplate.fielddata.SelectDataEntity; import eu.eudat.commons.types.descriptiontemplate.importexport.fielddata.SelectDataImportExport; import eu.eudat.convention.ConventionService; +import eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata.LabelAndMultiplicityDataCommonModelBuilder; +import eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata.SelectDataCommonModelBuilder; import eu.eudat.model.builder.descriptiontemplatedefinition.fielddata.SelectDataBuilder; import eu.eudat.model.descriptiontemplatedefinition.fielddata.SelectData; import eu.eudat.model.persist.descriptiontemplatedefinition.fielddata.*; @@ -19,7 +24,7 @@ import java.util.EnumSet; import java.util.List; @Component -public class SelectFieldDataHelperService extends BaseFieldDataHelperService { +public class SelectFieldDataHelperService extends BaseFieldDataHelperService { private final ConventionService conventionService; private final BuilderFactory builderFactory; @@ -52,6 +57,11 @@ public class SelectFieldDataHelperService extends BaseFieldDataHelperService getDataClass() { return SelectDataEntity.class; @@ -65,6 +75,11 @@ public class SelectFieldDataHelperService extends BaseFieldDataHelperService getCommonModelClass() { + return SelectDataModel.class; + } + @Override public Class getImportExportClass() { return SelectDataImportExport.class; @@ -80,6 +95,11 @@ public class SelectFieldDataHelperService extends BaseFieldDataHelperService buildCommonModelInternal(List data, EnumSet authorizationFlags) { + return this.builderFactory.builder(SelectDataCommonModelBuilder.class).authorize(authorizationFlags).build(data); + } + @Override protected SelectDataEntity applyPersistInternal(SelectDataPersist persist, SelectDataEntity data) { data.setMultipleSelect(persist.getMultipleSelect()); diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/UploadFieldDataHelperService.java b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/UploadFieldDataHelperService.java index 47f0e91a0..e3907a4cf 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/UploadFieldDataHelperService.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/fielddatahelper/UploadFieldDataHelperService.java @@ -1,9 +1,14 @@ package eu.eudat.service.fielddatahelper; import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.LabelAndMultiplicityDataModel; +import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.SelectDataModel; +import eu.eudat.commons.types.descriptiontemplate.fielddata.LabelAndMultiplicityDataEntity; import eu.eudat.commons.types.descriptiontemplate.fielddata.UploadDataEntity; import eu.eudat.commons.types.descriptiontemplate.importexport.fielddata.UploadDataImportExport; import eu.eudat.convention.ConventionService; +import eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata.LabelAndMultiplicityDataCommonModelBuilder; +import eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata.UploadDataCommonModelBuilder; import eu.eudat.model.builder.descriptiontemplatedefinition.fielddata.UploadDataBuilder; import eu.eudat.model.descriptiontemplatedefinition.fielddata.UploadData; import eu.eudat.model.persist.descriptiontemplatedefinition.fielddata.*; @@ -19,7 +24,7 @@ import java.util.EnumSet; import java.util.List; @Component -public class UploadFieldDataHelperService extends BaseFieldDataHelperService { +public class UploadFieldDataHelperService extends BaseFieldDataHelperService { private final ConventionService conventionService; private final BuilderFactory builderFactory; @@ -52,6 +57,11 @@ public class UploadFieldDataHelperService extends BaseFieldDataHelperService getDataClass() { return UploadDataEntity.class; @@ -70,6 +80,11 @@ public class UploadFieldDataHelperService extends BaseFieldDataHelperService getCommonModelClass() { + return SelectDataModel.class; + } + @Override public Validator getPersistModelValidator() { @@ -81,6 +96,11 @@ public class UploadFieldDataHelperService extends BaseFieldDataHelperService buildCommonModelInternal(List data, EnumSet authorizationFlags) { + return this.builderFactory.builder(UploadDataCommonModelBuilder.class).authorize(authorizationFlags).build(data); + } + @Override protected UploadDataEntity applyPersistInternal(UploadDataPersist persist, UploadDataEntity data) { if (!this.conventionService.isListNullOrEmpty(persist.getTypes())){ @@ -124,7 +144,7 @@ public class UploadFieldDataHelperService extends BaseFieldDataHelperService gr.cite.opendmp repositorydepositbase - 2.0.0 + 2.0.1