diff --git a/dmp-backend/core/pom.xml b/dmp-backend/core/pom.xml
index 2f10987ea..0d24aa6b8 100644
--- a/dmp-backend/core/pom.xml
+++ b/dmp-backend/core/pom.xml
@@ -45,17 +45,17 @@
gr.cite.opendmp
repositorydepositbase
- 2.0.1
+ 2.0.2
gr.cite.opendmp
common-models
- 0.0.1
+ 0.0.2
gr.cite.opendmp
file-transformer-base
- 0.0.4
+ 0.0.5
gr.cite
diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/EntityDoiCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/EntityDoiCommonModelBuilder.java
new file mode 100644
index 000000000..5114bb5a6
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/EntityDoiCommonModelBuilder.java
@@ -0,0 +1,52 @@
+package eu.eudat.model.builder.commonmodels;
+
+import eu.eudat.authorization.AuthorizationFlags;
+import eu.eudat.commonmodels.models.EntityDoiModel;
+import eu.eudat.convention.ConventionService;
+import eu.eudat.data.EntityDoiEntity;
+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 EntityDoiCommonModelBuilder extends BaseCommonModelBuilder {
+
+ private EnumSet authorize = EnumSet.of(AuthorizationFlags.None);
+
+ @Autowired
+ public EntityDoiCommonModelBuilder(
+ ConventionService conventionService) {
+ super(conventionService, new LoggerService(LoggerFactory.getLogger(EntityDoiCommonModelBuilder.class)));
+ }
+
+ public EntityDoiCommonModelBuilder 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 (EntityDoiEntity d : data) {
+ EntityDoiModel m = new EntityDoiModel();
+ m.setId(d.getId());
+ m.setDoi(d.getDoi());
+ 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/DescriptionCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/description/DescriptionCommonModelBuilder.java
index 76c54d36f..fbbdcd7d7 100644
--- 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
@@ -1,8 +1,10 @@
package eu.eudat.model.builder.commonmodels.description;
import eu.eudat.authorization.AuthorizationFlags;
+import eu.eudat.commonmodels.enums.DescriptionStatus;
import eu.eudat.commonmodels.models.description.DescriptionModel;
import eu.eudat.commonmodels.models.descriptiotemplate.DescriptionTemplateModel;
+import eu.eudat.commonmodels.models.dmp.DmpModel;
import eu.eudat.commons.JsonHandlingService;
import eu.eudat.commons.XmlHandlingService;
import eu.eudat.commons.types.description.PropertyDefinitionEntity;
@@ -10,9 +12,13 @@ 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.data.DmpDescriptionTemplateEntity;
+import eu.eudat.data.DmpEntity;
import eu.eudat.model.DescriptionTemplate;
+import eu.eudat.model.DmpDescriptionTemplate;
import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
+import eu.eudat.model.builder.commonmodels.dmp.DmpCommonModelBuilder;
import eu.eudat.model.builder.commonmodels.descriptiontemplate.DescriptionTemplateCommonModelBuilder;
import eu.eudat.query.*;
import gr.cite.tools.data.builder.BuilderFactory;
@@ -64,14 +70,26 @@ public class DescriptionCommonModelBuilder extends BaseCommonModelBuilder();
Map descriptionTemplates = this.collectDescriptionTemplates(data);
+ Map dmps = this.collectDmps(data);
Map definitionEntityMap = this.collectDescriptionTemplateDefinitions(data);
+ Map dmpDescriptionTemplateSections = this.collectDmpDescriptionTemplateSections(data);
List> models = new ArrayList<>();
for (DescriptionEntity d : data) {
DescriptionModel m = new DescriptionModel();
m.setLabel(d.getLabel());
m.setDescription(d.getDescription());
+ switch (d.getStatus()){
+ case Finalized -> m.setStatus(DescriptionStatus.Finalized);
+ case Draft -> m.setStatus(DescriptionStatus.Draft);
+ case Canceled -> m.setStatus(DescriptionStatus.Canceled);
+ default -> throw new MyApplicationException("unrecognized type " + d.getStatus());
+ }
+ m.setCreatedAt(d.getCreatedAt());
+ m.setDescription(d.getDescription());
+ if (dmps != null && d.getDmpId() != null && dmps.containsKey(d.getDmpId())) m.setDmp(dmps.get(d.getDmpId()));
+ if (dmpDescriptionTemplateSections != null && d.getDmpDescriptionTemplateId() != null && dmpDescriptionTemplateSections.containsKey(d.getDmpDescriptionTemplateId())) m.setSectionId(dmpDescriptionTemplateSections.get(d.getDmpDescriptionTemplateId()));
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
@@ -102,6 +120,33 @@ public class DescriptionCommonModelBuilder extends BaseCommonModelBuilder collectDmpDescriptionTemplateSections(List data) throws MyApplicationException {
+ if (data.isEmpty())
+ return null;
+ this.logger.debug("checking related - {}", DefinitionEntity.class.getSimpleName());
+
+ Map itemMap = new HashMap<>();
+ DmpDescriptionTemplateQuery q = this.queryFactory.query(DmpDescriptionTemplateQuery.class).authorize(this.authorize).ids(data.stream().map(DescriptionEntity::getDmpDescriptionTemplateId).distinct().collect(Collectors.toList()));
+ List items = q.collectAs(new BaseFieldSet().ensure(eu.eudat.model.DmpDescriptionTemplate._id).ensure(DmpDescriptionTemplate._sectionId));
+ for (DmpDescriptionTemplateEntity item : items){
+ itemMap.put(item.getId(), item.getSectionId());
+ }
+
+ return itemMap;
+ }
+
+ private Map collectDmps(List data) throws MyApplicationException {
+ if (data.isEmpty())
+ return null;
+ this.logger.debug("checking related - {}", DmpModel.class.getSimpleName());
+
+ Map itemMap;
+ DmpQuery q = this.queryFactory.query(DmpQuery.class).authorize(this.authorize).ids(data.stream().map(DescriptionEntity::getDmpId).distinct().collect(Collectors.toList()));
+ itemMap = this.builderFactory.builder(DmpCommonModelBuilder.class).setDisableDescriptions(true).authorize(this.authorize).asForeignKey(q, DmpEntity::getId);
+
+ return itemMap;
+ }
+
private Map collectDescriptionTemplates(List data) throws MyApplicationException {
if (data.isEmpty())
return null;
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
index ae75db44f..4350b8b76 100644
--- 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
@@ -4,10 +4,13 @@ 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.commons.types.descriptiontemplate.DefinitionEntity;
+import eu.eudat.commons.types.dmp.DmpPropertiesEntity;
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 eu.eudat.model.builder.commonmodels.dmp.DmpPropertiesCommonModelBuilder;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
@@ -24,24 +27,16 @@ import java.util.*;
@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);
+ private final XmlHandlingService xmlHandlingService;
+ private final BuilderFactory builderFactory;
@Autowired
public DescriptionTemplateCommonModelBuilder(
- ConventionService conventionService,
- QueryFactory queryFactory,
- BuilderFactory builderFactory, JsonHandlingService jsonHandlingService, XmlHandlingService xmlHandlingService) {
+ ConventionService conventionService, XmlHandlingService xmlHandlingService, BuilderFactory builderFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionTemplateCommonModelBuilder.class)));
- this.queryFactory = queryFactory;
- this.builderFactory = builderFactory;
- this.jsonHandlingService = jsonHandlingService;
this.xmlHandlingService = xmlHandlingService;
+ this.builderFactory = builderFactory;
}
public DescriptionTemplateCommonModelBuilder authorize(EnumSet values) {
@@ -63,6 +58,11 @@ public class DescriptionTemplateCommonModelBuilder extends BaseCommonModelBuilde
m.setGroupId(d.getGroupId());
m.setVersion(d.getVersion());
m.setLanguage(d.getLanguage());
+ if (d.getDefinition() != null){
+ //TODO Update with the new logic of property definition
+ DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(DefinitionEntity.class, d.getDefinition());
+ m.setDefinition(this.builderFactory.builder(DefinitionCommonModelBuilder.class).authorize(this.authorize).build(definition));
+ }
models.add(new CommonModelBuilderItemResponse<>(m, d));
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
index 551c3aad2..89a025dff 100644
--- 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
@@ -55,7 +55,6 @@ public class FieldSetCommonModelBuilder extends BaseCommonModelBuilder(m, d));
diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmp/DmpBlueprintValueCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmp/DmpBlueprintValueCommonModelBuilder.java
new file mode 100644
index 000000000..c5874aab4
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmp/DmpBlueprintValueCommonModelBuilder.java
@@ -0,0 +1,55 @@
+package eu.eudat.model.builder.commonmodels.dmp;
+
+import eu.eudat.authorization.AuthorizationFlags;
+import eu.eudat.commonmodels.models.dmp.DmpBlueprintValueModel;
+import eu.eudat.commons.types.dmp.DmpBlueprintValueEntity;
+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 DmpBlueprintValueCommonModelBuilder extends BaseCommonModelBuilder {
+ private EnumSet authorize = EnumSet.of(AuthorizationFlags.None);
+ @Autowired
+ public DmpBlueprintValueCommonModelBuilder(
+ ConventionService conventionService
+ ) {
+ super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpBlueprintValueCommonModelBuilder.class)));
+ }
+
+ public DmpBlueprintValueCommonModelBuilder 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 (DmpBlueprintValueEntity d : data) {
+ DmpBlueprintValueModel m = new DmpBlueprintValueModel();
+ m.setValue(d.getValue());
+ m.setFieldId(d.getFieldId());
+ 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/DmpCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmp/DmpCommonModelBuilder.java
similarity index 58%
rename from dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/DmpCommonModelBuilder.java
rename to dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmp/DmpCommonModelBuilder.java
index 50bca1e72..48990d5bc 100644
--- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/DmpCommonModelBuilder.java
+++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmp/DmpCommonModelBuilder.java
@@ -1,17 +1,27 @@
-package eu.eudat.model.builder.commonmodels;
+package eu.eudat.model.builder.commonmodels.dmp;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commonmodels.enums.DmpAccessType;
-import eu.eudat.commonmodels.models.DmpModel;
+import eu.eudat.commonmodels.enums.DmpStatus;
import eu.eudat.commonmodels.models.DmpUserModel;
+import eu.eudat.commonmodels.models.EntityDoiModel;
import eu.eudat.commonmodels.models.FileEnvelopeModel;
+import eu.eudat.commonmodels.models.UserModel;
import eu.eudat.commonmodels.models.description.DescriptionModel;
+import eu.eudat.commonmodels.models.dmp.DmpModel;
+import eu.eudat.commonmodels.models.dmpblueprint.DmpBlueprintModel;
+import eu.eudat.commonmodels.models.dmpreference.DmpReferenceModel;
import eu.eudat.commonmodels.models.reference.ReferenceModel;
+import eu.eudat.commons.JsonHandlingService;
import eu.eudat.commons.enums.IsActive;
+import eu.eudat.commons.types.dmp.DmpPropertiesEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.*;
import eu.eudat.model.*;
+import eu.eudat.model.builder.commonmodels.*;
import eu.eudat.model.builder.commonmodels.description.DescriptionCommonModelBuilder;
+import eu.eudat.model.builder.commonmodels.dmpblueprint.DmpBlueprintCommonModelBuilder;
+import eu.eudat.model.builder.commonmodels.dmpreference.DmpReferenceCommonModelBuilder;
import eu.eudat.model.builder.commonmodels.reference.ReferenceCommonModelBuilder;
import eu.eudat.query.*;
import gr.cite.tools.data.builder.BuilderFactory;
@@ -36,19 +46,22 @@ public class DmpCommonModelBuilder extends BaseCommonModelBuilder authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public DmpCommonModelBuilder(ConventionService conventionService,
QueryFactory queryFactory,
- BuilderFactory builderFactory) {
+ BuilderFactory builderFactory, JsonHandlingService jsonHandlingService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpCommonModelBuilder.class)));
this.queryFactory = queryFactory;
this.builderFactory = builderFactory;
+ this.jsonHandlingService = jsonHandlingService;
}
public DmpCommonModelBuilder authorize(EnumSet values) {
@@ -76,18 +89,24 @@ public class DmpCommonModelBuilder extends BaseCommonModelBuilder> buildInternal(List data) throws MyApplicationException {
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
if (data == null || data.isEmpty()) return new ArrayList<>();
List> models = new ArrayList<>();
-
- Map> dmpReferencesMap = this.collectReferences(data);
-
+
+ Map> dmpReferencesMap = this.collectDmpReferences(data);
Map> dmpUsersMap = this.collectDmpUsers(data);
-
- Map> descriptionsMap = this.collectDmpDescriptions(data);
+ Map> descriptionsMap = this.disableDescriptions ? null : this.collectDmpDescriptions(data);
+ Map> entityDois = this.collectDmpEntityDois(data);
+ Map creators = this.collectCreators(data);
+ Map dmpBlueprints = this.collectDmpBlueprints(data);
for (DmpEntity d : data) {
DmpModel m = new DmpModel();
@@ -96,6 +115,21 @@ public class DmpCommonModelBuilder extends BaseCommonModelBuilder m.setStatus(DmpStatus.Finalized);
+ case Draft -> m.setStatus(DmpStatus.Draft);
+ default -> throw new MyApplicationException("unrecognized type " + d.getStatus());
+ }
+ if (entityDois != null && !entityDois.isEmpty() && entityDois.containsKey(d.getId())) m.setEntityDois(entityDois.get(d.getId()));
+ if (creators != null && !creators.isEmpty() && d.getCreatorId() != null && creators.containsKey(d.getCreatorId())) m.setCreator(creators.get(d.getCreatorId()));
+ if (dmpBlueprints != null && !dmpBlueprints.isEmpty() && d.getBlueprintId() != null && dmpBlueprints.containsKey(d.getBlueprintId())) m.setDmpBlueprint(dmpBlueprints.get(d.getBlueprintId()));
+ if (d.getProperties() != null){
+ //TODO Update with the new logic of property definition
+ DmpPropertiesEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(DmpPropertiesEntity.class, d.getProperties());
+ m.setProperties(this.builderFactory.builder(DmpPropertiesCommonModelBuilder.class).authorize(this.authorize).build(propertyDefinition));
+ }
+ m.setPublicAfter(d.getPublicAfter());
+ m.setUpdatedAt(d.getUpdatedAt());
m.setPdfFile(this.pdfFile);
m.setRdaJsonFile(this.rdaJsonFile);
m.setSupportingFilesZip(this.supportingFilesZip);
@@ -104,8 +138,9 @@ public class DmpCommonModelBuilder extends BaseCommonModelBuilder m.setAccessType(DmpAccessType.Public);
case Restricted -> m.setAccessType(DmpAccessType.Restricted);
case null -> m.setAccessType(null);
- default -> throw new MyApplicationException("unrecognized type " + d.getAccessType().getValue());
+ default -> throw new MyApplicationException("unrecognized type " + d.getAccessType());
}
+
if (dmpReferencesMap != null && !dmpReferencesMap.isEmpty() && dmpReferencesMap.containsKey(d.getId())) m.setReferences(dmpReferencesMap.get(d.getId()));
if (dmpUsersMap != null && !dmpUsersMap.isEmpty() && dmpUsersMap.containsKey(d.getId())) m.setUsers(dmpUsersMap.get(d.getId()));
if (descriptionsMap != null && !descriptionsMap.isEmpty() && descriptionsMap.containsKey(d.getId())) m.setDescriptions(descriptionsMap.get(d.getId()));
@@ -134,27 +169,6 @@ public class DmpCommonModelBuilder extends BaseCommonModelBuilder> collectReferences(List data) throws MyApplicationException {
- if (data.isEmpty()) return null;
- this.logger.debug("checking related - {}", DmpReference.class.getSimpleName());
-
- List dmpReferences = this.queryFactory.query(DmpReferenceQuery.class).isActives(IsActive.Active).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList())).collectAs(new BaseFieldSet().ensure(DmpReference._dmp).ensure(DmpReference._reference));
-
- Map> itemMap = new HashMap<>();
- ReferenceQuery query = this.queryFactory.query(ReferenceQuery.class).authorize(this.authorize).isActive(IsActive.Active).ids(dmpReferences.stream().map(DmpReferenceEntity::getReferenceId).distinct().collect(Collectors.toList()));
- Map referenceModelMap = this.builderFactory.builder(ReferenceCommonModelBuilder.class).authorize(this.authorize).asForeignKey(query, ReferenceEntity::getId);
- if (referenceModelMap == null) return null;
- for (DmpReferenceEntity dmpReference : dmpReferences) {
- ReferenceModel model =referenceModelMap.getOrDefault(dmpReference.getReferenceId(), null);
- if (model == null) continue;;
- UUID key = dmpReference.getDmpId();
- if (!itemMap.containsKey(key)) itemMap.put(key, new ArrayList<>());
- itemMap.get(key).add(model);
- }
- return itemMap;
- }
-
-
private Map> collectDmpUsers(List data) throws MyApplicationException {
this.logger.debug("checking related - {}", DmpUser.class.getSimpleName());
@@ -165,6 +179,16 @@ public class DmpCommonModelBuilder extends BaseCommonModelBuilder> collectDmpReferences(List data) throws MyApplicationException {
+ this.logger.debug("checking related - {}", DmpReference.class.getSimpleName());
+
+ Map> itemMap;
+ DmpReferenceQuery query = this.queryFactory.query(DmpReferenceQuery.class).isActives(IsActive.Active).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList()));
+ itemMap = this.builderFactory.builder(DmpReferenceCommonModelBuilder.class).authorize(this.authorize).asMasterKey(query, DmpReferenceEntity::getDmpId);
+
+ return itemMap;
+ }
+
private Map> collectDmpDescriptions(List data) throws MyApplicationException {
if (data.isEmpty()) return null;
this.logger.debug("checking related - {}", Description.class.getSimpleName());
@@ -176,4 +200,37 @@ public class DmpCommonModelBuilder extends BaseCommonModelBuilder> collectDmpEntityDois(List data) throws MyApplicationException {
+ if (data.isEmpty()) return null;
+ this.logger.debug("checking related - {}", EntityDoi.class.getSimpleName());
+
+ Map> itemMap;
+ EntityDoiQuery query = this.queryFactory.query(EntityDoiQuery.class).isActive(IsActive.Active).authorize(this.authorize).entityIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList()));
+ itemMap = this.builderFactory.builder(EntityDoiCommonModelBuilder.class).authorize(this.authorize).asMasterKey(query, EntityDoiEntity::getEntityId);
+
+ return itemMap;
+ }
+
+ private Map collectCreators(List data) throws MyApplicationException {
+ if (data.isEmpty())
+ return null;
+ this.logger.debug("checking related - {}", UserModel.class.getSimpleName());
+
+ Map itemMap;
+ UserQuery q = this.queryFactory.query(UserQuery.class).isActive(IsActive.Active).authorize(this.authorize).ids(data.stream().filter(x-> x.getCreatorId() != null).map(DmpEntity::getCreatorId).distinct().collect(Collectors.toList()));
+ itemMap = this.builderFactory.builder(UserCommonModelBuilder.class).authorize(this.authorize).asForeignKey(q, UserEntity::getId);
+ return itemMap;
+ }
+
+ private Map collectDmpBlueprints(List data) throws MyApplicationException {
+ if (data.isEmpty())
+ return null;
+ this.logger.debug("checking related - {}", DmpBlueprintModel.class.getSimpleName());
+
+ Map itemMap;
+ DmpBlueprintQuery q = this.queryFactory.query(DmpBlueprintQuery.class).isActive(IsActive.Active).authorize(this.authorize).ids(data.stream().filter(x-> x.getBlueprintId() != null).map(DmpEntity::getBlueprintId).distinct().collect(Collectors.toList()));
+ itemMap = this.builderFactory.builder(DmpBlueprintCommonModelBuilder.class).authorize(this.authorize).asForeignKey(q, DmpBlueprintEntity::getId);
+ return itemMap;
+ }
+
}
diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmp/DmpPropertiesCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmp/DmpPropertiesCommonModelBuilder.java
new file mode 100644
index 000000000..962c09d45
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmp/DmpPropertiesCommonModelBuilder.java
@@ -0,0 +1,59 @@
+package eu.eudat.model.builder.commonmodels.dmp;
+
+import eu.eudat.authorization.AuthorizationFlags;
+import eu.eudat.commonmodels.models.dmp.DmpPropertiesModel;
+import eu.eudat.commons.types.dmp.DmpPropertiesEntity;
+import eu.eudat.convention.ConventionService;
+import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
+import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
+import eu.eudat.model.builder.commonmodels.descriptiontemplate.PageCommonModelBuilder;
+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 DmpPropertiesCommonModelBuilder extends BaseCommonModelBuilder {
+ private final BuilderFactory builderFactory;
+ private EnumSet authorize = EnumSet.of(AuthorizationFlags.None);
+ @Autowired
+ public DmpPropertiesCommonModelBuilder(
+ ConventionService conventionService, BuilderFactory builderFactory
+ ) {
+ super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpPropertiesCommonModelBuilder.class)));
+ this.builderFactory = builderFactory;
+ }
+
+ public DmpPropertiesCommonModelBuilder 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 (DmpPropertiesEntity d : data) {
+ DmpPropertiesModel m = new DmpPropertiesModel();
+ if (d.getDmpBlueprintValues() != null) m.setDmpBlueprintValues(this.builderFactory.builder(DmpBlueprintValueCommonModelBuilder.class).authorize(this.authorize).build(d.getDmpBlueprintValues()));
+
+ 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/dmpblueprint/DefinitionCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmpblueprint/DefinitionCommonModelBuilder.java
new file mode 100644
index 000000000..3e97f383a
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmpblueprint/DefinitionCommonModelBuilder.java
@@ -0,0 +1,59 @@
+package eu.eudat.model.builder.commonmodels.dmpblueprint;
+
+import eu.eudat.authorization.AuthorizationFlags;
+import eu.eudat.commonmodels.models.dmpblueprint.DefinitionModel;
+import eu.eudat.commons.types.dmpblueprint.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.commonmodels.dmp.DmpBlueprintValueCommonModelBuilder;
+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("dmpblueprint.DefinitionCommonModelBuilder")
+@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.getSections() != null) 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/dmpblueprint/DmpBlueprintCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmpblueprint/DmpBlueprintCommonModelBuilder.java
new file mode 100644
index 000000000..088753bb6
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmpblueprint/DmpBlueprintCommonModelBuilder.java
@@ -0,0 +1,78 @@
+package eu.eudat.model.builder.commonmodels.dmpblueprint;
+
+import eu.eudat.authorization.AuthorizationFlags;
+import eu.eudat.commonmodels.enums.DmpBlueprintStatus;
+import eu.eudat.commonmodels.models.dmpblueprint.DmpBlueprintModel;
+import eu.eudat.commons.XmlHandlingService;
+import eu.eudat.commons.types.dmpblueprint.DefinitionEntity;
+import eu.eudat.convention.ConventionService;
+import eu.eudat.data.DmpBlueprintEntity;
+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 DmpBlueprintCommonModelBuilder extends BaseCommonModelBuilder {
+
+ private final BuilderFactory builderFactory;
+ private final XmlHandlingService xmlHandlingService;
+ private EnumSet authorize = EnumSet.of(AuthorizationFlags.None);
+
+ @Autowired
+ public DmpBlueprintCommonModelBuilder(ConventionService conventionService,
+ BuilderFactory builderFactory, XmlHandlingService xmlHandlingService) {
+ super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpBlueprintCommonModelBuilder.class)));
+ this.builderFactory = builderFactory;
+ this.xmlHandlingService = xmlHandlingService;
+ }
+
+ public DmpBlueprintCommonModelBuilder 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 (DmpBlueprintEntity d : data) {
+ DmpBlueprintModel m = new DmpBlueprintModel();
+ m.setId(d.getId());
+ m.setLabel(d.getLabel());
+ m.setGroupId(d.getGroupId());
+ switch (d.getStatus()){
+ case Finalized -> m.setStatus(DmpBlueprintStatus.Finalized);
+ case Draft -> m.setStatus(DmpBlueprintStatus.Draft);
+ default -> throw new MyApplicationException("unrecognized type " + d.getStatus());
+ }
+ if (d.getDefinition() != null){
+ //TODO Update with the new logic of property definition
+ DefinitionEntity propertyDefinition = this.xmlHandlingService.fromXmlSafe(DefinitionEntity.class, d.getDefinition());
+ m.setDefinition(this.builderFactory.builder(DefinitionCommonModelBuilder.class).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;
+ }
+
+}
diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmpblueprint/ExtraFieldCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmpblueprint/ExtraFieldCommonModelBuilder.java
new file mode 100644
index 000000000..786ac4dd3
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmpblueprint/ExtraFieldCommonModelBuilder.java
@@ -0,0 +1,41 @@
+package eu.eudat.model.builder.commonmodels.dmpblueprint;
+
+import eu.eudat.commonmodels.enums.DmpBlueprintExtraFieldDataType;
+import eu.eudat.commonmodels.models.dmpblueprint.ExtraFieldModel;
+import eu.eudat.commons.types.dmpblueprint.ExtraFieldEntity;
+import eu.eudat.convention.ConventionService;
+import eu.eudat.model.dmpblueprintdefinition.ExtraField;
+import gr.cite.tools.exception.MyApplicationException;
+import gr.cite.tools.fieldset.FieldSet;
+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 ExtraFieldCommonModelBuilder extends FieldCommonModelBuilder {
+
+ @Autowired
+ public ExtraFieldCommonModelBuilder(
+ ConventionService conventionService) {
+ super(conventionService);
+ }
+
+ protected ExtraFieldModel getInstance() {
+ return new ExtraFieldModel();
+ }
+
+ protected ExtraFieldModel buildChild(ExtraFieldEntity data, ExtraFieldModel model) {
+ switch (data.getType()){
+ case Date -> model.setDataType(DmpBlueprintExtraFieldDataType.Date);
+ case Number -> model.setDataType(DmpBlueprintExtraFieldDataType.Number);
+ case RichTex -> model.setDataType(DmpBlueprintExtraFieldDataType.RichTex);
+ case Text -> model.setDataType(DmpBlueprintExtraFieldDataType.Text);
+ default -> throw new MyApplicationException("unrecognized type " + data.getType());
+ }
+ return model;
+ }
+}
diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmpblueprint/FieldCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmpblueprint/FieldCommonModelBuilder.java
new file mode 100644
index 000000000..b8b20ff61
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmpblueprint/FieldCommonModelBuilder.java
@@ -0,0 +1,77 @@
+package eu.eudat.model.builder.commonmodels.dmpblueprint;
+
+import eu.eudat.authorization.AuthorizationFlags;
+import eu.eudat.commonmodels.enums.DmpBlueprintFieldCategory;
+import eu.eudat.commonmodels.models.dmpblueprint.FieldModel;
+import eu.eudat.commons.types.dmpblueprint.FieldEntity;
+import eu.eudat.convention.ConventionService;
+import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
+import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
+import eu.eudat.model.builder.commonmodels.dmp.DmpBlueprintValueCommonModelBuilder;
+import eu.eudat.model.dmpblueprintdefinition.Field;
+import gr.cite.tools.data.builder.BuilderFactory;
+import gr.cite.tools.exception.MyApplicationException;
+import gr.cite.tools.fieldset.FieldSet;
+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("dmpblueprint.FieldCommonModelBuilder")
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+public abstract class FieldCommonModelBuilder extends BaseCommonModelBuilder {
+ private EnumSet authorize = EnumSet.of(AuthorizationFlags.None);
+ @Autowired
+ public FieldCommonModelBuilder(
+ ConventionService conventionService
+ ) {
+ super(conventionService, new LoggerService(LoggerFactory.getLogger(FieldCommonModelBuilder.class)));
+ }
+
+ public FieldCommonModelBuilder authorize(EnumSet values) {
+ this.authorize = values;
+ return this;
+ }
+
+ protected abstract Model getInstance();
+
+ protected abstract Model buildChild(Entity data, Model model);
+
+ @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.setId(d.getId());
+ m.setDescription(d.getDescription());
+ switch (d.getCategory()){
+ case System -> m.setCategory(DmpBlueprintFieldCategory.System);
+ case Extra -> m.setCategory(DmpBlueprintFieldCategory.Extra);
+ case ReferenceType -> m.setCategory(DmpBlueprintFieldCategory.ReferenceType);
+ default -> throw new MyApplicationException("unrecognized type " + d.getCategory());
+ }
+ m.setPlaceholder(d.getPlaceholder());
+ m.setDescription(d.getDescription());
+ m.setSemantics(d.getSemantics());
+ m.setRequired(d.isRequired());
+ m.setLabel(d.getLabel());
+ m.setOrdinal(d.getOrdinal());
+ 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/dmpblueprint/ReferenceTypeFieldCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmpblueprint/ReferenceTypeFieldCommonModelBuilder.java
new file mode 100644
index 000000000..69f23d359
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmpblueprint/ReferenceTypeFieldCommonModelBuilder.java
@@ -0,0 +1,37 @@
+package eu.eudat.model.builder.commonmodels.dmpblueprint;
+
+import eu.eudat.commonmodels.models.dmpblueprint.ReferenceTypeFieldModel;
+import eu.eudat.commons.types.dmpblueprint.ReferenceTypeFieldEntity;
+import eu.eudat.convention.ConventionService;
+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 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 ReferenceTypeFieldCommonModelBuilder extends FieldCommonModelBuilder {
+ private final QueryFactory queryFactory;
+ private final BuilderFactory builderFactory;
+ @Autowired
+ public ReferenceTypeFieldCommonModelBuilder(
+ ConventionService conventionService, QueryFactory queryFactory, BuilderFactory builderFactory) {
+ super(conventionService);
+ this.queryFactory = queryFactory;
+ this.builderFactory = builderFactory;
+ }
+
+ protected ReferenceTypeFieldModel getInstance() {
+ return new ReferenceTypeFieldModel();
+ }
+
+ protected ReferenceTypeFieldModel buildChild(ReferenceTypeFieldEntity data, ReferenceTypeFieldModel model) {
+ if (data.getReferenceTypeId() != null ) model.setReferenceType(this.builderFactory.builder(ReferenceTypeCommonModelBuilder.class).build(this.queryFactory.query(ReferenceTypeQuery.class).ids(data.getReferenceTypeId()).first())); //TODO: Optimize
+
+ return model;
+ }
+}
diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmpblueprint/SectionCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmpblueprint/SectionCommonModelBuilder.java
new file mode 100644
index 000000000..a2e87b54e
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmpblueprint/SectionCommonModelBuilder.java
@@ -0,0 +1,76 @@
+package eu.eudat.model.builder.commonmodels.dmpblueprint;
+
+import eu.eudat.authorization.AuthorizationFlags;
+import eu.eudat.commonmodels.models.dmpblueprint.SectionModel;
+import eu.eudat.commons.enums.DmpBlueprintFieldCategory;
+import eu.eudat.commons.types.dmpblueprint.ExtraFieldEntity;
+import eu.eudat.commons.types.dmpblueprint.ReferenceTypeFieldEntity;
+import eu.eudat.commons.types.dmpblueprint.SectionEntity;
+import eu.eudat.commons.types.dmpblueprint.SystemFieldEntity;
+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("dmpblueprint.SectionCommonModelBuilder")
+@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.setLabel(d.getLabel());
+ m.setOrdinal(d.getOrdinal());
+ m.setHasTemplates(d.getHasTemplates());
+
+ if ( d.getFields() != null) {
+ m.setFields(new ArrayList<>());
+ List systemFieldEntities = d.getFields().stream().filter(x-> DmpBlueprintFieldCategory.System.equals(x.getCategory())).map(x-> (SystemFieldEntity)x).toList();
+ m.getFields().addAll(this.builderFactory.builder(SystemFieldCommonModelBuilder.class).authorize(this.authorize).build(systemFieldEntities));
+ List extraFieldEntities = d.getFields().stream().filter(x-> DmpBlueprintFieldCategory.Extra.equals(x.getCategory())).map(x-> (ExtraFieldEntity)x).toList();
+ m.getFields().addAll(this.builderFactory.builder(ExtraFieldCommonModelBuilder.class).authorize(this.authorize).build(extraFieldEntities));
+ List referenceFieldEntities = d.getFields().stream().filter(x-> DmpBlueprintFieldCategory.ReferenceType.equals(x.getCategory())).map(x-> (ReferenceTypeFieldEntity)x).toList();
+ m.getFields().addAll(this.builderFactory.builder(ReferenceTypeFieldCommonModelBuilder.class).authorize(this.authorize).build(referenceFieldEntities));
+ }
+
+ 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/dmpblueprint/SystemFieldCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmpblueprint/SystemFieldCommonModelBuilder.java
new file mode 100644
index 000000000..169903ccd
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmpblueprint/SystemFieldCommonModelBuilder.java
@@ -0,0 +1,39 @@
+package eu.eudat.model.builder.commonmodels.dmpblueprint;
+
+import eu.eudat.commonmodels.enums.DmpBlueprintSystemFieldType;
+import eu.eudat.commonmodels.models.dmpblueprint.SystemFieldModel;
+import eu.eudat.commons.types.dmpblueprint.SystemFieldEntity;
+import eu.eudat.convention.ConventionService;
+import gr.cite.tools.exception.MyApplicationException;
+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 SystemFieldCommonModelBuilder extends FieldCommonModelBuilder {
+
+ @Autowired
+ public SystemFieldCommonModelBuilder(
+ ConventionService conventionService) {
+ super(conventionService);
+ }
+
+ protected SystemFieldModel getInstance() {
+ return new SystemFieldModel();
+ }
+
+ protected SystemFieldModel buildChild(SystemFieldEntity data, SystemFieldModel model) {
+ switch (data.getType()){
+ case AccessRights -> model.setSystemFieldType(DmpBlueprintSystemFieldType.AccessRights);
+ case Contact -> model.setSystemFieldType(DmpBlueprintSystemFieldType.Contact);
+ case Description -> model.setSystemFieldType(DmpBlueprintSystemFieldType.Description);
+ case Language -> model.setSystemFieldType(DmpBlueprintSystemFieldType.Language);
+ case Title -> model.setSystemFieldType(DmpBlueprintSystemFieldType.Title);
+ case User -> model.setSystemFieldType(DmpBlueprintSystemFieldType.User);
+ default -> throw new MyApplicationException("unrecognized type " + data.getType());
+ }
+ return model;
+ }
+}
diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmpreference/DmpReferenceCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmpreference/DmpReferenceCommonModelBuilder.java
new file mode 100644
index 000000000..26fbf8282
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmpreference/DmpReferenceCommonModelBuilder.java
@@ -0,0 +1,86 @@
+package eu.eudat.model.builder.commonmodels.dmpreference;
+
+import eu.eudat.authorization.AuthorizationFlags;
+import eu.eudat.commonmodels.models.dmpreference.DmpReferenceModel;
+import eu.eudat.commonmodels.models.reference.ReferenceModel;
+import eu.eudat.commons.JsonHandlingService;
+import eu.eudat.commons.types.dmpreference.DmpReferenceDataEntity;
+import eu.eudat.convention.ConventionService;
+import eu.eudat.data.DmpReferenceEntity;
+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.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 DmpReferenceCommonModelBuilder extends BaseCommonModelBuilder {
+
+ private final BuilderFactory builderFactory;
+ private final QueryFactory queryFactory;
+ private final JsonHandlingService jsonHandlingService;
+ private EnumSet authorize = EnumSet.of(AuthorizationFlags.None);
+
+ @Autowired
+ public DmpReferenceCommonModelBuilder(
+ ConventionService conventionService,
+ BuilderFactory builderFactory, QueryFactory queryFactory, JsonHandlingService jsonHandlingService) {
+ super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpReferenceCommonModelBuilder.class)));
+ this.builderFactory = builderFactory;
+ this.queryFactory = queryFactory;
+ this.jsonHandlingService = jsonHandlingService;
+ }
+
+ public DmpReferenceCommonModelBuilder 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 referenceModelMap = this.collectReferences(data);
+ List> models = new ArrayList<>();
+ for (DmpReferenceEntity d : data) {
+ DmpReferenceModel m = new DmpReferenceModel();
+ m.setId(d.getId());
+ if (d.getData() != null){
+ DmpReferenceDataEntity definition = this.jsonHandlingService.fromJsonSafe(DmpReferenceDataEntity.class, d.getData());
+ m.setData(this.builderFactory.builder(DmpReferenceDataCommonModelBuilder.class).authorize(this.authorize).build(definition));
+ }
+ if (referenceModelMap != null && d.getReferenceId() != null && referenceModelMap.containsKey(d.getReferenceId())) m.setReference(referenceModelMap.get(d.getReferenceId()));
+
+ 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 - {}", ReferenceModel.class.getSimpleName());
+
+ Map itemMap;
+ ReferenceQuery q = this.queryFactory.query(ReferenceQuery.class).authorize(this.authorize).ids(data.stream().map(DmpReferenceEntity::getReferenceId).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/dmpreference/DmpReferenceDataCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmpreference/DmpReferenceDataCommonModelBuilder.java
new file mode 100644
index 000000000..59b7abd1e
--- /dev/null
+++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/dmpreference/DmpReferenceDataCommonModelBuilder.java
@@ -0,0 +1,56 @@
+package eu.eudat.model.builder.commonmodels.dmpreference;
+
+import eu.eudat.authorization.AuthorizationFlags;
+import eu.eudat.commonmodels.models.dmpreference.DmpReferenceDataModel;
+import eu.eudat.commons.types.dmpreference.DmpReferenceDataEntity;
+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 DmpReferenceDataCommonModelBuilder extends BaseCommonModelBuilder {
+
+ private final BuilderFactory builderFactory;
+ private EnumSet authorize = EnumSet.of(AuthorizationFlags.None);
+
+ @Autowired
+ public DmpReferenceDataCommonModelBuilder(
+ ConventionService conventionService, BuilderFactory builderFactory) {
+ super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpReferenceDataCommonModelBuilder.class)));
+ this.builderFactory = builderFactory;
+ }
+
+ public DmpReferenceDataCommonModelBuilder 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 (DmpReferenceDataEntity d : data) {
+ DmpReferenceDataModel m = new DmpReferenceDataModel();
+ m.setBlueprintFieldId(d.getBlueprintFieldId());
+ 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/ReferenceDefinitionCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/reference/ReferenceDefinitionCommonModelBuilder.java
index c954e5f0a..4404b9b50 100644
--- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/reference/ReferenceDefinitionCommonModelBuilder.java
+++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/reference/ReferenceDefinitionCommonModelBuilder.java
@@ -13,9 +13,11 @@ 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 ReferenceDefinitionCommonModelBuilder extends BaseCommonModelBuilder {
diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/reference/ReferenceFieldCommonModelBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/reference/ReferenceFieldCommonModelBuilder.java
index c5481b0e3..a4900e903 100644
--- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/reference/ReferenceFieldCommonModelBuilder.java
+++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/commonmodels/reference/ReferenceFieldCommonModelBuilder.java
@@ -12,12 +12,14 @@ 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 ReferenceFieldCommonModelBuilder extends BaseCommonModelBuilder {
diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/file/TransformerCacheModel.java b/dmp-backend/core/src/main/java/eu/eudat/model/file/TransformerCacheModel.java
index c08809b10..7f1b523ba 100644
--- a/dmp-backend/core/src/main/java/eu/eudat/model/file/TransformerCacheModel.java
+++ b/dmp-backend/core/src/main/java/eu/eudat/model/file/TransformerCacheModel.java
@@ -1,23 +1,23 @@
package eu.eudat.model.file;
-import eu.eudat.file.transformer.models.misc.FileFormat;
+import eu.eudat.file.transformer.interfaces.FileTransformerConfiguration;
import java.util.List;
public class TransformerCacheModel {
- private List formats;
+ private List configurations;
public TransformerCacheModel() {
}
- public TransformerCacheModel(List formats) {
- this.formats = formats;
+ public TransformerCacheModel(List formats) {
+ this.configurations = formats;
}
- public List getFormats() {
- return formats;
+ public List getConfigurations() {
+ return configurations;
}
- public void setFormats(List formats) {
- this.formats = formats;
+ public void setConfigurations(List configurations) {
+ this.configurations = configurations;
}
}
diff --git a/dmp-backend/core/src/main/java/eu/eudat/repository/TransformerRepository.java b/dmp-backend/core/src/main/java/eu/eudat/repository/TransformerRepository.java
index 2e125f607..27803a819 100644
--- a/dmp-backend/core/src/main/java/eu/eudat/repository/TransformerRepository.java
+++ b/dmp-backend/core/src/main/java/eu/eudat/repository/TransformerRepository.java
@@ -1,15 +1,13 @@
package eu.eudat.repository;
+import eu.eudat.commonmodels.models.FileEnvelopeModel;
+import eu.eudat.commonmodels.models.description.DescriptionModel;
+import eu.eudat.commonmodels.models.dmp.DmpModel;
import eu.eudat.file.transformer.interfaces.FileTransformerClient;
import eu.eudat.file.transformer.interfaces.FileTransformerConfiguration;
-import eu.eudat.file.transformer.models.description.DescriptionFileTransformerModel;
-import eu.eudat.file.transformer.models.dmp.DmpFileTransformerModel;
-import eu.eudat.file.transformer.models.misc.FileEnvelope;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.web.reactive.function.client.WebClient;
-import javax.management.InvalidApplicationException;
-import java.io.IOException;
public class TransformerRepository implements FileTransformerClient {
@@ -20,23 +18,23 @@ public class TransformerRepository implements FileTransformerClient {
}
@Override
- public FileEnvelope exportDmp(DmpFileTransformerModel dmpFileTransformerModel) throws InvalidApplicationException, IOException {
- return transformerClient.post().uri("/export/dmp").bodyValue(dmpFileTransformerModel).exchangeToMono(mono -> mono.bodyToMono(FileEnvelope.class)).block();
+ public FileEnvelopeModel exportDmp(DmpModel dmpModel, String format) {
+ return transformerClient.post().uri("/export/dmp", uriBuilder -> uriBuilder.queryParam("format", format).build()).bodyValue(dmpModel).exchangeToMono(mono -> mono.bodyToMono(FileEnvelopeModel.class)).block();
}
@Override
- public DmpFileTransformerModel importDmp(FileEnvelope fileEnvelope) {
- return transformerClient.post().uri("/import/dmp").bodyValue(fileEnvelope).exchangeToMono(mono -> mono.bodyToMono(DmpFileTransformerModel.class)).block();
+ public DmpModel importDmp(FileEnvelopeModel fileEnvelope) {
+ return transformerClient.post().uri("/import/dmp").bodyValue(fileEnvelope).exchangeToMono(mono -> mono.bodyToMono(DmpModel.class)).block();
}
@Override
- public FileEnvelope exportDescription(DescriptionFileTransformerModel descriptionFileTransformerModel, String format) {
- return transformerClient.post().uri("/export/description", uriBuilder -> uriBuilder.queryParam("format", format).build()).bodyValue(descriptionFileTransformerModel).exchangeToMono(mono -> mono.bodyToMono(FileEnvelope.class)).block();
+ public FileEnvelopeModel exportDescription(DescriptionModel descriptionModel, String format) {
+ return transformerClient.post().uri("/export/description", uriBuilder -> uriBuilder.queryParam("format", format).build()).bodyValue(descriptionModel).exchangeToMono(mono -> mono.bodyToMono(FileEnvelopeModel.class)).block();
}
@Override
- public DescriptionFileTransformerModel importDescription(FileEnvelope fileEnvelope) {
- return transformerClient.post().uri("/import/description").bodyValue(fileEnvelope).exchangeToMono(mono -> mono.bodyToMono(DescriptionFileTransformerModel.class)).block();
+ public DescriptionModel importDescription(FileEnvelopeModel fileEnvelope) {
+ return transformerClient.post().uri("/import/description").bodyValue(fileEnvelope).exchangeToMono(mono -> mono.bodyToMono(DescriptionModel.class)).block();
}
@Override
diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositClientImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositClientImpl.java
index 246eea95f..e255d3aa8 100644
--- a/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositClientImpl.java
+++ b/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositClientImpl.java
@@ -1,10 +1,10 @@
package eu.eudat.service.deposit;
-import eu.eudat.commonmodels.models.DmpModel;
import eu.eudat.depositinterface.repository.DepositClient;
import eu.eudat.depositinterface.repository.DepositConfiguration;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.web.reactive.function.client.WebClient;
+import eu.eudat.commonmodels.models.dmp.DmpModel;
public class DepositClientImpl implements DepositClient {
diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositServiceImpl.java
index c56a8c72e..47e0382a7 100644
--- a/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositServiceImpl.java
+++ b/dmp-backend/core/src/main/java/eu/eudat/service/deposit/DepositServiceImpl.java
@@ -2,15 +2,15 @@ package eu.eudat.service.deposit;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.authorization.Permission;
-import eu.eudat.commonmodels.models.DmpModel;
import eu.eudat.commonmodels.models.FileEnvelopeModel;
+import eu.eudat.commonmodels.models.dmp.DmpModel;
import eu.eudat.configurations.deposit.DepositProperties;
import eu.eudat.data.DmpEntity;
import eu.eudat.depositinterface.repository.DepositClient;
import eu.eudat.depositinterface.repository.DepositConfiguration;
import eu.eudat.model.EntityDoi;
import eu.eudat.model.builder.commonmodels.DepositConfigurationBuilder;
-import eu.eudat.model.builder.commonmodels.DmpCommonModelBuilder;
+import eu.eudat.model.builder.commonmodels.dmp.DmpCommonModelBuilder;
import eu.eudat.model.persist.deposit.DepositAuthenticateRequest;
import eu.eudat.model.persist.deposit.DepositRequest;
import eu.eudat.model.persist.EntityDoiPersist;
diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/transformer/FileTransformerService.java b/dmp-backend/core/src/main/java/eu/eudat/service/transformer/FileTransformerService.java
index 2a2fab0ac..265d53c9c 100644
--- a/dmp-backend/core/src/main/java/eu/eudat/service/transformer/FileTransformerService.java
+++ b/dmp-backend/core/src/main/java/eu/eudat/service/transformer/FileTransformerService.java
@@ -3,21 +3,21 @@ package eu.eudat.service.transformer;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.authorization.Permission;
import eu.eudat.cache.transformer.FileTransformerConfigurationCache;
-import eu.eudat.commons.JsonHandlingService;
+import eu.eudat.commonmodels.models.FileEnvelopeModel;
+import eu.eudat.commonmodels.models.description.DescriptionModel;
+import eu.eudat.commonmodels.models.dmp.DmpModel;
import eu.eudat.commons.enums.StorageType;
import eu.eudat.configurations.transformer.TransformerProperties;
-import eu.eudat.convention.ConventionService;
import eu.eudat.file.transformer.interfaces.FileTransformerConfiguration;
-import eu.eudat.file.transformer.models.description.DescriptionFileTransformerModel;
-import eu.eudat.file.transformer.models.dmp.DmpFileTransformerModel;
-import eu.eudat.file.transformer.models.misc.FileEnvelope;
import eu.eudat.file.transformer.models.misc.FileFormat;
+import eu.eudat.model.Description;
+import eu.eudat.model.Dmp;
+import eu.eudat.model.builder.commonmodels.description.DescriptionCommonModelBuilder;
+import eu.eudat.model.builder.commonmodels.dmp.DmpCommonModelBuilder;
import eu.eudat.model.file.TransformerCacheModel;
import eu.eudat.query.DescriptionQuery;
import eu.eudat.query.DmpQuery;
-import eu.eudat.query.EntityDoiQuery;
import eu.eudat.repository.TransformerRepository;
-import eu.eudat.service.entitydoi.EntityDoiService;
import eu.eudat.service.storage.StorageFileService;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.commons.web.oidc.filter.webflux.TokenExchangeCacheService;
@@ -25,19 +25,18 @@ import gr.cite.commons.web.oidc.filter.webflux.TokenExchangeFilterFunction;
import gr.cite.commons.web.oidc.filter.webflux.TokenExchangeModel;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
-import jakarta.persistence.EntityManager;
+import gr.cite.tools.exception.MyNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.ApplicationContext;
+import org.springframework.context.MessageSource;
+import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import javax.management.InvalidApplicationException;
-import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URI;
import java.util.*;
@@ -51,31 +50,25 @@ public class FileTransformerService {
private final TokenExchangeCacheService tokenExchangeCacheService;
private final FileTransformerConfigurationCache fileTransformerConfigurationCache;
private final AuthorizationService authorizationService;
- private final ConventionService conventionService;
private final WebClient.Builder webClientBuilder;
- private final EntityDoiService doiService;
- private final ApplicationContext applicationContext;
- private final JsonHandlingService jsonHandlingService;
private final QueryFactory queryFactory;
private final BuilderFactory builderFactory;
private final StorageFileService storageFileService;
-
+ private final MessageSource messageSource;
@Autowired
- public FileTransformerService(TransformerProperties transformerProperties, TokenExchangeCacheService tokenExchangeCacheService, FileTransformerConfigurationCache fileTransformerConfigurationCache, WebClient.Builder builder, EntityManager entityManager, AuthorizationService authorizationService, ConventionService conventionService, DmpQuery dmpQuery, EntityDoiQuery doiQuery, EntityDoiService doiService, ApplicationContext applicationContext, JsonHandlingService jsonHandlingService, QueryFactory queryFactory, BuilderFactory builderFactory, StorageFileService storageFileService) {
+ public FileTransformerService(TransformerProperties transformerProperties, TokenExchangeCacheService tokenExchangeCacheService, FileTransformerConfigurationCache fileTransformerConfigurationCache, WebClient.Builder builder, AuthorizationService authorizationService,
+ QueryFactory queryFactory, BuilderFactory builderFactory, StorageFileService storageFileService, MessageSource messageSource) {
this.transformerProperties = transformerProperties;
this.tokenExchangeCacheService = tokenExchangeCacheService;
this.fileTransformerConfigurationCache = fileTransformerConfigurationCache;
this.authorizationService = authorizationService;
- this.conventionService = conventionService;
this.webClientBuilder = builder;
- this.doiService = doiService;
- this.applicationContext = applicationContext;
- this.jsonHandlingService = jsonHandlingService;
this.queryFactory = queryFactory;
this.builderFactory = builderFactory;
- this.storageFileService = storageFileService;
- this.clients = new HashMap<>();
+ this.storageFileService = storageFileService;
+ this.messageSource = messageSource;
+ this.clients = new HashMap<>();
}
private TransformerRepository getRepository(String repoId) {
@@ -87,7 +80,7 @@ public class FileTransformerService {
String host = URI.create(source.getUrl()).getHost();
TokenExchangeModel tokenExchangeModel = new TokenExchangeModel(host + "_" + source.getClientId(), source.getIssuerUrl(), source.getClientId(), source.getClientSecret(), source.getScope());
TokenExchangeFilterFunction tokenExchangeFilterFunction = new TokenExchangeFilterFunction(this.tokenExchangeCacheService, tokenExchangeModel);
- TransformerRepository repository = new TransformerRepository(webClientBuilder.baseUrl(source.getUrl() + "/api/file").filters(exchangeFilterFunctions -> {
+ TransformerRepository repository = new TransformerRepository(webClientBuilder.baseUrl(source.getUrl() + "/api/file-transformer").filters(exchangeFilterFunctions -> {
exchangeFilterFunctions.add(tokenExchangeFilterFunction);
exchangeFilterFunctions.add(logRequest());
}).build());
@@ -98,19 +91,30 @@ public class FileTransformerService {
}
- public List getAvailableConfigurations() {
+ public List getAvailableExportFileFormats() {
+ List formats = new ArrayList<>();
+ List configurations = this.getAvailableConfigurations();
+ if(configurations != null){
+ for (FileTransformerConfiguration configuration : configurations){
+ if (configuration != null && configuration.getExportVariants() != null) formats.addAll(configuration.getExportVariants());
+ }
+ }
+ return formats;
+ }
+
+ private List getAvailableConfigurations() {
TransformerCacheModel configs = fileTransformerConfigurationCache.lookup("base");
if (configs == null) {
- List configurations = new ArrayList<>();
+ List configurations = new ArrayList<>();
//GK: So much for lazy loading
- List repositories = transformerProperties.getSources().stream().map(depositSource -> getRepository(depositSource.getCodes().get(0))).toList();
+ List repositories = transformerProperties.getSources().stream().map(depositSource -> getRepository(depositSource.getCodes().getFirst())).toList();
repositories = new ArrayList<>(repositories);
repositories.forEach((client) -> {
try {
- FileTransformerConfiguration repositoryConfigs = client.getConfiguration();
- if (repositoryConfigs != null && !repositoryConfigs.getExportVariants().isEmpty()) {
- configurations.addAll(repositoryConfigs.getExportVariants());
+ FileTransformerConfiguration repositoryConfig = client.getConfiguration();
+ if (repositoryConfig != null) {
+ configurations.add(repositoryConfig);
}
} catch (Exception e) {
logger.warn(e.getLocalizedMessage(), e);
@@ -121,40 +125,42 @@ public class FileTransformerService {
this.fileTransformerConfigurationCache.put("base", configs);
}
- return configs.getFormats();
+ return configs.getConfigurations();
}
public eu.eudat.model.file.FileEnvelope exportDmp(UUID dmpId, String format) throws InvalidApplicationException, IOException {
this.authorizationService.authorize(Permission.EditDmp);
- //GK: Why it is in that service, and why it's not static?
- this.conventionService.isValidGuid(dmpId);
//GK: First get the right client
TransformerRepository repository = getRepository(format);
+ if (repository == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{format, TransformerRepository.class.getSimpleName()}, LocaleContextHolder.getLocale()));
//GK: Second get the Target Data Management Plan
DmpQuery query = this.queryFactory.query(DmpQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(dmpId);
-// DmpFileTransformerModel dmpFileTransformerModel = this.builderFactory.builder(DmpFileTransformerBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(query.first());
-// dmpFileTransformerModel.setVariant(format);
- FileEnvelope fileEnvelope = repository.exportDmp(null); //TODO
+ DmpModel dmpFileTransformerModel = this.builderFactory.builder(DmpCommonModelBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(query.first());
+ if (dmpFileTransformerModel == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{dmpId, Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
+
+ FileEnvelopeModel fileEnvelope = repository.exportDmp(dmpFileTransformerModel, format);
eu.eudat.model.file.FileEnvelope result = new eu.eudat.model.file.FileEnvelope();
- byte[] data = storageFileService.readByFileRefAsBytesSafe(fileEnvelope.getFile(), StorageType.Transformer);
+
+ byte[] data = repository.getConfiguration().isUseSharedStorage() ? storageFileService.readByFileRefAsBytesSafe(fileEnvelope.getFileRef(), StorageType.Transformer) : fileEnvelope.getFile();
result.setFile(data);
result.setFilename(fileEnvelope.getFilename());
return result;
}
- public eu.eudat.model.file.FileEnvelope exportDescription(UUID descriptionId, String format) throws InvalidApplicationException, IOException {
+ public eu.eudat.model.file.FileEnvelope exportDescription(UUID descriptionId, String format) {
this.authorizationService.authorize(Permission.EditDmp);
- //GK: Why it is in that service, and why it's not static?
- this.conventionService.isValidGuid(descriptionId);
//GK: First get the right client
TransformerRepository repository = getRepository(format);
+ if (repository == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{format, TransformerRepository.class.getSimpleName()}, LocaleContextHolder.getLocale()));
+
//GK: Second get the Target Data Management Plan
DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(descriptionId);
-// DescriptionFileTransformerModel descriptionFileTransformerModel = this.builderFactory.builder(DescriptionFileTransformerBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(query.first());
-// descriptionFileTransformerModel.setCreatedBy(descriptionFileTransformerModel.getDmp().getCreator());
- FileEnvelope fileEnvelope = repository.exportDescription(null, format); //TODO
+ DescriptionModel descriptionFileTransformerModel = this.builderFactory.builder(DescriptionCommonModelBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(query.first());
+ if (descriptionFileTransformerModel == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{descriptionId, Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
+
+ FileEnvelopeModel fileEnvelope = repository.exportDescription(descriptionFileTransformerModel, format);
eu.eudat.model.file.FileEnvelope result = new eu.eudat.model.file.FileEnvelope();
- byte[] data = this.storageFileService.readByFileRefAsBytesSafe(fileEnvelope.getFile(), StorageType.Transformer);
+ byte[] data = repository.getConfiguration().isUseSharedStorage() ? storageFileService.readByFileRefAsBytesSafe(fileEnvelope.getFileRef(), StorageType.Transformer) : fileEnvelope.getFile(); //TODO: shared storage should be per repository
result.setFile(data);
result.setFilename(fileEnvelope.getFilename());
return result;
diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/FileTransformerController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/FileTransformerController.java
index a21b2be12..a520eb020 100644
--- a/dmp-backend/web/src/main/java/eu/eudat/controllers/FileTransformerController.java
+++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/FileTransformerController.java
@@ -5,9 +5,7 @@ import eu.eudat.file.transformer.models.misc.FileFormat;
import eu.eudat.model.file.ExportRequestModel;
import eu.eudat.model.file.FileEnvelope;
import eu.eudat.service.transformer.FileTransformerService;
-import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.auditing.AuditService;
-import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import org.slf4j.LoggerFactory;
@@ -20,7 +18,6 @@ import org.springframework.web.bind.annotation.*;
import javax.management.InvalidApplicationException;
import java.io.IOException;
-import java.nio.file.Files;
import java.util.List;
@RestController
@@ -43,7 +40,7 @@ public class FileTransformerController {
public List getAvailableConfigurations() {
logger.debug(new MapLogEntry("getAvailableConfigurations"));
- List model = this.fileTransformerService.getAvailableConfigurations();
+ List model = this.fileTransformerService.getAvailableExportFileFormats();
this.auditService.track(AuditableAction.FileTransformer_GetAvailableConfigurations);
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
diff --git a/dmp-backend/web/src/main/resources/config/transformer.yml b/dmp-backend/web/src/main/resources/config/transformer.yml
index 683221506..b8df6d50d 100644
--- a/dmp-backend/web/src/main/resources/config/transformer.yml
+++ b/dmp-backend/web/src/main/resources/config/transformer.yml
@@ -18,6 +18,3 @@ transformer:
client-id: ${IDP_APIKEY_CLIENT_ID:}
client-secret: ${IDP_APIKEY_CLIENT_SECRET:}
scope: ${IDP_APIKEY_SCOPE:}
-
-temp:
- temp: ${TEMP_STORAGE}
\ No newline at end of file
diff --git a/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.html b/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.html
index 93d8371d9..33813389e 100644
--- a/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.html
+++ b/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.html
@@ -168,7 +168,7 @@