change to common models for Deposit
This commit is contained in:
parent
5fc7241dc2
commit
0530373c83
|
@ -45,7 +45,12 @@
|
|||
<dependency>
|
||||
<groupId>gr.cite.opendmp</groupId>
|
||||
<artifactId>repositorydepositbase</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<version>2.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>gr.cite.opendmp</groupId>
|
||||
<artifactId>common-models</artifactId>
|
||||
<version>0.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>gr.cite.opendmp</groupId>
|
||||
|
|
|
@ -1,21 +1,20 @@
|
|||
package eu.eudat.model.builder.deposit;
|
||||
package eu.eudat.model.builder.commonmodels;
|
||||
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import gr.cite.tools.data.builder.Builder;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.fieldset.FieldSet;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class BaseDepositBuilder<M, D> implements Builder {
|
||||
public abstract class BaseCommonModelBuilder<M, D> implements Builder {
|
||||
protected final LoggerService logger;
|
||||
protected final ConventionService conventionService;
|
||||
|
||||
public BaseDepositBuilder(
|
||||
public BaseCommonModelBuilder(
|
||||
ConventionService conventionService,
|
||||
LoggerService logger
|
||||
) {
|
||||
|
@ -30,16 +29,16 @@ public abstract class BaseDepositBuilder<M, D> implements Builder {
|
|||
M model = null;
|
||||
return null; //TODO
|
||||
}
|
||||
List<DepositBuilderItemResponse<M, D>> models = this.buildInternal(List.of(data));
|
||||
return models.stream().map(DepositBuilderItemResponse::getModel).findFirst().orElse(null); //TODO
|
||||
List<CommonModelBuilderItemResponse<M, D>> models = this.buildInternal(List.of(data));
|
||||
return models.stream().map(CommonModelBuilderItemResponse::getModel).findFirst().orElse(null); //TODO
|
||||
}
|
||||
|
||||
public List<M> build(List<D> data) throws MyApplicationException{
|
||||
List<DepositBuilderItemResponse<M, D>> models = this.buildInternal(data);
|
||||
return models == null ? null : models.stream().map(DepositBuilderItemResponse::getModel).collect(Collectors.toList());
|
||||
List<CommonModelBuilderItemResponse<M, D>> models = this.buildInternal(data);
|
||||
return models == null ? null : models.stream().map(CommonModelBuilderItemResponse::getModel).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
protected abstract List<DepositBuilderItemResponse<M, D>> buildInternal(List<D> data) throws MyApplicationException;
|
||||
protected abstract List<CommonModelBuilderItemResponse<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");
|
||||
|
@ -50,9 +49,9 @@ public abstract class BaseDepositBuilder<M, D> implements Builder {
|
|||
|
||||
public <K> Map<K, M> asForeignKey(List<D> data, Function<D, K> keySelector) throws MyApplicationException {
|
||||
this.logger.trace("building references");
|
||||
List<DepositBuilderItemResponse<M, D>> models = this.buildInternal(data);
|
||||
List<CommonModelBuilderItemResponse<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()), DepositBuilderItemResponse::getModel));
|
||||
return models == null ? new HashMap<>() : models.stream().collect(Collectors.toMap(x-> keySelector.apply(x.getData()), CommonModelBuilderItemResponse::getModel));
|
||||
}
|
||||
public <K> Map<K, List<M>> asMasterKey(QueryBase<D> query,Function<D, K> keySelector) throws MyApplicationException {
|
||||
this.logger.trace("Building details from query");
|
||||
|
@ -63,11 +62,11 @@ public abstract class BaseDepositBuilder<M, D> implements Builder {
|
|||
|
||||
public <K> Map<K, List<M>> asMasterKey(List<D> data, Function<D, K> keySelector) throws MyApplicationException {
|
||||
this.logger.trace("building details");
|
||||
List<DepositBuilderItemResponse<M, D>> models = this.buildInternal(data);
|
||||
List<CommonModelBuilderItemResponse<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 (DepositBuilderItemResponse<M, D> model : models) {
|
||||
for (CommonModelBuilderItemResponse<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());
|
|
@ -1,10 +1,10 @@
|
|||
package eu.eudat.model.builder.deposit;
|
||||
package eu.eudat.model.builder.commonmodels;
|
||||
|
||||
public class DepositBuilderItemResponse<M, D>{
|
||||
public class CommonModelBuilderItemResponse<M, D>{
|
||||
private final M model;
|
||||
private final D data;
|
||||
|
||||
public DepositBuilderItemResponse(M model, D data) {
|
||||
public CommonModelBuilderItemResponse(M model, D data) {
|
||||
this.model = model;
|
||||
this.data = data;
|
||||
}
|
|
@ -1,18 +1,10 @@
|
|||
package eu.eudat.model.builder.deposit;
|
||||
package eu.eudat.model.builder.commonmodels;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.TagEntity;
|
||||
import eu.eudat.model.Tag;
|
||||
import eu.eudat.model.User;
|
||||
import eu.eudat.model.builder.BaseBuilder;
|
||||
import eu.eudat.model.builder.UserBuilder;
|
||||
import eu.eudat.model.deposit.DepositConfiguration;
|
||||
import eu.eudat.query.UserQuery;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.fieldset.BaseFieldSet;
|
||||
import gr.cite.tools.fieldset.FieldSet;
|
||||
import gr.cite.tools.logging.DataLogEntry;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
|
@ -23,7 +15,6 @@ import org.springframework.context.annotation.Scope;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
|
@ -1,12 +1,18 @@
|
|||
package eu.eudat.model.builder.deposit;
|
||||
package eu.eudat.model.builder.commonmodels;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.enums.DmpAccessType;
|
||||
import eu.eudat.commonmodels.models.DmpModel;
|
||||
import eu.eudat.commonmodels.models.DmpUserModel;
|
||||
import eu.eudat.commonmodels.models.FileEnvelopeModel;
|
||||
import eu.eudat.commonmodels.models.description.DescriptionModel;
|
||||
import eu.eudat.commonmodels.models.reference.ReferenceModel;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.*;
|
||||
import eu.eudat.depositinterface.enums.DmpAccessType;
|
||||
import eu.eudat.depositinterface.models.*;
|
||||
import eu.eudat.model.*;
|
||||
import eu.eudat.model.builder.commonmodels.description.DescriptionCommonModelBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.reference.ReferenceCommonModelBuilder;
|
||||
import eu.eudat.query.*;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.query.Ordering;
|
||||
|
@ -25,66 +31,66 @@ import java.util.stream.Collectors;
|
|||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class DmpDepositBuilder extends BaseDepositBuilder<DmpDepositModel, DmpEntity> {
|
||||
public class DmpCommonModelBuilder extends BaseCommonModelBuilder<DmpModel, DmpEntity> {
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
|
||||
private final BuilderFactory builderFactory;
|
||||
private FileEnvelope pdfFile;
|
||||
private FileEnvelope rdaJsonFile;
|
||||
private FileEnvelope supportingFilesZip;
|
||||
private FileEnvelopeModel pdfFile;
|
||||
private FileEnvelopeModel rdaJsonFile;
|
||||
private FileEnvelopeModel supportingFilesZip;
|
||||
private String repositoryId;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
@Autowired
|
||||
public DmpDepositBuilder(ConventionService conventionService,
|
||||
QueryFactory queryFactory,
|
||||
BuilderFactory builderFactory) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpDepositBuilder.class)));
|
||||
public DmpCommonModelBuilder(ConventionService conventionService,
|
||||
QueryFactory queryFactory,
|
||||
BuilderFactory builderFactory) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpCommonModelBuilder.class)));
|
||||
this.queryFactory = queryFactory;
|
||||
this.builderFactory = builderFactory;
|
||||
}
|
||||
|
||||
public DmpDepositBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
public DmpCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DmpDepositBuilder setPdfFile(FileEnvelope pdfFile) {
|
||||
public DmpCommonModelBuilder setPdfFile(FileEnvelopeModel pdfFile) {
|
||||
this.pdfFile = pdfFile;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DmpDepositBuilder setRdaJsonFile(FileEnvelope rdaJsonFile) {
|
||||
public DmpCommonModelBuilder setRdaJsonFile(FileEnvelopeModel rdaJsonFile) {
|
||||
this.rdaJsonFile = rdaJsonFile;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DmpDepositBuilder setSupportingFilesZip(FileEnvelope supportingFilesZip) {
|
||||
public DmpCommonModelBuilder setSupportingFilesZip(FileEnvelopeModel supportingFilesZip) {
|
||||
this.supportingFilesZip = supportingFilesZip;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DmpDepositBuilder setRepositoryId(String repositoryId) {
|
||||
public DmpCommonModelBuilder setRepositoryId(String repositoryId) {
|
||||
this.repositoryId = repositoryId;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<DepositBuilderItemResponse<DmpDepositModel, DmpEntity>> buildInternal(List<DmpEntity> data) throws MyApplicationException {
|
||||
protected List<CommonModelBuilderItemResponse<DmpModel, DmpEntity>> buildInternal(List<DmpEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty()) return new ArrayList<>();
|
||||
|
||||
List<DepositBuilderItemResponse<DmpDepositModel, DmpEntity>> models = new ArrayList<>();
|
||||
List<CommonModelBuilderItemResponse<DmpModel, DmpEntity>> models = new ArrayList<>();
|
||||
|
||||
Map<UUID, List<ReferenceDepositModel>> dmpReferencesMap = this.collectReferences(data);
|
||||
Map<UUID, List<ReferenceModel>> dmpReferencesMap = this.collectReferences(data);
|
||||
|
||||
Map<UUID, List<DmpUserDepositModel>> dmpUsersMap = this.collectDmpUsers(data);
|
||||
Map<UUID, List<DmpUserModel>> dmpUsersMap = this.collectDmpUsers(data);
|
||||
|
||||
Map<UUID, List<DescriptionDepositModel>> descriptionsMap = this.collectDmpDescriptions(data);
|
||||
Map<UUID, List<DescriptionModel>> descriptionsMap = this.collectDmpDescriptions(data);
|
||||
|
||||
for (DmpEntity d : data) {
|
||||
DmpDepositModel m = new DmpDepositModel();
|
||||
DmpModel m = new DmpModel();
|
||||
m.setId(d.getId());
|
||||
m.setLabel(d.getLabel());
|
||||
m.setVersion(d.getVersion());
|
||||
|
@ -104,7 +110,7 @@ public class DmpDepositBuilder extends BaseDepositBuilder<DmpDepositModel, DmpEn
|
|||
if (dmpUsersMap != null && !dmpUsersMap.isEmpty() && dmpUsersMap.containsKey(d.getId())) m.setUsers(dmpUsersMap.get(d.getId()));
|
||||
if (descriptionsMap != null && !descriptionsMap.isEmpty() && descriptionsMap.containsKey(d.getId())) m.setDescriptions(descriptionsMap.get(d.getId()));
|
||||
|
||||
models.add(new DepositBuilderItemResponse<>(m, d));
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
|
@ -128,18 +134,18 @@ public class DmpDepositBuilder extends BaseDepositBuilder<DmpDepositModel, DmpEn
|
|||
return null;
|
||||
}
|
||||
|
||||
private Map<UUID, List<ReferenceDepositModel>> collectReferences(List<DmpEntity> data) throws MyApplicationException {
|
||||
private Map<UUID, List<ReferenceModel>> collectReferences(List<DmpEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty()) return null;
|
||||
this.logger.debug("checking related - {}", DmpReference.class.getSimpleName());
|
||||
|
||||
List<DmpReferenceEntity> dmpReferences = this.queryFactory.query(DmpReferenceQuery.class).isActives(IsActive.Active).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList())).collectAs(new BaseFieldSet().ensure(DmpReference._dmp).ensure(DmpReference._reference));
|
||||
|
||||
Map<UUID, List<ReferenceDepositModel>> itemMap = new HashMap<>();
|
||||
Map<UUID, List<ReferenceModel>> itemMap = new HashMap<>();
|
||||
ReferenceQuery query = this.queryFactory.query(ReferenceQuery.class).authorize(this.authorize).isActive(IsActive.Active).ids(dmpReferences.stream().map(DmpReferenceEntity::getReferenceId).distinct().collect(Collectors.toList()));
|
||||
Map<UUID, ReferenceDepositModel> referenceDepositModelMap = this.builderFactory.builder(ReferenceDepositBuilder.class).authorize(this.authorize).asForeignKey(query, ReferenceEntity::getId);
|
||||
if (referenceDepositModelMap == null) return null;
|
||||
Map<UUID, ReferenceModel> referenceModelMap = this.builderFactory.builder(ReferenceCommonModelBuilder.class).authorize(this.authorize).asForeignKey(query, ReferenceEntity::getId);
|
||||
if (referenceModelMap == null) return null;
|
||||
for (DmpReferenceEntity dmpReference : dmpReferences) {
|
||||
ReferenceDepositModel model =referenceDepositModelMap.getOrDefault(dmpReference.getReferenceId(), null);
|
||||
ReferenceModel model =referenceModelMap.getOrDefault(dmpReference.getReferenceId(), null);
|
||||
if (model == null) continue;;
|
||||
UUID key = dmpReference.getDmpId();
|
||||
if (!itemMap.containsKey(key)) itemMap.put(key, new ArrayList<>());
|
||||
|
@ -149,23 +155,23 @@ public class DmpDepositBuilder extends BaseDepositBuilder<DmpDepositModel, DmpEn
|
|||
}
|
||||
|
||||
|
||||
private Map<UUID, List<DmpUserDepositModel>> collectDmpUsers(List<DmpEntity> data) throws MyApplicationException {
|
||||
private Map<UUID, List<DmpUserModel>> collectDmpUsers(List<DmpEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("checking related - {}", DmpUser.class.getSimpleName());
|
||||
|
||||
Map<UUID, List<DmpUserDepositModel>> itemMap;
|
||||
Map<UUID, List<DmpUserModel>> itemMap;
|
||||
DmpUserQuery query = this.queryFactory.query(DmpUserQuery.class).isActives(IsActive.Active).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList()));
|
||||
itemMap = this.builderFactory.builder(DmpUserDepositBuilder.class).authorize(this.authorize).asMasterKey(query, DmpUserEntity::getDmpId);
|
||||
itemMap = this.builderFactory.builder(DmpUserCommonModelBuilder.class).authorize(this.authorize).asMasterKey(query, DmpUserEntity::getDmpId);
|
||||
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
private Map<UUID, List<DescriptionDepositModel>> collectDmpDescriptions(List<DmpEntity> data) throws MyApplicationException {
|
||||
private Map<UUID, List<DescriptionModel>> collectDmpDescriptions(List<DmpEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty()) return null;
|
||||
this.logger.debug("checking related - {}", Description.class.getSimpleName());
|
||||
|
||||
Map<UUID, List<DescriptionDepositModel>> itemMap;
|
||||
Map<UUID, List<DescriptionModel>> itemMap;
|
||||
DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).isActive(IsActive.Active).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList()));
|
||||
itemMap = this.builderFactory.builder(DescriptionDepositBuilder.class).authorize(this.authorize).asMasterKey(query, DescriptionEntity::getDmpId);
|
||||
itemMap = this.builderFactory.builder(DescriptionCommonModelBuilder.class).authorize(this.authorize).asMasterKey(query, DescriptionEntity::getDmpId);
|
||||
|
||||
return itemMap;
|
||||
}
|
|
@ -1,13 +1,13 @@
|
|||
package eu.eudat.model.builder.deposit;
|
||||
package eu.eudat.model.builder.commonmodels;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.enums.DmpUserRole;
|
||||
import eu.eudat.commonmodels.models.DmpUserModel;
|
||||
import eu.eudat.commonmodels.models.UserModel;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.DmpUserEntity;
|
||||
import eu.eudat.data.UserEntity;
|
||||
import eu.eudat.depositinterface.enums.DmpUserRole;
|
||||
import eu.eudat.depositinterface.models.DmpUserDepositModel;
|
||||
import eu.eudat.depositinterface.models.UserDepositModel;
|
||||
import eu.eudat.query.UserQuery;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
|
@ -24,7 +24,7 @@ import java.util.stream.Collectors;
|
|||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class DmpUserDepositBuilder extends BaseDepositBuilder<DmpUserDepositModel, DmpUserEntity> {
|
||||
public class DmpUserCommonModelBuilder extends BaseCommonModelBuilder<DmpUserModel, DmpUserEntity> {
|
||||
|
||||
private final BuilderFactory builderFactory;
|
||||
|
||||
|
@ -33,51 +33,51 @@ public class DmpUserDepositBuilder extends BaseDepositBuilder<DmpUserDepositMode
|
|||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
@Autowired
|
||||
public DmpUserDepositBuilder(
|
||||
public DmpUserCommonModelBuilder(
|
||||
ConventionService conventionService,
|
||||
BuilderFactory builderFactory, QueryFactory queryFactory) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpUserDepositBuilder.class)));
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpUserCommonModelBuilder.class)));
|
||||
this.builderFactory = builderFactory;
|
||||
this.queryFactory = queryFactory;
|
||||
}
|
||||
|
||||
public DmpUserDepositBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
public DmpUserCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<DepositBuilderItemResponse<DmpUserDepositModel, DmpUserEntity>> buildInternal(List<DmpUserEntity> data) throws MyApplicationException {
|
||||
protected List<CommonModelBuilderItemResponse<DmpUserModel, 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, UserDepositModel> userItemsMap = this.collectUsers(data);
|
||||
Map<UUID, UserModel> userItemsMap = this.collectUsers(data);
|
||||
|
||||
List<DepositBuilderItemResponse<DmpUserDepositModel, DmpUserEntity>> models = new ArrayList<>();
|
||||
List<CommonModelBuilderItemResponse<DmpUserModel, DmpUserEntity>> models = new ArrayList<>();
|
||||
for (DmpUserEntity d : data) {
|
||||
DmpUserDepositModel m = new DmpUserDepositModel();
|
||||
DmpUserModel m = new DmpUserModel();
|
||||
switch (d.getRole()){
|
||||
case User -> m.setRole(DmpUserRole.User);
|
||||
case Owner -> m.setRole(DmpUserRole.Owner);
|
||||
default -> throw new MyApplicationException("unrecognized type " + d.getRole().getValue());
|
||||
}
|
||||
if (userItemsMap != null && userItemsMap.containsKey(d.getUserId())) m.setUser(userItemsMap.get(d.getUserId()));
|
||||
models.add(new DepositBuilderItemResponse<>(m, d));
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
return models;
|
||||
}
|
||||
|
||||
private Map<UUID, UserDepositModel> collectUsers(List<DmpUserEntity> data) throws MyApplicationException {
|
||||
private Map<UUID, UserModel> collectUsers(List<DmpUserEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty())
|
||||
return null;
|
||||
this.logger.debug("checking related - {}", UserDepositModel.class.getSimpleName());
|
||||
this.logger.debug("checking related - {}", UserModel.class.getSimpleName());
|
||||
|
||||
Map<UUID, UserDepositModel> itemMap;
|
||||
Map<UUID, UserModel> itemMap;
|
||||
UserQuery q = this.queryFactory.query(UserQuery.class).isActive(IsActive.Active).authorize(this.authorize).ids(data.stream().map(DmpUserEntity::getUserId).distinct().collect(Collectors.toList()));
|
||||
itemMap = this.builderFactory.builder(UserDepositBuilder.class).authorize(this.authorize).asForeignKey(q, UserEntity::getId);
|
||||
itemMap = this.builderFactory.builder(UserCommonModelBuilder.class).authorize(this.authorize).asForeignKey(q, UserEntity::getId);
|
||||
return itemMap;
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
package eu.eudat.model.builder.commonmodels;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.reference.ReferenceTypeModel;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.ReferenceTypeEntity;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class ReferenceTypeCommonModelBuilder extends BaseCommonModelBuilder<ReferenceTypeModel, ReferenceTypeEntity> {
|
||||
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
@Autowired
|
||||
public ReferenceTypeCommonModelBuilder(
|
||||
ConventionService conventionService) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceTypeCommonModelBuilder.class)));
|
||||
}
|
||||
|
||||
public ReferenceTypeCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<ReferenceTypeModel, ReferenceTypeEntity>> buildInternal(List<ReferenceTypeEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty()) return new ArrayList<>();
|
||||
|
||||
List<CommonModelBuilderItemResponse<ReferenceTypeModel, ReferenceTypeEntity>> models = new ArrayList<>();
|
||||
for (ReferenceTypeEntity d : data) {
|
||||
ReferenceTypeModel m = new ReferenceTypeModel();
|
||||
m.setId(d.getId());
|
||||
m.setCode(d.getCode());
|
||||
m.setName(d.getName());
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
return models;
|
||||
}
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
package eu.eudat.model.builder.deposit;
|
||||
package eu.eudat.model.builder.commonmodels;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.UserModel;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.UserEntity;
|
||||
import eu.eudat.depositinterface.models.UserDepositModel;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -19,32 +19,32 @@ import java.util.Optional;
|
|||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class UserDepositBuilder extends BaseDepositBuilder<UserDepositModel, UserEntity> {
|
||||
public class UserCommonModelBuilder extends BaseCommonModelBuilder<UserModel, UserEntity> {
|
||||
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
@Autowired
|
||||
public UserDepositBuilder(ConventionService conventionService) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(UserDepositBuilder.class)));
|
||||
public UserCommonModelBuilder(ConventionService conventionService) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(UserCommonModelBuilder.class)));
|
||||
}
|
||||
|
||||
public UserDepositBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
public UserCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<DepositBuilderItemResponse<UserDepositModel, UserEntity>> buildInternal(List<UserEntity> data) throws MyApplicationException {
|
||||
protected List<CommonModelBuilderItemResponse<UserModel, 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<DepositBuilderItemResponse<UserDepositModel, UserEntity>> models = new ArrayList<>();
|
||||
List<CommonModelBuilderItemResponse<UserModel, UserEntity>> models = new ArrayList<>();
|
||||
|
||||
for (UserEntity d : data) {
|
||||
UserDepositModel m = new UserDepositModel();
|
||||
UserModel m = new UserModel();
|
||||
m.setName(d.getName());
|
||||
models.add(new DepositBuilderItemResponse<>(m, d));
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
package eu.eudat.model.builder.commonmodels.description;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.description.DescriptionModel;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.DescriptionTemplateModel;
|
||||
import eu.eudat.commons.JsonHandlingService;
|
||||
import eu.eudat.commons.XmlHandlingService;
|
||||
import eu.eudat.commons.types.description.PropertyDefinitionEntity;
|
||||
import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.DescriptionEntity;
|
||||
import eu.eudat.data.DescriptionTemplateEntity;
|
||||
import eu.eudat.model.DescriptionTemplate;
|
||||
import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
|
||||
import eu.eudat.model.builder.commonmodels.descriptiontemplate.DescriptionTemplateCommonModelBuilder;
|
||||
import eu.eudat.query.*;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.fieldset.BaseFieldSet;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class DescriptionCommonModelBuilder extends BaseCommonModelBuilder<DescriptionModel, 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 DescriptionCommonModelBuilder(
|
||||
ConventionService conventionService,
|
||||
QueryFactory queryFactory,
|
||||
BuilderFactory builderFactory, JsonHandlingService jsonHandlingService, XmlHandlingService xmlHandlingService) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionCommonModelBuilder.class)));
|
||||
this.queryFactory = queryFactory;
|
||||
this.builderFactory = builderFactory;
|
||||
this.jsonHandlingService = jsonHandlingService;
|
||||
this.xmlHandlingService = xmlHandlingService;
|
||||
}
|
||||
|
||||
public DescriptionCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<DescriptionModel, 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<>();
|
||||
|
||||
Map<UUID, DescriptionTemplateModel> descriptionTemplates = this.collectDescriptionTemplates(data);
|
||||
|
||||
Map<UUID, DefinitionEntity> definitionEntityMap = this.collectDescriptionTemplateDefinitions(data);
|
||||
|
||||
List<CommonModelBuilderItemResponse<DescriptionModel, DescriptionEntity>> models = new ArrayList<>();
|
||||
for (DescriptionEntity d : data) {
|
||||
DescriptionModel m = new DescriptionModel();
|
||||
m.setLabel(d.getLabel());
|
||||
m.setDescription(d.getDescription());
|
||||
if (descriptionTemplates != null && d.getDescriptionTemplateId() != null && descriptionTemplates.containsKey(d.getDescriptionTemplateId())) m.setDescriptionTemplate(descriptionTemplates.get(d.getDescriptionTemplateId()));
|
||||
if (d.getProperties() != null){
|
||||
//TODO Update with the new logic of property definition
|
||||
PropertyDefinitionEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(PropertyDefinitionEntity.class, d.getProperties());
|
||||
m.setProperties(this.builderFactory.builder(PropertyDefinitionCommonModelBuilder.class).withDefinition(definitionEntityMap != null ? definitionEntityMap.getOrDefault(d.getDescriptionTemplateId(), null) : null).authorize(this.authorize).build(propertyDefinition));
|
||||
}
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
|
||||
private Map<UUID, DefinitionEntity> collectDescriptionTemplateDefinitions(List<DescriptionEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty())
|
||||
return null;
|
||||
this.logger.debug("checking related - {}", DefinitionEntity.class.getSimpleName());
|
||||
|
||||
Map<java.util.UUID, DefinitionEntity> itemMap = new HashMap<>();
|
||||
DescriptionTemplateQuery q = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(this.authorize).ids(data.stream().map(DescriptionEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList()));
|
||||
List<DescriptionTemplateEntity> items = q.collectAs(new BaseFieldSet().ensure(eu.eudat.model.DescriptionTemplate._id).ensure(DescriptionTemplate._definition));
|
||||
for (DescriptionTemplateEntity item : items){
|
||||
DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(DefinitionEntity.class, item.getDefinition());
|
||||
itemMap.put(item.getId(), definition);
|
||||
}
|
||||
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
private Map<UUID, DescriptionTemplateModel> collectDescriptionTemplates(List<DescriptionEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty())
|
||||
return null;
|
||||
this.logger.debug("checking related - {}", DescriptionTemplateModel.class.getSimpleName());
|
||||
|
||||
Map<UUID, DescriptionTemplateModel> itemMap;
|
||||
DescriptionTemplateQuery q = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(this.authorize).ids(data.stream().map(DescriptionEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList()));
|
||||
itemMap = this.builderFactory.builder(DescriptionTemplateCommonModelBuilder.class).authorize(this.authorize).asForeignKey(q, DescriptionTemplateEntity::getId);
|
||||
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package eu.eudat.model.builder.commonmodels.description;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.description.ExternalIdentifierModel;
|
||||
import eu.eudat.commons.types.description.ExternalIdentifierEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class ExternalIdentifierCommonModelBuilder extends BaseCommonModelBuilder<ExternalIdentifierModel, ExternalIdentifierEntity> {
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
@Autowired
|
||||
public ExternalIdentifierCommonModelBuilder(
|
||||
ConventionService conventionService
|
||||
) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(ExternalIdentifierCommonModelBuilder.class)));
|
||||
}
|
||||
|
||||
public ExternalIdentifierCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<ExternalIdentifierModel, ExternalIdentifierEntity>> buildInternal(List<ExternalIdentifierEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty()) return new ArrayList<>();
|
||||
|
||||
List<CommonModelBuilderItemResponse<ExternalIdentifierModel, ExternalIdentifierEntity>> models = new ArrayList<>();
|
||||
for (ExternalIdentifierEntity d : data) {
|
||||
ExternalIdentifierModel m = new ExternalIdentifierModel();
|
||||
m.setIdentifier(d.getIdentifier());
|
||||
m.setType(d.getType());
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
package eu.eudat.model.builder.commonmodels.description;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.description.FieldModel;
|
||||
import eu.eudat.commonmodels.models.reference.ReferenceModel;
|
||||
import eu.eudat.commons.enums.FieldType;
|
||||
import eu.eudat.commons.types.description.FieldEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.ReferenceEntity;
|
||||
import eu.eudat.model.Reference;
|
||||
import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
|
||||
import eu.eudat.model.builder.commonmodels.reference.ReferenceCommonModelBuilder;
|
||||
import eu.eudat.query.ReferenceQuery;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class FieldCommonModelBuilder extends BaseCommonModelBuilder<FieldModel, FieldEntity> {
|
||||
private final BuilderFactory builderFactory;
|
||||
private final QueryFactory queryFactory;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
private eu.eudat.commons.types.descriptiontemplate.FieldEntity fieldEntity;
|
||||
@Autowired
|
||||
public FieldCommonModelBuilder(
|
||||
ConventionService conventionService, BuilderFactory builderFactory, QueryFactory queryFactory
|
||||
) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(FieldCommonModelBuilder.class)));
|
||||
this.builderFactory = builderFactory;
|
||||
this.queryFactory = queryFactory;
|
||||
}
|
||||
|
||||
public FieldCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FieldCommonModelBuilder withFieldEntity(eu.eudat.commons.types.descriptiontemplate.FieldEntity fieldEntity) {
|
||||
this.fieldEntity = fieldEntity;
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<FieldModel, 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<>();
|
||||
|
||||
FieldType fieldType = this.fieldEntity != null && this.fieldEntity.getData() != null ? this.fieldEntity.getData().getFieldType() : FieldType.FREE_TEXT;
|
||||
|
||||
Map<UUID, ReferenceModel> referenceItemsMap = FieldType.isReferenceType(fieldType) ? this.collectReferences(data) : null;
|
||||
|
||||
List<CommonModelBuilderItemResponse<FieldModel, FieldEntity>> models = new ArrayList<>();
|
||||
for (FieldEntity d : data) {
|
||||
FieldModel m = new FieldModel();
|
||||
if (FieldType.isDateType(fieldType)) m.setDateValue(d.getDateValue());
|
||||
if (FieldType.isTextType(fieldType)) m.setTextValue(d.getTextValue());
|
||||
if (FieldType.isTextListType(fieldType)) m.setTextListValue(d.getTextListValue());
|
||||
if (FieldType.isReferenceType(fieldType) && referenceItemsMap != null && d.getTextListValue() != null && !d.getTextListValue().isEmpty()) {
|
||||
m.setReferences(new ArrayList<>());
|
||||
for (UUID referenceId : d.getTextListValue().stream().map(UUID::fromString).toList()){
|
||||
if (referenceItemsMap.containsKey(referenceId)) m.getReferences().add(referenceItemsMap.get(referenceId));
|
||||
}
|
||||
}
|
||||
if (d.getExternalIdentifier() != null && FieldType.isExternalIdentifierType(fieldType)) m.setExternalIdentifier(this.builderFactory.builder(ExternalIdentifierCommonModelBuilder.class).authorize(this.authorize).build(d.getExternalIdentifier()));
|
||||
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
|
||||
private Map<UUID, ReferenceModel> collectReferences(List<FieldEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty())
|
||||
return null;
|
||||
this.logger.debug("checking related - {}", Reference.class.getSimpleName());
|
||||
|
||||
Map<UUID, ReferenceModel> itemMap;
|
||||
|
||||
ReferenceQuery q = this.queryFactory.query(ReferenceQuery.class).authorize(this.authorize).ids(data.stream().map(FieldEntity::getTextListValue).flatMap(List::stream).map(UUID::fromString).distinct().collect(Collectors.toList()));
|
||||
itemMap = this.builderFactory.builder(ReferenceCommonModelBuilder.class).authorize(this.authorize).asForeignKey(q, ReferenceEntity::getId);
|
||||
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package eu.eudat.model.builder.commonmodels.description;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.description.PropertyDefinitionModel;
|
||||
import eu.eudat.commons.types.description.PropertyDefinitionEntity;
|
||||
import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity;
|
||||
import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class PropertyDefinitionCommonModelBuilder extends BaseCommonModelBuilder<PropertyDefinitionModel, PropertyDefinitionEntity> {
|
||||
private final BuilderFactory builderFactory;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
private DefinitionEntity definition;
|
||||
@Autowired
|
||||
public PropertyDefinitionCommonModelBuilder(
|
||||
ConventionService conventionService, BuilderFactory builderFactory
|
||||
) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(PropertyDefinitionCommonModelBuilder.class)));
|
||||
this.builderFactory = builderFactory;
|
||||
}
|
||||
|
||||
public PropertyDefinitionCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertyDefinitionCommonModelBuilder withDefinition(DefinitionEntity definition) {
|
||||
this.definition = definition;
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<PropertyDefinitionModel, PropertyDefinitionEntity>> buildInternal(List<PropertyDefinitionEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty()) return new ArrayList<>();
|
||||
|
||||
List<CommonModelBuilderItemResponse<PropertyDefinitionModel, PropertyDefinitionEntity>> models = new ArrayList<>();
|
||||
for (PropertyDefinitionEntity d : data) {
|
||||
PropertyDefinitionModel m = new PropertyDefinitionModel();
|
||||
m.setFieldSets(new HashMap<>());
|
||||
for (String key : d.getFieldSets().keySet()){
|
||||
FieldSetEntity fieldSetEntity = definition != null ? definition.getFieldSetById(key).stream().findFirst().orElse(null) : null;
|
||||
m.getFieldSets().put(key, this.builderFactory.builder(PropertyDefinitionFieldSetCommonModelBuilder.class).authorize(this.authorize).withFieldSetEntity(fieldSetEntity).build(d.getFieldSets().get(key)));
|
||||
}
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package eu.eudat.model.builder.commonmodels.description;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.description.PropertyDefinitionFieldSetModel;
|
||||
import eu.eudat.commons.types.description.PropertyDefinitionFieldSetEntity;
|
||||
import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class PropertyDefinitionFieldSetCommonModelBuilder extends BaseCommonModelBuilder<PropertyDefinitionFieldSetModel, PropertyDefinitionFieldSetEntity> {
|
||||
private final BuilderFactory builderFactory;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
private FieldSetEntity fieldSetEntity;
|
||||
@Autowired
|
||||
public PropertyDefinitionFieldSetCommonModelBuilder(
|
||||
ConventionService conventionService, BuilderFactory builderFactory
|
||||
) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(PropertyDefinitionFieldSetCommonModelBuilder.class)));
|
||||
this.builderFactory = builderFactory;
|
||||
}
|
||||
|
||||
public PropertyDefinitionFieldSetCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public PropertyDefinitionFieldSetCommonModelBuilder withFieldSetEntity(FieldSetEntity fieldSetEntity) {
|
||||
this.fieldSetEntity = fieldSetEntity;
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<PropertyDefinitionFieldSetModel, PropertyDefinitionFieldSetEntity>> buildInternal(List<PropertyDefinitionFieldSetEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty()) return new ArrayList<>();
|
||||
|
||||
List<CommonModelBuilderItemResponse<PropertyDefinitionFieldSetModel, PropertyDefinitionFieldSetEntity>> models = new ArrayList<>();
|
||||
for (PropertyDefinitionFieldSetEntity d : data) {
|
||||
PropertyDefinitionFieldSetModel m = new PropertyDefinitionFieldSetModel();
|
||||
if (d.getItems() != null) m.setItems(this.builderFactory.builder(PropertyDefinitionFieldSetItemModelCommonModelBuilder.class).withFieldSetEntity(this.fieldSetEntity).authorize(this.authorize).build(d.getItems()));
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package eu.eudat.model.builder.commonmodels.description;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.description.PropertyDefinitionFieldSetItemModel;
|
||||
import eu.eudat.commons.types.description.PropertyDefinitionFieldSetItemEntity;
|
||||
import eu.eudat.commons.types.descriptiontemplate.FieldEntity;
|
||||
import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class PropertyDefinitionFieldSetItemModelCommonModelBuilder extends BaseCommonModelBuilder<PropertyDefinitionFieldSetItemModel, PropertyDefinitionFieldSetItemEntity> {
|
||||
private final BuilderFactory builderFactory;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
private FieldSetEntity fieldSetEntity;
|
||||
@Autowired
|
||||
public PropertyDefinitionFieldSetItemModelCommonModelBuilder(
|
||||
ConventionService conventionService, BuilderFactory builderFactory
|
||||
) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(PropertyDefinitionFieldSetItemModelCommonModelBuilder.class)));
|
||||
this.builderFactory = builderFactory;
|
||||
}
|
||||
|
||||
public PropertyDefinitionFieldSetItemModelCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public PropertyDefinitionFieldSetItemModelCommonModelBuilder withFieldSetEntity(FieldSetEntity fieldSetEntity) {
|
||||
this.fieldSetEntity = fieldSetEntity;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<PropertyDefinitionFieldSetItemModel, PropertyDefinitionFieldSetItemEntity>> buildInternal(List<PropertyDefinitionFieldSetItemEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty()) return new ArrayList<>();
|
||||
|
||||
List<CommonModelBuilderItemResponse<PropertyDefinitionFieldSetItemModel, PropertyDefinitionFieldSetItemEntity>> models = new ArrayList<>();
|
||||
for (PropertyDefinitionFieldSetItemEntity d : data) {
|
||||
PropertyDefinitionFieldSetItemModel m = new PropertyDefinitionFieldSetItemModel();
|
||||
|
||||
m.setComment(d.getComment());
|
||||
m.setOrdinal(d.getOrdinal());
|
||||
if (d.getFields() != null && !d.getFields().isEmpty()) {
|
||||
m.setFields(new HashMap<>());
|
||||
for (String key : d.getFields().keySet()){
|
||||
FieldEntity fieldEntity = fieldSetEntity != null ? fieldSetEntity.getAllField().stream().findFirst().orElse(null) : null;
|
||||
m.getFields().put(key, this.builderFactory.builder(FieldCommonModelBuilder.class).authorize(this.authorize).withFieldEntity(fieldEntity).build(d.getFields().get(key)));
|
||||
}
|
||||
}
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package eu.eudat.model.builder.commonmodels.descriptiontemplate;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.DefinitionModel;
|
||||
import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
|
||||
import eu.eudat.model.builder.descriptiontemplatedefinition.PageBuilder;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class DefinitionCommonModelBuilder extends BaseCommonModelBuilder<DefinitionModel, DefinitionEntity> {
|
||||
private final BuilderFactory builderFactory;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
@Autowired
|
||||
public DefinitionCommonModelBuilder(
|
||||
ConventionService conventionService, BuilderFactory builderFactory
|
||||
) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(DefinitionCommonModelBuilder.class)));
|
||||
this.builderFactory = builderFactory;
|
||||
}
|
||||
|
||||
public DefinitionCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<DefinitionModel, DefinitionEntity>> buildInternal(List<DefinitionEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty()) return new ArrayList<>();
|
||||
|
||||
List<CommonModelBuilderItemResponse<DefinitionModel, DefinitionEntity>> models = new ArrayList<>();
|
||||
for (DefinitionEntity d : data) {
|
||||
DefinitionModel m = new DefinitionModel();
|
||||
if (d.getPages() != null) m.setPages(this.builderFactory.builder(PageCommonModelBuilder.class).authorize(this.authorize).build(d.getPages()));
|
||||
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package eu.eudat.model.builder.commonmodels.descriptiontemplate;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.DescriptionTemplateModel;
|
||||
import eu.eudat.commons.JsonHandlingService;
|
||||
import eu.eudat.commons.XmlHandlingService;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.DescriptionTemplateEntity;
|
||||
import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class DescriptionTemplateCommonModelBuilder extends BaseCommonModelBuilder<DescriptionTemplateModel, DescriptionTemplateEntity> {
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
|
||||
private final BuilderFactory builderFactory;
|
||||
private final JsonHandlingService jsonHandlingService;
|
||||
|
||||
private final XmlHandlingService xmlHandlingService;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
@Autowired
|
||||
public DescriptionTemplateCommonModelBuilder(
|
||||
ConventionService conventionService,
|
||||
QueryFactory queryFactory,
|
||||
BuilderFactory builderFactory, JsonHandlingService jsonHandlingService, XmlHandlingService xmlHandlingService) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionTemplateCommonModelBuilder.class)));
|
||||
this.queryFactory = queryFactory;
|
||||
this.builderFactory = builderFactory;
|
||||
this.jsonHandlingService = jsonHandlingService;
|
||||
this.xmlHandlingService = xmlHandlingService;
|
||||
}
|
||||
|
||||
public DescriptionTemplateCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<DescriptionTemplateModel, 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<>();
|
||||
|
||||
List<CommonModelBuilderItemResponse<DescriptionTemplateModel, DescriptionTemplateEntity>> models = new ArrayList<>();
|
||||
for (DescriptionTemplateEntity d : data) {
|
||||
DescriptionTemplateModel m = new DescriptionTemplateModel();
|
||||
m.setId(d.getId());
|
||||
m.setLabel(d.getLabel());
|
||||
m.setDescription(d.getDescription());
|
||||
m.setGroupId(d.getGroupId());
|
||||
m.setVersion(d.getVersion());
|
||||
m.setLanguage(d.getLanguage());
|
||||
|
||||
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
package eu.eudat.model.builder.commonmodels.descriptiontemplate;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.FieldModel;
|
||||
import eu.eudat.commons.enums.FieldValidationType;
|
||||
import eu.eudat.commons.types.descriptiontemplate.FieldEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
|
||||
import eu.eudat.service.fielddatahelper.FieldDataHelperService;
|
||||
import eu.eudat.service.fielddatahelper.FieldDataHelperServiceProvider;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class FieldCommonModelBuilder extends BaseCommonModelBuilder<FieldModel, FieldEntity> {
|
||||
private final BuilderFactory builderFactory;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
private final FieldDataHelperServiceProvider fieldDataHelperServiceProvider;
|
||||
@Autowired
|
||||
public FieldCommonModelBuilder(
|
||||
ConventionService conventionService, BuilderFactory builderFactory, FieldDataHelperServiceProvider fieldDataHelperServiceProvider
|
||||
) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(FieldCommonModelBuilder.class)));
|
||||
this.builderFactory = builderFactory;
|
||||
this.fieldDataHelperServiceProvider = fieldDataHelperServiceProvider;
|
||||
}
|
||||
|
||||
public FieldCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<FieldModel, 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<CommonModelBuilderItemResponse<FieldModel, FieldEntity>> models = new ArrayList<>();
|
||||
for (FieldEntity d : data) {
|
||||
FieldModel m = new FieldModel();
|
||||
m.setId(d.getId());
|
||||
m.setOrdinal(d.getOrdinal());
|
||||
m.setNumbering(d.getNumbering());
|
||||
m.setSchematics(d.getSchematics());
|
||||
m.setDefaultValue(d.getDefaultValue());
|
||||
m.setIncludeInExport(d.getIncludeInExport());
|
||||
if (!this.conventionService.isListNullOrEmpty(d.getValidations())){
|
||||
m.setValidations(new ArrayList<>());
|
||||
for (FieldValidationType fieldValidationType : d.getValidations()) {
|
||||
switch (fieldValidationType){
|
||||
case Url -> m.getValidations().add(eu.eudat.commonmodels.enums.FieldValidationType.Url);
|
||||
case None -> m.getValidations().add(eu.eudat.commonmodels.enums.FieldValidationType.None);
|
||||
case Required -> m.getValidations().add(eu.eudat.commonmodels.enums.FieldValidationType.Required);
|
||||
default -> throw new MyApplicationException("unrecognized type " + fieldValidationType);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
m.setNumbering(d.getNumbering());
|
||||
m.setNumbering(d.getNumbering());
|
||||
if (d.getVisibilityRules() != null) m.setVisibilityRules(this.builderFactory.builder(RuleCommonModelBuilder.class).authorize(this.authorize).build(d.getVisibilityRules()));
|
||||
if (d.getData() != null){
|
||||
FieldDataHelperService fieldDataHelperService = this.fieldDataHelperServiceProvider.get(d.getData().getFieldType());
|
||||
m.setData(fieldDataHelperService.buildCommonModelOne(d.getData(), this.authorize));
|
||||
}
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package eu.eudat.model.builder.commonmodels.descriptiontemplate;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.FieldSetModel;
|
||||
import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
|
||||
import eu.eudat.model.builder.descriptiontemplatedefinition.FieldBuilder;
|
||||
import eu.eudat.model.builder.descriptiontemplatedefinition.MultiplicityBuilder;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class FieldSetCommonModelBuilder extends BaseCommonModelBuilder<FieldSetModel, FieldSetEntity> {
|
||||
private final BuilderFactory builderFactory;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
@Autowired
|
||||
public FieldSetCommonModelBuilder(
|
||||
ConventionService conventionService, BuilderFactory builderFactory
|
||||
) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(FieldSetCommonModelBuilder.class)));
|
||||
this.builderFactory = builderFactory;
|
||||
}
|
||||
|
||||
public FieldSetCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<FieldSetModel, FieldSetEntity>> buildInternal(List<FieldSetEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty()) return new ArrayList<>();
|
||||
|
||||
List<CommonModelBuilderItemResponse<FieldSetModel, FieldSetEntity>> models = new ArrayList<>();
|
||||
for (FieldSetEntity d : data) {
|
||||
FieldSetModel m = new FieldSetModel();
|
||||
m.setId(d.getId());
|
||||
m.setOrdinal(d.getOrdinal());
|
||||
m.setTitle(d.getTitle());
|
||||
m.setNumbering(d.getNumbering());
|
||||
m.setDescription(d.getDescription());
|
||||
m.setExtendedDescription(d.getExtendedDescription());
|
||||
m.setAdditionalInformation(d.getAdditionalInformation());
|
||||
m.setHasCommentField(d.getHasCommentField());
|
||||
if (d.getMultiplicity() != null) m.setMultiplicity(this.builderFactory.builder(MultiplicityCommonModelBuilder.class).authorize(this.authorize).build(d.getMultiplicity()));
|
||||
if (d.getFields() != null) m.setFields(this.builderFactory.builder(FieldCommonModelBuilder.class).authorize(this.authorize).build(d.getFields()));
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package eu.eudat.model.builder.commonmodels.descriptiontemplate;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.MultiplicityModel;
|
||||
import eu.eudat.commons.types.descriptiontemplate.MultiplicityEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
|
||||
import eu.eudat.model.descriptiontemplatedefinition.Multiplicity;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class MultiplicityCommonModelBuilder extends BaseCommonModelBuilder<MultiplicityModel, MultiplicityEntity> {
|
||||
private final BuilderFactory builderFactory;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
@Autowired
|
||||
public MultiplicityCommonModelBuilder(
|
||||
ConventionService conventionService, BuilderFactory builderFactory
|
||||
) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(MultiplicityCommonModelBuilder.class)));
|
||||
this.builderFactory = builderFactory;
|
||||
}
|
||||
|
||||
public MultiplicityCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<MultiplicityModel, MultiplicityEntity>> buildInternal(List<MultiplicityEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty()) return new ArrayList<>();
|
||||
|
||||
List<CommonModelBuilderItemResponse<MultiplicityModel, MultiplicityEntity>> models = new ArrayList<>();
|
||||
for (MultiplicityEntity d : data) {
|
||||
MultiplicityModel m = new MultiplicityModel();
|
||||
m.setMin(d.getMin());
|
||||
m.setMax(d.getMax());
|
||||
m.setPlaceholder(d.getPlaceholder());
|
||||
m.setTableView(d.getTableView());
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package eu.eudat.model.builder.commonmodels.descriptiontemplate;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.PageModel;
|
||||
import eu.eudat.commons.types.descriptiontemplate.PageEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
|
||||
import eu.eudat.model.builder.descriptiontemplatedefinition.SectionBuilder;
|
||||
import eu.eudat.model.descriptiontemplatedefinition.Page;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class PageCommonModelBuilder extends BaseCommonModelBuilder<PageModel, PageEntity> {
|
||||
private final BuilderFactory builderFactory;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
@Autowired
|
||||
public PageCommonModelBuilder(
|
||||
ConventionService conventionService, BuilderFactory builderFactory
|
||||
) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(PageCommonModelBuilder.class)));
|
||||
this.builderFactory = builderFactory;
|
||||
}
|
||||
|
||||
public PageCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<PageModel, PageEntity>> buildInternal(List<PageEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty()) return new ArrayList<>();
|
||||
|
||||
List<CommonModelBuilderItemResponse<PageModel, PageEntity>> models = new ArrayList<>();
|
||||
for (PageEntity d : data) {
|
||||
PageModel m = new PageModel();
|
||||
m.setId(d.getId());
|
||||
m.setOrdinal(d.getOrdinal());
|
||||
m.setTitle(d.getTitle());
|
||||
m.setSections(this.builderFactory.builder(SectionCommonModelBuilder.class).authorize(this.authorize).build(d.getSections()));
|
||||
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package eu.eudat.model.builder.commonmodels.descriptiontemplate;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.RuleModel;
|
||||
import eu.eudat.commons.types.descriptiontemplate.RuleEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class RuleCommonModelBuilder extends BaseCommonModelBuilder<RuleModel, RuleEntity> {
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
@Autowired
|
||||
public RuleCommonModelBuilder(
|
||||
ConventionService conventionService
|
||||
) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(RuleCommonModelBuilder.class)));
|
||||
}
|
||||
|
||||
public RuleCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<RuleModel, RuleEntity>> buildInternal(List<RuleEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty()) return new ArrayList<>();
|
||||
|
||||
List<CommonModelBuilderItemResponse<RuleModel, RuleEntity>> models = new ArrayList<>();
|
||||
for (RuleEntity d : data) {
|
||||
RuleModel m = new RuleModel();
|
||||
m.setTarget(d.getTarget());
|
||||
m.setValue(d.getValue());
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package eu.eudat.model.builder.commonmodels.descriptiontemplate;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.SectionModel;
|
||||
import eu.eudat.commons.types.descriptiontemplate.SectionEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
|
||||
import eu.eudat.model.builder.descriptiontemplatedefinition.FieldSetBuilder;
|
||||
import eu.eudat.model.builder.descriptiontemplatedefinition.SectionBuilder;
|
||||
import eu.eudat.model.descriptiontemplatedefinition.Section;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class SectionCommonModelBuilder extends BaseCommonModelBuilder<SectionModel, SectionEntity> {
|
||||
private final BuilderFactory builderFactory;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
@Autowired
|
||||
public SectionCommonModelBuilder(
|
||||
ConventionService conventionService, BuilderFactory builderFactory
|
||||
) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(SectionCommonModelBuilder.class)));
|
||||
this.builderFactory = builderFactory;
|
||||
}
|
||||
|
||||
public SectionCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<SectionModel, SectionEntity>> buildInternal(List<SectionEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty()) return new ArrayList<>();
|
||||
|
||||
List<CommonModelBuilderItemResponse<SectionModel, SectionEntity>> models = new ArrayList<>();
|
||||
for (SectionEntity d : data) {
|
||||
SectionModel m = new SectionModel();
|
||||
m.setId(d.getId());
|
||||
m.setDescription(d.getDescription());
|
||||
m.setOrdinal(d.getOrdinal());
|
||||
m.setDefaultVisibility(d.isDefaultVisibility());
|
||||
m.setMultiplicity(d.getMultiplicity());
|
||||
m.setNumbering(d.getNumbering());
|
||||
m.setTitle(d.getTitle());
|
||||
m.setExtendedDescription(d.getExtendedDescription());
|
||||
if (d.getSections() != null) m.setSections(this.builderFactory.builder(SectionCommonModelBuilder.class).authorize(this.authorize).build(d.getSections()));
|
||||
if (d.getFieldSets() != null) m.setFieldSets(this.builderFactory.builder(FieldSetCommonModelBuilder.class).authorize(this.authorize).build(d.getFieldSets()));
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.enums.FieldType;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.BaseFieldDataModel;
|
||||
import eu.eudat.commons.types.descriptiontemplate.fielddata.BaseFieldDataEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public abstract class BaseFieldDataCommonModelBuilder<Model extends BaseFieldDataModel, Entity extends BaseFieldDataEntity> extends BaseCommonModelBuilder<Model, Entity> {
|
||||
protected EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
@Autowired
|
||||
public BaseFieldDataCommonModelBuilder(
|
||||
ConventionService conventionService,
|
||||
LoggerService logger) {
|
||||
super(conventionService, logger);
|
||||
}
|
||||
|
||||
public BaseFieldDataCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
protected abstract Model getInstance();
|
||||
|
||||
protected abstract void buildChild(Entity d, Model m);
|
||||
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<Model, Entity>> buildInternal(List<Entity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty()) return new ArrayList<>();
|
||||
|
||||
List<CommonModelBuilderItemResponse<Model, Entity>> models = new ArrayList<>();
|
||||
for (Entity d : data) {
|
||||
Model m = this.getInstance();
|
||||
m.setLabel(d.getLabel());
|
||||
switch (d.getFieldType()){
|
||||
case SELECT -> m.setFieldType(FieldType.SELECT);
|
||||
case BOOLEAN_DECISION -> m.setFieldType(FieldType.BOOLEAN_DECISION);
|
||||
case RADIO_BOX -> m.setFieldType(FieldType.RADIO_BOX);
|
||||
case INTERNAL_ENTRIES_DMPS -> m.setFieldType(FieldType.INTERNAL_ENTRIES_DMPS);
|
||||
case INTERNAL_ENTRIES_DESCRIPTIONS -> m.setFieldType(FieldType.INTERNAL_ENTRIES_DESCRIPTIONS);
|
||||
case CHECK_BOX -> m.setFieldType(FieldType.CHECK_BOX);
|
||||
case FREE_TEXT -> m.setFieldType(FieldType.FREE_TEXT);
|
||||
case TEXT_AREA -> m.setFieldType(FieldType.TEXT_AREA);
|
||||
case RICH_TEXT_AREA -> m.setFieldType(FieldType.RICH_TEXT_AREA);
|
||||
case UPLOAD -> m.setFieldType(FieldType.UPLOAD);
|
||||
case DATE_PICKER -> m.setFieldType(FieldType.DATE_PICKER);
|
||||
case TAGS -> m.setFieldType(FieldType.TAGS);
|
||||
case REFERENCE_TYPES -> m.setFieldType(FieldType.REFERENCE_TYPES);
|
||||
case DATASET_IDENTIFIER -> m.setFieldType(FieldType.DATASET_IDENTIFIER);
|
||||
case CURRENCY -> m.setFieldType(FieldType.CURRENCY);
|
||||
case VALIDATION -> m.setFieldType(FieldType.VALIDATION);
|
||||
default -> throw new MyApplicationException("unrecognized type " + d.getFieldType());
|
||||
}
|
||||
this.buildChild(d, m);
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata;
|
||||
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.LabelAndMultiplicityDataModel;
|
||||
import eu.eudat.commons.types.descriptiontemplate.fielddata.LabelAndMultiplicityDataEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class LabelAndMultiplicityDataCommonModelBuilder extends BaseFieldDataCommonModelBuilder<LabelAndMultiplicityDataModel, LabelAndMultiplicityDataEntity> {
|
||||
@Autowired
|
||||
public LabelAndMultiplicityDataCommonModelBuilder(
|
||||
ConventionService conventionService
|
||||
) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(LabelAndMultiplicityDataCommonModelBuilder.class)));
|
||||
}
|
||||
|
||||
protected LabelAndMultiplicityDataModel getInstance() {
|
||||
return new LabelAndMultiplicityDataModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildChild(LabelAndMultiplicityDataEntity d, LabelAndMultiplicityDataModel m) {
|
||||
m.setMultipleSelect(d.getMultipleSelect());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata;
|
||||
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.LabelDataModel;
|
||||
import eu.eudat.commons.types.descriptiontemplate.fielddata.LabelDataEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class LabelDataCommonModelBuilder extends BaseFieldDataCommonModelBuilder<LabelDataModel, LabelDataEntity> {
|
||||
@Autowired
|
||||
public LabelDataCommonModelBuilder(
|
||||
ConventionService conventionService
|
||||
) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(LabelDataCommonModelBuilder.class)));
|
||||
}
|
||||
|
||||
protected LabelDataModel getInstance() {
|
||||
return new LabelDataModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildChild(LabelDataEntity d, LabelDataModel m) {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.RadioBoxDataModel;
|
||||
import eu.eudat.commons.types.descriptiontemplate.fielddata.RadioBoxDataEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class RadioBoxDataCommonModelBuilder extends BaseFieldDataCommonModelBuilder<RadioBoxDataModel, RadioBoxDataEntity> {
|
||||
private final BuilderFactory builderFactory;
|
||||
@Autowired
|
||||
public RadioBoxDataCommonModelBuilder(
|
||||
ConventionService conventionService, BuilderFactory builderFactory
|
||||
) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(RadioBoxDataCommonModelBuilder.class)));
|
||||
this.builderFactory = builderFactory;
|
||||
}
|
||||
|
||||
protected RadioBoxDataModel getInstance() {
|
||||
return new RadioBoxDataModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildChild(RadioBoxDataEntity d, RadioBoxDataModel m) {
|
||||
m.setOptions(this.builderFactory.builder(RadioBoxOptionCommonModelBuilder.class).authorize(this.authorize).build(d.getOptions()));
|
||||
}
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public static class RadioBoxOptionCommonModelBuilder extends BaseCommonModelBuilder<RadioBoxDataModel.RadioBoxOptionModel, RadioBoxDataEntity.RadioBoxDataOptionEntity> {
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
@Autowired
|
||||
public RadioBoxOptionCommonModelBuilder(
|
||||
ConventionService conventionService
|
||||
) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(RadioBoxOptionCommonModelBuilder.class)));
|
||||
}
|
||||
|
||||
public RadioBoxOptionCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<RadioBoxDataModel.RadioBoxOptionModel, RadioBoxDataEntity.RadioBoxDataOptionEntity>> buildInternal(List<RadioBoxDataEntity.RadioBoxDataOptionEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty()) return new ArrayList<>();
|
||||
|
||||
List<CommonModelBuilderItemResponse<RadioBoxDataModel.RadioBoxOptionModel, RadioBoxDataEntity.RadioBoxDataOptionEntity>> models = new ArrayList<>();
|
||||
for (RadioBoxDataEntity.RadioBoxDataOptionEntity d : data) {
|
||||
RadioBoxDataModel.RadioBoxOptionModel m = new RadioBoxDataModel.RadioBoxOptionModel();
|
||||
m.setLabel(d.getLabel());
|
||||
m.setValue(d.getValue());
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata;
|
||||
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.ReferenceTypeDataModel;
|
||||
import eu.eudat.commons.types.descriptiontemplate.fielddata.ReferenceTypeDataEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.model.builder.ReferenceTypeBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.ReferenceTypeCommonModelBuilder;
|
||||
import eu.eudat.query.ReferenceTypeQuery;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class ReferenceTypeDataCommonModelBuilder extends BaseFieldDataCommonModelBuilder<ReferenceTypeDataModel, ReferenceTypeDataEntity> {
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
private final BuilderFactory builderFactory;
|
||||
@Autowired
|
||||
public ReferenceTypeDataCommonModelBuilder(
|
||||
ConventionService conventionService, QueryFactory queryFactory, BuilderFactory builderFactory
|
||||
) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceTypeDataCommonModelBuilder.class)));
|
||||
this.queryFactory = queryFactory;
|
||||
this.builderFactory = builderFactory;
|
||||
}
|
||||
|
||||
protected ReferenceTypeDataModel getInstance() {
|
||||
return new ReferenceTypeDataModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildChild(ReferenceTypeDataEntity d, ReferenceTypeDataModel m) {
|
||||
if (d.getReferenceTypeId() != null) m.setReferenceType(this.builderFactory.builder(ReferenceTypeCommonModelBuilder.class).build(this.queryFactory.query(ReferenceTypeQuery.class).ids(d.getReferenceTypeId()).first())); //TODO: Optimize
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.SelectDataModel;
|
||||
import eu.eudat.commons.types.descriptiontemplate.fielddata.SelectDataEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class SelectDataCommonModelBuilder extends BaseFieldDataCommonModelBuilder<SelectDataModel, SelectDataEntity> {
|
||||
private final BuilderFactory builderFactory;
|
||||
@Autowired
|
||||
public SelectDataCommonModelBuilder(
|
||||
ConventionService conventionService, BuilderFactory builderFactory
|
||||
) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(SelectDataCommonModelBuilder.class)));
|
||||
this.builderFactory = builderFactory;
|
||||
}
|
||||
|
||||
protected SelectDataModel getInstance() {
|
||||
return new SelectDataModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildChild(SelectDataEntity d, SelectDataModel m) {
|
||||
m.setOptions(this.builderFactory.builder(SelectOptionCommonModelBuilder.class).authorize(this.authorize).build(d.getOptions()));
|
||||
}
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public static class SelectOptionCommonModelBuilder extends BaseCommonModelBuilder<SelectDataModel.OptionModel, SelectDataEntity.OptionEntity> {
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
@Autowired
|
||||
public SelectOptionCommonModelBuilder(
|
||||
ConventionService conventionService
|
||||
) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(SelectOptionCommonModelBuilder.class)));
|
||||
}
|
||||
|
||||
public SelectOptionCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<SelectDataModel.OptionModel, SelectDataEntity.OptionEntity>> buildInternal(List<SelectDataEntity.OptionEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty()) return new ArrayList<>();
|
||||
|
||||
List<CommonModelBuilderItemResponse<SelectDataModel.OptionModel, SelectDataEntity.OptionEntity>> models = new ArrayList<>();
|
||||
for (SelectDataEntity.OptionEntity d : data) {
|
||||
SelectDataModel.OptionModel m = new SelectDataModel.OptionModel();
|
||||
m.setLabel(d.getLabel());
|
||||
m.setValue(d.getValue());
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.UploadDataModel;
|
||||
import eu.eudat.commons.types.descriptiontemplate.fielddata.UploadDataEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class UploadDataCommonModelBuilder extends BaseFieldDataCommonModelBuilder<UploadDataModel, UploadDataEntity> {
|
||||
private final BuilderFactory builderFactory;
|
||||
@Autowired
|
||||
public UploadDataCommonModelBuilder(
|
||||
ConventionService conventionService, BuilderFactory builderFactory
|
||||
) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(UploadDataCommonModelBuilder.class)));
|
||||
this.builderFactory = builderFactory;
|
||||
}
|
||||
|
||||
protected UploadDataModel getInstance() {
|
||||
return new UploadDataModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildChild(UploadDataEntity d, UploadDataModel m) {
|
||||
m.setTypes(this.builderFactory.builder(UploadOptionCommonModelBuilder.class).authorize(this.authorize).build(d.getTypes()));
|
||||
}
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public static class UploadOptionCommonModelBuilder extends BaseCommonModelBuilder<UploadDataModel.UploadOptionModel, UploadDataEntity.UploadDataOptionEntity> {
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
@Autowired
|
||||
public UploadOptionCommonModelBuilder(
|
||||
ConventionService conventionService
|
||||
) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(UploadOptionCommonModelBuilder.class)));
|
||||
}
|
||||
|
||||
public UploadOptionCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<UploadDataModel.UploadOptionModel, UploadDataEntity.UploadDataOptionEntity>> buildInternal(List<UploadDataEntity.UploadDataOptionEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("building for {}", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty()) return new ArrayList<>();
|
||||
|
||||
List<CommonModelBuilderItemResponse<UploadDataModel.UploadOptionModel, UploadDataEntity.UploadDataOptionEntity>> models = new ArrayList<>();
|
||||
for (UploadDataEntity.UploadDataOptionEntity d : data) {
|
||||
UploadDataModel.UploadOptionModel m = new UploadDataModel.UploadOptionModel();
|
||||
m.setLabel(d.getLabel());
|
||||
m.setValue(d.getValue());
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
package eu.eudat.model.builder.commonmodels.reference;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.enums.ReferenceSourceType;
|
||||
import eu.eudat.commonmodels.models.reference.ReferenceModel;
|
||||
import eu.eudat.commonmodels.models.reference.ReferenceTypeModel;
|
||||
import eu.eudat.commons.XmlHandlingService;
|
||||
import eu.eudat.commons.types.reference.DefinitionEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.ReferenceTypeEntity;
|
||||
import eu.eudat.data.ReferenceEntity;
|
||||
import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
|
||||
import eu.eudat.model.builder.commonmodels.ReferenceTypeCommonModelBuilder;
|
||||
import eu.eudat.query.ReferenceTypeQuery;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class ReferenceCommonModelBuilder extends BaseCommonModelBuilder<ReferenceModel, ReferenceEntity> {
|
||||
|
||||
private final BuilderFactory builderFactory;
|
||||
private final QueryFactory queryFactory;
|
||||
private final XmlHandlingService xmlHandlingService;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
@Autowired
|
||||
public ReferenceCommonModelBuilder(
|
||||
ConventionService conventionService,
|
||||
BuilderFactory builderFactory, QueryFactory queryFactory, XmlHandlingService xmlHandlingService) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceCommonModelBuilder.class)));
|
||||
this.builderFactory = builderFactory;
|
||||
this.queryFactory = queryFactory;
|
||||
this.xmlHandlingService = xmlHandlingService;
|
||||
}
|
||||
|
||||
public ReferenceCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<ReferenceModel, 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<>();
|
||||
|
||||
Map<UUID, ReferenceTypeModel> typeMap = this.collectReferenceTypes(data);
|
||||
List<CommonModelBuilderItemResponse<ReferenceModel, ReferenceEntity>> models = new ArrayList<>();
|
||||
for (ReferenceEntity d : data) {
|
||||
ReferenceModel m = new ReferenceModel();
|
||||
m.setId(d.getId());
|
||||
m.setLabel(d.getLabel());
|
||||
if (d.getDefinition() != null){
|
||||
DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(DefinitionEntity.class, d.getDefinition());
|
||||
m.setDefinition(this.builderFactory.builder(ReferenceDefinitionCommonModelBuilder.class).authorize(this.authorize).build(definition));
|
||||
}
|
||||
m.setReference(d.getReference());
|
||||
m.setAbbreviation(d.getAbbreviation());
|
||||
m.setDescription(d.getDescription());
|
||||
m.setSource(d.getSource());
|
||||
switch (d.getSourceType()){
|
||||
case Internal -> m.setSourceType(ReferenceSourceType.Internal);
|
||||
case External -> m.setSourceType(ReferenceSourceType.External);
|
||||
default -> throw new MyApplicationException("unrecognized type " + d.getSourceType().getValue());
|
||||
}
|
||||
if (typeMap != null && d.getTypeId() != null && typeMap.containsKey(d.getTypeId())) m.setType(typeMap.get(d.getTypeId()));
|
||||
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
return models;
|
||||
}
|
||||
|
||||
|
||||
private Map<UUID, ReferenceTypeModel> collectReferenceTypes(List<ReferenceEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty())
|
||||
return null;
|
||||
this.logger.debug("checking related - {}", ReferenceTypeModel.class.getSimpleName());
|
||||
|
||||
Map<UUID, ReferenceTypeModel> itemMap;
|
||||
ReferenceTypeQuery q = this.queryFactory.query(ReferenceTypeQuery.class).authorize(this.authorize).ids(data.stream().map(ReferenceEntity::getTypeId).distinct().collect(Collectors.toList()));
|
||||
itemMap = this.builderFactory.builder(ReferenceTypeCommonModelBuilder.class).authorize(this.authorize).asForeignKey(q, ReferenceTypeEntity::getId);
|
||||
|
||||
return itemMap;
|
||||
}
|
||||
}
|
|
@ -1,9 +1,11 @@
|
|||
package eu.eudat.model.builder.deposit;
|
||||
package eu.eudat.model.builder.commonmodels.reference;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.reference.ReferenceDefinitionModel;
|
||||
import eu.eudat.commons.types.reference.DefinitionEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.depositinterface.models.reference.DefinitionDepositModel;
|
||||
import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
|
@ -15,33 +17,33 @@ import org.springframework.context.annotation.Scope;
|
|||
import java.util.*;
|
||||
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class ReferenceDefinitionDepositBuilder extends BaseDepositBuilder<DefinitionDepositModel, DefinitionEntity> {
|
||||
public class ReferenceDefinitionCommonModelBuilder extends BaseCommonModelBuilder<ReferenceDefinitionModel, DefinitionEntity> {
|
||||
|
||||
private final BuilderFactory builderFactory;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
@Autowired
|
||||
public ReferenceDefinitionDepositBuilder(
|
||||
public ReferenceDefinitionCommonModelBuilder(
|
||||
ConventionService conventionService, BuilderFactory builderFactory) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceDefinitionDepositBuilder.class)));
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceDefinitionCommonModelBuilder.class)));
|
||||
this.builderFactory = builderFactory;
|
||||
}
|
||||
|
||||
public ReferenceDefinitionDepositBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
public ReferenceDefinitionCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<DepositBuilderItemResponse<DefinitionDepositModel, DefinitionEntity>> buildInternal(List<DefinitionEntity> data) throws MyApplicationException {
|
||||
protected List<CommonModelBuilderItemResponse<ReferenceDefinitionModel, 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<DepositBuilderItemResponse<DefinitionDepositModel, DefinitionEntity>> models = new ArrayList<>();
|
||||
List<CommonModelBuilderItemResponse<ReferenceDefinitionModel, DefinitionEntity>> models = new ArrayList<>();
|
||||
for (DefinitionEntity d : data) {
|
||||
DefinitionDepositModel m = new DefinitionDepositModel();
|
||||
if (d.getFields() != null) m.setFields(this.builderFactory.builder(ReferenceFieldDepositBuilder.class).authorize(this.authorize).build(d.getFields()));
|
||||
models.add(new DepositBuilderItemResponse<>(m, d));
|
||||
ReferenceDefinitionModel m = new ReferenceDefinitionModel();
|
||||
if (d.getFields() != null) m.setFields(this.builderFactory.builder(ReferenceFieldCommonModelBuilder.class).authorize(this.authorize).build(d.getFields()));
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
return models;
|
|
@ -1,9 +1,11 @@
|
|||
package eu.eudat.model.builder.deposit;
|
||||
package eu.eudat.model.builder.commonmodels.reference;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.reference.ReferenceFieldModel;
|
||||
import eu.eudat.commons.types.reference.FieldEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.depositinterface.models.reference.FieldDepositModel;
|
||||
import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -17,33 +19,33 @@ import java.util.List;
|
|||
import java.util.Optional;
|
||||
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class ReferenceFieldDepositBuilder extends BaseDepositBuilder<FieldDepositModel, FieldEntity> {
|
||||
public class ReferenceFieldCommonModelBuilder extends BaseCommonModelBuilder<ReferenceFieldModel, FieldEntity> {
|
||||
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
@Autowired
|
||||
public ReferenceFieldDepositBuilder(
|
||||
public ReferenceFieldCommonModelBuilder(
|
||||
ConventionService conventionService) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceFieldDepositBuilder.class)));
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceFieldCommonModelBuilder.class)));
|
||||
}
|
||||
|
||||
public ReferenceFieldDepositBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
public ReferenceFieldCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<DepositBuilderItemResponse<FieldDepositModel, FieldEntity>> buildInternal(List<FieldEntity> data) throws MyApplicationException {
|
||||
protected List<CommonModelBuilderItemResponse<ReferenceFieldModel, 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<DepositBuilderItemResponse<FieldDepositModel, FieldEntity>> models = new ArrayList<>();
|
||||
List<CommonModelBuilderItemResponse<ReferenceFieldModel, FieldEntity>> models = new ArrayList<>();
|
||||
for (FieldEntity d : data) {
|
||||
FieldDepositModel m = new FieldDepositModel();
|
||||
ReferenceFieldModel m = new ReferenceFieldModel();
|
||||
m.setCode(d.getCode());
|
||||
m.setValue(d.getValue());
|
||||
|
||||
models.add(new DepositBuilderItemResponse<>(m, d));
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
return models;
|
|
@ -1,101 +0,0 @@
|
|||
package eu.eudat.model.builder.deposit;
|
||||
|
||||
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.model.*;
|
||||
import eu.eudat.model.builder.*;
|
||||
import eu.eudat.model.builder.descriptionpropertiesdefinition.PropertyDefinitionBuilder;
|
||||
import eu.eudat.query.*;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.fieldset.BaseFieldSet;
|
||||
import gr.cite.tools.fieldset.FieldSet;
|
||||
import gr.cite.tools.logging.DataLogEntry;
|
||||
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 DescriptionDepositBuilder extends BaseDepositBuilder<DescriptionDepositModel, 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 DescriptionDepositBuilder(
|
||||
ConventionService conventionService,
|
||||
QueryFactory queryFactory,
|
||||
BuilderFactory builderFactory, JsonHandlingService jsonHandlingService, XmlHandlingService xmlHandlingService) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionDepositBuilder.class)));
|
||||
this.queryFactory = queryFactory;
|
||||
this.builderFactory = builderFactory;
|
||||
this.jsonHandlingService = jsonHandlingService;
|
||||
this.xmlHandlingService = xmlHandlingService;
|
||||
}
|
||||
|
||||
public DescriptionDepositBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<DepositBuilderItemResponse<DescriptionDepositModel, 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<>();
|
||||
|
||||
Map<UUID, eu.eudat.commons.types.descriptiontemplate.DefinitionEntity> definitionMap = this.collectDescriptionTemplates(data);
|
||||
|
||||
List<DepositBuilderItemResponse<DescriptionDepositModel, DescriptionEntity>> models = new ArrayList<>();
|
||||
for (DescriptionEntity d : data) {
|
||||
DescriptionDepositModel m = new DescriptionDepositModel();
|
||||
m.setLabel(d.getLabel());
|
||||
m.setDescription(d.getDescription());
|
||||
if (d.getProperties() != null){
|
||||
//TODO Update with the new logic of property definition
|
||||
// PropertyDefinitionEntity propertyDefinition = this.jsonHandlingService.fromJsonSafe(PropertyDefinitionEntity.class, d.getProperties());
|
||||
// if (definitionMap != null && definitionMap.containsKey(d.getDescriptionTemplateId()) && propertyDefinition != null && !this.conventionService.isListNullOrEmpty(propertyDefinition.getFields())) m.setFields(this.builderFactory.builder(DescriptionFieldDepositBuilder.class).authorize(this.authorize).setDefinition(definitionMap.get(d.getDescriptionTemplateId())).build(propertyDefinition.getFields()));
|
||||
}
|
||||
models.add(new DepositBuilderItemResponse<>(m, d));
|
||||
}
|
||||
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
|
||||
private Map<UUID, eu.eudat.commons.types.descriptiontemplate.DefinitionEntity> 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));
|
||||
Map<UUID, eu.eudat.commons.types.descriptiontemplate.DefinitionEntity>itemMap = new HashMap<>();
|
||||
|
||||
for (DescriptionTemplateEntity descriptionTemplateEntity : descriptionTemplateEntities){
|
||||
eu.eudat.commons.types.descriptiontemplate.DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(eu.eudat.commons.types.descriptiontemplate.DefinitionEntity.class, descriptionTemplateEntity.getDefinition());
|
||||
itemMap.put(descriptionTemplateEntity.getId(), definition);
|
||||
}
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,112 +0,0 @@
|
|||
package eu.eudat.model.builder.deposit;
|
||||
|
||||
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.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 DescriptionFieldDepositBuilder extends BaseDepositBuilder<DescriptionFieldDepositModel, FieldEntity> {
|
||||
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
private eu.eudat.commons.types.descriptiontemplate.DefinitionEntity definition;
|
||||
private final FieldDataHelperServiceProvider fieldDataHelperServiceProvider;
|
||||
@Autowired
|
||||
public DescriptionFieldDepositBuilder(
|
||||
ConventionService conventionService, FieldDataHelperServiceProvider fieldDataHelperServiceProvider
|
||||
) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionFieldDepositBuilder.class)));
|
||||
this.fieldDataHelperServiceProvider = fieldDataHelperServiceProvider;
|
||||
}
|
||||
|
||||
public DescriptionFieldDepositBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescriptionFieldDepositBuilder setDefinition(DefinitionEntity definition) {
|
||||
this.definition = definition;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<DepositBuilderItemResponse<DescriptionFieldDepositModel, 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<DepositBuilderItemResponse<DescriptionFieldDepositModel, FieldEntity>> models = new ArrayList<>();
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
for (FieldEntity d : data) {
|
||||
DescriptionFieldDepositModel m = new DescriptionFieldDepositModel();
|
||||
if (definition != null){
|
||||
|
||||
//TODO Update with the new logic of property definition
|
||||
//List<eu.eudat.commons.types.descriptiontemplate.FieldEntity> fieldEntities = definition.getFieldById(d.getKey());
|
||||
List<eu.eudat.commons.types.descriptiontemplate.FieldEntity> fieldEntities = new ArrayList<>();
|
||||
if (!this.conventionService.isListNullOrEmpty(fieldEntities)){
|
||||
eu.eudat.commons.types.descriptiontemplate.FieldEntity field = fieldEntities.getFirst();
|
||||
m.setSchematics(field.getSchematics());
|
||||
if (field.getData() != null) {
|
||||
boolean isMultiValue = fieldDataHelperServiceProvider.get(field.getData().getFieldType()).isMultiValue(field.getData());
|
||||
if (!isMultiValue) m.setValues(List.of(d.getTextValue()));
|
||||
else {
|
||||
try {
|
||||
//TODO: Find better Solution
|
||||
List<Object> values = objectMapper.readValue(d.getTextValue(), new TypeReference<List<Object>>() {});
|
||||
m.setValues(values);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
switch (field.getData().getFieldType()) {
|
||||
case SELECT -> m.setFieldType(FieldType.WORD_LIST);
|
||||
case BOOLEAN_DECISION -> m.setFieldType(FieldType.BOOLEAN_DECISION);
|
||||
case RADIO_BOX -> m.setFieldType(FieldType.RADIO_BOX);
|
||||
case INTERNAL_ENTRIES_DMPS -> m.setFieldType(FieldType.INTERNAL_DMP_ENTRIES_DMPS);
|
||||
case INTERNAL_ENTRIES_DESCRIPTIONS -> 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 REFERENCE_TYPES -> m.setFieldType(FieldType.REFERENCE_TYPES); //TODO new reference logic
|
||||
case TAGS -> m.setFieldType(FieldType.TAGS);
|
||||
case DATASET_IDENTIFIER -> m.setFieldType(FieldType.DATASET_IDENTIFIER);
|
||||
case CURRENCY -> m.setFieldType(FieldType.CURRENCY);
|
||||
case VALIDATION -> m.setFieldType(FieldType.VALIDATION);
|
||||
default -> throw new MyApplicationException("unrecognized type " + field.getData().getFieldType());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
models.add(new DepositBuilderItemResponse<>(m, d));
|
||||
}
|
||||
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
package eu.eudat.model.builder.deposit;
|
||||
|
||||
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.depositinterface.enums.ReferenceSourceType;
|
||||
import eu.eudat.depositinterface.models.ReferenceDepositModel;
|
||||
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 ReferenceDepositBuilder extends BaseDepositBuilder<ReferenceDepositModel, ReferenceEntity> {
|
||||
|
||||
private final BuilderFactory builderFactory;
|
||||
private final XmlHandlingService xmlHandlingService;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
@Autowired
|
||||
public ReferenceDepositBuilder(
|
||||
ConventionService conventionService,
|
||||
BuilderFactory builderFactory, XmlHandlingService xmlHandlingService) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceDepositBuilder.class)));
|
||||
this.builderFactory = builderFactory;
|
||||
this.xmlHandlingService = xmlHandlingService;
|
||||
}
|
||||
|
||||
public ReferenceDepositBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<DepositBuilderItemResponse<ReferenceDepositModel, 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<DepositBuilderItemResponse<ReferenceDepositModel, ReferenceEntity>> models = new ArrayList<>();
|
||||
for (ReferenceEntity d : data) {
|
||||
ReferenceDepositModel m = new ReferenceDepositModel();
|
||||
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(ReferenceDefinitionDepositBuilder.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());
|
||||
}
|
||||
// m.setType(d.getTypeId()); //TODO new reference logic
|
||||
models.add(new DepositBuilderItemResponse<>(m, d));
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
return models;
|
||||
}
|
||||
}
|
|
@ -65,13 +65,8 @@ public class FieldBuilder extends BaseBuilder<Field, FieldEntity> {
|
|||
if (fields.hasField(this.asIndexer(Field._numbering))) m.setNumbering(d.getNumbering());
|
||||
if (!visibilityRulesFields.isEmpty() && d.getVisibilityRules() != null) m.setVisibilityRules(this.builderFactory.builder(RuleBuilder.class).authorize(this.authorize).build(visibilityRulesFields, d.getVisibilityRules()));
|
||||
if (!dataFields.isEmpty() && d.getData() != null){
|
||||
try {
|
||||
FieldDataHelperService fieldDataHelperService = this.fieldDataHelperServiceProvider.get(d.getData().getFieldType());
|
||||
m.setData(fieldDataHelperService.buildOne(dataFields, d.getData(), this.authorize));
|
||||
|
||||
} catch (Exception e){
|
||||
throw e;
|
||||
}
|
||||
FieldDataHelperService fieldDataHelperService = this.fieldDataHelperServiceProvider.get(d.getData().getFieldType());
|
||||
m.setData(fieldDataHelperService.buildOne(dataFields, d.getData(), this.authorize));
|
||||
}
|
||||
|
||||
models.add(m);
|
||||
|
|
|
@ -10,9 +10,6 @@ import gr.cite.tools.fieldset.FieldSet;
|
|||
import gr.cite.tools.logging.DataLogEntry;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
|
|
@ -1,77 +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;
|
||||
}
|
||||
}
|
||||
|
||||
//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;
|
||||
// }
|
||||
//}
|
||||
//
|
||||
|
|
|
@ -1,270 +1,265 @@
|
|||
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.*;
|
||||
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.*;
|
||||
|
||||
@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){
|
||||
//TODO Update with the new logic of property definition
|
||||
// FieldFileTransformerModel fieldEntity = findFieldById(d.getKey());
|
||||
FieldFileTransformerModel fieldEntity = new FieldFileTransformerModel();
|
||||
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));
|
||||
}
|
||||
|
||||
for (PageFileTransformerModel page : definition.getDefinition().getPages()) {
|
||||
page.setSections(calculateSectionVisibility(page.getSections()));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private List<SectionFileTransformerModel> calculateSectionVisibility(List<SectionFileTransformerModel> sections) {
|
||||
List<SectionFileTransformerModel> result = new ArrayList<>();
|
||||
|
||||
for (SectionFileTransformerModel section : sections) {
|
||||
if (section.getSections() != null && !section.getSections().isEmpty()) {
|
||||
section.setSections(calculateSectionVisibility(section.getSections()));
|
||||
}
|
||||
|
||||
if (section.getFieldSets() != null && !section.getFieldSets().isEmpty()) {
|
||||
section.setFieldSets(calculateFieldSetVisibility(section.getFieldSets()));
|
||||
}
|
||||
|
||||
if ((section.getSections() != null && !section.getSections().isEmpty()) || (section.getFieldSets() != null && !section.getFieldSets().isEmpty())) {
|
||||
result.add(section);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<FieldSetFileTransformerModel> calculateFieldSetVisibility(List<FieldSetFileTransformerModel> fieldSets) {
|
||||
List<FieldSetFileTransformerModel> result = new ArrayList<>();
|
||||
for (FieldSetFileTransformerModel fieldSet : fieldSets) {
|
||||
if (fieldSet.getFields() != null && !fieldSet.getFields().isEmpty()) {
|
||||
fieldSet.setFields(calculateFieldVisibility(fieldSet.getFields()));
|
||||
if (fieldSet.getFields() != null && !fieldSet.getFields().isEmpty()) {
|
||||
result.add(fieldSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<FieldFileTransformerModel> calculateFieldVisibility(List<FieldFileTransformerModel> fields) {
|
||||
List<FieldFileTransformerModel> result = new ArrayList<>();
|
||||
for (FieldFileTransformerModel field : fields) {
|
||||
if (field.getVisibilityRules() != null && !field.getVisibilityRules().isEmpty()) {
|
||||
Integer maxChecks = field.getVisibilityRules().size();
|
||||
Integer successfulChecks = 0;
|
||||
for (RuleFileTransformerModel rule : field.getVisibilityRules()) {
|
||||
FieldFileTransformerModel targetField = findFieldByPages(definition.getDefinition().getPages(), rule.getTarget());
|
||||
if (targetField.getData() != null ) {
|
||||
successfulChecks = targetField.getData().getValue().equals(rule.getValue()) ? successfulChecks + 1 : successfulChecks;
|
||||
}
|
||||
}
|
||||
if (successfulChecks.equals(maxChecks)) {
|
||||
result.add(field);
|
||||
}
|
||||
} else {
|
||||
result.add(field);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private FieldFileTransformerModel findFieldByPages(List<PageFileTransformerModel> pages, String fieldId) {
|
||||
FieldFileTransformerModel result = null;
|
||||
for (PageFileTransformerModel page : pages) {
|
||||
result = findFieldBySections(page.getSections(), fieldId);
|
||||
if (result != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private FieldFileTransformerModel findFieldBySections(List<SectionFileTransformerModel> sections, String fieldId) {
|
||||
FieldFileTransformerModel result = null;
|
||||
for (SectionFileTransformerModel section : sections) {
|
||||
if (section.getSections() != null && !section.getSections().isEmpty()) {
|
||||
result = findFieldBySections(section.getSections(), fieldId);
|
||||
if (result != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (section.getFieldSets() != null && !section.getFieldSets().isEmpty()) {
|
||||
result = findFieldByFieldSets(section.getFieldSets(), fieldId);
|
||||
if (result != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private FieldFileTransformerModel findFieldByFieldSets(List<FieldSetFileTransformerModel> fieldSets, String fieldId) {
|
||||
FieldFileTransformerModel result = null;
|
||||
for (FieldSetFileTransformerModel fieldSet: fieldSets) {
|
||||
result = findField(fieldSet.getFields(), fieldId);
|
||||
if (result != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private FieldFileTransformerModel findField(List<FieldFileTransformerModel> fields, String fieldId) {
|
||||
FieldFileTransformerModel result = null;
|
||||
for (FieldFileTransformerModel field: fields) {
|
||||
if (field.getId().equals(fieldId)) {
|
||||
result = field;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
//package eu.eudat.model.builder.filetransformer;
|
||||
//
|
||||
//import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
//import eu.eudat.authorization.AuthorizationFlags;
|
||||
//import eu.eudat.commons.types.description.FieldEntity;
|
||||
//import eu.eudat.convention.ConventionService;
|
||||
//import eu.eudat.file.transformer.models.descriptiontemplate.DescriptionTemplateFileTransformerModel;
|
||||
//import eu.eudat.file.transformer.models.descriptiontemplate.definition.*;
|
||||
//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.*;
|
||||
//
|
||||
//@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){
|
||||
// //TODO Update with the new logic of property definition
|
||||
//// FieldFileTransformerModel fieldEntity = findFieldById(d.getKey());
|
||||
// FieldFileTransformerModel fieldEntity = new FieldFileTransformerModel();
|
||||
// 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));
|
||||
// }
|
||||
//
|
||||
// for (PageFileTransformerModel page : definition.getDefinition().getPages()) {
|
||||
// page.setSections(calculateSectionVisibility(page.getSections()));
|
||||
// }
|
||||
//
|
||||
// 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;
|
||||
// }
|
||||
//
|
||||
// private List<SectionFileTransformerModel> calculateSectionVisibility(List<SectionFileTransformerModel> sections) {
|
||||
// List<SectionFileTransformerModel> result = new ArrayList<>();
|
||||
//
|
||||
// for (SectionFileTransformerModel section : sections) {
|
||||
// if (section.getSections() != null && !section.getSections().isEmpty()) {
|
||||
// section.setSections(calculateSectionVisibility(section.getSections()));
|
||||
// }
|
||||
//
|
||||
// if (section.getFieldSets() != null && !section.getFieldSets().isEmpty()) {
|
||||
// section.setFieldSets(calculateFieldSetVisibility(section.getFieldSets()));
|
||||
// }
|
||||
//
|
||||
// if ((section.getSections() != null && !section.getSections().isEmpty()) || (section.getFieldSets() != null && !section.getFieldSets().isEmpty())) {
|
||||
// result.add(section);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// private List<FieldSetFileTransformerModel> calculateFieldSetVisibility(List<FieldSetFileTransformerModel> fieldSets) {
|
||||
// List<FieldSetFileTransformerModel> result = new ArrayList<>();
|
||||
// for (FieldSetFileTransformerModel fieldSet : fieldSets) {
|
||||
// if (fieldSet.getFields() != null && !fieldSet.getFields().isEmpty()) {
|
||||
// fieldSet.setFields(calculateFieldVisibility(fieldSet.getFields()));
|
||||
// if (fieldSet.getFields() != null && !fieldSet.getFields().isEmpty()) {
|
||||
// result.add(fieldSet);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// private List<FieldFileTransformerModel> calculateFieldVisibility(List<FieldFileTransformerModel> fields) {
|
||||
// List<FieldFileTransformerModel> result = new ArrayList<>();
|
||||
// for (FieldFileTransformerModel field : fields) {
|
||||
// if (field.getVisibilityRules() != null && !field.getVisibilityRules().isEmpty()) {
|
||||
// Integer maxChecks = field.getVisibilityRules().size();
|
||||
// Integer successfulChecks = 0;
|
||||
// for (RuleFileTransformerModel rule : field.getVisibilityRules()) {
|
||||
// FieldFileTransformerModel targetField = findFieldByPages(definition.getDefinition().getPages(), rule.getTarget());
|
||||
// if (targetField.getData() != null ) {
|
||||
// successfulChecks = targetField.getData().getValue().equals(rule.getValue()) ? successfulChecks + 1 : successfulChecks;
|
||||
// }
|
||||
// }
|
||||
// if (successfulChecks.equals(maxChecks)) {
|
||||
// result.add(field);
|
||||
// }
|
||||
// } else {
|
||||
// result.add(field);
|
||||
// }
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// private FieldFileTransformerModel findFieldByPages(List<PageFileTransformerModel> pages, String fieldId) {
|
||||
// FieldFileTransformerModel result = null;
|
||||
// for (PageFileTransformerModel page : pages) {
|
||||
// result = findFieldBySections(page.getSections(), fieldId);
|
||||
// if (result != null) {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// private FieldFileTransformerModel findFieldBySections(List<SectionFileTransformerModel> sections, String fieldId) {
|
||||
// FieldFileTransformerModel result = null;
|
||||
// for (SectionFileTransformerModel section : sections) {
|
||||
// if (section.getSections() != null && !section.getSections().isEmpty()) {
|
||||
// result = findFieldBySections(section.getSections(), fieldId);
|
||||
// if (result != null) {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (section.getFieldSets() != null && !section.getFieldSets().isEmpty()) {
|
||||
// result = findFieldByFieldSets(section.getFieldSets(), fieldId);
|
||||
// if (result != null) {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// private FieldFileTransformerModel findFieldByFieldSets(List<FieldSetFileTransformerModel> fieldSets, String fieldId) {
|
||||
// FieldFileTransformerModel result = null;
|
||||
// for (FieldSetFileTransformerModel fieldSet: fieldSets) {
|
||||
// result = findField(fieldSet.getFields(), fieldId);
|
||||
// if (result != null) {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// private FieldFileTransformerModel findField(List<FieldFileTransformerModel> fields, String fieldId) {
|
||||
// FieldFileTransformerModel result = null;
|
||||
// for (FieldFileTransformerModel field: fields) {
|
||||
// if (field.getId().equals(fieldId)) {
|
||||
// result = field;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
|
|
@ -1,171 +1,167 @@
|
|||
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.*;
|
||||
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.description.DescriptionReferenceFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.description.DescriptionTagFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.descriptiontemplate.DescriptionTemplateFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.dmp.DmpFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.dmp.DmpReferenceFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.reference.ReferenceFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.tag.TagFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.user.UserFileTransformerModel;
|
||||
import eu.eudat.model.DescriptionReference;
|
||||
import eu.eudat.model.DescriptionTemplate;
|
||||
import eu.eudat.model.DmpReference;
|
||||
import eu.eudat.model.Tag;
|
||||
import eu.eudat.model.builder.TagBuilder;
|
||||
import eu.eudat.query.*;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.fieldset.BaseFieldSet;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class 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);
|
||||
Map<UUID, List<DescriptionReferenceFileTransformerModel>> referenceMap = collectReferences(data);
|
||||
Map<UUID, List<DescriptionTagFileTransformerModel>> tagMap = collectTags(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());
|
||||
|
||||
//TODO Update with the new logic of property definition
|
||||
// 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));
|
||||
}
|
||||
if (referenceMap != null && !referenceMap.isEmpty() && referenceMap.containsKey(d.getId())) m.setDescriptionReferenceFileTransformerModels(referenceMap.get(d.getId()));
|
||||
if (tagMap != null && !tagMap.isEmpty() && tagMap.containsKey(d.getId())) m.setDescriptionTagFileTransformerModels(tagMap.get(d.getId()));
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private Map<UUID, List<DescriptionReferenceFileTransformerModel>> collectReferences(List<DescriptionEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty()) return null;
|
||||
this.logger.debug("checking related - {}", DmpReference.class.getSimpleName());
|
||||
|
||||
List<DescriptionReferenceEntity> descriptionReferences = this.queryFactory.query(DescriptionReferenceQuery.class).authorize(this.authorize).descriptionIds(data.stream().map(DescriptionEntity::getId).distinct().collect(Collectors.toList())).collectAs(new BaseFieldSet().ensure(DescriptionReference._description).ensure(DescriptionReference._reference));
|
||||
|
||||
Map<UUID, List<DescriptionReferenceFileTransformerModel>> itemMap = new HashMap<>();
|
||||
ReferenceQuery query = this.queryFactory.query(ReferenceQuery.class).authorize(this.authorize).isActive(IsActive.Active).ids(descriptionReferences.stream().map(DescriptionReferenceEntity::getReferenceId).distinct().collect(Collectors.toList()));
|
||||
Map<UUID, ReferenceFileTransformerModel> referenceDepositModelMap = this.builderFactory.builder(ReferenceFileTransformerBuilder.class).authorize(this.authorize).asForeignKey(query, ReferenceEntity::getId);
|
||||
if (referenceDepositModelMap == null) return null;
|
||||
for (DescriptionReferenceEntity descriptionReference : descriptionReferences) {
|
||||
DescriptionReferenceFileTransformerModel descriptionReferenceFileTransformerModel = new DescriptionReferenceFileTransformerModel();
|
||||
descriptionReferenceFileTransformerModel.setId(descriptionReference.getId());
|
||||
descriptionReferenceFileTransformerModel.setReference(referenceDepositModelMap.getOrDefault(descriptionReference.getReferenceId(), null));
|
||||
DescriptionReferenceFileTransformerModel model = descriptionReferenceFileTransformerModel;
|
||||
if (model == null) continue;
|
||||
UUID key = descriptionReference.getDescriptionId();
|
||||
if (!itemMap.containsKey(key)) itemMap.put(key, new ArrayList<>());
|
||||
itemMap.get(key).add(model);
|
||||
}
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
private Map<UUID, List<DescriptionTagFileTransformerModel>> collectTags(List<DescriptionEntity> data) {
|
||||
if (data.isEmpty()) return null;
|
||||
|
||||
List<DescriptionTagEntity> descriptionTags = this.queryFactory.query(DescriptionTagQuery.class).authorize(this.authorize).descriptionIds(data.stream().map(DescriptionEntity::getId).distinct().toList()).collect();
|
||||
|
||||
Map<UUID, List<DescriptionTagFileTransformerModel>> itemMap = new HashMap<>();
|
||||
TagQuery query = this.queryFactory.query(TagQuery.class).authorize(this.authorize).isActive(IsActive.Active).ids(descriptionTags.stream().map(DescriptionTagEntity::getTagId).distinct().toList());
|
||||
Map<UUID, TagFileTransformerModel> tagMap = this.builderFactory.builder(TagFileTransformerBuilder.class).asForeignKey(query, TagEntity::getId);
|
||||
for (DescriptionTagEntity descriptionTag : descriptionTags) {
|
||||
DescriptionTagFileTransformerModel descriptionTagFileTransformerModel = new DescriptionTagFileTransformerModel();
|
||||
descriptionTagFileTransformerModel.setId(descriptionTag.getId());
|
||||
descriptionTagFileTransformerModel.setTagFileTransformerModel(tagMap.getOrDefault(descriptionTag.getTagId(), null));
|
||||
DescriptionTagFileTransformerModel model = descriptionTagFileTransformerModel;
|
||||
if (model == null) continue;
|
||||
UUID key = descriptionTag.getDescriptionId();
|
||||
if (!itemMap.containsKey(key)) itemMap.put(key, new ArrayList<>());
|
||||
itemMap.get(key).add(model);
|
||||
}
|
||||
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
}
|
||||
//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.*;
|
||||
//import eu.eudat.file.transformer.enums.DescriptionStatus;
|
||||
//import eu.eudat.file.transformer.models.description.DescriptionFileTransformerModel;
|
||||
//import eu.eudat.file.transformer.models.description.DescriptionReferenceFileTransformerModel;
|
||||
//import eu.eudat.file.transformer.models.description.DescriptionTagFileTransformerModel;
|
||||
//import eu.eudat.file.transformer.models.descriptiontemplate.DescriptionTemplateFileTransformerModel;
|
||||
//import eu.eudat.file.transformer.models.dmp.DmpFileTransformerModel;
|
||||
//import eu.eudat.file.transformer.models.reference.ReferenceFileTransformerModel;
|
||||
//import eu.eudat.file.transformer.models.tag.TagFileTransformerModel;
|
||||
//import eu.eudat.model.DescriptionReference;
|
||||
//import eu.eudat.model.DescriptionTemplate;
|
||||
//import eu.eudat.model.DmpReference;
|
||||
//import eu.eudat.query.*;
|
||||
//import gr.cite.tools.data.builder.BuilderFactory;
|
||||
//import gr.cite.tools.data.query.QueryFactory;
|
||||
//import gr.cite.tools.exception.MyApplicationException;
|
||||
//import gr.cite.tools.fieldset.BaseFieldSet;
|
||||
//import gr.cite.tools.logging.LoggerService;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
//import org.springframework.context.annotation.Scope;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import java.util.*;
|
||||
//import java.util.stream.Collectors;
|
||||
//
|
||||
//@Component
|
||||
//@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
//public class 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);
|
||||
// Map<UUID, List<DescriptionReferenceFileTransformerModel>> referenceMap = collectReferences(data);
|
||||
// Map<UUID, List<DescriptionTagFileTransformerModel>> tagMap = collectTags(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.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());
|
||||
//
|
||||
// //TODO Update with the new logic of property definition
|
||||
//// 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));
|
||||
// }
|
||||
// if (referenceMap != null && !referenceMap.isEmpty() && referenceMap.containsKey(d.getId())) m.setDescriptionReferenceFileTransformerModels(referenceMap.get(d.getId()));
|
||||
// if (tagMap != null && !tagMap.isEmpty() && tagMap.containsKey(d.getId())) m.setDescriptionTagFileTransformerModels(tagMap.get(d.getId()));
|
||||
//
|
||||
// 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);
|
||||
// }
|
||||
//
|
||||
// private Map<UUID, List<DescriptionReferenceFileTransformerModel>> collectReferences(List<DescriptionEntity> data) throws MyApplicationException {
|
||||
// if (data.isEmpty()) return null;
|
||||
// this.logger.debug("checking related - {}", DmpReference.class.getSimpleName());
|
||||
//
|
||||
// List<DescriptionReferenceEntity> descriptionReferences = this.queryFactory.query(DescriptionReferenceQuery.class).authorize(this.authorize).descriptionIds(data.stream().map(DescriptionEntity::getId).distinct().collect(Collectors.toList())).collectAs(new BaseFieldSet().ensure(DescriptionReference._description).ensure(DescriptionReference._reference));
|
||||
//
|
||||
// Map<UUID, List<DescriptionReferenceFileTransformerModel>> itemMap = new HashMap<>();
|
||||
// ReferenceQuery query = this.queryFactory.query(ReferenceQuery.class).authorize(this.authorize).isActive(IsActive.Active).ids(descriptionReferences.stream().map(DescriptionReferenceEntity::getReferenceId).distinct().collect(Collectors.toList()));
|
||||
// Map<UUID, ReferenceFileTransformerModel> referenceDepositModelMap = this.builderFactory.builder(ReferenceFileTransformerBuilder.class).authorize(this.authorize).asForeignKey(query, ReferenceEntity::getId);
|
||||
// if (referenceDepositModelMap == null) return null;
|
||||
// for (DescriptionReferenceEntity descriptionReference : descriptionReferences) {
|
||||
// DescriptionReferenceFileTransformerModel descriptionReferenceFileTransformerModel = new DescriptionReferenceFileTransformerModel();
|
||||
// descriptionReferenceFileTransformerModel.setId(descriptionReference.getId());
|
||||
// descriptionReferenceFileTransformerModel.setReference(referenceDepositModelMap.getOrDefault(descriptionReference.getReferenceId(), null));
|
||||
// DescriptionReferenceFileTransformerModel model = descriptionReferenceFileTransformerModel;
|
||||
// if (model == null) continue;
|
||||
// UUID key = descriptionReference.getDescriptionId();
|
||||
// if (!itemMap.containsKey(key)) itemMap.put(key, new ArrayList<>());
|
||||
// itemMap.get(key).add(model);
|
||||
// }
|
||||
// return itemMap;
|
||||
// }
|
||||
//
|
||||
// private Map<UUID, List<DescriptionTagFileTransformerModel>> collectTags(List<DescriptionEntity> data) {
|
||||
// if (data.isEmpty()) return null;
|
||||
//
|
||||
// List<DescriptionTagEntity> descriptionTags = this.queryFactory.query(DescriptionTagQuery.class).authorize(this.authorize).descriptionIds(data.stream().map(DescriptionEntity::getId).distinct().toList()).collect();
|
||||
//
|
||||
// Map<UUID, List<DescriptionTagFileTransformerModel>> itemMap = new HashMap<>();
|
||||
// TagQuery query = this.queryFactory.query(TagQuery.class).authorize(this.authorize).isActive(IsActive.Active).ids(descriptionTags.stream().map(DescriptionTagEntity::getTagId).distinct().toList());
|
||||
// Map<UUID, TagFileTransformerModel> tagMap = this.builderFactory.builder(TagFileTransformerBuilder.class).asForeignKey(query, TagEntity::getId);
|
||||
// for (DescriptionTagEntity descriptionTag : descriptionTags) {
|
||||
// DescriptionTagFileTransformerModel descriptionTagFileTransformerModel = new DescriptionTagFileTransformerModel();
|
||||
// descriptionTagFileTransformerModel.setId(descriptionTag.getId());
|
||||
// descriptionTagFileTransformerModel.setTagFileTransformerModel(tagMap.getOrDefault(descriptionTag.getTagId(), null));
|
||||
// DescriptionTagFileTransformerModel model = descriptionTagFileTransformerModel;
|
||||
// if (model == null) continue;
|
||||
// UUID key = descriptionTag.getDescriptionId();
|
||||
// if (!itemMap.containsKey(key)) itemMap.put(key, new ArrayList<>());
|
||||
// itemMap.get(key).add(model);
|
||||
// }
|
||||
//
|
||||
// return itemMap;
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
|
|
@ -1,243 +1,243 @@
|
|||
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 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()));
|
||||
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<PageFileTransformerModel> result = new ArrayList<>();
|
||||
for (PageEntity d: data) {
|
||||
PageFileTransformerModel m = new PageFileTransformerModel();
|
||||
m.setId(d.getId());
|
||||
m.setOrdinal(d.getOrdinal());
|
||||
m.setTitle(d.getTitle());
|
||||
if (d.getSections() != null) m.setSections(collectSections(d.getSections()));
|
||||
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());
|
||||
if (d.getSections() != null && !d.getSections().isEmpty()) {
|
||||
m.setSections(collectSections(d.getSections()));
|
||||
}
|
||||
if (d.getFieldSets() != null && !d.getFieldSets().isEmpty()) {
|
||||
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());
|
||||
if (d.getVisibilityRules() != null && !d.getVisibilityRules().isEmpty()) {
|
||||
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) { //TODO new reference logic
|
||||
// case ExternalSelectDataEntity d -> {
|
||||
// m = new ExternalSelectDataFileTransformerModel();
|
||||
//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 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()));
|
||||
// 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<PageFileTransformerModel> result = new ArrayList<>();
|
||||
// for (PageEntity d: data) {
|
||||
// PageFileTransformerModel m = new PageFileTransformerModel();
|
||||
// m.setId(d.getId());
|
||||
// m.setOrdinal(d.getOrdinal());
|
||||
// m.setTitle(d.getTitle());
|
||||
// if (d.getSections() != null) m.setSections(collectSections(d.getSections()));
|
||||
// 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());
|
||||
// if (d.getSections() != null && !d.getSections().isEmpty()) {
|
||||
// m.setSections(collectSections(d.getSections()));
|
||||
// }
|
||||
// if (d.getFieldSets() != null && !d.getFieldSets().isEmpty()) {
|
||||
// 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());
|
||||
// if (d.getVisibilityRules() != null && !d.getVisibilityRules().isEmpty()) {
|
||||
// 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) { //TODO new reference logic
|
||||
//// case ExternalSelectDataEntity d -> {
|
||||
//// m = new ExternalSelectDataFileTransformerModel();
|
||||
//// m.setLabel(d.getLabel());
|
||||
//// m.setFieldType(FieldType.of(d.getFieldType().getValue()));
|
||||
//// ((ExternalSelectDataFileTransformerModel)m).setMultipleSelect(d.getMultipleSelect());
|
||||
//// ((ExternalSelectDataFileTransformerModel) m).setSources(convertAutoCompleteSingleData(d.getSources()));
|
||||
//// }
|
||||
//// 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()));
|
||||
// ((ExternalSelectDataFileTransformerModel)m).setMultipleSelect(d.getMultipleSelect());
|
||||
// ((ExternalSelectDataFileTransformerModel) m).setSources(convertAutoCompleteSingleData(d.getSources()));
|
||||
// ((RadioBoxDataFileTransformerModel) m).setOptions(convertRadioBoxOptions(d.getOptions()));
|
||||
// }
|
||||
// case ExternalDatasetDataEntity d -> {
|
||||
// m = new ExternalDatasetDataFileTransformerModel();
|
||||
// case UploadDataEntity d -> {
|
||||
// m = new UploadDataFileTransformerModel();
|
||||
// m.setLabel(d.getLabel());
|
||||
// m.setFieldType(FieldType.of(d.getFieldType().getValue()));
|
||||
// ((ExternalDatasetDataFileTransformerModel)m).setType(FieldDataExternalDatasetType.of(d.getType().getValue()));
|
||||
// ((UploadDataFileTransformerModel) m).setMaxFileSizeInMB(d.getMaxFileSizeInMB());
|
||||
// ((UploadDataFileTransformerModel) m).setTypes(convertUploadDataOptions(d.getTypes()));
|
||||
// }
|
||||
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 SelectDataEntity d -> {
|
||||
m = new SelectDataFileTransformerModel();
|
||||
m.setLabel(d.getLabel());
|
||||
m.setFieldType(FieldType.of(d.getFieldType().getValue()));
|
||||
((SelectDataFileTransformerModel) m).setMultipleSelect(d.getMultipleSelect());
|
||||
((SelectDataFileTransformerModel) m).setOptions(d.getOptions().stream().map(this::convertComboBoxOption).toList());
|
||||
}
|
||||
case LabelAndMultiplicityDataEntity d -> {
|
||||
m = new LabelAndMultiplicityDataFileTransformerModel();
|
||||
m.setLabel(d.getLabel());
|
||||
m.setFieldType(FieldType.of(d.getFieldType().getValue()));
|
||||
((LabelAndMultiplicityDataFileTransformerModel)m).setMultipleSelect(d.getMultipleSelect());
|
||||
}
|
||||
default -> {
|
||||
m = new LabelDataFileTransformerModel();
|
||||
m.setLabel(data.getLabel());
|
||||
m.setFieldType(FieldType.of(data.getFieldType().getValue()));
|
||||
}
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
private List<RadioBoxDataFileTransformerModel.RadioBoxDataOptionFileTransformerModel> convertRadioBoxOptions(List<RadioBoxDataEntity.RadioBoxDataOptionEntity> data) {
|
||||
List<RadioBoxDataFileTransformerModel.RadioBoxDataOptionFileTransformerModel> result = new ArrayList<>();
|
||||
for (RadioBoxDataEntity.RadioBoxDataOptionEntity d : data) {
|
||||
RadioBoxDataFileTransformerModel.RadioBoxDataOptionFileTransformerModel m = new RadioBoxDataFileTransformerModel.RadioBoxDataOptionFileTransformerModel();
|
||||
m.setLabel(d.getLabel());
|
||||
m.setValue(d.getValue());
|
||||
result.add(m);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private SelectDataFileTransformerModel.OptionFileTransformerModel convertComboBoxOption(SelectDataEntity.OptionEntity data) {
|
||||
SelectDataFileTransformerModel.OptionFileTransformerModel m = new SelectDataFileTransformerModel.OptionFileTransformerModel();
|
||||
m.setLabel(data.getLabel());
|
||||
m.setValue(data.getValue());
|
||||
return m;
|
||||
}
|
||||
|
||||
private List<UploadDataFileTransformerModel.UploadDataOptionFileTransformerModel> convertUploadDataOptions(List<UploadDataEntity.UploadDataOptionEntity> data) {
|
||||
List<UploadDataFileTransformerModel.UploadDataOptionFileTransformerModel> result = new ArrayList<>();
|
||||
for (UploadDataEntity.UploadDataOptionEntity d : data) {
|
||||
UploadDataFileTransformerModel.UploadDataOptionFileTransformerModel m = new UploadDataFileTransformerModel.UploadDataOptionFileTransformerModel();
|
||||
m.setLabel(d.getLabel());
|
||||
m.setValue(d.getValue());
|
||||
result.add(m);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// case SelectDataEntity d -> {
|
||||
// m = new SelectDataFileTransformerModel();
|
||||
// m.setLabel(d.getLabel());
|
||||
// m.setFieldType(FieldType.of(d.getFieldType().getValue()));
|
||||
// ((SelectDataFileTransformerModel) m).setMultipleSelect(d.getMultipleSelect());
|
||||
// ((SelectDataFileTransformerModel) m).setOptions(d.getOptions().stream().map(this::convertComboBoxOption).toList());
|
||||
// }
|
||||
// case LabelAndMultiplicityDataEntity d -> {
|
||||
// m = new LabelAndMultiplicityDataFileTransformerModel();
|
||||
// m.setLabel(d.getLabel());
|
||||
// m.setFieldType(FieldType.of(d.getFieldType().getValue()));
|
||||
// ((LabelAndMultiplicityDataFileTransformerModel)m).setMultipleSelect(d.getMultipleSelect());
|
||||
// }
|
||||
// default -> {
|
||||
// m = new LabelDataFileTransformerModel();
|
||||
// m.setLabel(data.getLabel());
|
||||
// m.setFieldType(FieldType.of(data.getFieldType().getValue()));
|
||||
// }
|
||||
// }
|
||||
// return m;
|
||||
// }
|
||||
//
|
||||
// private List<RadioBoxDataFileTransformerModel.RadioBoxDataOptionFileTransformerModel> convertRadioBoxOptions(List<RadioBoxDataEntity.RadioBoxDataOptionEntity> data) {
|
||||
// List<RadioBoxDataFileTransformerModel.RadioBoxDataOptionFileTransformerModel> result = new ArrayList<>();
|
||||
// for (RadioBoxDataEntity.RadioBoxDataOptionEntity d : data) {
|
||||
// RadioBoxDataFileTransformerModel.RadioBoxDataOptionFileTransformerModel m = new RadioBoxDataFileTransformerModel.RadioBoxDataOptionFileTransformerModel();
|
||||
// m.setLabel(d.getLabel());
|
||||
// m.setValue(d.getValue());
|
||||
// result.add(m);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// private SelectDataFileTransformerModel.OptionFileTransformerModel convertComboBoxOption(SelectDataEntity.OptionEntity data) {
|
||||
// SelectDataFileTransformerModel.OptionFileTransformerModel m = new SelectDataFileTransformerModel.OptionFileTransformerModel();
|
||||
// m.setLabel(data.getLabel());
|
||||
// m.setValue(data.getValue());
|
||||
// return m;
|
||||
// }
|
||||
//
|
||||
// private List<UploadDataFileTransformerModel.UploadDataOptionFileTransformerModel> convertUploadDataOptions(List<UploadDataEntity.UploadDataOptionEntity> data) {
|
||||
// List<UploadDataFileTransformerModel.UploadDataOptionFileTransformerModel> result = new ArrayList<>();
|
||||
// for (UploadDataEntity.UploadDataOptionEntity d : data) {
|
||||
// UploadDataFileTransformerModel.UploadDataOptionFileTransformerModel m = new UploadDataFileTransformerModel.UploadDataOptionFileTransformerModel();
|
||||
// m.setLabel(d.getLabel());
|
||||
// m.setValue(d.getValue());
|
||||
// result.add(m);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
|
|
@ -1,83 +1,83 @@
|
|||
package eu.eudat.model.builder.filetransformer;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commons.JsonHandlingService;
|
||||
import eu.eudat.commons.XmlHandlingService;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.DescriptionTemplateEntity;
|
||||
import eu.eudat.file.transformer.models.descriptiontemplate.DescriptionTemplateFileTransformerModel;
|
||||
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.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 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.setLanguage(d.getLanguage());
|
||||
m.setVersion(d.getVersion());
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
//package eu.eudat.model.builder.filetransformer;
|
||||
//
|
||||
//import eu.eudat.authorization.AuthorizationFlags;
|
||||
//import eu.eudat.commons.JsonHandlingService;
|
||||
//import eu.eudat.commons.XmlHandlingService;
|
||||
//import eu.eudat.convention.ConventionService;
|
||||
//import eu.eudat.data.DescriptionTemplateEntity;
|
||||
//import eu.eudat.file.transformer.models.descriptiontemplate.DescriptionTemplateFileTransformerModel;
|
||||
//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.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 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.setLanguage(d.getLanguage());
|
||||
// m.setVersion(d.getVersion());
|
||||
// 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());
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
|
|
@ -1,129 +1,129 @@
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
//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;
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
|
|
@ -1,200 +1,200 @@
|
|||
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.dmpblueprint.definition.SectionFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.entitydoi.EntityDoiFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.reference.ReferenceFileTransformerModel;
|
||||
import eu.eudat.file.transformer.models.user.UserFileTransformerModel;
|
||||
import eu.eudat.model.*;
|
||||
import eu.eudat.model.builder.DmpReferenceBuilder;
|
||||
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.getBlueprintId())) m.setBlueprint(blueprintMap.get(d.getBlueprintId()));
|
||||
|
||||
SectionFileTransformerModel templateSection = m.getBlueprint().getDefinitionFileTransformerModel().getSections().stream().filter(SectionFileTransformerModel::getHasTemplates).findFirst().orElse(null);
|
||||
if (templateSection != null && m.getDescriptions() != null && !m.getDescriptions().isEmpty()) {
|
||||
m.getDescriptions().forEach(description -> {
|
||||
description.setSectionId(templateSection.getId());
|
||||
description.setCreatedBy(m.getCreator());
|
||||
});
|
||||
}
|
||||
|
||||
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, ReferenceFileTransformerModel> referenceDepositModelMap = this.builderFactory.builder(ReferenceFileTransformerBuilder.class).authorize(this.authorize).asForeignKey(query, ReferenceEntity::getId);
|
||||
if (referenceDepositModelMap == null) return null;
|
||||
for (DmpReferenceEntity dmpReference : dmpReferences) {
|
||||
DmpReferenceFileTransformerModel dmpReferenceFileTransformerModel = new DmpReferenceFileTransformerModel();
|
||||
dmpReferenceFileTransformerModel.setId(dmpReference.getId());
|
||||
dmpReferenceFileTransformerModel.setData(dmpReference.getData());
|
||||
dmpReferenceFileTransformerModel.setReference(referenceDepositModelMap.getOrDefault(dmpReference.getReferenceId(), null));
|
||||
DmpReferenceFileTransformerModel model = dmpReferenceFileTransformerModel;
|
||||
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(Map.Entry::getKey, Map.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;
|
||||
}
|
||||
|
||||
}
|
||||
//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.dmpblueprint.definition.SectionFileTransformerModel;
|
||||
//import eu.eudat.file.transformer.models.entitydoi.EntityDoiFileTransformerModel;
|
||||
//import eu.eudat.file.transformer.models.reference.ReferenceFileTransformerModel;
|
||||
//import eu.eudat.file.transformer.models.user.UserFileTransformerModel;
|
||||
//import eu.eudat.model.*;
|
||||
//import eu.eudat.model.builder.DmpReferenceBuilder;
|
||||
//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.getBlueprintId())) m.setBlueprint(blueprintMap.get(d.getBlueprintId()));
|
||||
//
|
||||
// SectionFileTransformerModel templateSection = m.getBlueprint().getDefinitionFileTransformerModel().getSections().stream().filter(SectionFileTransformerModel::getHasTemplates).findFirst().orElse(null);
|
||||
// if (templateSection != null && m.getDescriptions() != null && !m.getDescriptions().isEmpty()) {
|
||||
// m.getDescriptions().forEach(description -> {
|
||||
// description.setSectionId(templateSection.getId());
|
||||
// description.setCreatedBy(m.getCreator());
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// 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, ReferenceFileTransformerModel> referenceDepositModelMap = this.builderFactory.builder(ReferenceFileTransformerBuilder.class).authorize(this.authorize).asForeignKey(query, ReferenceEntity::getId);
|
||||
// if (referenceDepositModelMap == null) return null;
|
||||
// for (DmpReferenceEntity dmpReference : dmpReferences) {
|
||||
// DmpReferenceFileTransformerModel dmpReferenceFileTransformerModel = new DmpReferenceFileTransformerModel();
|
||||
// dmpReferenceFileTransformerModel.setId(dmpReference.getId());
|
||||
// dmpReferenceFileTransformerModel.setData(dmpReference.getData());
|
||||
// dmpReferenceFileTransformerModel.setReference(referenceDepositModelMap.getOrDefault(dmpReference.getReferenceId(), null));
|
||||
// DmpReferenceFileTransformerModel model = dmpReferenceFileTransformerModel;
|
||||
// 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(Map.Entry::getKey, Map.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;
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
|
|
@ -1,85 +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;
|
||||
}
|
||||
|
||||
}
|
||||
//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;
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
|
|
@ -1,34 +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;
|
||||
}
|
||||
}
|
||||
//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;
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,19 +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;
|
||||
}
|
||||
}
|
||||
//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;
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,55 +1,54 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
//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.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;
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,54 +1,53 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
//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.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;
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,80 +1,80 @@
|
|||
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.description.DescriptionReferenceFileTransformerModel;
|
||||
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<ReferenceFileTransformerModel, 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<ReferenceFileTransformerModel, 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<ReferenceFileTransformerModel, 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());
|
||||
}
|
||||
|
||||
//m.setType(d.getTypeId()); //TODO new reference logic
|
||||
|
||||
models.add(new FileTransformerBuilderItemResponse<>(m, d));
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
return models;
|
||||
}
|
||||
}
|
||||
//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.description.DescriptionReferenceFileTransformerModel;
|
||||
//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<ReferenceFileTransformerModel, 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<ReferenceFileTransformerModel, 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<ReferenceFileTransformerModel, 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());
|
||||
// }
|
||||
//
|
||||
// //m.setType(d.getTypeId()); //TODO new reference logic
|
||||
//
|
||||
// models.add(new FileTransformerBuilderItemResponse<>(m, d));
|
||||
// }
|
||||
// this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
// return models;
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,59 +1,59 @@
|
|||
package eu.eudat.model.builder.filetransformer;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commons.XmlHandlingService;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.TagEntity;
|
||||
import eu.eudat.file.transformer.models.tag.TagFileTransformerModel;
|
||||
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 TagFileTransformerBuilder extends BaseFileTransformerBuilder<TagFileTransformerModel, TagEntity> {
|
||||
|
||||
private final BuilderFactory builderFactory;
|
||||
private final XmlHandlingService xmlHandlingService;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
@Autowired
|
||||
public TagFileTransformerBuilder(
|
||||
ConventionService conventionService,
|
||||
BuilderFactory builderFactory, XmlHandlingService xmlHandlingService) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(TagFileTransformerBuilder.class)));
|
||||
this.builderFactory = builderFactory;
|
||||
this.xmlHandlingService = xmlHandlingService;
|
||||
}
|
||||
|
||||
public TagFileTransformerBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<FileTransformerBuilderItemResponse<TagFileTransformerModel, TagEntity>> buildInternal(List<TagEntity> 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<TagFileTransformerModel, TagEntity>> models = new ArrayList<>();
|
||||
for (TagEntity d : data) {
|
||||
TagFileTransformerModel m = new TagFileTransformerModel();
|
||||
m.setId(d.getId());
|
||||
m.setLabel(d.getLabel());
|
||||
models.add(new FileTransformerBuilderItemResponse<>(m, d));
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
return models;
|
||||
}
|
||||
}
|
||||
//package eu.eudat.model.builder.filetransformer;
|
||||
//
|
||||
//import eu.eudat.authorization.AuthorizationFlags;
|
||||
//import eu.eudat.commons.XmlHandlingService;
|
||||
//import eu.eudat.convention.ConventionService;
|
||||
//import eu.eudat.data.TagEntity;
|
||||
//import eu.eudat.file.transformer.models.tag.TagFileTransformerModel;
|
||||
//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 TagFileTransformerBuilder extends BaseFileTransformerBuilder<TagFileTransformerModel, TagEntity> {
|
||||
//
|
||||
// private final BuilderFactory builderFactory;
|
||||
// private final XmlHandlingService xmlHandlingService;
|
||||
// private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
//
|
||||
// @Autowired
|
||||
// public TagFileTransformerBuilder(
|
||||
// ConventionService conventionService,
|
||||
// BuilderFactory builderFactory, XmlHandlingService xmlHandlingService) {
|
||||
// super(conventionService, new LoggerService(LoggerFactory.getLogger(TagFileTransformerBuilder.class)));
|
||||
// this.builderFactory = builderFactory;
|
||||
// this.xmlHandlingService = xmlHandlingService;
|
||||
// }
|
||||
//
|
||||
// public TagFileTransformerBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
// this.authorize = values;
|
||||
// return this;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected List<FileTransformerBuilderItemResponse<TagFileTransformerModel, TagEntity>> buildInternal(List<TagEntity> 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<TagFileTransformerModel, TagEntity>> models = new ArrayList<>();
|
||||
// for (TagEntity d : data) {
|
||||
// TagFileTransformerModel m = new TagFileTransformerModel();
|
||||
// m.setId(d.getId());
|
||||
// m.setLabel(d.getLabel());
|
||||
// models.add(new FileTransformerBuilderItemResponse<>(m, d));
|
||||
// }
|
||||
// this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
// return models;
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,76 +1,75 @@
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
//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.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;
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package eu.eudat.service.deposit;
|
||||
|
||||
import eu.eudat.depositinterface.models.DmpDepositModel;
|
||||
import eu.eudat.commonmodels.models.DmpModel;
|
||||
import eu.eudat.depositinterface.repository.DepositClient;
|
||||
import eu.eudat.depositinterface.repository.DepositConfiguration;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
|
@ -16,7 +16,7 @@ public class DepositClientImpl implements DepositClient {
|
|||
|
||||
|
||||
@Override
|
||||
public String deposit(DmpDepositModel dmpDepositModel, String repositoryAccessToken) throws Exception {
|
||||
public String deposit(DmpModel dmpDepositModel, String repositoryAccessToken) throws Exception {
|
||||
return depositClient.post().uri("/", uriBuilder -> uriBuilder.queryParam("authToken", repositoryAccessToken).build()).bodyValue(dmpDepositModel).exchangeToMono(mono -> mono.bodyToMono(String.class)).block();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,22 +2,22 @@ package eu.eudat.service.deposit;
|
|||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.authorization.Permission;
|
||||
import eu.eudat.commonmodels.models.DmpModel;
|
||||
import eu.eudat.commonmodels.models.FileEnvelopeModel;
|
||||
import eu.eudat.configurations.deposit.DepositProperties;
|
||||
import eu.eudat.data.DmpEntity;
|
||||
import eu.eudat.depositinterface.models.DmpDepositModel;
|
||||
import eu.eudat.depositinterface.models.FileEnvelope;
|
||||
import eu.eudat.depositinterface.repository.DepositClient;
|
||||
import eu.eudat.depositinterface.repository.DepositConfiguration;
|
||||
import eu.eudat.model.EntityDoi;
|
||||
import eu.eudat.model.builder.deposit.DepositConfigurationBuilder;
|
||||
import eu.eudat.model.builder.deposit.DmpDepositBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.DepositConfigurationBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.DmpCommonModelBuilder;
|
||||
import eu.eudat.model.persist.deposit.DepositAuthenticateRequest;
|
||||
import eu.eudat.model.persist.deposit.DepositRequest;
|
||||
import eu.eudat.model.persist.EntityDoiPersist;
|
||||
import eu.eudat.query.DmpQuery;
|
||||
import eu.eudat.service.entitydoi.EntityDoiService;
|
||||
import gr.cite.commons.web.authz.service.AuthorizationService;
|
||||
import gr.cite.commons.web.oidc.filter.webflux.TokenExchangeCacheService;
|
||||
import gr.cite.commons.web.authz.service.AuthorizationService;
|
||||
import gr.cite.commons.web.oidc.filter.webflux.TokenExchangeFilterFunction;
|
||||
import gr.cite.commons.web.oidc.filter.webflux.TokenExchangeModel;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
|
@ -130,10 +130,10 @@ public class DepositServiceImpl implements DepositService {
|
|||
|
||||
//GK: Forth make the required files to be uploaded with the deposit
|
||||
//TODO: Properly create required files
|
||||
FileEnvelope docEnvelope = new FileEnvelope();
|
||||
FileEnvelope pdfEnvelope = new FileEnvelope();
|
||||
FileEnvelope jsonEnvelope = new FileEnvelope();
|
||||
FileEnvelope zip = new FileEnvelope();
|
||||
FileEnvelopeModel docEnvelope = new FileEnvelopeModel();
|
||||
FileEnvelopeModel pdfEnvelope = new FileEnvelopeModel();
|
||||
FileEnvelopeModel jsonEnvelope = new FileEnvelopeModel();
|
||||
FileEnvelopeModel zip = new FileEnvelopeModel();
|
||||
//TODO: Create Files
|
||||
// File zip = new File(environment.getProperty("temp.temp") + UUID.randomUUID() + ".zip");
|
||||
// try {
|
||||
|
@ -151,7 +151,7 @@ public class DepositServiceImpl implements DepositService {
|
|||
// }
|
||||
|
||||
//GK: Fifth Transform them to the DepositModel
|
||||
DmpDepositModel depositModel = this.builderFactory.builder(DmpDepositBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic)
|
||||
DmpModel depositModel = this.builderFactory.builder(DmpCommonModelBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic)
|
||||
.setRepositoryId(dmpDepositModel.getRepositoryId()).setPdfFile(pdfEnvelope).setRdaJsonFile(jsonEnvelope).setSupportingFilesZip(zip).build(dmpEntity);
|
||||
|
||||
//GK: Sixth Perform the deposit
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package eu.eudat.service.fielddatahelper;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.BaseFieldDataModel;
|
||||
import eu.eudat.commons.enums.FieldType;
|
||||
import eu.eudat.commons.types.descriptiontemplate.fielddata.BaseFieldDataEntity;
|
||||
import eu.eudat.commons.types.descriptiontemplate.importexport.fielddata.BaseFieldDataImportExport;
|
||||
|
@ -12,19 +13,21 @@ import java.util.EnumSet;
|
|||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class BaseFieldDataHelperService<M extends BaseFieldData, PM extends BaseFieldDataPersist, D extends BaseFieldDataEntity, IE extends BaseFieldDataImportExport> implements FieldDataHelperService {
|
||||
public abstract class BaseFieldDataHelperService<M extends BaseFieldData, PM extends BaseFieldDataPersist, D extends BaseFieldDataEntity, IE extends BaseFieldDataImportExport, CM extends BaseFieldDataModel> implements FieldDataHelperService {
|
||||
protected FieldType fieldType;
|
||||
|
||||
protected abstract D newDataInstanceInternal();
|
||||
protected abstract M newModelInstanceInternal();
|
||||
protected abstract PM newPersistModelInstanceInternal();
|
||||
protected abstract IE newImportExportInstanceInternal();
|
||||
protected abstract CM newCommonModelInstanceInternal();
|
||||
|
||||
protected abstract List<M> buildInternal(FieldSet fieldSet, List<D> data, EnumSet<AuthorizationFlags> authorizationFlags);
|
||||
protected abstract D applyPersistInternal(PM persist, D data);
|
||||
protected abstract PM importExportMapDataToPersistInternal(IE data, PM persist);
|
||||
protected abstract IE dataToImportExportXmlInternal(D data, IE xml);
|
||||
protected abstract boolean isMultiValueInternal(D data);
|
||||
protected abstract List<CM> buildCommonModelInternal(List<D> data, EnumSet<AuthorizationFlags> authorizationFlags);
|
||||
|
||||
@Override
|
||||
public FieldType getFieldType() {
|
||||
|
@ -45,6 +48,11 @@ public abstract class BaseFieldDataHelperService<M extends BaseFieldData, PM ext
|
|||
return this.newModelInstanceInternal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseFieldDataModel newCommonModelInstance() {
|
||||
return this.newCommonModelInstanceInternal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseFieldDataPersist newPersistModelInstance() {
|
||||
return this.newPersistModelInstanceInternal();
|
||||
|
@ -94,6 +102,13 @@ public abstract class BaseFieldDataHelperService<M extends BaseFieldData, PM ext
|
|||
return models.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseFieldDataModel buildCommonModelOne(BaseFieldDataEntity data, EnumSet<AuthorizationFlags> authorizationFlags){
|
||||
List<BaseFieldDataModel> models = this.buildCommonModelInternal(List.of((D) data), authorizationFlags).stream().map(x-> (CM)x).collect(Collectors.toList());
|
||||
if (models == null || models.isEmpty()) return null;
|
||||
return models.getFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BaseFieldData> build(FieldSet fieldSet, List<BaseFieldDataEntity> data, EnumSet<AuthorizationFlags> authorizationFlags) {
|
||||
return this.buildInternal(fieldSet, data.stream().map(x-> (D) x).collect(Collectors.toList()), authorizationFlags).stream().map(x-> (M)x).collect(Collectors.toList());
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package eu.eudat.service.fielddatahelper;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.BaseFieldDataModel;
|
||||
import eu.eudat.commons.enums.FieldType;
|
||||
import eu.eudat.commons.types.descriptiontemplate.fielddata.BaseFieldDataEntity;
|
||||
import eu.eudat.commons.types.descriptiontemplate.importexport.fielddata.BaseFieldDataImportExport;
|
||||
|
@ -16,15 +17,18 @@ public interface FieldDataHelperService {
|
|||
FieldType getFieldType();
|
||||
BaseFieldDataEntity newDataInstance();
|
||||
BaseFieldData newModelInstance();
|
||||
BaseFieldDataModel newCommonModelInstance();
|
||||
BaseFieldDataPersist newPersistModelInstance();
|
||||
BaseFieldDataImportExport newImportExportInstance();
|
||||
Class<?> getDataClass();
|
||||
Class<?> getModelClass();
|
||||
Class<?> getPersistModelClass();
|
||||
Class<?> getCommonModelClass();
|
||||
Class<?> getImportExportClass();
|
||||
Validator getPersistModelValidator();
|
||||
List<BaseFieldData> build(gr.cite.tools.fieldset.FieldSet fieldSet, List<BaseFieldDataEntity> data, EnumSet<AuthorizationFlags> authorizationFlags);
|
||||
BaseFieldData buildOne(FieldSet fieldSet, BaseFieldDataEntity data, EnumSet<AuthorizationFlags> authorizationFlags);
|
||||
BaseFieldDataModel buildCommonModelOne(BaseFieldDataEntity data, EnumSet<AuthorizationFlags> authorizationFlags);
|
||||
BaseFieldDataEntity applyPersist(BaseFieldDataPersist persist);
|
||||
BaseFieldDataEntity applyPersist(BaseFieldDataPersist persist, BaseFieldDataEntity data);
|
||||
BaseFieldDataPersist importExportMapDataToPersist(BaseFieldDataImportExport xml);
|
||||
|
|
|
@ -12,7 +12,7 @@ public class FieldDataHelperServiceProvider {
|
|||
private ApplicationContext applicationContext;
|
||||
|
||||
public FieldDataHelperService get(FieldType type){
|
||||
BaseFieldDataHelperService<?, ?, ?, ? > item = null;
|
||||
BaseFieldDataHelperService<?, ?, ?, ?, ? > item = null;
|
||||
|
||||
switch (type) {
|
||||
case INTERNAL_ENTRIES_DESCRIPTIONS:
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package eu.eudat.service.fielddatahelper;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.BaseFieldDataModel;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.LabelAndMultiplicityDataModel;
|
||||
import eu.eudat.commons.types.descriptiontemplate.fielddata.LabelAndMultiplicityDataEntity;
|
||||
import eu.eudat.commons.types.descriptiontemplate.importexport.fielddata.LabelAndMultiplicityDataImportExport;
|
||||
import eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata.LabelAndMultiplicityDataCommonModelBuilder;
|
||||
import eu.eudat.model.builder.descriptiontemplatedefinition.fielddata.LabelAndMultiplicityDataBuilder;
|
||||
import eu.eudat.model.descriptiontemplatedefinition.fielddata.LabelAndMultiplicityData;
|
||||
import eu.eudat.model.persist.descriptiontemplatedefinition.fielddata.LabelAndMultiplicityDataPersist;
|
||||
|
@ -16,7 +19,7 @@ import java.util.EnumSet;
|
|||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class LabelAndMultiplicityFieldDataHelperService extends BaseFieldDataHelperService<LabelAndMultiplicityData, LabelAndMultiplicityDataPersist, LabelAndMultiplicityDataEntity, LabelAndMultiplicityDataImportExport> {
|
||||
public class LabelAndMultiplicityFieldDataHelperService extends BaseFieldDataHelperService<LabelAndMultiplicityData, LabelAndMultiplicityDataPersist, LabelAndMultiplicityDataEntity, LabelAndMultiplicityDataImportExport, LabelAndMultiplicityDataModel> {
|
||||
|
||||
private final BuilderFactory builderFactory;
|
||||
|
||||
|
@ -46,6 +49,11 @@ public class LabelAndMultiplicityFieldDataHelperService extends BaseFieldDataHel
|
|||
return new LabelAndMultiplicityDataImportExport();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LabelAndMultiplicityDataModel newCommonModelInstanceInternal() {
|
||||
return new LabelAndMultiplicityDataModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getDataClass() {
|
||||
return LabelAndMultiplicityDataEntity.class;
|
||||
|
@ -63,6 +71,11 @@ public class LabelAndMultiplicityFieldDataHelperService extends BaseFieldDataHel
|
|||
public Class<?> getImportExportClass() {
|
||||
return LabelAndMultiplicityDataImportExport.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getCommonModelClass() {
|
||||
return LabelAndMultiplicityDataModel.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Validator getPersistModelValidator() {
|
||||
|
@ -73,7 +86,12 @@ public class LabelAndMultiplicityFieldDataHelperService extends BaseFieldDataHel
|
|||
public List<LabelAndMultiplicityData> buildInternal(FieldSet fieldSet, List<LabelAndMultiplicityDataEntity> data, EnumSet<AuthorizationFlags> authorizationFlags){
|
||||
return this.builderFactory.builder(LabelAndMultiplicityDataBuilder.class).authorize(authorizationFlags).build(fieldSet, data);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected List<LabelAndMultiplicityDataModel> buildCommonModelInternal(List<LabelAndMultiplicityDataEntity> data, EnumSet<AuthorizationFlags> authorizationFlags) {
|
||||
return this.builderFactory.builder(LabelAndMultiplicityDataCommonModelBuilder.class).authorize(authorizationFlags).build(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LabelAndMultiplicityDataEntity applyPersistInternal(LabelAndMultiplicityDataPersist persist, LabelAndMultiplicityDataEntity data) {
|
||||
data.setMultipleSelect(persist.getMultipleSelect());
|
||||
|
@ -96,4 +114,6 @@ public class LabelAndMultiplicityFieldDataHelperService extends BaseFieldDataHel
|
|||
protected boolean isMultiValueInternal(LabelAndMultiplicityDataEntity data) {
|
||||
return data.getMultipleSelect();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
package eu.eudat.service.fielddatahelper;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.LabelAndMultiplicityDataModel;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.LabelDataModel;
|
||||
import eu.eudat.commons.types.descriptiontemplate.fielddata.LabelAndMultiplicityDataEntity;
|
||||
import eu.eudat.commons.types.descriptiontemplate.fielddata.LabelDataEntity;
|
||||
import eu.eudat.commons.types.descriptiontemplate.importexport.fielddata.LabelDataImportExport;
|
||||
import eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata.LabelAndMultiplicityDataCommonModelBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata.LabelDataCommonModelBuilder;
|
||||
import eu.eudat.model.builder.descriptiontemplatedefinition.fielddata.LabelDataBuilder;
|
||||
import eu.eudat.model.descriptiontemplatedefinition.fielddata.LabelData;
|
||||
import eu.eudat.model.persist.descriptiontemplatedefinition.fielddata.LabelDataPersist;
|
||||
|
@ -16,7 +21,7 @@ import java.util.EnumSet;
|
|||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class LabelFieldDataHelperService extends BaseFieldDataHelperService<LabelData, LabelDataPersist, LabelDataEntity, LabelDataImportExport> {
|
||||
public class LabelFieldDataHelperService extends BaseFieldDataHelperService<LabelData, LabelDataPersist, LabelDataEntity, LabelDataImportExport, LabelDataModel> {
|
||||
private final BuilderFactory builderFactory;
|
||||
|
||||
private final ValidatorFactory validatorFactory;
|
||||
|
@ -46,6 +51,11 @@ public class LabelFieldDataHelperService extends BaseFieldDataHelperService<Labe
|
|||
return new LabelDataImportExport();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LabelDataModel newCommonModelInstanceInternal() {
|
||||
return new LabelDataModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getDataClass() {
|
||||
return LabelDataEntity.class;
|
||||
|
@ -63,6 +73,11 @@ public class LabelFieldDataHelperService extends BaseFieldDataHelperService<Labe
|
|||
public Class<?> getImportExportClass() {
|
||||
return LabelDataImportExport.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getCommonModelClass() {
|
||||
return LabelDataModel.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Validator getPersistModelValidator() {
|
||||
|
@ -74,6 +89,11 @@ public class LabelFieldDataHelperService extends BaseFieldDataHelperService<Labe
|
|||
return this.builderFactory.builder(LabelDataBuilder.class).authorize(authorizationFlags).build(fieldSet, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<LabelDataModel> buildCommonModelInternal(List<LabelDataEntity> data, EnumSet<AuthorizationFlags> authorizationFlags) {
|
||||
return this.builderFactory.builder(LabelDataCommonModelBuilder.class).authorize(authorizationFlags).build(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LabelDataEntity applyPersistInternal(LabelDataPersist persist, LabelDataEntity data) {
|
||||
return data;
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
package eu.eudat.service.fielddatahelper;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.LabelAndMultiplicityDataModel;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.RadioBoxDataModel;
|
||||
import eu.eudat.commons.types.descriptiontemplate.fielddata.LabelAndMultiplicityDataEntity;
|
||||
import eu.eudat.commons.types.descriptiontemplate.fielddata.RadioBoxDataEntity;
|
||||
import eu.eudat.commons.types.descriptiontemplate.importexport.fielddata.RadioBoxDataImportExport;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata.LabelAndMultiplicityDataCommonModelBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata.RadioBoxDataCommonModelBuilder;
|
||||
import eu.eudat.model.builder.descriptiontemplatedefinition.fielddata.RadioBoxDataBuilder;
|
||||
import eu.eudat.model.descriptiontemplatedefinition.fielddata.RadioBoxData;
|
||||
import eu.eudat.model.persist.descriptiontemplatedefinition.fielddata.*;
|
||||
|
@ -19,7 +24,7 @@ import java.util.EnumSet;
|
|||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class RadioBoxFieldDataHelperService extends BaseFieldDataHelperService<RadioBoxData, RadioBoxDataPersist, RadioBoxDataEntity, RadioBoxDataImportExport> {
|
||||
public class RadioBoxFieldDataHelperService extends BaseFieldDataHelperService<RadioBoxData, RadioBoxDataPersist, RadioBoxDataEntity, RadioBoxDataImportExport, RadioBoxDataModel> {
|
||||
|
||||
private final ConventionService conventionService;
|
||||
private final BuilderFactory builderFactory;
|
||||
|
@ -52,6 +57,11 @@ public class RadioBoxFieldDataHelperService extends BaseFieldDataHelperService<R
|
|||
return new RadioBoxDataImportExport();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RadioBoxDataModel newCommonModelInstanceInternal() {
|
||||
return new RadioBoxDataModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getDataClass() {
|
||||
return RadioBoxDataEntity.class;
|
||||
|
@ -70,6 +80,11 @@ public class RadioBoxFieldDataHelperService extends BaseFieldDataHelperService<R
|
|||
return RadioBoxDataImportExport.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getCommonModelClass() {
|
||||
return RadioBoxDataModel.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Validator getPersistModelValidator() {
|
||||
return this.validatorFactory.validator(RadioBoxDataPersist.RadioBoxDataPersistValidator.class);
|
||||
|
@ -80,6 +95,11 @@ public class RadioBoxFieldDataHelperService extends BaseFieldDataHelperService<R
|
|||
return this.builderFactory.builder(RadioBoxDataBuilder.class).authorize(authorizationFlags).build(fieldSet, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<RadioBoxDataModel> buildCommonModelInternal(List<RadioBoxDataEntity> data, EnumSet<AuthorizationFlags> authorizationFlags) {
|
||||
return this.builderFactory.builder(RadioBoxDataCommonModelBuilder.class).authorize(authorizationFlags).build(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RadioBoxDataEntity applyPersistInternal(RadioBoxDataPersist persist, RadioBoxDataEntity data) {
|
||||
if (!this.conventionService.isListNullOrEmpty(persist.getOptions())){
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package eu.eudat.service.fielddatahelper;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.ReferenceTypeDataModel;
|
||||
import eu.eudat.commons.types.descriptiontemplate.fielddata.ReferenceTypeDataEntity;
|
||||
import eu.eudat.commons.types.descriptiontemplate.importexport.fielddata.ReferenceTypeDataImportExport;
|
||||
import eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata.ReferenceTypeDataCommonModelBuilder;
|
||||
import eu.eudat.model.builder.descriptiontemplatedefinition.fielddata.ReferenceTypeDataBuilder;
|
||||
import eu.eudat.model.descriptiontemplatedefinition.fielddata.ReferenceTypeData;
|
||||
import eu.eudat.model.persist.descriptiontemplatedefinition.fielddata.ReferenceTypeDataPersist;
|
||||
|
@ -16,7 +18,7 @@ import java.util.EnumSet;
|
|||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class ReferenceTypeFieldDataHelperService extends BaseFieldDataHelperService<ReferenceTypeData, ReferenceTypeDataPersist, ReferenceTypeDataEntity, ReferenceTypeDataImportExport> {
|
||||
public class ReferenceTypeFieldDataHelperService extends BaseFieldDataHelperService<ReferenceTypeData, ReferenceTypeDataPersist, ReferenceTypeDataEntity, ReferenceTypeDataImportExport, ReferenceTypeDataModel> {
|
||||
|
||||
private final BuilderFactory builderFactory;
|
||||
|
||||
|
@ -46,6 +48,11 @@ public class ReferenceTypeFieldDataHelperService extends BaseFieldDataHelperServ
|
|||
return new ReferenceTypeDataImportExport();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReferenceTypeDataModel newCommonModelInstanceInternal() {
|
||||
return new ReferenceTypeDataModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getDataClass() {
|
||||
return ReferenceTypeDataEntity.class;
|
||||
|
@ -63,6 +70,11 @@ public class ReferenceTypeFieldDataHelperService extends BaseFieldDataHelperServ
|
|||
public Class<?> getImportExportClass() {
|
||||
return ReferenceTypeDataImportExport.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getCommonModelClass() {
|
||||
return ReferenceTypeDataModel.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Validator getPersistModelValidator() {
|
||||
|
@ -74,6 +86,11 @@ public class ReferenceTypeFieldDataHelperService extends BaseFieldDataHelperServ
|
|||
return this.builderFactory.builder(ReferenceTypeDataBuilder.class).authorize(authorizationFlags).build(fieldSet, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<ReferenceTypeDataModel> buildCommonModelInternal(List<ReferenceTypeDataEntity> data, EnumSet<AuthorizationFlags> authorizationFlags) {
|
||||
return this.builderFactory.builder(ReferenceTypeDataCommonModelBuilder.class).authorize(authorizationFlags).build(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReferenceTypeDataEntity applyPersistInternal(ReferenceTypeDataPersist persist, ReferenceTypeDataEntity data) {
|
||||
data.setMultipleSelect(persist.getMultipleSelect());
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
package eu.eudat.service.fielddatahelper;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.LabelAndMultiplicityDataModel;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.SelectDataModel;
|
||||
import eu.eudat.commons.types.descriptiontemplate.fielddata.LabelAndMultiplicityDataEntity;
|
||||
import eu.eudat.commons.types.descriptiontemplate.fielddata.SelectDataEntity;
|
||||
import eu.eudat.commons.types.descriptiontemplate.importexport.fielddata.SelectDataImportExport;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata.LabelAndMultiplicityDataCommonModelBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata.SelectDataCommonModelBuilder;
|
||||
import eu.eudat.model.builder.descriptiontemplatedefinition.fielddata.SelectDataBuilder;
|
||||
import eu.eudat.model.descriptiontemplatedefinition.fielddata.SelectData;
|
||||
import eu.eudat.model.persist.descriptiontemplatedefinition.fielddata.*;
|
||||
|
@ -19,7 +24,7 @@ import java.util.EnumSet;
|
|||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class SelectFieldDataHelperService extends BaseFieldDataHelperService<SelectData, SelectDataPersist, SelectDataEntity, SelectDataImportExport> {
|
||||
public class SelectFieldDataHelperService extends BaseFieldDataHelperService<SelectData, SelectDataPersist, SelectDataEntity, SelectDataImportExport, SelectDataModel> {
|
||||
|
||||
private final ConventionService conventionService;
|
||||
private final BuilderFactory builderFactory;
|
||||
|
@ -52,6 +57,11 @@ public class SelectFieldDataHelperService extends BaseFieldDataHelperService<Sel
|
|||
return new SelectDataImportExport();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SelectDataModel newCommonModelInstanceInternal() {
|
||||
return new SelectDataModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getDataClass() {
|
||||
return SelectDataEntity.class;
|
||||
|
@ -65,6 +75,11 @@ public class SelectFieldDataHelperService extends BaseFieldDataHelperService<Sel
|
|||
return SelectDataPersist.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getCommonModelClass() {
|
||||
return SelectDataModel.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getImportExportClass() {
|
||||
return SelectDataImportExport.class;
|
||||
|
@ -80,6 +95,11 @@ public class SelectFieldDataHelperService extends BaseFieldDataHelperService<Sel
|
|||
return this.builderFactory.builder(SelectDataBuilder.class).authorize(authorizationFlags).build(fieldSet, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<SelectDataModel> buildCommonModelInternal(List<SelectDataEntity> data, EnumSet<AuthorizationFlags> authorizationFlags) {
|
||||
return this.builderFactory.builder(SelectDataCommonModelBuilder.class).authorize(authorizationFlags).build(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SelectDataEntity applyPersistInternal(SelectDataPersist persist, SelectDataEntity data) {
|
||||
data.setMultipleSelect(persist.getMultipleSelect());
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
package eu.eudat.service.fielddatahelper;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.LabelAndMultiplicityDataModel;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.SelectDataModel;
|
||||
import eu.eudat.commons.types.descriptiontemplate.fielddata.LabelAndMultiplicityDataEntity;
|
||||
import eu.eudat.commons.types.descriptiontemplate.fielddata.UploadDataEntity;
|
||||
import eu.eudat.commons.types.descriptiontemplate.importexport.fielddata.UploadDataImportExport;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata.LabelAndMultiplicityDataCommonModelBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.descriptiontemplate.fielddata.UploadDataCommonModelBuilder;
|
||||
import eu.eudat.model.builder.descriptiontemplatedefinition.fielddata.UploadDataBuilder;
|
||||
import eu.eudat.model.descriptiontemplatedefinition.fielddata.UploadData;
|
||||
import eu.eudat.model.persist.descriptiontemplatedefinition.fielddata.*;
|
||||
|
@ -19,7 +24,7 @@ import java.util.EnumSet;
|
|||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class UploadFieldDataHelperService extends BaseFieldDataHelperService<UploadData, UploadDataPersist, UploadDataEntity, UploadDataImportExport> {
|
||||
public class UploadFieldDataHelperService extends BaseFieldDataHelperService<UploadData, UploadDataPersist, UploadDataEntity, UploadDataImportExport, SelectDataModel> {
|
||||
|
||||
private final ConventionService conventionService;
|
||||
private final BuilderFactory builderFactory;
|
||||
|
@ -52,6 +57,11 @@ public class UploadFieldDataHelperService extends BaseFieldDataHelperService<Upl
|
|||
return new UploadDataImportExport();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SelectDataModel newCommonModelInstanceInternal() {
|
||||
return new SelectDataModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getDataClass() {
|
||||
return UploadDataEntity.class;
|
||||
|
@ -70,6 +80,11 @@ public class UploadFieldDataHelperService extends BaseFieldDataHelperService<Upl
|
|||
return UploadDataImportExport.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getCommonModelClass() {
|
||||
return SelectDataModel.class;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Validator getPersistModelValidator() {
|
||||
|
@ -81,6 +96,11 @@ public class UploadFieldDataHelperService extends BaseFieldDataHelperService<Upl
|
|||
return this.builderFactory.builder(UploadDataBuilder.class).authorize(authorizationFlags).build(fieldSet, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<SelectDataModel> buildCommonModelInternal(List<UploadDataEntity> data, EnumSet<AuthorizationFlags> authorizationFlags) {
|
||||
return this.builderFactory.builder(UploadDataCommonModelBuilder.class).authorize(authorizationFlags).build(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UploadDataEntity applyPersistInternal(UploadDataPersist persist, UploadDataEntity data) {
|
||||
if (!this.conventionService.isListNullOrEmpty(persist.getTypes())){
|
||||
|
@ -124,7 +144,7 @@ public class UploadFieldDataHelperService extends BaseFieldDataHelperService<Upl
|
|||
|
||||
return persist;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected UploadDataImportExport dataToImportExportXmlInternal(UploadDataEntity data, UploadDataImportExport xml) {
|
||||
if (!this.conventionService.isListNullOrEmpty(data.getTypes())){
|
||||
|
|
|
@ -12,8 +12,6 @@ import eu.eudat.file.transformer.models.description.DescriptionFileTransformerMo
|
|||
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.builder.filetransformer.DescriptionFileTransformerBuilder;
|
||||
import eu.eudat.model.builder.filetransformer.DmpFileTransformerBuilder;
|
||||
import eu.eudat.model.file.TransformerCacheModel;
|
||||
import eu.eudat.query.DescriptionQuery;
|
||||
import eu.eudat.query.DmpQuery;
|
||||
|
@ -134,9 +132,9 @@ public class FileTransformerService {
|
|||
TransformerRepository repository = getRepository(format);
|
||||
//GK: Second get the Target Data Management Plan
|
||||
DmpQuery query = this.queryFactory.query(DmpQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(dmpId);
|
||||
DmpFileTransformerModel dmpFileTransformerModel = this.builderFactory.builder(DmpFileTransformerBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(query.first());
|
||||
dmpFileTransformerModel.setVariant(format);
|
||||
FileEnvelope fileEnvelope = repository.exportDmp(dmpFileTransformerModel);
|
||||
// DmpFileTransformerModel dmpFileTransformerModel = this.builderFactory.builder(DmpFileTransformerBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(query.first());
|
||||
// dmpFileTransformerModel.setVariant(format);
|
||||
FileEnvelope fileEnvelope = repository.exportDmp(null); //TODO
|
||||
eu.eudat.model.file.FileEnvelope result = new eu.eudat.model.file.FileEnvelope();
|
||||
byte[] data = storageFileService.readByFileRefAsBytesSafe(fileEnvelope.getFile(), StorageType.Transformer);
|
||||
result.setFile(data);
|
||||
|
@ -152,9 +150,9 @@ public class FileTransformerService {
|
|||
TransformerRepository repository = getRepository(format);
|
||||
//GK: Second get the Target Data Management Plan
|
||||
DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).ids(descriptionId);
|
||||
DescriptionFileTransformerModel descriptionFileTransformerModel = this.builderFactory.builder(DescriptionFileTransformerBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(query.first());
|
||||
descriptionFileTransformerModel.setCreatedBy(descriptionFileTransformerModel.getDmp().getCreator());
|
||||
FileEnvelope fileEnvelope = repository.exportDescription(descriptionFileTransformerModel, format);
|
||||
// DescriptionFileTransformerModel descriptionFileTransformerModel = this.builderFactory.builder(DescriptionFileTransformerBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(query.first());
|
||||
// descriptionFileTransformerModel.setCreatedBy(descriptionFileTransformerModel.getDmp().getCreator());
|
||||
FileEnvelope fileEnvelope = repository.exportDescription(null, format); //TODO
|
||||
eu.eudat.model.file.FileEnvelope result = new eu.eudat.model.file.FileEnvelope();
|
||||
byte[] data = this.storageFileService.readByFileRefAsBytesSafe(fileEnvelope.getFile(), StorageType.Transformer);
|
||||
result.setFile(data);
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
<dependency>
|
||||
<groupId>gr.cite.opendmp</groupId>
|
||||
<artifactId>repositorydepositbase</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<version>2.0.1</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue