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.OrganisationCriteria;
|
|
|
|
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
|
2019-05-14 13:12:31 +02:00
|
|
|
import eu.eudat.data.entities.DMP;
|
2018-03-21 11:57:56 +01:00
|
|
|
import eu.eudat.data.entities.Organisation;
|
2019-04-22 16:19:08 +02:00
|
|
|
import eu.eudat.data.entities.UserInfo;
|
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
|
|
|
|
2019-05-14 13:12:31 +02:00
|
|
|
import javax.persistence.criteria.JoinType;
|
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("organisationDao")
|
2018-01-25 16:24:21 +01:00
|
|
|
public class OrganisationDaoImpl extends DatabaseAccess<Organisation> implements OrganisationDao {
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
public OrganisationDaoImpl(DatabaseService<Organisation> databaseService) {
|
2018-05-28 11:50:42 +02:00
|
|
|
super(databaseService);
|
2018-01-25 16:24:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public QueryableList<Organisation> getWithCriteria(OrganisationCriteria criteria) {
|
|
|
|
QueryableList<Organisation> query = this.getDatabaseService().getQueryable(Organisation.class);
|
2021-04-30 14:25:31 +02:00
|
|
|
if (criteria.getLabelLike() != null && criteria.getLike() != null) {
|
|
|
|
query.where((builder, root) -> builder.or(builder.equal(root.get("reference"), criteria.getLike()), builder.like(builder.upper(root.get("label")), "%" + criteria.getLabelLike().toUpperCase() + "%")));
|
|
|
|
} else {
|
|
|
|
if (criteria.getLike() != null)
|
|
|
|
query.where((builder, root) -> builder.equal(root.get("reference"), criteria.getLike()));
|
|
|
|
if (criteria.getLabelLike() != null) {
|
|
|
|
query.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + criteria.getLabelLike().toUpperCase() + "%"));
|
|
|
|
}
|
|
|
|
if (criteria.getPublic() != null && criteria.getPublic()) {
|
|
|
|
query.where((builder, root) -> builder.equal(root.join("dmps", JoinType.LEFT).get("status"), DMP.DMPStatus.FINALISED.getValue()));
|
|
|
|
}
|
2019-05-14 13:12:31 +02:00
|
|
|
}
|
2021-07-19 17:34:29 +02:00
|
|
|
|
|
|
|
if (criteria.isActive()) {
|
|
|
|
query.where((builder, root) -> builder.notEqual(root.join("dmps").get("status"), DMP.DMPStatus.DELETED.getValue())).distinct();
|
|
|
|
}
|
|
|
|
|
2018-01-25 16:24:21 +01:00
|
|
|
return query;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Organisation createOrUpdate(Organisation item) {
|
2018-02-16 11:34:02 +01:00
|
|
|
return this.getDatabaseService().createOrUpdate(item, Organisation.class);
|
2018-01-25 16:24:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Organisation find(UUID id) {
|
|
|
|
return this.getDatabaseService().getQueryable(Organisation.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
|
|
|
|
}
|
2018-02-01 15:04:36 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void delete(Organisation item) {
|
|
|
|
this.getDatabaseService().delete(item);
|
|
|
|
}
|
2018-02-02 11:33:37 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public QueryableList<Organisation> asQueryable() {
|
|
|
|
return this.getDatabaseService().getQueryable(Organisation.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<Organisation> createOrUpdateAsync(Organisation item) {
|
|
|
|
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
|
|
|
|
}
|
|
|
|
|
2019-04-22 16:19:08 +02:00
|
|
|
public QueryableList<Organisation> getAuthenticated(QueryableList<Organisation> query, UserInfo principal) {
|
2021-04-30 13:45:00 +02:00
|
|
|
query.where((builder, root) -> builder.equal(root.join("dmps").join("users").get("user"), principal));
|
2019-04-22 16:19:08 +02:00
|
|
|
return query;
|
|
|
|
}
|
|
|
|
|
2018-02-21 11:07:31 +01:00
|
|
|
@Override
|
|
|
|
public Organisation find(UUID id, String hint) {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
2017-09-14 12:37:36 +02:00
|
|
|
}
|