diff --git a/dmp-backend/src/main/java/entities/DMP.java b/dmp-backend/src/main/java/entities/DMP.java index 9aaf98f18..0b597d633 100644 --- a/dmp-backend/src/main/java/entities/DMP.java +++ b/dmp-backend/src/main/java/entities/DMP.java @@ -104,11 +104,11 @@ public class DMP implements Serializable { @Column(name = "\"Status\"", nullable = false) private Short status; - @Column(name = "\"Created\"", nullable = false) + @Column(name = "\"Created\"") private Date created = null; - @Column(name = "\"Modified\"", nullable = false) - private Date modified = null; + @Column(name = "\"Modified\"") + private Date modified = new Date(); public Short getStatus() { diff --git a/dmp-backend/src/main/java/rest/entities/DMPs.java b/dmp-backend/src/main/java/rest/entities/DMPs.java index 4a42d46f8..0641eafed 100644 --- a/dmp-backend/src/main/java/rest/entities/DMPs.java +++ b/dmp-backend/src/main/java/rest/entities/DMPs.java @@ -2,6 +2,7 @@ package rest.entities; import java.util.ArrayList; +import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -149,7 +150,9 @@ public class DMPs { public @ResponseBody ResponseEntity updateDMP(@RequestBody DMP dmp) { DMP previousDmp = dMPDao.read(dmp.getId()); - addForeignElems(previousDmp, dmp); + addNullAndForeignElems(previousDmp, dmp); + + try { DMP updatedDMP = dMPDao.update(dmp); @@ -162,92 +165,6 @@ public class DMPs { } - /* - @RequestMapping(method = RequestMethod.POST, value = { "/dmp/set/full" }, consumes = "application/json", produces="application/json") - public @ResponseBody ResponseEntity setFullDMP(@RequestBody DMP dmp) { - - //This function is a little bit tricky to implement (due to the irregular ORM mappings of the hibernate). - // Please make changes only if you are sure about what you're altering. - - Dataset dataset = SerializationUtils.clone(dmp.getDataset()); - - dmp.setDataset(null); - - int failsDMP = 0; - String reasonDmp = ""; - DMP storedDMP = null; - //try first to create DMP - try { - storedDMP = dMPDao.create(dmp); - } - catch(Exception e) { - e.printStackTrace(); - failsDMP++; - reasonDmp += e.getMessage(); - //try updating DMP - try { - storedDMP = dMPDao.update(dmp); - } - catch(Exception ex) { - reasonDmp += (System.lineSeparator()+e.getMessage()); - failsDMP++; - ex.printStackTrace(); - } - } - - if(failsDMP==2) - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Could not create or update DMP! Reason: " + reasonDmp); - - dataset.setDmp(storedDMP); //very important! - - int failsDataset = 0; - String reasonDataset = ""; - Dataset storedDataset = null; - if(dataset != null) { - //try first to create DMP - try { - storedDataset = datasetDao.create(dataset); - } - catch(Exception e) { - e.printStackTrace(); - failsDataset++; - reasonDataset += e.getMessage(); - //try updating DMP - try { - storedDataset = datasetDao.update(dataset); - } - catch(Exception ex) { - reasonDataset += (System.lineSeparator()+e.getMessage()); - failsDataset++; - ex.printStackTrace(); - } - } - } - - String respBody; - try { - respBody = objectMapper.writeValueAsString(storedDMP.getId()); - } - catch(JsonProcessingException ex) { - respBody = "{\"id\":\""+storedDMP.getId()+"\"}"; - } - - if(failsDataset != 2) { - if(failsDMP==0) - return ResponseEntity.status(HttpStatus.CREATED).body(respBody); - else if(failsDMP==1) - return ResponseEntity.status(HttpStatus.CREATED).body("Updated DMP with id: " + storedDMP.getId()); - else - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Could not create DMP! Reason:"+ reasonDmp); - } - else { - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Could not create DMP! Failed to create or update its Dataset. Reason: "+reasonDataset); - } - - - } - - */ @@ -352,11 +269,16 @@ public class DMPs { users.add(userInfo); dmp.setUsers(users); + dmp.setCreated(new Date()); + dmp.setModified(new Date()); + dmp.setStatus(new Short("0")); + DMP newdmp = dMPDao.create(dmp); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(newdmp)); } catch(Exception ex) { + ex.printStackTrace(); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage()); } @@ -404,7 +326,14 @@ public class DMPs { - private static void addForeignElems(DMP existing, DMP newone) { + private static void addNullAndForeignElems(DMP existing, DMP newone) { + + newone.setModified(new Date()); + if(newone.getStatus()==null) + newone.setStatus(existing.getStatus()); + if(newone.getCreated()==null) + newone.setCreated(existing.getCreated()); + newone.setDataset(existing.getDataset()); newone.setOrganisations(existing.getOrganisations()); newone.setResearchers(existing.getResearchers()); diff --git a/dmp-backend/src/main/java/rest/entities/Datasets.java b/dmp-backend/src/main/java/rest/entities/Datasets.java index d9959eceb..3bc26d569 100644 --- a/dmp-backend/src/main/java/rest/entities/Datasets.java +++ b/dmp-backend/src/main/java/rest/entities/Datasets.java @@ -2,6 +2,7 @@ package rest.entities; import java.io.IOException; import java.io.PrintStream; +import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -124,6 +125,9 @@ public class Datasets { public @ResponseBody ResponseEntity createDataset(@RequestBody Dataset dataset) { dataset.setId(null); + dataset.setCreated(new Date()); + dataset.setModified(new Date()); + dataset.setStatus(new Short("0")); try { dataset = datasetDao.create(dataset); return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(dataset));