Updated rest services
This commit is contained in:
parent
eef2454e2d
commit
2b47980fe5
|
@ -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<Object> 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<Object> getAllDmpProfiles(){
|
||||
try {
|
||||
storedDMPProfile = dMPProfileDao.create(dmpProfile);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body("Created dmpProfile with id: " + storedDMPProfile.getId());
|
||||
List<DMPProfile> allDmpProfiles = dMPProfileDao.getAll();
|
||||
|
||||
//sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom
|
||||
List<String> dmpprofileStrL = allDmpProfiles.parallelStream().map((dmpProfileObj) -> {
|
||||
try {
|
||||
return objectMapper.writeValueAsString(dmpProfileObj);
|
||||
} catch (JsonProcessingException e) {
|
||||
return "";
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
return new ResponseEntity<Object>("["+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<Object> 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<Object> 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!\"");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Object> listOrganisations(){
|
||||
try {
|
||||
List<UUID> 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<Object> 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<Object> 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<Object> getAllOrganisations(){
|
||||
try {
|
||||
storedOrganisation = organisationDao.create(organisation);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body("Created organisation with id: " + storedOrganisation.getId());
|
||||
List<Organisation> allOrganisations = organisationDao.getAll();
|
||||
|
||||
//sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom
|
||||
List<String> organisationStrL = allOrganisations.parallelStream().map((organisationObj) -> {
|
||||
try {
|
||||
return objectMapper.writeValueAsString(organisationObj);
|
||||
} catch (JsonProcessingException e) {
|
||||
return "";
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
return new ResponseEntity<Object>("["+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<Object> 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<Object> 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!\"");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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<Object> 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<Object> getAllProjects(){
|
||||
try {
|
||||
storedProject = projectDao.create(project);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body("Created project with id: " + storedProject.getId());
|
||||
List<Project> allProjects = projectDao.getAll();
|
||||
|
||||
//sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom
|
||||
List<String> projectStrL = allProjects.parallelStream().map((projectObj) -> {
|
||||
try {
|
||||
return objectMapper.writeValueAsString(projectObj);
|
||||
} catch (JsonProcessingException e) {
|
||||
return "";
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
return new ResponseEntity<Object>("["+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<Object> 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<Object> 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!\"");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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<Object> setRegistry(@RequestBody Registry registry) {
|
||||
String reason = "";
|
||||
Registry storedRegistry = null;
|
||||
//try first to create
|
||||
@RequestMapping(method = RequestMethod.GET, value = { "/registries/listAllLabelIDs" })
|
||||
public @ResponseBody ResponseEntity<Object> listLabelIds(){
|
||||
try {
|
||||
storedRegistry = registryDao.create(registry);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body("Created registry with id: " + storedRegistry.getId());
|
||||
List<IDLabelPair> 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<Object> getAllRegistries(){
|
||||
try {
|
||||
List<Registry> allRegistries = registryDao.getAll();
|
||||
|
||||
//sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom
|
||||
List<String> registryStrL = allRegistries.parallelStream().map((registryObj) -> {
|
||||
try {
|
||||
return objectMapper.writeValueAsString(registryObj);
|
||||
} catch (JsonProcessingException e) {
|
||||
return "";
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
return new ResponseEntity<Object>("["+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<Object> 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<Object> 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!\"");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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<Object> listServices(){
|
||||
try {
|
||||
List<UUID> 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<Object> 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<Object> 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<Object> getAllServices(){
|
||||
try {
|
||||
storedService = serviceDao.create(service);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body("Created service with id: " + storedService.getId());
|
||||
List<Service> allServices = serviceDao.getAll();
|
||||
|
||||
//sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom
|
||||
List<String> serviceStrL = allServices.parallelStream().map((serviceObj) -> {
|
||||
try {
|
||||
return objectMapper.writeValueAsString(serviceObj);
|
||||
} catch (JsonProcessingException e) {
|
||||
return "";
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
return new ResponseEntity<Object>("["+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<Object> 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<Object> 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!\"");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue