argos/dmp-backend/src/main/java/eu/eudat/controllers/DashBoardController.java

43 lines
1.8 KiB
Java
Raw Normal View History

2017-12-15 11:05:51 +01:00
package eu.eudat.controllers;
import eu.eudat.models.helpers.responses.ResponseItem;
2017-12-15 17:57:41 +01:00
import eu.eudat.models.security.Principal;
2018-01-04 10:32:39 +01:00
import eu.eudat.services.ApiContext;
2018-01-23 16:21:38 +01:00
import eu.eudat.types.ApiMessageCode;
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;
2017-12-15 11:05:51 +01:00
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import eu.eudat.dao.entities.DMPDao;
import eu.eudat.dao.entities.DatasetDao;
import eu.eudat.dao.entities.ProjectDao;
import eu.eudat.managers.DashBoardManager;
import eu.eudat.models.dashboard.DashBoardStatistics;
@RestController
@CrossOrigin
2018-01-04 10:32:39 +01:00
public class DashBoardController extends BaseController{
@Autowired
public DashBoardController(ApiContext apiContext) {
super(apiContext);
}
2017-12-15 11:05:51 +01:00
@RequestMapping(method = RequestMethod.GET, value = { "/dashboard/getStatistics" }, produces="application/json")
2018-01-22 08:41:31 +01:00
public ResponseEntity<ResponseItem<DashBoardStatistics>> getStatistics(Principal principal){
2017-12-15 11:05:51 +01:00
try {
2018-01-04 10:32:39 +01:00
DashBoardStatistics statistics = new DashBoardManager().getStatistics(this.getApiContext().getDatabaseRepository().getDatasetDao(), this.getApiContext().getDatabaseRepository().getDmpDao()
, this.getApiContext().getDatabaseRepository().getProjectDao());
2018-01-23 16:21:38 +01:00
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DashBoardStatistics>().status(ApiMessageCode.NO_MESSAGE).payload(statistics));
2017-12-15 11:05:51 +01:00
}
catch(Exception ex) {
ex.printStackTrace();
2018-01-23 16:21:38 +01:00
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DashBoardStatistics>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
2017-12-15 11:05:51 +01:00
}
}
}