diff --git a/dmp-backend/src/main/java/dao/entities/DMPDaoImpl.java b/dmp-backend/src/main/java/dao/entities/DMPDaoImpl.java index 12bf56466..7553b7cd5 100644 --- a/dmp-backend/src/main/java/dao/entities/DMPDaoImpl.java +++ b/dmp-backend/src/main/java/dao/entities/DMPDaoImpl.java @@ -24,7 +24,7 @@ public class DMPDaoImpl extends JpaDao implements DMPDao { @Override public List listAllIDs() { - String queryString = "SELECT dmp.id FROM DMP dmp"; + String queryString = "SELECT dmp.id FROM DMP dmp where dmp.status>=0"; TypedQuery typedQuery = entityManager.createQuery(queryString, UUID.class); return typedQuery.getResultList(); } @@ -32,7 +32,7 @@ public class DMPDaoImpl extends JpaDao implements DMPDao { @Override public List listAllIDsLabels() { - String queryString = "SELECT dmp.id, dmp.label FROM DMP dmp"; + String queryString = "SELECT dmp.id, dmp.label FROM DMP dmp where dmp.status>=0"; Query query = (Query) entityManager.createQuery(queryString); List rows = query.list(); return rows.stream().map(row -> { diff --git a/dmp-backend/src/main/java/dao/entities/DatasetDaoImpl.java b/dmp-backend/src/main/java/dao/entities/DatasetDaoImpl.java index c31cd1dd7..b4a04cb99 100644 --- a/dmp-backend/src/main/java/dao/entities/DatasetDaoImpl.java +++ b/dmp-backend/src/main/java/dao/entities/DatasetDaoImpl.java @@ -22,7 +22,7 @@ public class DatasetDaoImpl extends JpaDao implements DatasetDao @Override public List listAllIDs() { - String queryString = "SELECT dataset.id FROM Dataset dataset"; + String queryString = "SELECT dataset.id FROM Dataset dataset where dataset.status>=0"; TypedQuery typedQuery = entityManager.createQuery(queryString, UUID.class); return typedQuery.getResultList(); } @@ -30,7 +30,7 @@ public class DatasetDaoImpl extends JpaDao implements DatasetDao @Override public List listAllIDsLabels() { - String queryString = "SELECT dataset.id, dataset.label FROM Dataset dataset"; + String queryString = "SELECT dataset.id, dataset.label FROM Dataset dataset where dataset.status>=0"; Query query = (Query) entityManager.createQuery(queryString); List rows = query.getResultList(); return rows.stream().map(row -> { @@ -41,7 +41,7 @@ public class DatasetDaoImpl extends JpaDao implements DatasetDao @Override public List getDatasetsOfDmp(UUID dmpID) { - String queryString = "FROM Dataset dataset where dataset.dmp.id=:dmpID"; + String queryString = "FROM Dataset dataset where dataset.dmp.id=:dmpID and dataset.status>=0"; Query query = (Query) entityManager.createQuery(queryString); query.setParameter("dmpID", dmpID); List datasets = (List) query.getResultList(); diff --git a/dmp-backend/src/main/java/rest/entities/DMPs.java b/dmp-backend/src/main/java/rest/entities/DMPs.java index 6cf06ff21..4a42d46f8 100644 --- a/dmp-backend/src/main/java/rest/entities/DMPs.java +++ b/dmp-backend/src/main/java/rest/entities/DMPs.java @@ -279,6 +279,24 @@ public class DMPs { } + @RequestMapping(method = RequestMethod.POST, value = { "/dmp/softdelete" }, consumes = "application/json", produces="text/plain") + public @ResponseBody ResponseEntity softDelete(@RequestBody DMP dmp) { + + DMP d = dMPDao.read(dmp.getId()); + d.setStatus(new Short("-1")); + try { + int code = updateDMP(dmp).getStatusCodeValue(); + if(code>199 && code<300) + return ResponseEntity.status(HttpStatus.CREATED).body("DELETED!"); + else + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not soft delete DMP!\""); + } catch (Exception e) { + e.printStackTrace(); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not soft delete DMP!\""); + } + + } + diff --git a/dmp-backend/src/main/java/rest/entities/Datasets.java b/dmp-backend/src/main/java/rest/entities/Datasets.java index 2cfefddc5..d9959eceb 100644 --- a/dmp-backend/src/main/java/rest/entities/Datasets.java +++ b/dmp-backend/src/main/java/rest/entities/Datasets.java @@ -175,6 +175,27 @@ public class Datasets { } } + + + @RequestMapping(method = RequestMethod.POST, value = { "/dataset/softdelete" }, consumes = "application/json", produces="text/plain") + public @ResponseBody ResponseEntity softDelete(@RequestBody Dataset dataset) { + + Dataset d = datasetDao.read(dataset.getId()); + d.setStatus(new Short("-1")); + try { + int code = updateDataset(SerializerProvider.toJson(d)).getStatusCodeValue(); + if(code>199 && code<300) + return ResponseEntity.status(HttpStatus.CREATED).body("DELETED!"); + else + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not soft delete dataset!\""); + } catch (Exception e) { + e.printStackTrace(); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not soft delete dataset!\""); + } + + } + + @RequestMapping(method = RequestMethod.GET, value = { "/dataset/assignDMPToDataset" }) public @ResponseBody ResponseEntity assignDMPToDataset(@RequestParam("datasetID") String datasetID, @RequestParam("dmpID") String dmpID) {