no message

This commit is contained in:
Ioannis Kalyvas 2018-02-02 17:24:06 +02:00
parent ab73f2ad62
commit 5340e90c65
14 changed files with 125 additions and 52 deletions

View File

@ -19,7 +19,7 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
@NamedEntityGraph(
name = "dataManagementPlanListingModel",
attributeNodes = {@NamedAttributeNode("organisations"), @NamedAttributeNode("researchers"),
@NamedAttributeNode("project"), @NamedAttributeNode("profile")}
@NamedAttributeNode("project"), @NamedAttributeNode("profile"),@NamedAttributeNode("dataset")}
),
@NamedEntityGraph(
name = "fullyDetailed",

View File

@ -6,21 +6,48 @@ import eu.eudat.models.helpers.common.Ordering;
import eu.eudat.models.helpers.requests.TableRequest;
import eu.eudat.queryable.QueryableList;
import java.util.Collection;
public class PaginationManager {
public static <T extends DataEntity<T>> QueryableList<T> applyPaging(QueryableList<T> items, TableRequest tableRequest) throws Exception {
if(tableRequest.getOrderings()!=null) applyOrder(items,tableRequest);
if(tableRequest.getLength()!=null)items.take(tableRequest.getLength());
if(tableRequest.getOffset()!=null)items.skip(tableRequest.getOffset());
if (tableRequest.getOrderings() != null) applyOrder(items, tableRequest);
if (tableRequest.getLength() != null) items.take(tableRequest.getLength());
if (tableRequest.getOffset() != null) items.skip(tableRequest.getOffset());
return items;
}
public static <T extends DataEntity<T>> void applyOrder(QueryableList<T> items, TableRequest tableRequest) throws Exception {
public static <T extends DataEntity<T>> void applyOrder(QueryableList<T> items, TableRequest tableRequest) throws Exception {
ColumnOrderings columnOrderings = tableRequest.getOrderings();
for(Ordering ordering:columnOrderings.getFieldOrderings()){
if(ordering.getType() == Ordering.OrderByType.ASC) items.orderByAsc(root -> root.get(ordering.getFieldName()));
if(ordering.getType() == Ordering.OrderByType.DESC) items.orderByDesc(root -> root.get(ordering.getFieldName()));
for (Ordering ordering : columnOrderings.getFieldOrderings()) {
if (ordering.getOrderByType() == Ordering.OrderByType.ASC)
applyAscOrder(items,ordering);
if (ordering.getOrderByType() == Ordering.OrderByType.DESC) {
applyDescOrder(items,ordering);
}
}
return;
}
private static <T extends DataEntity<T>> void applyAscOrder(QueryableList<T> items, Ordering ordering) {
if (ordering.getColumnType() == Ordering.ColumnType.COUNT) {
items.orderBy((builder, root) -> builder.asc(builder.size(root.<Collection>get(ordering.getFieldName()))));
} else if (ordering.getColumnType() == Ordering.ColumnType.JOIN_COLUMN) {
String[] fields = ordering.getFieldName().split(":");
items.orderBy((builder, root) -> builder.asc(root.get(fields[0]).get(fields[1])));
} else {
items.orderBy((builder, root) -> builder.asc(root.get(ordering.getFieldName())));
}
}
private static <T extends DataEntity<T>> void applyDescOrder(QueryableList<T> items, Ordering ordering) {
if (ordering.getColumnType() == Ordering.ColumnType.COUNT) {
items.orderBy((builder, root) -> builder.desc(builder.size(root.<Collection>get(ordering.getFieldName()))));
} else if (ordering.getColumnType() == Ordering.ColumnType.JOIN_COLUMN) {
String[] fields = ordering.getFieldName().split(":");
items.orderBy((builder, root) -> builder.desc(root.get(fields[0]).get(fields[1])));
} else {
items.orderBy((builder, root) -> builder.desc(root.get(ordering.getFieldName())));
}
}
}

View File

@ -25,8 +25,11 @@ public class ColumnOrderings {
}
private Ordering orderingFromString(String field) throws Exception {
if(field.startsWith("+")) return new Ordering(field.replace("+",""), Ordering.OrderByType.ASC);
else if(field.startsWith("-")) return new Ordering(field.replace("-",""), Ordering.OrderByType.DESC);
else throw new Exception("Unsupported Field Order Type");
Ordering ordering = new Ordering(field);
if(ordering.getFieldName().contains("+")) ordering.fieldName(ordering.getFieldName().replace("+","")).orderByType(Ordering.OrderByType.ASC);
else if(ordering.getFieldName().startsWith("-")) ordering.fieldName(ordering.getFieldName().replace("-","")).orderByType(Ordering.OrderByType.DESC);
if(ordering.getFieldName().contains("|count|")) ordering.fieldName(ordering.getFieldName().replace("|count|","")).columnType(Ordering.ColumnType.COUNT);
else if(ordering.getFieldName().contains("|join|")) ordering.fieldName(ordering.getFieldName().replace("|join|","")).columnType(Ordering.ColumnType.JOIN_COLUMN);
return ordering;
}
}

View File

@ -6,12 +6,16 @@ public class Ordering {
ASC, DESC
}
private String fieldName;
private OrderByType type;
public enum ColumnType {
COUNT, COLUMN , JOIN_COLUMN
}
public Ordering(String fieldName, OrderByType type) {
private String fieldName;
private OrderByType orderByType;
private ColumnType columnType;
public Ordering(String fieldName) {
this.fieldName = fieldName;
this.type = type;
}
public String getFieldName() {
@ -22,11 +26,34 @@ public class Ordering {
this.fieldName = fieldName;
}
public OrderByType getType() {
return type;
public OrderByType getOrderByType() {
return orderByType;
}
public void setType(OrderByType type) {
this.type = type;
public void setOrderByType(OrderByType orderByType) {
this.orderByType = orderByType;
}
public Ordering fieldName(String fieldName) {
this.fieldName = fieldName;
return this;
}
public Ordering orderByType(OrderByType orderByType) {
this.orderByType = orderByType;
return this;
}
public ColumnType getColumnType() {
return columnType;
}
public void setColumnType(ColumnType columnType) {
this.columnType = columnType;
}
public Ordering columnType(ColumnType columnType) {
this.columnType = columnType;
return this;
}
}

View File

@ -27,9 +27,7 @@ public interface QueryableList<T extends DataEntity<T>> {
QueryableList<T> distinct();
QueryableList<T> orderByAsc(OrderByPredicate<T> predicate);
QueryableList<T> orderByDesc(OrderByPredicate<T> predicate);
QueryableList<T> orderBy(OrderByPredicate<T> predicate);
QueryableList<T> setHints(Set<String> hints);

View File

@ -23,7 +23,7 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
private Class<T> tClass;
private Root<T> root;
private List<SinglePredicate<T>> predicates = new LinkedList<>();
private List<Order> orderings = new LinkedList<>();
private List<OrderByPredicate<T>> orderings = new LinkedList<>();
private List<Selection> fields = new LinkedList<>();
private Integer length;
private Integer offset;
@ -93,13 +93,8 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
return this;
}
public QueryableList<T> orderByAsc(OrderByPredicate<T> predicate) {
this.orderings.add(this.manager.getCriteriaBuilder().asc(predicate.applyPredicate(this.root)));
return this;
}
public QueryableList<T> orderByDesc(OrderByPredicate<T> predicate) {
this.orderings.add(this.manager.getCriteriaBuilder().desc(predicate.applyPredicate(this.root)));
public QueryableList<T> orderBy(OrderByPredicate<T> predicate) {
this.orderings.add(predicate);
return this;
}
@ -120,10 +115,18 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
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) {
predicates.add(orderPredicate.applyPredicate(this.manager.getCriteriaBuilder(), root));
}
return predicates.toArray(new Order[predicates.size()]);
}
public List<T> toList() {
this.query.where(this.generateWherePredicates(this.predicates, this.root));
if (!this.orderings.isEmpty()) this.query.orderBy(this.orderings);
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);
if (this.length != null) typedQuery.setMaxResults(this.length);
@ -156,6 +159,8 @@ public class QueryableHibernateList<T extends DataEntity<T>> implements Queryabl
Root<T> criteriaRoot = criteriaQuery.from(this.tClass);
criteriaQuery.where(criteriaRoot.get("id").in(ids));
if (!this.orderings.isEmpty()) criteriaQuery.orderBy(this.generateOrderPredicates(this.orderings, criteriaRoot));
TypedQuery<T> typedQuery = this.manager.createQuery(criteriaQuery);
typedQuery.setHint("javax.persistence.fetchgraph", this.manager.getEntityGraph(this.hint));
return typedQuery;

View File

@ -6,6 +6,6 @@ import javax.persistence.criteria.Path;
import javax.persistence.criteria.Root;
public interface OrderByPredicate<T> {
Path applyPredicate(Root<T> root);
Order applyPredicate(CriteriaBuilder builder, Root<T> root);
}

View File

@ -1,3 +1,4 @@
import { Field } from '../../models/Field';
import { DataTableRequest } from '../../models/data-table/DataTableRequest';
import { DatasetListingModel } from '../../models/datasets/DatasetListingModel';
import { DatasetCriteria } from '../../models/criteria/dataset/DatasetCriteria';
@ -54,7 +55,7 @@ export class DatasetListingComponent implements OnInit {
ngOnInit() {
this.route.params.subscribe((params: Params) => {
this.dmpId = params['dmpId'];
if(this.dmpId != null) this.setDmpTitle(this.dmpId);
if (this.dmpId != null) this.setDmpTitle(this.dmpId);
this.criteria.setCriteria(this.getDefaultCriteria(this.dmpId));
this.refresh();
this.criteria.setRefreshCallback(() => this.refresh());
@ -63,9 +64,9 @@ export class DatasetListingComponent implements OnInit {
setDmpTitle(dmpId: String) {
this.dataManagementPlanService.getSingle(dmpId).map(data => data as DataManagementPlanModel)
.subscribe(data => {
this.titlePrefix = data.label;
});
.subscribe(data => {
this.titlePrefix = data.label;
});
}
refresh() {
@ -84,7 +85,8 @@ export class DatasetListingComponent implements OnInit {
return defaultCriteria;
}
makeItPublic(id:String){debugger;
makeItPublic(id: String) {
debugger;
this.datasetService.makeDatasetPublic(id).subscribe();
}
@ -121,7 +123,9 @@ export class DatasetDataSource extends DataSource<DatasetListingModel> {
this.isLoadingResults = true;
});
const startIndex = this._paginator.pageIndex * this._paginator.pageSize;
const request = new DataTableRequest<DatasetCriteria>(startIndex, this._paginator.pageSize);
let fields: Array<string> = new Array()
if (this._sort.active) fields = this._sort.direction === "asc" ? ["+" + this._sort.active] : ["-" + this._sort.active];
const request = new DataTableRequest<DatasetCriteria>(startIndex, this._paginator.pageSize, { fields: fields });
request.criteria = this._criteria.criteria;
return this._service.getPaged(request);
})

View File

@ -6,18 +6,18 @@
<mat-card-header>
<mat-progress-bar *ngIf="dataSource?.isLoadingResults" mode="query"></mat-progress-bar>
</mat-card-header>
<mat-table [dataSource]="dataSource" matSort>
<mat-table [dataSource]="dataSource" matSort (matSortChange)="refresh()">
<!-- Column Definition: Name -->
<ng-container cdkColumnDef="name">
<mat-header-cell *matHeaderCellDef mat-short-header="name">{{'DMP-LISTING.COLUMNS.NAME' | translate}}</mat-header-cell>
<mat-header-cell *matHeaderCellDef mat-sort-header="label">{{'DMP-LISTING.COLUMNS.NAME' | translate}}</mat-header-cell>
<mat-cell *matCellDef="let row">{{row.label}}</mat-cell>
</ng-container>
<!-- Column Definition: Project -->
<ng-container cdkColumnDef="project">
<mat-header-cell *matHeaderCellDef mat-short-header="project">{{'DMP-LISTING.COLUMNS.PROJECT' | translate}}</mat-header-cell>
<mat-header-cell *matHeaderCellDef mat-sort-header="|join|project:label">{{'DMP-LISTING.COLUMNS.PROJECT' | translate}}</mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.project}} </mat-cell>
</ng-container>
@ -29,7 +29,7 @@
<!-- Column Definition: Researchers -->
<ng-container cdkColumnDef="creationTime">
<mat-header-cell *matHeaderCellDef mat-short-header="creationTime">{{'DMP-LISTING.COLUMNS.CREATION-TIME' | translate}}</mat-header-cell>
<mat-header-cell *matHeaderCellDef mat-sort-header="created">{{'DMP-LISTING.COLUMNS.CREATION-TIME' | translate}}</mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.creationTime | date:'shortDate'}} </mat-cell>
</ng-container>
@ -41,13 +41,13 @@
<!-- Column Definition: Version -->
<ng-container cdkColumnDef="version">
<mat-header-cell *matHeaderCellDef mat-short-header="version">{{'DMP-LISTING.COLUMNS.VERSION' | translate}}</mat-header-cell>
<mat-header-cell *matHeaderCellDef mat-sort-header="version">{{'DMP-LISTING.COLUMNS.VERSION' | translate}}</mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.version}}</mat-cell>
</ng-container>
<!-- Column Definition: Datasets(count) -->
<ng-container cdkColumnDef="numOfDatasets">
<mat-header-cell *matHeaderCellDef mat-short-header="numofdatasets">{{'DMP-LISTING.COLUMNS.DATASETS' | translate}}</mat-header-cell>
<mat-header-cell *matHeaderCellDef mat-sort-header="|count|dataset">{{'DMP-LISTING.COLUMNS.DATASETS' | translate}}</mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.numOfDatasets}}</mat-cell>
</ng-container>

View File

@ -47,8 +47,6 @@ export class DataManagementPlanListingComponent implements OnInit {
this.criteria.setRefreshCallback(() => this.refresh());
}
refresh() {
this.dataSource = new DataManagementPlanDataSource(this.dataManagementPlanService, this._paginator, this.sort, this.languageService, this.snackBar, this.criteria, );
}
@ -114,7 +112,9 @@ export class DataManagementPlanDataSource extends DataSource<DataManagementPlanL
this.isLoadingResults = true;
});
const startIndex = this._paginator.pageIndex * this._paginator.pageSize;
const request = new DataTableRequest<DataManagementPlanCriteria>(startIndex, this._paginator.pageSize);
let fields: Array<string> = new Array()
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;
return this._service.getPaged(request);
})

View File

@ -0,0 +1,3 @@
export class ColumnOrderings{
public fields:Array<string> = new Array();
}

View File

@ -1,13 +1,15 @@
import { ColumnOrderings } from './ColumnOrderings';
import { BaseCriteria } from "../criteria/BaseCriteria";
import { RequestItem } from "../criteria/RequestItem";
export class DataTableRequest<T> extends RequestItem<T> {
offset = 0;
length = 0;
constructor(offset: number, length: number) {
public orderings: ColumnOrderings;
constructor(offset: number, length: number, orderings: ColumnOrderings) {
super();
this.length = length;
this.offset = offset;
this.orderings = orderings;
}
}

View File

@ -93,7 +93,9 @@ export class ProjectDataSource extends DataSource<ProjectListingModel> {
this.isLoadingResults = true;
});
const startIndex = this._paginator.pageIndex * this._paginator.pageSize;
const request = new DataTableRequest<ProjectCriteria>(startIndex, this._paginator.pageSize);
let fields: Array<string> = new Array()
if (this._sort.active) fields = this._sort.direction === "asc" ? ["+" + this._sort.active] : ["-" + this._sort.active];
const request = new DataTableRequest<ProjectCriteria>(startIndex, this._paginator.pageSize, { fields: fields });
request.criteria = this._criteria.criteria;
return this._service.getPaged(request);
})

View File

@ -53,7 +53,9 @@ export class UsersDataSource extends DataSource<UserListingModel> {
this.isLoadingResults = true;
});
const startIndex = this._paginator.pageIndex * this._paginator.pageSize;
const request = new DataTableRequest<UserCriteria>(startIndex, this._paginator.pageSize);
let fields: Array<string> = new Array()
if (this._sort.active) fields = this._sort.direction === "asc" ? ["+" + this._sort.active] : ["-" + this._sort.active];
const request = new DataTableRequest<UserCriteria>(startIndex, this._paginator.pageSize, { fields: fields });
request.criteria = this._criteria.getFormData();
return this._service.getPaged(request);
})