diff --git a/dmp-backend/src/main/java/eu/eudat/dao/entities/security/UserTokenDaoImpl.java b/dmp-backend/src/main/java/eu/eudat/dao/entities/security/UserTokenDaoImpl.java index b17ad1b74..d5b65d941 100644 --- a/dmp-backend/src/main/java/eu/eudat/dao/entities/security/UserTokenDaoImpl.java +++ b/dmp-backend/src/main/java/eu/eudat/dao/entities/security/UserTokenDaoImpl.java @@ -26,7 +26,7 @@ public class UserTokenDaoImpl extends DatabaseAccess implements UserT @Override public UserToken find(UUID id) { - return this.getDatabaseService().getQueryable(UserToken.class).where((builder, root) -> builder.equal(root.get("token"),id)).getSingle(); + return this.getDatabaseService().getQueryable(UserToken.class).where((builder, root) -> builder.equal(root.get("token"),id)).getSingleOrDefault(); } @Override diff --git a/dmp-backend/src/main/java/eu/eudat/queryable/QueryableList.java b/dmp-backend/src/main/java/eu/eudat/queryable/QueryableList.java index 3076b100d..48bff08db 100644 --- a/dmp-backend/src/main/java/eu/eudat/queryable/QueryableList.java +++ b/dmp-backend/src/main/java/eu/eudat/queryable/QueryableList.java @@ -19,6 +19,8 @@ public interface QueryableList> { T getSingle(); + T getSingleOrDefault(); + QueryableList skip(Integer offset); QueryableList take(Integer length); diff --git a/dmp-backend/src/main/java/eu/eudat/queryable/exceptions/NotSingleResultException.java b/dmp-backend/src/main/java/eu/eudat/queryable/exceptions/NotSingleResultException.java new file mode 100644 index 000000000..ef171fbdb --- /dev/null +++ b/dmp-backend/src/main/java/eu/eudat/queryable/exceptions/NotSingleResultException.java @@ -0,0 +1,19 @@ +package eu.eudat.queryable.exceptions; + +/** + * Created by ikalyvas on 1/30/2018. + */ +public class NotSingleResultException extends RuntimeException{ + public NotSingleResultException() { + super(); + } + public NotSingleResultException(String message, Throwable cause) { + super(message, cause); + } + public NotSingleResultException(String message) { + super(message); + } + public NotSingleResultException(Throwable cause) { + super(cause); + } +} \ No newline at end of file diff --git a/dmp-backend/src/main/java/eu/eudat/queryable/hibernatequeryablelist/QueryableHibernateList.java b/dmp-backend/src/main/java/eu/eudat/queryable/hibernatequeryablelist/QueryableHibernateList.java index 0dc6c6185..f09476ac4 100644 --- a/dmp-backend/src/main/java/eu/eudat/queryable/hibernatequeryablelist/QueryableHibernateList.java +++ b/dmp-backend/src/main/java/eu/eudat/queryable/hibernatequeryablelist/QueryableHibernateList.java @@ -3,6 +3,7 @@ package eu.eudat.queryable.hibernatequeryablelist; import eu.eudat.entities.DataEntity; import eu.eudat.queryable.QueryableList; +import eu.eudat.queryable.exceptions.NotSingleResultException; import eu.eudat.queryable.predicates.OrderByPredicate; import eu.eudat.queryable.predicates.SelectPredicate; import eu.eudat.queryable.predicates.SinglePredicate; @@ -133,6 +134,18 @@ public class QueryableHibernateList> implements Queryabl return typedQuery.getSingleResult(); } + public T getSingleOrDefault() { + Predicate[] array = new Predicate[this.predicates.size()]; + this.predicates.toArray(array); + this.query.where(array); + + TypedQuery typedQuery = this.manager.createQuery(this.query); + List results = typedQuery.getResultList(); + if (results.size() == 0) return null; + if (results.size() == 1) return results.get(0); + else throw new NotSingleResultException("Query returned more than one items"); + } + private TypedQuery queryWithHint(List ids) { CriteriaBuilder criteriaBuilder = this.manager.getCriteriaBuilder(); CriteriaQuery criteriaQuery = criteriaBuilder.createQuery(tClass); diff --git a/dmp-frontend/src/app/models/datasets/DatasetWizardModel.ts b/dmp-frontend/src/app/models/datasets/DatasetWizardModel.ts index 0fcfefbfa..e057b4181 100644 --- a/dmp-frontend/src/app/models/datasets/DatasetWizardModel.ts +++ b/dmp-frontend/src/app/models/datasets/DatasetWizardModel.ts @@ -26,7 +26,6 @@ export class DatasetWizardModel implements Serializable { public externalDatasets: ExternalDatasetModel[] = []; public dmp: DataManagementPlanModel = new DataManagementPlanModel(); public datasetProfileDefinition; - public properties: any; public errorModel: BaseErrorModel = new BaseErrorModel(); fromJSONObject(item: any): DatasetWizardModel {