no message
This commit is contained in:
parent
ca1593d5a7
commit
b4f59b0ce6
|
@ -88,6 +88,17 @@ public class DMPs extends BaseController {
|
|||
}
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/dmps/clone/{id}"}, consumes = "application/json", produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<DMP>> clone(@PathVariable UUID id, @RequestBody eu.eudat.models.dmp.DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) {
|
||||
try {
|
||||
DataManagementPlanManager.clone(this.getApiContext(), id, dataManagementPlan, principal);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.NO_MESSAGE));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/dmps/get"}, consumes = "application/json", produces = "application/json")
|
||||
public @ResponseBody
|
||||
|
|
|
@ -31,7 +31,7 @@ public class DatasetProfiles extends BaseController {
|
|||
super(apiContext);
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/admin/datasetprofiles/get"}, produces = "application/json")
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/dmps/datasetprofiles/get"}, produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<List<DatasetProfileAutocompleteItem>>> get(@RequestBody DatasetProfileAutocompleteRequest datasetProfileAutocompleteRequest) {
|
||||
try {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package eu.eudat.dao.entities;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -13,6 +14,8 @@ import eu.eudat.models.datasetwizard.DatasetWizardAutocompleteRequest;
|
|||
import eu.eudat.queryable.QueryableList;
|
||||
|
||||
import eu.eudat.entities.DMP;
|
||||
import eu.eudat.queryable.types.FieldSelectionType;
|
||||
import eu.eudat.queryable.types.SelectionField;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
@ -36,8 +39,11 @@ public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
|
|||
query.where((builder, root) -> builder.greaterThan(root.get("created"), criteria.getPeriodStart()));
|
||||
if (criteria.getProjects() != null && !criteria.getProjects().isEmpty())
|
||||
query.where(((builder, root) -> root.get("project").in(criteria.getProjectEntities())));
|
||||
if (!criteria.getAllVersions())
|
||||
query.where((builder, root) -> builder.equal(root.get("version"), query.<String>subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.equal(externalRoot.get("groupId"), nestedRoot.get("groupId")), Arrays.asList(new SelectionField(FieldSelectionType.FIELD, "version")), String.class)));
|
||||
if (criteria.getGroupIds() != null && !criteria.getGroupIds().isEmpty())
|
||||
query.where((builder, root) -> root.get("groupId").in(criteria.getGroupIds()));
|
||||
query.where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue()));
|
||||
query.where((builder, root) -> builder.not(root.get("id").in(query.subQuery((builder1, root1) -> root1.get("previous").isNotNull(), Arrays.asList("previous")))));
|
||||
return query;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,8 +48,8 @@ public class DatasetDaoImpl extends DatabaseAccess<Dataset> implements DatasetDa
|
|||
}
|
||||
|
||||
@Override
|
||||
public Dataset find(UUID id,String hint) {
|
||||
return getDatabaseService().getQueryable(Dataset.getHints(),Dataset.class).withHint(hint).where((builder, root) -> builder.equal((root.get("id")), id)).getSingle();
|
||||
public Dataset find(UUID id, String hint) {
|
||||
return getDatabaseService().getQueryable(Dataset.getHints(), Dataset.class).withHint(hint).where((builder, root) -> builder.equal((root.get("id")), id)).getSingle();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -67,9 +67,8 @@ public class DMP implements Serializable, DataEntity<DMP> {
|
|||
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
||||
private UUID id;
|
||||
|
||||
@OneToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "\"Previous\"")
|
||||
private DMP previous;
|
||||
@Column(name = "\"GroupId\"", columnDefinition = "BINARY(16)")
|
||||
private UUID groupId;
|
||||
|
||||
@Column(name = "\"Label\"")
|
||||
private String label;
|
||||
|
@ -206,12 +205,12 @@ public class DMP implements Serializable, DataEntity<DMP> {
|
|||
this.id = id;
|
||||
}
|
||||
|
||||
public DMP getPrevious() {
|
||||
return previous;
|
||||
public UUID getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setPrevious(DMP previous) {
|
||||
this.previous = previous;
|
||||
public void setGroupId(UUID groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
|
|
|
@ -83,12 +83,25 @@ public class DataManagementPlanManager {
|
|||
user.setId(principal.getId());
|
||||
createProjectIfItDoesntExist(newDmp, apiContext.getDatabaseRepository().getProjectDao(), user);
|
||||
newDmp.setCreator(user);
|
||||
newDmp.setPrevious(oldDmp);
|
||||
newDmp.setGroupId(oldDmp.getGroupId());
|
||||
newDmp.setVersion(oldDmp.getVersion() + 1);
|
||||
newDmp.setId(null);
|
||||
newDmp = apiContext.getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
|
||||
copyDatasets(newDmp, apiContext.getDatabaseRepository().getDatasetDao());
|
||||
}
|
||||
|
||||
public static void clone(ApiContext apiContext, UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {DMP newDmp = dataManagementPlan.toDataModel();
|
||||
createOrganisationsIfTheyDontExist(newDmp, apiContext.getDatabaseRepository().getOrganisationDao());
|
||||
createResearchersIfTheyDontExist(newDmp, apiContext.getDatabaseRepository().getResearcherDao());
|
||||
UserInfo user = new UserInfo();
|
||||
user.setId(principal.getId());
|
||||
createProjectIfItDoesntExist(newDmp, apiContext.getDatabaseRepository().getProjectDao(), user);
|
||||
newDmp.setCreator(user);
|
||||
newDmp.setGroupId(UUID.randomUUID());
|
||||
newDmp.setVersion(0);
|
||||
newDmp.setId(null);
|
||||
newDmp = apiContext.getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
|
||||
copyDatasets(newDmp, apiContext.getDatabaseRepository().getDatasetDao());
|
||||
}
|
||||
|
||||
public static void delete(ApiContext apiContext, UUID uuid) throws DMPWithDatasetsException {
|
||||
|
|
|
@ -11,10 +11,30 @@ import java.util.List;
|
|||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DataManagementPlanCriteria extends Criteria<DMP>{
|
||||
public class DataManagementPlanCriteria extends Criteria<DMP> {
|
||||
private Date periodStart;
|
||||
private Date periodEnd;
|
||||
private boolean allVersions;
|
||||
private List<UUID> groupIds;
|
||||
|
||||
public boolean getAllVersions() {
|
||||
return allVersions;
|
||||
}
|
||||
|
||||
public void setAllVersions(boolean allVersions) {
|
||||
this.allVersions = allVersions;
|
||||
}
|
||||
|
||||
public List<UUID> getGroupIds() {
|
||||
return groupIds;
|
||||
}
|
||||
|
||||
public void setGroupIds(List<UUID> groupIds) {
|
||||
this.groupIds = groupIds;
|
||||
}
|
||||
|
||||
private List<ProjectCriteriaModel> projects;
|
||||
|
||||
public Date getPeriodStart() {
|
||||
return periodStart;
|
||||
}
|
||||
|
@ -41,7 +61,7 @@ public class DataManagementPlanCriteria extends Criteria<DMP>{
|
|||
|
||||
public List<eu.eudat.entities.Project> getProjectEntities() {
|
||||
try {
|
||||
return new DomainModelConverter<eu.eudat.entities.Project,ProjectCriteriaModel>().toDataModel(this.projects);
|
||||
return new DomainModelConverter<eu.eudat.entities.Project, ProjectCriteriaModel>().toDataModel(this.projects);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return new LinkedList<>();
|
||||
|
|
|
@ -18,7 +18,7 @@ import java.util.stream.Collectors;
|
|||
public class DataManagementPlan implements DataModel<DMP> {
|
||||
private UUID id;
|
||||
private String label;
|
||||
private DataManagementPlan previous;
|
||||
private UUID groupId;
|
||||
private int version;
|
||||
private int status;
|
||||
private String description;
|
||||
|
@ -46,12 +46,12 @@ public class DataManagementPlan implements DataModel<DMP> {
|
|||
this.label = label;
|
||||
}
|
||||
|
||||
public DataManagementPlan getPrevious() {
|
||||
return previous;
|
||||
public UUID getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setPrevious(DataManagementPlan previous) {
|
||||
this.previous = previous;
|
||||
public void setGroupId(UUID groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public List<UserInfo> getAssociatedUsers() {
|
||||
|
@ -140,7 +140,7 @@ public class DataManagementPlan implements DataModel<DMP> {
|
|||
this.organisations = new DomainModelConverter<eu.eudat.entities.Organisation, Organisation>().fromDataModel(entity.getOrganisations().stream().collect(Collectors.toList()), Organisation.class);
|
||||
this.researchers = new DomainModelConverter<eu.eudat.entities.Researcher, Researcher>().fromDataModel(entity.getResearchers().stream().collect(Collectors.toList()), Researcher.class);
|
||||
this.version = entity.getVersion();
|
||||
this.previous = this.previous == null ? null : new DomainModelConverter<DMP, DataManagementPlan>().fromDataModel(Arrays.asList(entity.getPrevious()), DataManagementPlan.class).get(0);
|
||||
this.groupId = this.groupId == null ? null : this.groupId;
|
||||
this.label = entity.getLabel();
|
||||
this.project = new Project();
|
||||
this.project.fromDataModel(entity.getProject());
|
||||
|
|
|
@ -19,7 +19,7 @@ import java.util.*;
|
|||
public class DataManagementPlanNewVersionModel implements DataModel<DMP> {
|
||||
private UUID id;
|
||||
private String label;
|
||||
private DataManagementPlan previous;
|
||||
private UUID groupId;
|
||||
private int version;
|
||||
private int status;
|
||||
private String description;
|
||||
|
@ -48,12 +48,12 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP> {
|
|||
this.label = label;
|
||||
}
|
||||
|
||||
public DataManagementPlan getPrevious() {
|
||||
return previous;
|
||||
public UUID getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setPrevious(DataManagementPlan previous) {
|
||||
this.previous = previous;
|
||||
public void setGroupId(UUID groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
|
@ -156,13 +156,13 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP> {
|
|||
entity.setUsers(new HashSet<>(new DomainModelConverter<eu.eudat.entities.UserInfo, UserInfo>().toDataModel(this.associatedUsers)));
|
||||
entity.setDescription(this.description);
|
||||
entity.setStatus((short) this.status);
|
||||
entity.setPrevious(this.previous == null ? null : new DomainModelConverter<DMP, DataManagementPlan>().toDataModel(Arrays.asList(this.previous)).get(0));
|
||||
entity.setGroupId(this.groupId == null ? UUID.randomUUID() : this.groupId);
|
||||
entity.setCreated(new Date());
|
||||
entity.setLabel(this.label);
|
||||
entity.setModified(new Date());
|
||||
List<eu.eudat.entities.Dataset> datasets = new LinkedList<>();
|
||||
if(this.datasets!=null){
|
||||
for (Dataset dataset :this.datasets){
|
||||
if (this.datasets != null) {
|
||||
for (Dataset dataset : this.datasets) {
|
||||
eu.eudat.entities.Dataset entityDataset = new eu.eudat.entities.Dataset();
|
||||
entityDataset.setId(dataset.getId());
|
||||
datasets.add(entityDataset);
|
||||
|
|
|
@ -10,6 +10,7 @@ import eu.eudat.utilities.helpers.LabelBuilder;
|
|||
import eu.eudat.utilities.helpers.LabelGenerator;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
|
@ -21,6 +22,7 @@ public class DataManagementPlanListingModel implements DataModel<DMP> {
|
|||
private String creationTime;
|
||||
private String organisations;
|
||||
private String version;
|
||||
private UUID groupId;
|
||||
private Integer numOfDatasets;
|
||||
|
||||
public String getId() {
|
||||
|
@ -79,6 +81,14 @@ public class DataManagementPlanListingModel implements DataModel<DMP> {
|
|||
this.version = version;
|
||||
}
|
||||
|
||||
public UUID getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setGroupId(UUID groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public Integer getNumOfDatasets() {
|
||||
return numOfDatasets;
|
||||
}
|
||||
|
@ -96,6 +106,7 @@ public class DataManagementPlanListingModel implements DataModel<DMP> {
|
|||
this.organisations =LabelBuilder.getLabel(new DomainModelConverter<eu.eudat.entities.Organisation,Organisation>().fromDataModel(entity.getOrganisations().stream().collect(Collectors.toList()),Organisation.class));
|
||||
this.creationTime = entity.getCreated().toString();
|
||||
this.version = ""+entity.getVersion();
|
||||
this.groupId = entity.getGroupId();
|
||||
this.numOfDatasets = entity.getDataset().size();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,9 +2,11 @@ package eu.eudat.queryable;
|
|||
|
||||
|
||||
import eu.eudat.entities.DataEntity;
|
||||
import eu.eudat.queryable.predicates.NestedQuerySinglePredicate;
|
||||
import eu.eudat.queryable.predicates.OrderByPredicate;
|
||||
import eu.eudat.queryable.predicates.SelectPredicate;
|
||||
import eu.eudat.queryable.predicates.SinglePredicate;
|
||||
import eu.eudat.queryable.types.SelectionField;
|
||||
|
||||
import javax.persistence.criteria.Subquery;
|
||||
import java.util.List;
|
||||
|
@ -42,8 +44,19 @@ public interface QueryableList<T extends DataEntity<T>> {
|
|||
|
||||
Long count();
|
||||
|
||||
QueryableList<T> where(NestedQuerySinglePredicate<T> predicate);
|
||||
|
||||
CompletableFuture<Long> countAsync();
|
||||
|
||||
Subquery<T> subQuery(SinglePredicate<T> predicate,List<String> fields);
|
||||
Subquery<T> subQuery(SinglePredicate<T> predicate,List<SelectionField> fields);
|
||||
|
||||
Subquery<T> subQuery(NestedQuerySinglePredicate<T> predicate, List<SelectionField> fields);
|
||||
|
||||
Subquery<Long> subQueryCount(NestedQuerySinglePredicate<T> predicate, List<SelectionField> fields);
|
||||
|
||||
Subquery<Long> subQueryCount(SinglePredicate<T> predicate, List<SelectionField> fields);
|
||||
|
||||
<U extends Comparable> Subquery<U> subQueryMax(SinglePredicate<T> predicate, List<SelectionField> fields,Class<U> uClass);
|
||||
|
||||
<U extends Comparable> Subquery<U> subQueryMax(NestedQuerySinglePredicate<T> predicate, List<SelectionField> fields,Class<U> uClass);
|
||||
}
|
||||
|
|
|
@ -4,15 +4,19 @@ 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.NestedQuerySinglePredicate;
|
||||
import eu.eudat.queryable.predicates.OrderByPredicate;
|
||||
import eu.eudat.queryable.predicates.SelectPredicate;
|
||||
import eu.eudat.queryable.predicates.SinglePredicate;
|
||||
import eu.eudat.queryable.types.SelectionField;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.TypedQuery;
|
||||
import javax.persistence.criteria.*;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -25,8 +29,11 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
|||
private CriteriaQuery<T> query;
|
||||
private Class<T> tClass;
|
||||
private Root<T> root;
|
||||
private Root<T> nestedQueryRoot;
|
||||
private Subquery<T> subquery;
|
||||
private List<SinglePredicate<T>> predicates = new LinkedList<>();
|
||||
private List<SinglePredicate<T>> singlePredicates = new LinkedList<>();
|
||||
private List<NestedQuerySinglePredicate<T>> nestedPredicates = new LinkedList<>();
|
||||
|
||||
private List<OrderByPredicate<T>> orderings = new LinkedList<>();
|
||||
private List<Selection> fields = new LinkedList<>();
|
||||
private Integer length;
|
||||
|
@ -79,7 +86,12 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
|||
}
|
||||
|
||||
public QueryableList<T> where(SinglePredicate<T> predicate) {
|
||||
this.predicates.add(predicate);
|
||||
this.singlePredicates.add(predicate);
|
||||
return this;
|
||||
}
|
||||
|
||||
public QueryableList<T> where(NestedQuerySinglePredicate<T> predicate) {
|
||||
this.nestedPredicates.add(predicate);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -107,7 +119,7 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
|||
CriteriaQuery<Long> criteriaQuery = criteriaBuilder.createQuery(Long.class);
|
||||
Root<T> root = criteriaQuery.from(tClass);
|
||||
criteriaQuery.select(criteriaBuilder.count(root));
|
||||
criteriaQuery.where(this.generateWherePredicates(this.predicates, root));
|
||||
criteriaQuery.where(this.generateWherePredicates(this.singlePredicates, root, this.nestedPredicates, this.nestedQueryRoot));
|
||||
return this.manager.createQuery(criteriaQuery).getSingleResult();
|
||||
}
|
||||
|
||||
|
@ -116,11 +128,19 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
|||
CriteriaQuery<Long> criteriaQuery = criteriaBuilder.createQuery(Long.class);
|
||||
Root<T> root = criteriaQuery.from(tClass);
|
||||
criteriaQuery.select(criteriaBuilder.count(root));
|
||||
criteriaQuery.where(this.generateWherePredicates(this.predicates, root));
|
||||
criteriaQuery.where(this.generateWherePredicates(this.singlePredicates, root, this.nestedPredicates, this.nestedQueryRoot));
|
||||
return CompletableFuture.supplyAsync(() -> this.manager.createQuery(criteriaQuery).getSingleResult());
|
||||
}
|
||||
|
||||
private Predicate[] generateWherePredicates(List<SinglePredicate<T>> singlePredicates, Root<T> root) {
|
||||
|
||||
private Predicate[] generateWherePredicates(List<SinglePredicate<T>> singlePredicates, Root<T> root, List<NestedQuerySinglePredicate<T>> nestedPredicates, Root<T> nestedQueryRoot) {
|
||||
List<Predicate> predicates = new LinkedList<>();
|
||||
predicates.addAll(Arrays.asList(this.generateSingleWherePredicates(singlePredicates, root)));
|
||||
predicates.addAll(Arrays.asList(this.generateNestedWherePredicates(nestedPredicates, root, nestedQueryRoot)));
|
||||
return predicates.toArray(new Predicate[predicates.size()]);
|
||||
}
|
||||
|
||||
private Predicate[] generateSingleWherePredicates(List<SinglePredicate<T>> singlePredicates, Root<T> root) {
|
||||
List<Predicate> predicates = new LinkedList<>();
|
||||
for (SinglePredicate<T> singlePredicate : singlePredicates) {
|
||||
predicates.add(singlePredicate.applyPredicate(this.manager.getCriteriaBuilder(), root));
|
||||
|
@ -128,6 +148,14 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
|||
return predicates.toArray(new Predicate[predicates.size()]);
|
||||
}
|
||||
|
||||
private Predicate[] generateNestedWherePredicates(List<NestedQuerySinglePredicate<T>> nestedPredicates, Root<T> root, Root<T> nestedQueryRoot) {
|
||||
List<Predicate> predicates = new LinkedList<>();
|
||||
for (NestedQuerySinglePredicate<T> singlePredicate : nestedPredicates) {
|
||||
predicates.add(singlePredicate.applyPredicate(this.manager.getCriteriaBuilder(), root, nestedQueryRoot));
|
||||
}
|
||||
return predicates.toArray(new Predicate[predicates.size()]);
|
||||
}
|
||||
|
||||
private Order[] generateOrderPredicates(List<OrderByPredicate<T>> orderByPredicates, Root<T> root) {
|
||||
List<Order> predicates = new LinkedList<>();
|
||||
for (OrderByPredicate<T> orderPredicate : orderByPredicates) {
|
||||
|
@ -138,7 +166,7 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
|||
|
||||
public List<T> toList() {
|
||||
|
||||
this.query.where(this.generateWherePredicates(this.predicates, this.root));
|
||||
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
||||
if (!this.orderings.isEmpty()) this.query.orderBy(this.generateOrderPredicates(this.orderings, this.root));
|
||||
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
||||
if (this.offset != null) typedQuery.setFirstResult(this.offset);
|
||||
|
@ -151,7 +179,7 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
|||
}
|
||||
|
||||
public CompletableFuture<List<T>> toListAsync() {
|
||||
this.query.where(this.generateWherePredicates(this.predicates, this.root));
|
||||
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
||||
if (!this.orderings.isEmpty()) this.query.orderBy(this.generateOrderPredicates(this.orderings, this.root));
|
||||
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
||||
if (this.offset != null) typedQuery.setFirstResult(this.offset);
|
||||
|
@ -165,7 +193,7 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
|||
}
|
||||
|
||||
public T getSingle() {
|
||||
this.query.where(this.generateWherePredicates(this.predicates, this.root));
|
||||
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
||||
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
||||
if (this.hint != null)
|
||||
typedQuery.setHint("javax.persistence.fetchgraph", this.manager.getEntityGraph(this.hint));
|
||||
|
@ -173,7 +201,7 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
|||
}
|
||||
|
||||
public CompletableFuture<T> getSingleAsync() {
|
||||
this.query.where(this.generateWherePredicates(this.predicates, this.root));
|
||||
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
||||
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
||||
if (this.hint != null)
|
||||
typedQuery.setHint("javax.persistence.fetchgraph", this.manager.getEntityGraph(this.hint));
|
||||
|
@ -181,7 +209,7 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
|||
}
|
||||
|
||||
public T getSingleOrDefault() {
|
||||
this.query.where(this.generateWherePredicates(this.predicates, this.root));
|
||||
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
||||
|
||||
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
||||
if (this.hint != null)
|
||||
|
@ -193,7 +221,7 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
|||
}
|
||||
|
||||
public CompletableFuture<T> getSingleOrDefaultAsync() {
|
||||
this.query.where(this.generateWherePredicates(this.predicates, this.root));
|
||||
this.query.where(this.generateWherePredicates(this.singlePredicates, this.root, this.nestedPredicates, this.nestedQueryRoot));
|
||||
|
||||
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
||||
if (this.hint != null)
|
||||
|
@ -220,11 +248,56 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
|
|||
}
|
||||
|
||||
@Override
|
||||
public Subquery<T> subQuery(SinglePredicate<T> predicate, List<String> fields) {
|
||||
public Subquery<T> subQuery(SinglePredicate<T> predicate, List<SelectionField> fields) {
|
||||
Subquery<T> subquery = this.manager.getCriteriaBuilder().createQuery().subquery(this.tClass);
|
||||
Root<T> root = subquery.from(this.tClass);
|
||||
subquery.where(predicate.applyPredicate(this.manager.getCriteriaBuilder(), root));
|
||||
subquery.select(root.get(fields.get(0)));
|
||||
this.nestedQueryRoot = subquery.from(this.tClass);
|
||||
subquery.where(predicate.applyPredicate(this.manager.getCriteriaBuilder(), this.nestedQueryRoot));
|
||||
subquery.select(this.nestedQueryRoot.get(fields.get(0).getField()));
|
||||
return subquery;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Subquery<T> subQuery(NestedQuerySinglePredicate<T> predicate, List<SelectionField> fields) {
|
||||
Subquery<T> subquery = this.manager.getCriteriaBuilder().createQuery().subquery(this.tClass);
|
||||
this.nestedQueryRoot = subquery.from(this.tClass);
|
||||
subquery.where(predicate.applyPredicate(this.manager.getCriteriaBuilder(), this.root, this.nestedQueryRoot));
|
||||
subquery.select(this.nestedQueryRoot.get(fields.get(0).getField()));
|
||||
return subquery;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Subquery<Long> subQueryCount(SinglePredicate<T> predicate, List<SelectionField> fields) {
|
||||
Subquery<Long> subquery = this.manager.getCriteriaBuilder().createQuery().subquery(Long.class);
|
||||
this.nestedQueryRoot = subquery.from(this.tClass);
|
||||
subquery.where(predicate.applyPredicate(this.manager.getCriteriaBuilder(), this.nestedQueryRoot));
|
||||
subquery.select(this.manager.getCriteriaBuilder().count(this.nestedQueryRoot.get(fields.get(0).getField())));
|
||||
return subquery;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Subquery<Long> subQueryCount(NestedQuerySinglePredicate<T> predicate, List<SelectionField> fields) {
|
||||
Subquery<Long> subquery = this.manager.getCriteriaBuilder().createQuery().subquery(Long.class);
|
||||
this.nestedQueryRoot = subquery.from(this.tClass);
|
||||
subquery.where(predicate.applyPredicate(this.manager.getCriteriaBuilder(), this.root, this.nestedQueryRoot));
|
||||
subquery.select(this.manager.getCriteriaBuilder().count(this.nestedQueryRoot.get(fields.get(0).getField())));
|
||||
return subquery;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U extends Comparable> Subquery<U> subQueryMax(SinglePredicate<T> predicate, List<SelectionField> fields,Class<U> uClass) {
|
||||
Subquery<U> subquery = this.manager.getCriteriaBuilder().createQuery().subquery(uClass);
|
||||
this.nestedQueryRoot = subquery.from(this.tClass);
|
||||
subquery.where(predicate.applyPredicate(this.manager.getCriteriaBuilder(), this.nestedQueryRoot));
|
||||
subquery.select(this.manager.getCriteriaBuilder().greatest(this.nestedQueryRoot.<U>get(fields.get(0).getField())));
|
||||
return subquery;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U extends Comparable> Subquery<U> subQueryMax(NestedQuerySinglePredicate<T> predicate, List<SelectionField> fields,Class<U> uClass) {
|
||||
Subquery<U> subquery = this.manager.getCriteriaBuilder().createQuery().subquery(uClass);
|
||||
this.nestedQueryRoot = subquery.from(this.tClass);
|
||||
subquery.where(predicate.applyPredicate(this.manager.getCriteriaBuilder(), this.root, this.nestedQueryRoot));
|
||||
subquery.select(this.manager.getCriteriaBuilder().greatest(this.nestedQueryRoot.<U>get(fields.get(0).getField())));
|
||||
return subquery;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package eu.eudat.queryable.predicates;
|
||||
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 2/7/2018.
|
||||
*/
|
||||
public interface NestedQuerySinglePredicate<T> {
|
||||
Predicate applyPredicate(CriteriaBuilder builder, Root<T> root, Root<T> nestedQueryRoot);
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package eu.eudat.queryable.predicates;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 2/7/2018.
|
||||
*/
|
||||
public interface QueryablePredicate<T> {
|
||||
}
|
|
@ -5,5 +5,5 @@ import javax.persistence.criteria.Predicate;
|
|||
import javax.persistence.criteria.Root;
|
||||
|
||||
public interface SinglePredicate<T> {
|
||||
Predicate applyPredicate(CriteriaBuilder builder, Root<T> root) ;
|
||||
Predicate applyPredicate(CriteriaBuilder builder, Root<T> root);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package eu.eudat.queryable.types;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 2/7/2018.
|
||||
*/
|
||||
public enum FieldSelectionType {
|
||||
FIELD, COUNT, MAX
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package eu.eudat.queryable.types;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 2/7/2018.
|
||||
*/
|
||||
public class SelectionField {
|
||||
private FieldSelectionType type = FieldSelectionType.FIELD;
|
||||
private String field;
|
||||
|
||||
public SelectionField(String field) {
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
public SelectionField(FieldSelectionType type, String field) {
|
||||
this.type = type;
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
public FieldSelectionType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(FieldSelectionType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getField() {
|
||||
return field;
|
||||
}
|
||||
|
||||
public void setField(String field) {
|
||||
this.field = field;
|
||||
}
|
||||
}
|
|
@ -6,9 +6,11 @@ import { RouterModule, Routes } from '@angular/router';
|
|||
|
||||
const routes: Routes = [
|
||||
{ path: '', component: DataManagementPlanListingComponent },
|
||||
{ path: 'viewversions/:groupId', component: DataManagementPlanListingComponent },
|
||||
{ path: 'edit/:id', component: DataManagementPlanEditorComponent },
|
||||
{ path: 'new', component: DataManagementPlanEditorComponent },
|
||||
{ path: 'new_version/:id', component: DataManagementPlanWizardComponent, data: { clone: "clone" } },
|
||||
{ path: 'new_version/:id', component: DataManagementPlanWizardComponent, data: { clone: false } },
|
||||
{ path: 'clone/:id', component: DataManagementPlanWizardComponent, data: { clone: true } }
|
||||
];
|
||||
|
||||
export const DataManagementPlanRoutes = RouterModule.forChild(routes);
|
||||
|
|
|
@ -60,6 +60,8 @@
|
|||
<button mat-menu-item (click)="addDataset(row.id)"><mat-icon>add</mat-icon>{{'DMP-LISTING.ACTIONS.ADD-DATASET' | translate}}</button>
|
||||
<button mat-menu-item (click)="showDatasets(row.id)"><mat-icon>list</mat-icon>{{'DMP-LISTING.ACTIONS.DATASETS' | translate}}</button>
|
||||
<button mat-menu-item (click)="newVersion(row.id)"><mat-icon>filter_none</mat-icon>{{'DMP-LISTING.ACTIONS.NEW-VERSION' | translate}}</button>
|
||||
<button mat-menu-item (click)="viewVersions(row.groupId)"><mat-icon>filter_none</mat-icon>{{'DMP-LISTING.ACTIONS.VIEW-VERSION' | translate}}</button>
|
||||
<button mat-menu-item (click)="clone(row.id)"><mat-icon>filter_none</mat-icon>{{'DMP-LISTING.ACTIONS.CLONE' | translate}}</button>
|
||||
</mat-menu>
|
||||
<button mat-icon-button [matMenuTriggerFor]="actionsMenu">
|
||||
<mat-icon>more_vert</mat-icon>
|
||||
|
|
|
@ -8,7 +8,7 @@ import {
|
|||
import { DataManagementPlanService } from '../../services/data-management-plan/data-management-plan.service';
|
||||
import { Component, ViewChild, OnInit, AfterViewInit } from "@angular/core";
|
||||
import { MatPaginator, MatSort, MatSnackBar, MatDialog } from "@angular/material";
|
||||
import { Router } from "@angular/router";
|
||||
import { Router, ActivatedRoute } from "@angular/router";
|
||||
import { TranslateService } from "@ngx-translate/core";
|
||||
import { DataSource } from "@angular/cdk/table";
|
||||
import { Observable } from "rxjs/Observable";
|
||||
|
@ -30,10 +30,12 @@ export class DataManagementPlanListingComponent implements OnInit {
|
|||
|
||||
dataSource: DataManagementPlanDataSource | null;
|
||||
displayedColumns: String[] = ['name', 'project', 'creationTime', 'organisations', 'version', 'numOfDatasets', 'actions'];
|
||||
itemId: string;
|
||||
|
||||
constructor(
|
||||
private dataManagementPlanService: DataManagementPlanService,
|
||||
private router: Router,
|
||||
private route: ActivatedRoute,
|
||||
private languageService: TranslateService,
|
||||
public snackBar: MatSnackBar,
|
||||
public dialog: MatDialog
|
||||
|
@ -42,13 +44,17 @@ export class DataManagementPlanListingComponent implements OnInit {
|
|||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.params.subscribe(params => {
|
||||
this.itemId = params['groupId'];
|
||||
this.criteria.setCriteria(this.getDefaultCriteria());
|
||||
this.refresh();
|
||||
this.criteria.setRefreshCallback(() => this.refresh());
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
refresh() {
|
||||
this.dataSource = new DataManagementPlanDataSource(this.dataManagementPlanService, this._paginator, this.sort, this.languageService, this.snackBar, this.criteria, );
|
||||
this.dataSource = new DataManagementPlanDataSource(this.dataManagementPlanService, this._paginator, this.sort, this.languageService, this.snackBar, this.criteria, this.itemId);
|
||||
}
|
||||
|
||||
rowClick(rowId: String) {
|
||||
|
@ -67,6 +73,14 @@ export class DataManagementPlanListingComponent implements OnInit {
|
|||
this.router.navigate(['/dmps/new_version/' + rowId]);
|
||||
}
|
||||
|
||||
viewVersions(rowId: String) {
|
||||
this.router.navigate(['/dmps/viewversions/' + rowId]);
|
||||
}
|
||||
|
||||
clone(rowId: String) {
|
||||
this.router.navigate(['/dmps/clone/' + rowId]);
|
||||
}
|
||||
|
||||
getDefaultCriteria(): DataManagementPlanCriteria {
|
||||
const defaultCriteria = new DataManagementPlanCriteria();
|
||||
return defaultCriteria;
|
||||
|
@ -88,14 +102,14 @@ export class DataManagementPlanDataSource extends DataSource<DataManagementPlanL
|
|||
|
||||
totalCount = 0;
|
||||
isLoadingResults = false;
|
||||
|
||||
constructor(
|
||||
private _service: DataManagementPlanService,
|
||||
private _paginator: MatPaginator,
|
||||
private _sort: MatSort,
|
||||
private _languageService: TranslateService,
|
||||
private _snackBar: MatSnackBar,
|
||||
private _criteria: DataManagementPlanCriteriaComponent
|
||||
private _criteria: DataManagementPlanCriteriaComponent,
|
||||
private itemId
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
@ -116,6 +130,10 @@ export class DataManagementPlanDataSource extends DataSource<DataManagementPlanL
|
|||
if (this._sort.active) fields = this._sort.direction === "asc" ? ["+" + this._sort.active] : ["-" + this._sort.active];
|
||||
const request = new DataTableRequest<DataManagementPlanCriteria>(startIndex, this._paginator.pageSize, { fields: fields });
|
||||
request.criteria = this._criteria.criteria;
|
||||
if (this.itemId) {
|
||||
request.criteria.groupIds = [this.itemId];
|
||||
request.criteria.allVersions = true;
|
||||
}
|
||||
return this._service.getPaged(request);
|
||||
})
|
||||
/*.catch((error: any) => {
|
||||
|
|
|
@ -26,6 +26,8 @@ export class DataManagementPlanWizardComponent implements OnInit {
|
|||
itemId: string
|
||||
dataManagementPlan: DataManagementPlanModel;
|
||||
formGroup: FormGroup
|
||||
isClone: boolean
|
||||
|
||||
ngOnInit(): void {
|
||||
this.route.params.subscribe((params: Params) => {
|
||||
this.itemId = params['id'];
|
||||
|
@ -33,18 +35,25 @@ export class DataManagementPlanWizardComponent implements OnInit {
|
|||
.subscribe(data => {
|
||||
this.dataManagementPlan = JsonSerializer.fromJSONObject(data, DataManagementPlanModel);
|
||||
this.formGroup = this.dataManagementPlan.buildForm();
|
||||
this.isClone = this.route.snapshot.data.clone;
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
submit() {
|
||||
debugger;
|
||||
if (this.isClone) {
|
||||
this.dataManagementPlanService.clone(this.formGroup.value, this.itemId).subscribe(
|
||||
complete => this.onCallbackSuccess(),
|
||||
error => this.onCallbackError(error)
|
||||
);
|
||||
} else {
|
||||
this.dataManagementPlanService.newVersion(this.formGroup.value, this.itemId).subscribe(
|
||||
complete => this.onCallbackSuccess(),
|
||||
error => this.onCallbackError(error)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
onCallbackSuccess(): void {
|
||||
this.snackBar.openFromComponent(SnackBarNotificationComponent, {
|
||||
|
|
|
@ -3,4 +3,6 @@ import { ProjectModel } from "../../projects/ProjectModel";
|
|||
|
||||
export class DataManagementPlanCriteria extends BaseCriteria {
|
||||
public projects: ProjectModel[] = [];
|
||||
public groupIds: string[]
|
||||
public allVersions: boolean
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ export class DataManagementPlanListingModel implements Serializable<DataManageme
|
|||
public profile: String;
|
||||
public creationTime: String;
|
||||
public organisations: String;
|
||||
public groupId: string;
|
||||
public version: number;
|
||||
|
||||
fromJSONObject(item: any): DataManagementPlanListingModel {
|
||||
|
@ -17,7 +18,7 @@ export class DataManagementPlanListingModel implements Serializable<DataManageme
|
|||
this.creationTime = item.creationTime;
|
||||
this.organisations = item.organisations;
|
||||
this.version = item.version;
|
||||
|
||||
this.groupId = item.groupId;
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -15,7 +15,7 @@ import { DmpUsersModel } from "@app/models/dmpUsers/DmpUsersModel";
|
|||
export class DataManagementPlanModel implements Serializable<DataManagementPlanModel> {
|
||||
public id: String;
|
||||
public label: String;
|
||||
public previous: String;
|
||||
public groupId: String;
|
||||
public version: number;
|
||||
public status: Status = Status.Active;
|
||||
public description: String;
|
||||
|
@ -30,7 +30,7 @@ export class DataManagementPlanModel implements Serializable<DataManagementPlanM
|
|||
fromJSONObject(item: any): DataManagementPlanModel {
|
||||
this.id = item.id;
|
||||
this.label = item.label;
|
||||
this.previous = item.previous;
|
||||
this.groupId = item.groupId;
|
||||
this.version = item.version;
|
||||
this.status = item.status;
|
||||
this.description = item.description;
|
||||
|
@ -49,7 +49,7 @@ export class DataManagementPlanModel implements Serializable<DataManagementPlanM
|
|||
const formGroup = new FormBuilder().group({
|
||||
id: [{ value: this.id, disabled: disabled }, context.getValidation('id').validators],
|
||||
label: [{ value: this.label, disabled: disabled }, context.getValidation('label').validators],
|
||||
previous: [{ value: this.previous, disabled: disabled }, context.getValidation('previous').validators],
|
||||
groupId: [{ value: this.groupId, disabled: disabled }, context.getValidation('groupId').validators],
|
||||
version: [{ value: this.version, disabled: disabled }, context.getValidation('version').validators],
|
||||
status: [{ value: this.status, disabled: disabled }, context.getValidation('status').validators],
|
||||
description: [{ value: this.description, disabled: disabled }, context.getValidation('description').validators],
|
||||
|
@ -67,7 +67,7 @@ export class DataManagementPlanModel implements Serializable<DataManagementPlanM
|
|||
const baseContext: ValidationContext = new ValidationContext();
|
||||
baseContext.validation.push({ key: 'id', validators: [ BackendErrorValidator(this.errorModel, 'id')] });
|
||||
baseContext.validation.push({ key: 'label', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'label')] });
|
||||
baseContext.validation.push({ key: 'previous', validators: [BackendErrorValidator(this.errorModel, 'previous')] });
|
||||
baseContext.validation.push({ key: 'groupId', validators: [BackendErrorValidator(this.errorModel, 'groupId')] });
|
||||
baseContext.validation.push({ key: 'version', validators: [BackendErrorValidator(this.errorModel, 'version')] });
|
||||
baseContext.validation.push({ key: 'status', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'status')] });
|
||||
baseContext.validation.push({ key: 'description', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'description')] });
|
||||
|
|
|
@ -53,6 +53,10 @@ export class DataManagementPlanService {
|
|||
return this.http.post<DataManagementPlanModel>(this.actionUrl + 'new/' + id , dataManagementPlanModel, { headers: this.headers });
|
||||
}
|
||||
|
||||
clone(dataManagementPlanModel: DataManagementPlanModel, id:String): Observable<DataManagementPlanModel> {
|
||||
return this.http.post<DataManagementPlanModel>(this.actionUrl + 'clone/' + id , dataManagementPlanModel, { headers: this.headers });
|
||||
}
|
||||
|
||||
delete(id: String): Observable<DataManagementPlanModel> {
|
||||
return this.http.delete<DataManagementPlanModel>(this.actionUrl + 'delete/' + id, { headers: this.headers });
|
||||
}
|
||||
|
|
|
@ -57,7 +57,9 @@
|
|||
"INVITE": "Invite",
|
||||
"ADD-DATASET": "Add Dataset",
|
||||
"DATASETS": "Datasets",
|
||||
"NEW-VERSION": "New Version"
|
||||
"NEW-VERSION": "New Version",
|
||||
"VIEW-VERSION": "All Versions",
|
||||
"CLONE" : "Clone"
|
||||
}
|
||||
},
|
||||
"DATASET-WIZARD": {
|
||||
|
|
Loading…
Reference in New Issue