MOstly annotations and minor changes on rest api
This commit is contained in:
parent
3c2c9ea5bd
commit
52ce365123
|
@ -92,6 +92,23 @@ 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;
|
||||
}
|
||||
|
|
|
@ -69,23 +69,6 @@ public class Project implements Serializable {
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -19,9 +19,9 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
|||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
|
||||
@Entity
|
||||
@Table(name="\"UserProject\"")
|
||||
@Table(name="\"UserDMP\"")
|
||||
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
|
||||
public class UserProject implements Serializable{
|
||||
public class UserDMP implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = -4467370784003784660L;
|
||||
|
||||
|
@ -36,8 +36,8 @@ public class UserProject implements Serializable{
|
|||
private UUID usr;
|
||||
|
||||
@Type(type="org.hibernate.type.PostgresUUIDType") //DEPWARN dependency to Hibernate and PostgreSQL
|
||||
@Column(name = "project", nullable = false)
|
||||
private UUID project;
|
||||
@Column(name = "dmp", nullable = false)
|
||||
private UUID dmp;
|
||||
|
||||
@Column(name = "role")
|
||||
private Integer role;
|
||||
|
@ -59,12 +59,12 @@ public class UserProject implements Serializable{
|
|||
this.usr = usr;
|
||||
}
|
||||
|
||||
public UUID getProject() {
|
||||
return project;
|
||||
public UUID getDmp() {
|
||||
return dmp;
|
||||
}
|
||||
|
||||
public void setProject(UUID project) {
|
||||
this.project = project;
|
||||
public void setDmp(UUID dmp) {
|
||||
this.dmp = dmp;
|
||||
}
|
||||
|
||||
public Integer getRole() {
|
|
@ -77,22 +77,21 @@ public class UserInfo implements Serializable{
|
|||
private String additionalinfo;
|
||||
|
||||
@OneToMany(fetch = FetchType.LAZY)
|
||||
@JoinTable(name="\"UserProject\"",
|
||||
@JoinTable(name="\"UserDMP\"",
|
||||
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() {
|
||||
return projects;
|
||||
public Set<DMP> getDmps() {
|
||||
return dmps;
|
||||
}
|
||||
|
||||
public void setProjects(Set<Project> projects) {
|
||||
this.projects = projects;
|
||||
public void setDmps(Set<DMP> dmps) {
|
||||
this.dmps = dmps;
|
||||
}
|
||||
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
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.datatype.hibernate5.Hibernate5Module;
|
||||
import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module.Feature;
|
||||
|
@ -12,7 +19,11 @@ public class SerializerProvider {
|
|||
|
||||
|
||||
static {
|
||||
initialize();
|
||||
}
|
||||
|
||||
|
||||
public static void initialize() {
|
||||
Hibernate5Module module = new Hibernate5Module();
|
||||
module.enable(Feature.SERIALIZE_IDENTIFIER_FOR_LAZY_NOT_LOADED_OBJECTS);
|
||||
objectMapper = new ObjectMapper()
|
||||
|
@ -20,12 +31,26 @@ public class SerializerProvider {
|
|||
// .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||
.registerModule(new Hibernate5Module())
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
public static ObjectMapper getJsonSerializer() {
|
||||
if(objectMapper==null)
|
||||
initialize();
|
||||
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(), ",")+"]";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package rest.entities;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -72,8 +74,6 @@ public class DMPs {
|
|||
@Autowired private UserInfoDao userInfoDao;
|
||||
|
||||
|
||||
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
|
||||
|
||||
|
||||
// FETCH BY DMP(S)
|
||||
|
||||
|
@ -81,9 +81,10 @@ public class DMPs {
|
|||
public @ResponseBody ResponseEntity<Object> listDMPs(){
|
||||
try {
|
||||
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) {
|
||||
ex.printStackTrace();
|
||||
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){
|
||||
try {
|
||||
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) {
|
||||
ex.printStackTrace();
|
||||
|
@ -104,9 +105,10 @@ public class DMPs {
|
|||
public @ResponseBody ResponseEntity<Object> listDmpLabelID(){
|
||||
try {
|
||||
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) {
|
||||
ex.printStackTrace();
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -120,18 +122,7 @@ public class DMPs {
|
|||
|
||||
try {
|
||||
List<DMP> allDMPs = dMPDao.getAll();
|
||||
|
||||
//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);
|
||||
|
||||
return new ResponseEntity<Object>(SerializerProvider.toJson(allDMPs), HttpStatus.OK);
|
||||
}
|
||||
catch(Exception ex) {
|
||||
ex.printStackTrace();
|
||||
|
@ -143,10 +134,11 @@ public class DMPs {
|
|||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/create" }, consumes = "application/json", produces="application/json")
|
||||
public @ResponseBody ResponseEntity<Object> createDMP(@RequestBody DMP dmp) {
|
||||
DMP createdDmp = dMPDao.update(dmp);
|
||||
try {
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdDmp));
|
||||
} catch (JsonProcessingException e) {
|
||||
DMP createdDmp = dMPDao.update(dmp);
|
||||
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!\"");
|
||||
}
|
||||
|
||||
|
@ -155,10 +147,11 @@ 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) {
|
||||
DMP updatedDMP = dMPDao.update(dmp);
|
||||
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!\"");
|
||||
}
|
||||
|
||||
|
@ -256,10 +249,10 @@ public class DMPs {
|
|||
|
||||
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/getdatasets" }, consumes = "application/json", produces="application/json")
|
||||
public @ResponseBody ResponseEntity<Object> getDatasetsOfDMP(@RequestBody DMP dmp) {
|
||||
Set<Dataset> datasets = dMPDao.read(dmp.getId()).getDataset();
|
||||
try {
|
||||
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(datasets));
|
||||
} catch (JsonProcessingException e) {
|
||||
Set<Dataset> datasets = dMPDao.read(dmp.getId()).getDataset();
|
||||
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!\"");
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
|
||||
try {
|
||||
Set<DMP> userDMPs = new HashSet<DMP>();
|
||||
|
||||
userInfo.getProjects().forEach(project -> {
|
||||
userDMPs.addAll(project.getDmps());
|
||||
});
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(userDMPs));
|
||||
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(userInfo.getDmps()));
|
||||
}
|
||||
catch(Exception ex) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
||||
|
@ -319,33 +306,72 @@ public class DMPs {
|
|||
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = { "/dmp/createforproject" }, produces="text/plain")
|
||||
public @ResponseBody ResponseEntity<Object> createDmpOfProject(@RequestParam("projectid") String projectid, @RequestBody DMP dmp){
|
||||
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/createofuser" }, produces="text/plain")
|
||||
public @ResponseBody ResponseEntity<Object> createDmpOfUser(@RequestBody DMP dmp){
|
||||
|
||||
UUID projIdUuid;
|
||||
|
||||
String userID = null;
|
||||
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");
|
||||
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 {
|
||||
|
||||
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();
|
||||
if(dmps == null)
|
||||
dmps = new HashSet<DMP>();
|
||||
dmps.add(dmp);
|
||||
project.setDmps(dmps);
|
||||
DMP newdmp = dMPDao.create(dmp);
|
||||
|
||||
project = projectDao.update(project);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(newdmp));
|
||||
}
|
||||
catch(Exception ex) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
||||
}
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(dmp));
|
||||
}
|
||||
|
||||
|
||||
@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());
|
||||
|
@ -356,7 +382,5 @@ public class DMPs {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -69,16 +69,13 @@ public class DataRepositories {
|
|||
@Autowired private ResearcherDao researcherDao;
|
||||
@Autowired private ServiceDao serviceDao;
|
||||
|
||||
|
||||
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
|
||||
|
||||
// MANAGE DATAREPOSITORy(IES)
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = { "/datarepos" })
|
||||
public @ResponseBody ResponseEntity<Object> listDataRepositories(){
|
||||
try {
|
||||
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) {
|
||||
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) {
|
||||
try {
|
||||
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) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
|
||||
|
@ -105,16 +102,7 @@ public class DataRepositories {
|
|||
try {
|
||||
List<DataRepository> allDataRepositories = dataRepositoryDao.getAll();
|
||||
|
||||
//sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom
|
||||
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);
|
||||
return new ResponseEntity<Object>(SerializerProvider.toJson(allDataRepositories), HttpStatus.OK);
|
||||
|
||||
}
|
||||
catch(Exception ex) {
|
||||
|
@ -130,8 +118,8 @@ public class DataRepositories {
|
|||
public @ResponseBody ResponseEntity<Object> setOrganisation(@RequestBody DataRepository dataRepository) {
|
||||
DataRepository createdDataRepository = dataRepositoryDao.update(dataRepository);
|
||||
try {
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdDataRepository));
|
||||
} catch (JsonProcessingException e) {
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(createdDataRepository));
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create data repository!\"}");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,8 +72,6 @@ public class DatasetProfiles {
|
|||
@Autowired private ResearcherDao researcherDao;
|
||||
@Autowired private ServiceDao serviceDao;
|
||||
|
||||
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
|
||||
|
||||
|
||||
//FETCH BY DATASET PROFILE
|
||||
|
||||
|
@ -81,7 +79,7 @@ public class DatasetProfiles {
|
|||
public @ResponseBody ResponseEntity<Object> listDMPs(){
|
||||
try {
|
||||
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) {
|
||||
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) {
|
||||
try {
|
||||
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) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
|
||||
|
@ -105,18 +103,7 @@ public class DatasetProfiles {
|
|||
|
||||
try {
|
||||
List<DatasetProfile> allDatasetProfiles = datasetProfileDao.getAll();
|
||||
|
||||
//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);
|
||||
return new ResponseEntity<Object>(SerializerProvider.toJson(allDatasetProfiles), HttpStatus.OK);
|
||||
}
|
||||
catch(Exception ex) {
|
||||
ex.printStackTrace();
|
||||
|
@ -149,17 +136,11 @@ public class DatasetProfiles {
|
|||
datasetProfile.setViewstyle(datasetprofileviewstyle);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
if(datasetProfile.getId()==null)
|
||||
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!\"}");
|
||||
}
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(datasetProfile));
|
||||
|
||||
}
|
||||
|
||||
|
@ -185,17 +166,11 @@ public class DatasetProfiles {
|
|||
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!\"}");
|
||||
}
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(datasetProfile));
|
||||
|
||||
}
|
||||
|
||||
|
@ -213,7 +188,7 @@ public class DatasetProfiles {
|
|||
if(datasetprofileviewstyle != null)
|
||||
datasetProfileViewstyleDao.delete(datasetprofileviewstyle);
|
||||
datasetProfileDao.delete(datasetProfile);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(datasetProfile));
|
||||
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(datasetProfile));
|
||||
}
|
||||
catch(Exception ex) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not delete dataset profile!\"}");
|
||||
|
|
|
@ -72,7 +72,6 @@ public class Datasets {
|
|||
@Autowired private ResearcherDao researcherDao;
|
||||
@Autowired private ServiceDao serviceDao;
|
||||
|
||||
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
|
||||
|
||||
// FETCH BY DATASET(S)
|
||||
|
||||
|
@ -81,7 +80,7 @@ public class Datasets {
|
|||
public @ResponseBody ResponseEntity<Object> listDatasets(){
|
||||
try {
|
||||
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) {
|
||||
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) {
|
||||
try {
|
||||
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) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
|
||||
|
@ -109,19 +108,7 @@ public class Datasets {
|
|||
|
||||
try {
|
||||
List<Dataset> allDatasets = datasetDao.getAll();
|
||||
|
||||
|
||||
//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);
|
||||
return new ResponseEntity<Object>(SerializerProvider.toJson(allDatasets), HttpStatus.OK);
|
||||
}
|
||||
catch(Exception ex) {
|
||||
ex.printStackTrace();
|
||||
|
@ -137,7 +124,7 @@ public class Datasets {
|
|||
dataset.setId(null);
|
||||
try {
|
||||
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) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Could not create or update Dataset! Reason: " + e.getMessage());
|
||||
|
|
|
@ -70,7 +70,6 @@ public class DmpProfiles {
|
|||
@Autowired private ResearcherDao researcherDao;
|
||||
@Autowired private ServiceDao serviceDao;
|
||||
|
||||
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
|
||||
|
||||
// MANAGE DMPPROFILE(S)
|
||||
|
||||
|
@ -78,7 +77,7 @@ public class DmpProfiles {
|
|||
public @ResponseBody ResponseEntity<Object> listDmpProfiles(){
|
||||
try {
|
||||
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) {
|
||||
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) {
|
||||
try {
|
||||
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) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
|
||||
|
@ -105,7 +104,7 @@ public class DmpProfiles {
|
|||
public @ResponseBody ResponseEntity<Object> listLabelIds(){
|
||||
try {
|
||||
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) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
||||
|
@ -117,18 +116,7 @@ public class DmpProfiles {
|
|||
public @ResponseBody ResponseEntity<Object> getAllDmpProfiles(){
|
||||
try {
|
||||
List<DMPProfile> allDmpProfiles = dMPProfileDao.getAll();
|
||||
|
||||
//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);
|
||||
|
||||
return new ResponseEntity<Object>(SerializerProvider.toJson(allDmpProfiles), HttpStatus.OK);
|
||||
}
|
||||
catch(Exception ex) {
|
||||
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
|
@ -139,10 +127,10 @@ public class DmpProfiles {
|
|||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.POST, value = { "/dmpprofile/create" }, consumes = "application/json", produces="application/json")
|
||||
public @ResponseBody ResponseEntity<Object> setDmpProfile(@RequestBody DMPProfile dmpprofile) {
|
||||
DMPProfile createdDMPProfile = dMPProfileDao.update(dmpprofile);
|
||||
try {
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdDMPProfile));
|
||||
} catch (JsonProcessingException e) {
|
||||
DMPProfile createdDMPProfile = dMPProfileDao.update(dmpprofile);
|
||||
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!\"}");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,7 +70,6 @@ public class Organisations {
|
|||
@Autowired private ServiceDao serviceDao;
|
||||
|
||||
|
||||
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
|
||||
|
||||
// MANAGE ORGANISATIONS(S)
|
||||
|
||||
|
@ -78,7 +77,7 @@ public class Organisations {
|
|||
public @ResponseBody ResponseEntity<Object> listOrganisations(){
|
||||
try {
|
||||
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) {
|
||||
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) {
|
||||
try {
|
||||
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) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
|
||||
|
@ -102,18 +101,7 @@ public class Organisations {
|
|||
public @ResponseBody ResponseEntity<Object> getAllOrganisations(){
|
||||
try {
|
||||
List<Organisation> allOrganisations = organisationDao.getAll();
|
||||
|
||||
//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);
|
||||
|
||||
return new ResponseEntity<Object>(SerializerProvider.toJson(allOrganisations), HttpStatus.OK);
|
||||
}
|
||||
catch(Exception ex) {
|
||||
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
|
@ -124,10 +112,10 @@ public class Organisations {
|
|||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.POST, value = { "/organisation/create" }, consumes = "application/json", produces="application/json")
|
||||
public @ResponseBody ResponseEntity<Object> setOrganisation(@RequestBody Organisation organisation) {
|
||||
Organisation createdOrganisation = organisationDao.update(organisation);
|
||||
try {
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdOrganisation));
|
||||
} catch (JsonProcessingException e) {
|
||||
Organisation createdOrganisation = organisationDao.update(organisation);
|
||||
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!\"}");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package rest.entities;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -80,15 +82,13 @@ public class Projects {
|
|||
@Autowired private UserInfoDao userInfoDao;
|
||||
|
||||
|
||||
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
|
||||
|
||||
// MANAGE PROJECT(S)
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = { "/projects" }, produces="application/json")
|
||||
public @ResponseBody ResponseEntity<Object> listProjects(){
|
||||
try {
|
||||
List<UUID> allIDs = projectDao.listAllIDs();
|
||||
return ResponseEntity.status(HttpStatus.OK).body(allIDs);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
|
||||
}
|
||||
catch(Exception ex) {
|
||||
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());
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(project);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(project));
|
||||
}
|
||||
catch(Exception ex) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
|
||||
|
@ -126,18 +126,7 @@ public class Projects {
|
|||
public @ResponseBody ResponseEntity<Object> getAllProjects(){
|
||||
try {
|
||||
List<Project> allProjects = projectDao.getAll();
|
||||
|
||||
//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);
|
||||
|
||||
return new ResponseEntity<Object>(SerializerProvider.toJson(allProjects), HttpStatus.OK);
|
||||
}
|
||||
catch(Exception ex) {
|
||||
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
|
@ -175,8 +164,8 @@ public class Projects {
|
|||
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.CREATED).body(SerializerProvider.toJson(dmps));
|
||||
} catch (Exception e) {
|
||||
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));
|
||||
|
||||
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");
|
||||
|
||||
|
||||
Map<UUID, Project> userProjects = new HashMap<UUID, Project>();
|
||||
|
||||
userInfo.getDmps().forEach( dmp -> {
|
||||
Project proj = dmp.getProject();
|
||||
userProjects.put(proj.getId(), proj);
|
||||
});
|
||||
|
||||
try {
|
||||
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(userInfo.getProjects()));
|
||||
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(userProjects.values()));
|
||||
}
|
||||
catch(Exception ex) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
||||
|
@ -236,16 +233,19 @@ public class Projects {
|
|||
|
||||
Project newproj = projectDao.create(project);
|
||||
|
||||
Set<Project> userProjects = userInfo.getProjects();
|
||||
if(userProjects==null)
|
||||
userProjects = new HashSet<Project>();
|
||||
userProjects.add(newproj);
|
||||
DMP newdmp = new DMP();
|
||||
newdmp.setId(null);
|
||||
newdmp.setLabel("Auto-Generated");
|
||||
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(newdmp));
|
||||
}
|
||||
catch(Exception ex) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
||||
|
@ -253,15 +253,15 @@ public class Projects {
|
|||
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
}
|
||||
// @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);
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -70,15 +70,13 @@ public class Registries {
|
|||
@Autowired private ServiceDao serviceDao;
|
||||
|
||||
|
||||
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
|
||||
|
||||
// MANAGE REGISTRY(IES)
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = { "/registries" })
|
||||
public @ResponseBody ResponseEntity<Object> listRegistries(){
|
||||
try {
|
||||
List<UUID> allIDs = registryDao.listAllIDs();
|
||||
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs));
|
||||
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
|
||||
}
|
||||
catch(Exception ex) {
|
||||
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) {
|
||||
try {
|
||||
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) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
|
||||
|
@ -103,7 +101,7 @@ public class Registries {
|
|||
public @ResponseBody ResponseEntity<Object> listLabelIds(){
|
||||
try {
|
||||
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) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
||||
|
@ -116,16 +114,7 @@ public class Registries {
|
|||
try {
|
||||
List<Registry> allRegistries = registryDao.getAll();
|
||||
|
||||
//sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom
|
||||
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);
|
||||
return new ResponseEntity<Object>(SerializerProvider.toJson(allRegistries), HttpStatus.OK);
|
||||
|
||||
}
|
||||
catch(Exception ex) {
|
||||
|
@ -139,8 +128,8 @@ public class Registries {
|
|||
public @ResponseBody ResponseEntity<Object> setRegistry(@RequestBody Registry registry) {
|
||||
Registry createdRegistry = registryDao.update(registry);
|
||||
try {
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdRegistry));
|
||||
} catch (JsonProcessingException e) {
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(createdRegistry));
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create registry!\"}");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,15 +70,13 @@ public class Researchers {
|
|||
@Autowired private ServiceDao serviceDao;
|
||||
|
||||
|
||||
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
|
||||
|
||||
// MANAGE RESEARCHER(S)
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = { "/researchers" })
|
||||
public @ResponseBody ResponseEntity<Object> listResearchers(){
|
||||
try {
|
||||
List<UUID> allIDs = researcherDao.listAllIDs();
|
||||
return ResponseEntity.status(HttpStatus.OK).body(objectMapper.writeValueAsString(allIDs));
|
||||
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
|
||||
}
|
||||
catch(Exception ex) {
|
||||
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) {
|
||||
try {
|
||||
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) {
|
||||
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){
|
||||
try {
|
||||
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) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
|
||||
|
@ -115,16 +113,7 @@ public class Researchers {
|
|||
try {
|
||||
List<Researcher> allResearchers = researcherDao.getAll();
|
||||
|
||||
//sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom
|
||||
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);
|
||||
return new ResponseEntity<Object>(SerializerProvider.toJson(allResearchers), HttpStatus.OK);
|
||||
|
||||
}
|
||||
catch(Exception ex) {
|
||||
|
@ -138,8 +127,8 @@ public class Researchers {
|
|||
public @ResponseBody ResponseEntity<Object> setResearcher(@RequestBody Researcher researcher) {
|
||||
Researcher createdResearcher = researcherDao.update(researcher);
|
||||
try {
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdResearcher));
|
||||
} catch (JsonProcessingException e) {
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(createdResearcher));
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create researcher!\"}");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,9 +71,6 @@ public class Services {
|
|||
@Autowired private ServiceDao serviceDao;
|
||||
|
||||
|
||||
private ObjectMapper objectMapper =
|
||||
SerializerProvider.getJsonSerializer();
|
||||
// new ObjectMapper();
|
||||
|
||||
// MANAGE SERVICE(S)
|
||||
|
||||
|
@ -81,7 +78,7 @@ public class Services {
|
|||
public @ResponseBody ResponseEntity<Object> listServices(){
|
||||
try {
|
||||
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) {
|
||||
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) {
|
||||
try {
|
||||
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) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
|
||||
|
@ -107,16 +104,7 @@ public class Services {
|
|||
try {
|
||||
List<Service> allServices = serviceDao.getAll();
|
||||
|
||||
//sorry for that, spring-jersey serialisation has issues when performed on tables, so -> custom
|
||||
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);
|
||||
return new ResponseEntity<Object>(SerializerProvider.toJson(allServices), HttpStatus.OK);
|
||||
|
||||
}
|
||||
catch(Exception ex) {
|
||||
|
@ -127,20 +115,12 @@ public class Services {
|
|||
|
||||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.POST, value = { "/service/create" }, consumes = "application/json", produces="application/json")
|
||||
public @ResponseBody ResponseEntity<Object> setService(@RequestBody String serviceSTR) {
|
||||
|
||||
System.out.println(serviceSTR);
|
||||
Service service = null;
|
||||
try {
|
||||
service = objectMapper.readValue(serviceSTR, Service.class);
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
public @ResponseBody ResponseEntity<Object> setService(@RequestBody Service service) {
|
||||
|
||||
Service createdService = serviceDao.update(service);
|
||||
try {
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(objectMapper.writeValueAsString(createdService));
|
||||
} catch (JsonProcessingException e) {
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(createdService));
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create service entity!\"}");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,11 +70,6 @@ public class Users {
|
|||
@Autowired private ServiceDao serviceDao;
|
||||
|
||||
|
||||
private ObjectMapper objectMapper = SerializerProvider.getJsonSerializer();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -74,6 +74,8 @@ public class TokenSessionManager {
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
// public static void main(String [] args) throws NoSuchAlgorithmException {
|
||||
// System.out.println(TokenSessionManager.getInstance().hashPassword("apa$$2gu3$$"));
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ public class TestRest {
|
|||
|
||||
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;
|
||||
|
||||
|
@ -159,12 +159,30 @@ public class TestRest {
|
|||
// @Test
|
||||
public void testProject() {
|
||||
|
||||
System.out.println(projectsService.listProjects().getBody());
|
||||
System.out.println(dmpsService.listDMPs().getBody());
|
||||
// System.out.println(projectsService.listProjects().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");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue