no message
This commit is contained in:
parent
391fd20baf
commit
0120818f36
|
@ -2,17 +2,11 @@ package eu.eudat.controllers;
|
||||||
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
|
||||||
import eu.eudat.entities.DMP;
|
import eu.eudat.entities.DMP;
|
||||||
import eu.eudat.entities.Dataset;
|
|
||||||
import eu.eudat.entities.UserInfo;
|
|
||||||
import eu.eudat.models.criteria.DataManagementPlanCriteria;
|
|
||||||
import eu.eudat.models.criteria.OrganisationCriteria;
|
|
||||||
import eu.eudat.models.criteria.ResearcherCriteria;
|
|
||||||
import eu.eudat.models.dmp.DataManagementPlan;
|
import eu.eudat.models.dmp.DataManagementPlan;
|
||||||
import eu.eudat.models.dmp.DataManagementPlanCriteriaRequest;
|
import eu.eudat.models.dmp.DataManagementPlanCriteriaRequest;
|
||||||
import eu.eudat.models.dmp.DataManagementPlanTableRequest;
|
import eu.eudat.models.dmp.DataManagementPlanTableRequest;
|
||||||
|
@ -20,11 +14,10 @@ import eu.eudat.models.helpers.DataTableData;
|
||||||
import eu.eudat.models.helpers.responses.*;
|
import eu.eudat.models.helpers.responses.*;
|
||||||
import eu.eudat.models.listingmodels.DataManagementPlanListingModel;
|
import eu.eudat.models.listingmodels.DataManagementPlanListingModel;
|
||||||
import eu.eudat.models.security.Principal;
|
import eu.eudat.models.security.Principal;
|
||||||
import eu.eudat.validators.DataManagementTableRequestValidator;
|
import eu.eudat.validators.DataManagementPlanTableRequestValidator;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
|
||||||
import org.springframework.web.bind.WebDataBinder;
|
import org.springframework.web.bind.WebDataBinder;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@ -41,7 +34,6 @@ import eu.eudat.dao.entities.RegistryDao;
|
||||||
import eu.eudat.dao.entities.ResearcherDao;
|
import eu.eudat.dao.entities.ResearcherDao;
|
||||||
import eu.eudat.dao.entities.ServiceDao;
|
import eu.eudat.dao.entities.ServiceDao;
|
||||||
import eu.eudat.dao.entities.UserInfoDao;
|
import eu.eudat.dao.entities.UserInfoDao;
|
||||||
import eu.eudat.entities.responses.IDLabelPair;
|
|
||||||
import eu.eudat.managers.DataManagementPlanManager;
|
import eu.eudat.managers.DataManagementPlanManager;
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,12 +55,15 @@ public class DMPs {
|
||||||
@Autowired private ServiceDao serviceDao;
|
@Autowired private ServiceDao serviceDao;
|
||||||
@Autowired private UserInfoDao userInfoDao;
|
@Autowired private UserInfoDao userInfoDao;
|
||||||
|
|
||||||
|
@InitBinder
|
||||||
|
protected void initBinder(WebDataBinder binder){
|
||||||
|
binder.setValidator(new DataManagementPlanTableRequestValidator());
|
||||||
|
}
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.POST, value = { "/dmps/getPaged" }, consumes = "application/json", produces="application/json")
|
@RequestMapping(method = RequestMethod.POST, value = { "/dmps/getPaged" }, consumes = "application/json", produces="application/json")
|
||||||
public @ResponseBody ResponseItem<DataTableData<DataManagementPlanListingModel>> getPaged( @RequestBody DataManagementPlanTableRequest dataManagementPlanTableRequest) {
|
public @ResponseBody ResponseItem<DataTableData<DataManagementPlanListingModel>> getPaged(@Valid @RequestBody DataManagementPlanTableRequest dataManagementPlanTableRequest) {
|
||||||
try {
|
try {
|
||||||
DataTableData<DataManagementPlanListingModel> dataTable = new DataManagementPlanManager().getPaged(dMPDao, dataManagementPlanTableRequest);
|
DataTableData<DataManagementPlanListingModel> dataTable = new DataManagementPlanManager().getPaged(dMPDao, dataManagementPlanTableRequest);
|
||||||
|
|
||||||
return new ResponseItem<DataTableData<DataManagementPlanListingModel>>().status(HttpStatus.OK).payload(dataTable);
|
return new ResponseItem<DataTableData<DataManagementPlanListingModel>>().status(HttpStatus.OK).payload(dataTable);
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
|
|
@ -7,6 +7,8 @@ import eu.eudat.queryable.QueryableList;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by giannis on 7/17/2017.
|
* Created by giannis on 7/17/2017.
|
||||||
*/
|
*/
|
||||||
|
@ -19,6 +21,10 @@ public class DatabaseService<T extends DataEntity<T>> {
|
||||||
return this.databaseCtx.getQueryable(tClass);
|
return this.databaseCtx.getQueryable(tClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public QueryableList<T> getQueryable(Class<T> tClass,Set<String> hints) {
|
||||||
|
return this.databaseCtx.getQueryable(tClass).setHints(hints);
|
||||||
|
}
|
||||||
|
|
||||||
public T createOrUpdate(T item, Class<T> tClass) {
|
public T createOrUpdate(T item, Class<T> tClass) {
|
||||||
return this.databaseCtx.createOrUpdate(item, tClass);
|
return this.databaseCtx.createOrUpdate(item, tClass);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ public class DMPDaoImpl implements DMPDao {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryableList<DMP> getWithCriteria(DataManagementPlanCriteria criteria) {
|
public QueryableList<DMP> getWithCriteria(DataManagementPlanCriteria criteria) {
|
||||||
QueryableList<DMP> query = databaseService.getQueryable(DMP.class);
|
QueryableList<DMP> query = databaseService.getQueryable(DMP.class,DMP.getHints());
|
||||||
if(criteria.getLike()!=null&&!criteria.getLike().isEmpty())query.where((builder, root) -> builder.like(root.get("label"),"%"+criteria.getLike()+"%"));
|
if(criteria.getLike()!=null&&!criteria.getLike().isEmpty())query.where((builder, root) -> builder.like(root.get("label"),"%"+criteria.getLike()+"%"));
|
||||||
if(criteria.getPeriodEnd()!=null)query.where((builder, root) -> builder.lessThan(root.get("created"),criteria.getPeriodEnd()));
|
if(criteria.getPeriodEnd()!=null)query.where((builder, root) -> builder.lessThan(root.get("created"),criteria.getPeriodEnd()));
|
||||||
if(criteria.getPeriodStart()!=null)query.where((builder, root) -> builder.greaterThan(root.get("created"),criteria.getPeriodStart()));
|
if(criteria.getPeriodStart()!=null)query.where((builder, root) -> builder.greaterThan(root.get("created"),criteria.getPeriodStart()));
|
||||||
|
|
|
@ -32,7 +32,7 @@ public class DatasetDaoImpl implements DatasetDao {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryableList<Dataset> getWithCriteria(DatasetCriteria criteria) {
|
public QueryableList<Dataset> getWithCriteria(DatasetCriteria criteria) {
|
||||||
QueryableList<Dataset> query = databaseService.getQueryable(Dataset.class);
|
QueryableList<Dataset> query = databaseService.getQueryable(Dataset.class,Dataset.getHints());
|
||||||
if(criteria.getLike()!=null&&!criteria.getLike().isEmpty())query.where((builder, root) -> builder.like(root.get("label"),"%"+criteria.getLike()+"%"));
|
if(criteria.getLike()!=null&&!criteria.getLike().isEmpty())query.where((builder, root) -> builder.like(root.get("label"),"%"+criteria.getLike()+"%"));
|
||||||
if(criteria.getStatus()!=null)query.where((builder, root) -> builder.equal(root.get("status"),criteria.getStatus()));
|
if(criteria.getStatus()!=null)query.where((builder, root) -> builder.equal(root.get("status"),criteria.getStatus()));
|
||||||
if(criteria.getPeriodEnd()!=null)query.where((builder, root) -> builder.lessThan(root.get("created"),criteria.getPeriodEnd()));
|
if(criteria.getPeriodEnd()!=null)query.where((builder, root) -> builder.lessThan(root.get("created"),criteria.getPeriodEnd()));
|
||||||
|
|
|
@ -2,20 +2,9 @@ package eu.eudat.entities;
|
||||||
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.*;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.*;
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.FetchType;
|
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import javax.persistence.JoinColumn;
|
|
||||||
import javax.persistence.JoinTable;
|
|
||||||
import javax.persistence.ManyToOne;
|
|
||||||
import javax.persistence.OneToMany;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
|
|
||||||
import org.hibernate.annotations.GenericGenerator;
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
import org.hibernate.annotations.Type;
|
import org.hibernate.annotations.Type;
|
||||||
|
@ -26,10 +15,23 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="\"DMP\"")
|
@Table(name="\"DMP\"")
|
||||||
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id", scope = DMP.class)
|
@NamedEntityGraphs({
|
||||||
|
@NamedEntityGraph(
|
||||||
|
name = "organisationsAndResearchers",
|
||||||
|
attributeNodes = {@NamedAttributeNode("organisations"),@NamedAttributeNode("researchers")}),
|
||||||
|
@NamedEntityGraph(
|
||||||
|
name = "fullyDetailed",
|
||||||
|
attributeNodes = {
|
||||||
|
@NamedAttributeNode("project"),@NamedAttributeNode("profile"),
|
||||||
|
@NamedAttributeNode("users"),@NamedAttributeNode("organisations"),@NamedAttributeNode("researchers")})
|
||||||
|
})
|
||||||
public class DMP implements Serializable,DataEntity<DMP> {
|
public class DMP implements Serializable,DataEntity<DMP> {
|
||||||
|
|
||||||
|
|
||||||
|
public static Set<String> getHints() {
|
||||||
|
return hints;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Set<String> hints = new HashSet<>(Arrays.asList("organisationsAndResearchers", "fullyDetailed"));
|
||||||
private static final long serialVersionUID = -8263056535208547615L;
|
private static final long serialVersionUID = -8263056535208547615L;
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,7 +55,7 @@ public class DMP implements Serializable,DataEntity<DMP> {
|
||||||
private Set<Dataset> dataset;
|
private Set<Dataset> dataset;
|
||||||
|
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.EAGER)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
@JoinColumn(name = "\"Project\"")
|
@JoinColumn(name = "\"Project\"")
|
||||||
private Project project;
|
private Project project;
|
||||||
|
|
||||||
|
@ -62,7 +64,7 @@ public class DMP implements Serializable,DataEntity<DMP> {
|
||||||
@Column(name = "\"AssociatedDmps\"", columnDefinition = "xml", nullable = true)
|
@Column(name = "\"AssociatedDmps\"", columnDefinition = "xml", nullable = true)
|
||||||
private String associatedDmps;
|
private String associatedDmps;
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.EAGER)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
@JoinColumn(name = "\"Profile\"")
|
@JoinColumn(name = "\"Profile\"")
|
||||||
private DMPProfile profile;
|
private DMPProfile profile;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
package eu.eudat.entities;
|
package eu.eudat.entities;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public interface DataEntity<T> {
|
public interface DataEntity<T> {
|
||||||
void update(T entity);
|
void update(T entity);
|
||||||
|
|
||||||
Object[] getKeys();
|
Object[] getKeys();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,20 +2,9 @@ package eu.eudat.entities;
|
||||||
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.*;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.*;
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.FetchType;
|
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import javax.persistence.JoinColumn;
|
|
||||||
import javax.persistence.JoinTable;
|
|
||||||
import javax.persistence.ManyToOne;
|
|
||||||
import javax.persistence.OneToMany;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
|
|
||||||
import org.hibernate.annotations.GenericGenerator;
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
import org.hibernate.annotations.Type;
|
import org.hibernate.annotations.Type;
|
||||||
|
@ -25,9 +14,22 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="\"Dataset\"")
|
@Table(name="\"Dataset\"")
|
||||||
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
|
@NamedEntityGraphs({
|
||||||
public class Dataset implements DataEntity<Dataset> {
|
@NamedEntityGraph(
|
||||||
|
name = "datasetreferences",
|
||||||
|
attributeNodes = {@NamedAttributeNode("services"),@NamedAttributeNode("dataRepositories"),@NamedAttributeNode("registries")}),
|
||||||
|
@NamedEntityGraph(
|
||||||
|
name = "datasetFullyDetailed",
|
||||||
|
attributeNodes = {
|
||||||
|
@NamedAttributeNode("dmp"),@NamedAttributeNode("profile"),@NamedAttributeNode("creator"),
|
||||||
|
@NamedAttributeNode("services"),@NamedAttributeNode("dataRepositories"),@NamedAttributeNode("registries")})
|
||||||
|
})public class Dataset implements DataEntity<Dataset> {
|
||||||
|
|
||||||
|
public static Set<String> getHints() {
|
||||||
|
return hints;
|
||||||
|
}
|
||||||
|
private static final Set<String> hints = new HashSet<>(Arrays.asList("datasetreferences", "datasetFullyDetailed"));
|
||||||
|
|
||||||
private static final long serialVersionUID = 3575723814399553259L;
|
private static final long serialVersionUID = 3575723814399553259L;
|
||||||
|
|
||||||
public Dataset () {}
|
public Dataset () {}
|
||||||
|
@ -43,7 +45,7 @@ public class Dataset implements DataEntity<Dataset> {
|
||||||
private String label;
|
private String label;
|
||||||
|
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.EAGER)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
// @Cascade(value=org.hibernate.annotations.CascadeType.ALL)
|
// @Cascade(value=org.hibernate.annotations.CascadeType.ALL)
|
||||||
@JoinColumn(name = "\"DMP\"", nullable = true)
|
@JoinColumn(name = "\"DMP\"", nullable = true)
|
||||||
private DMP dmp;
|
private DMP dmp;
|
||||||
|
@ -57,7 +59,7 @@ public class Dataset implements DataEntity<Dataset> {
|
||||||
private String properties;
|
private String properties;
|
||||||
|
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.EAGER)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
//@Cascade(value=org.hibernate.annotations.CascadeType.ALL)
|
//@Cascade(value=org.hibernate.annotations.CascadeType.ALL)
|
||||||
@JoinColumn(name = "\"Profile\"", nullable = true)
|
@JoinColumn(name = "\"Profile\"", nullable = true)
|
||||||
private DatasetProfile profile;
|
private DatasetProfile profile;
|
||||||
|
@ -100,7 +102,7 @@ public class Dataset implements DataEntity<Dataset> {
|
||||||
@Column(name = "\"Modified\"")
|
@Column(name = "\"Modified\"")
|
||||||
private Date modified = new Date();
|
private Date modified = new Date();
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.EAGER)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
@JoinColumn(name = "\"Creator\"", nullable = true)
|
@JoinColumn(name = "\"Creator\"", nullable = true)
|
||||||
private UserInfo creator;
|
private UserInfo creator;
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class Registry implements Serializable,DataEntity<Registry> {
|
||||||
private String definition;
|
private String definition;
|
||||||
|
|
||||||
|
|
||||||
@OneToMany(fetch = FetchType.EAGER)
|
@OneToMany(fetch = FetchType.LAZY)
|
||||||
@JoinTable(name="\"DatasetRegistry\"",
|
@JoinTable(name="\"DatasetRegistry\"",
|
||||||
joinColumns={@JoinColumn(name="\"Registry\"", referencedColumnName="\"ID\"")},
|
joinColumns={@JoinColumn(name="\"Registry\"", referencedColumnName="\"ID\"")},
|
||||||
inverseJoinColumns={@JoinColumn(name="\"Dataset\"", referencedColumnName="\"ID\"")}
|
inverseJoinColumns={@JoinColumn(name="\"Dataset\"", referencedColumnName="\"ID\"")}
|
||||||
|
|
|
@ -25,6 +25,7 @@ public class DataManagementPlanManager {
|
||||||
public DataTableData<DataManagementPlanListingModel> getPaged(DMPDao dmpsRepository, DataManagementPlanTableRequest dataManagementPlanTableRequest) throws IllegalAccessException, InstantiationException{
|
public DataTableData<DataManagementPlanListingModel> getPaged(DMPDao dmpsRepository, DataManagementPlanTableRequest dataManagementPlanTableRequest) throws IllegalAccessException, InstantiationException{
|
||||||
QueryableList<DMP> items = dmpsRepository.getWithCriteria(dataManagementPlanTableRequest.getCriteria());
|
QueryableList<DMP> items = dmpsRepository.getWithCriteria(dataManagementPlanTableRequest.getCriteria());
|
||||||
QueryableList<DMP> pagedItems = PaginationManager.applyPaging(items,dataManagementPlanTableRequest);
|
QueryableList<DMP> pagedItems = PaginationManager.applyPaging(items,dataManagementPlanTableRequest);
|
||||||
|
if(dataManagementPlanTableRequest.getWithHint())pagedItems.withHint("fullyDetailed");
|
||||||
List<DataManagementPlanListingModel> datamanagementPlans = new DomainModelConverter<eu.eudat.entities.DMP, DataManagementPlanListingModel>().fromDataModel( pagedItems.toList(), DataManagementPlanListingModel.class);
|
List<DataManagementPlanListingModel> datamanagementPlans = new DomainModelConverter<eu.eudat.entities.DMP, DataManagementPlanListingModel>().fromDataModel( pagedItems.toList(), DataManagementPlanListingModel.class);
|
||||||
DataTableData<DataManagementPlanListingModel> dataTable = new DataTableData<DataManagementPlanListingModel>();
|
DataTableData<DataManagementPlanListingModel> dataTable = new DataTableData<DataManagementPlanListingModel>();
|
||||||
dataTable.setData(datamanagementPlans);
|
dataTable.setData(datamanagementPlans);
|
||||||
|
|
|
@ -27,6 +27,7 @@ public class DatasetManager {
|
||||||
public DataTableData<DatasetListingModel> getPaged(DatasetDao datatasetRepository, DatasetTableRequest datasetTableRequest) throws IllegalAccessException, InstantiationException{
|
public DataTableData<DatasetListingModel> getPaged(DatasetDao datatasetRepository, DatasetTableRequest datasetTableRequest) throws IllegalAccessException, InstantiationException{
|
||||||
QueryableList<eu.eudat.entities.Dataset> items = datatasetRepository.getWithCriteria(datasetTableRequest.getCriteria());
|
QueryableList<eu.eudat.entities.Dataset> items = datatasetRepository.getWithCriteria(datasetTableRequest.getCriteria());
|
||||||
QueryableList<eu.eudat.entities.Dataset> pagedItems = PaginationManager.applyPaging( items ,datasetTableRequest);
|
QueryableList<eu.eudat.entities.Dataset> pagedItems = PaginationManager.applyPaging( items ,datasetTableRequest);
|
||||||
|
if(datasetTableRequest.getWithHint())pagedItems.withHint("datasetFullyDetailed");
|
||||||
List<DatasetListingModel> datasets = new DomainModelConverter<eu.eudat.entities.Dataset, DatasetListingModel>().fromDataModel( pagedItems.toList(), DatasetListingModel.class);
|
List<DatasetListingModel> datasets = new DomainModelConverter<eu.eudat.entities.Dataset, DatasetListingModel>().fromDataModel( pagedItems.toList(), DatasetListingModel.class);
|
||||||
DataTableData<DatasetListingModel> dataTable = new DataTableData<DatasetListingModel>();
|
DataTableData<DatasetListingModel> dataTable = new DataTableData<DatasetListingModel>();
|
||||||
dataTable.setData(datasets);
|
dataTable.setData(datasets);
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
package eu.eudat.managers;
|
package eu.eudat.managers;
|
||||||
|
|
||||||
|
import eu.eudat.entities.DataEntity;
|
||||||
import eu.eudat.models.helpers.requests.TableRequest;
|
import eu.eudat.models.helpers.requests.TableRequest;
|
||||||
import eu.eudat.queryable.QueryableList;
|
import eu.eudat.queryable.QueryableList;
|
||||||
|
|
||||||
public class PaginationManager {
|
public class PaginationManager {
|
||||||
|
|
||||||
public static <T> QueryableList<T> applyPaging(QueryableList<T> items, TableRequest tableRequest){
|
public static <T extends DataEntity<T>> QueryableList<T> applyPaging(QueryableList<T> items, TableRequest tableRequest){
|
||||||
if(tableRequest.getLength()!=null)items.take(tableRequest.getLength());
|
if(tableRequest.getLength()!=null)items.take(tableRequest.getLength());
|
||||||
if(tableRequest.getOffset()!=null)items.skip(tableRequest.getOffset());
|
if(tableRequest.getOffset()!=null)items.skip(tableRequest.getOffset());
|
||||||
return items;
|
return items;
|
||||||
|
|
|
@ -8,6 +8,22 @@ public class FieldError {
|
||||||
|
|
||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
|
public String getField() {
|
||||||
|
return field;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setField(String field) {
|
||||||
|
this.field = field;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
public FieldError(String field, String message) {
|
public FieldError(String field, String message) {
|
||||||
this.field = field;
|
this.field = field;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
|
|
|
@ -9,6 +9,14 @@ import java.util.List;
|
||||||
public class ValidationErrorContext {
|
public class ValidationErrorContext {
|
||||||
private List<FieldError> fieldErrors = new ArrayList<>();
|
private List<FieldError> fieldErrors = new ArrayList<>();
|
||||||
|
|
||||||
|
public List<FieldError> getFieldErrors() {
|
||||||
|
return fieldErrors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFieldErrors(List<FieldError> fieldErrors) {
|
||||||
|
this.fieldErrors = fieldErrors;
|
||||||
|
}
|
||||||
|
|
||||||
public ValidationErrorContext() {
|
public ValidationErrorContext() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package eu.eudat.models.helpers.requests;
|
package eu.eudat.models.helpers.requests;
|
||||||
|
|
||||||
public abstract class RequestItem<T>{
|
public abstract class RequestItem<T>{
|
||||||
|
private boolean withHint;
|
||||||
private T criteria;
|
private T criteria;
|
||||||
|
|
||||||
public T getCriteria() {
|
public T getCriteria() {
|
||||||
|
@ -10,4 +11,12 @@ public abstract class RequestItem<T>{
|
||||||
public void setCriteria(T criteria) {
|
public void setCriteria(T criteria) {
|
||||||
this.criteria = criteria;
|
this.criteria = criteria;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getWithHint() {
|
||||||
|
return withHint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWithHint(boolean withHint) {
|
||||||
|
this.withHint = withHint;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
package eu.eudat.queryable;
|
package eu.eudat.queryable;
|
||||||
|
|
||||||
|
|
||||||
|
import eu.eudat.entities.DataEntity;
|
||||||
import eu.eudat.queryable.predicates.OrderByPredicate;
|
import eu.eudat.queryable.predicates.OrderByPredicate;
|
||||||
import eu.eudat.queryable.predicates.SelectPredicate;
|
import eu.eudat.queryable.predicates.SelectPredicate;
|
||||||
import eu.eudat.queryable.predicates.SinglePredicate;
|
import eu.eudat.queryable.predicates.SinglePredicate;
|
||||||
|
|
||||||
|
import javax.xml.crypto.Data;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public interface QueryableList<T> {
|
public interface QueryableList<T extends DataEntity<T>> {
|
||||||
QueryableList<T> where(SinglePredicate<T> predicate);
|
QueryableList<T> where(SinglePredicate<T> predicate);
|
||||||
|
|
||||||
<R> List<R> select(SelectPredicate<T, R> predicate);
|
<R> List<R> select(SelectPredicate<T, R> predicate);
|
||||||
|
@ -22,6 +25,7 @@ public interface QueryableList<T> {
|
||||||
|
|
||||||
QueryableList<T> orderByAsc(OrderByPredicate<T> predicate);
|
QueryableList<T> orderByAsc(OrderByPredicate<T> predicate);
|
||||||
QueryableList<T> orderByDesc(OrderByPredicate<T> predicate);
|
QueryableList<T> orderByDesc(OrderByPredicate<T> predicate);
|
||||||
|
QueryableList<T> setHints(Set<String> hints);
|
||||||
|
void withHint(String hint);
|
||||||
Long count();
|
Long count();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package eu.eudat.queryable.hibernatequeryablelist;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import eu.eudat.entities.DataEntity;
|
||||||
import eu.eudat.queryable.QueryableList;
|
import eu.eudat.queryable.QueryableList;
|
||||||
import eu.eudat.queryable.predicates.OrderByPredicate;
|
import eu.eudat.queryable.predicates.OrderByPredicate;
|
||||||
import eu.eudat.queryable.predicates.SelectPredicate;
|
import eu.eudat.queryable.predicates.SelectPredicate;
|
||||||
|
@ -15,8 +16,10 @@ import javax.persistence.criteria.Predicate;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class QueryableHibernateList<T> implements QueryableList<T> {
|
public class QueryableHibernateList<T extends DataEntity<T>> implements QueryableList<T> {
|
||||||
|
|
||||||
private EntityManager manager;
|
private EntityManager manager;
|
||||||
private CriteriaQuery<T> query;
|
private CriteriaQuery<T> query;
|
||||||
|
@ -25,6 +28,8 @@ public class QueryableHibernateList<T> implements QueryableList<T> {
|
||||||
private LinkedList<Predicate> predicates = new LinkedList<Predicate>();
|
private LinkedList<Predicate> predicates = new LinkedList<Predicate>();
|
||||||
private Integer length;
|
private Integer length;
|
||||||
private Integer offset;
|
private Integer offset;
|
||||||
|
private Set<String> hints;
|
||||||
|
private String hint;
|
||||||
public QueryableHibernateList(EntityManager manager, Class<T> tClass) {
|
public QueryableHibernateList(EntityManager manager, Class<T> tClass) {
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
this.tClass = tClass;
|
this.tClass = tClass;
|
||||||
|
@ -35,6 +40,14 @@ public class QueryableHibernateList<T> implements QueryableList<T> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void withHint(String hint){
|
||||||
|
this.hint = hint;
|
||||||
|
}
|
||||||
|
public QueryableList<T> setHints(Set<String> hints){
|
||||||
|
this.hints = hints;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public QueryableHibernateList<T> setEntity(Class<T> type) {
|
public QueryableHibernateList<T> setEntity(Class<T> type) {
|
||||||
CriteriaBuilder builder = this.manager.getCriteriaBuilder();
|
CriteriaBuilder builder = this.manager.getCriteriaBuilder();
|
||||||
this.query = builder.createQuery(type);
|
this.query = builder.createQuery(type);
|
||||||
|
@ -106,6 +119,21 @@ public class QueryableHibernateList<T> implements QueryableList<T> {
|
||||||
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
|
||||||
if(this.offset!=null)typedQuery.setFirstResult(this.offset);
|
if(this.offset!=null)typedQuery.setFirstResult(this.offset);
|
||||||
if(this.length!=null)typedQuery.setMaxResults(this.length);
|
if(this.length!=null)typedQuery.setMaxResults(this.length);
|
||||||
|
if(this.hint!=null&&this.hints.contains(hint)){
|
||||||
|
List ids = typedQuery.getResultList().stream().map(item->item.getKeys()[0]).collect(Collectors.toList());
|
||||||
|
typedQuery = queryWithHint(ids);
|
||||||
|
}
|
||||||
return typedQuery.getResultList();
|
return typedQuery.getResultList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private TypedQuery<T> queryWithHint(List ids){
|
||||||
|
CriteriaBuilder criteriaBuilder = this.manager.getCriteriaBuilder();
|
||||||
|
CriteriaQuery<T> criteriaQuery = criteriaBuilder.createQuery(tClass);
|
||||||
|
Root<T> criteriaRoot = criteriaQuery.from(this.tClass);
|
||||||
|
|
||||||
|
criteriaQuery.where(criteriaRoot.get("id").in(ids));
|
||||||
|
TypedQuery<T> typedQuery = this.manager.createQuery(criteriaQuery);
|
||||||
|
typedQuery.setHint("javax.persistence.fetchgraph", this.manager.getEntityGraph(this.hint));
|
||||||
|
return typedQuery;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,7 @@ import org.springframework.validation.Validator;
|
||||||
/**
|
/**
|
||||||
* Created by ikalyvas on 12/22/2017.
|
* Created by ikalyvas on 12/22/2017.
|
||||||
*/
|
*/
|
||||||
@Component("beforeCreateDataManagementTableRequestValidator")
|
public class DataManagementPlanTableRequestValidator implements Validator {
|
||||||
public class DataManagementTableRequestValidator implements Validator {
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supports(Class<?> aClass) {
|
public boolean supports(Class<?> aClass) {
|
||||||
return DataManagementPlanTableRequest.class.equals(aClass);
|
return DataManagementPlanTableRequest.class.equals(aClass);
|
||||||
|
@ -19,10 +18,10 @@ public class DataManagementTableRequestValidator implements Validator {
|
||||||
public void validate(Object obj, Errors errors) {
|
public void validate(Object obj, Errors errors) {
|
||||||
DataManagementPlanTableRequest user = (DataManagementPlanTableRequest) obj;
|
DataManagementPlanTableRequest user = (DataManagementPlanTableRequest) obj;
|
||||||
if(user.getOffset()<0){
|
if(user.getOffset()<0){
|
||||||
errors.rejectValue("offset", "Offset Cannot Be Negative");
|
errors.rejectValue("offset", "datamanagementplanrequest.offset.negative");
|
||||||
}
|
}
|
||||||
if(user.getLength()<0){
|
if(user.getLength()<0){
|
||||||
errors.rejectValue("length", "Length Cannot Be Negative");
|
errors.rejectValue("length", "datamanagementplanrequest.length.negative");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,9 +5,9 @@
|
||||||
|
|
||||||
##########################Persistence##########################################
|
##########################Persistence##########################################
|
||||||
database.driver-class-name=org.postgresql.Driver
|
database.driver-class-name=org.postgresql.Driver
|
||||||
database.url = jdbc:postgresql://develdb1.madgik.di.uoa.gr:5432/dmptool
|
database.url = jdbc:postgresql://localhost:5432/dmptool
|
||||||
database.username = dmptool
|
database.username = postgres
|
||||||
database.password = dmpt00lu$r
|
database.password = zxcvbnm
|
||||||
##########################/Persistence##########################################
|
##########################/Persistence##########################################
|
||||||
|
|
||||||
###################Allowed Proxy Service Host ############################
|
###################Allowed Proxy Service Host ############################
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
datamanagementplanrequest.length.negative=table length cannot be negative
|
||||||
|
datamanagementplanrequest.offset.negative=table offset cannot be negative
|
|
@ -0,0 +1,2 @@
|
||||||
|
datamanagementplanrequest.length.negative=Το πληθος των σειρων στο table δεν μπορει να ειναι αρνητικο
|
||||||
|
datamanagementplanrequest.offset.negative=Το offset των τιμων δεν μπορει να ειναι αρνητικο
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue