diff --git a/dmp-backend/src/main/java/rest/DmpProfiles.java b/dmp-backend/src/main/java/rest/DmpProfiles.java index 93eb1500d..475500e54 100644 --- a/dmp-backend/src/main/java/rest/DmpProfiles.java +++ b/dmp-backend/src/main/java/rest/DmpProfiles.java @@ -2,6 +2,9 @@ package rest; import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; + +import javax.transaction.Transactional; import org.apache.commons.lang3.SerializationUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -66,7 +69,7 @@ public class DmpProfiles { @Autowired private ResearcherDao researcherDao; @Autowired private ServiceDao serviceDao; - + private ObjectMapper objectMapper = new ObjectMapper(); // MANAGE DMPPROFILE(S) @@ -109,31 +112,57 @@ public class DmpProfiles { } - - - @RequestMapping(method = RequestMethod.POST, value = { "/dmpprofile/set" }, consumes = "application/json") - public @ResponseBody ResponseEntity setDmpProfile(@RequestBody DMPProfile dmpProfile) { - String reason = ""; - DMPProfile storedDMPProfile = null; - //try first to create + @RequestMapping(method = RequestMethod.GET, value = { "/dmpprofile/getAll" }, produces="application/json") + public @ResponseBody ResponseEntity getAllDmpProfiles(){ try { - storedDMPProfile = dMPProfileDao.create(dmpProfile); - return ResponseEntity.status(HttpStatus.CREATED).body("Created dmpProfile with id: " + storedDMPProfile.getId()); + List allDmpProfiles = dMPProfileDao.getAll(); + + //sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom + List dmpprofileStrL = allDmpProfiles.parallelStream().map((dmpProfileObj) -> { + try { + return objectMapper.writeValueAsString(dmpProfileObj); + } catch (JsonProcessingException e) { + return ""; + } + }).collect(Collectors.toList()); + + return new ResponseEntity("["+String.join(",", dmpprofileStrL)+"]", HttpStatus.OK); + } - 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); - } + catch(Exception ex) { + return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); } } + @Transactional + @RequestMapping(method = RequestMethod.POST, value = { "/dmpprofile/create" }, consumes = "application/json", produces="application/json") + public @ResponseBody ResponseEntity setDmpProfile(@RequestBody DMPProfile dmpprofile) { + DMPProfile createdDMPProfile = dMPProfileDao.update(dmpprofile); + try { + return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdDMPProfile)); + } catch (JsonProcessingException e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create DMP Profile!\""); + } + } + + + @RequestMapping(method = RequestMethod.POST, value = { "/dmpprofile/delete" }, consumes = "application/json", produces="text/plain") + public @ResponseBody ResponseEntity delete(@RequestBody DMPProfile dmpprofile) { + + DMPProfile dmpp = new DMPProfile(); + dmpp.setId(dmpprofile.getId()); + try { + dMPProfileDao.delete(dmpp); + return ResponseEntity.status(HttpStatus.CREATED).body("DELETED!"); + } catch (Exception e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete DMP Profile!\""); + } + + } + + + + } diff --git a/dmp-backend/src/main/java/rest/Organisations.java b/dmp-backend/src/main/java/rest/Organisations.java index a6e026041..fe8caa611 100644 --- a/dmp-backend/src/main/java/rest/Organisations.java +++ b/dmp-backend/src/main/java/rest/Organisations.java @@ -2,6 +2,9 @@ package rest; import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; + +import javax.transaction.Transactional; import org.apache.commons.lang3.SerializationUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -65,9 +68,12 @@ public class Organisations { @Autowired private ResearcherDao researcherDao; @Autowired private ServiceDao serviceDao; + + private ObjectMapper objectMapper = new ObjectMapper(); + // MANAGE ORGANISATIONS(S) - @RequestMapping(method = RequestMethod.GET, value = { "/organizations" }) + @RequestMapping(method = RequestMethod.GET, value = { "/organisations" }) public @ResponseBody ResponseEntity listOrganisations(){ try { List allIDs = organisationDao.listAllIDs(); @@ -79,7 +85,7 @@ public class Organisations { } - @RequestMapping(method = RequestMethod.GET, value = { "/organizations/{id}" }) + @RequestMapping(method = RequestMethod.GET, value = { "/organisations/{id}" }) public @ResponseBody ResponseEntity getOrganisations(@PathVariable("id") String id) { try { Organisation organisation = organisationDao.read(UUID.fromString(id)); @@ -91,29 +97,55 @@ public class Organisations { } - @RequestMapping(method = RequestMethod.POST, value = { "/setOrganisation" }, consumes = "application/json") - public @ResponseBody ResponseEntity setOrganisation(@RequestBody Organisation organisation) { - String reason = ""; - Organisation storedOrganisation = null; - //try first to create + @RequestMapping(method = RequestMethod.GET, value = { "/organisation/getAll" }, produces="application/json") + public @ResponseBody ResponseEntity getAllOrganisations(){ try { - storedOrganisation = organisationDao.create(organisation); - return ResponseEntity.status(HttpStatus.CREATED).body("Created organisation with id: " + storedOrganisation.getId()); + List allOrganisations = organisationDao.getAll(); + + //sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom + List organisationStrL = allOrganisations.parallelStream().map((organisationObj) -> { + try { + return objectMapper.writeValueAsString(organisationObj); + } catch (JsonProcessingException e) { + return ""; + } + }).collect(Collectors.toList()); + + return new ResponseEntity("["+String.join(",", organisationStrL)+"]", HttpStatus.OK); + } - 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); - } + catch(Exception ex) { + return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); } } + + @Transactional + @RequestMapping(method = RequestMethod.POST, value = { "/organisation/create" }, consumes = "application/json", produces="application/json") + public @ResponseBody ResponseEntity setOrganisation(@RequestBody Organisation organisation) { + Organisation createdOrganisation = organisationDao.update(organisation); + try { + return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdOrganisation)); + } catch (JsonProcessingException e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create organisation!\""); + } + } + + + @RequestMapping(method = RequestMethod.POST, value = { "/organisation/delete" }, consumes = "application/json", produces="text/plain") + public @ResponseBody ResponseEntity delete(@RequestBody Organisation organisation) { + + Organisation org = new Organisation(); + org.setId(organisation.getId()); + try { + organisationDao.delete(org); + return ResponseEntity.status(HttpStatus.OK).body("DELETED!"); + } catch (Exception e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not delete organisation!\""); + } + + } + diff --git a/dmp-backend/src/main/java/rest/Projects.java b/dmp-backend/src/main/java/rest/Projects.java index f8b3c5b22..f2c8923e0 100644 --- a/dmp-backend/src/main/java/rest/Projects.java +++ b/dmp-backend/src/main/java/rest/Projects.java @@ -2,6 +2,9 @@ package rest; import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; + +import javax.transaction.Transactional; import org.apache.commons.lang3.SerializationUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -67,6 +70,7 @@ public class Projects { @Autowired private ServiceDao serviceDao; + private ObjectMapper objectMapper = new ObjectMapper(); // MANAGE PROJECT(S) @@ -105,29 +109,55 @@ public class Projects { } - @RequestMapping(method = RequestMethod.POST, value = { "/project/set" }, consumes = "application/json") - public @ResponseBody ResponseEntity setProject(@RequestBody Project project) { - String reason = ""; - Project storedProject = null; - //try first to create + @RequestMapping(method = RequestMethod.GET, value = { "/project/getAll" }, produces="application/json") + public @ResponseBody ResponseEntity getAllProjects(){ try { - storedProject = projectDao.create(project); - return ResponseEntity.status(HttpStatus.CREATED).body("Created project with id: " + storedProject.getId()); + List allProjects = projectDao.getAll(); + + //sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom + List projectStrL = allProjects.parallelStream().map((projectObj) -> { + try { + return objectMapper.writeValueAsString(projectObj); + } catch (JsonProcessingException e) { + return ""; + } + }).collect(Collectors.toList()); + + return new ResponseEntity("["+String.join(",", projectStrL)+"]", HttpStatus.OK); + } - 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); - } + catch(Exception ex) { + return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); } } + + @Transactional + @RequestMapping(method = RequestMethod.POST, value = { "/project/create" }, consumes = "application/json", produces="application/json") + public @ResponseBody ResponseEntity setProject(@RequestBody Project project) { + Project createdProject = projectDao.update(project); + try { + return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdProject)); + } catch (JsonProcessingException e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create Project!\""); + } + } + + + @RequestMapping(method = RequestMethod.POST, value = { "/project/delete" }, consumes = "application/json", produces="text/plain") + public @ResponseBody ResponseEntity delete(@RequestBody Project project) { + + Project p = new Project(); + p.setId(project.getId()); + try { + projectDao.delete(p); + return ResponseEntity.status(HttpStatus.CREATED).body("DELETED!"); + } catch (Exception e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete Project!\""); + } + + } + } diff --git a/dmp-backend/src/main/java/rest/Registries.java b/dmp-backend/src/main/java/rest/Registries.java index a6dbef9c6..011dd9096 100644 --- a/dmp-backend/src/main/java/rest/Registries.java +++ b/dmp-backend/src/main/java/rest/Registries.java @@ -2,12 +2,14 @@ package rest; import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; 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.transaction.annotation.Transactional; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.PathVariable; @@ -44,6 +46,7 @@ import entities.Project; import entities.Registry; import entities.Researcher; import entities.Service; +import entities.responses.IDLabelPair; import helpers.Transformers; import responses.RestResponse; @@ -65,7 +68,8 @@ public class Registries { @Autowired private ResearcherDao researcherDao; @Autowired private ServiceDao serviceDao; - + + private ObjectMapper objectMapper = new ObjectMapper(); // MANAGE REGISTRY(IES) @@ -91,31 +95,72 @@ public class Registries { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage()); } } + + - - @RequestMapping(method = RequestMethod.POST, value = { "/setRegistry" }, consumes = "application/json") - public @ResponseBody ResponseEntity setRegistry(@RequestBody Registry registry) { - String reason = ""; - Registry storedRegistry = null; - //try first to create + @RequestMapping(method = RequestMethod.GET, value = { "/registries/listAllLabelIDs" }) + public @ResponseBody ResponseEntity listLabelIds(){ try { - storedRegistry = registryDao.create(registry); - return ResponseEntity.status(HttpStatus.CREATED).body("Created registry with id: " + storedRegistry.getId()); + List allIDs = registryDao.listAllIDsLabels(); + return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs)); } - 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); - } + catch(Exception ex) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage()); } } + + @RequestMapping(method = RequestMethod.GET, value = { "/registry/getAll" }, produces="application/json") + public @ResponseBody ResponseEntity getAllRegistries(){ + try { + List allRegistries = registryDao.getAll(); + + //sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom + List registryStrL = allRegistries.parallelStream().map((registryObj) -> { + try { + return objectMapper.writeValueAsString(registryObj); + } catch (JsonProcessingException e) { + return ""; + } + }).collect(Collectors.toList()); + + return new ResponseEntity("["+String.join(",", registryStrL)+"]", HttpStatus.OK); + + } + catch(Exception ex) { + return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + + @Transactional + @RequestMapping(method = RequestMethod.POST, value = { "/registry/create" }, consumes = "application/json", produces="application/json") + public @ResponseBody ResponseEntity setRegistry(@RequestBody Registry registry) { + Registry createdRegistry = registryDao.update(registry); + try { + return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdRegistry)); + } catch (JsonProcessingException e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create registry!\""); + } + } + + + @RequestMapping(method = RequestMethod.POST, value = { "/registry/delete" }, consumes = "application/json", produces="text/plain") + public @ResponseBody ResponseEntity delete(@RequestBody Registry registry) { + + Registry r = new Registry(); + r.setId(registry.getId()); + try { + registryDao.delete(r); + return ResponseEntity.status(HttpStatus.CREATED).body("DELETED!"); + } catch (Exception e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete registry!\""); + } + + } + + + } diff --git a/dmp-backend/src/main/java/rest/Services.java b/dmp-backend/src/main/java/rest/Services.java index ef9e8e635..43bfabcda 100644 --- a/dmp-backend/src/main/java/rest/Services.java +++ b/dmp-backend/src/main/java/rest/Services.java @@ -2,6 +2,9 @@ package rest; import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; + +import javax.transaction.Transactional; import org.apache.commons.lang3.SerializationUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -66,6 +69,7 @@ public class Services { @Autowired private ServiceDao serviceDao; + private ObjectMapper objectMapper = new ObjectMapper(); // MANAGE SERVICE(S) @@ -73,7 +77,7 @@ public class Services { public @ResponseBody ResponseEntity listServices(){ try { List allIDs = serviceDao.listAllIDs(); - return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(allIDs)); + return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs)); } catch(Exception ex) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage()); @@ -85,7 +89,7 @@ public class Services { public @ResponseBody ResponseEntity getServices(@PathVariable("id") String id) { try { Service service = serviceDao.read(UUID.fromString(id)); - return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(service)); + return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(service)); } catch(Exception ex) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage()); @@ -93,28 +97,58 @@ public class Services { } - @RequestMapping(method = RequestMethod.POST, value = { "/setService" }, consumes = "application/json") - public @ResponseBody ResponseEntity setService(@RequestBody Service service) { - String reason = ""; - Service storedService = null; - //try first to create + + @RequestMapping(method = RequestMethod.GET, value = { "/service/getAll" }, produces="application/json") + public @ResponseBody ResponseEntity getAllServices(){ try { - storedService = serviceDao.create(service); - return ResponseEntity.status(HttpStatus.CREATED).body("Created service with id: " + storedService.getId()); + List allServices = serviceDao.getAll(); + + //sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom + List serviceStrL = allServices.parallelStream().map((serviceObj) -> { + try { + return objectMapper.writeValueAsString(serviceObj); + } catch (JsonProcessingException e) { + return ""; + } + }).collect(Collectors.toList()); + + return new ResponseEntity("["+String.join(",", serviceStrL)+"]", HttpStatus.OK); + } - 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); - } + catch(Exception ex) { + return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); } } + + @Transactional + @RequestMapping(method = RequestMethod.POST, value = { "/service/create" }, consumes = "application/json", produces="application/json") + public @ResponseBody ResponseEntity setService(@RequestBody Service service) { + Service createdService = serviceDao.update(service); + try { + return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdService)); + } catch (JsonProcessingException e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create service entity!\""); + } + } + + + @RequestMapping(method = RequestMethod.POST, value = { "/service/delete" }, consumes = "application/json", produces="text/plain") + public @ResponseBody ResponseEntity delete(@RequestBody Service service) { + + Service s = new Service(); + s.setId(service.getId()); + try { + serviceDao.delete(s); + return ResponseEntity.status(HttpStatus.CREATED).body("DELETED!"); + } catch (Exception e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete Service entity!\""); + } + + } + + + + }