Add criteria for the recent activity model

This commit is contained in:
George Kalampokis 2020-07-02 11:57:59 +03:00
parent 5db3485079
commit 325979a896
6 changed files with 47 additions and 8 deletions

View File

@ -1,5 +1,6 @@
package eu.eudat.controllers; package eu.eudat.controllers;
import eu.eudat.criteria.RecentActivityCriteria;
import eu.eudat.logic.managers.DashBoardManager; import eu.eudat.logic.managers.DashBoardManager;
import eu.eudat.logic.security.claims.ClaimedAuthorities; import eu.eudat.logic.security.claims.ClaimedAuthorities;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
@ -44,11 +45,11 @@ public class DashBoardController extends BaseController {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DashBoardStatistics>().status(ApiMessageCode.NO_MESSAGE).payload(statistics)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DashBoardStatistics>().status(ApiMessageCode.NO_MESSAGE).payload(statistics));
} }
@RequestMapping(method = RequestMethod.GET, value = {"/dashboard/recentActivity"}, produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/dashboard/recentActivity"}, produces = "application/json")
@Transactional @Transactional
public ResponseEntity<ResponseItem<List<RecentActivityModel>>> getNewRecentActivity(@RequestParam(name = "numOfActivities", required = false, defaultValue = "5") Integer numberOfActivities, public ResponseEntity<ResponseItem<List<RecentActivityModel>>> getNewRecentActivity(@RequestBody RecentActivityCriteria criteria, @RequestParam(name = "numOfActivities", required = false, defaultValue = "5") Integer numberOfActivities,
@ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) { @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) {
List<RecentActivityModel> statistics = dashBoardManager.getNewRecentActivity(principal, numberOfActivities); List<RecentActivityModel> statistics = dashBoardManager.getNewRecentActivity(criteria, principal, numberOfActivities);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<RecentActivityModel>>().status(ApiMessageCode.NO_MESSAGE).payload(statistics)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<RecentActivityModel>>().status(ApiMessageCode.NO_MESSAGE).payload(statistics));
} }

View File

@ -0,0 +1,22 @@
package eu.eudat.criteria;
public class RecentActivityCriteria {
private String like;
private String order;
public String getLike() {
return like;
}
public void setLike(String like) {
this.like = like;
}
public String getOrder() {
return order;
}
public void setOrder(String order) {
this.order = order;
}
}

View File

@ -1,5 +1,6 @@
package eu.eudat.logic.managers; package eu.eudat.logic.managers;
import eu.eudat.criteria.RecentActivityCriteria;
import eu.eudat.data.dao.criteria.*; import eu.eudat.data.dao.criteria.*;
import eu.eudat.data.dao.entities.DMPDao; import eu.eudat.data.dao.entities.DMPDao;
import eu.eudat.data.dao.entities.DatasetDao; import eu.eudat.data.dao.entities.DatasetDao;
@ -182,16 +183,18 @@ public class DashBoardManager {
} }
@Transactional @Transactional
public List<RecentActivityModel> getNewRecentActivity(Principal principal, Integer numberofactivities) { public List<RecentActivityModel> getNewRecentActivity(RecentActivityCriteria criteria, Principal principal, Integer numberofactivities) {
List<RecentActivityModel> recentActivityModels = new ArrayList<>(); List<RecentActivityModel> recentActivityModels = new ArrayList<>();
DMPDao dataManagementPlanRepository = databaseRepository.getDmpDao(); DMPDao dataManagementPlanRepository = databaseRepository.getDmpDao();
DatasetDao datasetRepository = databaseRepository.getDatasetDao(); DatasetDao datasetRepository = databaseRepository.getDatasetDao();
UserInfo user = new UserInfo(); UserInfo user = new UserInfo();
user.setId(principal.getId()); user.setId(principal.getId());
DatasetCriteria datasetCriteria = new DatasetCriteria(); DatasetCriteria datasetCriteria = new DatasetCriteria();
datasetCriteria.setLike(criteria.getLike());
datasetCriteria.setAllVersions(false); datasetCriteria.setAllVersions(false);
DataManagementPlanCriteria dataManagementPlanCriteria = new DataManagementPlanCriteria(); DataManagementPlanCriteria dataManagementPlanCriteria = new DataManagementPlanCriteria();
dataManagementPlanCriteria.setAllVersions(false); dataManagementPlanCriteria.setAllVersions(false);
dataManagementPlanCriteria.setLike(criteria.getLike());
QueryableList<DMP> dmpList; QueryableList<DMP> dmpList;
QueryableList<Dataset> datasetList; QueryableList<Dataset> datasetList;
@ -210,7 +213,7 @@ public class DashBoardManager {
CompletableFuture<List<RecentActivityModel>> dmps = dmpList CompletableFuture<List<RecentActivityModel>> dmps = dmpList
.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class)) .withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class))
.orderBy((builder, root) -> builder.desc(root.get("modified"))) .orderBy((builder, root) -> builder.desc(root.get(criteria.getOrder())))
.take(numberofactivities) .take(numberofactivities)
.selectAsync(item -> { .selectAsync(item -> {
return new RecentDmpModel().fromEntity(item); return new RecentDmpModel().fromEntity(item);
@ -219,7 +222,7 @@ public class DashBoardManager {
CompletableFuture<List<RecentActivityModel>> datasets = datasetList CompletableFuture<List<RecentActivityModel>> datasets = datasetList
.withHint(HintedModelFactory.getHint(DatasetListingModel.class)) .withHint(HintedModelFactory.getHint(DatasetListingModel.class))
.orderBy((builder, root) -> builder.desc(root.get("modified"))) .orderBy((builder, root) -> builder.desc(root.get(criteria.getOrder())))
.take(numberofactivities) .take(numberofactivities)
.selectAsync(item -> { .selectAsync(item -> {
return new RecentDatasetModel().fromEntity(item); return new RecentDatasetModel().fromEntity(item);

View File

@ -0,0 +1,6 @@
export enum RecentActivityOrder {
LABEL = "label",
CREATED = "created",
MODIFIED = "modified",
STATUS = "status"
}

View File

@ -0,0 +1,6 @@
import { RecentActivityOrder } from '@app/core/common/enum/recent-activity-order';
import { BaseCriteria } from '../base-criteria';
export class RecentActivityCriteria extends BaseCriteria{
public order: RecentActivityOrder = RecentActivityOrder.MODIFIED;
}

View File

@ -5,6 +5,7 @@ import { environment } from '../../../../environments/environment';
import { DashboardStatisticsModel } from '../../model/dashboard/dashboard-statistics-model'; import { DashboardStatisticsModel } from '../../model/dashboard/dashboard-statistics-model';
import { BaseHttpService } from '../http/base-http.service'; import { BaseHttpService } from '../http/base-http.service';
import { ConfigurationService } from '../configuration/configuration.service'; import { ConfigurationService } from '../configuration/configuration.service';
import { RecentActivityCriteria } from '@app/core/query/recent-activity/recent-activity-criteria';
@Injectable() @Injectable()
export class DashboardService { export class DashboardService {
@ -25,7 +26,7 @@ export class DashboardService {
return this.http.get<DashboardStatisticsModel>(this.actionUrl + 'me/getStatistics', { headers: this.headers }); return this.http.get<DashboardStatisticsModel>(this.actionUrl + 'me/getStatistics', { headers: this.headers });
} }
getRecentAcitvity(): Observable<any[]> { getRecentAcitvity(criteria: RecentActivityCriteria): Observable<any[]> {
return this.http.get<any[]>(this.actionUrl + 'recentActivity', {headers: this.headers}); return this.http.post<any[]>(this.actionUrl + 'recentActivity', criteria, {headers: this.headers});
} }
} }