argos/dmp-backend/core/src/main/java/eu/eudat/elastic/elasticbuilder/nested/NestedCollaboratorElasticBu...

46 lines
1.8 KiB
Java

package eu.eudat.elastic.elasticbuilder.nested;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.DmpUserEntity;
import eu.eudat.elastic.data.nested.NestedCollaboratorElasticEntity;
import eu.eudat.elastic.elasticbuilder.BaseElasticBuilder;
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.List;
import java.util.Optional;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class NestedCollaboratorElasticBuilder extends BaseElasticBuilder<NestedCollaboratorElasticEntity, DmpUserEntity> {
@Autowired
public NestedCollaboratorElasticBuilder(
ConventionService conventionService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(NestedCollaboratorElasticBuilder.class)));
}
@Override
public List<NestedCollaboratorElasticEntity> build(List<DmpUserEntity> data) throws MyApplicationException {
if (data == null)
return new ArrayList<>();
List<NestedCollaboratorElasticEntity> models = new ArrayList<>();
for (DmpUserEntity d : data) {
NestedCollaboratorElasticEntity m = new NestedCollaboratorElasticEntity();
m.setId(d.getId());
m.setRole(d.getRole());
m.setName(d.getUser().toString()); //TODO: Get UserName
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}