file transformer changes
This commit is contained in:
parent
d844d35392
commit
49f3da1314
|
@ -44,6 +44,7 @@ public class EntityDoiCommonModelBuilder extends BaseCommonModelBuilder<EntityDo
|
|||
EntityDoiModel m = new EntityDoiModel();
|
||||
m.setId(d.getId());
|
||||
m.setDoi(d.getDoi());
|
||||
m.setRepositoryId(d.getRepositoryId());
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package eu.eudat.model.builder.commonmodels;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.TagModel;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.TagEntity;
|
||||
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 TagCommonModelBuilder extends BaseCommonModelBuilder<TagModel, TagEntity> {
|
||||
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
@Autowired
|
||||
public TagCommonModelBuilder(
|
||||
ConventionService conventionService) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(TagCommonModelBuilder.class)));
|
||||
}
|
||||
|
||||
public TagCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<TagModel, 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<CommonModelBuilderItemResponse<TagModel, TagEntity>> models = new ArrayList<>();
|
||||
for (TagEntity d : data) {
|
||||
TagModel m = new TagModel();
|
||||
m.setId(d.getId());
|
||||
m.setLabel(d.getLabel());
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
return models;
|
||||
}
|
||||
}
|
|
@ -1,9 +1,21 @@
|
|||
package eu.eudat.model.builder.commonmodels;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.DmpUserModel;
|
||||
import eu.eudat.commonmodels.models.UserContactInfoModel;
|
||||
import eu.eudat.commonmodels.models.UserModel;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.DmpEntity;
|
||||
import eu.eudat.data.DmpUserEntity;
|
||||
import eu.eudat.data.UserContactInfoEntity;
|
||||
import eu.eudat.data.UserEntity;
|
||||
import eu.eudat.model.DmpUser;
|
||||
import eu.eudat.model.UserContactInfo;
|
||||
import eu.eudat.query.DmpUserQuery;
|
||||
import eu.eudat.query.UserContactInfoQuery;
|
||||
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;
|
||||
|
@ -12,20 +24,23 @@ 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;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class UserCommonModelBuilder extends BaseCommonModelBuilder<UserModel, UserEntity> {
|
||||
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
private final BuilderFactory builderFactory;
|
||||
private final QueryFactory queryFactory;
|
||||
private boolean disableContacts;
|
||||
|
||||
@Autowired
|
||||
public UserCommonModelBuilder(ConventionService conventionService) {
|
||||
public UserCommonModelBuilder(ConventionService conventionService, BuilderFactory builderFactory, QueryFactory queryFactory) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(UserCommonModelBuilder.class)));
|
||||
this.builderFactory = builderFactory;
|
||||
this.queryFactory = queryFactory;
|
||||
}
|
||||
|
||||
public UserCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
|
@ -33,22 +48,39 @@ public class UserCommonModelBuilder extends BaseCommonModelBuilder<UserModel, Us
|
|||
return this;
|
||||
}
|
||||
|
||||
public UserCommonModelBuilder disableContacts(boolean values) {
|
||||
this.disableContacts = disableContacts;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
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<>();
|
||||
Map<UUID, List<UserContactInfoModel>> userContactInfoModelMap = this.disableContacts ? null : this.collectUserContactInfos(data);
|
||||
|
||||
List<CommonModelBuilderItemResponse<UserModel, UserEntity>> models = new ArrayList<>();
|
||||
|
||||
for (UserEntity d : data) {
|
||||
UserModel m = new UserModel();
|
||||
m.setId(d.getId());
|
||||
m.setName(d.getName());
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
if (userContactInfoModelMap != null && d.getId() != null && userContactInfoModelMap.containsKey(d.getId())) m.setContacts(userContactInfoModelMap.get(d.getId()));
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
|
||||
private Map<UUID, List<UserContactInfoModel>> collectUserContactInfos(List<UserEntity> data) throws MyApplicationException {
|
||||
this.logger.debug("checking related - {}", UserContactInfo.class.getSimpleName());
|
||||
|
||||
Map<UUID, List<UserContactInfoModel>> itemMap;
|
||||
UserContactInfoQuery query = this.queryFactory.query(UserContactInfoQuery.class).authorize(this.authorize).userIds(data.stream().map(UserEntity::getId).distinct().collect(Collectors.toList()));
|
||||
itemMap = this.builderFactory.builder(UserContactInfoCommonModelBuilder.class).authorize(this.authorize).asMasterKey(query, UserContactInfoEntity::getUserId);
|
||||
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
package eu.eudat.model.builder.commonmodels;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.enums.ContactInfoType;
|
||||
import eu.eudat.commonmodels.models.UserContactInfoModel;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.UserContactInfoEntity;
|
||||
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 UserContactInfoCommonModelBuilder extends BaseCommonModelBuilder<UserContactInfoModel, UserContactInfoEntity> {
|
||||
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
@Autowired
|
||||
public UserContactInfoCommonModelBuilder(
|
||||
ConventionService conventionService) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(UserContactInfoCommonModelBuilder.class)));
|
||||
}
|
||||
|
||||
public UserContactInfoCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<UserContactInfoModel, UserContactInfoEntity>> buildInternal(List<UserContactInfoEntity> 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<UserContactInfoModel, UserContactInfoEntity>> models = new ArrayList<>();
|
||||
for (UserContactInfoEntity d : data) {
|
||||
UserContactInfoModel m = new UserContactInfoModel();
|
||||
m.setId(d.getId());
|
||||
m.setCreatedAt(d.getCreatedAt());
|
||||
m.setValue(d.getValue());
|
||||
switch (d.getType()){
|
||||
case Email -> m.setType(ContactInfoType.Email);
|
||||
default -> throw new MyApplicationException("unrecognized type " + d.getType());
|
||||
}
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
return models;
|
||||
}
|
||||
}
|
|
@ -78,6 +78,7 @@ public class DescriptionCommonModelBuilder extends BaseCommonModelBuilder<Descri
|
|||
List<CommonModelBuilderItemResponse<DescriptionModel, DescriptionEntity>> models = new ArrayList<>();
|
||||
for (DescriptionEntity d : data) {
|
||||
DescriptionModel m = new DescriptionModel();
|
||||
m.setId(d.getId());
|
||||
m.setLabel(d.getLabel());
|
||||
m.setDescription(d.getDescription());
|
||||
switch (d.getStatus()){
|
||||
|
|
|
@ -62,6 +62,7 @@ public class FieldCommonModelBuilder extends BaseCommonModelBuilder<FieldModel,
|
|||
List<CommonModelBuilderItemResponse<FieldModel, FieldEntity>> models = new ArrayList<>();
|
||||
for (FieldEntity d : data) {
|
||||
FieldModel m = new FieldModel();
|
||||
if (this.fieldEntity != null) m.setId(fieldEntity.getId());
|
||||
if (FieldType.isDateType(fieldType)) m.setDateValue(d.getDateValue());
|
||||
if (FieldType.isTextType(fieldType)) m.setTextValue(d.getTextValue());
|
||||
if (FieldType.isTextListType(fieldType)) m.setTextListValue(d.getTextListValue());
|
||||
|
|
|
@ -115,6 +115,8 @@ public class DmpCommonModelBuilder extends BaseCommonModelBuilder<DmpModel, DmpE
|
|||
m.setVersion(d.getVersion());
|
||||
m.setDescription(d.getDescription());
|
||||
m.setFinalizedAt(d.getFinalizedAt());
|
||||
m.setCreatedAt(d.getCreatedAt());
|
||||
m.setLanguage(d.getLanguage());
|
||||
switch (d.getStatus()){
|
||||
case Finalized -> m.setStatus(DmpStatus.Finalized);
|
||||
case Draft -> m.setStatus(DmpStatus.Draft);
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
package eu.eudat.model.builder.commonmodels.dmp;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commonmodels.models.UserModel;
|
||||
import eu.eudat.commonmodels.models.dmp.DmpContactModel;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.commons.types.dmp.DmpContactEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.UserEntity;
|
||||
import eu.eudat.model.builder.commonmodels.BaseCommonModelBuilder;
|
||||
import eu.eudat.model.builder.commonmodels.CommonModelBuilderItemResponse;
|
||||
import eu.eudat.model.builder.commonmodels.UserCommonModelBuilder;
|
||||
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 DmpContactCommonModelBuilder extends BaseCommonModelBuilder<DmpContactModel, DmpContactEntity> {
|
||||
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
private final BuilderFactory builderFactory;
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
|
||||
@Autowired
|
||||
public DmpContactCommonModelBuilder(
|
||||
ConventionService conventionService, BuilderFactory builderFactory, QueryFactory queryFactory) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpContactCommonModelBuilder.class)));
|
||||
this.builderFactory = builderFactory;
|
||||
this.queryFactory = queryFactory;
|
||||
}
|
||||
|
||||
public DmpContactCommonModelBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
this.authorize = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<CommonModelBuilderItemResponse<DmpContactModel, DmpContactEntity>> buildInternal(List<DmpContactEntity> 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, UserModel> userItemsMap = this.collectUsers(data);
|
||||
|
||||
List<CommonModelBuilderItemResponse<DmpContactModel, DmpContactEntity>> models = new ArrayList<>();
|
||||
for (DmpContactEntity d : data) {
|
||||
DmpContactModel m = new DmpContactModel();
|
||||
m.setEmail(d.getEmail());
|
||||
m.setFirstName(d.getFirstName());
|
||||
m.setLastName(d.getLastName());
|
||||
if (userItemsMap != null && d.getUserId() != null && userItemsMap.containsKey(d.getUserId())) m.setUser(userItemsMap.get(d.getUserId()));
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
return models;
|
||||
}
|
||||
|
||||
private Map<UUID, UserModel> collectUsers(List<DmpContactEntity> data) throws MyApplicationException {
|
||||
if (data.isEmpty())
|
||||
return null;
|
||||
this.logger.debug("checking related - {}", UserModel.class.getSimpleName());
|
||||
|
||||
Map<UUID, UserModel> itemMap;
|
||||
UserQuery q = this.queryFactory.query(UserQuery.class).isActive(IsActive.Active).authorize(this.authorize).ids(data.stream().filter(x-> x.getUserId() != null).map(DmpContactEntity::getUserId).distinct().collect(Collectors.toList()));
|
||||
itemMap = this.builderFactory.builder(UserCommonModelBuilder.class).disableContacts(true).authorize(this.authorize).asForeignKey(q, UserEntity::getId);
|
||||
return itemMap;
|
||||
}
|
||||
}
|
|
@ -48,6 +48,7 @@ public class DmpPropertiesCommonModelBuilder extends BaseCommonModelBuilder<DmpP
|
|||
for (DmpPropertiesEntity d : data) {
|
||||
DmpPropertiesModel m = new DmpPropertiesModel();
|
||||
if (d.getDmpBlueprintValues() != null) m.setDmpBlueprintValues(this.builderFactory.builder(DmpBlueprintValueCommonModelBuilder.class).authorize(this.authorize).build(d.getDmpBlueprintValues()));
|
||||
if (d.getContacts() != null) m.setContacts(this.builderFactory.builder(DmpContactCommonModelBuilder.class).authorize(this.authorize).build(d.getContacts()));
|
||||
|
||||
models.add(new CommonModelBuilderItemResponse<>(m, d));
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
<dependency>
|
||||
<groupId>gr.cite.opendmp</groupId>
|
||||
<artifactId>repositorydepositbase</artifactId>
|
||||
<version>2.0.1</version>
|
||||
<version>2.0.2</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
@ -199,7 +199,7 @@
|
|||
<dependency>
|
||||
<groupId>gr.cite.opendmp</groupId>
|
||||
<artifactId>file-transformer-base</artifactId>
|
||||
<version>0.0.4</version>
|
||||
<version>0.0.5</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
|
Loading…
Reference in New Issue