2018-03-21 11:57:56 +01:00
|
|
|
package eu.eudat.data.dao.entities;
|
2017-09-14 12:37:36 +02:00
|
|
|
|
2018-03-21 11:57:56 +01:00
|
|
|
import eu.eudat.data.dao.DatabaseAccess;
|
|
|
|
import eu.eudat.data.dao.criteria.ResearcherCriteria;
|
|
|
|
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
|
|
|
|
import eu.eudat.data.entities.Researcher;
|
2018-01-25 16:24:21 +01:00
|
|
|
import eu.eudat.queryable.QueryableList;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2018-10-02 16:33:58 +02:00
|
|
|
import org.springframework.scheduling.annotation.Async;
|
2017-12-15 00:01:26 +01:00
|
|
|
import org.springframework.stereotype.Component;
|
2017-09-14 12:37:36 +02:00
|
|
|
|
2018-02-16 11:34:02 +01:00
|
|
|
import java.util.UUID;
|
2018-02-21 11:07:31 +01:00
|
|
|
import java.util.concurrent.CompletableFuture;
|
2018-02-16 11:34:02 +01:00
|
|
|
|
2017-12-15 00:01:26 +01:00
|
|
|
@Component("researcherDao")
|
2018-01-25 16:24:21 +01:00
|
|
|
public class ResearcherDaoImpl extends DatabaseAccess<Researcher> implements ResearcherDao {
|
2017-09-14 12:37:36 +02:00
|
|
|
|
2018-02-16 11:34:02 +01:00
|
|
|
@Autowired
|
|
|
|
public ResearcherDaoImpl(DatabaseService<Researcher> databaseService) {
|
2018-05-28 11:50:42 +02:00
|
|
|
super(databaseService);
|
2018-02-16 11:34:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public QueryableList<Researcher> getWithCriteria(ResearcherCriteria criteria) {
|
2019-02-11 14:46:29 +01:00
|
|
|
QueryableList<Researcher> query = asQueryable();
|
|
|
|
if (criteria.getLike() != null && !criteria.getLike().isEmpty())
|
2019-02-15 12:03:59 +01:00
|
|
|
query.where((builder, root) ->builder.or(builder.like(builder.upper(root.get("reference")), "%" + criteria.getLike().toUpperCase() + "%")));
|
2019-02-11 14:46:29 +01:00
|
|
|
if (criteria.getName() != null && !criteria.getName().isEmpty())
|
2019-02-15 12:03:59 +01:00
|
|
|
query.where((builder, root) ->builder.or(builder.like(builder.upper(root.get("label")), "%" + criteria.getName().toUpperCase() + "%")));
|
2018-02-16 11:34:02 +01:00
|
|
|
return query;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Researcher createOrUpdate(Researcher item) {
|
|
|
|
return this.getDatabaseService().createOrUpdate(item, Researcher.class);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Researcher find(UUID id) {
|
|
|
|
return this.getDatabaseService().getQueryable(Researcher.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void delete(Researcher item) {
|
|
|
|
this.getDatabaseService().delete(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public QueryableList<Researcher> asQueryable() {
|
|
|
|
return this.getDatabaseService().getQueryable(Researcher.class);
|
|
|
|
}
|
2018-02-21 11:07:31 +01:00
|
|
|
|
2018-10-02 16:33:58 +02:00
|
|
|
@Async
|
2018-02-21 11:07:31 +01:00
|
|
|
@Override
|
|
|
|
public CompletableFuture<Researcher> createOrUpdateAsync(Researcher item) {
|
|
|
|
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Researcher find(UUID id, String hint) {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
2017-09-14 12:37:36 +02:00
|
|
|
}
|