common models changes
This commit is contained in:
parent
6c82fcf8b0
commit
535c07a1ad
|
@ -45,17 +45,17 @@
|
|||
<dependency>
|
||||
<groupId>gr.cite.opendmp</groupId>
|
||||
<artifactId>repositorydepositbase</artifactId>
|
||||
<version>2.0.1</version>
|
||||
<version>2.0.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>gr.cite.opendmp</groupId>
|
||||
<artifactId>common-models</artifactId>
|
||||
<version>0.0.1</version>
|
||||
<version>0.0.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>gr.cite.opendmp</groupId>
|
||||
<artifactId>file-transformer-base</artifactId>
|
||||
<version>0.0.4</version>
|
||||
<version>0.0.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>gr.cite</groupId>
|
||||
|
|
|
@ -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<EntityDoiModel, EntityDoiEntity> {
|
||||
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
@Autowired
|
||||
public EntityDoiCommonModelBuilder(
|
||||
ConventionService conventionService) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(EntityDoiCommonModelBuilder.class)));
|
||||
}
|
||||
|
||||
public EntityDoiCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<EntityDoiModel, EntityDoiEntity>> buildInternal(List<EntityDoiEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty()) return new ArrayList<>();
|
||||
|
||||
List<CommonModelBuilderItemResponse<EntityDoiModel, EntityDoiEntity>> 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;
|
||||
}
|
||||
}
|
|
@ -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<Descri
|
|||
if (data == null || data.isEmpty()) return new ArrayList<>();
|
||||
|
||||
Map<UUID, DescriptionTemplateModel> descriptionTemplates = this.collectDescriptionTemplates(data);
|
||||
Map<UUID, DmpModel> dmps = this.collectDmps(data);
|
||||
|
||||
Map<UUID, DefinitionEntity> definitionEntityMap = this.collectDescriptionTemplateDefinitions(data);
|
||||
Map<UUID, UUID> dmpDescriptionTemplateSections = this.collectDmpDescriptionTemplateSections(data);
|
||||
|
||||
List<CommonModelBuilderItemResponse<DescriptionModel, DescriptionEntity>> 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<Descri
|
|||
return itemMap;
|
||||
}
|
||||
|
||||
private Map<UUID, UUID> collectDmpDescriptionTemplateSections(List<DescriptionEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty())
|
||||
return null;
|
||||
this.logger.debug("checking related - {}", DefinitionEntity.class.getSimpleName());
|
||||
|
||||
Map<UUID, UUID> itemMap = new HashMap<>();
|
||||
DmpDescriptionTemplateQuery q = this.queryFactory.query(DmpDescriptionTemplateQuery.class).authorize(this.authorize).ids(data.stream().map(DescriptionEntity::getDmpDescriptionTemplateId).distinct().collect(Collectors.toList()));
|
||||
List<DmpDescriptionTemplateEntity> 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<UUID, DmpModel> collectDmps(List<DescriptionEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty())
|
||||
return null;
|
||||
this.logger.debug("checking related - {}", DmpModel.class.getSimpleName());
|
||||
|
||||
Map<UUID, DmpModel> 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<UUID, DescriptionTemplateModel> collectDescriptionTemplates(List<DescriptionEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty())
|
||||
return null;
|
||||
|
|
|
@ -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<DescriptionTemplateModel, DescriptionTemplateEntity> {
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
|
||||
private final BuilderFactory builderFactory;
|
||||
private final JsonHandlingService jsonHandlingService;
|
||||
|
||||
private final XmlHandlingService xmlHandlingService;
|
||||
private EnumSet<AuthorizationFlags> 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<AuthorizationFlags> 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));
|
||||
|
|
|
@ -55,7 +55,6 @@ public class FieldSetCommonModelBuilder extends BaseCommonModelBuilder<FieldSetM
|
|||
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));
|
||||
|
|
|
@ -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<DmpBlueprintValueModel, DmpBlueprintValueEntity> {
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
@Autowired
|
||||
public DmpBlueprintValueCommonModelBuilder(
|
||||
ConventionService conventionService
|
||||
) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpBlueprintValueCommonModelBuilder.class)));
|
||||
}
|
||||
|
||||
public DmpBlueprintValueCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<DmpBlueprintValueModel, DmpBlueprintValueEntity>> buildInternal(List<DmpBlueprintValueEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty()) return new ArrayList<>();
|
||||
|
||||
List<CommonModelBuilderItemResponse<DmpBlueprintValueModel, DmpBlueprintValueEntity>> 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;
|
||||
}
|
||||
}
|
|
@ -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<DmpModel, DmpE
|
|||
private final QueryFactory queryFactory;
|
||||
|
||||
private final BuilderFactory builderFactory;
|
||||
private final JsonHandlingService jsonHandlingService;
|
||||
private FileEnvelopeModel pdfFile;
|
||||
private FileEnvelopeModel rdaJsonFile;
|
||||
private FileEnvelopeModel supportingFilesZip;
|
||||
private String repositoryId;
|
||||
private boolean disableDescriptions;
|
||||
private EnumSet<AuthorizationFlags> 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<AuthorizationFlags> values) {
|
||||
|
@ -76,18 +89,24 @@ public class DmpCommonModelBuilder extends BaseCommonModelBuilder<DmpModel, DmpE
|
|||
return this;
|
||||
}
|
||||
|
||||
public DmpCommonModelBuilder setDisableDescriptions(boolean disableDescriptions) {
|
||||
this.disableDescriptions = disableDescriptions;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<DmpModel, DmpEntity>> buildInternal(List<DmpEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty()) return new ArrayList<>();
|
||||
|
||||
List<CommonModelBuilderItemResponse<DmpModel, DmpEntity>> models = new ArrayList<>();
|
||||
|
||||
Map<UUID, List<ReferenceModel>> dmpReferencesMap = this.collectReferences(data);
|
||||
|
||||
|
||||
Map<UUID, List<DmpReferenceModel>> dmpReferencesMap = this.collectDmpReferences(data);
|
||||
Map<UUID, List<DmpUserModel>> dmpUsersMap = this.collectDmpUsers(data);
|
||||
|
||||
Map<UUID, List<DescriptionModel>> descriptionsMap = this.collectDmpDescriptions(data);
|
||||
Map<UUID, List<DescriptionModel>> descriptionsMap = this.disableDescriptions ? null : this.collectDmpDescriptions(data);
|
||||
Map<UUID, List<EntityDoiModel>> entityDois = this.collectDmpEntityDois(data);
|
||||
Map<UUID, UserModel> creators = this.collectCreators(data);
|
||||
Map<UUID, DmpBlueprintModel> dmpBlueprints = this.collectDmpBlueprints(data);
|
||||
|
||||
for (DmpEntity d : data) {
|
||||
DmpModel m = new DmpModel();
|
||||
|
@ -96,6 +115,21 @@ public class DmpCommonModelBuilder extends BaseCommonModelBuilder<DmpModel, DmpE
|
|||
m.setVersion(d.getVersion());
|
||||
m.setDescription(d.getDescription());
|
||||
m.setFinalizedAt(d.getFinalizedAt());
|
||||
switch (d.getStatus()){
|
||||
case Finalized -> 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<DmpModel, DmpE
|
|||
case Public -> m.setAccessType(DmpAccessType.Public);
|
||||
case Restricted -> m.setAccessType(DmpAccessType.Restricted);
|
||||
case null -> m.setAccessType(null);
|
||||
default -> throw new MyApplicationException("unrecognized type " + d.getAccessType().getValue());
|
||||
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<DmpModel, DmpE
|
|||
return null;
|
||||
}
|
||||
|
||||
private Map<UUID, List<ReferenceModel>> collectReferences(List<DmpEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty()) return null;
|
||||
this.logger.debug("checking related - {}", DmpReference.class.getSimpleName());
|
||||
|
||||
List<DmpReferenceEntity> 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<UUID, List<ReferenceModel>> 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<UUID, ReferenceModel> 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<UUID, List<DmpUserModel>> collectDmpUsers(List<DmpEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("checking related - {}", DmpUser.class.getSimpleName());
|
||||
|
||||
|
@ -165,6 +179,16 @@ public class DmpCommonModelBuilder extends BaseCommonModelBuilder<DmpModel, DmpE
|
|||
return itemMap;
|
||||
}
|
||||
|
||||
private Map<UUID, List<DmpReferenceModel>> collectDmpReferences(List<DmpEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("checking related - {}", DmpReference.class.getSimpleName());
|
||||
|
||||
Map<UUID, List<DmpReferenceModel>> 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<UUID, List<DescriptionModel>> collectDmpDescriptions(List<DmpEntity> 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<DmpModel, DmpE
|
|||
return itemMap;
|
||||
}
|
||||
|
||||
private Map<UUID, List<EntityDoiModel>> collectDmpEntityDois(List<DmpEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty()) return null;
|
||||
this.logger.debug("checking related - {}", EntityDoi.class.getSimpleName());
|
||||
|
||||
Map<UUID, List<EntityDoiModel>> 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<UUID, UserModel> collectCreators(List<DmpEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty())
|
||||
return null;
|
||||
this.logger.debug("checking related - {}", UserModel.class.getSimpleName());
|
||||
|
||||
Map<UUID, UserModel> 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<UUID, DmpBlueprintModel> collectDmpBlueprints(List<DmpEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty())
|
||||
return null;
|
||||
this.logger.debug("checking related - {}", DmpBlueprintModel.class.getSimpleName());
|
||||
|
||||
Map<UUID, DmpBlueprintModel> 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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<DmpPropertiesModel, DmpPropertiesEntity> {
|
||||
private final BuilderFactory builderFactory;
|
||||
private EnumSet<AuthorizationFlags> 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<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<DmpPropertiesModel, DmpPropertiesEntity>> buildInternal(List<DmpPropertiesEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty()) return new ArrayList<>();
|
||||
|
||||
List<CommonModelBuilderItemResponse<DmpPropertiesModel, DmpPropertiesEntity>> 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;
|
||||
}
|
||||
}
|
|
@ -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<DefinitionModel, DefinitionEntity> {
|
||||
private final BuilderFactory builderFactory;
|
||||
private EnumSet<AuthorizationFlags> 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<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<DefinitionModel, DefinitionEntity>> buildInternal(List<DefinitionEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty()) return new ArrayList<>();
|
||||
|
||||
List<CommonModelBuilderItemResponse<DefinitionModel, DefinitionEntity>> 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;
|
||||
}
|
||||
}
|
|
@ -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<DmpBlueprintModel, DmpBlueprintEntity> {
|
||||
|
||||
private final BuilderFactory builderFactory;
|
||||
private final XmlHandlingService xmlHandlingService;
|
||||
private EnumSet<AuthorizationFlags> 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<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<DmpBlueprintModel, DmpBlueprintEntity>> buildInternal(List<DmpBlueprintEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty()) return new ArrayList<>();
|
||||
|
||||
List<CommonModelBuilderItemResponse<DmpBlueprintModel, DmpBlueprintEntity>> 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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<ExtraFieldModel, ExtraFieldEntity> {
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
|
@ -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<Model extends FieldModel, Entity extends FieldEntity> extends BaseCommonModelBuilder<Model, Entity> {
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
@Autowired
|
||||
public FieldCommonModelBuilder(
|
||||
ConventionService conventionService
|
||||
) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(FieldCommonModelBuilder.class)));
|
||||
}
|
||||
|
||||
public FieldCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
protected abstract Model getInstance();
|
||||
|
||||
protected abstract Model buildChild(Entity data, Model model);
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<Model, Entity>> buildInternal(List<Entity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty()) return new ArrayList<>();
|
||||
|
||||
List<CommonModelBuilderItemResponse<Model, Entity>> 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;
|
||||
}
|
||||
}
|
|
@ -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<ReferenceTypeFieldModel, ReferenceTypeFieldEntity> {
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -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<SectionModel, SectionEntity> {
|
||||
private final BuilderFactory builderFactory;
|
||||
private EnumSet<AuthorizationFlags> 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<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<SectionModel, SectionEntity>> buildInternal(List<SectionEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty()) return new ArrayList<>();
|
||||
|
||||
List<CommonModelBuilderItemResponse<SectionModel, SectionEntity>> 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<SystemFieldEntity> 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<ExtraFieldEntity> 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<ReferenceTypeFieldEntity> 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;
|
||||
}
|
||||
}
|
|
@ -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<SystemFieldModel, SystemFieldEntity> {
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
|
@ -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<DmpReferenceModel, DmpReferenceEntity> {
|
||||
|
||||
private final BuilderFactory builderFactory;
|
||||
private final QueryFactory queryFactory;
|
||||
private final JsonHandlingService jsonHandlingService;
|
||||
private EnumSet<AuthorizationFlags> 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<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<DmpReferenceModel, DmpReferenceEntity>> buildInternal(List<DmpReferenceEntity> 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<UUID, ReferenceModel> referenceModelMap = this.collectReferences(data);
|
||||
List<CommonModelBuilderItemResponse<DmpReferenceModel, DmpReferenceEntity>> 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<UUID, ReferenceModel> collectReferences(List<DmpReferenceEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty())
|
||||
return null;
|
||||
this.logger.debug("checking related - {}", ReferenceModel.class.getSimpleName());
|
||||
|
||||
Map<UUID, ReferenceModel> 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;
|
||||
}
|
||||
}
|
|
@ -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<DmpReferenceDataModel, DmpReferenceDataEntity> {
|
||||
|
||||
private final BuilderFactory builderFactory;
|
||||
private EnumSet<AuthorizationFlags> 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<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<DmpReferenceDataModel, DmpReferenceDataEntity>> buildInternal(List<DmpReferenceDataEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty()) return new ArrayList<>();
|
||||
|
||||
List<CommonModelBuilderItemResponse<DmpReferenceDataModel, DmpReferenceDataEntity>> 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;
|
||||
}
|
||||
}
|
|
@ -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<ReferenceDefinitionModel, DefinitionEntity> {
|
||||
|
||||
|
|
|
@ -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<ReferenceFieldModel, FieldEntity> {
|
||||
|
||||
|
|
|
@ -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<FileFormat> formats;
|
||||
private List<FileTransformerConfiguration> configurations;
|
||||
|
||||
public TransformerCacheModel() {
|
||||
}
|
||||
|
||||
public TransformerCacheModel(List<FileFormat> formats) {
|
||||
this.formats = formats;
|
||||
public TransformerCacheModel(List<FileTransformerConfiguration> formats) {
|
||||
this.configurations = formats;
|
||||
}
|
||||
|
||||
public List<FileFormat> getFormats() {
|
||||
return formats;
|
||||
public List<FileTransformerConfiguration> getConfigurations() {
|
||||
return configurations;
|
||||
}
|
||||
|
||||
public void setFormats(List<FileFormat> formats) {
|
||||
this.formats = formats;
|
||||
public void setConfigurations(List<FileTransformerConfiguration> configurations) {
|
||||
this.configurations = configurations;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<FileFormat> getAvailableConfigurations() {
|
||||
public List<FileFormat> getAvailableExportFileFormats() {
|
||||
List<FileFormat> formats = new ArrayList<>();
|
||||
List<FileTransformerConfiguration> configurations = this.getAvailableConfigurations();
|
||||
if(configurations != null){
|
||||
for (FileTransformerConfiguration configuration : configurations){
|
||||
if (configuration != null && configuration.getExportVariants() != null) formats.addAll(configuration.getExportVariants());
|
||||
}
|
||||
}
|
||||
return formats;
|
||||
}
|
||||
|
||||
private List<FileTransformerConfiguration> getAvailableConfigurations() {
|
||||
TransformerCacheModel configs = fileTransformerConfigurationCache.lookup("base");
|
||||
if (configs == null) {
|
||||
List<FileFormat> configurations = new ArrayList<>();
|
||||
List<FileTransformerConfiguration> configurations = new ArrayList<>();
|
||||
//GK: So much for lazy loading
|
||||
List<TransformerRepository> repositories = transformerProperties.getSources().stream().map(depositSource -> getRepository(depositSource.getCodes().get(0))).toList();
|
||||
List<TransformerRepository> 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;
|
||||
|
|
|
@ -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<FileFormat> getAvailableConfigurations() {
|
||||
logger.debug(new MapLogEntry("getAvailableConfigurations"));
|
||||
|
||||
List<FileFormat> model = this.fileTransformerService.getAvailableConfigurations();
|
||||
List<FileFormat> model = this.fileTransformerService.getAvailableExportFileFormats();
|
||||
this.auditService.track(AuditableAction.FileTransformer_GetAvailableConfigurations);
|
||||
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
|
||||
|
||||
|
|
|
@ -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}
|
|
@ -168,7 +168,7 @@
|
|||
<mat-menu #exportMenu="matMenu" xPosition="before">
|
||||
<button mat-menu-item *ngFor='let fileTransformer of fileTransformerService.availableFormats' (click)="fileTransformerService.exportDmp(dmp.id, fileTransformer.format)">
|
||||
<i class="fa pr-2" [ngClass]="fileTransformer.icon ? fileTransformer.icon : 'fa-file-o'"></i>
|
||||
<span>{{'GENERAL.FILE-TRANSFORMER.' + fileTransformer.formatName.toUpperCase() | translate}}</span>
|
||||
<span>{{'GENERAL.FILE-TRANSFORMER.' + fileTransformer?.formatName?.toUpperCase() | translate}}</span>
|
||||
</button>
|
||||
</mat-menu>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue