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.DataRepositoryCriteria;
|
|
|
|
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
|
|
|
|
import eu.eudat.data.entities.DataRepository;
|
2017-12-17 22:34:24 +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("dataRepositoryDao")
|
2018-01-25 16:24:21 +01:00
|
|
|
public class DataRepositoryDaoImpl extends DatabaseAccess<DataRepository> implements DataRepositoryDao {
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
public DataRepositoryDaoImpl(DatabaseService<DataRepository> databaseService) {
|
2018-05-28 11:50:42 +02:00
|
|
|
super(databaseService);
|
2018-01-25 16:24:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public QueryableList<DataRepository> getWithCriteria(DataRepositoryCriteria criteria) {
|
|
|
|
QueryableList<DataRepository> query = this.getDatabaseService().getQueryable(DataRepository.class);
|
|
|
|
if (criteria.getLike() != null)
|
2019-09-25 17:31:41 +02:00
|
|
|
query.where((builder, root) -> builder.or(
|
|
|
|
builder.like(builder.upper(root.get("reference")), "%" + criteria.getLike().toUpperCase() + "%"),
|
|
|
|
builder.equal(builder.upper(root.get("label")), "%" + criteria.getLike().toUpperCase() + "%")));
|
|
|
|
if (criteria.getCreationUserId() != null)
|
|
|
|
query.where((builder, root) -> builder.equal(root.get("creationUser").get("id"), criteria.getCreationUserId()));
|
2018-01-25 16:24:21 +01:00
|
|
|
return query;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public DataRepository find(UUID id) {
|
|
|
|
return this.getDatabaseService().getQueryable(DataRepository.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public DataRepository createOrUpdate(DataRepository item) {
|
|
|
|
return getDatabaseService().createOrUpdate(item, DataRepository.class);
|
|
|
|
}
|
2018-02-01 15:04:36 +01:00
|
|
|
|
2018-02-21 11:07:31 +01:00
|
|
|
@Override
|
2018-10-02 16:33:58 +02:00
|
|
|
@Async
|
2018-02-21 11:07:31 +01:00
|
|
|
public CompletableFuture<DataRepository> createOrUpdateAsync(DataRepository item) {
|
|
|
|
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public DataRepository find(UUID id, String hint) {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
2018-02-01 15:04:36 +01:00
|
|
|
@Override
|
|
|
|
public void delete(DataRepository item) {
|
|
|
|
this.getDatabaseService().delete(item);
|
|
|
|
}
|
2018-02-02 11:33:37 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public QueryableList<DataRepository> asQueryable() {
|
|
|
|
return this.getDatabaseService().getQueryable(DataRepository.class);
|
|
|
|
}
|
2017-09-14 12:37:36 +02:00
|
|
|
}
|