Recent Activity controller will require a custom DataTable Request
This commit is contained in:
parent
1ec90d7b52
commit
b57f6fb73c
|
@ -6,6 +6,7 @@ import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
|||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.models.data.dashboard.recent.RecentActivity;
|
||||
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.statistics.DashBoardStatistics;
|
||||
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")
|
||||
@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) {
|
||||
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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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.RecentDatasetModel;
|
||||
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.statistics.DashBoardStatistics;
|
||||
import eu.eudat.models.data.listingmodels.DataManagementPlanListingModel;
|
||||
|
@ -35,11 +36,19 @@ import java.io.IOException;
|
|||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Component
|
||||
public class DashBoardManager {
|
||||
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 DatabaseRepository databaseRepository;
|
||||
|
||||
|
@ -183,18 +192,18 @@ public class DashBoardManager {
|
|||
}
|
||||
|
||||
@Transactional
|
||||
public List<RecentActivityModel> getNewRecentActivity(RecentActivityCriteria criteria, Principal principal, Integer numberofactivities) {
|
||||
public List<RecentActivityModel> getNewRecentActivity(RecentActivityTableRequest tableRequest, Principal principal) {
|
||||
List<RecentActivityModel> recentActivityModels = new ArrayList<>();
|
||||
DMPDao dataManagementPlanRepository = databaseRepository.getDmpDao();
|
||||
DatasetDao datasetRepository = databaseRepository.getDatasetDao();
|
||||
UserInfo user = new UserInfo();
|
||||
user.setId(principal.getId());
|
||||
DatasetCriteria datasetCriteria = new DatasetCriteria();
|
||||
datasetCriteria.setLike(criteria.getLike());
|
||||
datasetCriteria.setLike(tableRequest.getCriteria().getLike());
|
||||
datasetCriteria.setAllVersions(false);
|
||||
DataManagementPlanCriteria dataManagementPlanCriteria = new DataManagementPlanCriteria();
|
||||
dataManagementPlanCriteria.setAllVersions(false);
|
||||
dataManagementPlanCriteria.setLike(criteria.getLike());
|
||||
dataManagementPlanCriteria.setLike(tableRequest.getCriteria().getLike());
|
||||
|
||||
QueryableList<DMP> dmpList;
|
||||
QueryableList<Dataset> datasetList;
|
||||
|
@ -213,8 +222,9 @@ public class DashBoardManager {
|
|||
|
||||
CompletableFuture<List<RecentActivityModel>> dmps = dmpList
|
||||
.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class))
|
||||
.orderBy((builder, root) -> builder.desc(root.get(criteria.getOrder())))
|
||||
.take(numberofactivities)
|
||||
.orderBy((builder, root) -> builder.desc(root.get(tableRequest.getCriteria().getOrder())))
|
||||
.skip(tableRequest.getOffset())
|
||||
.take(tableRequest.getSize())
|
||||
.selectAsync(item -> {
|
||||
return new RecentDmpModel().fromEntity(item);
|
||||
})
|
||||
|
@ -222,15 +232,17 @@ public class DashBoardManager {
|
|||
|
||||
CompletableFuture<List<RecentActivityModel>> datasets = datasetList
|
||||
.withHint(HintedModelFactory.getHint(DatasetListingModel.class))
|
||||
.orderBy((builder, root) -> builder.desc(root.get(criteria.getOrder())))
|
||||
.take(numberofactivities)
|
||||
.orderBy((builder, root) -> builder.desc(root.get(tableRequest.getCriteria().getOrder())))
|
||||
.skip(tableRequest.getOffset())
|
||||
.take(tableRequest.getSize())
|
||||
.selectAsync(item -> {
|
||||
return new RecentDatasetModel().fromEntity(item);
|
||||
})
|
||||
.whenComplete((datasetActivities, throwable) -> recentActivityModels.addAll(datasetActivities));
|
||||
|
||||
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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import { BaseHttpService } from '../http/base-http.service';
|
|||
import { ConfigurationService } from '../configuration/configuration.service';
|
||||
import { RecentActivityModel } from '@app/core/model/recent-activity/recent-activity.model';
|
||||
import { RecentActivityCriteria } from '@app/core/query/recent-activity/recent-activity-criteria';
|
||||
import { DataTableRequest } from '@app/core/model/data-table/data-table-request';
|
||||
|
||||
@Injectable()
|
||||
export class DashboardService {
|
||||
|
@ -27,7 +28,7 @@ export class DashboardService {
|
|||
return this.http.get<DashboardStatisticsModel>(this.actionUrl + 'me/getStatistics', { headers: this.headers });
|
||||
}
|
||||
|
||||
getRecentAcitvity(criteria: RecentActivityCriteria): Observable<RecentActivityModel[]> {
|
||||
return this.http.post<RecentActivityModel[]>(this.actionUrl + 'recentActivity', criteria, {headers: this.headers});
|
||||
getRecentAcitvity(request: DataTableRequest<RecentActivityCriteria>): Observable<RecentActivityModel[]> {
|
||||
return this.http.post<RecentActivityModel[]>(this.actionUrl + 'recentActivity', request, {headers: this.headers});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue