Reforming the Rest api
This commit is contained in:
parent
c7e8fe4f5f
commit
833129d8ac
|
@ -17,7 +17,9 @@
|
||||||
<org.springframework.security.version>4.2.3.RELEASE</org.springframework.security.version>
|
<org.springframework.security.version>4.2.3.RELEASE</org.springframework.security.version>
|
||||||
<com.sun.jersey.version>1.19.1</com.sun.jersey.version>
|
<com.sun.jersey.version>1.19.1</com.sun.jersey.version>
|
||||||
<org.apache.tomcat.tomcat-jdbc.version>7.0.35</org.apache.tomcat.tomcat-jdbc.version>
|
<org.apache.tomcat.tomcat-jdbc.version>7.0.35</org.apache.tomcat.tomcat-jdbc.version>
|
||||||
<hibernate.version>5.2.9.Final</hibernate.version>
|
|
||||||
|
<hibernate.version>5.2.11.Final</hibernate.version>
|
||||||
|
|
||||||
<commons-codec.version>1.9</commons-codec.version>
|
<commons-codec.version>1.9</commons-codec.version>
|
||||||
<org.junit.version>4.11</org.junit.version>
|
<org.junit.version>4.11</org.junit.version>
|
||||||
<log4j.version>1.2.17</log4j.version>
|
<log4j.version>1.2.17</log4j.version>
|
||||||
|
|
|
@ -14,6 +14,7 @@ public interface DMPDao extends Dao<DMP, UUID> {
|
||||||
|
|
||||||
List<IDLabelPair> listAllIDsLabels();
|
List<IDLabelPair> listAllIDsLabels();
|
||||||
|
|
||||||
|
// public boolean createFromForm();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package dao.entities;
|
package dao.entities;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -38,4 +39,10 @@ public class DMPDaoImpl extends JpaDao<DMP, UUID> implements DMPDao {
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public boolean createFromForm(Map<String,String> keyVals) {
|
||||||
|
// String query = "insert into DMP () values"
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,4 +14,6 @@ public interface DatasetDao extends Dao<Dataset, UUID> {
|
||||||
|
|
||||||
List<IDLabelPair> listAllIDsLabels();
|
List<IDLabelPair> listAllIDsLabels();
|
||||||
|
|
||||||
|
int assignDMPToDataset(String datasetID, String dmpID);
|
||||||
|
|
||||||
}
|
}
|
|
@ -4,11 +4,10 @@ import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import javax.persistence.Query;
|
||||||
import javax.persistence.TypedQuery;
|
import javax.persistence.TypedQuery;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
import org.hibernate.query.Query;
|
|
||||||
|
|
||||||
import dao.JpaDao;
|
import dao.JpaDao;
|
||||||
import entities.Dataset;
|
import entities.Dataset;
|
||||||
import entities.responses.IDLabelPair;
|
import entities.responses.IDLabelPair;
|
||||||
|
@ -32,11 +31,22 @@ public class DatasetDaoImpl extends JpaDao<Dataset, UUID> implements DatasetDao
|
||||||
public List<IDLabelPair> listAllIDsLabels() {
|
public List<IDLabelPair> listAllIDsLabels() {
|
||||||
String queryString = "SELECT dataset.id, dataset.label FROM Dataset dataset";
|
String queryString = "SELECT dataset.id, dataset.label FROM Dataset dataset";
|
||||||
Query query = (Query) entityManager.createQuery(queryString);
|
Query query = (Query) entityManager.createQuery(queryString);
|
||||||
List<Object[]> rows = query.list();
|
List<Object[]> rows = query.getResultList();
|
||||||
return rows.stream().map(row -> {
|
return rows.stream().map(row -> {
|
||||||
return new IDLabelPair(row[0].toString(), row[1].toString());
|
return new IDLabelPair(row[0].toString(), row[1].toString());
|
||||||
})
|
})
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int assignDMPToDataset(String datasetID , String dmpID) {
|
||||||
|
System.out.println("Dataset -> "+datasetID +" switches to dmp -> "+dmpID);
|
||||||
|
|
||||||
|
Query query = entityManager.createQuery("UPDATE Dataset dataset SET dataset.dmp=:dmpID where dataset.id=:datasetID ");
|
||||||
|
query.setParameter("dmpID", dmpID);
|
||||||
|
query.setParameter("datasetID", datasetID);
|
||||||
|
return query.executeUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,6 @@ public class DMP implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -8263056535208547615L;
|
private static final long serialVersionUID = -8263056535208547615L;
|
||||||
|
|
||||||
public DMP () {}
|
|
||||||
|
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@ -56,11 +55,10 @@ public class DMP implements Serializable {
|
||||||
@Column(name = "\"Version\"")
|
@Column(name = "\"Version\"")
|
||||||
private Integer version;
|
private Integer version;
|
||||||
|
|
||||||
@OneToOne(mappedBy = "dmp", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
@OneToOne(mappedBy = "dmp", fetch = FetchType.EAGER)
|
||||||
private Dataset dataset;
|
private Dataset dataset;
|
||||||
|
|
||||||
@OneToOne(fetch = FetchType.EAGER, cascade=CascadeType.ALL)
|
@OneToOne(fetch = FetchType.EAGER)
|
||||||
// @Cascade(value=org.hibernate.annotations.CascadeType.ALL)
|
|
||||||
@JoinColumn(name = "\"Project\"")
|
@JoinColumn(name = "\"Project\"")
|
||||||
private Project project;
|
private Project project;
|
||||||
|
|
||||||
|
@ -69,13 +67,12 @@ public class DMP implements Serializable {
|
||||||
@Column(name = "\"ProfileData\"", columnDefinition = "xml", nullable = true)
|
@Column(name = "\"ProfileData\"", columnDefinition = "xml", nullable = true)
|
||||||
private String profileData;
|
private String profileData;
|
||||||
|
|
||||||
@OneToOne(fetch = FetchType.EAGER, cascade=CascadeType.ALL)
|
@OneToOne(fetch = FetchType.EAGER)
|
||||||
// @Cascade(value=org.hibernate.annotations.CascadeType.ALL)
|
|
||||||
@JoinColumn(name = "\"Profile\"")
|
@JoinColumn(name = "\"Profile\"")
|
||||||
private DMPProfile profile;
|
private DMPProfile profile;
|
||||||
|
|
||||||
|
|
||||||
@OneToMany(fetch = FetchType.EAGER, cascade=CascadeType.ALL)
|
@OneToMany(fetch = FetchType.EAGER)
|
||||||
@JoinTable(name="\"DMPOrganisation\"",
|
@JoinTable(name="\"DMPOrganisation\"",
|
||||||
joinColumns={@JoinColumn(name="\"DMP\"", referencedColumnName="\"ID\"")},
|
joinColumns={@JoinColumn(name="\"DMP\"", referencedColumnName="\"ID\"")},
|
||||||
inverseJoinColumns={@JoinColumn(name="\"Organisation\"", referencedColumnName="\"ID\"")}
|
inverseJoinColumns={@JoinColumn(name="\"Organisation\"", referencedColumnName="\"ID\"")}
|
||||||
|
@ -83,7 +80,7 @@ public class DMP implements Serializable {
|
||||||
private Set<Organisation> organisations;
|
private Set<Organisation> organisations;
|
||||||
|
|
||||||
|
|
||||||
@OneToMany(fetch = FetchType.EAGER, cascade=CascadeType.ALL)
|
@OneToMany(fetch = FetchType.EAGER)
|
||||||
@JoinTable(name="\"DMPResearcher\"",
|
@JoinTable(name="\"DMPResearcher\"",
|
||||||
joinColumns={@JoinColumn(name="\"DMP\"", referencedColumnName="\"ID\"")},
|
joinColumns={@JoinColumn(name="\"DMP\"", referencedColumnName="\"ID\"")},
|
||||||
inverseJoinColumns={@JoinColumn(name="\"Researcher\"", referencedColumnName="\"ID\"")}
|
inverseJoinColumns={@JoinColumn(name="\"Researcher\"", referencedColumnName="\"ID\"")}
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class Dataset implements Serializable {
|
||||||
private String label;
|
private String label;
|
||||||
|
|
||||||
|
|
||||||
@OneToOne(fetch = FetchType.EAGER, cascade=CascadeType.ALL)
|
@OneToOne(fetch = FetchType.EAGER)
|
||||||
// @Cascade(value=org.hibernate.annotations.CascadeType.ALL)
|
// @Cascade(value=org.hibernate.annotations.CascadeType.ALL)
|
||||||
@JoinColumn(name = "\"DMP\"", nullable = true)
|
@JoinColumn(name = "\"DMP\"", nullable = true)
|
||||||
private DMP dmp;
|
private DMP dmp;
|
||||||
|
@ -58,13 +58,13 @@ public class Dataset implements Serializable {
|
||||||
private String properties;
|
private String properties;
|
||||||
|
|
||||||
|
|
||||||
@OneToOne(fetch = FetchType.EAGER, cascade=CascadeType.ALL)
|
@OneToOne(fetch = FetchType.EAGER)
|
||||||
//@Cascade(value=org.hibernate.annotations.CascadeType.ALL)
|
//@Cascade(value=org.hibernate.annotations.CascadeType.ALL)
|
||||||
@JoinColumn(name = "\"Profile\"", nullable = true)
|
@JoinColumn(name = "\"Profile\"", nullable = true)
|
||||||
private DatasetProfile profile;
|
private DatasetProfile profile;
|
||||||
|
|
||||||
|
|
||||||
@OneToMany(fetch = FetchType.EAGER, cascade=CascadeType.ALL)
|
@OneToMany(fetch = FetchType.EAGER)
|
||||||
@JoinTable(name="\"DatasetDataRepository\"",
|
@JoinTable(name="\"DatasetDataRepository\"",
|
||||||
joinColumns={@JoinColumn(name="\"Dataset\"", referencedColumnName="\"ID\"")},
|
joinColumns={@JoinColumn(name="\"Dataset\"", referencedColumnName="\"ID\"")},
|
||||||
inverseJoinColumns={@JoinColumn(name="\"DataRepository\"", referencedColumnName="\"ID\"")}
|
inverseJoinColumns={@JoinColumn(name="\"DataRepository\"", referencedColumnName="\"ID\"")}
|
||||||
|
@ -72,7 +72,7 @@ public class Dataset implements Serializable {
|
||||||
private Set<DataRepository> dataRepositories;
|
private Set<DataRepository> dataRepositories;
|
||||||
|
|
||||||
|
|
||||||
@OneToMany(fetch = FetchType.EAGER, cascade=CascadeType.ALL)
|
@OneToMany(fetch = FetchType.EAGER)
|
||||||
@JoinTable(name="\"DatasetRegistry\"",
|
@JoinTable(name="\"DatasetRegistry\"",
|
||||||
joinColumns={@JoinColumn(name="\"Dataset\"", referencedColumnName="\"ID\"")},
|
joinColumns={@JoinColumn(name="\"Dataset\"", referencedColumnName="\"ID\"")},
|
||||||
inverseJoinColumns={@JoinColumn(name="\"Registry\"", referencedColumnName="\"ID\"")}
|
inverseJoinColumns={@JoinColumn(name="\"Registry\"", referencedColumnName="\"ID\"")}
|
||||||
|
@ -80,7 +80,7 @@ public class Dataset implements Serializable {
|
||||||
private Set<Registry> registries;
|
private Set<Registry> registries;
|
||||||
|
|
||||||
|
|
||||||
@OneToMany(fetch = FetchType.EAGER, cascade=CascadeType.ALL)
|
@OneToMany(fetch = FetchType.EAGER)
|
||||||
@JoinTable(name="\"DatasetService\"",
|
@JoinTable(name="\"DatasetService\"",
|
||||||
joinColumns={@JoinColumn(name="\"Dataset\"", referencedColumnName="\"ID\"")},
|
joinColumns={@JoinColumn(name="\"Dataset\"", referencedColumnName="\"ID\"")},
|
||||||
inverseJoinColumns={@JoinColumn(name="\"Service\"", referencedColumnName="\"ID\"")}
|
inverseJoinColumns={@JoinColumn(name="\"Service\"", referencedColumnName="\"ID\"")}
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class Project implements Serializable {
|
||||||
private UUID id;
|
private UUID id;
|
||||||
|
|
||||||
|
|
||||||
@OneToOne(fetch = FetchType.EAGER, mappedBy = "project", cascade = CascadeType.ALL)
|
@OneToOne(fetch = FetchType.EAGER, mappedBy = "project")
|
||||||
private DMP dmp;
|
private DMP dmp;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
package rest;
|
package rest;
|
||||||
|
|
||||||
|
import java.io.Console;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
import org.apache.commons.lang3.SerializationUtils;
|
import org.apache.commons.lang3.SerializationUtils;
|
||||||
|
import org.junit.internal.builders.AllDefaultPossibilitiesBuilder;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
|
@ -20,6 +25,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.mchange.v2.sql.filter.SynchronizedFilterDataSource;
|
||||||
|
|
||||||
import dao.entities.DMPDao;
|
import dao.entities.DMPDao;
|
||||||
import dao.entities.DMPProfileDao;
|
import dao.entities.DMPProfileDao;
|
||||||
|
@ -34,6 +40,7 @@ import dao.entities.RegistryDao;
|
||||||
import dao.entities.ResearcherDao;
|
import dao.entities.ResearcherDao;
|
||||||
import dao.entities.ServiceDao;
|
import dao.entities.ServiceDao;
|
||||||
import entities.DMP;
|
import entities.DMP;
|
||||||
|
import entities.DMPProfile;
|
||||||
import entities.Dataset;
|
import entities.Dataset;
|
||||||
import entities.DatasetProfile;
|
import entities.DatasetProfile;
|
||||||
import entities.DatasetProfileRuleset;
|
import entities.DatasetProfileRuleset;
|
||||||
|
@ -61,11 +68,11 @@ public class DMPs {
|
||||||
@Autowired private ServiceDao serviceDao;
|
@Autowired private ServiceDao serviceDao;
|
||||||
|
|
||||||
|
|
||||||
|
private ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
// FETCH BY DMP(S)
|
// FETCH BY DMP(S)
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = { "/DMP" }, produces="text/plain")
|
@RequestMapping(method = RequestMethod.GET, value = { "/dmps" }, produces="text/plain")
|
||||||
public @ResponseBody ResponseEntity<Object> listDMPs(){
|
public @ResponseBody ResponseEntity<Object> listDMPs(){
|
||||||
try {
|
try {
|
||||||
List<UUID> allIDs = dMPDao.listAllIDs();
|
List<UUID> allIDs = dMPDao.listAllIDs();
|
||||||
|
@ -76,7 +83,18 @@ public class DMPs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = { "/listDMPLabelID" }, produces="text/plain")
|
@RequestMapping(method = RequestMethod.GET, value = { "/dmps/{id}" }, produces="application/json")
|
||||||
|
public @ResponseBody ResponseEntity<Object> getDMP(@PathVariable("id") String id){
|
||||||
|
try {
|
||||||
|
DMP dmp = dMPDao.read(UUID.fromString(id));
|
||||||
|
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(dmp));
|
||||||
|
}
|
||||||
|
catch(Exception ex) {
|
||||||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.GET, value = { "/dmp/listDMPLabelID" }, produces="text/plain")
|
||||||
public @ResponseBody ResponseEntity<Object> listDmpLabelID(){
|
public @ResponseBody ResponseEntity<Object> listDmpLabelID(){
|
||||||
try {
|
try {
|
||||||
List<IDLabelPair> allIDLabels = dMPDao.listAllIDsLabels();
|
List<IDLabelPair> allIDLabels = dMPDao.listAllIDsLabels();
|
||||||
|
@ -88,36 +106,50 @@ public class DMPs {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = { "/DMP/{id}" }, produces="application/json")
|
|
||||||
public @ResponseBody ResponseEntity<Object> getDMP(@PathVariable("id") String id){
|
|
||||||
try {
|
|
||||||
DMP dmp = dMPDao.read(UUID.fromString(id));
|
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(dmp));
|
|
||||||
}
|
|
||||||
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
|
* This should be called on extreme cases. It's computationally intensive
|
||||||
*/
|
*/
|
||||||
@RequestMapping(method = RequestMethod.GET, value = { "/getAllDMPs" }, produces="application/json")
|
@RequestMapping(method = RequestMethod.GET, value = { "/dmp/getAll" }, produces="application/json")
|
||||||
public @ResponseBody ResponseEntity<Object> getAllDMPs(){
|
public @ResponseBody ResponseEntity<Object> getAllDMPs(){
|
||||||
try {
|
try {
|
||||||
List<DMP> allDMPs = dMPDao.getAll();
|
List<DMP> allDMPs = dMPDao.getAll();
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ObjectMapper().writeValueAsString(allDMPs));
|
|
||||||
|
//sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom
|
||||||
|
List<String> dmpStrL = allDMPs.parallelStream().map((dmpObj) -> {
|
||||||
|
try {
|
||||||
|
return objectMapper.writeValueAsString(dmpObj);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
|
return new ResponseEntity<Object>("["+String.join(",", dmpStrL)+"]", HttpStatus.OK);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch(Exception ex) {
|
catch(Exception ex) {
|
||||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Transactional
|
||||||
@RequestMapping(method = RequestMethod.POST, value = { "/setDMP" }, consumes = "application/json", produces="text/plain")
|
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/create" }, consumes = "application/json", produces="application/json")
|
||||||
public @ResponseBody ResponseEntity<Object> setDMP(@RequestBody DMP dmp) {
|
public @ResponseBody ResponseEntity<Object> setDMP(@RequestBody DMP dmp) {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
DMP createdDmp = dMPDao.update(dmp);
|
||||||
|
try {
|
||||||
|
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdDmp));
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create DMP!\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/set/full" }, consumes = "application/json", produces="application/json")
|
||||||
|
public @ResponseBody ResponseEntity<Object> setFullDMP(@RequestBody DMP dmp) {
|
||||||
|
|
||||||
//This function is a little bit tricky to implement (due to the irregular ORM mappings of the hibernate).
|
//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.
|
// Please make changes only if you are sure about what you're altering.
|
||||||
|
@ -177,9 +209,17 @@ public class DMPs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String respBody;
|
||||||
|
try {
|
||||||
|
respBody = objectMapper.writeValueAsString(storedDMP.getId());
|
||||||
|
}
|
||||||
|
catch(JsonProcessingException ex) {
|
||||||
|
respBody = "{\"id\":\""+storedDMP.getId()+"\"}";
|
||||||
|
}
|
||||||
|
|
||||||
if(failsDataset != 2) {
|
if(failsDataset != 2) {
|
||||||
if(failsDMP==0)
|
if(failsDMP==0)
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).body("Created DMP with id: " + storedDMP.getId());
|
return ResponseEntity.status(HttpStatus.CREATED).body(respBody);
|
||||||
else if(failsDMP==1)
|
else if(failsDMP==1)
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).body("Updated DMP with id: " + storedDMP.getId());
|
return ResponseEntity.status(HttpStatus.CREATED).body("Updated DMP with id: " + storedDMP.getId());
|
||||||
else
|
else
|
||||||
|
@ -193,7 +233,26 @@ public class DMPs {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/delete" }, consumes = "application/json", produces="text/plain")
|
||||||
|
public @ResponseBody ResponseEntity<Object> delete(@RequestBody DMP dmp) {
|
||||||
|
|
||||||
|
DMP d = new DMP();
|
||||||
|
d.setId(dmp.getId());
|
||||||
|
try {
|
||||||
|
dMPDao.delete(d);
|
||||||
|
return ResponseEntity.status(HttpStatus.CREATED).body("DELETED!");
|
||||||
|
} catch (Exception e) {
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete DMP!\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// OLD ONES, USED BY THE EMBEDDED (simple) UI OF THIS SERVICE
|
||||||
@RequestMapping(method = RequestMethod.POST, value = { "/setDMPByForm" }, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces="text/plain")
|
@RequestMapping(method = RequestMethod.POST, value = { "/setDMPByForm" }, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces="text/plain")
|
||||||
public @ResponseBody ResponseEntity<Object> setDMPByForm(@RequestBody MultiValueMap<String,String> formData) {
|
public @ResponseBody ResponseEntity<Object> setDMPByForm(@RequestBody MultiValueMap<String,String> formData) {
|
||||||
//create the whole dmp structure by the form fields
|
//create the whole dmp structure by the form fields
|
||||||
|
|
|
@ -0,0 +1,122 @@
|
||||||
|
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 DataRepositories {
|
||||||
|
|
||||||
|
@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 DATAREPOSITORy(IES)
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.GET, value = { "/datarepositories" })
|
||||||
|
public @ResponseBody ResponseEntity<Object> listDataRepositories(){
|
||||||
|
try {
|
||||||
|
List<UUID> 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<Object> 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<Object> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -133,6 +133,11 @@ public class Datasets {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.POST, value = { "/deleteDataset" }, consumes = "application/json")
|
@RequestMapping(method = RequestMethod.POST, value = { "/deleteDataset" }, consumes = "application/json")
|
||||||
public @ResponseBody ResponseEntity<Object> deleteDataset(@RequestBody Dataset dataset) {
|
public @ResponseBody ResponseEntity<Object> deleteDataset(@RequestBody Dataset dataset) {
|
||||||
|
|
||||||
|
@ -151,12 +156,13 @@ public class Datasets {
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = { "/assignDMPToDataset" })
|
@RequestMapping(method = RequestMethod.GET, value = { "/assignDMPToDataset" })
|
||||||
public @ResponseBody ResponseEntity<Object> assignDMPToDataset(@RequestParam("datasetID") String datasetID, @RequestParam("dmpID") String dmpID) {
|
public @ResponseBody ResponseEntity<Object> assignDMPToDataset(@RequestParam("datasetID") String datasetID, @RequestParam("dmpID") String dmpID) {
|
||||||
DMP dmp = null;
|
|
||||||
Dataset dataset = null;
|
|
||||||
|
|
||||||
|
Dataset dataset = null;
|
||||||
try {
|
try {
|
||||||
dmp = dMPDao.read(UUID.fromString(dmpID));
|
|
||||||
dataset = datasetDao.read(UUID.fromString(datasetID));
|
dataset = datasetDao.read(UUID.fromString(datasetID));
|
||||||
|
if(dataset==null || dataset.getId()==null) throw new Exception("Could not find a Dataset by this id");
|
||||||
|
DMP dmp = new DMP();
|
||||||
|
dmp.setId(UUID.fromString(dmpID));
|
||||||
dataset.setDmp(dmp);
|
dataset.setDmp(dmp);
|
||||||
datasetDao.update(dataset);
|
datasetDao.update(dataset);
|
||||||
return ResponseEntity.status(HttpStatus.OK).build();
|
return ResponseEntity.status(HttpStatus.OK).build();
|
||||||
|
@ -165,29 +171,6 @@ public class Datasets {
|
||||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// try {dmp = dMPDao.read(UUID.fromString(dmpID));}
|
|
||||||
// catch(Exception e) {
|
|
||||||
// RestResponse rr = new RestResponse("Could not find a DMP with id: "+dmpID+"! Detailed message: " + e.getMessage(), null);
|
|
||||||
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(rr.toString());
|
|
||||||
// }
|
|
||||||
// try {dataset = datasetDao.read(UUID.fromString(datasetID));}
|
|
||||||
// catch(Exception e) {
|
|
||||||
// RestResponse rr = new RestResponse("Could not find a Dataset with id: "+datasetID+"! Detailed message: " + e.getMessage(), null);
|
|
||||||
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(rr.toString());
|
|
||||||
// }
|
|
||||||
// try {
|
|
||||||
// dataset.setDmp(dmp);
|
|
||||||
// datasetDao.update(dataset);
|
|
||||||
// RestResponse rr = new RestResponse("Assigned DMP with id: "+dmpID+" on Dataset with id: "+datasetID+"!", null);
|
|
||||||
// return ResponseEntity.status(HttpStatus.OK).body(rr.toString());
|
|
||||||
// }
|
|
||||||
// catch(Exception e) {
|
|
||||||
// RestResponse rr = new RestResponse("Could not assign DMP with id: "+dmpID+" on Dataset with id: "+datasetID+"! Detailed message: " + e.getMessage(), null);
|
|
||||||
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(rr.toString());
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -236,23 +219,24 @@ public class Datasets {
|
||||||
//try first to create
|
//try first to create
|
||||||
try {
|
try {
|
||||||
storedDatasetProfile = datasetProfileDao.create(datasetProfile);
|
storedDatasetProfile = datasetProfileDao.create(datasetProfile);
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).body("Created DatasetProfile with id: " + storedDatasetProfile.getId());
|
return ResponseEntity.status(HttpStatus.CREATED).body(new ObjectMapper().writeValueAsString(storedDatasetProfile));
|
||||||
}
|
}
|
||||||
catch(Exception e) {
|
catch(Exception e) {
|
||||||
reason += e.getMessage();
|
reason += e.getMessage();
|
||||||
//try updating
|
//try updating
|
||||||
try {
|
try {
|
||||||
storedDatasetProfile = datasetProfileDao.update(datasetProfile);
|
storedDatasetProfile = datasetProfileDao.update(datasetProfile);
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).body("Updated DatasetProfile with id: " + storedDatasetProfile.getId());
|
return ResponseEntity.status(HttpStatus.CREATED).body(new ObjectMapper().writeValueAsString(storedDatasetProfile));
|
||||||
}
|
}
|
||||||
catch(Exception ex) {
|
catch(Exception ex) {
|
||||||
reason += (System.lineSeparator()+e.getMessage());
|
reason += (System.lineSeparator()+e.getMessage());
|
||||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Could not create or update DatasetProfile! Reason: " + reason);
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("An error occurred! Reason: " + reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
@RequestMapping(method = RequestMethod.GET, value = { "/createEmptyDatasetProfile" })
|
@RequestMapping(method = RequestMethod.GET, value = { "/createEmptyDatasetProfile" })
|
||||||
public @ResponseBody ResponseEntity<Object> createEmptyDatasetProfile() {
|
public @ResponseBody ResponseEntity<Object> createEmptyDatasetProfile() {
|
||||||
DatasetProfile datasetProfile = new DatasetProfile();
|
DatasetProfile datasetProfile = new DatasetProfile();
|
||||||
|
@ -260,12 +244,13 @@ public class Datasets {
|
||||||
datasetProfile.setDefinition("");
|
datasetProfile.setDefinition("");
|
||||||
try {
|
try {
|
||||||
datasetProfile = datasetProfileDao.create(datasetProfile);
|
datasetProfile = datasetProfileDao.create(datasetProfile);
|
||||||
|
return ResponseEntity.status(HttpStatus.CREATED).body(new ObjectMapper().writeValueAsString(datasetProfile));
|
||||||
}
|
}
|
||||||
catch(Exception e) {
|
catch(Exception e) {
|
||||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("FAILED: reason: "+e.getMessage());
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("FAILED: reason: "+e.getMessage());
|
||||||
}
|
}
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).body("Created DatasetProfile with id: " + datasetProfile.getId());
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,139 @@
|
||||||
|
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 entities.responses.IDLabelPair;
|
||||||
|
import helpers.Transformers;
|
||||||
|
import responses.RestResponse;
|
||||||
|
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@CrossOrigin
|
||||||
|
public class DmpProfiles {
|
||||||
|
|
||||||
|
@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 DMPPROFILE(S)
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.GET, value = { "/dmpprofiles" })
|
||||||
|
public @ResponseBody ResponseEntity<Object> listDmpProfiles(){
|
||||||
|
try {
|
||||||
|
List<UUID> 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<Object> 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.GET, value = { "/dmpprofile/listAllLabelIDs" })
|
||||||
|
public @ResponseBody ResponseEntity<Object> listLabelIds(){
|
||||||
|
try {
|
||||||
|
List<IDLabelPair> allIDs = dMPProfileDao.listAllIDsLabels();
|
||||||
|
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.POST, value = { "/dmpprofile/set" }, consumes = "application/json")
|
||||||
|
public @ResponseBody ResponseEntity<Object> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,419 +0,0 @@
|
||||||
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<Object> listProjects(){
|
|
||||||
try {
|
|
||||||
List<UUID> 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<Object> 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<Object> 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<Object> listOrganisations(){
|
|
||||||
try {
|
|
||||||
List<UUID> 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<Object> 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<Object> 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<Object> listResearchers(){
|
|
||||||
try {
|
|
||||||
List<UUID> 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<Object> 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<Object> 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<Object> listServices(){
|
|
||||||
try {
|
|
||||||
List<UUID> 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<Object> 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<Object> 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<Object> listRegistries(){
|
|
||||||
try {
|
|
||||||
List<UUID> 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<Object> 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<Object> 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<Object> listDataRepositories(){
|
|
||||||
try {
|
|
||||||
List<UUID> 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<Object> 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<Object> 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<Object> listDmpProfiles(){
|
|
||||||
try {
|
|
||||||
List<UUID> 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<Object> 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<Object> 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,122 @@
|
||||||
|
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 Organisations {
|
||||||
|
|
||||||
|
@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 ORGANISATIONS(S)
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.GET, value = { "/organizations" })
|
||||||
|
public @ResponseBody ResponseEntity<Object> listOrganisations(){
|
||||||
|
try {
|
||||||
|
List<UUID> 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<Object> 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<Object> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,134 @@
|
||||||
|
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 entities.responses.IDLabelPair;
|
||||||
|
import helpers.Transformers;
|
||||||
|
import responses.RestResponse;
|
||||||
|
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@CrossOrigin
|
||||||
|
public class Projects {
|
||||||
|
|
||||||
|
@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 = { "/projects" })
|
||||||
|
public @ResponseBody ResponseEntity<Object> listProjects(){
|
||||||
|
try {
|
||||||
|
List<UUID> 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 = { "/projects/{id}" })
|
||||||
|
public @ResponseBody ResponseEntity<Object> 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.GET, value = { "/project/listAllLabelIDs" })
|
||||||
|
public @ResponseBody ResponseEntity<Object> listLabelIds(){
|
||||||
|
try {
|
||||||
|
List<IDLabelPair> allIDs = projectDao.listAllIDsLabels();
|
||||||
|
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.POST, value = { "/project/set" }, consumes = "application/json")
|
||||||
|
public @ResponseBody ResponseEntity<Object> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,122 @@
|
||||||
|
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 Registries {
|
||||||
|
|
||||||
|
@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 REGISTRY(IES)
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.GET, value = { "/registries" })
|
||||||
|
public @ResponseBody ResponseEntity<Object> listRegistries(){
|
||||||
|
try {
|
||||||
|
List<UUID> 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<Object> 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<Object> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,122 @@
|
||||||
|
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 Researchers {
|
||||||
|
|
||||||
|
@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 RESEARCHER(S)
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.GET, value = { "/researchers" })
|
||||||
|
public @ResponseBody ResponseEntity<Object> listResearchers(){
|
||||||
|
try {
|
||||||
|
List<UUID> 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<Object> 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<Object> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,120 @@
|
||||||
|
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 Services {
|
||||||
|
|
||||||
|
@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 SERVICE(S)
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.GET, value = { "/services" })
|
||||||
|
public @ResponseBody ResponseEntity<Object> listServices(){
|
||||||
|
try {
|
||||||
|
List<UUID> 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<Object> 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<Object> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue