2023-10-20 15:48:55 +02:00
|
|
|
package eu.eudat.model.builder;
|
|
|
|
|
2023-10-23 10:16:58 +02:00
|
|
|
import eu.eudat.authorization.AuthorizationFlags;
|
|
|
|
import eu.eudat.convention.ConventionService;
|
2023-10-23 10:31:07 +02:00
|
|
|
import eu.eudat.data.DmpEntity;
|
|
|
|
import eu.eudat.model.Dmp;
|
2023-10-23 10:16:58 +02:00
|
|
|
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)
|
2023-10-23 10:31:07 +02:00
|
|
|
public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
|
2023-10-23 10:16:58 +02:00
|
|
|
|
|
|
|
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
|
|
|
|
|
|
|
@Autowired
|
2023-10-23 10:31:07 +02:00
|
|
|
public DmpBuilder(ConventionService conventionService) {
|
|
|
|
super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpBuilder.class)));
|
2023-10-23 10:16:58 +02:00
|
|
|
}
|
|
|
|
|
2023-10-23 10:31:07 +02:00
|
|
|
public DmpBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
2023-10-23 10:16:58 +02:00
|
|
|
this.authorize = values;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-10-23 10:31:07 +02:00
|
|
|
public List<Dmp> build(FieldSet fields, List<DmpEntity> data) throws MyApplicationException {
|
2023-10-23 10:16:58 +02:00
|
|
|
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<>();
|
2023-10-23 10:31:07 +02:00
|
|
|
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()));
|
2023-10-23 10:16:58 +02:00
|
|
|
models.add(m);
|
|
|
|
}
|
|
|
|
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
|
|
|
return models;
|
|
|
|
}
|
2023-10-20 15:48:55 +02:00
|
|
|
|
|
|
|
}
|