Parameterizes DMPs query endpoint for more efficient listing

This commit is contained in:
Diamantis Tziotzios 2019-01-31 15:56:53 +02:00
parent 6a7c1b6e9d
commit e829c5e6f0
6 changed files with 45 additions and 24 deletions

View File

@ -66,8 +66,8 @@ public class DMPs extends BaseController {
@RequestMapping(method = RequestMethod.POST, value = {"/paged"}, consumes = "application/json", produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/paged"}, consumes = "application/json", produces = "application/json")
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<DataTableData<DataManagementPlanListingModel>>> getPaged(@Valid @RequestBody DataManagementPlanTableRequest dataManagementPlanTableRequest, Principal principal) throws Exception { ResponseEntity<ResponseItem<DataTableData<DataManagementPlanListingModel>>> getPaged(@Valid @RequestBody DataManagementPlanTableRequest dataManagementPlanTableRequest,@RequestParam String fieldsGroup, Principal principal) throws Exception {
DataTableData<DataManagementPlanListingModel> dataTable = this.dataManagementPlanManager.getPaged(this.getApiContext(), dataManagementPlanTableRequest, principal); DataTableData<DataManagementPlanListingModel> dataTable = this.dataManagementPlanManager.getPaged(this.getApiContext(), dataManagementPlanTableRequest, principal, fieldsGroup);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
} }

View File

@ -52,7 +52,7 @@ import java.util.stream.Collectors;
@Component @Component
public class DataManagementPlanManager { public class DataManagementPlanManager {
public DataTableData<DataManagementPlanListingModel> getPaged(ApiContext apiContext, DataManagementPlanTableRequest dataManagementPlanTableRequest, Principal principal) throws Exception { public DataTableData<DataManagementPlanListingModel> getPaged(ApiContext apiContext, DataManagementPlanTableRequest dataManagementPlanTableRequest, Principal principal, String fieldsGroup) throws Exception {
UserInfo userInfo = new UserInfo(); UserInfo userInfo = new UserInfo();
userInfo.setId(principal.getId()); userInfo.setId(principal.getId());
QueryableList<DMP> items = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(dataManagementPlanTableRequest.getCriteria()).withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class)); QueryableList<DMP> items = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(dataManagementPlanTableRequest.getCriteria()).withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class));
@ -61,17 +61,26 @@ public class DataManagementPlanManager {
DataTableData<DataManagementPlanListingModel> dataTable = new DataTableData<>(); DataTableData<DataManagementPlanListingModel> dataTable = new DataTableData<>();
CompletableFuture itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class)) CompletableFuture itemsFuture;
.selectAsync(item -> { if(fieldsGroup.equals("listing")){
item.setDataset(
item.getDataset().stream() itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class))
.filter(dataset -> dataset.getDmp().getCreator().getId().equals(userInfo.getId()) .selectAsync(item -> {
|| dataset.isPublic() item.setDataset(
|| dataset.getDmp().getUsers().stream() item.getDataset().stream()
.filter(x -> x.getId().equals(userInfo.getId())).collect(Collectors.toList()).size() > 0).collect(Collectors.toSet())); .filter(dataset -> dataset.getDmp().getCreator().getId().equals(userInfo.getId())
return new DataManagementPlanListingModel().fromDataModel(item); || dataset.isPublic()
}) || dataset.getDmp().getUsers().stream()
.whenComplete((resultList, throwable) -> dataTable.setData(resultList)); .filter(x -> x.getId().equals(userInfo.getId())).collect(Collectors.toList()).size() > 0).collect(Collectors.toSet()));
return new DataManagementPlanListingModel().fromDataModelDatasets(item);
})
.whenComplete((resultList, throwable) -> dataTable.setData(resultList));
}
else{
itemsFuture = pagedItems
.selectAsync(item -> new DataManagementPlanListingModel().fromDataModel(item) )
.whenComplete((resultList, throwable) -> dataTable.setData(resultList));
}
CompletableFuture countFuture = authItems.countAsync().whenComplete((count, throwable) -> { CompletableFuture countFuture = authItems.countAsync().whenComplete((count, throwable) -> {
dataTable.setTotalCount(count); dataTable.setTotalCount(count);

View File

@ -108,17 +108,23 @@ public class DataManagementPlanListingModel implements DataModel<DMP, DataManage
public DataManagementPlanListingModel fromDataModel(DMP entity) { public DataManagementPlanListingModel fromDataModel(DMP entity) {
this.id = entity.getId().toString(); this.id = entity.getId().toString();
this.label = entity.getLabel(); this.label = entity.getLabel();
this.project = entity.getProject().getLabel();
this.status = entity.getStatus();
if (entity.getProfile() != null) this.profile = entity.getProfile().getLabel();
this.organisations = LabelBuilder.getLabel(entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()));
this.creationTime = entity.getCreated();
this.version = entity.getVersion();
this.groupId = entity.getGroupId(); this.groupId = entity.getGroupId();
return this;
}
public DataManagementPlanListingModel fromDataModelDatasets(DMP entity) {
this.fromDataModel(entity);
this.status = entity.getStatus();
this.version = entity.getVersion();
this.project = entity.getProject().getLabel();
if (entity.getProfile() != null) this.profile = entity.getProfile().getLabel();
this.creationTime = entity.getCreated();
this.organisations = LabelBuilder.getLabel(entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()));
this.datasets = entity.getDataset().stream().map(x-> new DatasetUrlListing().fromDataModel(x)).collect(Collectors.toList()); this.datasets = entity.getDataset().stream().map(x-> new DatasetUrlListing().fromDataModel(x)).collect(Collectors.toList());
return this; return this;
} }
@Override @Override
public DMP toDataModel() { public DMP toDataModel() {
return null; return null;

View File

@ -23,8 +23,14 @@ export class DmpService {
this.actionUrl = environment.Server + 'dmps/'; this.actionUrl = environment.Server + 'dmps/';
} }
getPaged(dataTableRequest: DataTableRequest<DmpCriteria>): Observable<DataTableData<DmpListingModel>> { getPaged(dataTableRequest: DataTableRequest<DmpCriteria>, fieldsGroup?: string): Observable<DataTableData<DmpListingModel>> {
return this.http.post<DataTableData<DmpListingModel>>(this.actionUrl + 'paged', dataTableRequest, { headers: this.headers }); if (fieldsGroup) {
return this.http.post<DataTableData<DmpListingModel>>(this.actionUrl + 'paged?fieldsGroup=' + fieldsGroup, dataTableRequest, { headers: this.headers });
}
else {
return this.http.post<DataTableData<DmpListingModel>>(this.actionUrl + 'paged?fieldsGroup=' + fieldsGroup, dataTableRequest, { headers: this.headers });
}
} }
getSingle(id: String): Observable<DmpModel> { getSingle(id: String): Observable<DmpModel> {

View File

@ -218,7 +218,7 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
const dmpDataTableRequest: DataTableRequest<DmpCriteria> = new DataTableRequest(0, null, { fields: fields }); const dmpDataTableRequest: DataTableRequest<DmpCriteria> = new DataTableRequest(0, null, { fields: fields });
dmpDataTableRequest.criteria = new DmpCriteria(); dmpDataTableRequest.criteria = new DmpCriteria();
dmpDataTableRequest.criteria.like = query; dmpDataTableRequest.criteria.like = query;
return this.dmpService.getPaged(dmpDataTableRequest).map(x => x.data); return this.dmpService.getPaged(dmpDataTableRequest, "autocomplete").map(x => x.data);
} }
loadDatasetProfiles() { loadDatasetProfiles() {

View File

@ -156,7 +156,7 @@ export class DmpDataSource extends DataSource<DmpListingModel> {
request.criteria.groupIds = [this.itemId]; request.criteria.groupIds = [this.itemId];
request.criteria.allVersions = true; request.criteria.allVersions = true;
} }
return this._service.getPaged(request); return this._service.getPaged(request, "listing");
}) })
/*.catch((error: any) => { /*.catch((error: any) => {
this._snackBar.openFromComponent(SnackBarNotificationComponent, { this._snackBar.openFromComponent(SnackBarNotificationComponent, {