67 lines
3.5 KiB
Java
67 lines
3.5 KiB
Java
package eu.eudat.model.builder;
|
|
|
|
import eu.eudat.authorization.AuthorizationFlags;
|
|
import eu.eudat.convention.ConventionService;
|
|
import eu.eudat.data.DMPEntity;
|
|
import eu.eudat.model.DMP;
|
|
import gr.cite.tools.exception.MyApplicationException;
|
|
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.*;
|
|
|
|
@Component
|
|
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
|
public class DMPBuilder extends BaseBuilder<DMP, DMPEntity> {
|
|
|
|
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
|
|
|
@Autowired
|
|
public DMPBuilder(ConventionService conventionService) {
|
|
super(conventionService, new LoggerService(LoggerFactory.getLogger(DMPBuilder.class)));
|
|
}
|
|
|
|
public DMPBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
|
this.authorize = values;
|
|
return this;
|
|
}
|
|
|
|
@Override
|
|
public List<DMP> build(FieldSet fields, List<DMPEntity> data) throws MyApplicationException {
|
|
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
|
|
this.logger.trace(new DataLogEntry("requested fields", fields));
|
|
if (fields == null || data == null || fields.isEmpty())
|
|
return new ArrayList<>();
|
|
List<DMP> models = new ArrayList<>();
|
|
for (DMPEntity d : data) {
|
|
DMP m = new DMP();
|
|
if (fields.hasField(this.asIndexer(DMP._id))) m.setId(d.getId());
|
|
if (fields.hasField(this.asIndexer(DMP._label))) m.setLabel(d.getLabel());
|
|
if (fields.hasField(this.asIndexer(DMP._version))) m.setVersion(d.getVersion());
|
|
if (fields.hasField(this.asIndexer(DMP._status))) m.setStatus(d.getStatus());
|
|
if (fields.hasField(this.asIndexer(DMP._properties))) m.setProperties(d.getProperties());
|
|
if (fields.hasField(this.asIndexer(DMP._dmpProperties))) m.setDmpProperties(d.getDmpProperties());
|
|
if (fields.hasField(this.asIndexer(DMP._groupId))) m.setGroupId(d.getGroupId());
|
|
if (fields.hasField(this.asIndexer(DMP._description))) m.setDescription(d.getDescription());
|
|
if (fields.hasField(this.asIndexer(DMP._isPublic))) m.setIsPublic(d.getIsPublic());
|
|
if (fields.hasField(this.asIndexer(DMP._extraProperties))) m.setExtraProperties(d.getExtraProperties());
|
|
if (fields.hasField(this.asIndexer(DMP._createdAt))) m.setCreatedAt(d.getCreatedAt());
|
|
if (fields.hasField(this.asIndexer(DMP._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
|
|
if (fields.hasField(this.asIndexer(DMP._isActive))) m.setIsActive(d.getIsActive());
|
|
if (fields.hasField(this.asIndexer(DMP._finalizedAt))) m.setFinalizedAt(d.getFinalizedAt());
|
|
if (fields.hasField(this.asIndexer(DMP._publishedAt))) m.setPublishedAt(d.getPublishedAt());
|
|
if (fields.hasField(this.asIndexer(DMP._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));
|
|
models.add(m);
|
|
}
|
|
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
|
return models;
|
|
}
|
|
|
|
}
|