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")
public @ResponseBody
ResponseEntity<ResponseItem<DataTableData<DataManagementPlanListingModel>>> getPaged(@Valid @RequestBody DataManagementPlanTableRequest dataManagementPlanTableRequest, Principal principal) throws Exception {
DataTableData<DataManagementPlanListingModel> dataTable = this.dataManagementPlanManager.getPaged(this.getApiContext(), dataManagementPlanTableRequest, principal);
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, fieldsGroup);
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
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.setId(principal.getId());
QueryableList<DMP> items = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(dataManagementPlanTableRequest.getCriteria()).withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class));
@ -61,7 +61,10 @@ public class DataManagementPlanManager {
DataTableData<DataManagementPlanListingModel> dataTable = new DataTableData<>();
CompletableFuture itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class))
CompletableFuture itemsFuture;
if(fieldsGroup.equals("listing")){
itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class))
.selectAsync(item -> {
item.setDataset(
item.getDataset().stream()
@ -69,9 +72,15 @@ public class DataManagementPlanManager {
|| dataset.isPublic()
|| dataset.getDmp().getUsers().stream()
.filter(x -> x.getId().equals(userInfo.getId())).collect(Collectors.toList()).size() > 0).collect(Collectors.toSet()));
return new DataManagementPlanListingModel().fromDataModel(item);
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) -> {
dataTable.setTotalCount(count);

View File

@ -108,17 +108,23 @@ public class DataManagementPlanListingModel implements DataModel<DMP, DataManage
public DataManagementPlanListingModel fromDataModel(DMP entity) {
this.id = entity.getId().toString();
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();
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());
return this;
}
@Override
public DMP toDataModel() {
return null;

View File

@ -23,8 +23,14 @@ export class DmpService {
this.actionUrl = environment.Server + 'dmps/';
}
getPaged(dataTableRequest: DataTableRequest<DmpCriteria>): Observable<DataTableData<DmpListingModel>> {
return this.http.post<DataTableData<DmpListingModel>>(this.actionUrl + 'paged', dataTableRequest, { headers: this.headers });
getPaged(dataTableRequest: DataTableRequest<DmpCriteria>, fieldsGroup?: string): Observable<DataTableData<DmpListingModel>> {
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> {

View File

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

View File

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