Add FileTransformer Builders
This commit is contained in:
parent
e8553b1605
commit
71746419fc
|
@ -42,7 +42,7 @@
|
|||
<dependency>
|
||||
<groupId>gr.cite.opendmp</groupId>
|
||||
<artifactId>file-transformer-base</artifactId>
|
||||
<version>0.0.2</version>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>gr.cite</groupId>
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
package eu.eudat.model.builder.filetransformer;
|
||||
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import gr.cite.tools.data.builder.Builder;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class BaseFileTransformerBuilder<M, D> implements Builder {
|
||||
protected final LoggerService logger;
|
||||
protected final ConventionService conventionService;
|
||||
|
||||
public BaseFileTransformerBuilder(
|
||||
ConventionService conventionService,
|
||||
LoggerService logger
|
||||
) {
|
||||
this.conventionService = conventionService;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public M build(D data) throws MyApplicationException {
|
||||
if (data == null) {
|
||||
//this.logger.Debug(new MapLogEntry("requested build for null item requesting fields").And("fields", directives));
|
||||
// return default(M);
|
||||
M model = null;
|
||||
return null; //TODO
|
||||
}
|
||||
List<FileTransformerBuilderItemResponse<M, D>> models = this.buildInternal(List.of(data));
|
||||
return models.stream().map(FileTransformerBuilderItemResponse::getModel).findFirst().orElse(null); //TODO
|
||||
}
|
||||
|
||||
public List<M> build(List<D> data) throws MyApplicationException{
|
||||
List<FileTransformerBuilderItemResponse<M, D>> models = this.buildInternal(data);
|
||||
return models == null ? null : models.stream().map(FileTransformerBuilderItemResponse::getModel).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
protected abstract List<FileTransformerBuilderItemResponse<M, D>> buildInternal(List<D> data) throws MyApplicationException;
|
||||
|
||||
public <K> Map<K, M> asForeignKey(QueryBase<D> query, Function<D, K> keySelector) throws MyApplicationException {
|
||||
this.logger.trace("Building references from query");
|
||||
List<D> data = query.collect();
|
||||
this.logger.debug("collected {} items to build", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
return this.asForeignKey(data, keySelector);
|
||||
}
|
||||
|
||||
public <K> Map<K, M> asForeignKey(List<D> data, Function<D, K> keySelector) throws MyApplicationException {
|
||||
this.logger.trace("building references");
|
||||
List<FileTransformerBuilderItemResponse<M, D>> models = this.buildInternal(data);
|
||||
this.logger.debug("mapping {} build items from {} requested", Optional.ofNullable(models).map(List::size).orElse(0), Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
return models == null ? new HashMap<>() : models.stream().collect(Collectors.toMap(x-> keySelector.apply(x.getData()), FileTransformerBuilderItemResponse::getModel));
|
||||
}
|
||||
public <K> Map<K, List<M>> asMasterKey(QueryBase<D> query,Function<D, K> keySelector) throws MyApplicationException {
|
||||
this.logger.trace("Building details from query");
|
||||
List<D> data = query.collect();
|
||||
this.logger.debug("collected {} items to build", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
return this.asMasterKey(data, keySelector);
|
||||
}
|
||||
|
||||
public <K> Map<K, List<M>> asMasterKey(List<D> data, Function<D, K> keySelector) throws MyApplicationException {
|
||||
this.logger.trace("building details");
|
||||
List<FileTransformerBuilderItemResponse<M, D>> models = this.buildInternal(data);
|
||||
this.logger.debug("mapping {} build items from {} requested", Optional.ofNullable(models).map(List::size).orElse(0), Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
Map<K, List<M>> map = new HashMap<>();
|
||||
if (models == null) return map;
|
||||
for (FileTransformerBuilderItemResponse<M, D> model : models) {
|
||||
K key = keySelector.apply(model.getData());
|
||||
if (!map.containsKey(key)) map.put(key, new ArrayList<M>());
|
||||
map.get(key).add(model.getModel());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,161 @@
|
|||
package eu.eudat.model.builder.filetransformer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commons.types.description.FieldEntity;
|
||||
import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.depositinterface.enums.FieldType;
|
||||
import eu.eudat.depositinterface.models.DescriptionFieldDepositModel;
|
||||
import eu.eudat.file.transformer.models.descriptiontemplate.DescriptionTemplateFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.descriptiontemplate.definition.FieldFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.descriptiontemplate.definition.FieldSetFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.descriptiontemplate.definition.PageFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.descriptiontemplate.definition.SectionFileTransformerModel;
|
||||
import eu.eudat.service.fielddatahelper.FieldDataHelperServiceProvider;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class DescriptionFieldFileTransformerBuilder extends BaseFileTransformerBuilder<DescriptionTemplateFileTransformerModel, FieldEntity> {
|
||||
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
private DescriptionTemplateFileTransformerModel definition;
|
||||
private final FieldDataHelperServiceProvider fieldDataHelperServiceProvider;
|
||||
@Autowired
|
||||
public DescriptionFieldFileTransformerBuilder(
|
||||
ConventionService conventionService, FieldDataHelperServiceProvider fieldDataHelperServiceProvider
|
||||
) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionFieldFileTransformerBuilder.class)));
|
||||
this.fieldDataHelperServiceProvider = fieldDataHelperServiceProvider;
|
||||
}
|
||||
|
||||
public DescriptionFieldFileTransformerBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescriptionFieldFileTransformerBuilder setDefinition(DescriptionTemplateFileTransformerModel definition) {
|
||||
this.definition = definition;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<FileTransformerBuilderItemResponse<DescriptionTemplateFileTransformerModel, FieldEntity>> buildInternal(List<FieldEntity> 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<FileTransformerBuilderItemResponse<DescriptionFieldDepositModel, FieldEntity>> models = new ArrayList<>();
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
for (FieldEntity d : data) {
|
||||
// DescriptionFieldDepositModel m = new DescriptionFieldDepositModel();
|
||||
if (definition != null){
|
||||
FieldFileTransformerModel fieldEntity = findFieldById(d.getKey());
|
||||
if (fieldEntity != null){
|
||||
//m.setSchematics(fieldEntity.getSchematics());
|
||||
if (fieldEntity.getData() != null) {
|
||||
/*boolean isMultiValue = fieldDataHelperServiceProvider.get(eu.eudat.commons.enums.FieldType.of(fieldEntity.getData().getFieldType().getValue())).isMultiValue(fieldEntity.getData());
|
||||
if (!isMultiValue) fieldEntity.getData().setValue(List.of(d.getValue());
|
||||
else*/ {
|
||||
fieldEntity.getData().setValue(d.getValue());
|
||||
}
|
||||
|
||||
/*switch (field.getData().getFieldType()) {
|
||||
case AUTO_COMPLETE -> m.setFieldType(FieldType.AUTO_COMPLETE);
|
||||
case WORD_LIST -> m.setFieldType(FieldType.WORD_LIST);
|
||||
case BOOLEAN_DECISION -> m.setFieldType(FieldType.BOOLEAN_DECISION);
|
||||
case RADIO_BOX -> m.setFieldType(FieldType.RADIO_BOX);
|
||||
case INTERNAL_DMP_ENTRIES_RESEARCHERS -> m.setFieldType(FieldType.INTERNAL_DMP_ENTRIES_RESEARCHERS);
|
||||
case INTERNAL_DMP_ENTRIES_DMPS -> m.setFieldType(FieldType.INTERNAL_DMP_ENTRIES_DMPS);
|
||||
case INTERNAL_DMP_ENTRIES_DATASETS -> m.setFieldType(FieldType.INTERNAL_DMP_ENTRIES_DATASETS);
|
||||
case CHECK_BOX -> m.setFieldType(FieldType.CHECK_BOX);
|
||||
case FREE_TEXT -> m.setFieldType(FieldType.FREE_TEXT);
|
||||
case TEXT_AREA -> m.setFieldType(FieldType.TEXT_AREA);
|
||||
case RICH_TEXT_AREA -> m.setFieldType(FieldType.RICH_TEXT_AREA);
|
||||
case UPLOAD -> m.setFieldType(FieldType.UPLOAD);
|
||||
case DATE_PICKER -> m.setFieldType(FieldType.DATE_PICKER);
|
||||
case EXTERNAL_DATASETS -> m.setFieldType(FieldType.EXTERNAL_DATASETS);
|
||||
case DATA_REPOSITORIES -> m.setFieldType(FieldType.DATA_REPOSITORIES);
|
||||
case JOURNAL_REPOSITORIES -> m.setFieldType(FieldType.JOURNAL_REPOSITORIES);
|
||||
case PUB_REPOSITORIES -> m.setFieldType(FieldType.PUB_REPOSITORIES);
|
||||
case LICENSES -> m.setFieldType(FieldType.LICENSES);
|
||||
case PUBLICATIONS -> m.setFieldType(FieldType.PUBLICATIONS);
|
||||
case REGISTRIES -> m.setFieldType(FieldType.REGISTRIES);
|
||||
case SERVICES -> m.setFieldType(FieldType.SERVICES);
|
||||
case TAGS -> m.setFieldType(FieldType.TAGS);
|
||||
case RESEARCHERS -> m.setFieldType(FieldType.RESEARCHERS);
|
||||
case ORGANIZATIONS -> m.setFieldType(FieldType.ORGANIZATIONS);
|
||||
case DATASET_IDENTIFIER -> m.setFieldType(FieldType.DATASET_IDENTIFIER);
|
||||
case CURRENCY -> m.setFieldType(FieldType.CURRENCY);
|
||||
case VALIDATION -> m.setFieldType(FieldType.VALIDATION);
|
||||
case TAXONOMIES -> m.setFieldType(FieldType.TAXONOMIES);
|
||||
default -> throw new MyApplicationException("unrecognized type " + field.getData().getFieldType());
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
//models.add(new FileTransformerBuilderItemResponse<>(m, d));
|
||||
}
|
||||
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return List.of(new FileTransformerBuilderItemResponse<>(definition, data.get(0)));
|
||||
}
|
||||
|
||||
private FieldFileTransformerModel findFieldById(String id) {
|
||||
FieldFileTransformerModel result = null;
|
||||
List<PageFileTransformerModel> pages = definition.getDefinition().getPages();
|
||||
for (PageFileTransformerModel page: pages) {
|
||||
if (page.getSections() != null && !page.getSections().isEmpty()) {
|
||||
result = findSectionFieldById(id, page.getSections());
|
||||
if (result != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private FieldFileTransformerModel findSectionFieldById(String id, List<SectionFileTransformerModel> sections) {
|
||||
FieldFileTransformerModel result = null;
|
||||
for (SectionFileTransformerModel section: sections) {
|
||||
if (section.getSections() != null && !section.getSections().isEmpty()) {
|
||||
result = findSectionFieldById(id, section.getSections());
|
||||
}
|
||||
if (result == null) {
|
||||
List<FieldSetFileTransformerModel> fieldSets = section.getFieldSets();
|
||||
if (fieldSets != null && !fieldSets.isEmpty()) {
|
||||
for (FieldSetFileTransformerModel fieldSet : fieldSets) {
|
||||
List<FieldFileTransformerModel> fields = fieldSet.getFields();
|
||||
if (fields != null && !fields.isEmpty()) {
|
||||
for (FieldFileTransformerModel field : fields) {
|
||||
if (field.getId().equals(id)) {
|
||||
result = field;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
package eu.eudat.model.builder.filetransformer;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commons.JsonHandlingService;
|
||||
import eu.eudat.commons.XmlHandlingService;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.commons.types.description.PropertyDefinitionEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.DescriptionEntity;
|
||||
import eu.eudat.data.DescriptionTemplateEntity;
|
||||
import eu.eudat.depositinterface.models.DescriptionDepositModel;
|
||||
import eu.eudat.file.transformer.enums.DescriptionStatus;
|
||||
import eu.eudat.file.transformer.models.description.DescriptionFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.descriptiontemplate.DescriptionTemplateFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.dmp.DmpFileTransformerModel;
|
||||
import eu.eudat.model.DescriptionTemplate;
|
||||
import eu.eudat.query.DescriptionTemplateQuery;
|
||||
import eu.eudat.query.DmpQuery;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.fieldset.BaseFieldSet;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class DescriptionFileTransformerBuilder extends BaseFileTransformerBuilder<DescriptionFileTransformerModel, DescriptionEntity> {
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
|
||||
private final BuilderFactory builderFactory;
|
||||
private final JsonHandlingService jsonHandlingService;
|
||||
|
||||
private final XmlHandlingService xmlHandlingService;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
@Autowired
|
||||
public DescriptionFileTransformerBuilder(
|
||||
ConventionService conventionService,
|
||||
QueryFactory queryFactory,
|
||||
BuilderFactory builderFactory, JsonHandlingService jsonHandlingService, XmlHandlingService xmlHandlingService) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionFileTransformerBuilder.class)));
|
||||
this.queryFactory = queryFactory;
|
||||
this.builderFactory = builderFactory;
|
||||
this.jsonHandlingService = jsonHandlingService;
|
||||
this.xmlHandlingService = xmlHandlingService;
|
||||
}
|
||||
|
||||
public DescriptionFileTransformerBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<FileTransformerBuilderItemResponse<DescriptionFileTransformerModel, DescriptionEntity>> buildInternal(List<DescriptionEntity> 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<DescriptionTemplateFileTransformerModel> definitionMap = this.collectDescriptionTemplates(data);
|
||||
|
||||
DmpFileTransformerModel dmp = this.getDmp(data.get(0).getDmpId());
|
||||
|
||||
|
||||
List<FileTransformerBuilderItemResponse<DescriptionFileTransformerModel, DescriptionEntity>> models = new ArrayList<>();
|
||||
for (DescriptionEntity d : data) {
|
||||
DescriptionFileTransformerModel m = new DescriptionFileTransformerModel();
|
||||
m.setId(d.getId());
|
||||
m.setLabel(d.getLabel());
|
||||
m.setDescription(d.getDescription());
|
||||
m.setCreatedAt(d.getCreatedAt());
|
||||
m.setFinalizedAt(d.getFinalizedAt());
|
||||
m.setUpdatedAt(d.getUpdatedAt());
|
||||
m.setStatus(DescriptionStatus.of(d.getStatus().getValue()));
|
||||
if (d.getProperties() != null){
|
||||
PropertyDefinitionEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(PropertyDefinitionEntity.class, d.getProperties());
|
||||
|
||||
if (definitionMap != null && definitionMap.stream().anyMatch(dt -> dt.getId().equals(d.getDescriptionTemplateId())) && propertyDefinition != null && !this.conventionService.isListNullOrEmpty(propertyDefinition.getFields())) m.setDescriptionTemplate(this.builderFactory.builder(DescriptionFieldFileTransformerBuilder.class).authorize(this.authorize).setDefinition(definitionMap.stream().filter(dm -> dm.getId().equals(d.getDescriptionTemplateId())).findFirst().get()).build(propertyDefinition.getFields()).get(0));
|
||||
}
|
||||
m.setDmp(dmp);
|
||||
models.add(new FileTransformerBuilderItemResponse<>(m, d));
|
||||
}
|
||||
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
|
||||
private DmpFileTransformerModel getDmp(UUID id) {
|
||||
DmpQuery query = queryFactory.query(DmpQuery.class).authorize(authorize).isActive(IsActive.Active).ids(id);
|
||||
return builderFactory.builder(DmpFileTransformerBuilder.class).ignoreDescriptions(true).authorize(authorize).build(query.first());
|
||||
}
|
||||
|
||||
private List<DescriptionTemplateFileTransformerModel> collectDescriptionTemplates(List<DescriptionEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty())
|
||||
return null;
|
||||
this.logger.debug("checking related - {}", DescriptionTemplate.class.getSimpleName());
|
||||
|
||||
List<DescriptionTemplateEntity> descriptionTemplateEntities = this.queryFactory.query(DescriptionTemplateQuery.class).isActive(IsActive.Active).authorize(this.authorize).ids(data.stream().map(DescriptionEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList())).collectAs(new BaseFieldSet().ensure(DescriptionTemplate._id).ensure(DescriptionTemplate._definition));
|
||||
|
||||
return this.builderFactory.builder(DescriptionTemplateFileTransformerBuilder.class).authorize(authorize).build(descriptionTemplateEntities);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,241 @@
|
|||
package eu.eudat.model.builder.filetransformer;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commons.JsonHandlingService;
|
||||
import eu.eudat.commons.XmlHandlingService;
|
||||
import eu.eudat.commons.types.descriptiontemplate.*;
|
||||
import eu.eudat.commons.types.descriptiontemplate.fielddata.*;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.file.transformer.enums.FieldDataExternalDatasetType;
|
||||
import eu.eudat.file.transformer.enums.FieldType;
|
||||
import eu.eudat.file.transformer.enums.FieldValidationType;
|
||||
import eu.eudat.file.transformer.models.descriptiontemplate.definition.*;
|
||||
import eu.eudat.file.transformer.models.descriptiontemplate.definition.fielddata.*;
|
||||
import eu.eudat.model.descriptiontemplatedefinition.fielddata.UploadOption;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class DescriptionTemplateDefinitionFileTransformerBuilder extends BaseFileTransformerBuilder<DefinitionFileTransformerModel, DefinitionEntity> {
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
|
||||
private final BuilderFactory builderFactory;
|
||||
private final JsonHandlingService jsonHandlingService;
|
||||
|
||||
private final XmlHandlingService xmlHandlingService;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
@Autowired
|
||||
public DescriptionTemplateDefinitionFileTransformerBuilder(
|
||||
ConventionService conventionService,
|
||||
QueryFactory queryFactory,
|
||||
BuilderFactory builderFactory, JsonHandlingService jsonHandlingService, XmlHandlingService xmlHandlingService) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionTemplateDefinitionFileTransformerBuilder.class)));
|
||||
this.queryFactory = queryFactory;
|
||||
this.builderFactory = builderFactory;
|
||||
this.jsonHandlingService = jsonHandlingService;
|
||||
this.xmlHandlingService = xmlHandlingService;
|
||||
}
|
||||
|
||||
public DescriptionTemplateDefinitionFileTransformerBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<FileTransformerBuilderItemResponse<DefinitionFileTransformerModel, 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<FileTransformerBuilderItemResponse<DefinitionFileTransformerModel, DefinitionEntity>> models = new ArrayList<>();
|
||||
for (DefinitionEntity d : data) {
|
||||
DefinitionFileTransformerModel m = new DefinitionFileTransformerModel();
|
||||
m.setPages(collectPages(d.getPages(), d.getSections()));
|
||||
models.add(new FileTransformerBuilderItemResponse<>(m, d));
|
||||
}
|
||||
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
|
||||
private List<PageFileTransformerModel> collectPages(List<PageEntity> data, List<SectionEntity> sections) {
|
||||
List<PageFileTransformerModel> result = new ArrayList<>();
|
||||
for (PageEntity d: data) {
|
||||
PageFileTransformerModel m = new PageFileTransformerModel();
|
||||
m.setId(d.getId());
|
||||
m.setOrdinal(d.getOrdinal());
|
||||
m.setTitle(d.getTitle());
|
||||
m.setSections(collectSections(sections.stream().filter(sectionEntity -> sectionEntity.getPage().equals(d.getId())).toList()));
|
||||
result.add(m);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<SectionFileTransformerModel> collectSections(List<SectionEntity> data) {
|
||||
List<SectionFileTransformerModel> result = new ArrayList<>();
|
||||
for (SectionEntity d : data) {
|
||||
SectionFileTransformerModel m = new SectionFileTransformerModel();
|
||||
m.setId(d.getId());
|
||||
m.setDescription(d.getDescription());
|
||||
m.setTitle(d.getTitle());
|
||||
m.setOrdinal(d.getOrdinal());
|
||||
m.setDefaultVisibility(d.isDefaultVisibility());
|
||||
m.setExtendedDescription(d.getExtendedDescription());
|
||||
m.setMultiplicity(d.getMultiplicity());
|
||||
m.setNumbering(d.getNumbering());
|
||||
m.setSections(collectSections(d.getSections()));
|
||||
m.setFieldSets(collectFieldSet(d.getFieldSets()));
|
||||
result.add(m);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<FieldSetFileTransformerModel> collectFieldSet(List<FieldSetEntity> data) {
|
||||
List<FieldSetFileTransformerModel> result = new ArrayList<>();
|
||||
for (FieldSetEntity d : data) {
|
||||
FieldSetFileTransformerModel m = new FieldSetFileTransformerModel();
|
||||
m.setId(d.getId());
|
||||
m.setDescription(d.getDescription());
|
||||
m.setExtendedDescription(d.getExtendedDescription());
|
||||
m.setAdditionalInformation(d.getAdditionalInformation());
|
||||
m.setHasCommentField(d.getHasCommentField());
|
||||
m.setNumbering(d.getNumbering());
|
||||
m.setOrdinal(d.getOrdinal());
|
||||
m.setTitle(d.getTitle());
|
||||
//m.setMultiplicity(); //TODO: No multiplicity in this code (yet)
|
||||
m.setFields(convertFields(d.getFields()));
|
||||
result.add(m);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<FieldFileTransformerModel> convertFields(List<FieldEntity> data) {
|
||||
List<FieldFileTransformerModel> result = new ArrayList<>();
|
||||
for (FieldEntity d : data) {
|
||||
FieldFileTransformerModel m = new FieldFileTransformerModel();
|
||||
m.setId(d.getId());
|
||||
m.setSchematics(d.getSchematics());
|
||||
m.setNumbering(d.getNumbering());
|
||||
m.setOrdinal(d.getOrdinal());
|
||||
m.setDefaultValue(d.getDefaultValue());
|
||||
m.setIncludeInExport(d.getIncludeInExport());
|
||||
m.setValidations(d.getValidations().stream().map(fieldValidationType -> FieldValidationType.of(fieldValidationType.getValue())).toList());
|
||||
m.setVisibilityRules(convertVisibilityRules(d.getVisibilityRules()));
|
||||
m.setData(convertData(d.getData()));
|
||||
result.add(m);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<RuleFileTransformerModel> convertVisibilityRules(List<RuleEntity> data) {
|
||||
List<RuleFileTransformerModel> result = new ArrayList<>();
|
||||
for (RuleEntity d : data) {
|
||||
RuleFileTransformerModel m = new RuleFileTransformerModel();
|
||||
m.setTarget(d.getTarget());
|
||||
m.setValue(d.getValue());
|
||||
result.add(m);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public BaseFieldDataFileTransformerModel convertData (BaseFieldDataEntity data) {
|
||||
BaseFieldDataFileTransformerModel m;
|
||||
switch (data) {
|
||||
case AutoCompleteDataEntity d -> {
|
||||
m = new AutoCompleteDataFileTransformerModel();
|
||||
m.setLabel(d.getLabel());
|
||||
m.setFieldType(FieldType.of(d.getFieldType().getValue()));
|
||||
((AutoCompleteDataFileTransformerModel)m).setMultiAutoComplete(d.getMultiAutoComplete());
|
||||
((AutoCompleteDataFileTransformerModel) m).setAutoCompleteSingleDataList(convertAutoCompleteSingleData(d.getAutoCompleteSingleDataList()));
|
||||
}
|
||||
case ExternalDatasetDataEntity d -> {
|
||||
m = new ExternalDatasetDataFileTransformerModel();
|
||||
m.setLabel(d.getLabel());
|
||||
m.setFieldType(FieldType.of(d.getFieldType().getValue()));
|
||||
((ExternalDatasetDataFileTransformerModel)m).setType(FieldDataExternalDatasetType.of(d.getType().getValue()));
|
||||
}
|
||||
case RadioBoxDataEntity d -> {
|
||||
m = new RadioBoxDataFileTransformerModel();
|
||||
m.setLabel(d.getLabel());
|
||||
m.setFieldType(FieldType.of(d.getFieldType().getValue()));
|
||||
((RadioBoxDataFileTransformerModel) m).setOptions(convertRadioBoxOptions(d.getOptions()));
|
||||
}
|
||||
case UploadDataEntity d -> {
|
||||
m = new UploadDataFileTransformerModel();
|
||||
m.setLabel(d.getLabel());
|
||||
m.setFieldType(FieldType.of(d.getFieldType().getValue()));
|
||||
((UploadDataFileTransformerModel) m).setMaxFileSizeInMB(d.getMaxFileSizeInMB());
|
||||
((UploadDataFileTransformerModel) m).setTypes(convertUploadDataOptions(d.getTypes()));
|
||||
}
|
||||
case WordListDataEntity d -> {
|
||||
m = new WordListDataFileTransformerModel();
|
||||
m.setLabel(d.getLabel());
|
||||
m.setFieldType(FieldType.of(d.getFieldType().getValue()));
|
||||
((WordListDataFileTransformerModel) m).setMultiList(d.getMultiList());
|
||||
((WordListDataFileTransformerModel) m).setOptions(d.getOptions().stream().map(this::convertComboBoxOption).toList());
|
||||
}
|
||||
default -> m = null;
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
private List<RadioBoxOptionFileTransformerModel> convertRadioBoxOptions(List<RadioBoxDataEntity.Option> data) {
|
||||
List<RadioBoxOptionFileTransformerModel> result = new ArrayList<>();
|
||||
for (RadioBoxDataEntity.Option d : data) {
|
||||
RadioBoxOptionFileTransformerModel m = new RadioBoxOptionFileTransformerModel();
|
||||
m.setLabel(d.getLabel());
|
||||
m.setValue(d.getValue());
|
||||
result.add(m);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<AutoCompleteSingleDataFileTransformerModel> convertAutoCompleteSingleData(List<AutoCompleteDataEntity.AutoCompleteSingleData> data) {
|
||||
List<AutoCompleteSingleDataFileTransformerModel> result = new ArrayList<>();
|
||||
for (AutoCompleteDataEntity.AutoCompleteSingleData d : data) {
|
||||
AutoCompleteSingleDataFileTransformerModel m = new AutoCompleteSingleDataFileTransformerModel();
|
||||
m.setUrl(d.getUrl());
|
||||
m.setAutoCompleteOptions(convertComboBoxOption(d.getAutoCompleteOptions()));
|
||||
result.add(m);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private ComboBoxOptionFileTransformerModel convertComboBoxOption(ComboBoxDataEntity.Option data) {
|
||||
ComboBoxOptionFileTransformerModel m = new ComboBoxOptionFileTransformerModel();
|
||||
m.setUri(data.getUri());
|
||||
m.setSource(data.getSource());
|
||||
m.setLabel(data.getLabel());
|
||||
m.setValue(data.getValue());
|
||||
return m;
|
||||
}
|
||||
|
||||
private List<UploadOptionFileTransformerModel> convertUploadDataOptions(List<UploadDataEntity.Option> data) {
|
||||
List<UploadOptionFileTransformerModel> result = new ArrayList<>();
|
||||
for (UploadDataEntity.Option d : data) {
|
||||
UploadOptionFileTransformerModel m = new UploadOptionFileTransformerModel();
|
||||
m.setLabel(d.getLabel());
|
||||
m.setValue(d.getValue());
|
||||
result.add(m);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
package eu.eudat.model.builder.filetransformer;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commons.JsonHandlingService;
|
||||
import eu.eudat.commons.XmlHandlingService;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.commons.types.description.PropertyDefinitionEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.DescriptionEntity;
|
||||
import eu.eudat.data.DescriptionTemplateEntity;
|
||||
import eu.eudat.file.transformer.models.description.DescriptionFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.descriptiontemplate.DescriptionTemplateFileTransformerModel;
|
||||
import eu.eudat.model.DescriptionTemplate;
|
||||
import eu.eudat.query.DescriptionTemplateQuery;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.fieldset.BaseFieldSet;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class DescriptionTemplateFileTransformerBuilder extends BaseFileTransformerBuilder<DescriptionTemplateFileTransformerModel, 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);
|
||||
|
||||
@Autowired
|
||||
public DescriptionTemplateFileTransformerBuilder(
|
||||
ConventionService conventionService,
|
||||
QueryFactory queryFactory,
|
||||
BuilderFactory builderFactory, JsonHandlingService jsonHandlingService, XmlHandlingService xmlHandlingService) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionTemplateFileTransformerBuilder.class)));
|
||||
this.queryFactory = queryFactory;
|
||||
this.builderFactory = builderFactory;
|
||||
this.jsonHandlingService = jsonHandlingService;
|
||||
this.xmlHandlingService = xmlHandlingService;
|
||||
}
|
||||
|
||||
public DescriptionTemplateFileTransformerBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<FileTransformerBuilderItemResponse<DescriptionTemplateFileTransformerModel, DescriptionTemplateEntity>> buildInternal(List<DescriptionTemplateEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty()) return new ArrayList<>();
|
||||
|
||||
data = queryFactory.query(DescriptionTemplateQuery.class).ids(data.stream().map(DescriptionTemplateEntity::getId).toList()).collect();
|
||||
List<FileTransformerBuilderItemResponse<DescriptionTemplateFileTransformerModel, DescriptionTemplateEntity>> models = new ArrayList<>();
|
||||
for (DescriptionTemplateEntity d : data) {
|
||||
|
||||
DescriptionTemplateFileTransformerModel m = new DescriptionTemplateFileTransformerModel();
|
||||
m.setId(d.getId());
|
||||
m.setLabel(d.getLabel());
|
||||
m.setDescription(d.getDescription());
|
||||
m.setDefinition(this.builderFactory.builder(DescriptionTemplateDefinitionFileTransformerBuilder.class).authorize(authorize).build(collectDescriptionTemplates(d)));
|
||||
|
||||
models.add(new FileTransformerBuilderItemResponse<>(m, d));
|
||||
}
|
||||
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
|
||||
private eu.eudat.commons.types.descriptiontemplate.DefinitionEntity collectDescriptionTemplates(DescriptionTemplateEntity data) throws MyApplicationException {
|
||||
return this.xmlHandlingService.fromXmlSafe(eu.eudat.commons.types.descriptiontemplate.DefinitionEntity.class, data.getDefinition());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,127 @@
|
|||
package eu.eudat.model.builder.filetransformer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commons.JsonHandlingService;
|
||||
import eu.eudat.commons.XmlHandlingService;
|
||||
import eu.eudat.commons.types.dmpblueprint.*;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.DescriptionTemplateEntity;
|
||||
import eu.eudat.data.DmpBlueprintEntity;
|
||||
import eu.eudat.file.transformer.enums.DmpBlueprintExtraFieldDataType;
|
||||
import eu.eudat.file.transformer.enums.DmpBlueprintFieldCategory;
|
||||
import eu.eudat.file.transformer.enums.DmpBlueprintSystemFieldType;
|
||||
import eu.eudat.file.transformer.models.descriptiontemplate.DescriptionTemplateFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.dmpblueprint.DmpBlueprintFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.dmpblueprint.definition.*;
|
||||
import eu.eudat.model.dmpblueprintdefinition.*;
|
||||
import eu.eudat.query.DescriptionTemplateQuery;
|
||||
import eu.eudat.query.DmpBlueprintQuery;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class DmpBlueprintFileTransformerBuilder extends BaseFileTransformerBuilder<DmpBlueprintFileTransformerModel, DmpBlueprintEntity> {
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
|
||||
private final BuilderFactory builderFactory;
|
||||
private final JsonHandlingService jsonHandlingService;
|
||||
|
||||
private final XmlHandlingService xmlHandlingService;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
@Autowired
|
||||
public DmpBlueprintFileTransformerBuilder(
|
||||
ConventionService conventionService,
|
||||
QueryFactory queryFactory,
|
||||
BuilderFactory builderFactory, JsonHandlingService jsonHandlingService, XmlHandlingService xmlHandlingService) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpBlueprintFileTransformerBuilder.class)));
|
||||
this.queryFactory = queryFactory;
|
||||
this.builderFactory = builderFactory;
|
||||
this.jsonHandlingService = jsonHandlingService;
|
||||
this.xmlHandlingService = xmlHandlingService;
|
||||
}
|
||||
|
||||
public DmpBlueprintFileTransformerBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<FileTransformerBuilderItemResponse<DmpBlueprintFileTransformerModel, 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<>();
|
||||
|
||||
data = queryFactory.query(DmpBlueprintQuery.class).ids(data.stream().map(DmpBlueprintEntity::getId).toList()).collect();
|
||||
List<FileTransformerBuilderItemResponse<DmpBlueprintFileTransformerModel, DmpBlueprintEntity>> models = new ArrayList<>();
|
||||
for (DmpBlueprintEntity d : data) {
|
||||
|
||||
DmpBlueprintFileTransformerModel m = new DmpBlueprintFileTransformerModel();
|
||||
m.setId(d.getId());
|
||||
m.setLabel(d.getLabel());
|
||||
try {
|
||||
m.setDefinitionFileTransformerModel(getDefinition(d.getDefinition()));
|
||||
} catch (JsonProcessingException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
models.add(new FileTransformerBuilderItemResponse<>(m, d));
|
||||
}
|
||||
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
|
||||
private DefinitionFileTransformerModel getDefinition(String source) throws JsonProcessingException {
|
||||
DefinitionFileTransformerModel result = new DefinitionFileTransformerModel();
|
||||
result.setSections(new ArrayList<>());
|
||||
DefinitionEntity parsedDefinition = xmlHandlingService.fromXmlSafe(DefinitionEntity.class, source);
|
||||
List<SectionEntity> sections = parsedDefinition.getSections();
|
||||
sections.forEach(section -> {
|
||||
SectionFileTransformerModel m = new SectionFileTransformerModel();
|
||||
m.setId(section.getId());
|
||||
m.setLabel(section.getLabel());
|
||||
m.setDescription(section.getDescription());
|
||||
m.setFields(mapFields(section.getFields()));
|
||||
m.setHasTemplates(section.getHasTemplates());
|
||||
result.getSections().add(m);
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<FieldFileTransformerModel> mapFields(List<FieldEntity> fieldEntities) {
|
||||
List<FieldFileTransformerModel> result = new ArrayList<>();
|
||||
fieldEntities.forEach(fieldEntity -> {
|
||||
FieldFileTransformerModel m = switch (fieldEntity.getCategory()) {
|
||||
case System -> new SystemFieldFileTransformerModel();
|
||||
case Extra -> new ExtraFieldFileTransformerModelFileTransformerModel();
|
||||
};
|
||||
m.setId(fieldEntity.getId());
|
||||
m.setLabel(fieldEntity.getLabel());
|
||||
m.setDescription(fieldEntity.getDescription());
|
||||
m.setOrdinal(fieldEntity.getOrdinal());
|
||||
m.setPlaceholder(fieldEntity.getPlaceholder());
|
||||
m.setRequired(fieldEntity.isRequired());
|
||||
switch (m) {
|
||||
case SystemFieldFileTransformerModel sm -> sm.setSystemFieldType(DmpBlueprintSystemFieldType.of(((SystemFieldEntity)fieldEntity).getType().getValue()));
|
||||
case ExtraFieldFileTransformerModelFileTransformerModel sm -> sm.setDataType(DmpBlueprintExtraFieldDataType.of(((ExtraFieldEntity)fieldEntity).getType().getValue()));
|
||||
default -> {}
|
||||
}
|
||||
result.add(m);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,185 @@
|
|||
package eu.eudat.model.builder.filetransformer;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.*;
|
||||
import eu.eudat.file.transformer.enums.DmpAccessType;
|
||||
import eu.eudat.file.transformer.enums.DmpStatus;
|
||||
import eu.eudat.file.transformer.enums.DmpVersionStatus;
|
||||
import eu.eudat.file.transformer.models.description.DescriptionFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.dmp.DmpFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.dmp.DmpReferenceFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.dmp.DmpUserFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.dmpblueprint.DmpBlueprintFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.entitydoi.EntityDoiFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.user.UserFileTransformerModel;
|
||||
import eu.eudat.model.*;
|
||||
import eu.eudat.query.*;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.query.Ordering;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.fieldset.BaseFieldSet;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class DmpFileTransformerBuilder extends BaseFileTransformerBuilder<DmpFileTransformerModel, DmpEntity> {
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
private final BuilderFactory builderFactory;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
private Boolean ignoreDescriptions = false;
|
||||
|
||||
@Autowired
|
||||
public DmpFileTransformerBuilder(ConventionService conventionService,
|
||||
QueryFactory queryFactory,
|
||||
BuilderFactory builderFactory) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpFileTransformerBuilder.class)));
|
||||
this.queryFactory = queryFactory;
|
||||
this.builderFactory = builderFactory;
|
||||
}
|
||||
|
||||
public DmpFileTransformerBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DmpFileTransformerBuilder ignoreDescriptions(Boolean ignoreDescriptions) {
|
||||
this.ignoreDescriptions = ignoreDescriptions;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<FileTransformerBuilderItemResponse<DmpFileTransformerModel, 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<FileTransformerBuilderItemResponse<DmpFileTransformerModel, DmpEntity>> models = new ArrayList<>();
|
||||
|
||||
Map<UUID, List<DmpReferenceFileTransformerModel>> dmpReferencesMap = this.collectReferences(data);
|
||||
|
||||
Map<UUID, List<DmpUserFileTransformerModel>> dmpUsersMap = this.collectDmpUsers(data);
|
||||
|
||||
Map<UUID, List<DescriptionFileTransformerModel>> descriptionsMap = null;
|
||||
if (!ignoreDescriptions) {
|
||||
descriptionsMap = this.collectDmpDescriptions(data);
|
||||
}
|
||||
|
||||
Map<UUID, List<EntityDoiFileTransformerModel>> doiMap = this.collectEntityDois(data);
|
||||
Map<UUID, UserFileTransformerModel> creatorMap = this.collectCreators(data);
|
||||
Map<UUID, DmpBlueprintFileTransformerModel> blueprintMap = this.collectBlueprints(data);
|
||||
|
||||
for (DmpEntity d : data) {
|
||||
DmpFileTransformerModel m = new DmpFileTransformerModel();
|
||||
m.setId(d.getId());
|
||||
m.setLabel(d.getLabel());
|
||||
m.setVersion(d.getVersion());
|
||||
m.setDescription(d.getDescription());
|
||||
m.setFinalizedAt(d.getFinalizedAt());
|
||||
m.setCreatedAt(d.getCreatedAt());
|
||||
if (d.getPublicAfter() != null && d.getPublicAfter().isAfter(Instant.now())) {
|
||||
m.setPublishedAt(d.getPublicAfter());
|
||||
}
|
||||
switch (d.getAccessType()){
|
||||
case Public -> m.setAccessType(DmpAccessType.Public);
|
||||
case Restricted -> m.setAccessType(DmpAccessType.Restricted);
|
||||
case null -> m.setAccessType(null);
|
||||
default -> throw new MyApplicationException("unrecognized type " + d.getAccessType().getValue());
|
||||
}
|
||||
|
||||
m.setProperties(d.getProperties());
|
||||
m.setUpdatedAt(d.getUpdatedAt());
|
||||
m.setLanguage(d.getLanguage());
|
||||
m.setStatus(DmpStatus.of(d.getStatus().getValue()));
|
||||
m.setVersionStatus(DmpVersionStatus.of(d.getVersionStatus().getValue()));
|
||||
if (dmpReferencesMap != null && !dmpReferencesMap.isEmpty() && dmpReferencesMap.containsKey(d.getId())) m.setDmpReferences(dmpReferencesMap.get(d.getId()));
|
||||
if (dmpUsersMap != null && !dmpUsersMap.isEmpty() && dmpUsersMap.containsKey(d.getId())) m.setDmpUsers(dmpUsersMap.get(d.getId()));
|
||||
if (descriptionsMap != null && !descriptionsMap.isEmpty() && descriptionsMap.containsKey(d.getId())) m.setDescriptions(descriptionsMap.get(d.getId()));
|
||||
if (doiMap != null && !doiMap.isEmpty() && doiMap.containsKey(d.getId())) m.setEntityDois(doiMap.get(d.getId()));
|
||||
if (creatorMap != null && !creatorMap.isEmpty() && creatorMap.containsKey(d.getId())) m.setCreator(creatorMap.get(d.getId()));
|
||||
if (blueprintMap != null && !blueprintMap.isEmpty() && blueprintMap.containsKey(d.getId())) m.setBlueprint(blueprintMap.get(d.getId()));
|
||||
|
||||
models.add(new FileTransformerBuilderItemResponse<>(m, d));
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
|
||||
private Map<UUID, List<DmpReferenceFileTransformerModel>> 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<DmpReferenceFileTransformerModel>> 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, DmpReferenceFileTransformerModel> referenceDepositModelMap = this.builderFactory.builder(ReferenceFileTransformerBuilder.class).authorize(this.authorize).asForeignKey(query, ReferenceEntity::getId);
|
||||
if (referenceDepositModelMap == null) return null;
|
||||
for (DmpReferenceEntity dmpReference : dmpReferences) {
|
||||
DmpReferenceFileTransformerModel model =referenceDepositModelMap.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<DmpUserFileTransformerModel>> collectDmpUsers(List<DmpEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("checking related - {}", DmpUser.class.getSimpleName());
|
||||
|
||||
Map<UUID, List<DmpUserFileTransformerModel>> itemMap;
|
||||
DmpUserQuery query = this.queryFactory.query(DmpUserQuery.class).isActives(IsActive.Active).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList()));
|
||||
itemMap = this.builderFactory.builder(DmpUserFileTransformerBuilder.class).authorize(this.authorize).asMasterKey(query, DmpUserEntity::getDmpId);
|
||||
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
private Map<UUID, List<DescriptionFileTransformerModel>> collectDmpDescriptions(List<DmpEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty()) return null;
|
||||
this.logger.debug("checking related - {}", Description.class.getSimpleName());
|
||||
|
||||
Map<UUID, List<DescriptionFileTransformerModel>> itemMap;
|
||||
DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).isActive(IsActive.Active).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList()));
|
||||
itemMap = this.builderFactory.builder(DescriptionFileTransformerBuilder.class).authorize(this.authorize).asMasterKey(query, DescriptionEntity::getDmpId);
|
||||
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
private Map<UUID, UserFileTransformerModel> collectCreators(List<DmpEntity> data) {
|
||||
DmpUserQuery query = this.queryFactory.query(DmpUserQuery.class).isActives(IsActive.Active).authorize(this.authorize).userIds(data.stream().map(DmpEntity::getCreatorId).toList());
|
||||
return this.builderFactory.builder(DmpUserFileTransformerBuilder.class).authorize(this.authorize).asMasterKey(query, DmpUserEntity::getDmpId)
|
||||
.entrySet().stream().map(uuidListEntry -> Map.entry(uuidListEntry.getKey(), uuidListEntry.getValue().get(0).getUser()))
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
}
|
||||
|
||||
private Map<UUID, DmpBlueprintFileTransformerModel> collectBlueprints(List<DmpEntity> data) {
|
||||
DmpBlueprintQuery query = this.queryFactory.query(DmpBlueprintQuery.class).isActive(IsActive.Active).authorize(this.authorize).ids(data.stream().map(DmpEntity::getBlueprintId).toList());
|
||||
return this.builderFactory.builder(DmpBlueprintFileTransformerBuilder.class).authorize(this.authorize).asMasterKey(query, DmpBlueprintEntity::getId)
|
||||
.entrySet().stream().map(uuidListEntry -> Map.entry(uuidListEntry.getKey(), uuidListEntry.getValue().get(0)))
|
||||
.collect(Collectors.toMap(entry -> entry.getKey(), entry -> entry.getValue()));
|
||||
}
|
||||
|
||||
private Map<UUID, List<EntityDoiFileTransformerModel>> collectEntityDois(List<DmpEntity> data) {
|
||||
if (data.isEmpty()) return null;
|
||||
Map<UUID, List<EntityDoiFileTransformerModel>> result;
|
||||
EntityDoiQuery query = this.queryFactory.query(EntityDoiQuery.class).isActive(IsActive.Active).authorize(authorize).entityIds(data.stream().map(DmpEntity::getId).distinct().toList());
|
||||
result = builderFactory.builder(EntityDoiFileTransformerBuilder.class).asMasterKey(query, EntityDoiEntity::getEntityId);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
package eu.eudat.model.builder.filetransformer;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.DmpUserEntity;
|
||||
import eu.eudat.data.UserEntity;
|
||||
import eu.eudat.file.transformer.enums.DmpUserRole;
|
||||
import eu.eudat.file.transformer.models.dmp.DmpUserFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.user.UserFileTransformerModel;
|
||||
import eu.eudat.query.UserQuery;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class DmpUserFileTransformerBuilder extends BaseFileTransformerBuilder<DmpUserFileTransformerModel, DmpUserEntity> {
|
||||
|
||||
private final BuilderFactory builderFactory;
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
@Autowired
|
||||
public DmpUserFileTransformerBuilder(
|
||||
ConventionService conventionService,
|
||||
BuilderFactory builderFactory, QueryFactory queryFactory) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpUserFileTransformerBuilder.class)));
|
||||
this.builderFactory = builderFactory;
|
||||
this.queryFactory = queryFactory;
|
||||
}
|
||||
|
||||
public DmpUserFileTransformerBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<FileTransformerBuilderItemResponse<DmpUserFileTransformerModel, DmpUserEntity>> buildInternal(List<DmpUserEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {} items ", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null)
|
||||
return new ArrayList<>();
|
||||
|
||||
|
||||
Map<UUID, UserFileTransformerModel> userItemsMap = this.collectUsers(data);
|
||||
|
||||
List<FileTransformerBuilderItemResponse<DmpUserFileTransformerModel, DmpUserEntity>> models = new ArrayList<>();
|
||||
for (DmpUserEntity d : data) {
|
||||
DmpUserFileTransformerModel m = new DmpUserFileTransformerModel();
|
||||
m.setId(d.getId());
|
||||
switch (d.getRole()){
|
||||
case User -> m.setRole(DmpUserRole.User);
|
||||
case Owner -> m.setRole(DmpUserRole.Owner);
|
||||
default -> throw new MyApplicationException("unrecognized type " + d.getRole().getValue());
|
||||
}
|
||||
if (userItemsMap != null && userItemsMap.containsKey(d.getUserId())) m.setUser(userItemsMap.get(d.getUserId()));
|
||||
models.add(new FileTransformerBuilderItemResponse<>(m, d));
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
return models;
|
||||
}
|
||||
|
||||
private Map<UUID, UserFileTransformerModel> collectUsers(List<DmpUserEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty())
|
||||
return null;
|
||||
this.logger.debug("checking related - {}", UserFileTransformerModel.class.getSimpleName());
|
||||
|
||||
Map<UUID, UserFileTransformerModel> itemMap;
|
||||
UserQuery q = this.queryFactory.query(UserQuery.class).isActive(IsActive.Active).authorize(this.authorize).ids(data.stream().map(DmpUserEntity::getUserId).distinct().collect(Collectors.toList()));
|
||||
itemMap = this.builderFactory.builder(UserFileTransformerBuilder.class).authorize(this.authorize).asForeignKey(q, UserEntity::getId);
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package eu.eudat.model.builder.filetransformer;
|
||||
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.EntityDoiEntity;
|
||||
import eu.eudat.file.transformer.models.entitydoi.EntityDoiFileTransformerModel;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class EntityDoiFileTransformerBuilder extends BaseFileTransformerBuilder<EntityDoiFileTransformerModel, EntityDoiEntity>{
|
||||
@Autowired
|
||||
public EntityDoiFileTransformerBuilder(ConventionService conventionService) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpFileTransformerBuilder.class)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<FileTransformerBuilderItemResponse<EntityDoiFileTransformerModel, EntityDoiEntity>> buildInternal(List<EntityDoiEntity> data) throws MyApplicationException {
|
||||
List<FileTransformerBuilderItemResponse<EntityDoiFileTransformerModel, EntityDoiEntity>> result = new ArrayList<>();
|
||||
for (EntityDoiEntity d : data) {
|
||||
EntityDoiFileTransformerModel m = new EntityDoiFileTransformerModel();
|
||||
m.setId(d.getId());
|
||||
m.setDoi(d.getDoi());
|
||||
m.setRepositoryId(d.getRepositoryId());
|
||||
result.add(new FileTransformerBuilderItemResponse<>(m, d));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package eu.eudat.model.builder.filetransformer;
|
||||
|
||||
public class FileTransformerBuilderItemResponse<M, D>{
|
||||
private final M model;
|
||||
private final D data;
|
||||
|
||||
public FileTransformerBuilderItemResponse(M model, D data) {
|
||||
this.model = model;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public D getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public M getModel() {
|
||||
return model;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package eu.eudat.model.builder.filetransformer;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commons.types.reference.DefinitionEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.depositinterface.models.reference.DefinitionDepositModel;
|
||||
import eu.eudat.file.transformer.models.reference.DefinitionFileTransformerModel;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class ReferenceDefinitionFileTransformerBuilder extends BaseFileTransformerBuilder<DefinitionFileTransformerModel, DefinitionEntity> {
|
||||
|
||||
private final BuilderFactory builderFactory;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
@Autowired
|
||||
public ReferenceDefinitionFileTransformerBuilder(
|
||||
ConventionService conventionService, BuilderFactory builderFactory) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceDefinitionFileTransformerBuilder.class)));
|
||||
this.builderFactory = builderFactory;
|
||||
}
|
||||
|
||||
public ReferenceDefinitionFileTransformerBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<FileTransformerBuilderItemResponse<DefinitionFileTransformerModel, 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<FileTransformerBuilderItemResponse<DefinitionFileTransformerModel, DefinitionEntity>> models = new ArrayList<>();
|
||||
for (DefinitionEntity d : data) {
|
||||
DefinitionFileTransformerModel m = new DefinitionFileTransformerModel();
|
||||
if (d.getFields() != null) m.setFields(this.builderFactory.builder(ReferenceFieldFileTransformerBuilder.class).authorize(this.authorize).build(d.getFields()));
|
||||
models.add(new FileTransformerBuilderItemResponse<>(m, d));
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
return models;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package eu.eudat.model.builder.filetransformer;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commons.types.reference.FieldEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.depositinterface.models.reference.FieldDepositModel;
|
||||
import eu.eudat.file.transformer.models.reference.FieldFileTransformerModel;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class ReferenceFieldFileTransformerBuilder extends BaseFileTransformerBuilder<FieldFileTransformerModel, FieldEntity> {
|
||||
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
@Autowired
|
||||
public ReferenceFieldFileTransformerBuilder(
|
||||
ConventionService conventionService) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceFieldFileTransformerBuilder.class)));
|
||||
}
|
||||
|
||||
public ReferenceFieldFileTransformerBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<FileTransformerBuilderItemResponse<FieldFileTransformerModel, FieldEntity>> buildInternal(List<FieldEntity> 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<FileTransformerBuilderItemResponse<FieldFileTransformerModel, FieldEntity>> models = new ArrayList<>();
|
||||
for (FieldEntity d : data) {
|
||||
FieldFileTransformerModel m = new FieldFileTransformerModel();
|
||||
m.setCode(d.getCode());
|
||||
m.setValue(d.getValue());
|
||||
|
||||
models.add(new FileTransformerBuilderItemResponse<>(m, d));
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
return models;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
package eu.eudat.model.builder.filetransformer;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commons.XmlHandlingService;
|
||||
import eu.eudat.commons.types.reference.DefinitionEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.ReferenceEntity;
|
||||
import eu.eudat.file.transformer.enums.ReferenceSourceType;
|
||||
import eu.eudat.file.transformer.enums.ReferenceType;
|
||||
import eu.eudat.file.transformer.models.dmp.DmpReferenceFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.reference.ReferenceFileTransformerModel;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class ReferenceFileTransformerBuilder extends BaseFileTransformerBuilder<DmpReferenceFileTransformerModel, ReferenceEntity> {
|
||||
|
||||
private final BuilderFactory builderFactory;
|
||||
private final XmlHandlingService xmlHandlingService;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
@Autowired
|
||||
public ReferenceFileTransformerBuilder(
|
||||
ConventionService conventionService,
|
||||
BuilderFactory builderFactory, XmlHandlingService xmlHandlingService) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceFileTransformerBuilder.class)));
|
||||
this.builderFactory = builderFactory;
|
||||
this.xmlHandlingService = xmlHandlingService;
|
||||
}
|
||||
|
||||
public ReferenceFileTransformerBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<FileTransformerBuilderItemResponse<DmpReferenceFileTransformerModel, ReferenceEntity>> buildInternal(List<ReferenceEntity> 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<FileTransformerBuilderItemResponse<DmpReferenceFileTransformerModel, ReferenceEntity>> models = new ArrayList<>();
|
||||
for (ReferenceEntity d : data) {
|
||||
ReferenceFileTransformerModel m = new ReferenceFileTransformerModel();
|
||||
m.setId(d.getId());
|
||||
m.setLabel(d.getLabel());
|
||||
if (d.getDefinition() != null){
|
||||
DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(DefinitionEntity.class, d.getDefinition());
|
||||
m.setDefinition(this.builderFactory.builder(ReferenceDefinitionFileTransformerBuilder.class).authorize(this.authorize).build(definition));
|
||||
}
|
||||
m.setReference(d.getReference());
|
||||
m.setAbbreviation(d.getAbbreviation());
|
||||
m.setDescription(d.getDescription());
|
||||
m.setSource(d.getSource());
|
||||
switch (d.getSourceType()){
|
||||
case Internal -> m.setSourceType(ReferenceSourceType.Internal);
|
||||
case External -> m.setSourceType(ReferenceSourceType.External);
|
||||
default -> throw new MyApplicationException("unrecognized type " + d.getSourceType().getValue());
|
||||
}
|
||||
switch (d.getType()){
|
||||
case Taxonomies -> m.setType(ReferenceType.Taxonomies);
|
||||
case Licenses -> m.setType(ReferenceType.Licenses);
|
||||
case Publications -> m.setType(ReferenceType.Publications);
|
||||
case Journals -> m.setType(ReferenceType.Journals);
|
||||
case PubRepositories -> m.setType(ReferenceType.PubRepositories);
|
||||
case DataRepositories -> m.setType(ReferenceType.DataRepositories);
|
||||
case Registries -> m.setType(ReferenceType.Registries);
|
||||
case Services -> m.setType(ReferenceType.Services);
|
||||
case Project -> m.setType(ReferenceType.Project);
|
||||
case Funder -> m.setType(ReferenceType.Funder);
|
||||
case Datasets -> m.setType(ReferenceType.Datasets);
|
||||
case Organizations -> m.setType(ReferenceType.Organizations);
|
||||
case Grants -> m.setType(ReferenceType.Grants);
|
||||
case Researcher -> m.setType(ReferenceType.Researcher);
|
||||
default -> throw new MyApplicationException("unrecognized type " + d.getType().getValue());
|
||||
}
|
||||
|
||||
DmpReferenceFileTransformerModel dmpReferenceFileTransformerModel = new DmpReferenceFileTransformerModel();
|
||||
dmpReferenceFileTransformerModel.setReference(m);
|
||||
models.add(new FileTransformerBuilderItemResponse<>(dmpReferenceFileTransformerModel, d));
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
return models;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package eu.eudat.model.builder.filetransformer;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.UserContactInfoEntity;
|
||||
import eu.eudat.data.UserEntity;
|
||||
import eu.eudat.depositinterface.models.UserDepositModel;
|
||||
import eu.eudat.file.transformer.enums.ContactInfoType;
|
||||
import eu.eudat.file.transformer.models.user.UserContactInfoFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.user.UserFileTransformerModel;
|
||||
import eu.eudat.query.UserContactInfoQuery;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class UserFileTransformerBuilder extends BaseFileTransformerBuilder<UserFileTransformerModel, UserEntity> {
|
||||
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
private final QueryFactory queryFactory;
|
||||
|
||||
@Autowired
|
||||
public UserFileTransformerBuilder(ConventionService conventionService, QueryFactory queryFactory) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(UserFileTransformerBuilder.class)));
|
||||
this.queryFactory = queryFactory;
|
||||
}
|
||||
|
||||
public UserFileTransformerBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<FileTransformerBuilderItemResponse<UserFileTransformerModel, UserEntity>> buildInternal(List<UserEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {} items ", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null)
|
||||
return new ArrayList<>();
|
||||
|
||||
List<FileTransformerBuilderItemResponse<UserFileTransformerModel, UserEntity>> models = new ArrayList<>();
|
||||
|
||||
for (UserEntity d : data) {
|
||||
UserFileTransformerModel m = new UserFileTransformerModel();
|
||||
m.setId(d.getId());
|
||||
m.setName(d.getName());
|
||||
m.setContacts(mapContactInfo(d.getId()));
|
||||
models.add(new FileTransformerBuilderItemResponse<>(m, d));
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
|
||||
private List<UserContactInfoFileTransformerModel> mapContactInfo(UUID userId) {
|
||||
List<UserContactInfoFileTransformerModel> result = new ArrayList<>();
|
||||
UserContactInfoQuery query = this.queryFactory.query(UserContactInfoQuery.class).userIds(userId);
|
||||
List<UserContactInfoEntity> contactInfos = query.collect();
|
||||
contactInfos.forEach(contactInfo -> {
|
||||
UserContactInfoFileTransformerModel m = new UserContactInfoFileTransformerModel();
|
||||
m.setId(contactInfo.getId());
|
||||
m.setOrdinal(contactInfo.getOrdinal());
|
||||
m.setType(ContactInfoType.of(contactInfo.getType().getValue()));
|
||||
m.setValue(contactInfo.getValue());
|
||||
result.add(m);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package eu.eudat.model.file;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class ExportRequestModel {
|
||||
|
||||
private UUID id;
|
||||
private String format;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFormat() {
|
||||
return format;
|
||||
}
|
||||
|
||||
public void setFormat(String format) {
|
||||
this.format = format;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package eu.eudat.model.file;
|
||||
|
||||
import eu.eudat.file.transformer.model.file.FileFormat;
|
||||
import eu.eudat.file.transformer.models.misc.FileFormat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
|
@ -1,21 +1,17 @@
|
|||
package eu.eudat.repository;
|
||||
|
||||
import eu.eudat.file.transformer.executor.FileTransformerExecutor;
|
||||
import eu.eudat.file.transformer.model.DescriptionFileTransformerModel;
|
||||
import eu.eudat.file.transformer.model.DmpFileTransformerModel;
|
||||
import eu.eudat.file.transformer.model.ExtraPropertiesModel;
|
||||
import eu.eudat.file.transformer.model.file.FileEnvelope;
|
||||
import eu.eudat.file.transformer.model.file.FileFormat;
|
||||
import eu.eudat.utilities.webclient.WebClientUtils;
|
||||
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;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class TransformerRepository implements FileTransformerExecutor {
|
||||
public class TransformerRepository implements FileTransformerClient {
|
||||
|
||||
private final WebClient transformerClient;
|
||||
|
||||
|
@ -24,28 +20,28 @@ public class TransformerRepository implements FileTransformerExecutor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public FileEnvelope exportDmp(DmpFileTransformerModel dmpFileTransformerModel, ExtraPropertiesModel map) throws InvalidApplicationException, IOException {
|
||||
return transformerClient.post().uri("/export/dmp", uriBuilder -> WebClientUtils.buildParameters(uriBuilder, map)).bodyValue(dmpFileTransformerModel).exchangeToMono(mono -> mono.bodyToMono(FileEnvelope.class)).block();
|
||||
public FileEnvelope exportDmp(DmpFileTransformerModel dmpFileTransformerModel, String format) throws InvalidApplicationException, IOException {
|
||||
return transformerClient.post().uri("/export/dmp", uriBuilder -> uriBuilder.queryParam("format", format).build()).bodyValue(dmpFileTransformerModel).exchangeToMono(mono -> mono.bodyToMono(FileEnvelope.class)).block();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DmpFileTransformerModel importFileToDmp(FileEnvelope fileEnvelope) {
|
||||
public DmpFileTransformerModel importDmp(FileEnvelope fileEnvelope) {
|
||||
return transformerClient.post().uri("/import/dmp").bodyValue(fileEnvelope).exchangeToMono(mono -> mono.bodyToMono(DmpFileTransformerModel.class)).block();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileEnvelope exportDescription(DescriptionFileTransformerModel descriptionFileTransformerModel, ExtraPropertiesModel map) throws InvalidApplicationException, IOException {
|
||||
return transformerClient.post().uri("/export/description", uriBuilder -> WebClientUtils.buildParameters(uriBuilder, map)).bodyValue(descriptionFileTransformerModel).exchangeToMono(mono -> mono.bodyToMono(FileEnvelope.class)).block();
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DescriptionFileTransformerModel importFileToDescription(FileEnvelope fileEnvelope) {
|
||||
public DescriptionFileTransformerModel importDescription(FileEnvelope fileEnvelope) {
|
||||
return transformerClient.post().uri("/import/description").bodyValue(fileEnvelope).exchangeToMono(mono -> mono.bodyToMono(DescriptionFileTransformerModel.class)).block();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileFormat> getSupportedFileFormats() {
|
||||
return transformerClient.get().uri("/formats").exchangeToMono(mono -> mono.bodyToMono(new ParameterizedTypeReference<List<FileFormat>>() {})).block();
|
||||
public FileTransformerConfiguration getConfiguration() {
|
||||
return transformerClient.get().uri("/formats").exchangeToMono(mono -> mono.bodyToMono(new ParameterizedTypeReference<FileTransformerConfiguration>() {})).block();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -7,27 +7,24 @@ import eu.eudat.commons.JsonHandlingService;
|
|||
import eu.eudat.commons.enums.DmpUserRole;
|
||||
import eu.eudat.configurations.transformer.TransformerProperties;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.file.transformer.model.DescriptionFileTransformerModel;
|
||||
import eu.eudat.file.transformer.model.DmpFileTransformerModel;
|
||||
import eu.eudat.file.transformer.model.ExtraPropertiesModel;
|
||||
import eu.eudat.file.transformer.model.descriptiontemplatedefinition.Field;
|
||||
import eu.eudat.file.transformer.model.descriptiontemplatedefinition.Rule;
|
||||
import eu.eudat.file.transformer.model.file.FileFormat;
|
||||
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.*;
|
||||
import eu.eudat.model.builder.DescriptionBuilder;
|
||||
import eu.eudat.model.builder.DmpBuilder;
|
||||
import eu.eudat.model.builder.filetransformer.DescriptionFileTransformerBuilder;
|
||||
import eu.eudat.model.builder.filetransformer.DmpFileTransformerBuilder;
|
||||
import eu.eudat.model.descriptionproperties.PropertyDefinition;
|
||||
import eu.eudat.model.descriptiontemplatedefinition.Definition;
|
||||
import eu.eudat.model.descriptiontemplatedefinition.Multiplicity;
|
||||
import eu.eudat.model.descriptiontemplatedefinition.Page;
|
||||
import eu.eudat.model.descriptiontemplatedefinition.Section;
|
||||
import eu.eudat.model.descriptiontemplatedefinition.*;
|
||||
import eu.eudat.model.descriptiontemplatedefinition.fielddata.AutoCompleteData;
|
||||
import eu.eudat.model.descriptiontemplatedefinition.fielddata.AutoCompleteSingleData;
|
||||
import eu.eudat.model.descriptiontemplatedefinition.fielddata.BaseFieldData;
|
||||
import eu.eudat.model.descriptiontemplatedefinition.fielddata.ComboBoxOption;
|
||||
import eu.eudat.model.dmpblueprintdefinition.ExtraField;
|
||||
import eu.eudat.model.dmpblueprintdefinition.SystemField;
|
||||
import eu.eudat.model.file.FileEnvelope;
|
||||
import eu.eudat.model.file.TransformerCacheModel;
|
||||
import eu.eudat.query.DescriptionQuery;
|
||||
import eu.eudat.query.DmpQuery;
|
||||
|
@ -125,9 +122,9 @@ public class FileTransformerService {
|
|||
List<TransformerRepository> repositories = transformerProperties.getSources().stream().map(depositSource -> getRepository(depositSource.getCodes().get(0))).toList();
|
||||
|
||||
repositories.forEach((client) -> {
|
||||
List<FileFormat> repositoryConfigs = client.getSupportedFileFormats();
|
||||
if (repositoryConfigs != null && !repositoryConfigs.isEmpty()) {
|
||||
configurations.addAll(repositoryConfigs);
|
||||
FileTransformerConfiguration repositoryConfigs = client.getConfiguration();
|
||||
if (repositoryConfigs != null && !repositoryConfigs.getExportVariants().isEmpty()) {
|
||||
configurations.addAll(repositoryConfigs.getExportVariants());
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -138,14 +135,14 @@ public class FileTransformerService {
|
|||
return configs.getFormats();
|
||||
}
|
||||
|
||||
public FileEnvelope exportDmp(UUID dmpId, String format) throws InvalidApplicationException, IOException {
|
||||
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);
|
||||
//GK: Second get the Target Data Management Plan
|
||||
FieldSet fieldSet = new BaseFieldSet(Dmp._id,
|
||||
/*FieldSet fieldSet = new BaseFieldSet(Dmp._id,
|
||||
Dmp._accessType,
|
||||
Dmp._dmpReferences,
|
||||
Dmp._blueprint,
|
||||
|
@ -304,14 +301,11 @@ public class FileTransformerService {
|
|||
Dmp._dmpUsers + "." + DmpUser._user + "." + User._roles + "." + UserRole._id,
|
||||
Dmp._dmpUsers + "." + DmpUser._user + "." + User._roles + "." + UserRole._role,
|
||||
Dmp._dmpUsers + "." + DmpUser._role
|
||||
);
|
||||
);*/
|
||||
DmpQuery query = this.queryFactory.query(DmpQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(dmpId);
|
||||
Dmp model = this.builderFactory.builder(DmpBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet));
|
||||
DmpFileTransformerModel dmpFileTransformerModel = this.jsonHandlingService.fromJsonSafe(DmpFileTransformerModel.class, this.jsonHandlingService.toJsonSafe(model));
|
||||
ExtraPropertiesModel extraPropertiesModel = new ExtraPropertiesModel();
|
||||
extraPropertiesModel.setFormat(format);
|
||||
eu.eudat.file.transformer.model.file.FileEnvelope fileEnvelope = repository.exportDmp(dmpFileTransformerModel, extraPropertiesModel);
|
||||
FileEnvelope result = new FileEnvelope();
|
||||
DmpFileTransformerModel dmpFileTransformerModel = this.builderFactory.builder(DmpFileTransformerBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(query.first());
|
||||
FileEnvelope fileEnvelope = repository.exportDmp(dmpFileTransformerModel, format);
|
||||
eu.eudat.model.file.FileEnvelope result = new eu.eudat.model.file.FileEnvelope();
|
||||
File temp = new File(environment.getProperty("path.path") + UUID.randomUUID());
|
||||
try (FileOutputStream fos = new FileOutputStream(temp)) {
|
||||
fos.write(fileEnvelope.getFile());
|
||||
|
@ -321,14 +315,14 @@ public class FileTransformerService {
|
|||
return result;
|
||||
}
|
||||
|
||||
public FileEnvelope exportDescription(UUID descriptionId, String format) throws InvalidApplicationException, IOException {
|
||||
public eu.eudat.model.file.FileEnvelope exportDescription(UUID descriptionId, 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(descriptionId);
|
||||
//GK: First get the right client
|
||||
TransformerRepository repository = getRepository(format);
|
||||
//GK: Second get the Target Data Management Plan
|
||||
FieldSet fieldSet = new BaseFieldSet(
|
||||
/*FieldSet fieldSet = new BaseFieldSet(
|
||||
Description._dmp + "." + Dmp._id,
|
||||
Description._dmp + "." + Dmp._createdAt,
|
||||
Description._dmp + "." + Dmp._finalizedAt,
|
||||
|
@ -439,14 +433,11 @@ public class FileTransformerService {
|
|||
Description._dmp + "." + Dmp._entityDois + "." + EntityDoi._doi,
|
||||
Description._dmp + "." + Dmp._entityDois + "." + EntityDoi._id,
|
||||
Description._dmp + "." + Dmp._entityDois + "." + EntityDoi._entityType
|
||||
);
|
||||
);*/
|
||||
DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(descriptionId);
|
||||
Description model = this.builderFactory.builder(DescriptionBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(fieldSet, query.firstAs(fieldSet));
|
||||
DescriptionFileTransformerModel descriptionFileTransformerModel = this.jsonHandlingService.fromJsonSafe(DescriptionFileTransformerModel.class, this.jsonHandlingService.toJsonSafe(model));
|
||||
ExtraPropertiesModel extraPropertiesModel = new ExtraPropertiesModel();
|
||||
extraPropertiesModel.setFormat(format);
|
||||
eu.eudat.file.transformer.model.file.FileEnvelope fileEnvelope = repository.exportDescription(descriptionFileTransformerModel, extraPropertiesModel);
|
||||
FileEnvelope result = new FileEnvelope();
|
||||
DescriptionFileTransformerModel descriptionFileTransformerModel = this.builderFactory.builder(DescriptionFileTransformerBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(query.first());
|
||||
FileEnvelope fileEnvelope = repository.exportDescription(descriptionFileTransformerModel, format);
|
||||
eu.eudat.model.file.FileEnvelope result = new eu.eudat.model.file.FileEnvelope();
|
||||
File temp = new File(environment.getProperty("path.path") + UUID.randomUUID());
|
||||
try (FileOutputStream fos = new FileOutputStream(temp)) {
|
||||
fos.write(fileEnvelope.getFile());
|
||||
|
|
|
@ -2,8 +2,10 @@ package eu.eudat.controllers.v2;
|
|||
|
||||
import eu.eudat.audit.AuditableAction;
|
||||
import eu.eudat.controllers.BaseController;
|
||||
import eu.eudat.file.transformer.model.file.FileFormat;
|
||||
import eu.eudat.file.transformer.models.misc.FileFormat;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
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;
|
||||
|
@ -12,9 +14,17 @@ import gr.cite.tools.logging.LoggerService;
|
|||
import gr.cite.tools.logging.MapLogEntry;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.management.InvalidApplicationException;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
|
@ -24,15 +34,15 @@ public class FileTransformerController extends BaseController {
|
|||
|
||||
|
||||
private final AuthorizationService authorizationService;
|
||||
private final FileTransformerService depositService;
|
||||
private final FileTransformerService fileTransformerService;
|
||||
private final CensorFactory censorFactory;
|
||||
private final AuditService auditService;
|
||||
|
||||
@Autowired
|
||||
public FileTransformerController(ApiContext apiContext, AuthorizationService authorizationService, FileTransformerService depositService, CensorFactory censorFactory, AuditService auditService){
|
||||
public FileTransformerController(ApiContext apiContext, AuthorizationService authorizationService, FileTransformerService fileTransformerService, CensorFactory censorFactory, AuditService auditService){
|
||||
super(apiContext);
|
||||
this.authorizationService = authorizationService;
|
||||
this.depositService = depositService;
|
||||
this.fileTransformerService = fileTransformerService;
|
||||
this.censorFactory = censorFactory;
|
||||
this.auditService = auditService;
|
||||
}
|
||||
|
@ -41,10 +51,34 @@ public class FileTransformerController extends BaseController {
|
|||
public List<FileFormat> getAvailableConfigurations() {
|
||||
logger.debug(new MapLogEntry("getAvailableConfigurations"));
|
||||
|
||||
List<FileFormat> model = this.depositService.getAvailableConfigurations();
|
||||
List<FileFormat> model = this.fileTransformerService.getAvailableConfigurations();
|
||||
this.auditService.track(AuditableAction.FileTransformer_GetAvailableConfigurations);
|
||||
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
@PostMapping("/export-dmp")
|
||||
public ResponseEntity<byte[]> export(@RequestBody ExportRequestModel requestModel) throws InvalidApplicationException, IOException {
|
||||
logger.debug(new MapLogEntry("exporting dmp"));
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
FileEnvelope fileEnvelope = this.fileTransformerService.exportDmp(requestModel.getId(), requestModel.getFormat());
|
||||
headers.add("Content-Disposition", "attachment;filename=" + fileEnvelope.getFilename());
|
||||
byte[] data = Files.readAllBytes(fileEnvelope.getFile().toPath());
|
||||
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||
return new ResponseEntity<>(data, headers, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/export-description")
|
||||
public ResponseEntity<byte[]> exportDescription(@RequestBody ExportRequestModel requestModel) throws InvalidApplicationException, IOException {
|
||||
logger.debug(new MapLogEntry("exporting dmp"));
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
FileEnvelope fileEnvelope = this.fileTransformerService.exportDescription(requestModel.getId(), requestModel.getFormat());
|
||||
headers.add("Content-Disposition", "attachment;filename=" + fileEnvelope.getFilename());
|
||||
byte[] data = Files.readAllBytes(fileEnvelope.getFile().toPath());
|
||||
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||
return new ResponseEntity<>(data, headers, HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue