130 lines
6.6 KiB
Java
130 lines
6.6 KiB
Java
//package eu.eudat.model.builder.filetransformer;
|
|
//
|
|
//import com.fasterxml.jackson.core.JsonProcessingException;
|
|
//import eu.eudat.authorization.AuthorizationFlags;
|
|
//import eu.eudat.commons.JsonHandlingService;
|
|
//import eu.eudat.commons.XmlHandlingService;
|
|
//import eu.eudat.commons.types.dmpblueprint.*;
|
|
//import eu.eudat.convention.ConventionService;
|
|
//import eu.eudat.data.DmpBlueprintEntity;
|
|
//import eu.eudat.file.transformer.enums.DmpBlueprintExtraFieldDataType;
|
|
//import eu.eudat.file.transformer.enums.DmpBlueprintSystemFieldType;
|
|
//import eu.eudat.file.transformer.models.dmpblueprint.DmpBlueprintFileTransformerModel;
|
|
//import eu.eudat.file.transformer.models.dmpblueprint.definition.*;
|
|
//import eu.eudat.query.DmpBlueprintQuery;
|
|
//import gr.cite.tools.data.builder.BuilderFactory;
|
|
//import gr.cite.tools.data.query.QueryFactory;
|
|
//import gr.cite.tools.exception.MyApplicationException;
|
|
//import gr.cite.tools.logging.LoggerService;
|
|
//import org.apache.commons.lang3.NotImplementedException;
|
|
//import org.slf4j.LoggerFactory;
|
|
//import org.springframework.beans.factory.annotation.Autowired;
|
|
//import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
|
//import org.springframework.context.annotation.Scope;
|
|
//import org.springframework.stereotype.Component;
|
|
//
|
|
//import java.util.*;
|
|
//
|
|
//@Component
|
|
//@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
|
//public class DmpBlueprintFileTransformerBuilder extends BaseFileTransformerBuilder<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.setOrdinal(section.getOrdinal());
|
|
// m.setDescription(section.getDescription());
|
|
// if (section.getFields() != null && !section.getFields().isEmpty()) {
|
|
// m.setFields(mapFields(section.getFields()));
|
|
// }
|
|
// m.setHasTemplates(section.getHasTemplates());
|
|
// result.getSections().add(m);
|
|
// });
|
|
//
|
|
// return result;
|
|
// }
|
|
//
|
|
// private List<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();
|
|
// case ReferenceType -> throw new NotImplementedException("ReferenceFieldFileTransformerModel");
|
|
// default -> throw new MyApplicationException("unrecognized type " + fieldEntity.getCategory());
|
|
// };
|
|
// m.setId(fieldEntity.getId());
|
|
// m.setLabel(fieldEntity.getLabel());
|
|
// m.setDescription(fieldEntity.getDescription());
|
|
// m.setOrdinal(fieldEntity.getOrdinal());
|
|
// m.setPlaceholder(fieldEntity.getPlaceholder());
|
|
// m.setRequired(fieldEntity.isRequired());
|
|
// switch (m) {
|
|
// case SystemFieldFileTransformerModel sm -> sm.setSystemFieldType(DmpBlueprintSystemFieldType.of(((SystemFieldEntity)fieldEntity).getType().getValue()));
|
|
// case ExtraFieldFileTransformerModelFileTransformerModel sm -> sm.setDataType(DmpBlueprintExtraFieldDataType.of(((ExtraFieldEntity)fieldEntity).getType().getValue()));
|
|
//// case ReferenceFieldFileTransformerModelFileTransformerModel sm -> sm.setReferenceTypeId(((ReferenceFieldEntity)fieldEntity).getReferenceTypeId());
|
|
// default -> throw new MyApplicationException("unrecognized type " + fieldEntity.getCategory());
|
|
// }
|
|
// result.add(m);
|
|
// });
|
|
// return result;
|
|
// }
|
|
//
|
|
//}
|