package eu.eudat.controllers; import eu.eudat.logic.managers.DashBoardManager; import eu.eudat.logic.services.ApiContext; import eu.eudat.models.data.dashboard.recent.RecentActivity; import eu.eudat.models.data.dashboard.searchbar.SearchBarItem; import eu.eudat.models.data.dashboard.statistics.DashBoardStatistics; import eu.eudat.models.data.helpers.responses.ResponseItem; import eu.eudat.models.data.security.Principal; import eu.eudat.types.ApiMessageCode; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.util.List; @RestController @CrossOrigin @RequestMapping(value = {"/api"}) public class DashBoardController extends BaseController { @Autowired public DashBoardController(ApiContext apiContext) { super(apiContext); } @RequestMapping(method = RequestMethod.GET, value = {"/dashboard/getStatistics"}, produces = "application/json") public ResponseEntity> getStatistics() { DashBoardStatistics statistics = new DashBoardManager().getStatistics(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao() , this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao()); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(statistics)); } @RequestMapping(method = RequestMethod.GET, value = {"/dashboard/me/getStatistics"}, produces = "application/json") public ResponseEntity> getStatistics(Principal principal) { DashBoardStatistics statistics = new DashBoardManager().getMeStatistics(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao() , this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(statistics)); } @RequestMapping(method = RequestMethod.GET, value = {"/user/recentActivity"}, produces = "application/json") public ResponseEntity> getRecentActivity(@RequestParam(name = "numOfActivities", required = false, defaultValue = "5") Integer numberOfActivities, Principal principal) { RecentActivity statistics = new DashBoardManager().getRecentActivity(this.getApiContext(), this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao() , this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), principal, numberOfActivities); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(statistics)); } @RequestMapping(method = RequestMethod.GET, value = {"/dashboard/search"}, produces = "application/json") public ResponseEntity>> search(@RequestParam(name = "like") String like, Principal principal) { List searchBarItemList = new DashBoardManager().searchUserData(like, this.getApiContext(), this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao() , this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(searchBarItemList)); } }