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

93 lines
6.2 KiB
Java
Raw Normal View History

2017-12-15 11:05:51 +01:00
package eu.eudat.controllers;
2018-03-21 11:57:56 +01:00
import eu.eudat.data.entities.Project;
2018-08-31 16:12:31 +02:00
import eu.eudat.data.query.items.item.project.ProjectCriteriaRequest;
import eu.eudat.data.query.items.table.project.ProjectTableRequest;
import eu.eudat.exceptions.project.ProjectWithDMPsDeleteException;
2018-06-27 12:29:21 +02:00
import eu.eudat.logic.managers.ProjectManager;
2018-08-31 16:12:31 +02:00
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
2018-10-02 16:33:58 +02: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.external.ProjectsExternalSourcesModel;
import eu.eudat.models.data.helpers.common.DataTableData;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.project.ProjectListingModel;
import eu.eudat.models.data.security.Principal;
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;
import org.springframework.http.ResponseEntity;
2018-02-16 11:34:02 +01:00
import org.springframework.web.bind.annotation.*;
2017-12-15 11:05:51 +01:00
2018-02-16 11:34:02 +01:00
import javax.transaction.Transactional;
import javax.validation.Valid;
2018-08-31 16:12:31 +02:00
import java.io.IOException;
import java.text.ParseException;
2018-02-16 11:34:02 +01:00
import java.util.List;
import java.util.Map;
import java.util.UUID;
2018-01-31 16:39:16 +01:00
2018-10-02 16:33:58 +02:00
import static eu.eudat.types.Authorities.ANONYMOUS;
2017-12-15 11:05:51 +01:00
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/projects/"})
2018-01-17 13:03:51 +01:00
public class Projects extends BaseController {
private ProjectManager projectManager;
2018-01-03 11:44:54 +01:00
2018-01-17 13:03:51 +01:00
@Autowired
public Projects(ApiContext apiContext, ProjectManager projectManager) {
2018-01-17 13:03:51 +01:00
super(apiContext);
this.projectManager = projectManager;
2018-01-17 13:03:51 +01:00
}
2017-12-15 11:05:51 +01:00
@RequestMapping(method = RequestMethod.POST, value = {"/paged"}, consumes = "application/json", produces = "application/json")
2018-01-31 16:39:16 +01:00
public @ResponseBody
ResponseEntity<ResponseItem<DataTableData<ProjectListingModel>>> getPaged(@Valid @RequestBody ProjectTableRequest projectTableRequest, @RequestParam String fieldsGroup, Principal principal) throws Exception {
System.out.println(fieldsGroup);
DataTableData<eu.eudat.models.data.project.ProjectListingModel> dataTable = this.projectManager.getPaged(this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), projectTableRequest, principal, fieldsGroup);
2018-08-31 16:12:31 +02:00
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<eu.eudat.models.data.project.ProjectListingModel>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
2018-01-17 13:03:51 +01:00
}
2017-12-19 09:38:47 +01:00
@RequestMapping(method = RequestMethod.GET, value = {"{id}"}, produces = "application/json")
2018-01-31 16:39:16 +01:00
public @ResponseBody
2018-06-27 12:29:21 +02:00
ResponseEntity<ResponseItem<eu.eudat.models.data.project.Project>> getSingle(@PathVariable String id, Principal principal) throws IllegalAccessException, InstantiationException {
eu.eudat.models.data.project.Project project = this.projectManager.getSingle(this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), id);
2018-08-31 16:12:31 +02:00
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.models.data.project.Project>().payload(project).status(ApiMessageCode.NO_MESSAGE));
2018-01-17 13:03:51 +01:00
}
2017-12-19 09:38:47 +01:00
2018-01-17 13:03:51 +01:00
@Transactional
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
2018-01-31 16:39:16 +01:00
public @ResponseBody
2018-08-31 16:12:31 +02:00
ResponseEntity<ResponseItem<Project>> addProject(@Valid @RequestBody eu.eudat.models.data.project.Project project, Principal principal) throws IOException, ParseException {
this.projectManager.createOrUpdate(this.getApiContext().getOperationsContext().getFileStorageService(), this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), this.getApiContext().getOperationsContext().getDatabaseRepository().getContentDao(), this.getApiContext().getOperationsContext().getDatabaseRepository().getUserInfoDao(), project, principal);
2018-08-31 16:12:31 +02:00
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.data.entities.Project>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created"));
2018-01-17 13:03:51 +01:00
}
2017-12-22 14:42:47 +01:00
2018-01-17 13:03:51 +01:00
@Transactional
@RequestMapping(method = RequestMethod.DELETE, value = {"{id}"}, consumes = "application/json", produces = "application/json")
2018-01-31 16:39:16 +01:00
public @ResponseBody
2018-08-31 16:12:31 +02:00
ResponseEntity<ResponseItem<Project>> inactivate(@PathVariable String id, Principal principal) throws IllegalAccessException, InstantiationException {
this.projectManager.inactivate(this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), id);
2018-08-31 16:12:31 +02:00
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.data.entities.Project>().status(ApiMessageCode.SUCCESS_MESSAGE));
2018-01-17 13:03:51 +01:00
}
2017-12-19 09:38:47 +01:00
@RequestMapping(method = RequestMethod.POST, value = {"/external"}, consumes = "application/json", produces = "application/json")
2018-01-31 16:39:16 +01:00
public @ResponseBody
2018-08-31 16:12:31 +02:00
ResponseEntity<ResponseItem<List<eu.eudat.models.data.project.Project>>> getWithExternal(@RequestBody ProjectCriteriaRequest projectCriteria, Principal principal) throws NoURLFound, InstantiationException, HugeResultSet, IllegalAccessException {
List<eu.eudat.models.data.project.Project> dataTable = this.projectManager.getCriteriaWithExternal(this.getApiContext(), projectCriteria, this.getApiContext().getOperationsContext().getRemoteFetcher());
2018-08-31 16:12:31 +02:00
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<eu.eudat.models.data.project.Project>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
2018-01-17 13:03:51 +01:00
}
@RequestMapping(method = RequestMethod.POST, value = {"get"}, consumes = "application/json", produces = "application/json")
2018-01-31 16:39:16 +01:00
public @ResponseBody
2018-10-02 16:33:58 +02:00
ResponseEntity<ResponseItem<List<eu.eudat.models.data.project.Project>>> get(@RequestBody ProjectCriteriaRequest projectCriteria, @ClaimedAuthorities(claims = {ANONYMOUS}) Principal principal) throws NoURLFound, InstantiationException, HugeResultSet, IllegalAccessException {
List<eu.eudat.models.data.project.Project> dataTable = this.projectManager.getCriteria(this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), projectCriteria, this.getApiContext().getOperationsContext().getRemoteFetcher());
2018-08-31 16:12:31 +02:00
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<eu.eudat.models.data.project.Project>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
2018-01-17 13:03:51 +01:00
}
2017-12-15 11:05:51 +01:00
}