Minor edits

This commit is contained in:
Nikolaos Laskaris 2017-11-27 16:08:13 +02:00
parent 06272c79da
commit 9941c96dc2
12 changed files with 105 additions and 40 deletions

View File

@ -20,7 +20,7 @@ import entities.Service;
public class Transformers {
/*
public static DMP createDMPfromMap(MultiValueMap<String,String> formData) {
DatasetProfileRuleset dpr = new DatasetProfileRuleset();
@ -89,7 +89,7 @@ public class Transformers {
dmp.setLabel(formData.getFirst("DMP.label"));
try {
dmp.setPrevious(UUID.fromString(formData.getFirst("DMP.previous")));
}catch(Exception ex) {/*do nothing*/}
}catch(Exception ex) {}
dmp.setProfile(profile);
dmp.setProfileData(formData.getFirst("DMP.profileData"));
dmp.setProject(project);
@ -102,6 +102,7 @@ public class Transformers {
return dmp;
}
*/
}

View File

@ -92,7 +92,7 @@ public class DMPs {
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/dmps/{id}" }, produces="application/json")
@RequestMapping(method = RequestMethod.GET, value = { "/dmps/{id}" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> getDMP(@PathVariable("id") String id, @RequestParam(value="eager", defaultValue="false") boolean eager){
try {
DMP dmp = dMPDao.read(UUID.fromString(id));
@ -100,6 +100,7 @@ public class DMPs {
dmp.getOrganisations().size(); //used only for lazy load trigger...
dmp.getResearchers().size(); //used only for lazy load trigger...
dmp.getUsers().size(); //used only for lazy load trigger...
dmp.getDataset().size(); //used only for lazy load trigger...
}
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(dmp));
}
@ -109,6 +110,26 @@ public class DMPs {
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/dmp/history/{id}" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> getDMPHistory(@PathVariable("id") String id){
try {
List<DMP> history = new ArrayList<DMP>();
DMP dmp;
dmp = dMPDao.read(UUID.fromString(id));
while(dmp.getPrevious()!=null) {
dmp = dMPDao.read(dmp.getPrevious()); //replace with previous
history.add(dmp);
}
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(history));
}
catch(Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/dmp/listDMPLabelID" }, produces="text/plain")
public @ResponseBody ResponseEntity<Object> listDmpLabelID(){
@ -126,7 +147,7 @@ public class DMPs {
/**
* This should be called on extreme cases. It's computationally intensive
*/
@RequestMapping(method = RequestMethod.GET, value = { "/dmp/getAll" }, produces="application/json")
@RequestMapping(method = RequestMethod.GET, value = { "/dmp/getAll" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> getAllDMPs(){
try {
@ -141,7 +162,7 @@ public class DMPs {
@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;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> createDMP(@RequestBody DMP dmp) {
try {
DMP createdDmp = dMPDao.update(dmp);
@ -154,7 +175,7 @@ public class DMPs {
}
@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;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> updateDMP(@RequestBody DMP dmp) {
DMP previousDmp = dMPDao.read(dmp.getId());
@ -175,7 +196,7 @@ 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;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> getDatasetsOfDMP(@RequestBody DMP dmp) {
try {
List<Dataset> datasets = datasetDao.getDatasetsOfDmp(dmp.getId());

View File

@ -79,7 +79,7 @@ public class DataRepositories {
@RequestMapping(method = RequestMethod.GET, value = { "/external/datarepos" }, produces="application/json")
@RequestMapping(method = RequestMethod.GET, value = { "/external/datarepos" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> listExternalDataRepositories(@RequestParam(value="query", required=false) String query ){
try {
List<Map<String,String>> remoteRepos = remoteFetcher.getRepositories(query);
@ -123,7 +123,7 @@ public class DataRepositories {
@RequestMapping(method = RequestMethod.GET, value = { "/datarepo/getAll" }, produces="application/json")
@RequestMapping(method = RequestMethod.GET, value = { "/datarepo/getAll" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> getAllDataRepositories(){
try {
@ -141,7 +141,7 @@ public class DataRepositories {
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/datarepo/create" }, consumes = "application/json", produces="application/json")
@RequestMapping(method = RequestMethod.POST, value = { "/datarepo/create" }, consumes = "application/json", produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> setOrganisation(@RequestBody DataRepository dataRepository) {
DataRepository createdDataRepository = dataRepositoryDao.update(dataRepository);
try {

View File

@ -111,7 +111,7 @@ public class DatasetProfiles {
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/datasetprofile/create" }, consumes = "application/json", produces="application/json")
@RequestMapping(method = RequestMethod.POST, value = { "/datasetprofile/create" }, consumes = "application/json", produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> createDatasetProfile(@RequestBody DatasetProfile datasetProfile) {
DatasetProfileRuleset datasetprofileruleset = datasetProfile.getRuleset();
@ -143,7 +143,7 @@ public class DatasetProfiles {
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/datasetprofile/update" }, consumes = "application/json", produces="application/json")
@RequestMapping(method = RequestMethod.POST, value = { "/datasetprofile/update" }, consumes = "application/json", produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> updateDatasetProfile(@RequestBody DatasetProfile datasetProfile) {
DatasetProfileRuleset datasetprofileruleset = datasetProfile.getRuleset();
@ -172,7 +172,7 @@ public class DatasetProfiles {
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/datasetprofile/delete" }, consumes = "application/json", produces="application/json")
@RequestMapping(method = RequestMethod.POST, value = { "/datasetprofile/delete" }, consumes = "application/json", produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> deleteDatasetProfile(@RequestBody DatasetProfile datasetProfile) {
DatasetProfileRuleset datasetprofileruleset = datasetProfile.getRuleset();

View File

@ -125,7 +125,7 @@ public class Datasets {
}
@RequestMapping(method = RequestMethod.POST, value = { "/dataset/create" }, consumes = "application/json", produces="application/json")
@RequestMapping(method = RequestMethod.POST, value = { "/dataset/create" }, consumes = "application/json", produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> createDataset(@RequestBody Dataset dataset) {
@ -164,7 +164,7 @@ public class Datasets {
}
@RequestMapping(method = RequestMethod.POST, value = { "/dataset/update" }, consumes = "application/json", produces="application/json")
@RequestMapping(method = RequestMethod.POST, value = { "/dataset/update" }, consumes = "application/json", produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> updateDataset(@RequestBody String datasetJson) {
Dataset dataset;

View File

@ -112,7 +112,7 @@ public class DmpProfiles {
}
@RequestMapping(method = RequestMethod.GET, value = { "/dmpprofile/getAll" }, produces="application/json")
@RequestMapping(method = RequestMethod.GET, value = { "/dmpprofile/getAll" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> getAllDmpProfiles(){
try {
List<DMPProfile> allDmpProfiles = dMPProfileDao.getAll();
@ -125,7 +125,7 @@ public class DmpProfiles {
@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;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> setDmpProfile(@RequestBody DMPProfile dmpprofile) {
try {
DMPProfile createdDMPProfile = dMPProfileDao.update(dmpprofile);

View File

@ -77,7 +77,7 @@ public class Organisations {
@Autowired private RemoteFetcher remoteFetcher;
@RequestMapping(method = RequestMethod.GET, value = { "/external/organisations" }, produces="application/json")
@RequestMapping(method = RequestMethod.GET, value = { "/external/organisations" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> listExternalOrganisations(@RequestParam(value="query", required=false) String query ){
try {
List<Map<String,String>> remoteRepos = remoteFetcher.getOrganisations(query);
@ -118,7 +118,7 @@ public class Organisations {
}
@RequestMapping(method = RequestMethod.GET, value = { "/organisation/getAll" }, produces="application/json")
@RequestMapping(method = RequestMethod.GET, value = { "/organisation/getAll" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> getAllOrganisations(){
try {
List<Organisation> allOrganisations = organisationDao.getAll();
@ -131,7 +131,7 @@ public class Organisations {
@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;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> setOrganisation(@RequestBody Organisation organisation) {
try {
Organisation createdOrganisation = organisationDao.update(organisation);

View File

@ -88,7 +88,7 @@ public class Projects {
@Autowired private RemoteFetcher remoteFetcher;
@RequestMapping(method = RequestMethod.GET, value = { "/external/projects" }, produces="application/json")
@RequestMapping(method = RequestMethod.GET, value = { "/external/projects" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> listExternalProjects(@RequestParam(value="query", required=false) String query ){
try {
List<Map<String,String>> remoteRepos = remoteFetcher.getProjects(query);
@ -105,7 +105,7 @@ public class Projects {
// MANAGE PROJECT(S)
@RequestMapping(method = RequestMethod.GET, value = { "/projects" }, produces="application/json")
@RequestMapping(method = RequestMethod.GET, value = { "/projects" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> listProjects(){
try {
List<UUID> allIDs = projectDao.listAllIDs();
@ -116,7 +116,7 @@ public class Projects {
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/projects/{id}" }, produces="application/json")
@RequestMapping(method = RequestMethod.GET, value = { "/projects/{id}" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> getProject(@PathVariable("id") String id, @RequestParam(value="eager", defaultValue="false") boolean eager) {
try {
Project project = projectDao.read(UUID.fromString(id));
@ -132,8 +132,22 @@ public class Projects {
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/project/dmps" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> getDMPsOfProject(@RequestParam("id") String id) {
try {
Project project = projectDao.read(UUID.fromString(id));
if(project==null)
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Could not find project with id: "+id);
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(project.getDmps()));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/project/listAllLabelIDs" }, produces="application/json")
@RequestMapping(method = RequestMethod.GET, value = { "/project/listAllLabelIDs" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> listLabelIds(){
try {
List<IDLabelPair> allIDs = projectDao.listAllIDsLabels();
@ -145,7 +159,7 @@ public class Projects {
}
@RequestMapping(method = RequestMethod.GET, value = { "/project/getAll" }, produces="application/json")
@RequestMapping(method = RequestMethod.GET, value = { "/project/getAll" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> getAllProjects(){
try {
List<Project> allProjects = projectDao.getAll();
@ -159,7 +173,7 @@ public class Projects {
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/project/create" }, consumes = "application/json", produces="application/json")
@RequestMapping(method = RequestMethod.POST, value = { "/project/create" }, consumes = "application/json", produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> createProject(@RequestBody Project project) {
Project createdProject = projectDao.update(project);
return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(createdProject));
@ -167,14 +181,14 @@ public class Projects {
@RequestMapping(method = RequestMethod.POST, value = { "/project/update" }, consumes = "application/json", produces="application/json")
@RequestMapping(method = RequestMethod.POST, value = { "/project/update" }, consumes = "application/json", produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> updateProject(@RequestBody Project project) {
Project updatedProject = projectDao.update(project);
return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(updatedProject));
}
@RequestMapping(method = RequestMethod.POST, value = { "/project/delete" }, consumes = "application/json", produces="application/json")
@RequestMapping(method = RequestMethod.POST, value = { "/project/delete" }, consumes = "application/json", produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> delete(@RequestBody Project project) {
Project p = new Project();
@ -191,7 +205,7 @@ public class Projects {
@RequestMapping(method = RequestMethod.POST, value = { "/project/softdelete" }, consumes = "application/json", produces="application/json")
@RequestMapping(method = RequestMethod.POST, value = { "/project/softdelete" }, consumes = "application/json", produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> softDelete(@RequestBody Project project) {
project.setStatus(new Short("-1"));
@ -208,7 +222,7 @@ public class Projects {
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/project/getdmps" }, consumes = "application/json", produces="application/json")
@RequestMapping(method = RequestMethod.POST, value = { "/project/getdmps" }, consumes = "application/json", produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> getProjectDmps(@RequestBody Project project) {
try {
Set<DMP> dmps = projectDao.read(project.getId()).getDmps();

View File

@ -76,7 +76,7 @@ public class Registries {
@Autowired private RemoteFetcher remoteFetcher;
@RequestMapping(method = RequestMethod.GET, value = { "/external/registries" }, produces="application/json")
@RequestMapping(method = RequestMethod.GET, value = { "/external/registries" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> listExternalRegistries(@RequestParam(value="query", required=false) String query ){
try {
List<Map<String,String>> remoteRepos = remoteFetcher.getRegistries(query);
@ -130,7 +130,7 @@ public class Registries {
}
@RequestMapping(method = RequestMethod.GET, value = { "/registry/getAll" }, produces="application/json")
@RequestMapping(method = RequestMethod.GET, value = { "/registry/getAll" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> getAllRegistries(){
try {
List<Registry> allRegistries = registryDao.getAll();
@ -145,7 +145,7 @@ public class Registries {
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/registry/create" }, consumes = "application/json", produces="application/json")
@RequestMapping(method = RequestMethod.POST, value = { "/registry/create" }, consumes = "application/json", produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> setRegistry(@RequestBody Registry registry) {
Registry createdRegistry = registryDao.update(registry);
try {

View File

@ -76,7 +76,7 @@ public class Researchers {
@Autowired private RemoteFetcher remoteFetcher;
@RequestMapping(method = RequestMethod.GET, value = { "/external/researchers" }, produces="application/json")
@RequestMapping(method = RequestMethod.GET, value = { "/external/researchers" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> listExternalResearchers(@RequestParam(value="query", required=false) String query ){
try {
List<Map<String,String>> remoteRepos = remoteFetcher.getResearchers(query);
@ -116,7 +116,7 @@ public class Researchers {
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/researcher/getByEmail" }, produces="application/json")
@RequestMapping(method = RequestMethod.GET, value = { "/researcher/getByEmail" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> getResearcherByEmail(@RequestParam("email") String email){
try {
Researcher researcher = researcherDao.getResearcherByEmail(email);
@ -129,7 +129,7 @@ public class Researchers {
}
@RequestMapping(method = RequestMethod.GET, value = { "/researcher/getAll" }, produces="application/json")
@RequestMapping(method = RequestMethod.GET, value = { "/researcher/getAll" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> getAllResearchers(){
try {
List<Researcher> allResearchers = researcherDao.getAll();
@ -144,7 +144,7 @@ public class Researchers {
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/researcher/create" }, consumes = "application/json", produces="application/json")
@RequestMapping(method = RequestMethod.POST, value = { "/researcher/create" }, consumes = "application/json", produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> setResearcher(@RequestBody Researcher researcher) {
Researcher createdResearcher = researcherDao.update(researcher);
try {

View File

@ -77,7 +77,7 @@ public class Services {
@Autowired private RemoteFetcher remoteFetcher;
@RequestMapping(method = RequestMethod.GET, value = { "/external/services" }, produces="application/json")
@RequestMapping(method = RequestMethod.GET, value = { "/external/services" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> listExternalServices(@RequestParam(value="query", required=false) String query ){
try {
List<Map<String,String>> remoteRepos = remoteFetcher.getServices(query);
@ -119,7 +119,7 @@ public class Services {
@RequestMapping(method = RequestMethod.GET, value = { "/service/getAll" }, produces="application/json")
@RequestMapping(method = RequestMethod.GET, value = { "/service/getAll" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> getAllServices(){
try {
List<Service> allServices = serviceDao.getAll();
@ -134,7 +134,7 @@ public class Services {
@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;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> setService(@RequestBody Service service) {
Service createdService = serviceDao.update(service);

View File

@ -74,6 +74,35 @@ public class Users {
@Autowired private UserInfoDao userInfoDao;
@RequestMapping(method = RequestMethod.GET, value = { "/users/{id}" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> getUserByID(@PathVariable("id") String id){
String userID = null;
try {
userID = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
} catch(NullPointerException ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("You have not logged in. You shouldn't be here");
}
UserInfo userInfo = userInfoDao.getUserInfo(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");
//now get the user the caller asked for...
UserInfo userAsked4 = userInfoDao.getUserInfo(id);
try {
return new ResponseEntity<Object>(SerializerProvider.toJson(userAsked4), HttpStatus.OK);
}
catch(Exception ex) {
ex.printStackTrace();
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/user/whoami" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> whoami(){