157 lines
9.5 KiB
Java
157 lines
9.5 KiB
Java
package eu.eudat.controllers;
|
|
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.UUID;
|
|
|
|
import javax.transaction.Transactional;
|
|
import javax.validation.Valid;
|
|
|
|
import eu.eudat.models.criteria.ProjectCriteria;
|
|
import eu.eudat.models.external.OrganisationsExternalSourcesModel;
|
|
import eu.eudat.models.external.ProjectsExternalSourcesModel;
|
|
import eu.eudat.models.external.RegistriesExternalSourcesModel;
|
|
import eu.eudat.models.helpers.responses.*;
|
|
import eu.eudat.models.project.ProjectCriteriaRequest;
|
|
import eu.eudat.models.project.ProjectListingModel;
|
|
import eu.eudat.models.security.Principal;
|
|
import eu.eudat.services.ApiContext;
|
|
import eu.eudat.types.ApiMessageCode;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.context.ApplicationContext;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import eu.eudat.dao.entities.DMPDao;
|
|
import eu.eudat.dao.entities.DMPProfileDao;
|
|
import eu.eudat.dao.entities.DataRepositoryDao;
|
|
import eu.eudat.dao.entities.DatasetDao;
|
|
import eu.eudat.dao.entities.DatasetProfileDao;
|
|
import eu.eudat.dao.entities.DatasetProfileRulesetDao;
|
|
import eu.eudat.dao.entities.DatasetProfileViewstyleDao;
|
|
import eu.eudat.dao.entities.OrganisationDao;
|
|
import eu.eudat.dao.entities.ProjectDao;
|
|
import eu.eudat.dao.entities.RegistryDao;
|
|
import eu.eudat.dao.entities.ResearcherDao;
|
|
import eu.eudat.dao.entities.ServiceDao;
|
|
import eu.eudat.dao.entities.UserInfoDao;
|
|
import eu.eudat.entities.DMP;
|
|
import eu.eudat.entities.Project;
|
|
import eu.eudat.entities.UserInfo;
|
|
import eu.eudat.entities.responses.IDLabelPair;
|
|
|
|
import eu.eudat.managers.ProjectManager;
|
|
import eu.eudat.models.helpers.DataTableData;
|
|
import eu.eudat.models.project.ProjectTableRequest;
|
|
import eu.eudat.proxy.config.exceptions.HugeResultSet;
|
|
import eu.eudat.proxy.config.exceptions.NoURLFound;
|
|
import eu.eudat.proxy.fetching.RemoteFetcher;
|
|
|
|
|
|
@RestController
|
|
@CrossOrigin
|
|
public class Projects extends BaseController {
|
|
|
|
@Autowired
|
|
public Projects(ApiContext apiContext) {
|
|
super(apiContext);
|
|
}
|
|
|
|
@RequestMapping(method = RequestMethod.POST, value = {"/projects/getPaged"}, consumes = "application/json", produces = "application/json")
|
|
public @ResponseBody ResponseEntity<ResponseItem<DataTableData<ProjectListingModel>>> getPaged(@Valid @RequestBody ProjectTableRequest projectTableRequest, Principal principal) {
|
|
try {
|
|
DataTableData<eu.eudat.models.project.ProjectListingModel> dataTable = new ProjectManager().getPaged(this.getApiContext().getDatabaseRepository().getProjectDao(), projectTableRequest);
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<eu.eudat.models.project.ProjectListingModel>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
|
|
|
|
} catch (Exception ex) {
|
|
ex.printStackTrace();
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataTableData<eu.eudat.models.project.ProjectListingModel>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
|
|
}
|
|
}
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = {"/projects/getSingle/{id}"}, produces = "application/json")
|
|
public @ResponseBody ResponseEntity<ResponseItem<eu.eudat.models.project.Project>> getSingle(@PathVariable String id, Principal principal) {
|
|
try {
|
|
eu.eudat.models.project.Project project = new ProjectManager().getSingle(this.getApiContext().getDatabaseRepository().getProjectDao(), id);
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.models.project.Project>().payload(project).status(ApiMessageCode.NO_MESSAGE));
|
|
} catch (Exception ex) {
|
|
ex.printStackTrace();
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<eu.eudat.models.project.Project>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
|
|
}
|
|
}
|
|
|
|
|
|
@Transactional
|
|
@RequestMapping(method = RequestMethod.POST, value = {"/projects/createOrUpdate"}, consumes = "application/json", produces = "application/json")
|
|
public @ResponseBody ResponseEntity<ResponseItem<Project>> addProject(@Valid @RequestBody eu.eudat.models.project.Project project, Principal principal) {
|
|
try {
|
|
ProjectManager.createOrUpdate(this.getApiContext().getDatabaseRepository().getProjectDao(), this.getApiContext().getDatabaseRepository().getUserInfoDao(), project, principal);
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.entities.Project>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created"));
|
|
} catch (Exception ex) {
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<eu.eudat.entities.Project>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
|
|
}
|
|
}
|
|
|
|
|
|
@Transactional
|
|
@RequestMapping(method = RequestMethod.DELETE, value = {"/projects/inactivate/{id}"}, consumes = "application/json", produces = "application/json")
|
|
public @ResponseBody ResponseEntity<ResponseItem<Project>> inactivate(@PathVariable String id, Principal principal) {
|
|
try {
|
|
Project project = new ProjectManager().inactivate(this.getApiContext().getDatabaseRepository().getProjectDao(), id);
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.entities.Project>().status(ApiMessageCode.SUCCESS_MESSAGE));
|
|
} catch (Exception ex) {
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<eu.eudat.entities.Project>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
|
|
}
|
|
}
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.POST, value = {"/projects/getWithExternal"}, consumes = "application/json", produces = "application/json")
|
|
public @ResponseBody ResponseEntity<ResponseItem<List<eu.eudat.models.project.Project>>> getWithExternal(@RequestBody ProjectCriteriaRequest projectCriteria, Principal principal) {
|
|
try {
|
|
List<eu.eudat.models.project.Project> dataTable = new ProjectManager().getCriteriaWithExternal(this.getApiContext().getDatabaseRepository().getProjectDao(), projectCriteria, this.getApiContext().getRemoteFetcher());
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<eu.eudat.models.project.Project>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
|
|
} catch (Exception ex) {
|
|
ex.printStackTrace();
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<eu.eudat.models.project.Project>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
|
|
}
|
|
}
|
|
|
|
@RequestMapping(method = RequestMethod.POST, value = {"/projects/get"}, consumes = "application/json", produces = "application/json")
|
|
public @ResponseBody ResponseEntity<ResponseItem<List<eu.eudat.models.project.Project>>> get(@RequestBody ProjectCriteriaRequest projectCriteria, Principal principal) {
|
|
try {
|
|
List<eu.eudat.models.project.Project> dataTable = new ProjectManager().getCriteria(this.getApiContext().getDatabaseRepository().getProjectDao(), projectCriteria, this.getApiContext().getRemoteFetcher());
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<eu.eudat.models.project.Project>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
|
|
} catch (Exception ex) {
|
|
ex.printStackTrace();
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<eu.eudat.models.project.Project>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
|
|
}
|
|
}
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = {"/external/projects"}, produces = "application/json")
|
|
public @ResponseBody ResponseEntity<ResponseItem<ProjectsExternalSourcesModel>> listExternalProjects(@RequestParam(value = "query", required = false) String query, Principal principal) {
|
|
try {
|
|
List<Map<String, String>> remoteRepos = this.getApiContext().getRemoteFetcher().getProjects(query);
|
|
ProjectsExternalSourcesModel projectsExternalSourcesModel = new ProjectsExternalSourcesModel().fromExternalItem(remoteRepos);
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ProjectsExternalSourcesModel>().payload(projectsExternalSourcesModel).status(ApiMessageCode.SUCCESS_MESSAGE));
|
|
} catch (NoURLFound ex) {
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<ProjectsExternalSourcesModel>().status(ApiMessageCode.ERROR_MESSAGE).message("External Url Not Found"));
|
|
} catch (HugeResultSet ex) {
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<ProjectsExternalSourcesModel>().status(ApiMessageCode.ERROR_MESSAGE).message("Huge Result Set"));
|
|
} catch (Exception ex) {
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<ProjectsExternalSourcesModel>().status(ApiMessageCode.ERROR_MESSAGE).message(ex.getMessage()));
|
|
}
|
|
}
|
|
|
|
}
|
|
|