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