diff --git a/dmp-backend/src/main/java/dao/entities/DMPDao.java b/dmp-backend/src/main/java/dao/entities/DMPDao.java index c7f49858a..018690b8d 100644 --- a/dmp-backend/src/main/java/dao/entities/DMPDao.java +++ b/dmp-backend/src/main/java/dao/entities/DMPDao.java @@ -6,10 +6,13 @@ import java.util.UUID; import dao.Dao; import entities.DMP; import entities.Organisation; +import entities.responses.IDLabelPair; public interface DMPDao extends Dao { public List listAllIDs(); + + List listAllIDsLabels(); diff --git a/dmp-backend/src/main/java/dao/entities/DMPDaoImpl.java b/dmp-backend/src/main/java/dao/entities/DMPDaoImpl.java index 556f1a48d..d733194d9 100644 --- a/dmp-backend/src/main/java/dao/entities/DMPDaoImpl.java +++ b/dmp-backend/src/main/java/dao/entities/DMPDaoImpl.java @@ -2,11 +2,15 @@ package dao.entities; import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; import javax.persistence.TypedQuery; +import org.hibernate.query.Query; + import dao.JpaDao; import entities.DMP; +import entities.responses.IDLabelPair; public class DMPDaoImpl extends JpaDao implements DMPDao { @@ -22,5 +26,16 @@ public class DMPDaoImpl extends JpaDao implements DMPDao { return typedQuery.getResultList(); } + + @Override + public List listAllIDsLabels() { + String queryString = "SELECT dmp.id, dmp.label FROM DMP dmp"; + Query query = (Query) entityManager.createQuery(queryString); + List rows = query.list(); + return rows.stream().map(row -> { + return new IDLabelPair(row[0].toString(), row[1].toString()); + }) + .collect(Collectors.toList()); + } } diff --git a/dmp-backend/src/main/java/dao/entities/DMPProfileDao.java b/dmp-backend/src/main/java/dao/entities/DMPProfileDao.java index c48a9fdea..23ed9e85e 100644 --- a/dmp-backend/src/main/java/dao/entities/DMPProfileDao.java +++ b/dmp-backend/src/main/java/dao/entities/DMPProfileDao.java @@ -1,10 +1,16 @@ package dao.entities; +import java.util.List; import java.util.UUID; import dao.Dao; import entities.DMPProfile; +import entities.responses.IDLabelPair; public interface DMPProfileDao extends Dao { + List listAllIDs(); + + List listAllIDsLabels(); + } \ No newline at end of file diff --git a/dmp-backend/src/main/java/dao/entities/DMPProfileDaoImpl.java b/dmp-backend/src/main/java/dao/entities/DMPProfileDaoImpl.java index 9a431955a..0ef29231b 100644 --- a/dmp-backend/src/main/java/dao/entities/DMPProfileDaoImpl.java +++ b/dmp-backend/src/main/java/dao/entities/DMPProfileDaoImpl.java @@ -1,17 +1,41 @@ package dao.entities; +import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; +import javax.persistence.TypedQuery; + +import org.hibernate.query.Query; import dao.JpaDao; import entities.DMPProfile; +import entities.responses.IDLabelPair; public class DMPProfileDaoImpl extends JpaDao implements DMPProfileDao { public DMPProfile loadDetails(DMPProfile t) { - // TODO Auto-generated method stub return null; } + @Override + public List listAllIDs() { + String queryString = "SELECT dmpProfile.id FROM DMPProfile dmpProfile"; + TypedQuery typedQuery = entityManager.createQuery(queryString, UUID.class); + return typedQuery.getResultList(); + } + + @Override + public List listAllIDsLabels() { + String queryString = "SELECT dmpProfile.id, dmpProfile.label FROM DMPProfile dmpProfile"; + Query query = (Query) entityManager.createQuery(queryString); + List rows = query.list(); + return rows.stream().map(row -> { + return new IDLabelPair(row[0].toString(), row[1].toString()); + }) + .collect(Collectors.toList()); + } + + } diff --git a/dmp-backend/src/main/java/dao/entities/DataRepositoryDao.java b/dmp-backend/src/main/java/dao/entities/DataRepositoryDao.java index 58b54cf9f..7ca2c4038 100644 --- a/dmp-backend/src/main/java/dao/entities/DataRepositoryDao.java +++ b/dmp-backend/src/main/java/dao/entities/DataRepositoryDao.java @@ -1,10 +1,16 @@ package dao.entities; +import java.util.List; import java.util.UUID; import dao.Dao; import entities.DataRepository; +import entities.responses.IDLabelPair; public interface DataRepositoryDao extends Dao { + List listAllIDs(); + + List listAllIDsLabels(); + } \ No newline at end of file diff --git a/dmp-backend/src/main/java/dao/entities/DataRepositoryDaoImpl.java b/dmp-backend/src/main/java/dao/entities/DataRepositoryDaoImpl.java index 1b9449010..c5e902916 100644 --- a/dmp-backend/src/main/java/dao/entities/DataRepositoryDaoImpl.java +++ b/dmp-backend/src/main/java/dao/entities/DataRepositoryDaoImpl.java @@ -1,10 +1,16 @@ package dao.entities; +import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; +import javax.persistence.TypedQuery; + +import org.hibernate.query.Query; import dao.JpaDao; import entities.DataRepository; +import entities.responses.IDLabelPair; public class DataRepositoryDaoImpl extends JpaDao implements DataRepositoryDao { @@ -13,5 +19,24 @@ public class DataRepositoryDaoImpl extends JpaDao implemen return null; } + @Override + public List listAllIDs() { + String queryString = "SELECT dataRepository.id FROM DataRepository dataRepository"; + TypedQuery typedQuery = entityManager.createQuery(queryString, UUID.class); + return typedQuery.getResultList(); + } + + + @Override + public List listAllIDsLabels() { + String queryString = "SELECT dataRepository.id, dataRepository.label FROM DataRepository dataRepository"; + Query query = (Query) entityManager.createQuery(queryString); + List rows = query.list(); + return rows.stream().map(row -> { + return new IDLabelPair(row[0].toString(), row[1].toString()); + }) + .collect(Collectors.toList()); + } + } diff --git a/dmp-backend/src/main/java/dao/entities/DatasetDao.java b/dmp-backend/src/main/java/dao/entities/DatasetDao.java index eeffa638b..b53f1a057 100644 --- a/dmp-backend/src/main/java/dao/entities/DatasetDao.java +++ b/dmp-backend/src/main/java/dao/entities/DatasetDao.java @@ -5,10 +5,13 @@ import java.util.UUID; import dao.Dao; import entities.Dataset; +import entities.responses.IDLabelPair; public interface DatasetDao extends Dao { public List listAllIDs(); + + List listAllIDsLabels(); } \ No newline at end of file diff --git a/dmp-backend/src/main/java/dao/entities/DatasetDaoImpl.java b/dmp-backend/src/main/java/dao/entities/DatasetDaoImpl.java index 3b774ec1b..3fcde77d6 100644 --- a/dmp-backend/src/main/java/dao/entities/DatasetDaoImpl.java +++ b/dmp-backend/src/main/java/dao/entities/DatasetDaoImpl.java @@ -2,12 +2,16 @@ package dao.entities; import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; import javax.persistence.TypedQuery; import javax.transaction.Transactional; +import org.hibernate.query.Query; + import dao.JpaDao; import entities.Dataset; +import entities.responses.IDLabelPair; public class DatasetDaoImpl extends JpaDao implements DatasetDao { @@ -22,5 +26,17 @@ public class DatasetDaoImpl extends JpaDao implements DatasetDao TypedQuery typedQuery = entityManager.createQuery(queryString, UUID.class); return typedQuery.getResultList(); } - + + + @Override + public List listAllIDsLabels() { + String queryString = "SELECT dataset.id, dataset.label FROM Dataset dataset"; + Query query = (Query) entityManager.createQuery(queryString); + List rows = query.list(); + return rows.stream().map(row -> { + return new IDLabelPair(row[0].toString(), row[1].toString()); + }) + .collect(Collectors.toList()); + } + } diff --git a/dmp-backend/src/main/java/dao/entities/OrganisationDao.java b/dmp-backend/src/main/java/dao/entities/OrganisationDao.java index 0e0634364..7fa04dbf9 100644 --- a/dmp-backend/src/main/java/dao/entities/OrganisationDao.java +++ b/dmp-backend/src/main/java/dao/entities/OrganisationDao.java @@ -1,11 +1,16 @@ package dao.entities; +import java.util.List; import java.util.UUID; import dao.Dao; import entities.Organisation; +import entities.responses.IDLabelPair; public interface OrganisationDao extends Dao { + public List listAllIDs(); + List listAllIDsLabels(); + } \ No newline at end of file diff --git a/dmp-backend/src/main/java/dao/entities/OrganisationDaoImpl.java b/dmp-backend/src/main/java/dao/entities/OrganisationDaoImpl.java index ffa5ef0a4..d520361fa 100644 --- a/dmp-backend/src/main/java/dao/entities/OrganisationDaoImpl.java +++ b/dmp-backend/src/main/java/dao/entities/OrganisationDaoImpl.java @@ -1,13 +1,16 @@ package dao.entities; +import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; -import javax.persistence.Query; -import javax.transaction.Transactional; +import javax.persistence.TypedQuery; +import org.hibernate.query.Query; import dao.JpaDao; import entities.Organisation; +import entities.responses.IDLabelPair; public class OrganisationDaoImpl extends JpaDao implements OrganisationDao { @@ -15,6 +18,25 @@ public class OrganisationDaoImpl extends JpaDao implements O // TODO Auto-generated method stub return null; } - + @Override + public List listAllIDs() { + String queryString = "SELECT organisation.id FROM Organisation organisation"; + TypedQuery typedQuery = entityManager.createQuery(queryString, UUID.class); + return typedQuery.getResultList(); + } + + @Override + public List listAllIDsLabels() { + String queryString = "SELECT organisation.id, organisation.label FROM Organisation organisation"; + Query query = (Query) entityManager.createQuery(queryString); + List rows = query.list(); + return rows.stream().map(row -> { + return new IDLabelPair(row[0].toString(), row[1].toString()); + }) + .collect(Collectors.toList()); + } + + + } diff --git a/dmp-backend/src/main/java/dao/entities/ProjectDao.java b/dmp-backend/src/main/java/dao/entities/ProjectDao.java index f0a922c6f..5591c76d2 100644 --- a/dmp-backend/src/main/java/dao/entities/ProjectDao.java +++ b/dmp-backend/src/main/java/dao/entities/ProjectDao.java @@ -5,9 +5,12 @@ import java.util.UUID; import dao.Dao; import entities.Project; +import entities.responses.IDLabelPair; public interface ProjectDao extends Dao { public List listAllIDs(); + + public List listAllIDsLabels(); } \ No newline at end of file diff --git a/dmp-backend/src/main/java/dao/entities/ProjectDaoImpl.java b/dmp-backend/src/main/java/dao/entities/ProjectDaoImpl.java index decc9a762..6aa4f394d 100644 --- a/dmp-backend/src/main/java/dao/entities/ProjectDaoImpl.java +++ b/dmp-backend/src/main/java/dao/entities/ProjectDaoImpl.java @@ -2,11 +2,15 @@ package dao.entities; import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; import javax.persistence.TypedQuery; +import org.hibernate.query.Query; + import dao.JpaDao; import entities.Project; +import entities.responses.IDLabelPair; public class ProjectDaoImpl extends JpaDao implements ProjectDao { @@ -22,5 +26,17 @@ public class ProjectDaoImpl extends JpaDao implements ProjectDao return typedQuery.getResultList(); } + + @Override + public List listAllIDsLabels() { + String queryString = "SELECT project.id, project.label FROM Project project"; + Query query = (Query) entityManager.createQuery(queryString); + List rows = query.list(); + return rows.stream().map(row -> { + return new IDLabelPair(row[0].toString(), row[1].toString()); + }) + .collect(Collectors.toList()); + } + } diff --git a/dmp-backend/src/main/java/dao/entities/RegistryDao.java b/dmp-backend/src/main/java/dao/entities/RegistryDao.java index da4c8ad07..a4d921610 100644 --- a/dmp-backend/src/main/java/dao/entities/RegistryDao.java +++ b/dmp-backend/src/main/java/dao/entities/RegistryDao.java @@ -1,10 +1,16 @@ package dao.entities; +import java.util.List; import java.util.UUID; import dao.Dao; import entities.Registry; +import entities.responses.IDLabelPair; public interface RegistryDao extends Dao { + List listAllIDs(); + + List listAllIDsLabels(); + } \ No newline at end of file diff --git a/dmp-backend/src/main/java/dao/entities/RegistryDaoImpl.java b/dmp-backend/src/main/java/dao/entities/RegistryDaoImpl.java index c1bf9e83b..dc59ec05a 100644 --- a/dmp-backend/src/main/java/dao/entities/RegistryDaoImpl.java +++ b/dmp-backend/src/main/java/dao/entities/RegistryDaoImpl.java @@ -1,10 +1,16 @@ package dao.entities; +import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; +import javax.persistence.TypedQuery; + +import org.hibernate.query.Query; import dao.JpaDao; import entities.Registry; +import entities.responses.IDLabelPair; public class RegistryDaoImpl extends JpaDao implements RegistryDao { @@ -13,5 +19,24 @@ public class RegistryDaoImpl extends JpaDao implements RegistryD return null; } + @Override + public List listAllIDs() { + String queryString = "SELECT registry.id FROM Registry registry"; + TypedQuery typedQuery = entityManager.createQuery(queryString, UUID.class); + return typedQuery.getResultList(); + } + + + @Override + public List listAllIDsLabels() { + String queryString = "SELECT registry.id, registry.label FROM Registry registry"; + Query query = (Query) entityManager.createQuery(queryString); + List rows = query.list(); + return rows.stream().map(row -> { + return new IDLabelPair(row[0].toString(), row[1].toString()); + }) + .collect(Collectors.toList()); + } + } diff --git a/dmp-backend/src/main/java/dao/entities/ResearcherDao.java b/dmp-backend/src/main/java/dao/entities/ResearcherDao.java index 1a285bf7e..16e74cd34 100644 --- a/dmp-backend/src/main/java/dao/entities/ResearcherDao.java +++ b/dmp-backend/src/main/java/dao/entities/ResearcherDao.java @@ -1,10 +1,16 @@ package dao.entities; +import java.util.List; import java.util.UUID; import dao.Dao; import entities.Researcher; +import entities.responses.IDLabelPair; public interface ResearcherDao extends Dao { + List listAllIDs(); + + List listAllIDsLabels(); + } \ No newline at end of file diff --git a/dmp-backend/src/main/java/dao/entities/ResearcherDaoImpl.java b/dmp-backend/src/main/java/dao/entities/ResearcherDaoImpl.java index b5b9537c5..bdf592e21 100644 --- a/dmp-backend/src/main/java/dao/entities/ResearcherDaoImpl.java +++ b/dmp-backend/src/main/java/dao/entities/ResearcherDaoImpl.java @@ -1,10 +1,16 @@ package dao.entities; +import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; +import javax.persistence.TypedQuery; + +import org.hibernate.query.Query; import dao.JpaDao; import entities.Researcher; +import entities.responses.IDLabelPair; public class ResearcherDaoImpl extends JpaDao implements ResearcherDao { @@ -14,4 +20,24 @@ public class ResearcherDaoImpl extends JpaDao implements Resea } + @Override + public List listAllIDs() { + String queryString = "SELECT researcher.id FROM Researcher researcher"; + TypedQuery typedQuery = entityManager.createQuery(queryString, UUID.class); + return typedQuery.getResultList(); + } + + + @Override + public List listAllIDsLabels() { + String queryString = "SELECT researcher.id, researcher.label FROM Researcher researcher"; + Query query = (Query) entityManager.createQuery(queryString); + List rows = query.list(); + return rows.stream().map(row -> { + return new IDLabelPair(row[0].toString(), row[1].toString()); + }) + .collect(Collectors.toList()); + } + + } diff --git a/dmp-backend/src/main/java/dao/entities/ServiceDao.java b/dmp-backend/src/main/java/dao/entities/ServiceDao.java index 381d038e5..fd69e8341 100644 --- a/dmp-backend/src/main/java/dao/entities/ServiceDao.java +++ b/dmp-backend/src/main/java/dao/entities/ServiceDao.java @@ -1,10 +1,16 @@ package dao.entities; +import java.util.List; import java.util.UUID; import dao.Dao; import entities.Service; +import entities.responses.IDLabelPair; public interface ServiceDao extends Dao { + List listAllIDs(); + + List listAllIDsLabels(); + } \ No newline at end of file diff --git a/dmp-backend/src/main/java/dao/entities/ServiceDaoImpl.java b/dmp-backend/src/main/java/dao/entities/ServiceDaoImpl.java index 61ef9e28f..2f6ed120f 100644 --- a/dmp-backend/src/main/java/dao/entities/ServiceDaoImpl.java +++ b/dmp-backend/src/main/java/dao/entities/ServiceDaoImpl.java @@ -1,10 +1,16 @@ package dao.entities; +import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; +import javax.persistence.TypedQuery; + +import org.hibernate.query.Query; import dao.JpaDao; import entities.Service; +import entities.responses.IDLabelPair; public class ServiceDaoImpl extends JpaDao implements ServiceDao { @@ -13,5 +19,24 @@ public class ServiceDaoImpl extends JpaDao implements ServiceDao return null; } + @Override + public List listAllIDs() { + String queryString = "SELECT service.id FROM Service service"; + TypedQuery typedQuery = entityManager.createQuery(queryString, UUID.class); + return typedQuery.getResultList(); + } + + + @Override + public List listAllIDsLabels() { + String queryString = "SELECT service.id, service.label FROM Service service"; + Query query = (Query) entityManager.createQuery(queryString); + List rows = query.list(); + return rows.stream().map(row -> { + return new IDLabelPair(row[0].toString(), row[1].toString()); + }) + .collect(Collectors.toList()); + } + } diff --git a/dmp-backend/src/main/java/entities/Dataset.java b/dmp-backend/src/main/java/entities/Dataset.java index 2628b3ec7..58b9ddd62 100644 --- a/dmp-backend/src/main/java/entities/Dataset.java +++ b/dmp-backend/src/main/java/entities/Dataset.java @@ -46,7 +46,7 @@ public class Dataset implements Serializable { @OneToOne(fetch = FetchType.EAGER, cascade=CascadeType.ALL) // @Cascade(value=org.hibernate.annotations.CascadeType.ALL) - @JoinColumn(name = "\"DMP\"", nullable = false) + @JoinColumn(name = "\"DMP\"", nullable = true) private DMP dmp; @@ -59,8 +59,8 @@ public class Dataset implements Serializable { @OneToOne(fetch = FetchType.EAGER, cascade=CascadeType.ALL) - @Cascade(value=org.hibernate.annotations.CascadeType.ALL) - @JoinColumn(name = "\"Profile\"", nullable = false) + //@Cascade(value=org.hibernate.annotations.CascadeType.ALL) + @JoinColumn(name = "\"Profile\"", nullable = true) private DatasetProfile profile; diff --git a/dmp-backend/src/main/java/entities/DatasetProfile.java b/dmp-backend/src/main/java/entities/DatasetProfile.java index 53919eadc..016ac1633 100644 --- a/dmp-backend/src/main/java/entities/DatasetProfile.java +++ b/dmp-backend/src/main/java/entities/DatasetProfile.java @@ -44,18 +44,18 @@ public class DatasetProfile implements Serializable { @Column(name = "\"Label\"") private String label; - @OneToOne(fetch = FetchType.EAGER, mappedBy = "profile", cascade = CascadeType.ALL) + @OneToOne(fetch = FetchType.EAGER, mappedBy = "profile") private Dataset dataset; - @OneToOne(fetch = FetchType.EAGER, cascade=CascadeType.ALL) + @OneToOne(fetch = FetchType.EAGER) // @Cascade(value=org.hibernate.annotations.CascadeType.ALL) - @JoinColumn(name = "\"Ruleset\"", nullable = false) + @JoinColumn(name = "\"Ruleset\"", nullable = true) private DatasetProfileRuleset ruleset; - @OneToOne(fetch = FetchType.EAGER, cascade=CascadeType.ALL) + @OneToOne(fetch = FetchType.EAGER) // @Cascade(value=org.hibernate.annotations.CascadeType.ALL) - @JoinColumn(name = "\"Viewstyle\"", nullable = false) + @JoinColumn(name = "\"Viewstyle\"", nullable = true) private DatasetProfileViewstyle viewstyle; @@ -113,6 +113,12 @@ public class DatasetProfile implements Serializable { this.dataset = dataset; } + @Override + public String toString() { + return "DatasetProfile [id=" + id + ", label=" + label + ", dataset=" + dataset + ", ruleset=" + ruleset + + ", viewstyle=" + viewstyle + ", definition=" + definition + "]"; + } + } diff --git a/dmp-backend/src/main/java/entities/responses/IDLabelPair.java b/dmp-backend/src/main/java/entities/responses/IDLabelPair.java new file mode 100644 index 000000000..877cada04 --- /dev/null +++ b/dmp-backend/src/main/java/entities/responses/IDLabelPair.java @@ -0,0 +1,43 @@ +package entities.responses; + +import java.io.Serializable; + +import javax.persistence.Column; + +public class IDLabelPair implements Serializable { + + private static final long serialVersionUID = 4539082928100004914L; + + @Column(name = "\"ID\"") + private String id; + + @Column(name = "\"Label\"") + private String label; + + + public IDLabelPair(String id, String label) { + super(); + this.id = id; + this.label = label; + } + + + public String getLabel() { + return label; + } + public void setLabel(String label) { + this.label = label; + } + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + + + + + + +} diff --git a/dmp-backend/src/main/java/responses/RestResponse.java b/dmp-backend/src/main/java/responses/RestResponse.java new file mode 100644 index 000000000..d249b9646 --- /dev/null +++ b/dmp-backend/src/main/java/responses/RestResponse.java @@ -0,0 +1,32 @@ +package responses; + +public class RestResponse { + + private String message; + private String objID; + + public RestResponse(String message, String objID) { + super(); + this.message = message; + this.objID = objID; + } + + public String getMessage() { + return message; + } + public void setMessage(String message) { + this.message = message; + } + public String getObjID() { + return objID; + } + public void setObjID(String objID) { + this.objID = objID; + } + + @Override + public String toString() { + return "{\"message\":\"" + message + "\", \"objID\":\"" + objID + "\"}"; + } + +} diff --git a/dmp-backend/src/main/java/rest/BackendInterface.java b/dmp-backend/src/main/java/rest/DMPs.java similarity index 64% rename from dmp-backend/src/main/java/rest/BackendInterface.java rename to dmp-backend/src/main/java/rest/DMPs.java index 6d3a67b2e..b491e2f82 100644 --- a/dmp-backend/src/main/java/rest/BackendInterface.java +++ b/dmp-backend/src/main/java/rest/DMPs.java @@ -14,9 +14,11 @@ 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; @@ -33,13 +35,17 @@ import dao.entities.ResearcherDao; import dao.entities.ServiceDao; import entities.DMP; import entities.Dataset; +import entities.DatasetProfile; +import entities.DatasetProfileRuleset; import entities.Project; +import entities.responses.IDLabelPair; import helpers.Transformers; +import responses.RestResponse; @RestController @CrossOrigin -public class BackendInterface { +public class DMPs { @Autowired private DataRepositoryDao dataRepositoryDao; @Autowired private DatasetDao datasetDao; @@ -69,6 +75,17 @@ public class BackendInterface { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage()); } } + + @RequestMapping(method = RequestMethod.GET, value = { "/listDMPLabelID" }, produces="text/plain") + public @ResponseBody ResponseEntity listDmpLabelID(){ + try { + List allIDLabels = dMPDao.listAllIDsLabels(); + return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(allIDLabels)); + } + catch(Exception ex) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage()); + } + } @RequestMapping(method = RequestMethod.GET, value = { "/DMP/{id}" }, produces="application/json") @@ -197,122 +214,5 @@ public class BackendInterface { - // FETCH BY DATASET(S) - - @RequestMapping(method = RequestMethod.GET, value = { "/dataset" }) - public @ResponseBody ResponseEntity listDatasets(){ - try { - List allIDs = datasetDao.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 = { "/dataset/{id}" }) - public @ResponseBody ResponseEntity getDataset(@PathVariable("id") String id) { - try { - Dataset ds = datasetDao.read(UUID.fromString(id)); - return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(ds)); - } - catch(Exception ex) { - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage()); - } - } - - - /** - * This should be called on extreme cases. It's computationally intensive - */ - @RequestMapping(method = RequestMethod.GET, value = { "/getAllDatasets" }) - public @ResponseBody ResponseEntity getAllDatasets(){ - try { - List allDatasets = datasetDao.getAll(); - return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(allDatasets)); - } - catch(Exception ex) { - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage()); - } - } - - - @RequestMapping(method = RequestMethod.POST, value = { "/setDataset" }, consumes = "application/json") - public @ResponseBody ResponseEntity setDataset(@RequestBody Dataset dataset) { - String reason = ""; - Dataset storedDataset = null; - //try first to create - try { - storedDataset = datasetDao.create(dataset); - return ResponseEntity.status(HttpStatus.CREATED).body("Created Dataset with id: " + storedDataset.getId()); - } - catch(Exception e) { - reason += e.getMessage(); - //try updating - try { - storedDataset = datasetDao.update(dataset); - return ResponseEntity.status(HttpStatus.CREATED).body("Updated Dataset with id: " + storedDataset.getId()); - } - catch(Exception ex) { - reason += (System.lineSeparator()+e.getMessage()); - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Could not create or update Dataset! Reason: " + reason); - } - } - - } - - - // FETCH BY PROJECT(S) - - @RequestMapping(method = RequestMethod.GET, value = { "/project" }) - public @ResponseBody ResponseEntity listProjects(){ - try { - List 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 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 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); - } - } - } - - - } diff --git a/dmp-backend/src/main/java/rest/Datasets.java b/dmp-backend/src/main/java/rest/Datasets.java new file mode 100644 index 000000000..e7267b459 --- /dev/null +++ b/dmp-backend/src/main/java/rest/Datasets.java @@ -0,0 +1,231 @@ +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.Dataset; +import entities.DatasetProfile; +import entities.DatasetProfileRuleset; +import entities.Project; +import helpers.Transformers; +import responses.RestResponse; + + +@RestController +@CrossOrigin +public class Datasets { + + @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; + + + + + // FETCH BY DATASET(S) + + @RequestMapping(method = RequestMethod.GET, value = { "/dataset" }) + public @ResponseBody ResponseEntity listDatasets(){ + try { + List allIDs = datasetDao.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 = { "/dataset/{id}" }) + public @ResponseBody ResponseEntity getDataset(@PathVariable("id") String id) { + try { + Dataset ds = datasetDao.read(UUID.fromString(id)); + return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(ds)); + } + catch(Exception ex) { + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage()); + } + } + + + /** + * This should be called on extreme cases. It's computationally intensive + */ + @RequestMapping(method = RequestMethod.GET, value = { "/getAllDatasets" }) + public @ResponseBody ResponseEntity getAllDatasets(){ + try { + List allDatasets = datasetDao.getAll(); + return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(allDatasets)); + } + catch(Exception ex) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage()); + } + } + + + @RequestMapping(method = RequestMethod.POST, value = { "/setDataset" }, consumes = "application/json") + public @ResponseBody ResponseEntity setDataset(@RequestBody Dataset dataset) { + + String reason = ""; + Dataset storedDataset = null; + //try first to create + try { + storedDataset = datasetDao.create(dataset); + RestResponse rr = new RestResponse("Created dataset with id: "+storedDataset.toString(), storedDataset.getId().toString()); + return ResponseEntity.status(HttpStatus.CREATED).body(rr.toString()); + } + catch(Exception e) { + e.printStackTrace(); + reason += e.getMessage(); + //try updating + try { + storedDataset = datasetDao.update(dataset); + RestResponse rr = new RestResponse("Updated dataset with id: "+storedDataset.toString(), storedDataset.getId().toString()); + return ResponseEntity.status(HttpStatus.CREATED).body(rr.toString()); + } + catch(Exception ex) { + ex.printStackTrace(); + reason += (System.lineSeparator()+e.getMessage()); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Could not create or update Dataset! Reason: " + reason); + } + } + + } + + + @RequestMapping(method = RequestMethod.POST, value = { "/deleteDataset" }, consumes = "application/json") + public @ResponseBody ResponseEntity deleteDataset(@RequestBody Dataset dataset) { + + //if we want to make sure it won't cascade up to other (child) components, we can just unhook them by setting them = new ones + // e.g: DMP dmp = new DMP() and then dataset.setDMP(dmp) + try { + datasetDao.delete(dataset); + RestResponse rr = new RestResponse("Deleted dataset with id: "+dataset.getId().toString(), dataset.getId().toString()); + return ResponseEntity.status(HttpStatus.OK).body(rr.toString()); + } + catch(Exception e) { + e.printStackTrace(); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Could not delete Dataset! Reason: " + e.getMessage()); + } + } + + /* + @RequestMapping(method = RequestMethod.GET, value = { "/createEmptyDataset" }) + public @ResponseBody ResponseEntity createEmptyDataset() { + Dataset dataset = new Dataset(); + dataset.setLabel(""); + + try { + dataset = datasetDao.create(dataset); + } + catch(Exception e) { + e.printStackTrace(); + try { + dataset = datasetDao.update(dataset); + } + catch(Exception ex) { + ex.printStackTrace(); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("FAILED: reason: "+e.getMessage()); + } + } + return ResponseEntity.status(HttpStatus.CREATED).body("Created Dataset with id: " + dataset.getId()); + } + */ + + + //FETCH BY DATASET PROFILE + + @RequestMapping(method = RequestMethod.GET, value = { "/datasetprofile/{id}" }) + public @ResponseBody ResponseEntity getDatasetProfile(@PathVariable("id") String id) { + try { + DatasetProfile profile = datasetProfileDao.read(UUID.fromString(id)); + return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(profile)); + } + catch(Exception ex) { + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage()); + } + } + + @RequestMapping(method = RequestMethod.POST, value = { "/setDatasetProfile" }, consumes = "application/json") + public @ResponseBody ResponseEntity setDatasetProfile(@RequestBody DatasetProfile datasetProfile) { + + String reason = ""; + DatasetProfile storedDatasetProfile = null; + //try first to create + try { + storedDatasetProfile = datasetProfileDao.create(datasetProfile); + return ResponseEntity.status(HttpStatus.CREATED).body("Created DatasetProfile with id: " + storedDatasetProfile.getId()); + } + catch(Exception e) { + reason += e.getMessage(); + //try updating + try { + storedDatasetProfile = datasetProfileDao.update(datasetProfile); + return ResponseEntity.status(HttpStatus.CREATED).body("Updated DatasetProfile with id: " + storedDatasetProfile.getId()); + } + catch(Exception ex) { + reason += (System.lineSeparator()+e.getMessage()); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Could not create or update DatasetProfile! Reason: " + reason); + } + } + + } + + @RequestMapping(method = RequestMethod.GET, value = { "/createEmptyDatasetProfile" }) + public @ResponseBody ResponseEntity createEmptyDatasetProfile() { + DatasetProfile datasetProfile = new DatasetProfile(); + datasetProfile.setLabel(""); + datasetProfile.setDefinition(""); + try { + datasetProfile = datasetProfileDao.create(datasetProfile); + } + catch(Exception e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("FAILED: reason: "+e.getMessage()); + } + return ResponseEntity.status(HttpStatus.CREATED).body("Created DatasetProfile with id: " + datasetProfile.getId()); + } + + + +} + diff --git a/dmp-backend/src/main/java/rest/LoneTables.java b/dmp-backend/src/main/java/rest/LoneTables.java new file mode 100644 index 000000000..fc64b7f6a --- /dev/null +++ b/dmp-backend/src/main/java/rest/LoneTables.java @@ -0,0 +1,419 @@ +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 listProjects(){ + try { + List 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 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 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 listOrganisations(){ + try { + List 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 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 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 listResearchers(){ + try { + List 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 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 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 listServices(){ + try { + List 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 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 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 listRegistries(){ + try { + List 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 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 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 listDataRepositories(){ + try { + List 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 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 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 listDmpProfiles(){ + try { + List 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 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 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); + } + } + } + + +} + diff --git a/dmp-backend/src/main/java/security/CustomAuthenticationProvider.java b/dmp-backend/src/main/java/security/CustomAuthenticationProvider.java index c4674c643..77247c341 100644 --- a/dmp-backend/src/main/java/security/CustomAuthenticationProvider.java +++ b/dmp-backend/src/main/java/security/CustomAuthenticationProvider.java @@ -5,15 +5,12 @@ import java.util.ArrayList; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.authentication.AuthenticationProvider; -import org.springframework.security.authentication.AuthenticationServiceException; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; import org.springframework.stereotype.Component; import dao.entities.security.UserInfoDao; -import entities.security.UserInfo; -import exceptions.NonValidTokenException; @Component public class CustomAuthenticationProvider implements AuthenticationProvider { @@ -49,6 +46,7 @@ public class CustomAuthenticationProvider implements AuthenticationProvider { throw new AuthenticationServiceException("Authentication failed"); */ + //DELETE THIS, USE THE ABOVE return new UsernamePasswordAuthenticationToken("", "", new ArrayList<>()); diff --git a/dmp-backend/src/main/java/security/TokenAuthenticationFilter.java b/dmp-backend/src/main/java/security/TokenAuthenticationFilter.java index f9e968e33..24c7099eb 100644 --- a/dmp-backend/src/main/java/security/TokenAuthenticationFilter.java +++ b/dmp-backend/src/main/java/security/TokenAuthenticationFilter.java @@ -28,7 +28,8 @@ public class TokenAuthenticationFilter extends GenericFilterBean { //just pass the token into the credentials object of the UsernamePasswordAuthenticationToken class final UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken("google-user", accessToken); SecurityContextHolder.getContext().setAuthentication(authentication); - + /* + */ chain.doFilter(request, response); } diff --git a/dmp-backend/src/main/webapp/WEB-INF/spring-security.xml b/dmp-backend/src/main/webapp/WEB-INF/spring-security.xml index 28e58abf8..e51309b46 100644 --- a/dmp-backend/src/main/webapp/WEB-INF/spring-security.xml +++ b/dmp-backend/src/main/webapp/WEB-INF/spring-security.xml @@ -1,3 +1,4 @@ + - - - - @@ -37,19 +28,9 @@ - - - \ No newline at end of file + + --> diff --git a/dmp-backend/src/main/webapp/WEB-INF/web.xml b/dmp-backend/src/main/webapp/WEB-INF/web.xml index 0c3aa66c5..11282be42 100644 --- a/dmp-backend/src/main/webapp/WEB-INF/web.xml +++ b/dmp-backend/src/main/webapp/WEB-INF/web.xml @@ -28,10 +28,10 @@ org.springframework.web.context.ContextLoaderListener - + contextConfigLocation - /WEB-INF/applicationContext.xml,/WEB-INF/spring-security.xml + /WEB-INF/applicationContext.xml @@ -39,6 +39,7 @@ + \ No newline at end of file