no message

This commit is contained in:
annabakouli 2018-01-18 12:55:35 +02:00
parent bfc6b63067
commit b2e49fbb8a
11 changed files with 0 additions and 2406 deletions

View File

@ -1,422 +0,0 @@
package rest.entities;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.transaction.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mchange.v2.sql.filter.SynchronizedFilterDataSource;
import dao.entities.DMPDao;
import dao.entities.DMPProfileDao;
import dao.entities.DataRepositoryDao;
import dao.entities.DatasetDao;
import dao.entities.DatasetProfileDao;
import dao.entities.DatasetProfileRulesetDao;
import dao.entities.DatasetProfileViewstyleDao;
import dao.entities.OrganisationDao;
import dao.entities.ProjectDao;
import dao.entities.RegistryDao;
import dao.entities.ResearcherDao;
import dao.entities.ServiceDao;
import dao.entities.UserInfoDao;
import entities.DMP;
import entities.DMPProfile;
import entities.Dataset;
import entities.DatasetProfile;
import entities.DatasetProfileRuleset;
import entities.Organisation;
import entities.Project;
import entities.Researcher;
import entities.UserInfo;
import entities.responses.IDLabelPair;
import helpers.SerializerProvider;
import helpers.Transformers;
import responses.RestResponse;
@RestController
@CrossOrigin
public class DMPs {
@Autowired private DataRepositoryDao dataRepositoryDao;
@Autowired private DatasetDao datasetDao;
@Autowired private DatasetProfileDao datasetProfileDao;
@Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao;
@Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao;
@Autowired private DMPDao dMPDao;
@Autowired private DMPProfileDao dMPProfileDao;
@Autowired private OrganisationDao organisationDao;
@Autowired private ProjectDao projectDao;
@Autowired private RegistryDao registryDao;
@Autowired private ResearcherDao researcherDao;
@Autowired private ServiceDao serviceDao;
@Autowired private UserInfoDao userInfoDao;
// FETCH BY DMP(S)
@RequestMapping(method = RequestMethod.GET, value = { "/dmps" }, produces="text/plain")
public @ResponseBody ResponseEntity<Object> listDMPs(){
try {
List<UUID> allIDs = dMPDao.listAllIDs();
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());
}
}
@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));
if(eager) {
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));
}
catch(Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
}
}
@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(){
try {
List<IDLabelPair> allIDLabels = dMPDao.listAllIDsLabels();
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());
}
}
/**
* This should be called on extreme cases. It's computationally intensive
*/
@RequestMapping(method = RequestMethod.GET, value = { "/dmp/getAll" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> getAllDMPs(){
try {
List<DMP> allDMPs = dMPDao.getAll();
return new ResponseEntity<Object>(SerializerProvider.toJson(allDMPs), HttpStatus.OK);
}
catch(Exception ex) {
ex.printStackTrace();
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@Transactional
@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);
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!\"");
}
}
@Transactional
@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());
addNullAndForeignElems(previousDmp, dmp);
try {
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!\"");
}
}
@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());
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!\"");
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/delete" }, consumes = "application/json", produces="text/plain")
public @ResponseBody ResponseEntity<Object> delete(@RequestBody DMP dmp) {
DMP d = new DMP();
d.setId(dmp.getId());
try {
dMPDao.delete(d);
return ResponseEntity.status(HttpStatus.CREATED).body("DELETED!");
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete DMP!\"");
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/softdelete" }, consumes = "application/json", produces="text/plain")
public @ResponseBody ResponseEntity<Object> softDelete(@RequestBody DMP dmp) {
DMP d = dMPDao.read(dmp.getId());
d.setStatus(new Short("-1"));
try {
int code = updateDMP(d).getStatusCodeValue();
if(code>199 && code<300)
return ResponseEntity.status(HttpStatus.CREATED).body("DELETED!");
else
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not soft delete DMP!\"");
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not soft delete DMP!\"");
}
}
////////////////////////////////
//// USER - RELATED ACTIONS ////
////////////////////////////////
@RequestMapping(method = RequestMethod.GET, value = { "/dmp/getofuser" }, produces="text/plain")
public @ResponseBody ResponseEntity<Object> getDmpsOfUser(){
String userID = null;
try {
userID = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
} catch(NullPointerException ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("You have not logged in. You shouldn't be here");
}
try {
//List<DMP> nonDeleted = userInfoDao.getDmpsOfUser(userID);
List<DMP> nonDeleted = dMPDao.getDMPsOfUser(userID);
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(nonDeleted));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/createofuser" }, produces="text/plain", consumes = "application/json")
public @ResponseBody ResponseEntity<Object> createDmpOfUser(@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");
}
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.setCreator(userInfo);
Set<UserInfo> users = new HashSet<UserInfo>();
users.add(userInfo);
dmp.setUsers(users);
dmp.setCreated(new Date());
dmp.setModified(new Date());
dmp.setStatus(new Short("0"));
DMP newdmp = dMPDao.create(dmp);
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(newdmp));
}
catch(Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/cloneforuser" }, produces="text/plain", consumes = "application/json")
public @ResponseBody ResponseEntity<Object> cloneDmpOfUser(@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");
}
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");
DMP clone = dMPDao.read(dmp.getId());
try {
Set<UserInfo> users = new HashSet<UserInfo>();
users.add(userInfo);
clone.setUsers(users);
clone.setCreated(new Date());
clone.setModified(new Date());
clone.setStatus(new Short("0"));
String cloneLabel = dmp.getLabel();
if(cloneLabel==null || cloneLabel.isEmpty()) //if the provided label is null or empty, use parent's label + "_clone"
cloneLabel = clone.getLabel()+"_clone";
clone.setVersion(clone.getVersion()+1);
clone.setLabel(cloneLabel);
clone.setPrevious(clone.getId());
clone.setId(null);
clone = dMPDao.create(clone);
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(clone));
}
catch(Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}
@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());
}
}
private static void addNullAndForeignElems(DMP existing, DMP newone) {
newone.setModified(new Date());
if(newone.getStatus()==null)
newone.setStatus(existing.getStatus());
if(newone.getCreated()==null)
newone.setCreated(existing.getCreated());
newone.setDataset(existing.getDataset());
newone.setOrganisations(existing.getOrganisations());
newone.setResearchers(existing.getResearchers());
newone.setUsers(existing.getUsers());
}
}

View File

@ -1,171 +0,0 @@
package rest.entities;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.transaction.Transactional;
import org.apache.commons.lang3.SerializationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import dao.entities.DMPDao;
import dao.entities.DMPProfileDao;
import dao.entities.DataRepositoryDao;
import dao.entities.DatasetDao;
import dao.entities.DatasetProfileDao;
import dao.entities.DatasetProfileRulesetDao;
import dao.entities.DatasetProfileViewstyleDao;
import dao.entities.OrganisationDao;
import dao.entities.ProjectDao;
import dao.entities.RegistryDao;
import dao.entities.ResearcherDao;
import dao.entities.ServiceDao;
import dao.entities.UserInfoDao;
import entities.DMP;
import entities.DMPProfile;
import entities.DataRepository;
import entities.Dataset;
import entities.DatasetProfile;
import entities.DatasetProfileRuleset;
import entities.Organisation;
import entities.Project;
import entities.Registry;
import entities.Researcher;
import entities.Service;
import helpers.SerializerProvider;
import helpers.Transformers;
import proxy.config.exceptions.HugeResultSet;
import proxy.config.exceptions.NoURLFound;
import proxy.fetching.RemoteFetcher;
import responses.RestResponse;
@RestController
@CrossOrigin
public class DataRepositories {
@Autowired private DataRepositoryDao dataRepositoryDao;
@Autowired private DatasetDao datasetDao;
@Autowired private DatasetProfileDao datasetProfileDao;
@Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao;
@Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao;
@Autowired private DMPDao dMPDao;
@Autowired private DMPProfileDao dMPProfileDao;
@Autowired private OrganisationDao organisationDao;
@Autowired private ProjectDao projectDao;
@Autowired private RegistryDao registryDao;
@Autowired private ResearcherDao researcherDao;
@Autowired private ServiceDao serviceDao;
@Autowired private RemoteFetcher remoteFetcher;
@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);
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(remoteRepos));
}
catch(NoURLFound ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"reason\":\""+ex.getMessage()+"\"}");
}
catch(HugeResultSet ex) {
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body("{\"reason\":\""+ex.getMessage()+"\"}"); //the ex.getMessage has the appropriate text description
}
}
// 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(SerializerProvider.toJson(allIDs));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/datarepos/{id}" })
public @ResponseBody ResponseEntity<Object> getDataRepository(@PathVariable("id") String id) {
try {
DataRepository dataRepository = dataRepositoryDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(dataRepository));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/datarepo/getAll" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> getAllDataRepositories(){
try {
List<DataRepository> allDataRepositories = dataRepositoryDao.getAll();
return new ResponseEntity<Object>(SerializerProvider.toJson(allDataRepositories), HttpStatus.OK);
}
catch(Exception ex) {
ex.printStackTrace();
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@Transactional
@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 {
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!\"}");
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/datarepo/delete" }, consumes = "application/json", produces="text/plain")
public @ResponseBody ResponseEntity<Object> delete(@RequestBody DataRepository dataRepository) {
DataRepository dr = new DataRepository();
dr.setId(dataRepository.getId());
try {
dataRepositoryDao.delete(dr);
return ResponseEntity.status(HttpStatus.CREATED).body("{\"msg\":\"Deleted data repository!\"}");
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not delete data repository!\"}");
}
}
}

View File

@ -1,199 +0,0 @@
package rest.entities;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.transaction.Transactional;
import org.apache.commons.lang3.SerializationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import dao.entities.DMPDao;
import dao.entities.DMPProfileDao;
import dao.entities.DataRepositoryDao;
import dao.entities.DatasetDao;
import dao.entities.DatasetProfileDao;
import dao.entities.DatasetProfileRulesetDao;
import dao.entities.DatasetProfileViewstyleDao;
import dao.entities.OrganisationDao;
import dao.entities.ProjectDao;
import dao.entities.RegistryDao;
import dao.entities.ResearcherDao;
import dao.entities.ServiceDao;
import entities.DMP;
import entities.DMPProfile;
import entities.Dataset;
import entities.DatasetProfile;
import entities.DatasetProfileRuleset;
import entities.DatasetProfileViewstyle;
import entities.Organisation;
import entities.Project;
import helpers.SerializerProvider;
import helpers.Transformers;
import responses.RestResponse;
@RestController
@CrossOrigin
public class DatasetProfiles {
@Autowired private DataRepositoryDao dataRepositoryDao;
@Autowired private DatasetDao datasetDao;
@Autowired private DatasetProfileDao datasetProfileDao;
@Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao;
@Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao;
@Autowired private DMPDao dMPDao;
@Autowired private DMPProfileDao dMPProfileDao;
@Autowired private OrganisationDao organisationDao;
@Autowired private ProjectDao projectDao;
@Autowired private RegistryDao registryDao;
@Autowired private ResearcherDao researcherDao;
@Autowired private ServiceDao serviceDao;
//FETCH BY DATASET PROFILE
@RequestMapping(method = RequestMethod.GET, value = { "/datasetprofiles" }, produces="text/plain")
public @ResponseBody ResponseEntity<Object> listDMPs(){
try {
List<UUID> allIDs = datasetProfileDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/datasetprofiles/{id}" })
public @ResponseBody ResponseEntity<Object> getDatasetProfile(@PathVariable("id") String id) {
try {
DatasetProfile profile = datasetProfileDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(profile));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/datasetprofile/getAll" })
public @ResponseBody ResponseEntity<Object> getAllDatasetProfiles(){
try {
List<DatasetProfile> allDatasetProfiles = datasetProfileDao.getAll();
return new ResponseEntity<Object>(SerializerProvider.toJson(allDatasetProfiles), HttpStatus.OK);
}
catch(Exception ex) {
ex.printStackTrace();
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@Transactional
@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();
DatasetProfileViewstyle datasetprofileviewstyle = datasetProfile.getViewstyle();
if(datasetprofileruleset != null) {
if(datasetprofileruleset.getId()==null)
datasetProfileRulesetDao.create(datasetprofileruleset);
else
datasetProfileRulesetDao.update(datasetprofileruleset);
datasetProfile.setRuleset(datasetprofileruleset);
}
if(datasetprofileviewstyle != null) {
if(datasetprofileviewstyle.getId()==null)
datasetProfileViewstyleDao.create(datasetprofileviewstyle);
else
datasetProfileViewstyleDao.update(datasetprofileviewstyle);
datasetProfile.setViewstyle(datasetprofileviewstyle);
}
if(datasetProfile.getId()==null)
datasetProfileDao.create(datasetProfile);
else
datasetProfileDao.update(datasetProfile);
return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(datasetProfile));
}
@Transactional
@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();
DatasetProfileViewstyle datasetprofileviewstyle = datasetProfile.getViewstyle();
if(datasetprofileruleset != null) {
if(datasetprofileruleset.getId()==null)
datasetProfileRulesetDao.create(datasetprofileruleset);
else
datasetProfileRulesetDao.update(datasetprofileruleset);
}
if(datasetprofileviewstyle != null) {
if(datasetprofileviewstyle.getId()==null)
datasetProfileViewstyleDao.create(datasetprofileviewstyle);
else
datasetProfileViewstyleDao.update(datasetprofileviewstyle);
}
if(datasetProfile.getId()==null)
datasetProfile = datasetProfileDao.create(datasetProfile);
else
datasetProfile = datasetProfileDao.update(datasetProfile);
return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(datasetProfile));
}
@Transactional
@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();
DatasetProfileViewstyle datasetprofileviewstyle = datasetProfile.getViewstyle();
try {
if(datasetprofileruleset != null)
datasetProfileRulesetDao.delete(datasetprofileruleset);
if(datasetprofileviewstyle != null)
datasetProfileViewstyleDao.delete(datasetprofileviewstyle);
datasetProfileDao.delete(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!\"}");
}
}
}

View File

@ -1,276 +0,0 @@
package rest.entities;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.transaction.Transactional;
import org.apache.commons.lang3.SerializationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import dao.entities.DMPDao;
import dao.entities.DMPProfileDao;
import dao.entities.DataRepositoryDao;
import dao.entities.DatasetDao;
import dao.entities.DatasetProfileDao;
import dao.entities.DatasetProfileRulesetDao;
import dao.entities.DatasetProfileViewstyleDao;
import dao.entities.OrganisationDao;
import dao.entities.ProjectDao;
import dao.entities.RegistryDao;
import dao.entities.ResearcherDao;
import dao.entities.ServiceDao;
import dao.entities.UserInfoDao;
import entities.DMP;
import entities.DMPProfile;
import entities.Dataset;
import entities.DatasetProfile;
import entities.DatasetProfileRuleset;
import entities.DatasetProfileViewstyle;
import entities.Organisation;
import entities.Project;
import entities.UserInfo;
import helpers.SafeCleanAttribs;
import helpers.SerializerProvider;
import helpers.Transformers;
import responses.RestResponse;
@RestController
@CrossOrigin
public class Datasets {
@Autowired private DataRepositoryDao dataRepositoryDao;
@Autowired private DatasetDao datasetDao;
@Autowired private DatasetProfileDao datasetProfileDao;
@Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao;
@Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao;
@Autowired private DMPDao dMPDao;
@Autowired private DMPProfileDao dMPProfileDao;
@Autowired private OrganisationDao organisationDao;
@Autowired private ProjectDao projectDao;
@Autowired private RegistryDao registryDao;
@Autowired private ResearcherDao researcherDao;
@Autowired private ServiceDao serviceDao;
@Autowired private UserInfoDao userInfoDao;
// FETCH BY DATASET(S)
@RequestMapping(method = RequestMethod.GET, value = { "/datasets" })
public @ResponseBody ResponseEntity<Object> listDatasets(){
try {
List<UUID> allIDs = datasetDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/datasets/{id}" })
public @ResponseBody ResponseEntity<Object> getDataset(@PathVariable("id") String id) {
try {
Dataset ds = datasetDao.read(UUID.fromString(id));
ds.setDmp(ds.getDmp());
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(ds));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
}
}
/**
* This should be called on extreme cases. It's computationally intensive
*/
@RequestMapping(method = RequestMethod.GET, value = { "/dataset/getAll" })
public @ResponseBody ResponseEntity<Object> getAllDatasets(){
try {
List<Dataset> allDatasets = datasetDao.getAll();
return new ResponseEntity<Object>(SerializerProvider.toJson(allDatasets), HttpStatus.OK);
}
catch(Exception ex) {
ex.printStackTrace();
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/dataset/create" }, consumes = "application/json", produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> createDataset(@RequestBody Dataset dataset) {
String userID = null;
try {
userID = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
} catch(NullPointerException ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("You have not logged in. You shouldn't be here");
}
UserInfo userInfo = userInfoDao.read(UUID.fromString(userID));
if(userInfo==null) //this should normally never happer
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("There's no such a user on the system. You shouldn't be here");
dataset.setId(null);
dataset.setCreated(new Date());
dataset.setModified(new Date());
dataset.setStatus(new Short("0"));
dataset.setCreator(userInfo);
if("".equals(dataset.getReference())) dataset.setReference(null);
if("".equals(dataset.getProperties())) dataset.setProperties(null);
try {
dataset = datasetDao.create(dataset);
return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(dataset));
}
catch(Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Could not create or update Dataset! Reason: " + e.getMessage());
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/dataset/update" }, consumes = "application/json", produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> updateDataset(@RequestBody String datasetJson) {
Dataset dataset;
try {
dataset = SerializerProvider.fromJson(datasetJson, Dataset.class);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Could not create or update Dataset! Reason: " + e.getMessage());
}
SafeCleanAttribs.clean(dataset);
if("".equals(dataset.getReference())) dataset.setReference(null);
if("".equals(dataset.getProperties())) dataset.setProperties(null);
try {
dataset = datasetDao.update(dataset);
return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(dataset));
}
catch(Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Could not create or update Dataset! Reason: " + ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/dataset/delete" }, consumes = "application/json")
public @ResponseBody ResponseEntity<Object> deleteDataset(@RequestBody Dataset dataset) {
//if we want to make sure it won't cascade up to other (child) components, we can just unhook them by setting them = new ones
// e.g: DMP dmp = new DMP() and then dataset.setDMP(dmp)
try {
datasetDao.delete(dataset);
RestResponse rr = new RestResponse("Deleted dataset with id: "+dataset.getId().toString(), dataset.getId().toString());
return ResponseEntity.status(HttpStatus.OK).body(rr.toString());
}
catch(Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Could not delete Dataset! Reason: " + e.getMessage());
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/dataset/softdelete" }, consumes = "application/json", produces="text/plain")
public @ResponseBody ResponseEntity<Object> softDelete(@RequestBody Dataset dataset) {
Dataset d = datasetDao.read(dataset.getId());
d.setStatus(new Short("-1"));
try {
int code = updateDataset(SerializerProvider.toJson(d)).getStatusCodeValue();
if(code>199 && code<300)
return ResponseEntity.status(HttpStatus.CREATED).body("DELETED!");
else
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not soft delete dataset!\"");
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not soft delete dataset!\"");
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/dataset/assignDMPToDataset" })
public @ResponseBody ResponseEntity<Object> assignDMPToDataset(@RequestParam("datasetID") String datasetID, @RequestParam("dmpID") String dmpID) {
Dataset dataset = null;
try {
dataset = datasetDao.read(UUID.fromString(datasetID));
if(dataset==null || dataset.getId()==null) throw new Exception("Could not find a Dataset by this id");
DMP dmp = new DMP();
dmp.setId(UUID.fromString(dmpID));
dataset.setDmp(dmp);
datasetDao.update(dataset);
return ResponseEntity.status(HttpStatus.OK).build();
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/dataset/assignProfileToDataset" })
public @ResponseBody ResponseEntity<Object> assignProfileToDataset(@RequestParam("datasetID") String datasetID, @RequestParam("profileID") String profileID) {
Dataset dataset = null;
try {
dataset = datasetDao.read(UUID.fromString(datasetID));
if(dataset==null || dataset.getId()==null) throw new Exception("Could not find a Dataset by this id");
DatasetProfile profile = new DatasetProfile();
profile.setId(UUID.fromString(profileID));
dataset.setProfile(profile);
datasetDao.update(dataset);
return ResponseEntity.status(HttpStatus.OK).build();
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}
}

View File

@ -1,157 +0,0 @@
package rest.entities;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.transaction.Transactional;
import org.apache.commons.lang3.SerializationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import dao.entities.DMPDao;
import dao.entities.DMPProfileDao;
import dao.entities.DataRepositoryDao;
import dao.entities.DatasetDao;
import dao.entities.DatasetProfileDao;
import dao.entities.DatasetProfileRulesetDao;
import dao.entities.DatasetProfileViewstyleDao;
import dao.entities.OrganisationDao;
import dao.entities.ProjectDao;
import dao.entities.RegistryDao;
import dao.entities.ResearcherDao;
import dao.entities.ServiceDao;
import entities.DMP;
import entities.DMPProfile;
import entities.DataRepository;
import entities.Dataset;
import entities.DatasetProfile;
import entities.DatasetProfileRuleset;
import entities.Organisation;
import entities.Project;
import entities.Registry;
import entities.Researcher;
import entities.Service;
import entities.responses.IDLabelPair;
import helpers.SerializerProvider;
import helpers.Transformers;
import responses.RestResponse;
@RestController
@CrossOrigin
public class DmpProfiles {
@Autowired private DataRepositoryDao dataRepositoryDao;
@Autowired private DatasetDao datasetDao;
@Autowired private DatasetProfileDao datasetProfileDao;
@Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao;
@Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao;
@Autowired private DMPDao dMPDao;
@Autowired private DMPProfileDao dMPProfileDao;
@Autowired private OrganisationDao organisationDao;
@Autowired private ProjectDao projectDao;
@Autowired private RegistryDao registryDao;
@Autowired private ResearcherDao researcherDao;
@Autowired private ServiceDao serviceDao;
// MANAGE DMPPROFILE(S)
@RequestMapping(method = RequestMethod.GET, value = { "/dmpprofiles" })
public @ResponseBody ResponseEntity<Object> listDmpProfiles(){
try {
List<UUID> allIDs = dMPProfileDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/dmpprofiles/{id}" })
public @ResponseBody ResponseEntity<Object> getDmpProfile(@PathVariable("id") String id) {
try {
DMPProfile dmpProfile = dMPProfileDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(dmpProfile));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/dmpprofile/listAllLabelIDs" })
public @ResponseBody ResponseEntity<Object> listLabelIds(){
try {
List<IDLabelPair> allIDs = dMPProfileDao.listAllIDsLabels();
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/dmpprofile/getAll" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> getAllDmpProfiles(){
try {
List<DMPProfile> allDmpProfiles = dMPProfileDao.getAll();
return new ResponseEntity<Object>(SerializerProvider.toJson(allDmpProfiles), HttpStatus.OK);
}
catch(Exception ex) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@Transactional
@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);
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!\"}");
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/dmpprofile/delete" }, consumes = "application/json", produces="text/plain")
public @ResponseBody ResponseEntity<Object> delete(@RequestBody DMPProfile dmpprofile) {
DMPProfile dmpp = new DMPProfile();
dmpp.setId(dmpprofile.getId());
try {
dMPProfileDao.delete(dmpp);
return ResponseEntity.status(HttpStatus.CREATED).body("{\"msg\":\"Deleted DMP Profile!\"}");
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete DMP Profile!\"}");
}
}
}

View File

@ -1,164 +0,0 @@
package rest.entities;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.transaction.Transactional;
import org.apache.commons.lang3.SerializationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import dao.entities.DMPDao;
import dao.entities.DMPProfileDao;
import dao.entities.DataRepositoryDao;
import dao.entities.DatasetDao;
import dao.entities.DatasetProfileDao;
import dao.entities.DatasetProfileRulesetDao;
import dao.entities.DatasetProfileViewstyleDao;
import dao.entities.OrganisationDao;
import dao.entities.ProjectDao;
import dao.entities.RegistryDao;
import dao.entities.ResearcherDao;
import dao.entities.ServiceDao;
import entities.DMP;
import entities.DMPProfile;
import entities.DataRepository;
import entities.Dataset;
import entities.DatasetProfile;
import entities.DatasetProfileRuleset;
import entities.Organisation;
import entities.Project;
import entities.Registry;
import entities.Researcher;
import entities.Service;
import helpers.SerializerProvider;
import helpers.Transformers;
import proxy.config.exceptions.HugeResultSet;
import proxy.config.exceptions.NoURLFound;
import proxy.fetching.RemoteFetcher;
import responses.RestResponse;
@RestController
@CrossOrigin
public class Organisations {
@Autowired private DataRepositoryDao dataRepositoryDao;
@Autowired private DatasetDao datasetDao;
@Autowired private DatasetProfileDao datasetProfileDao;
@Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao;
@Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao;
@Autowired private DMPDao dMPDao;
@Autowired private DMPProfileDao dMPProfileDao;
@Autowired private OrganisationDao organisationDao;
@Autowired private ProjectDao projectDao;
@Autowired private RegistryDao registryDao;
@Autowired private ResearcherDao researcherDao;
@Autowired private ServiceDao serviceDao;
@Autowired private RemoteFetcher remoteFetcher;
@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);
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(remoteRepos));
}
catch(NoURLFound ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"reason\":\""+ex.getMessage()+"\"}");
}
catch(HugeResultSet ex) {
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body("{\"reason\":\""+ex.getMessage()+"\"}"); //the ex.getMessage has the appropriate text description
}
}
// MANAGE ORGANISATIONS(S)
@RequestMapping(method = RequestMethod.GET, value = { "/organisations" })
public @ResponseBody ResponseEntity<Object> listOrganisations(){
try {
List<UUID> allIDs = organisationDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/organisations/{id}" })
public @ResponseBody ResponseEntity<Object> getOrganisations(@PathVariable("id") String id) {
try {
Organisation organisation = organisationDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(organisation));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/organisation/getAll" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> getAllOrganisations(){
try {
List<Organisation> allOrganisations = organisationDao.getAll();
return new ResponseEntity<Object>(SerializerProvider.toJson(allOrganisations), HttpStatus.OK);
}
catch(Exception ex) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@Transactional
@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);
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!\"}");
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/organisation/delete" }, consumes = "application/json", produces="text/plain")
public @ResponseBody ResponseEntity<Object> delete(@RequestBody Organisation organisation) {
Organisation org = new Organisation();
org.setId(organisation.getId());
try {
organisationDao.delete(org);
return ResponseEntity.status(HttpStatus.CREATED).body("{\"msg\":\"Deleted organisation!\"}");
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not delete organisation!\"}");
}
}
}

View File

@ -1,352 +0,0 @@
package rest.entities;
import java.util.Date;
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;
import javax.transaction.Transactional;
import org.apache.commons.lang3.SerializationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module;
import dao.entities.DMPDao;
import dao.entities.DMPProfileDao;
import dao.entities.DataRepositoryDao;
import dao.entities.DatasetDao;
import dao.entities.DatasetProfileDao;
import dao.entities.DatasetProfileRulesetDao;
import dao.entities.DatasetProfileViewstyleDao;
import dao.entities.OrganisationDao;
import dao.entities.ProjectDao;
import dao.entities.RegistryDao;
import dao.entities.ResearcherDao;
import dao.entities.ServiceDao;
import dao.entities.UserInfoDao;
import entities.DMP;
import entities.DMPProfile;
import entities.DataRepository;
import entities.Dataset;
import entities.DatasetProfile;
import entities.DatasetProfileRuleset;
import entities.Organisation;
import entities.Project;
import entities.Registry;
import entities.Researcher;
import entities.Service;
import entities.UserInfo;
import entities.responses.IDLabelPair;
import helpers.SerializerProvider;
import helpers.Transformers;
import proxy.config.exceptions.HugeResultSet;
import proxy.config.exceptions.NoURLFound;
import proxy.fetching.RemoteFetcher;
import responses.RestResponse;
@RestController
@CrossOrigin
public class Projects {
@Autowired private DataRepositoryDao dataRepositoryDao;
@Autowired private DatasetDao datasetDao;
@Autowired private DatasetProfileDao datasetProfileDao;
@Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao;
@Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao;
@Autowired private DMPDao dMPDao;
@Autowired private DMPProfileDao dMPProfileDao;
@Autowired private OrganisationDao organisationDao;
@Autowired private ProjectDao projectDao;
@Autowired private RegistryDao registryDao;
@Autowired private ResearcherDao researcherDao;
@Autowired private ServiceDao serviceDao;
@Autowired private UserInfoDao userInfoDao;
@Autowired private RemoteFetcher remoteFetcher;
@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);
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(remoteRepos));
}
catch(NoURLFound ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"reason\":\""+ex.getMessage()+"\"}");
}
catch(HugeResultSet ex) {
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body("{\"reason\":\""+ex.getMessage()+"\"}"); //the ex.getMessage has the appropriate text description
}
}
// MANAGE PROJECT(S)
@RequestMapping(method = RequestMethod.GET, value = { "/projects" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> listProjects(){
try {
List<UUID> allIDs = projectDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}
@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));
if(eager) {
project.getDmps().size(); //used only for lazy load trigger...
}
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(project));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
}
}
@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;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> listLabelIds(){
try {
List<IDLabelPair> allIDs = projectDao.listAllIDsLabels();
return ResponseEntity.status(HttpStatus.OK).body(allIDs);
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/project/getAll" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> getAllProjects(){
try {
List<Project> allProjects = projectDao.getAll();
return new ResponseEntity<Object>(SerializerProvider.toJson(allProjects), HttpStatus.OK);
}
catch(Exception ex) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@Transactional
@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));
}
@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;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> delete(@RequestBody Project project) {
Project p = new Project();
p.setId(project.getId());
try {
projectDao.delete(p);
return ResponseEntity.status(HttpStatus.CREATED).body("{\"msg\":\"Deleted Project entity!\"}");
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete Project!\"}");
}
}
@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"));
try {
projectDao.update(project);
return ResponseEntity.status(HttpStatus.CREATED).body("{\"msg\":\"Deleted project!\"}");
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not delete Project!\"}");
}
}
@Transactional
@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();
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!\"}");
}
}
////////////////////////////////
//// USER - RELATED ACTIONS ////
////////////////////////////////
@RequestMapping(method = RequestMethod.GET, value = { "/project/getofuser" }, produces="text/plain")
public @ResponseBody ResponseEntity<Object> getProjectsOfUser(){
String userID = null;
try {
userID = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
} catch(NullPointerException ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("You have not logged in. You shouldn't be here");
}
UserInfo userInfo = userInfoDao.read(UUID.fromString(userID));
if(userInfo==null) //this should normally never happen
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("There's no such a user on the system. You shouldn't be here");
try {
List<Project> userProjects = projectDao.getProjectsOfUser(userID);
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(userProjects));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
/*
* OLD ONE
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(SerializerProvider.toJson(userProjects.values()));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
*/
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/project/createofuser" }, produces="text/plain", consumes = "application/json")
public @ResponseBody ResponseEntity<Object> createProjectOfUser(@RequestBody Project project){
String userID = null;
try {
userID = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
} catch(NullPointerException ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("You have not logged in. You shouldn't be here");
}
UserInfo userInfo = userInfoDao.read(UUID.fromString(userID));
if(userInfo==null) //this should normally never happer
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("There's no such a user on the system. You shouldn't be here");
try {
project.setId(null);
project.setStatus(new Short("0"));
project.setCreationUser(userInfo);
project.setCreated(new Date());
project.setModified(new Date());
Project newproj = projectDao.create(project);
// DMP newdmp = new DMP();
// newdmp.setId(null);
// newdmp.setLabel("Auto-Generated");
// newdmp.setCreated(new Date());
// newdmp.setVersion(1);
// newdmp.setStatus(new Short("0"));
// newdmp.setProject(newproj);
//
// Set<UserInfo> users = new HashSet<UserInfo>();
// users.add(userInfo);
// newdmp.setUsers(users);
//
// newdmp = dMPDao.create(newdmp);
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(newproj));
}
catch(Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}
// @Transactional
// @RequestMapping(method = RequestMethod.POST, value = { "/project/updateofuser" }, produces="text/plain")
// public @ResponseBody ResponseEntity<Object> updateProjectOfUser(@RequestBody Project project){
//
// if(project.getId()==null)
// return ResponseEntity.status(HttpStatus.NOT_MODIFIED).body("Cannot update, id was null");
// return setProject(project);
//
// }
}

View File

@ -1,178 +0,0 @@
package rest.entities;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
import org.apache.commons.lang3.SerializationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import dao.entities.DMPDao;
import dao.entities.DMPProfileDao;
import dao.entities.DataRepositoryDao;
import dao.entities.DatasetDao;
import dao.entities.DatasetProfileDao;
import dao.entities.DatasetProfileRulesetDao;
import dao.entities.DatasetProfileViewstyleDao;
import dao.entities.OrganisationDao;
import dao.entities.ProjectDao;
import dao.entities.RegistryDao;
import dao.entities.ResearcherDao;
import dao.entities.ServiceDao;
import entities.DMP;
import entities.DMPProfile;
import entities.DataRepository;
import entities.Dataset;
import entities.DatasetProfile;
import entities.DatasetProfileRuleset;
import entities.Organisation;
import entities.Project;
import entities.Registry;
import entities.Researcher;
import entities.Service;
import entities.responses.IDLabelPair;
import helpers.SerializerProvider;
import helpers.Transformers;
import proxy.config.exceptions.HugeResultSet;
import proxy.config.exceptions.NoURLFound;
import proxy.fetching.RemoteFetcher;
import responses.RestResponse;
@RestController
@CrossOrigin
public class Registries {
@Autowired private DataRepositoryDao dataRepositoryDao;
@Autowired private DatasetDao datasetDao;
@Autowired private DatasetProfileDao datasetProfileDao;
@Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao;
@Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao;
@Autowired private DMPDao dMPDao;
@Autowired private DMPProfileDao dMPProfileDao;
@Autowired private OrganisationDao organisationDao;
@Autowired private ProjectDao projectDao;
@Autowired private RegistryDao registryDao;
@Autowired private ResearcherDao researcherDao;
@Autowired private ServiceDao serviceDao;
@Autowired private RemoteFetcher remoteFetcher;
@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);
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(remoteRepos));
}
catch(NoURLFound ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"reason\":\""+ex.getMessage()+"\"}");
}
catch(HugeResultSet ex) {
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body("{\"reason\":\""+ex.getMessage()+"\"}"); //the ex.getMessage has the appropriate text description
}
}
// 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(SerializerProvider.toJson(allIDs));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/registries/{id}" })
public @ResponseBody ResponseEntity<Object> getRegistries(@PathVariable("id") String id) {
try {
Registry registry = registryDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(registry));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/registries/listAllLabelIDs" })
public @ResponseBody ResponseEntity<Object> listLabelIds(){
try {
List<IDLabelPair> allIDs = registryDao.listAllIDsLabels();
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/registry/getAll" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> getAllRegistries(){
try {
List<Registry> allRegistries = registryDao.getAll();
return new ResponseEntity<Object>(SerializerProvider.toJson(allRegistries), HttpStatus.OK);
}
catch(Exception ex) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@Transactional
@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 {
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!\"}");
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/registry/delete" }, consumes = "application/json", produces="text/plain")
public @ResponseBody ResponseEntity<Object> delete(@RequestBody Registry registry) {
Registry r = new Registry();
r.setId(registry.getId());
try {
registryDao.delete(r);
return ResponseEntity.status(HttpStatus.CREATED).body("{\"msg\":\"Deleted registry!\"}");
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete registry!\"}");
}
}
}

View File

@ -1,176 +0,0 @@
package rest.entities;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.transaction.Transactional;
import org.apache.commons.lang3.SerializationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import dao.entities.DMPDao;
import dao.entities.DMPProfileDao;
import dao.entities.DataRepositoryDao;
import dao.entities.DatasetDao;
import dao.entities.DatasetProfileDao;
import dao.entities.DatasetProfileRulesetDao;
import dao.entities.DatasetProfileViewstyleDao;
import dao.entities.OrganisationDao;
import dao.entities.ProjectDao;
import dao.entities.RegistryDao;
import dao.entities.ResearcherDao;
import dao.entities.ServiceDao;
import entities.DMP;
import entities.DMPProfile;
import entities.DataRepository;
import entities.Dataset;
import entities.DatasetProfile;
import entities.DatasetProfileRuleset;
import entities.Organisation;
import entities.Project;
import entities.Registry;
import entities.Researcher;
import entities.Service;
import helpers.SerializerProvider;
import helpers.Transformers;
import proxy.config.exceptions.HugeResultSet;
import proxy.config.exceptions.NoURLFound;
import proxy.fetching.RemoteFetcher;
import responses.RestResponse;
@RestController
@CrossOrigin
public class Researchers {
@Autowired private DataRepositoryDao dataRepositoryDao;
@Autowired private DatasetDao datasetDao;
@Autowired private DatasetProfileDao datasetProfileDao;
@Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao;
@Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao;
@Autowired private DMPDao dMPDao;
@Autowired private DMPProfileDao dMPProfileDao;
@Autowired private OrganisationDao organisationDao;
@Autowired private ProjectDao projectDao;
@Autowired private RegistryDao registryDao;
@Autowired private ResearcherDao researcherDao;
@Autowired private ServiceDao serviceDao;
@Autowired private RemoteFetcher remoteFetcher;
@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);
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(remoteRepos));
}
catch(NoURLFound ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"reason\":\""+ex.getMessage()+"\"}");
}
catch(HugeResultSet ex) {
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body("{\"reason\":\""+ex.getMessage()+"\"}"); //the ex.getMessage has the appropriate text description
}
}
// 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(SerializerProvider.toJson(allIDs));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/researchers/{id}" })
public @ResponseBody ResponseEntity<Object> getResearchers(@PathVariable("id") String id) {
try {
Researcher researcher = researcherDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(researcher));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
}
}
@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);
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(researcher));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/researcher/getAll" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> getAllResearchers(){
try {
List<Researcher> allResearchers = researcherDao.getAll();
return new ResponseEntity<Object>(SerializerProvider.toJson(allResearchers), HttpStatus.OK);
}
catch(Exception ex) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@Transactional
@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 {
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!\"}");
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/researcher/delete" }, consumes = "application/json", produces="text/plain")
public @ResponseBody ResponseEntity<Object> delete(@RequestBody Researcher researcher) {
Researcher res = new Researcher();
res.setId(researcher.getId());
try {
researcherDao.delete(res);
return ResponseEntity.status(HttpStatus.CREATED).body("{\"msg\":\"Deleted researcher!\"}");
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not delete researcher!\"}");
}
}
}

View File

@ -1,167 +0,0 @@
package rest.entities;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.transaction.Transactional;
import org.apache.commons.lang3.SerializationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import dao.entities.DMPDao;
import dao.entities.DMPProfileDao;
import dao.entities.DataRepositoryDao;
import dao.entities.DatasetDao;
import dao.entities.DatasetProfileDao;
import dao.entities.DatasetProfileRulesetDao;
import dao.entities.DatasetProfileViewstyleDao;
import dao.entities.OrganisationDao;
import dao.entities.ProjectDao;
import dao.entities.RegistryDao;
import dao.entities.ResearcherDao;
import dao.entities.ServiceDao;
import entities.DMP;
import entities.DMPProfile;
import entities.DataRepository;
import entities.Dataset;
import entities.DatasetProfile;
import entities.DatasetProfileRuleset;
import entities.Organisation;
import entities.Project;
import entities.Registry;
import entities.Researcher;
import entities.Service;
import helpers.SerializerProvider;
import helpers.Transformers;
import proxy.config.exceptions.HugeResultSet;
import proxy.config.exceptions.NoURLFound;
import proxy.fetching.RemoteFetcher;
import responses.RestResponse;
@RestController
@CrossOrigin
public class Services {
@Autowired private DataRepositoryDao dataRepositoryDao;
@Autowired private DatasetDao datasetDao;
@Autowired private DatasetProfileDao datasetProfileDao;
@Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao;
@Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao;
@Autowired private DMPDao dMPDao;
@Autowired private DMPProfileDao dMPProfileDao;
@Autowired private OrganisationDao organisationDao;
@Autowired private ProjectDao projectDao;
@Autowired private RegistryDao registryDao;
@Autowired private ResearcherDao researcherDao;
@Autowired private ServiceDao serviceDao;
@Autowired private RemoteFetcher remoteFetcher;
@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);
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(remoteRepos));
}
catch(NoURLFound ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"reason\":\""+ex.getMessage()+"\"}");
}
catch(HugeResultSet ex) {
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body("{\"reason\":\""+ex.getMessage()+"\"}"); //the ex.getMessage has the appropriate text description
}
}
// MANAGE SERVICE(S)
@RequestMapping(method = RequestMethod.GET, value = { "/services" })
public @ResponseBody ResponseEntity<Object> listServices(){
try {
List<UUID> allIDs = serviceDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/services/{id}" })
public @ResponseBody ResponseEntity<Object> getServices(@PathVariable("id") String id) {
try {
Service service = serviceDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(service));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/service/getAll" }, produces="application/json;charset=UTF-8")
public @ResponseBody ResponseEntity<Object> getAllServices(){
try {
List<Service> allServices = serviceDao.getAll();
return new ResponseEntity<Object>(SerializerProvider.toJson(allServices), HttpStatus.OK);
}
catch(Exception ex) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@Transactional
@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);
try {
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!\"}");
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/service/delete" }, consumes = "application/json", produces="text/plain")
public @ResponseBody ResponseEntity<Object> delete(@RequestBody Service service) {
System.out.println(service);
try {
serviceDao.delete(service);
return ResponseEntity.status(HttpStatus.CREATED).body("{\"msg\":\"Deleted Service entity!\"}");
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete Service entity!\"}");
}
}
}

View File

@ -1,144 +0,0 @@
package rest.entities;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.transaction.Transactional;
import org.apache.commons.lang3.SerializationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import dao.entities.DMPDao;
import dao.entities.DMPProfileDao;
import dao.entities.DataRepositoryDao;
import dao.entities.DatasetDao;
import dao.entities.DatasetProfileDao;
import dao.entities.DatasetProfileRulesetDao;
import dao.entities.DatasetProfileViewstyleDao;
import dao.entities.OrganisationDao;
import dao.entities.ProjectDao;
import dao.entities.RegistryDao;
import dao.entities.ResearcherDao;
import dao.entities.ServiceDao;
import dao.entities.UserInfoDao;
import entities.DMP;
import entities.DMPProfile;
import entities.DataRepository;
import entities.Dataset;
import entities.DatasetProfile;
import entities.DatasetProfileRuleset;
import entities.Organisation;
import entities.Project;
import entities.Registry;
import entities.Researcher;
import entities.Service;
import entities.UserInfo;
import helpers.SerializerProvider;
import helpers.Transformers;
import responses.RestResponse;
@RestController
@CrossOrigin
public class Users {
@Autowired private DataRepositoryDao dataRepositoryDao;
@Autowired private DatasetDao datasetDao;
@Autowired private DatasetProfileDao datasetProfileDao;
@Autowired private DatasetProfileRulesetDao datasetProfileRulesetDao;
@Autowired private DatasetProfileViewstyleDao datasetProfileViewstyleDao;
@Autowired private DMPDao dMPDao;
@Autowired private DMPProfileDao dMPProfileDao;
@Autowired private OrganisationDao organisationDao;
@Autowired private ProjectDao projectDao;
@Autowired private RegistryDao registryDao;
@Autowired private ResearcherDao researcherDao;
@Autowired private ServiceDao serviceDao;
@Autowired private UserInfoDao userInfoDao;
@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(){
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");
try {
return new ResponseEntity<Object>(SerializerProvider.toJson(userInfo), HttpStatus.OK);
}
catch(Exception ex) {
ex.printStackTrace();
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}