Recent Activity controller will require a custom DataTable Request

This commit is contained in:
George Kalampokis 2020-07-03 10:43:19 +03:00
parent 1ec90d7b52
commit b57f6fb73c
4 changed files with 59 additions and 12 deletions

View File

@ -6,6 +6,7 @@ import eu.eudat.logic.security.claims.ClaimedAuthorities;
import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.dashboard.recent.RecentActivity; import eu.eudat.models.data.dashboard.recent.RecentActivity;
import eu.eudat.models.data.dashboard.recent.model.RecentActivityModel; import eu.eudat.models.data.dashboard.recent.model.RecentActivityModel;
import eu.eudat.models.data.dashboard.recent.tablerequest.RecentActivityTableRequest;
import eu.eudat.models.data.dashboard.searchbar.SearchBarItem; import eu.eudat.models.data.dashboard.searchbar.SearchBarItem;
import eu.eudat.models.data.dashboard.statistics.DashBoardStatistics; import eu.eudat.models.data.dashboard.statistics.DashBoardStatistics;
import eu.eudat.models.data.helpers.responses.ResponseItem; import eu.eudat.models.data.helpers.responses.ResponseItem;
@ -47,9 +48,9 @@ public class DashBoardController extends BaseController {
@RequestMapping(method = RequestMethod.POST, value = {"/dashboard/recentActivity"}, produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/dashboard/recentActivity"}, produces = "application/json")
@Transactional @Transactional
public ResponseEntity<ResponseItem<List<RecentActivityModel>>> getNewRecentActivity(@RequestBody RecentActivityCriteria criteria, @RequestParam(name = "numOfActivities", required = false, defaultValue = "5") Integer numberOfActivities, public ResponseEntity<ResponseItem<List<RecentActivityModel>>> getNewRecentActivity(@RequestBody RecentActivityTableRequest tableRequest,
@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(criteria, principal, numberOfActivities); List<RecentActivityModel> statistics = dashBoardManager.getNewRecentActivity(tableRequest, principal);
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

@ -18,6 +18,7 @@ import eu.eudat.models.data.dashboard.recent.RecentActivityData;
import eu.eudat.models.data.dashboard.recent.model.RecentActivityModel; import eu.eudat.models.data.dashboard.recent.model.RecentActivityModel;
import eu.eudat.models.data.dashboard.recent.model.RecentDatasetModel; import eu.eudat.models.data.dashboard.recent.model.RecentDatasetModel;
import eu.eudat.models.data.dashboard.recent.model.RecentDmpModel; import eu.eudat.models.data.dashboard.recent.model.RecentDmpModel;
import eu.eudat.models.data.dashboard.recent.tablerequest.RecentActivityTableRequest;
import eu.eudat.models.data.dashboard.searchbar.SearchBarItem; import eu.eudat.models.data.dashboard.searchbar.SearchBarItem;
import eu.eudat.models.data.dashboard.statistics.DashBoardStatistics; import eu.eudat.models.data.dashboard.statistics.DashBoardStatistics;
import eu.eudat.models.data.listingmodels.DataManagementPlanListingModel; import eu.eudat.models.data.listingmodels.DataManagementPlanListingModel;
@ -35,11 +36,19 @@ import java.io.IOException;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
@Component @Component
public class DashBoardManager { public class DashBoardManager {
private static final Logger logger = LoggerFactory.getLogger(DashBoardManager.class); private static final Logger logger = LoggerFactory.getLogger(DashBoardManager.class);
private final Map<String, Comparator<RecentActivityModel>> comparators = Stream.of(new Object[][] {
{ "modified", Comparator.comparing(o -> ((RecentActivityModel)o).getModified())},
{ "created", Comparator.comparing(o -> ((RecentActivityModel)o).getCreated())},
{ "label", Comparator.comparing(o -> ((RecentActivityModel)o).getTitle())},
{ "status", Comparator.comparing(o -> ((RecentActivityModel)o).getStatus())}
}).collect(Collectors.toMap(data -> (String) data[0], data -> (Comparator<RecentActivityModel>)data[1]));
private ApiContext apiContext; private ApiContext apiContext;
private DatabaseRepository databaseRepository; private DatabaseRepository databaseRepository;
@ -183,18 +192,18 @@ public class DashBoardManager {
} }
@Transactional @Transactional
public List<RecentActivityModel> getNewRecentActivity(RecentActivityCriteria criteria, Principal principal, Integer numberofactivities) { public List<RecentActivityModel> getNewRecentActivity(RecentActivityTableRequest tableRequest, Principal principal) {
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.setLike(tableRequest.getCriteria().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()); dataManagementPlanCriteria.setLike(tableRequest.getCriteria().getLike());
QueryableList<DMP> dmpList; QueryableList<DMP> dmpList;
QueryableList<Dataset> datasetList; QueryableList<Dataset> datasetList;
@ -213,8 +222,9 @@ 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(criteria.getOrder()))) .orderBy((builder, root) -> builder.desc(root.get(tableRequest.getCriteria().getOrder())))
.take(numberofactivities) .skip(tableRequest.getOffset())
.take(tableRequest.getSize())
.selectAsync(item -> { .selectAsync(item -> {
return new RecentDmpModel().fromEntity(item); return new RecentDmpModel().fromEntity(item);
}) })
@ -222,15 +232,17 @@ 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(criteria.getOrder()))) .orderBy((builder, root) -> builder.desc(root.get(tableRequest.getCriteria().getOrder())))
.take(numberofactivities) .skip(tableRequest.getOffset())
.take(tableRequest.getSize())
.selectAsync(item -> { .selectAsync(item -> {
return new RecentDatasetModel().fromEntity(item); return new RecentDatasetModel().fromEntity(item);
}) })
.whenComplete((datasetActivities, throwable) -> recentActivityModels.addAll(datasetActivities)); .whenComplete((datasetActivities, throwable) -> recentActivityModels.addAll(datasetActivities));
CompletableFuture.allOf(dmps, datasets).join(); CompletableFuture.allOf(dmps, datasets).join();
return recentActivityModels.stream().sorted(Comparator.comparing(RecentActivityModel::getModified)).collect(Collectors.toList());
return recentActivityModels.stream().sorted(this.comparators.get(tableRequest.getCriteria().getOrder())).collect(Collectors.toList());
} }
public List<SearchBarItem> searchUserData(String like, Principal principal) { public List<SearchBarItem> searchUserData(String like, Principal principal) {

View File

@ -0,0 +1,33 @@
package eu.eudat.models.data.dashboard.recent.tablerequest;
import eu.eudat.criteria.RecentActivityCriteria;
public class RecentActivityTableRequest {
private RecentActivityCriteria criteria;
private int offset;
private int size;
public int getOffset() {
return offset;
}
public void setOffset(int offset) {
this.offset = offset;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public RecentActivityCriteria getCriteria() {
return criteria;
}
public void setCriteria(RecentActivityCriteria criteria) {
this.criteria = criteria;
}
}

View File

@ -7,6 +7,7 @@ import { BaseHttpService } from '../http/base-http.service';
import { ConfigurationService } from '../configuration/configuration.service'; import { ConfigurationService } from '../configuration/configuration.service';
import { RecentActivityModel } from '@app/core/model/recent-activity/recent-activity.model'; import { RecentActivityModel } from '@app/core/model/recent-activity/recent-activity.model';
import { RecentActivityCriteria } from '@app/core/query/recent-activity/recent-activity-criteria'; import { RecentActivityCriteria } from '@app/core/query/recent-activity/recent-activity-criteria';
import { DataTableRequest } from '@app/core/model/data-table/data-table-request';
@Injectable() @Injectable()
export class DashboardService { export class DashboardService {
@ -27,7 +28,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(criteria: RecentActivityCriteria): Observable<RecentActivityModel[]> { getRecentAcitvity(request: DataTableRequest<RecentActivityCriteria>): Observable<RecentActivityModel[]> {
return this.http.post<RecentActivityModel[]>(this.actionUrl + 'recentActivity', criteria, {headers: this.headers}); return this.http.post<RecentActivityModel[]>(this.actionUrl + 'recentActivity', request, {headers: this.headers});
} }
} }