2017-12-15 11:05:51 +01:00
|
|
|
package eu.eudat.controllers;
|
|
|
|
|
2020-07-02 10:57:59 +02:00
|
|
|
import eu.eudat.criteria.RecentActivityCriteria;
|
2018-06-27 12:29:21 +02:00
|
|
|
import eu.eudat.logic.managers.DashBoardManager;
|
2020-01-03 15:52:27 +01:00
|
|
|
import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
2018-08-31 16:12:31 +02:00
|
|
|
import eu.eudat.logic.services.ApiContext;
|
2018-06-27 12:29:21 +02:00
|
|
|
import eu.eudat.models.data.dashboard.recent.RecentActivity;
|
2020-06-30 15:59:06 +02:00
|
|
|
import eu.eudat.models.data.dashboard.recent.model.RecentActivityModel;
|
2020-07-03 09:43:19 +02:00
|
|
|
import eu.eudat.models.data.dashboard.recent.tablerequest.RecentActivityTableRequest;
|
2018-08-24 17:21:02 +02:00
|
|
|
import eu.eudat.models.data.dashboard.searchbar.SearchBarItem;
|
2018-06-27 12:29:21 +02:00
|
|
|
import eu.eudat.models.data.dashboard.statistics.DashBoardStatistics;
|
|
|
|
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
|
|
|
import eu.eudat.models.data.security.Principal;
|
2018-01-23 16:21:38 +01:00
|
|
|
import eu.eudat.types.ApiMessageCode;
|
2020-01-03 15:52:27 +01:00
|
|
|
import eu.eudat.types.Authorities;
|
2017-12-15 11:05:51 +01:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.http.HttpStatus;
|
2018-01-22 08:41:31 +01:00
|
|
|
import org.springframework.http.ResponseEntity;
|
2018-03-19 13:40:04 +01:00
|
|
|
import org.springframework.web.bind.annotation.*;
|
2017-12-15 11:05:51 +01:00
|
|
|
|
2020-06-30 15:59:06 +02:00
|
|
|
import javax.transaction.Transactional;
|
2020-03-18 10:22:10 +01:00
|
|
|
import java.io.IOException;
|
2018-08-24 17:21:02 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2017-12-15 11:05:51 +01:00
|
|
|
@RestController
|
|
|
|
@CrossOrigin
|
2018-02-09 16:54:41 +01:00
|
|
|
@RequestMapping(value = {"/api"})
|
2018-02-16 11:34:02 +01:00
|
|
|
public class DashBoardController extends BaseController {
|
2018-01-04 10:32:39 +01:00
|
|
|
|
2019-03-05 16:33:59 +01:00
|
|
|
private DashBoardManager dashBoardManager;
|
2018-02-16 11:34:02 +01:00
|
|
|
@Autowired
|
2019-03-05 16:33:59 +01:00
|
|
|
public DashBoardController(ApiContext apiContext, DashBoardManager dashBoardManager) {
|
2018-02-16 11:34:02 +01:00
|
|
|
super(apiContext);
|
2019-03-05 16:33:59 +01:00
|
|
|
this.dashBoardManager = dashBoardManager;
|
2018-02-16 11:34:02 +01:00
|
|
|
}
|
2018-01-04 10:32:39 +01:00
|
|
|
|
2018-02-16 11:34:02 +01:00
|
|
|
@RequestMapping(method = RequestMethod.GET, value = {"/dashboard/getStatistics"}, produces = "application/json")
|
|
|
|
public ResponseEntity<ResponseItem<DashBoardStatistics>> getStatistics() {
|
2019-03-05 16:33:59 +01:00
|
|
|
DashBoardStatistics statistics = dashBoardManager.getStatistics();
|
2018-08-31 16:12:31 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DashBoardStatistics>().status(ApiMessageCode.NO_MESSAGE).payload(statistics));
|
2018-02-16 11:34:02 +01:00
|
|
|
}
|
2018-02-02 11:33:37 +01:00
|
|
|
|
2018-02-16 11:34:02 +01:00
|
|
|
@RequestMapping(method = RequestMethod.GET, value = {"/dashboard/me/getStatistics"}, produces = "application/json")
|
2020-03-18 10:22:10 +01:00
|
|
|
public ResponseEntity<ResponseItem<DashBoardStatistics>> getStatistics(Principal principal) throws IOException {
|
2019-03-05 16:33:59 +01:00
|
|
|
DashBoardStatistics statistics = dashBoardManager.getMeStatistics(principal);
|
2018-08-31 16:12:31 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DashBoardStatistics>().status(ApiMessageCode.NO_MESSAGE).payload(statistics));
|
2018-02-16 11:34:02 +01:00
|
|
|
}
|
2018-03-19 13:40:04 +01:00
|
|
|
|
2020-07-02 10:57:59 +02:00
|
|
|
@RequestMapping(method = RequestMethod.POST, value = {"/dashboard/recentActivity"}, produces = "application/json")
|
2020-06-30 15:59:06 +02:00
|
|
|
@Transactional
|
2020-07-03 09:43:19 +02:00
|
|
|
public ResponseEntity<ResponseItem<List<RecentActivityModel>>> getNewRecentActivity(@RequestBody RecentActivityTableRequest tableRequest,
|
2020-06-30 15:59:06 +02:00
|
|
|
@ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) {
|
2020-07-03 09:43:19 +02:00
|
|
|
List<RecentActivityModel> statistics = dashBoardManager.getNewRecentActivity(tableRequest, principal);
|
2020-06-30 15:59:06 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<RecentActivityModel>>().status(ApiMessageCode.NO_MESSAGE).payload(statistics));
|
|
|
|
}
|
|
|
|
|
2018-03-19 13:40:04 +01:00
|
|
|
@RequestMapping(method = RequestMethod.GET, value = {"/user/recentActivity"}, produces = "application/json")
|
|
|
|
public ResponseEntity<ResponseItem<RecentActivity>> getRecentActivity(@RequestParam(name = "numOfActivities", required = false, defaultValue = "5") Integer numberOfActivities, Principal principal) {
|
2019-03-05 16:33:59 +01:00
|
|
|
RecentActivity statistics = dashBoardManager.getRecentActivity(principal, numberOfActivities);
|
2018-08-31 16:12:31 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<RecentActivity>().status(ApiMessageCode.NO_MESSAGE).payload(statistics));
|
2018-03-19 13:40:04 +01:00
|
|
|
}
|
2018-08-24 17:21:02 +02:00
|
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = {"/dashboard/search"}, produces = "application/json")
|
2020-01-03 15:52:27 +01:00
|
|
|
public ResponseEntity<ResponseItem<List<SearchBarItem>>> search(@RequestParam(name = "like") String like,
|
|
|
|
@ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) {
|
2019-03-05 16:33:59 +01:00
|
|
|
List<SearchBarItem> searchBarItemList = dashBoardManager.searchUserData(like, principal);
|
2018-08-31 16:12:31 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<SearchBarItem>>().status(ApiMessageCode.NO_MESSAGE).payload(searchBarItemList));
|
2018-08-24 17:21:02 +02:00
|
|
|
}
|
2017-12-15 11:05:51 +01:00
|
|
|
}
|