Merge branch 'master' of gitlab.eudat.eu:dmp/OpenAIRE-EUDAT-DMP-service-pilot

This commit is contained in:
annampak 2017-10-27 17:13:21 +03:00
commit 294e113a05
18 changed files with 248 additions and 301 deletions

View File

@ -92,6 +92,23 @@ public class DMP implements Serializable {
private Set<Researcher> researchers; 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() { public UUID getId() {
return id; return id;
} }

View File

@ -67,23 +67,6 @@ public class Project implements Serializable {
@Type(type="typedefinition.XMLType") @Type(type="typedefinition.XMLType")
@Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true) @Column(name = "\"Definition\"", columnDefinition = "xml", nullable = true)
private String definition; 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() { public UUID getId() {

View File

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

View File

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

View File

@ -1,5 +1,12 @@
package helpers; package helpers;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module; import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module;
import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module.Feature; import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module.Feature;
@ -12,7 +19,11 @@ public class SerializerProvider {
static { static {
initialize();
}
public static void initialize() {
Hibernate5Module module = new Hibernate5Module(); Hibernate5Module module = new Hibernate5Module();
module.enable(Feature.SERIALIZE_IDENTIFIER_FOR_LAZY_NOT_LOADED_OBJECTS); module.enable(Feature.SERIALIZE_IDENTIFIER_FOR_LAZY_NOT_LOADED_OBJECTS);
objectMapper = new ObjectMapper() objectMapper = new ObjectMapper()
@ -20,12 +31,26 @@ public class SerializerProvider {
// .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) // .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.registerModule(new Hibernate5Module()) .registerModule(new Hibernate5Module())
; ;
} }
public static ObjectMapper getJsonSerializer() { public static ObjectMapper getJsonSerializer() {
if(objectMapper==null)
initialize();
return objectMapper; return objectMapper;
} }
public static String toJson(Object obj) {
try {
return getJsonSerializer().writeValueAsString(obj);
}catch(JsonProcessingException ex) {
return "";
}
}
public static String toJson(Collection<?> coll) {
List<String> list = coll.parallelStream().map(obj -> toJson(obj)).collect(Collectors.toList());
return "["+StringUtils.join(list.toArray(), ",")+"]";
}
} }

View File

@ -1,5 +1,7 @@
package rest.entities; package rest.entities;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -72,8 +74,6 @@ public class DMPs {
@Autowired private UserInfoDao userInfoDao; @Autowired private UserInfoDao userInfoDao;
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
// FETCH BY DMP(S) // FETCH BY DMP(S)
@ -81,9 +81,10 @@ public class DMPs {
public @ResponseBody ResponseEntity<Object> listDMPs(){ public @ResponseBody ResponseEntity<Object> listDMPs(){
try { try {
List<UUID> allIDs = dMPDao.listAllIDs(); List<UUID> allIDs = dMPDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs)); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
} }
catch(Exception ex) { catch(Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
} }
} }
@ -92,7 +93,7 @@ public class DMPs {
public @ResponseBody ResponseEntity<Object> getDMP(@PathVariable("id") String id){ public @ResponseBody ResponseEntity<Object> getDMP(@PathVariable("id") String id){
try { try {
DMP dmp = dMPDao.read(UUID.fromString(id)); DMP dmp = dMPDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(dmp)); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(dmp));
} }
catch(Exception ex) { catch(Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -104,9 +105,10 @@ public class DMPs {
public @ResponseBody ResponseEntity<Object> listDmpLabelID(){ public @ResponseBody ResponseEntity<Object> listDmpLabelID(){
try { try {
List<IDLabelPair> allIDLabels = dMPDao.listAllIDsLabels(); List<IDLabelPair> allIDLabels = dMPDao.listAllIDsLabels();
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDLabels)); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDLabels));
} }
catch(Exception ex) { catch(Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
} }
} }
@ -120,18 +122,7 @@ public class DMPs {
try { try {
List<DMP> allDMPs = dMPDao.getAll(); List<DMP> allDMPs = dMPDao.getAll();
return new ResponseEntity<Object>(SerializerProvider.toJson(allDMPs), HttpStatus.OK);
//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) {
ex.printStackTrace(); ex.printStackTrace();
@ -143,10 +134,11 @@ public class DMPs {
@Transactional @Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/create" }, consumes = "application/json", produces="application/json") @RequestMapping(method = RequestMethod.POST, value = { "/dmp/create" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> createDMP(@RequestBody DMP dmp) { public @ResponseBody ResponseEntity<Object> createDMP(@RequestBody DMP dmp) {
DMP createdDmp = dMPDao.update(dmp);
try { try {
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdDmp)); DMP createdDmp = dMPDao.update(dmp);
} catch (JsonProcessingException e) { return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(createdDmp));
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create DMP!\""); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create DMP!\"");
} }
@ -155,10 +147,11 @@ public class DMPs {
@Transactional @Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/update" }, consumes = "application/json", produces="application/json") @RequestMapping(method = RequestMethod.POST, value = { "/dmp/update" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> updateDMP(@RequestBody DMP dmp) { public @ResponseBody ResponseEntity<Object> updateDMP(@RequestBody DMP dmp) {
DMP updatedDMP = dMPDao.update(dmp);
try { try {
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(updatedDMP)); DMP updatedDMP = dMPDao.update(dmp);
} catch (JsonProcessingException e) { return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(updatedDMP));
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not update DMP!\""); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not update DMP!\"");
} }
@ -256,10 +249,10 @@ public class DMPs {
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/getdatasets" }, consumes = "application/json", produces="application/json") @RequestMapping(method = RequestMethod.POST, value = { "/dmp/getdatasets" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> getDatasetsOfDMP(@RequestBody DMP dmp) { public @ResponseBody ResponseEntity<Object> getDatasetsOfDMP(@RequestBody DMP dmp) {
Set<Dataset> datasets = dMPDao.read(dmp.getId()).getDataset();
try { try {
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(datasets)); Set<Dataset> datasets = dMPDao.read(dmp.getId()).getDataset();
} catch (JsonProcessingException e) { return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(datasets));
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not get datasets of DMP!\""); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not get datasets of DMP!\"");
} }
@ -305,13 +298,7 @@ public class DMPs {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("There's no such a user on the system. You shouldn't be here"); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("There's no such a user on the system. You shouldn't be here");
try { try {
Set<DMP> userDMPs = new HashSet<DMP>(); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(userInfo.getDmps()));
userInfo.getProjects().forEach(project -> {
userDMPs.addAll(project.getDmps());
});
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(userDMPs));
} }
catch(Exception ex) { catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
@ -319,33 +306,33 @@ public class DMPs {
} }
@RequestMapping(method = RequestMethod.GET, value = { "/dmp/createforproject" }, produces="text/plain") @RequestMapping(method = RequestMethod.POST, value = { "/dmp/createofuser" }, produces="text/plain")
public @ResponseBody ResponseEntity<Object> createDmpOfProject(@RequestParam("projectid") String projectid, @RequestBody DMP dmp){ public @ResponseBody ResponseEntity<Object> createDmpOfUser(@RequestBody DMP dmp){
UUID projIdUuid;
String userID = null;
try { try {
projIdUuid = UUID.fromString(projectid); userID = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
} } catch(NullPointerException ex) {
catch(Exception ex) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("You have not logged in. You shouldn't be here");
return ResponseEntity.status(HttpStatus.NOT_MODIFIED).body("Did not specify an id or id was not valid... Could not do anything");
} }
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 { try {
dmp.setId(null); dmp.setId(null);
dmp = dMPDao.create(dmp);
Project project = projectDao.read(projIdUuid); Set<UserInfo> users = new HashSet<UserInfo>();
users.add(userInfo);
dmp.setUsers(users);
Set<DMP> dmps = project.getDmps(); DMP newdmp = dMPDao.create(dmp);
if(dmps == null)
dmps = new HashSet<DMP>();
dmps.add(dmp);
project.setDmps(dmps);
project = projectDao.update(project); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(newdmp));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(dmp));
} }
catch(Exception ex) { catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
@ -354,6 +341,43 @@ public class DMPs {
} }
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/adduser" }, produces="text/plain")
public @ResponseBody ResponseEntity<Object> addUserToDmp(@RequestBody DMP dmp){
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");
}
final 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");
if(dmp==null || dmp.getId()==null)
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("DMP is null or dmp has null id");
try {
DMP existingDMP = dMPDao.read(dmp.getId());
Set<UserInfo> users = existingDMP.getUsers().parallelStream().filter(user -> user.getId().toString() != userInfo.getId().toString()).collect(Collectors.toSet());
users.add(userInfo);
dmp.setUsers(users);
DMP updateddmp = dMPDao.update(dmp);
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(updateddmp));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}

View File

@ -69,16 +69,13 @@ public class DataRepositories {
@Autowired private ResearcherDao researcherDao; @Autowired private ResearcherDao researcherDao;
@Autowired private ServiceDao serviceDao; @Autowired private ServiceDao serviceDao;
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
// MANAGE DATAREPOSITORy(IES) // MANAGE DATAREPOSITORy(IES)
@RequestMapping(method = RequestMethod.GET, value = { "/datarepos" }) @RequestMapping(method = RequestMethod.GET, value = { "/datarepos" })
public @ResponseBody ResponseEntity<Object> listDataRepositories(){ public @ResponseBody ResponseEntity<Object> listDataRepositories(){
try { try {
List<UUID> allIDs = dataRepositoryDao.listAllIDs(); List<UUID> allIDs = dataRepositoryDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs)); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
} }
catch(Exception ex) { catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
@ -90,7 +87,7 @@ public class DataRepositories {
public @ResponseBody ResponseEntity<Object> getDataRepository(@PathVariable("id") String id) { public @ResponseBody ResponseEntity<Object> getDataRepository(@PathVariable("id") String id) {
try { try {
DataRepository dataRepository = dataRepositoryDao.read(UUID.fromString(id)); DataRepository dataRepository = dataRepositoryDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(dataRepository)); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(dataRepository));
} }
catch(Exception ex) { catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
@ -105,16 +102,7 @@ public class DataRepositories {
try { try {
List<DataRepository> allDataRepositories = dataRepositoryDao.getAll(); List<DataRepository> allDataRepositories = dataRepositoryDao.getAll();
//sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom return new ResponseEntity<Object>(SerializerProvider.toJson(allDataRepositories), HttpStatus.OK);
List<String> datareposStrL = allDataRepositories.parallelStream().map((datarepoObj) -> {
try {
return objectMapper.writeValueAsString(datarepoObj);
} catch (JsonProcessingException e) {
return "";
}
}).collect(Collectors.toList());
return new ResponseEntity<Object>("["+String.join(",", datareposStrL)+"]", HttpStatus.OK);
} }
catch(Exception ex) { catch(Exception ex) {
@ -130,8 +118,8 @@ public class DataRepositories {
public @ResponseBody ResponseEntity<Object> setOrganisation(@RequestBody DataRepository dataRepository) { public @ResponseBody ResponseEntity<Object> setOrganisation(@RequestBody DataRepository dataRepository) {
DataRepository createdDataRepository = dataRepositoryDao.update(dataRepository); DataRepository createdDataRepository = dataRepositoryDao.update(dataRepository);
try { try {
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdDataRepository)); return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(createdDataRepository));
} catch (JsonProcessingException e) { } catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create data repository!\"}"); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create data repository!\"}");
} }
} }

View File

@ -72,8 +72,6 @@ public class DatasetProfiles {
@Autowired private ResearcherDao researcherDao; @Autowired private ResearcherDao researcherDao;
@Autowired private ServiceDao serviceDao; @Autowired private ServiceDao serviceDao;
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
//FETCH BY DATASET PROFILE //FETCH BY DATASET PROFILE
@ -81,7 +79,7 @@ public class DatasetProfiles {
public @ResponseBody ResponseEntity<Object> listDMPs(){ public @ResponseBody ResponseEntity<Object> listDMPs(){
try { try {
List<UUID> allIDs = datasetProfileDao.listAllIDs(); List<UUID> allIDs = datasetProfileDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs)); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
} }
catch(Exception ex) { catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
@ -93,7 +91,7 @@ public class DatasetProfiles {
public @ResponseBody ResponseEntity<Object> getDatasetProfile(@PathVariable("id") String id) { public @ResponseBody ResponseEntity<Object> getDatasetProfile(@PathVariable("id") String id) {
try { try {
DatasetProfile profile = datasetProfileDao.read(UUID.fromString(id)); DatasetProfile profile = datasetProfileDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(profile)); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(profile));
} }
catch(Exception ex) { catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
@ -105,18 +103,7 @@ public class DatasetProfiles {
try { try {
List<DatasetProfile> allDatasetProfiles = datasetProfileDao.getAll(); List<DatasetProfile> allDatasetProfiles = datasetProfileDao.getAll();
return new ResponseEntity<Object>(SerializerProvider.toJson(allDatasetProfiles), HttpStatus.OK);
//sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom
List<String> datasetProfilesStrL = allDatasetProfiles.stream().map((datasetProfileObj) -> {
try {
return objectMapper.writeValueAsString(datasetProfileObj);
} catch (JsonProcessingException e) {
e.printStackTrace();
return "";
}
}).collect(Collectors.toList());
return new ResponseEntity<Object>("["+String.join(",", datasetProfilesStrL)+"]", HttpStatus.OK);
} }
catch(Exception ex) { catch(Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -149,17 +136,11 @@ public class DatasetProfiles {
datasetProfile.setViewstyle(datasetprofileviewstyle); datasetProfile.setViewstyle(datasetprofileviewstyle);
} }
if(datasetProfile.getId()==null)
try { datasetProfileDao.create(datasetProfile);
if(datasetProfile.getId()==null) else
datasetProfileDao.create(datasetProfile); datasetProfileDao.update(datasetProfile);
else return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(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!\"}");
}
} }
@ -185,17 +166,11 @@ public class DatasetProfiles {
datasetProfileViewstyleDao.update(datasetprofileviewstyle); datasetProfileViewstyleDao.update(datasetprofileviewstyle);
} }
if(datasetProfile.getId()==null)
try { datasetProfile = datasetProfileDao.create(datasetProfile);
if(datasetProfile.getId()==null) else
datasetProfile = datasetProfileDao.create(datasetProfile); datasetProfile = datasetProfileDao.update(datasetProfile);
else return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(datasetProfile));
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!\"}");
}
} }
@ -213,7 +188,7 @@ public class DatasetProfiles {
if(datasetprofileviewstyle != null) if(datasetprofileviewstyle != null)
datasetProfileViewstyleDao.delete(datasetprofileviewstyle); datasetProfileViewstyleDao.delete(datasetprofileviewstyle);
datasetProfileDao.delete(datasetProfile); datasetProfileDao.delete(datasetProfile);
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(datasetProfile)); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(datasetProfile));
} }
catch(Exception ex) { catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not delete dataset profile!\"}"); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not delete dataset profile!\"}");

View File

@ -72,7 +72,6 @@ public class Datasets {
@Autowired private ResearcherDao researcherDao; @Autowired private ResearcherDao researcherDao;
@Autowired private ServiceDao serviceDao; @Autowired private ServiceDao serviceDao;
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
// FETCH BY DATASET(S) // FETCH BY DATASET(S)
@ -81,7 +80,7 @@ public class Datasets {
public @ResponseBody ResponseEntity<Object> listDatasets(){ public @ResponseBody ResponseEntity<Object> listDatasets(){
try { try {
List<UUID> allIDs = datasetDao.listAllIDs(); List<UUID> allIDs = datasetDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs)); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
} }
catch(Exception ex) { catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
@ -93,7 +92,7 @@ public class Datasets {
public @ResponseBody ResponseEntity<Object> getDataset(@PathVariable("id") String id) { public @ResponseBody ResponseEntity<Object> getDataset(@PathVariable("id") String id) {
try { try {
Dataset ds = datasetDao.read(UUID.fromString(id)); Dataset ds = datasetDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(ds)); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(ds));
} }
catch(Exception ex) { catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
@ -109,19 +108,7 @@ public class Datasets {
try { try {
List<Dataset> allDatasets = datasetDao.getAll(); List<Dataset> allDatasets = datasetDao.getAll();
return new ResponseEntity<Object>(SerializerProvider.toJson(allDatasets), HttpStatus.OK);
//sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom
List<String> datasetsStrL = allDatasets.stream().map((datasetObj) -> {
try {
return objectMapper.writeValueAsString(datasetObj);
} catch (JsonProcessingException e) {
e.printStackTrace();
return "";
}
}).collect(Collectors.toList());
return new ResponseEntity<Object>("["+String.join(",", datasetsStrL)+"]", HttpStatus.OK);
} }
catch(Exception ex) { catch(Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -137,7 +124,7 @@ public class Datasets {
dataset.setId(null); dataset.setId(null);
try { try {
dataset = datasetDao.create(dataset); dataset = datasetDao.create(dataset);
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(dataset)); return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(dataset));
} }
catch(Exception e) { catch(Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Could not create or update Dataset! Reason: " + e.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Could not create or update Dataset! Reason: " + e.getMessage());

View File

@ -70,7 +70,6 @@ public class DmpProfiles {
@Autowired private ResearcherDao researcherDao; @Autowired private ResearcherDao researcherDao;
@Autowired private ServiceDao serviceDao; @Autowired private ServiceDao serviceDao;
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
// MANAGE DMPPROFILE(S) // MANAGE DMPPROFILE(S)
@ -78,7 +77,7 @@ public class DmpProfiles {
public @ResponseBody ResponseEntity<Object> listDmpProfiles(){ public @ResponseBody ResponseEntity<Object> listDmpProfiles(){
try { try {
List<UUID> allIDs = dMPProfileDao.listAllIDs(); List<UUID> allIDs = dMPProfileDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs)); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
} }
catch(Exception ex) { catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
@ -92,7 +91,7 @@ public class DmpProfiles {
public @ResponseBody ResponseEntity<Object> getDmpProfile(@PathVariable("id") String id) { public @ResponseBody ResponseEntity<Object> getDmpProfile(@PathVariable("id") String id) {
try { try {
DMPProfile dmpProfile = dMPProfileDao.read(UUID.fromString(id)); DMPProfile dmpProfile = dMPProfileDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(dmpProfile)); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(dmpProfile));
} }
catch(Exception ex) { catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
@ -105,7 +104,7 @@ public class DmpProfiles {
public @ResponseBody ResponseEntity<Object> listLabelIds(){ public @ResponseBody ResponseEntity<Object> listLabelIds(){
try { try {
List<IDLabelPair> allIDs = dMPProfileDao.listAllIDsLabels(); List<IDLabelPair> allIDs = dMPProfileDao.listAllIDsLabels();
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs)); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
} }
catch(Exception ex) { catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
@ -117,18 +116,7 @@ public class DmpProfiles {
public @ResponseBody ResponseEntity<Object> getAllDmpProfiles(){ public @ResponseBody ResponseEntity<Object> getAllDmpProfiles(){
try { try {
List<DMPProfile> allDmpProfiles = dMPProfileDao.getAll(); List<DMPProfile> allDmpProfiles = dMPProfileDao.getAll();
return new ResponseEntity<Object>(SerializerProvider.toJson(allDmpProfiles), HttpStatus.OK);
//sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom
List<String> dmpprofileStrL = allDmpProfiles.parallelStream().map((dmpProfileObj) -> {
try {
return objectMapper.writeValueAsString(dmpProfileObj);
} catch (JsonProcessingException e) {
return "";
}
}).collect(Collectors.toList());
return new ResponseEntity<Object>("["+String.join(",", dmpprofileStrL)+"]", HttpStatus.OK);
} }
catch(Exception ex) { catch(Exception ex) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
@ -139,10 +127,10 @@ public class DmpProfiles {
@Transactional @Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/dmpprofile/create" }, consumes = "application/json", produces="application/json") @RequestMapping(method = RequestMethod.POST, value = { "/dmpprofile/create" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> setDmpProfile(@RequestBody DMPProfile dmpprofile) { public @ResponseBody ResponseEntity<Object> setDmpProfile(@RequestBody DMPProfile dmpprofile) {
DMPProfile createdDMPProfile = dMPProfileDao.update(dmpprofile);
try { try {
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdDMPProfile)); DMPProfile createdDMPProfile = dMPProfileDao.update(dmpprofile);
} catch (JsonProcessingException e) { return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(createdDMPProfile));
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create DMP Profile!\"}"); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create DMP Profile!\"}");
} }
} }

View File

@ -70,7 +70,6 @@ public class Organisations {
@Autowired private ServiceDao serviceDao; @Autowired private ServiceDao serviceDao;
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
// MANAGE ORGANISATIONS(S) // MANAGE ORGANISATIONS(S)
@ -78,7 +77,7 @@ public class Organisations {
public @ResponseBody ResponseEntity<Object> listOrganisations(){ public @ResponseBody ResponseEntity<Object> listOrganisations(){
try { try {
List<UUID> allIDs = organisationDao.listAllIDs(); List<UUID> allIDs = organisationDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs)); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
} }
catch(Exception ex) { catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
@ -90,7 +89,7 @@ public class Organisations {
public @ResponseBody ResponseEntity<Object> getOrganisations(@PathVariable("id") String id) { public @ResponseBody ResponseEntity<Object> getOrganisations(@PathVariable("id") String id) {
try { try {
Organisation organisation = organisationDao.read(UUID.fromString(id)); Organisation organisation = organisationDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(organisation)); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(organisation));
} }
catch(Exception ex) { catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
@ -102,18 +101,7 @@ public class Organisations {
public @ResponseBody ResponseEntity<Object> getAllOrganisations(){ public @ResponseBody ResponseEntity<Object> getAllOrganisations(){
try { try {
List<Organisation> allOrganisations = organisationDao.getAll(); List<Organisation> allOrganisations = organisationDao.getAll();
return new ResponseEntity<Object>(SerializerProvider.toJson(allOrganisations), HttpStatus.OK);
//sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom
List<String> organisationStrL = allOrganisations.parallelStream().map((organisationObj) -> {
try {
return objectMapper.writeValueAsString(organisationObj);
} catch (JsonProcessingException e) {
return "";
}
}).collect(Collectors.toList());
return new ResponseEntity<Object>("["+String.join(",", organisationStrL)+"]", HttpStatus.OK);
} }
catch(Exception ex) { catch(Exception ex) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
@ -124,10 +112,10 @@ public class Organisations {
@Transactional @Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/organisation/create" }, consumes = "application/json", produces="application/json") @RequestMapping(method = RequestMethod.POST, value = { "/organisation/create" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> setOrganisation(@RequestBody Organisation organisation) { public @ResponseBody ResponseEntity<Object> setOrganisation(@RequestBody Organisation organisation) {
Organisation createdOrganisation = organisationDao.update(organisation);
try { try {
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdOrganisation)); Organisation createdOrganisation = organisationDao.update(organisation);
} catch (JsonProcessingException e) { return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(createdOrganisation));
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create organisation!\"}"); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create organisation!\"}");
} }
} }

View File

@ -1,7 +1,9 @@
package rest.entities; package rest.entities;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -80,15 +82,13 @@ public class Projects {
@Autowired private UserInfoDao userInfoDao; @Autowired private UserInfoDao userInfoDao;
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
// MANAGE PROJECT(S) // MANAGE PROJECT(S)
@RequestMapping(method = RequestMethod.GET, value = { "/projects" }, produces="application/json") @RequestMapping(method = RequestMethod.GET, value = { "/projects" }, produces="application/json")
public @ResponseBody ResponseEntity<Object> listProjects(){ public @ResponseBody ResponseEntity<Object> listProjects(){
try { try {
List<UUID> allIDs = projectDao.listAllIDs(); List<UUID> allIDs = projectDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(allIDs); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
} }
catch(Exception ex) { catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
@ -102,7 +102,7 @@ public class Projects {
System.out.println(project.getId().toString()); System.out.println(project.getId().toString());
return ResponseEntity.status(HttpStatus.OK).body(project); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(project));
} }
catch(Exception ex) { catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
@ -126,18 +126,7 @@ public class Projects {
public @ResponseBody ResponseEntity<Object> getAllProjects(){ public @ResponseBody ResponseEntity<Object> getAllProjects(){
try { try {
List<Project> allProjects = projectDao.getAll(); List<Project> allProjects = projectDao.getAll();
return new ResponseEntity<Object>(SerializerProvider.toJson(allProjects), HttpStatus.OK);
//sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom
List<String> projectStrL = allProjects.parallelStream().map((projectObj) -> {
try {
return objectMapper.writeValueAsString(projectObj);
} catch (JsonProcessingException e) {
return "";
}
}).collect(Collectors.toList());
return new ResponseEntity<Object>("["+String.join(",", projectStrL)+"]", HttpStatus.OK);
} }
catch(Exception ex) { catch(Exception ex) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
@ -175,8 +164,8 @@ public class Projects {
public @ResponseBody ResponseEntity<Object> getProjectDmps(@RequestBody Project project) { public @ResponseBody ResponseEntity<Object> getProjectDmps(@RequestBody Project project) {
try { try {
Set<DMP> dmps = projectDao.read(project.getId()).getDmps(); Set<DMP> dmps = projectDao.read(project.getId()).getDmps();
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(dmps)); return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(dmps));
} catch (JsonProcessingException e) { } catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create Project!\"}"); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create Project!\"}");
} }
} }
@ -200,11 +189,19 @@ public class Projects {
UserInfo userInfo = userInfoDao.read(UUID.fromString(userID)); UserInfo userInfo = userInfoDao.read(UUID.fromString(userID));
if(userInfo==null) //this should normally never happer if(userInfo==null) //this should normally never happen
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("There's no such a user on the system. You shouldn't be here"); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("There's no such a user on the system. You shouldn't be here");
Map<UUID, Project> userProjects = new HashMap<UUID, Project>();
userInfo.getDmps().forEach( dmp -> {
Project proj = dmp.getProject();
userProjects.put(proj.getId(), proj);
});
try { try {
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(userInfo.getProjects())); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(userProjects.values()));
} }
catch(Exception ex) { catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
@ -236,16 +233,19 @@ public class Projects {
Project newproj = projectDao.create(project); Project newproj = projectDao.create(project);
Set<Project> userProjects = userInfo.getProjects(); DMP newdmp = new DMP();
if(userProjects==null) newdmp.setId(null);
userProjects = new HashSet<Project>(); newdmp.setLabel("Auto-Generated");
userProjects.add(newproj); newdmp.setVersion(1);
newdmp.setProject(newproj);
userInfo.setProjects(userProjects); Set<UserInfo> users = new HashSet<UserInfo>();
users.add(userInfo);
newdmp.setUsers(users);
userInfo = userInfoDao.update(userInfo); newdmp = dMPDao.create(newdmp);
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(userInfo)); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(newproj));
} }
catch(Exception ex) { catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
@ -253,15 +253,15 @@ public class Projects {
} }
@Transactional // @Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/project/updateofuser" }, produces="text/plain") // @RequestMapping(method = RequestMethod.POST, value = { "/project/updateofuser" }, produces="text/plain")
public @ResponseBody ResponseEntity<Object> updateProjectOfUser(@RequestBody Project project){ // public @ResponseBody ResponseEntity<Object> updateProjectOfUser(@RequestBody Project project){
//
if(project.getId()==null) // if(project.getId()==null)
return ResponseEntity.status(HttpStatus.NOT_MODIFIED).body("Cannot update, id was null"); // return ResponseEntity.status(HttpStatus.NOT_MODIFIED).body("Cannot update, id was null");
return setProject(project); // return setProject(project);
//
} // }

View File

@ -70,15 +70,13 @@ public class Registries {
@Autowired private ServiceDao serviceDao; @Autowired private ServiceDao serviceDao;
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
// MANAGE REGISTRY(IES) // MANAGE REGISTRY(IES)
@RequestMapping(method = RequestMethod.GET, value = { "/registries" }) @RequestMapping(method = RequestMethod.GET, value = { "/registries" })
public @ResponseBody ResponseEntity<Object> listRegistries(){ public @ResponseBody ResponseEntity<Object> listRegistries(){
try { try {
List<UUID> allIDs = registryDao.listAllIDs(); List<UUID> allIDs = registryDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs)); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
} }
catch(Exception ex) { catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
@ -90,7 +88,7 @@ public class Registries {
public @ResponseBody ResponseEntity<Object> getRegistries(@PathVariable("id") String id) { public @ResponseBody ResponseEntity<Object> getRegistries(@PathVariable("id") String id) {
try { try {
Registry registry = registryDao.read(UUID.fromString(id)); Registry registry = registryDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(registry)); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(registry));
} }
catch(Exception ex) { catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
@ -103,7 +101,7 @@ public class Registries {
public @ResponseBody ResponseEntity<Object> listLabelIds(){ public @ResponseBody ResponseEntity<Object> listLabelIds(){
try { try {
List<IDLabelPair> allIDs = registryDao.listAllIDsLabels(); List<IDLabelPair> allIDs = registryDao.listAllIDsLabels();
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs)); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
} }
catch(Exception ex) { catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
@ -116,16 +114,7 @@ public class Registries {
try { try {
List<Registry> allRegistries = registryDao.getAll(); List<Registry> allRegistries = registryDao.getAll();
//sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom return new ResponseEntity<Object>(SerializerProvider.toJson(allRegistries), HttpStatus.OK);
List<String> registryStrL = allRegistries.parallelStream().map((registryObj) -> {
try {
return objectMapper.writeValueAsString(registryObj);
} catch (JsonProcessingException e) {
return "";
}
}).collect(Collectors.toList());
return new ResponseEntity<Object>("["+String.join(",", registryStrL)+"]", HttpStatus.OK);
} }
catch(Exception ex) { catch(Exception ex) {
@ -139,8 +128,8 @@ public class Registries {
public @ResponseBody ResponseEntity<Object> setRegistry(@RequestBody Registry registry) { public @ResponseBody ResponseEntity<Object> setRegistry(@RequestBody Registry registry) {
Registry createdRegistry = registryDao.update(registry); Registry createdRegistry = registryDao.update(registry);
try { try {
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdRegistry)); return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(createdRegistry));
} catch (JsonProcessingException e) { } catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create registry!\"}"); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create registry!\"}");
} }
} }

View File

@ -70,15 +70,13 @@ public class Researchers {
@Autowired private ServiceDao serviceDao; @Autowired private ServiceDao serviceDao;
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
// MANAGE RESEARCHER(S) // MANAGE RESEARCHER(S)
@RequestMapping(method = RequestMethod.GET, value = { "/researchers" }) @RequestMapping(method = RequestMethod.GET, value = { "/researchers" })
public @ResponseBody ResponseEntity<Object> listResearchers(){ public @ResponseBody ResponseEntity<Object> listResearchers(){
try { try {
List<UUID> allIDs = researcherDao.listAllIDs(); List<UUID> allIDs = researcherDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs)); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
} }
catch(Exception ex) { catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
@ -90,7 +88,7 @@ public class Researchers {
public @ResponseBody ResponseEntity<Object> getResearchers(@PathVariable("id") String id) { public @ResponseBody ResponseEntity<Object> getResearchers(@PathVariable("id") String id) {
try { try {
Researcher researcher = researcherDao.read(UUID.fromString(id)); Researcher researcher = researcherDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(researcher)); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(researcher));
} }
catch(Exception ex) { catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
@ -101,7 +99,7 @@ public class Researchers {
public @ResponseBody ResponseEntity<Object> getResearcherByEmail(@RequestParam("email") String email){ public @ResponseBody ResponseEntity<Object> getResearcherByEmail(@RequestParam("email") String email){
try { try {
Researcher researcher = researcherDao.getResearcherByEmail(email); Researcher researcher = researcherDao.getResearcherByEmail(email);
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(researcher)); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(researcher));
} }
catch(Exception ex) { catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
@ -115,16 +113,7 @@ public class Researchers {
try { try {
List<Researcher> allResearchers = researcherDao.getAll(); List<Researcher> allResearchers = researcherDao.getAll();
//sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom return new ResponseEntity<Object>(SerializerProvider.toJson(allResearchers), HttpStatus.OK);
List<String> researcherStrL = allResearchers.parallelStream().map((researcherObj) -> {
try {
return objectMapper.writeValueAsString(researcherObj);
} catch (JsonProcessingException e) {
return "";
}
}).collect(Collectors.toList());
return new ResponseEntity<Object>("["+String.join(",", researcherStrL)+"]", HttpStatus.OK);
} }
catch(Exception ex) { catch(Exception ex) {
@ -138,8 +127,8 @@ public class Researchers {
public @ResponseBody ResponseEntity<Object> setResearcher(@RequestBody Researcher researcher) { public @ResponseBody ResponseEntity<Object> setResearcher(@RequestBody Researcher researcher) {
Researcher createdResearcher = researcherDao.update(researcher); Researcher createdResearcher = researcherDao.update(researcher);
try { try {
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdResearcher)); return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(createdResearcher));
} catch (JsonProcessingException e) { } catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create researcher!\"}"); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create researcher!\"}");
} }
} }

View File

@ -71,9 +71,6 @@ public class Services {
@Autowired private ServiceDao serviceDao; @Autowired private ServiceDao serviceDao;
private ObjectMapper objectMapper =
SerializerProvider.getJsonSerializer();
// new ObjectMapper();
// MANAGE SERVICE(S) // MANAGE SERVICE(S)
@ -81,7 +78,7 @@ public class Services {
public @ResponseBody ResponseEntity<Object> listServices(){ public @ResponseBody ResponseEntity<Object> listServices(){
try { try {
List<UUID> allIDs = serviceDao.listAllIDs(); List<UUID> allIDs = serviceDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs)); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
} }
catch(Exception ex) { catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
@ -93,7 +90,7 @@ public class Services {
public @ResponseBody ResponseEntity<Object> getServices(@PathVariable("id") String id) { public @ResponseBody ResponseEntity<Object> getServices(@PathVariable("id") String id) {
try { try {
Service service = serviceDao.read(UUID.fromString(id)); Service service = serviceDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(service)); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(service));
} }
catch(Exception ex) { catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
@ -107,16 +104,7 @@ public class Services {
try { try {
List<Service> allServices = serviceDao.getAll(); List<Service> allServices = serviceDao.getAll();
//sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom return new ResponseEntity<Object>(SerializerProvider.toJson(allServices), HttpStatus.OK);
List<String> serviceStrL = allServices.parallelStream().map((serviceObj) -> {
try {
return objectMapper.writeValueAsString(serviceObj);
} catch (JsonProcessingException e) {
return "";
}
}).collect(Collectors.toList());
return new ResponseEntity<Object>("["+String.join(",", serviceStrL)+"]", HttpStatus.OK);
} }
catch(Exception ex) { catch(Exception ex) {
@ -127,20 +115,12 @@ public class Services {
@Transactional @Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/service/create" }, consumes = "application/json", produces="application/json") @RequestMapping(method = RequestMethod.POST, value = { "/service/create" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> setService(@RequestBody String serviceSTR) { public @ResponseBody ResponseEntity<Object> setService(@RequestBody Service service) {
System.out.println(serviceSTR);
Service service = null;
try {
service = objectMapper.readValue(serviceSTR, Service.class);
} catch (IOException e1) {
e1.printStackTrace();
}
Service createdService = serviceDao.update(service); Service createdService = serviceDao.update(service);
try { try {
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdService)); return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(createdService));
} catch (JsonProcessingException e) { } catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create service entity!\"}"); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create service entity!\"}");
} }
} }

View File

@ -70,11 +70,6 @@ public class Users {
@Autowired private ServiceDao serviceDao; @Autowired private ServiceDao serviceDao;
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();

View File

@ -74,6 +74,8 @@ public class TokenSessionManager {
return sb.toString(); return sb.toString();
} }
// public static void main(String [] args) throws NoSuchAlgorithmException {
// System.out.println(TokenSessionManager.getInstance().hashPassword("apa$$2gu3$$"));
// }
} }

View File

@ -64,7 +64,7 @@ public class TestRest {
Gson gson = new Gson(); Gson gson = new Gson();
private static String userID = "0f51f686-a2ce-47c1-9433-00736787aa88"; private static String userID = "332ffc36-bd51-4d4e-bf9a-ffb01fdee05a";
private ApplicationContext context; private ApplicationContext context;
@ -159,12 +159,30 @@ public class TestRest {
// @Test // @Test
public void testProject() { public void testProject() {
System.out.println(projectsService.listProjects().getBody()); // System.out.println(projectsService.listProjects().getBody());
System.out.println(dmpsService.listDMPs().getBody()); // System.out.println(dmpsService.listDMPs().getBody());
System.out.println(projectsService.getProjectsOfUser().getBody());
assertEquals("aaa", "aaa");
}
@Test
public void testDmpUser() {
System.out.println(dmpsService.getDmpsOfUser().getBody());
// System.out.println(projectsService.listProjects().getBody());
// System.out.println(dmpsService.listDMPs().getBody());
assertEquals("aaa", "aaa"); assertEquals("aaa", "aaa");
} }
} }