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;
|
2018-11-30 15:57:20 +01:00
|
|
|
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;
|
2018-11-30 15:57:20 +01:00
|
|
|
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
|
2019-01-30 17:37:49 +01:00
|
|
|
@RequestMapping(value = {"/api/projects/"})
|
2018-01-17 13:03:51 +01:00
|
|
|
public class Projects extends BaseController {
|
2019-01-30 17:37:49 +01:00
|
|
|
private ProjectManager projectManager;
|
2018-01-03 11:44:54 +01:00
|
|
|
|
2018-01-17 13:03:51 +01:00
|
|
|
@Autowired
|
2019-01-31 12:24:11 +01:00
|
|
|
public Projects(ApiContext apiContext, ProjectManager projectManager) {
|
2018-01-17 13:03:51 +01:00
|
|
|
super(apiContext);
|
2019-01-30 17:37:49 +01:00
|
|
|
this.projectManager = projectManager;
|
2018-01-17 13:03:51 +01:00
|
|
|
}
|
2017-12-15 11:05:51 +01:00
|
|
|
|
2019-01-30 17:37:49 +01:00
|
|
|
@RequestMapping(method = RequestMethod.POST, value = {"/paged"}, consumes = "application/json", produces = "application/json")
|
2018-01-31 16:39:16 +01:00
|
|
|
public @ResponseBody
|
2019-01-31 12:24:11 +01:00
|
|
|
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
|
|
|
|
2019-01-30 17:37:49 +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 {
|
2019-01-30 17:37:49 +01:00
|
|
|
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
|
2019-01-30 17:37:49 +01:00
|
|
|
@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 {
|
2019-01-30 17:37:49 +01:00
|
|
|
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
|
2019-01-30 17:37:49 +01:00
|
|
|
@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 {
|
2019-01-30 17:37:49 +01:00
|
|
|
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
|
|
|
|
2019-01-30 17:37:49 +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 {
|
2019-01-30 17:37:49 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-01-30 17:37:49 +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 {
|
2019-01-30 17:37:49 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|