420 lines
15 KiB
Java
420 lines
15 KiB
Java
package rest;
|
|
|
|
import java.util.List;
|
|
import java.util.UUID;
|
|
|
|
import org.apache.commons.lang3.SerializationUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.util.MultiValueMap;
|
|
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 com.fasterxml.jackson.core.JsonProcessingException;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
import dao.entities.DMPDao;
|
|
import dao.entities.DMPProfileDao;
|
|
import dao.entities.DataRepositoryDao;
|
|
import dao.entities.DatasetDao;
|
|
import dao.entities.DatasetProfileDao;
|
|
import dao.entities.DatasetProfileRulesetDao;
|
|
import dao.entities.DatasetProfileViewstyleDao;
|
|
import dao.entities.OrganisationDao;
|
|
import dao.entities.ProjectDao;
|
|
import dao.entities.RegistryDao;
|
|
import dao.entities.ResearcherDao;
|
|
import dao.entities.ServiceDao;
|
|
import entities.DMP;
|
|
import entities.DMPProfile;
|
|
import entities.DataRepository;
|
|
import entities.Dataset;
|
|
import entities.DatasetProfile;
|
|
import entities.DatasetProfileRuleset;
|
|
import entities.Organisation;
|
|
import entities.Project;
|
|
import entities.Registry;
|
|
import entities.Researcher;
|
|
import entities.Service;
|
|
import helpers.Transformers;
|
|
import responses.RestResponse;
|
|
|
|
|
|
@RestController
|
|
@CrossOrigin
|
|
public class LoneTables {
|
|
|
|
@Autowired private DataRepositoryDao dataRepositoryDao;
|
|
@Autowired private DatasetDao datasetDao;
|
|
@Autowired private DatasetProfileDao datasetProfileDao;
|
|
@Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao;
|
|
@Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao;
|
|
@Autowired private DMPDao dMPDao;
|
|
@Autowired private DMPProfileDao dMPProfileDao;
|
|
@Autowired private OrganisationDao organisationDao;
|
|
@Autowired private ProjectDao projectDao;
|
|
@Autowired private RegistryDao registryDao;
|
|
@Autowired private ResearcherDao researcherDao;
|
|
@Autowired private ServiceDao serviceDao;
|
|
|
|
|
|
|
|
// MANAGE PROJECT(S)
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/project" })
|
|
public @ResponseBody ResponseEntity<Object> listProjects(){
|
|
try {
|
|
List<UUID> allIDs = projectDao.listAllIDs();
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(allIDs));
|
|
}
|
|
catch(Exception ex) {
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/project/{id}" })
|
|
public @ResponseBody ResponseEntity<Object> getProject(@PathVariable("id") String id) {
|
|
try {
|
|
Project project = projectDao.read(UUID.fromString(id));
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(project));
|
|
}
|
|
catch(Exception ex) {
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.POST, value = { "/setProject" }, consumes = "application/json")
|
|
public @ResponseBody ResponseEntity<Object> setProject(@RequestBody Project project) {
|
|
String reason = "";
|
|
Project storedProject = null;
|
|
//try first to create
|
|
try {
|
|
storedProject = projectDao.create(project);
|
|
return ResponseEntity.status(HttpStatus.CREATED).body("Created project with id: " + storedProject.getId());
|
|
}
|
|
catch(Exception e) {
|
|
reason += e.getMessage();
|
|
//try updating
|
|
try {
|
|
storedProject = projectDao.update(project);
|
|
return ResponseEntity.status(HttpStatus.CREATED).body("Updated project with id: " + storedProject.getId());
|
|
}
|
|
catch(Exception ex) {
|
|
reason += (System.lineSeparator()+e.getMessage());
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Could not create or update project! Reason: " + reason);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// MANAGE ORGANISATIONS(S)
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/organizations" })
|
|
public @ResponseBody ResponseEntity<Object> listOrganisations(){
|
|
try {
|
|
List<UUID> allIDs = organisationDao.listAllIDs();
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(allIDs));
|
|
}
|
|
catch(Exception ex) {
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/organizations/{id}" })
|
|
public @ResponseBody ResponseEntity<Object> getOrganisations(@PathVariable("id") String id) {
|
|
try {
|
|
Organisation organisation = organisationDao.read(UUID.fromString(id));
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(organisation));
|
|
}
|
|
catch(Exception ex) {
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.POST, value = { "/setOrganisation" }, consumes = "application/json")
|
|
public @ResponseBody ResponseEntity<Object> setOrganisation(@RequestBody Organisation organisation) {
|
|
String reason = "";
|
|
Organisation storedOrganisation = null;
|
|
//try first to create
|
|
try {
|
|
storedOrganisation = organisationDao.create(organisation);
|
|
return ResponseEntity.status(HttpStatus.CREATED).body("Created organisation with id: " + storedOrganisation.getId());
|
|
}
|
|
catch(Exception e) {
|
|
reason += e.getMessage();
|
|
//try updating
|
|
try {
|
|
storedOrganisation = organisationDao.update(organisation);
|
|
return ResponseEntity.status(HttpStatus.CREATED).body("Updated organisation with id: " + storedOrganisation.getId());
|
|
}
|
|
catch(Exception ex) {
|
|
reason += (System.lineSeparator()+e.getMessage());
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Could not create or update organisation! Reason: " + reason);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// MANAGE RESEARCHER(S)
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/researchers" })
|
|
public @ResponseBody ResponseEntity<Object> listResearchers(){
|
|
try {
|
|
List<UUID> allIDs = researcherDao.listAllIDs();
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(allIDs));
|
|
}
|
|
catch(Exception ex) {
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/researchers/{id}" })
|
|
public @ResponseBody ResponseEntity<Object> getResearchers(@PathVariable("id") String id) {
|
|
try {
|
|
Researcher researcher = researcherDao.read(UUID.fromString(id));
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(researcher));
|
|
}
|
|
catch(Exception ex) {
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.POST, value = { "/setResearcher" }, consumes = "application/json")
|
|
public @ResponseBody ResponseEntity<Object> setResearcher(@RequestBody Researcher researcher) {
|
|
String reason = "";
|
|
Researcher storedResearcher = null;
|
|
//try first to create
|
|
try {
|
|
storedResearcher = researcherDao.create(researcher);
|
|
return ResponseEntity.status(HttpStatus.CREATED).body("Created researcher with id: " + storedResearcher.getId());
|
|
}
|
|
catch(Exception e) {
|
|
reason += e.getMessage();
|
|
//try updating
|
|
try {
|
|
storedResearcher = researcherDao.update(researcher);
|
|
return ResponseEntity.status(HttpStatus.CREATED).body("Updated researcher with id: " + storedResearcher.getId());
|
|
}
|
|
catch(Exception ex) {
|
|
reason += (System.lineSeparator()+e.getMessage());
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Could not create or update researcher! Reason: " + reason);
|
|
}
|
|
}
|
|
}
|
|
|
|
// MANAGE SERVICE(S)
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/services" })
|
|
public @ResponseBody ResponseEntity<Object> listServices(){
|
|
try {
|
|
List<UUID> allIDs = serviceDao.listAllIDs();
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(allIDs));
|
|
}
|
|
catch(Exception ex) {
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/services/{id}" })
|
|
public @ResponseBody ResponseEntity<Object> getServices(@PathVariable("id") String id) {
|
|
try {
|
|
Service service = serviceDao.read(UUID.fromString(id));
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(service));
|
|
}
|
|
catch(Exception ex) {
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.POST, value = { "/setService" }, consumes = "application/json")
|
|
public @ResponseBody ResponseEntity<Object> setService(@RequestBody Service service) {
|
|
String reason = "";
|
|
Service storedService = null;
|
|
//try first to create
|
|
try {
|
|
storedService = serviceDao.create(service);
|
|
return ResponseEntity.status(HttpStatus.CREATED).body("Created service with id: " + storedService.getId());
|
|
}
|
|
catch(Exception e) {
|
|
reason += e.getMessage();
|
|
//try updating
|
|
try {
|
|
storedService = serviceDao.update(service);
|
|
return ResponseEntity.status(HttpStatus.CREATED).body("Updated service with id: " + storedService.getId());
|
|
}
|
|
catch(Exception ex) {
|
|
reason += (System.lineSeparator()+e.getMessage());
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Could not create or update service! Reason: " + reason);
|
|
}
|
|
}
|
|
}
|
|
|
|
// MANAGE REGISTRY(IES)
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/registries" })
|
|
public @ResponseBody ResponseEntity<Object> listRegistries(){
|
|
try {
|
|
List<UUID> allIDs = registryDao.listAllIDs();
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(allIDs));
|
|
}
|
|
catch(Exception ex) {
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/registries/{id}" })
|
|
public @ResponseBody ResponseEntity<Object> getRegistries(@PathVariable("id") String id) {
|
|
try {
|
|
Registry registry = registryDao.read(UUID.fromString(id));
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(registry));
|
|
}
|
|
catch(Exception ex) {
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.POST, value = { "/setRegistry" }, consumes = "application/json")
|
|
public @ResponseBody ResponseEntity<Object> setRegistry(@RequestBody Registry registry) {
|
|
String reason = "";
|
|
Registry storedRegistry = null;
|
|
//try first to create
|
|
try {
|
|
storedRegistry = registryDao.create(registry);
|
|
return ResponseEntity.status(HttpStatus.CREATED).body("Created registry with id: " + storedRegistry.getId());
|
|
}
|
|
catch(Exception e) {
|
|
reason += e.getMessage();
|
|
//try updating
|
|
try {
|
|
storedRegistry = registryDao.update(registry);
|
|
return ResponseEntity.status(HttpStatus.CREATED).body("Updated registry with id: " + storedRegistry.getId());
|
|
}
|
|
catch(Exception ex) {
|
|
reason += (System.lineSeparator()+e.getMessage());
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Could not create or update registry! Reason: " + reason);
|
|
}
|
|
}
|
|
}
|
|
|
|
// MANAGE DATAREPOSITORy(IES)
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/datarepositories" })
|
|
public @ResponseBody ResponseEntity<Object> listDataRepositories(){
|
|
try {
|
|
List<UUID> allIDs = dataRepositoryDao.listAllIDs();
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(allIDs));
|
|
}
|
|
catch(Exception ex) {
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/datarepositories/{id}" })
|
|
public @ResponseBody ResponseEntity<Object> getDataRepository(@PathVariable("id") String id) {
|
|
try {
|
|
DataRepository dataRepository = dataRepositoryDao.read(UUID.fromString(id));
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(dataRepository));
|
|
}
|
|
catch(Exception ex) {
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.POST, value = { "/setDataRepository" }, consumes = "application/json")
|
|
public @ResponseBody ResponseEntity<Object> setDataRepository(@RequestBody DataRepository dataRepository) {
|
|
String reason = "";
|
|
DataRepository storedDataRepository = null;
|
|
//try first to create
|
|
try {
|
|
storedDataRepository = dataRepositoryDao.create(dataRepository);
|
|
return ResponseEntity.status(HttpStatus.CREATED).body("Created dataRepository with id: " + storedDataRepository.getId());
|
|
}
|
|
catch(Exception e) {
|
|
reason += e.getMessage();
|
|
//try updating
|
|
try {
|
|
storedDataRepository = dataRepositoryDao.update(dataRepository);
|
|
return ResponseEntity.status(HttpStatus.CREATED).body("Updated dataRepository with id: " + storedDataRepository.getId());
|
|
}
|
|
catch(Exception ex) {
|
|
reason += (System.lineSeparator()+e.getMessage());
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Could not create or update dataRepository! Reason: " + reason);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// MANAGE DMPPROFILE(S)
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/dmpprofiles" })
|
|
public @ResponseBody ResponseEntity<Object> listDmpProfiles(){
|
|
try {
|
|
List<UUID> allIDs = dMPProfileDao.listAllIDs();
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(allIDs));
|
|
}
|
|
catch(Exception ex) {
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/dmpprofiles/{id}" })
|
|
public @ResponseBody ResponseEntity<Object> getDmpProfile(@PathVariable("id") String id) {
|
|
try {
|
|
DMPProfile dmpProfile = dMPProfileDao.read(UUID.fromString(id));
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(dmpProfile));
|
|
}
|
|
catch(Exception ex) {
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.POST, value = { "/setDmpProfile" }, consumes = "application/json")
|
|
public @ResponseBody ResponseEntity<Object> setDmpProfile(@RequestBody DMPProfile dmpProfile) {
|
|
String reason = "";
|
|
DMPProfile storedDMPProfile = null;
|
|
//try first to create
|
|
try {
|
|
storedDMPProfile = dMPProfileDao.create(dmpProfile);
|
|
return ResponseEntity.status(HttpStatus.CREATED).body("Created dmpProfile with id: " + storedDMPProfile.getId());
|
|
}
|
|
catch(Exception e) {
|
|
reason += e.getMessage();
|
|
//try updating
|
|
try {
|
|
storedDMPProfile = dMPProfileDao.update(dmpProfile);
|
|
return ResponseEntity.status(HttpStatus.CREATED).body("Updated dmpProfile with id: " + storedDMPProfile.getId());
|
|
}
|
|
catch(Exception ex) {
|
|
reason += (System.lineSeparator()+e.getMessage());
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Could not create or update dmpProfile! Reason: " + reason);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|