argos/dmp-backend/core/src/main/java/eu/eudat/model/builder/filetransformer/FileTransformerSourceBuilde...

58 lines
2.9 KiB
Java

package eu.eudat.model.builder.filetransformer;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.filetransformer.FileTransformerSourceEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.filetransformer.FileTransformerSource;
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 FileTransformerSourceBuilder extends BaseBuilder<FileTransformerSource, FileTransformerSourceEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public FileTransformerSourceBuilder(
ConventionService conventionService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(FileTransformerSourceBuilder.class)));
}
public FileTransformerSourceBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<FileTransformerSource> build(FieldSet fields, List<FileTransformerSourceEntity> 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<FileTransformerSource> models = new ArrayList<>();
for (FileTransformerSourceEntity d : data) {
FileTransformerSource m = new FileTransformerSource();
if (fields.hasField(this.asIndexer(FileTransformerSource._transformerId))) m.setTransformerId(d.getTransformerId());
if (fields.hasField(this.asIndexer(FileTransformerSource._url))) m.setUrl(d.getUrl());
if (fields.hasField(this.asIndexer(FileTransformerSource._issuerUrl))) m.setIssuerUrl(d.getIssuerUrl());
if (fields.hasField(this.asIndexer(FileTransformerSource._clientId))) m.setClientId(d.getClientId());
if (fields.hasField(this.asIndexer(FileTransformerSource._clientSecret))) m.setClientSecret(d.getClientSecret());
if (fields.hasField(this.asIndexer(FileTransformerSource._scope))) m.setScope(d.getScope());
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}