Added more rest calls. Added a sample junit test.

This commit is contained in:
Nikolaos Laskaris 2017-10-23 19:06:24 +03:00
parent 38676904c8
commit 528580f7b8
24 changed files with 838 additions and 246 deletions

View File

@ -28,5 +28,10 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -4,6 +4,7 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/resources"/>
<property name="context-root" value="dmp-backend"/>
<property name="java-output-path" value="/dmp-backend/target/classes"/>
</wb-module>

View File

@ -271,7 +271,6 @@
</dependency>
<!-- Various libs -->
<dependency>
<groupId>org.apache.commons</groupId>

View File

@ -6,6 +6,7 @@ import java.util.UUID;
import dao.Dao;
import entities.DMP;
import entities.Organisation;
import entities.Project;
import entities.responses.IDLabelPair;
public interface DMPDao extends Dao<DMP, UUID> {
@ -14,7 +15,7 @@ public interface DMPDao extends Dao<DMP, UUID> {
List<IDLabelPair> listAllIDsLabels();
List<DMP> listUserDMPs(String username);
List<DMP> listUserDMPs(String userID);
// public boolean createFromForm();

View File

@ -11,6 +11,7 @@ import org.hibernate.query.Query;
import dao.JpaDao;
import entities.DMP;
import entities.Project;
import entities.UserInfo;
import entities.responses.IDLabelPair;
@ -41,10 +42,12 @@ public class DMPDaoImpl extends JpaDao<DMP, UUID> implements DMPDao {
}
@Override
public List<DMP> listUserDMPs(String username) {
public List<DMP> listUserDMPs(String userID) {
// String queryString = "select ui from UserInfo ui join UserAuth ui.authentication ua where ua.username=:username";
String queryString = "select ui from UserInfo ui join Project ui.pro.authentication ua where ua.username=:username";
// TypedQuery<UserInfo> typedQuery = entityManager.createQuery(queryString, UserInfo.class);
// typedQuery.setParameter("username", username);

View File

@ -14,6 +14,5 @@ public interface DatasetDao extends Dao<Dataset, UUID> {
List<IDLabelPair> listAllIDsLabels();
int assignDMPToDataset(String datasetID, String dmpID);
}

View File

@ -38,15 +38,5 @@ public class DatasetDaoImpl extends JpaDao<Dataset, UUID> implements DatasetDao
.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();
}
}

View File

@ -1,10 +1,17 @@
package dao.entities;
import java.util.List;
import java.util.UUID;
import dao.Dao;
import entities.DatasetProfile;
import entities.responses.IDLabelPair;
public interface DatasetProfileDao extends Dao<DatasetProfile, UUID> {
public List<UUID> listAllIDs();
List<IDLabelPair> listAllIDsLabels();
}

View File

@ -1,10 +1,15 @@
package dao.entities;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import dao.JpaDao;
import entities.DatasetProfile;
import entities.responses.IDLabelPair;
public class DatasetProfileDaoImpl extends JpaDao<DatasetProfile, UUID> implements DatasetProfileDao {
@ -14,5 +19,24 @@ public class DatasetProfileDaoImpl extends JpaDao<DatasetProfile, UUID> implemen
return null;
}
@Override
public List<UUID> listAllIDs() {
String queryString = "SELECT dp.id FROM DatasetProfile dp";
TypedQuery<UUID> typedQuery = entityManager.createQuery(queryString, UUID.class);
return typedQuery.getResultList();
}
@Override
public List<IDLabelPair> listAllIDsLabels() {
String queryString = "SELECT dp.id, dp.label FROM DatasetProfile dp";
Query query = (Query) entityManager.createQuery(queryString);
List<Object[]> rows = query.getResultList();
return rows.stream().map(row -> {
return new IDLabelPair(row[0].toString(), row[1].toString());
})
.collect(Collectors.toList());
}
}

View File

@ -94,23 +94,6 @@ public class DMP implements Serializable {
private Set<Researcher> researchers;
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name="\"UserDMP\"",
joinColumns={@JoinColumn(name="dmp", referencedColumnName="\"ID\"")},
inverseJoinColumns={@JoinColumn(name="usr", referencedColumnName="id")}
)
private Set<UserInfo> users;
public Set<UserInfo> getUsers() {
return users;
}
public void setUsers(Set<UserInfo> users) {
this.users = users;
}
public UUID getId() {
return id;
}

View File

@ -5,7 +5,6 @@ import java.io.Serializable;
import java.util.Set;
import java.util.UUID;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
@ -13,7 +12,6 @@ import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@ -64,7 +62,7 @@ public class DataRepository implements Serializable {
@OneToMany(fetch = FetchType.EAGER, cascade=CascadeType.ALL)
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name="\"DatasetDataRepository\"",
joinColumns={@JoinColumn(name="\"DataRepository\"", referencedColumnName="\"ID\"")},
inverseJoinColumns={@JoinColumn(name="\"Dataset\"", referencedColumnName="\"ID\"")}

View File

@ -50,7 +50,7 @@ public class Dataset implements Serializable {
private String label;
@ManyToOne(fetch = FetchType.EAGER)
@ManyToOne(fetch = FetchType.LAZY)
// @Cascade(value=org.hibernate.annotations.CascadeType.ALL)
@JoinColumn(name = "\"DMP\"", nullable = true)
private DMP dmp;
@ -64,14 +64,14 @@ public class Dataset implements Serializable {
private String properties;
@ManyToOne(fetch = FetchType.EAGER)
@ManyToOne(fetch = FetchType.LAZY)
//@Cascade(value=org.hibernate.annotations.CascadeType.ALL)
@JoinColumn(name = "\"Profile\"", nullable = true)
private DatasetProfile profile;
@OneToMany(fetch = FetchType.EAGER)
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name="\"DatasetDataRepository\"",
joinColumns={@JoinColumn(name="\"Dataset\"", referencedColumnName="\"ID\"")},
inverseJoinColumns={@JoinColumn(name="\"DataRepository\"", referencedColumnName="\"ID\"")}
@ -79,7 +79,7 @@ public class Dataset implements Serializable {
private Set<DataRepository> dataRepositories;
@OneToMany(fetch = FetchType.EAGER)
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name="\"DatasetRegistry\"",
joinColumns={@JoinColumn(name="\"Dataset\"", referencedColumnName="\"ID\"")},
inverseJoinColumns={@JoinColumn(name="\"Registry\"", referencedColumnName="\"ID\"")}
@ -87,7 +87,7 @@ public class Dataset implements Serializable {
private Set<Registry> registries;
@OneToMany(fetch = FetchType.EAGER)
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name="\"DatasetService\"",
joinColumns={@JoinColumn(name="\"Dataset\"", referencedColumnName="\"ID\"")},
inverseJoinColumns={@JoinColumn(name="\"Service\"", referencedColumnName="\"ID\"")}

View File

@ -5,7 +5,6 @@ import java.io.Serializable;
import java.util.Set;
import java.util.UUID;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
@ -16,15 +15,11 @@ import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@Entity
@ -49,14 +44,10 @@ public class DatasetProfile implements Serializable {
@Column(name = "\"Label\"")
private String label;
// @OneToOne(fetch = FetchType.EAGER, mappedBy = "profile")
// private Dataset dataset;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "profile")
@OneToMany(fetch = FetchType.LAZY, mappedBy = "profile")
private Set<Dataset> dataset;
@OneToOne(fetch = FetchType.EAGER)
// @Cascade(value=org.hibernate.annotations.CascadeType.ALL)
@JoinColumn(name = "\"Ruleset\"", nullable = true)

View File

@ -11,6 +11,8 @@ import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
@ -68,6 +70,24 @@ public class Project implements Serializable {
@Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true)
private String definition;
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name="\"UserProject\"",
joinColumns={@JoinColumn(name="project", referencedColumnName="\"ID\"")},
inverseJoinColumns={@JoinColumn(name="usr", referencedColumnName="id")}
)
private Set<UserInfo> users;
public Set<UserInfo> getUsers() {
return users;
}
public void setUsers(Set<UserInfo> users) {
this.users = users;
}
public UUID getId() {
return id;
}

View File

@ -79,23 +79,22 @@ public class UserInfo implements Serializable{
private String additionalinfo;
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name="\"UserDMP\"",
@JoinTable(name="\"UserProject\"",
joinColumns={@JoinColumn(name="usr", referencedColumnName="id")},
inverseJoinColumns={@JoinColumn(name="dmp", referencedColumnName="\"ID\"")}
inverseJoinColumns={@JoinColumn(name="project", referencedColumnName="\"ID\"")}
)
private Set<DMP> dmps;
private Set<Project> projects;
public Set<DMP> getDmps() {
return dmps;
public Set<Project> getProjects() {
return projects;
}
public void setDmps(Set<DMP> dmps) {
this.dmps = dmps;
public void setProjects(Set<Project> projects) {
this.projects = projects;
}
public UUID getId() {
return id;
}

View File

@ -19,11 +19,11 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@Entity
@Table(name="\"UserDMP\"")
@Table(name="\"UserProject\"")
//@Proxy(lazy = false)
//@JsonInclude(Include.NON_NULL)
@JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="id")
public class UserDMP implements Serializable{
public class UserProject implements Serializable{
private static final long serialVersionUID = -4467370784003784660L;
@ -38,8 +38,8 @@ public class UserDMP implements Serializable{
private UUID usr;
@Type(type="org.hibernate.type.PostgresUUIDType") //DEPWARN dependency to Hibernate and PostgreSQL
@Column(name = "dmp", nullable = false)
private UUID dmp;
@Column(name = "project", nullable = false)
private UUID project;
@Column(name = "role")
private Integer role;
@ -61,12 +61,12 @@ public class UserDMP implements Serializable{
this.usr = usr;
}
public UUID getDmp() {
return dmp;
public UUID getProject() {
return project;
}
public void setDmp(UUID dmp) {
this.dmp = dmp;
public void setProject(UUID project) {
this.project = project;
}
public Integer getRole() {

View File

@ -1,6 +1,8 @@
package rest.entities;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
@ -86,16 +88,11 @@ public class DMPs {
}
}
@Transactional
@RequestMapping(method = RequestMethod.GET, value = { "/dmps/{id}" }, produces="application/json")
public @ResponseBody ResponseEntity<Object> getDMP(@PathVariable("id") String id){
try {
System.out.println("Trying for id: "+ id);
DMP dmp = dMPDao.read(UUID.fromString(id));
System.out.println("tried, got : "+ dmp.getId());
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(dmp));
// return ResponseEntity.status(HttpStatus.OK).body(dmp);
}
catch(Exception ex) {
ex.printStackTrace();
@ -114,31 +111,6 @@ public class DMPs {
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/dmp/ofuser" }, produces="text/plain")
public @ResponseBody ResponseEntity<Object> getDmpsOfUser(){
String userID = null;
try {
userID = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
} catch(NullPointerException ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("You have not logged in. You shouldn't be here");
}
UserInfo userInfo = userInfoDao.read(UUID.fromString(userID));
if(userInfo==null) //this should normally never happer
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("There's no such a user on the system. You shouldn't be here");
try {
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(userInfo.getDmps()));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}
/**
* This should be called on extreme cases. It's computationally intensive
@ -169,7 +141,7 @@ public class DMPs {
@Transactional
@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> createDMP(@RequestBody DMP dmp) {
DMP createdDmp = dMPDao.update(dmp);
try {
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdDmp));
@ -179,6 +151,19 @@ public class DMPs {
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/update" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> updateDMP(@RequestBody DMP dmp) {
DMP updatedDMP = dMPDao.update(dmp);
try {
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(updatedDMP));
} catch (JsonProcessingException e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not update DMP!\"");
}
}
/*
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/set/full" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> setFullDMP(@RequestBody DMP dmp) {
@ -284,25 +269,76 @@ public class DMPs {
/*
// 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")
public @ResponseBody ResponseEntity<Object> setDMPByForm(@RequestBody MultiValueMap<String,String> formData) {
//create the whole dmp structure by the form fields
DMP dmp = Transformers.createDMPfromMap(formData);
return setDMP(dmp);
////////////////////////////////
//// USER - RELATED ACTIONS ////
////////////////////////////////
@RequestMapping(method = RequestMethod.GET, value = { "/dmp/getofuser" }, produces="text/plain")
public @ResponseBody ResponseEntity<Object> getDmpsOfUser(){
String userID = null;
try {
userID = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
} catch(NullPointerException ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("You have not logged in. You shouldn't be here");
}
@RequestMapping(method = RequestMethod.POST, value = { "/editDMPByForm" }, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces="text/plain")
public @ResponseBody ResponseEntity<Object> editDMPByForm(@RequestBody MultiValueMap<String,String> formData) {
//get previous DMP by id, replace fields, and update
DMP dmp = dMPDao.read(UUID.fromString(formData.getFirst("dmp-id")));
dmp.getDataset().getProfile().setDefinition(formData.getFirst("DatasetProfile.definition"));
dmp.getDataset().getProfile().getRuleset().setDefinition(formData.getFirst("DatasetProfileRuleset.definition"));
dmp.getDataset().getProfile().getViewstyle().setDefinition(formData.getFirst("DatasetProfileViewStyle.definition"));
return setDMP(dmp);
UserInfo userInfo = userInfoDao.read(UUID.fromString(userID));
if(userInfo==null) //this should normally never happer
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("There's no such a user on the system. You shouldn't be here");
try {
Set<DMP> userDMPs = new HashSet<DMP>();
userInfo.getProjects().forEach(project -> {
userDMPs.addAll(project.getDmps());
});
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(userDMPs));
}
*/
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/dmp/createforproject" }, produces="text/plain")
public @ResponseBody ResponseEntity<Object> createDmpOfProject(@RequestParam("projectid") String projectid, @RequestBody DMP dmp){
UUID projIdUuid;
try {
projIdUuid = UUID.fromString(projectid);
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.NOT_MODIFIED).body("Did not specify an id or id was not valid... Could not do anything");
}
try {
dmp.setId(null);
dmp = dMPDao.create(dmp);
Project project = projectDao.read(projIdUuid);
Set<DMP> dmps = project.getDmps();
if(dmps == null)
dmps = new HashSet<DMP>();
dmps.add(dmp);
project.setDmps(dmps);
project = projectDao.update(project);
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(dmp));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}

View File

@ -0,0 +1,259 @@
package rest.entities;
import java.io.IOException;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.transaction.Transactional;
import org.apache.commons.lang3.SerializationUtils;
import org.springframework.beans.factory.annotation.Autowired;
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.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
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.Dataset;
import entities.DatasetProfile;
import entities.DatasetProfileRuleset;
import entities.DatasetProfileViewstyle;
import entities.Organisation;
import entities.Project;
import helpers.SerializerProvider;
import helpers.Transformers;
import responses.RestResponse;
@RestController
@CrossOrigin
public class DatasetProfiles {
@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;
private ObjectMapper objectMapper =
new ObjectMapper();
//SerializerProvider.getJsonSerializer();
//FETCH BY DATASET PROFILE
@RequestMapping(method = RequestMethod.GET, value = { "/datasetprofiles" }, produces="text/plain")
public @ResponseBody ResponseEntity<Object> listDMPs(){
try {
List<UUID> allIDs = datasetProfileDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/datasetprofiles/{id}" })
public @ResponseBody ResponseEntity<Object> getDatasetProfile(@PathVariable("id") String id) {
try {
DatasetProfile profile = datasetProfileDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(profile));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
}
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/datasetprofile/create" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> createDatasetProfile(@RequestBody DatasetProfile datasetProfile) {
DatasetProfileRuleset datasetprofileruleset = datasetProfile.getRuleset();
DatasetProfileViewstyle datasetprofileviewstyle = datasetProfile.getViewstyle();
if(datasetprofileruleset != null) {
if(datasetprofileruleset.getId()==null)
datasetprofileruleset = datasetProfileRulesetDao.create(datasetprofileruleset);
else
datasetProfileRulesetDao.update(datasetprofileruleset);
datasetProfile.setRuleset(datasetprofileruleset);
}
if(datasetprofileviewstyle != null) {
if(datasetprofileviewstyle.getId()==null)
datasetprofileviewstyle = datasetProfileViewstyleDao.create(datasetprofileviewstyle);
else
datasetProfileViewstyleDao.update(datasetprofileviewstyle);
datasetProfile.setViewstyle(datasetprofileviewstyle);
}
try {
if(datasetProfile.getId()==null)
datasetProfile = datasetProfileDao.create(datasetProfile);
else
datasetProfileDao.update(datasetProfile);
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(datasetProfile));
} catch (JsonProcessingException e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create dataset profile!\"}");
}
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/datasetprofile/update" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> updateDatasetProfile(@RequestBody DatasetProfile datasetProfile) {
DatasetProfileRuleset datasetprofileruleset = datasetProfile.getRuleset();
DatasetProfileViewstyle datasetprofileviewstyle = datasetProfile.getViewstyle();
if(datasetprofileruleset != null) {
if(datasetprofileruleset.getId()==null)
datasetProfileRulesetDao.create(datasetprofileruleset);
else
datasetProfileRulesetDao.update(datasetprofileruleset);
}
if(datasetprofileviewstyle != null) {
if(datasetprofileviewstyle.getId()==null)
datasetProfileViewstyleDao.create(datasetprofileviewstyle);
else
datasetProfileViewstyleDao.update(datasetprofileviewstyle);
}
try {
if(datasetProfile.getId()==null)
datasetProfile = datasetProfileDao.create(datasetProfile);
else
datasetProfile = datasetProfileDao.update(datasetProfile);
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(datasetProfile));
} catch (JsonProcessingException e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create dataset profile!\"}");
}
}
// //@Transactional
// @RequestMapping(method = RequestMethod.POST, value = { "/datasetprofile/set" }, consumes = "application/json", produces="application/json")
// public @ResponseBody ResponseEntity<Object> setDatasetProfile(@RequestBody DatasetProfile datasetProfile) {
//
// System.out.println("inside setDatasetProfile");
// try {
// System.out.println(objectMapper.writeValueAsString(datasetProfile));
// } catch (JsonProcessingException e) {
// e.printStackTrace();
// }
//
// if(datasetProfile.getRuleset()!=null && datasetProfile.getRuleset().getId()!=null){
// DatasetProfileRuleset dpr = datasetProfile.getRuleset();
// datasetProfileRulesetDao.update(dpr);
// DatasetProfileRuleset n = new DatasetProfileRuleset();
// n.setId(dpr.getId());
// datasetProfile.setRuleset(n);
// }
//
// if(datasetProfile.getViewstyle()!=null && datasetProfile.getViewstyle().getId()!=null){
// DatasetProfileViewstyle dpv = datasetProfile.getViewstyle();
// datasetProfileViewstyleDao.update(dpv);
// DatasetProfileViewstyle n = new DatasetProfileViewstyle();
// n.setId(dpv.getId());
// datasetProfile.setViewstyle(n);
// }
//
// datasetProfile.setDataset(null);
//
// DatasetProfile createdDatasetProfile = datasetProfileDao.update(datasetProfile);
// try {
// return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdDatasetProfile));
// } catch (JsonProcessingException e) {
// e.printStackTrace();
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not set dataset profile!\"}");
// }
//
// }
// @RequestMapping(method = RequestMethod.POST, value = { "/createEmptyDatasetProfile" })
// public @ResponseBody ResponseEntity<Object> createEmptyDatasetProfile(@RequestParam("datasetID") String datasetID) {
//
// DatasetProfileRuleset dpr = new DatasetProfileRuleset();
// dpr.setLabel("");
// dpr.setDefinition("");
// dpr.setId(datasetProfileRulesetDao.create(dpr).getId());
//
// DatasetProfileViewstyle dpv = new DatasetProfileViewstyle();
// dpv.setLabel("");
// dpv.setDefinition("");
// dpv.setId(datasetProfileViewstyleDao.create(dpv).getId());
//
// DatasetProfile datasetProfile = new DatasetProfile();
// datasetProfile.setLabel("");
// datasetProfile.setDefinition("");
// datasetProfile.setRuleset(dpr);
// datasetProfile.setViewstyle(dpv);
//
// Dataset ds = new Dataset();
// ds.setId(UUID.fromString(datasetID));
// Set<Dataset> datasets = new HashSet<Dataset>();
// datasets.add(ds);
// datasetProfile.setDataset(datasets);
//
// try {
// datasetProfile = datasetProfileDao.create(datasetProfile);
// return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(datasetProfile));
// }
// catch(Exception e) {
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("FAILED: reason: "+e.getMessage());
// }
// }
}

View File

@ -77,7 +77,8 @@ public class Datasets {
// FETCH BY DATASET(S)
@RequestMapping(method = RequestMethod.GET, value = { "/dataset" })
@RequestMapping(method = RequestMethod.GET, value = { "/datasets" })
public @ResponseBody ResponseEntity<Object> listDatasets(){
try {
List<UUID> allIDs = datasetDao.listAllIDs();
@ -89,7 +90,7 @@ public class Datasets {
}
@RequestMapping(method = RequestMethod.GET, value = { "/dataset/{id}" })
@RequestMapping(method = RequestMethod.GET, value = { "/datasets/{id}" })
public @ResponseBody ResponseEntity<Object> getDataset(@PathVariable("id") String id) {
try {
Dataset ds = datasetDao.read(UUID.fromString(id));
@ -104,7 +105,7 @@ public class Datasets {
/**
* This should be called on extreme cases. It's computationally intensive
*/
@RequestMapping(method = RequestMethod.GET, value = { "/getAllDatasets" })
@RequestMapping(method = RequestMethod.GET, value = { "/dataset/getAll" })
public @ResponseBody ResponseEntity<Object> getAllDatasets(){
try {
@ -128,31 +129,32 @@ public class Datasets {
}
@RequestMapping(method = RequestMethod.POST, value = { "/setDataset" }, consumes = "application/json")
public @ResponseBody ResponseEntity<Object> setDataset(@RequestBody Dataset dataset) {
@RequestMapping(method = RequestMethod.POST, value = { "/dataset/create" }, consumes = "application/json")
public @ResponseBody ResponseEntity<Object> createDataset(@RequestBody Dataset dataset) {
String reason = "";
Dataset storedDataset = null;
//try first to create
dataset.setId(null);
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());
dataset = datasetDao.create(dataset);
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(dataset));
}
catch(Exception e) {
e.printStackTrace();
reason += e.getMessage();
//try updating
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Could not create or update Dataset! Reason: " + e.getMessage());
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/dataset/update" }, consumes = "application/json")
public @ResponseBody ResponseEntity<Object> updateDataset(@RequestBody Dataset dataset) {
try {
storedDataset = datasetDao.update(dataset);
RestResponse rr = new RestResponse("Updated dataset with id: "+storedDataset.toString(), storedDataset.getId().toString());
dataset = datasetDao.update(dataset);
RestResponse rr = new RestResponse("Updated dataset with id: "+dataset.toString(), dataset.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);
}
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Could not create or update Dataset! Reason: " + ex.getMessage());
}
}
@ -160,10 +162,7 @@ public class Datasets {
@RequestMapping(method = RequestMethod.POST, value = { "/deleteDataset" }, consumes = "application/json")
@RequestMapping(method = RequestMethod.POST, value = { "/dataset/delete" }, consumes = "application/json")
public @ResponseBody ResponseEntity<Object> 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
@ -179,7 +178,7 @@ public class Datasets {
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/assignDMPToDataset" })
@RequestMapping(method = RequestMethod.GET, value = { "/dataset/assignDMPToDataset" })
public @ResponseBody ResponseEntity<Object> assignDMPToDataset(@RequestParam("datasetID") String datasetID, @RequestParam("dmpID") String dmpID) {
Dataset dataset = null;
@ -199,6 +198,28 @@ public class Datasets {
}
@RequestMapping(method = RequestMethod.GET, value = { "/dataset/assignProfileToDataset" })
public @ResponseBody ResponseEntity<Object> assignProfileToDataset(@RequestParam("datasetID") String datasetID, @RequestParam("profileID") String profileID) {
Dataset dataset = null;
try {
dataset = datasetDao.read(UUID.fromString(datasetID));
if(dataset==null || dataset.getId()==null) throw new Exception("Could not find a Dataset by this id");
DatasetProfile profile = new DatasetProfile();
profile.setId(UUID.fromString(profileID));
dataset.setProfile(profile);
datasetDao.update(dataset);
return ResponseEntity.status(HttpStatus.OK).build();
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}
/*
@RequestMapping(method = RequestMethod.GET, value = { "/createEmptyDataset" })
public @ResponseBody ResponseEntity<Object> createEmptyDataset() {
@ -223,99 +244,6 @@ public class Datasets {
*/
//FETCH BY DATASET PROFILE
@RequestMapping(method = RequestMethod.GET, value = { "/datasetprofile/{id}" })
public @ResponseBody ResponseEntity<Object> getDatasetProfile(@PathVariable("id") String id) {
try {
DatasetProfile profile = datasetProfileDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(profile));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
}
}
//@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/datasetprofile/set" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> setDatasetProfile(@RequestBody DatasetProfile datasetProfile) {
System.out.println("inside setDatasetProfile");
try {
System.out.println(objectMapper.writeValueAsString(datasetProfile));
} catch (JsonProcessingException e) {
e.printStackTrace();
}
if(datasetProfile.getRuleset()!=null && datasetProfile.getRuleset().getId()!=null){
DatasetProfileRuleset dpr = datasetProfile.getRuleset();
datasetProfileRulesetDao.update(dpr);
DatasetProfileRuleset n = new DatasetProfileRuleset();
n.setId(dpr.getId());
datasetProfile.setRuleset(n);
}
if(datasetProfile.getViewstyle()!=null && datasetProfile.getViewstyle().getId()!=null){
DatasetProfileViewstyle dpv = datasetProfile.getViewstyle();
datasetProfileViewstyleDao.update(dpv);
DatasetProfileViewstyle n = new DatasetProfileViewstyle();
n.setId(dpv.getId());
datasetProfile.setViewstyle(n);
}
datasetProfile.setDataset(null);
DatasetProfile createdDatasetProfile = datasetProfileDao.update(datasetProfile);
try {
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdDatasetProfile));
} catch (JsonProcessingException e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not set dataset profile!\"}");
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/createEmptyDatasetProfile" })
public @ResponseBody ResponseEntity<Object> createEmptyDatasetProfile(@RequestParam("datasetID") String datasetID) {
DatasetProfileRuleset dpr = new DatasetProfileRuleset();
dpr.setLabel("");
dpr.setDefinition("");
dpr.setId(datasetProfileRulesetDao.create(dpr).getId());
DatasetProfileViewstyle dpv = new DatasetProfileViewstyle();
dpv.setLabel("");
dpv.setDefinition("");
dpv.setId(datasetProfileViewstyleDao.create(dpv).getId());
DatasetProfile datasetProfile = new DatasetProfile();
datasetProfile.setLabel("");
datasetProfile.setDefinition("");
datasetProfile.setRuleset(dpr);
datasetProfile.setViewstyle(dpv);
Dataset ds = new Dataset();
ds.setId(UUID.fromString(datasetID));
Set<Dataset> datasets = new HashSet<Dataset>();
datasets.add(ds);
datasetProfile.setDataset(datasets);
try {
datasetProfile = datasetProfileDao.create(datasetProfile);
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(datasetProfile));
}
catch(Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("FAILED: reason: "+e.getMessage());
}
}

View File

@ -1,6 +1,8 @@
package rest.entities;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
@ -11,6 +13,7 @@ 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.security.core.context.SecurityContextHolder;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
@ -39,6 +42,7 @@ import dao.entities.ProjectDao;
import dao.entities.RegistryDao;
import dao.entities.ResearcherDao;
import dao.entities.ServiceDao;
import dao.entities.UserInfoDao;
import entities.DMP;
import entities.DMPProfile;
import entities.DataRepository;
@ -50,6 +54,7 @@ import entities.Project;
import entities.Registry;
import entities.Researcher;
import entities.Service;
import entities.UserInfo;
import entities.responses.IDLabelPair;
import helpers.SerializerProvider;
import helpers.Transformers;
@ -72,6 +77,7 @@ public class Projects {
@Autowired private RegistryDao registryDao;
@Autowired private ResearcherDao researcherDao;
@Autowired private ServiceDao serviceDao;
@Autowired private UserInfoDao userInfoDao;
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
@ -168,6 +174,102 @@ public class Projects {
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/project/getdmps" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> getProjectDmps(@RequestBody Project project) {
try {
Set<DMP> dmps = projectDao.read(project.getId()).getDmps();
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(dmps));
} catch (JsonProcessingException e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create Project!\"}");
}
}
////////////////////////////////
//// USER - RELATED ACTIONS ////
////////////////////////////////
@RequestMapping(method = RequestMethod.GET, value = { "/project/getofuser" }, produces="text/plain")
public @ResponseBody ResponseEntity<Object> getProjectsOfUser(){
String userID = null;
try {
userID = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
} catch(NullPointerException ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("You have not logged in. You shouldn't be here");
}
UserInfo userInfo = userInfoDao.read(UUID.fromString(userID));
if(userInfo==null) //this should normally never happer
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("There's no such a user on the system. You shouldn't be here");
try {
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(userInfo.getProjects()));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/project/createofuser" }, produces="text/plain")
public @ResponseBody ResponseEntity<Object> createProjectOfUser(@RequestBody Project project){
String userID = null;
try {
userID = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
} catch(NullPointerException ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("You have not logged in. You shouldn't be here");
}
UserInfo userInfo = userInfoDao.read(UUID.fromString(userID));
if(userInfo==null) //this should normally never happer
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("There's no such a user on the system. You shouldn't be here");
try {
project.setId(null);
Project newproj = projectDao.create(project);
Set<Project> userProjects = userInfo.getProjects();
if(userProjects==null)
userProjects = new HashSet<Project>();
userProjects.add(newproj);
userInfo.setProjects(userProjects);
userInfo = userInfoDao.update(userInfo);
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(userInfo));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/project/updateofuser" }, produces="text/plain")
public @ResponseBody ResponseEntity<Object> updateProjectOfUser(@RequestBody Project project){
if(project.getId()==null)
return ResponseEntity.status(HttpStatus.NOT_MODIFIED).body("Cannot update, id was null");
return setProject(project);
}
}

View File

@ -79,5 +79,7 @@ public class Users {
}

View File

@ -67,22 +67,22 @@
<context-param>
<param-name>contextConfigLocation</param-name>
<!-- <param-value>/WEB-INF/applicationContext.xml,/WEB-INF/spring-security.xml</param-value> -->
<param-value>/WEB-INF/applicationContext.xml</param-value>
<param-value>/WEB-INF/applicationContext.xml,/WEB-INF/spring-security.xml</param-value>
<!-- <param-value>/WEB-INF/applicationContext.xml</param-value> -->
</context-param>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<!-- THIS FILTER IS FOR SPRING SECURITY -->
<!-- <filter> -->
<!-- <filter-name>springSecurityFilterChain</filter-name> -->
<!-- <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> -->
<!-- </filter> -->
<!-- <filter-mapping> -->
<!-- <filter-name>springSecurityFilterChain</filter-name> -->
<!-- <url-pattern>/rest/*</url-pattern> -->
<!-- </filter-mapping> -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/rest/*</url-pattern>
</filter-mapping>

View File

@ -0,0 +1,127 @@
import static org.junit.Assert.*;
import java.util.ArrayList;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
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 dao.entities.UserInfoDao;
import entities.DatasetProfile;
import entities.DatasetProfileRuleset;
import entities.DatasetProfileViewstyle;
import helpers.SerializerProvider;
import rest.entities.DMPs;
import rest.entities.DatasetProfiles;
import rest.entities.Datasets;
import rest.entities.Projects;
@ComponentScan(basePackages = "dao, entities, controller, login, proxy, rest")
public class TestRest {
@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;
@Autowired private UserInfoDao userInfoDao;
private static ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
private static String userID = "0f51f686-a2ce-47c1-9433-00736787aa88";
private ApplicationContext context;
private Projects projectsService;
private Datasets datasetsService;
private DatasetProfiles datasetProfilesService;
private DMPs dmpsService;
@Before
public void setupAll() {
Authentication dummy = new UsernamePasswordAuthenticationToken(userID, "test-creds", new ArrayList<>());
SecurityContextHolder.getContext().setAuthentication(dummy);
context = new ClassPathXmlApplicationContext("applicationContextTEST.xml");
projectsService = context.getBean(Projects.class);
datasetsService = context.getBean(Datasets.class);
datasetProfilesService = context.getBean(DatasetProfiles.class);
dmpsService = context.getBean(DMPs.class);
}
@Test
public void testDatasetProfile() {
DatasetProfile datasetProfile = new DatasetProfile();
datasetProfile.setLabel("Sample-Dataset-Profile");
datasetProfile.setDefinition("Sample-Dataset-Profile definition");
DatasetProfileRuleset dpr = new DatasetProfileRuleset();
dpr.setLabel("Sample-Dataset-Profile ruleset");
dpr.setDefinition("dpr definition");
datasetProfile.setRuleset(dpr);
DatasetProfileViewstyle dpv = new DatasetProfileViewstyle();
dpv.setLabel("Sample-Dataset-Profile viewstyle");
dpv.setDefinition("dpv definition");
datasetProfile.setViewstyle(dpv);
String profJSON = (String)datasetProfilesService.createDatasetProfile(datasetProfile).getBody();
DatasetProfile prof = null;
try {
prof = objectMapper.readValue(profJSON, DatasetProfile.class);
assertNotNull(prof.getId());
}
catch(Exception ex) {
}
assertNotNull(prof);
}
@Test
public void testProject() {
System.out.println(projectsService.listProjects().getBody());
System.out.println(dmpsService.listDMPs().getBody());
assertEquals("aaa", "aaa");
}
}

View File

@ -0,0 +1,118 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder location="classpath*:**/dmpTEST.properties" />
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
<!-- <bean id="remoteFileRepositoryHostname" class="java.lang.String" /> -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="emf" />
<property name="jpaDialect" ref="jpaDialect" />
</bean>
<bean id="tokenSessionManager" class="security.TokenSessionManager" factory-method="getInstance" />
<bean id="googleTokenValidator" class="security.validators.GoogleTokenValidator" />
<bean id="nativeTokenValidator" class="security.validators.NativeTokenValidator" />
<bean id="proxy" class="proxy.Proxy">
<constructor-arg type = "String" value = "${proxy.allowed.host}"/>
</bean>
<bean id="springApplicationContext" class="dao.SpringJpaDaoFactory" />
<bean id="databaseColumnType" class="typedefinition.PostgreSQLDatabaseColumnType" />
<bean id="tokenAuthenticationFilter" class="security.TokenAuthenticationFilter" />
<bean id="customAuthenticationProvider" class="security.CustomAuthenticationProvider" />
<bean id="emf" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="DMPBackendPersistence" />
<property name="jpaProperties">
<props>
<prop key="javax.persistence.jdbc.driver">${persistence.jdbc.driver}</prop>
<prop key="javax.persistence.jdbc.url">${persistence.jdbc.url}</prop>
<prop key="hibernate.connection.username">${persistence.dbusername}</prop>
<prop key="hibernate.connection.password">${persistence.dbpassword}</prop>
<prop key="hibernate.show_sql">${persistence.hibernate.show_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${persistence.hibernate.hbm2dll}</prop>
<prop key="hibernate.dialect">${persistence.hibernate.dialect}</prop>
<prop key="hibernate.enable_lazy_load_no_trans">true</prop> <!-- USE WITH CAUTION -->
<prop key="hibernate.jdbc.batch_size">${persistence.hibernate.jdbc.batch_size}</prop>
<prop key="hibernate.order_inserts">${persistence.hibernate.order_inserts}</prop>
<prop key="hibernate.order_updates">${persistence.hibernate.order_updates}</prop>
<prop key="hibernate.jdbc.batch_versioned_data">${persistence.hibernate.batch_versioned_data}</prop>
<prop key="hibernate.connection.handling_mode">${persistence.hibernate.jdbc.batch_versioned_data}</prop>
<prop key="hibernate.connection.release_mode">on_close</prop>
<prop key="hibernate.connection.provider_class">${persistence.hibernate.connectionpool.provider_class}</prop>
<prop key="hibernate.c3p0.min_size">${persistence.hibernate.connectionpool.c3p0.min_size}</prop>
<prop key="hibernate.c3p0.max_size">${persistence.hibernate.connectionpool.c3p0.max_size}</prop>
<prop key="hibernate.c3p0.timeout">0</prop>
<!-- <prop key="hibernate.c3p0.timeout">${persistence.hibernate.connectionpool.c3p0.timeout}</prop> -->
<prop key="hibernate.c3p0.max_statements">${persistence.hibernate.connectionpool.c3p0.max_statements}</prop>
<prop key="hibernate.c3p0.acquire_retry_attempts">${persistence.hibernate.connectionpool.c3p0.acquire_retry_attempts}</prop>
<prop key="hibernate.c3p0.acquire_retry_delay">${persistence.hibernate.connectionpool.c3p0.acquire_retry_delay}</prop>
<prop key="hibernate.c3p0.idle_test_period">${persistence.hibernate.connectionpool.c3p0.idle_test_period}</prop>
<prop key="hibernate.c3p0.break_after_acquire_failure">${persistence.hibernate.connectionpool.c3p0.break_after_acquire_failure}</prop>
<prop key="hibernate.c3p0.idle_connection_test_period">${persistence.hibernate.connectionpool.c3p0.idle_connection_test_period}</prop>
<prop key="hibernate.c3p0.test_connection_on_checkin">${persistence.hibernate.connectionpool.c3p0.test_connection_on_checkin}</prop>
<prop key="hibernate.c3p0.test_connection_on_checkout">${persistence.hibernate.connectionpool.c3p0.test_connection_on_checkout}</prop>
<prop key="hibernate.c3p0.preferred_test_query">${persistence.hibernate.connectionpool.c3p0.preferred_test_query}</prop>
</props>
</property>
</bean>
<bean id="organisationDao" class="dao.entities.OrganisationDaoImpl" />
<bean id="dataRepositoryDao" class="dao.entities.DataRepositoryDaoImpl" />
<bean id="datasetDao" class="dao.entities.DatasetDaoImpl" />
<bean id="datasetProfileDao" class="dao.entities.DatasetProfileDaoImpl" />
<bean id="datasetProfileRulesetDao" class="dao.entities.DatasetProfileRulesetDaoImpl" />
<bean id="datasetProfileViewstyleDao" class="dao.entities.DatasetProfileViewstyleDaoImpl" />
<bean id="datasetRegistryDao" class="dao.entities.DatasetRegistryDaoImpl" />
<bean id="datasetServiceDao" class="dao.entities.DatasetServiceDaoImpl" />
<bean id="dMPDao" class="dao.entities.DMPDaoImpl" />
<bean id="dMPProfileDao" class="dao.entities.DMPProfileDaoImpl" />
<bean id="dMPResearcherDao" class="dao.entities.DMPResearcherDaoImpl" />
<bean id="projectDao" class="dao.entities.ProjectDaoImpl" />
<bean id="registryDao" class="dao.entities.RegistryDaoImpl" />
<bean id="researcherDao" class="dao.entities.ResearcherDaoImpl" />
<bean id="serviceDao" class="dao.entities.ServiceDaoImpl" />
<bean id="userInfoDao" class="dao.entities.UserInfoDaoImpl" />
<bean id="userAuthDao" class="dao.entities.security.UserAuthDaoImpl" />
<context:annotation-config />
<context:component-scan base-package="entities" />
<context:component-scan base-package="dao" />
<context:component-scan base-package="core" />
<context:component-scan base-package="rest" />
<!-- <context:component-scan base-package="controller" /> -->
</beans>