diff --git a/dmp-backend/src/main/java/rest/entities/DMPs.java b/dmp-backend/src/main/java/rest/entities/DMPs.java deleted file mode 100644 index dd6195fbd..000000000 --- a/dmp-backend/src/main/java/rest/entities/DMPs.java +++ /dev/null @@ -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 listDMPs(){ - try { - List 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 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 getDMPHistory(@PathVariable("id") String id){ - try { - List history = new ArrayList(); - 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 listDmpLabelID(){ - try { - List 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 getAllDMPs(){ - - try { - List allDMPs = dMPDao.getAll(); - return new ResponseEntity(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 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 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 getDatasetsOfDMP(@RequestBody DMP dmp) { - try { - List 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 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 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 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 nonDeleted = userInfoDao.getDmpsOfUser(userID); - List 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 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 users = new HashSet(); - 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 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 users = new HashSet(); - 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 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 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()); - } - - -} - diff --git a/dmp-backend/src/main/java/rest/entities/DataRepositories.java b/dmp-backend/src/main/java/rest/entities/DataRepositories.java deleted file mode 100644 index 0be2a8772..000000000 --- a/dmp-backend/src/main/java/rest/entities/DataRepositories.java +++ /dev/null @@ -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 listExternalDataRepositories(@RequestParam(value="query", required=false) String query ){ - try { - List> 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 listDataRepositories(){ - try { - List 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 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 getAllDataRepositories(){ - - try { - List allDataRepositories = dataRepositoryDao.getAll(); - - return new ResponseEntity(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 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 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!\"}"); - } - - } - - -} - diff --git a/dmp-backend/src/main/java/rest/entities/DatasetProfiles.java b/dmp-backend/src/main/java/rest/entities/DatasetProfiles.java deleted file mode 100644 index a510c1ebe..000000000 --- a/dmp-backend/src/main/java/rest/entities/DatasetProfiles.java +++ /dev/null @@ -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 listDMPs(){ - try { - List 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 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 getAllDatasetProfiles(){ - - try { - List allDatasetProfiles = datasetProfileDao.getAll(); - return new ResponseEntity(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 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 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 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!\"}"); - } - - } - - - - -} - diff --git a/dmp-backend/src/main/java/rest/entities/Datasets.java b/dmp-backend/src/main/java/rest/entities/Datasets.java deleted file mode 100644 index f81b2092b..000000000 --- a/dmp-backend/src/main/java/rest/entities/Datasets.java +++ /dev/null @@ -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 listDatasets(){ - try { - List 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 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 getAllDatasets(){ - - try { - List allDatasets = datasetDao.getAll(); - return new ResponseEntity(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 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 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 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 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 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 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(); - } - - } - - - - - - -} - diff --git a/dmp-backend/src/main/java/rest/entities/DmpProfiles.java b/dmp-backend/src/main/java/rest/entities/DmpProfiles.java deleted file mode 100644 index 18f845fe6..000000000 --- a/dmp-backend/src/main/java/rest/entities/DmpProfiles.java +++ /dev/null @@ -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 listDmpProfiles(){ - try { - List 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 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 listLabelIds(){ - try { - List 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 getAllDmpProfiles(){ - try { - List allDmpProfiles = dMPProfileDao.getAll(); - return new ResponseEntity(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 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 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!\"}"); - } - - } - - - - -} - diff --git a/dmp-backend/src/main/java/rest/entities/Organisations.java b/dmp-backend/src/main/java/rest/entities/Organisations.java deleted file mode 100644 index b2e48c65b..000000000 --- a/dmp-backend/src/main/java/rest/entities/Organisations.java +++ /dev/null @@ -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 listExternalOrganisations(@RequestParam(value="query", required=false) String query ){ - try { - List> 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 listOrganisations(){ - try { - List 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 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 getAllOrganisations(){ - try { - List allOrganisations = organisationDao.getAll(); - return new ResponseEntity(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 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 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!\"}"); - } - - } - - - - - -} - diff --git a/dmp-backend/src/main/java/rest/entities/Projects.java b/dmp-backend/src/main/java/rest/entities/Projects.java deleted file mode 100644 index 636041c01..000000000 --- a/dmp-backend/src/main/java/rest/entities/Projects.java +++ /dev/null @@ -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 listExternalProjects(@RequestParam(value="query", required=false) String query ){ - try { - List> 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 listProjects(){ - try { - List 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 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 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 listLabelIds(){ - try { - List 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 getAllProjects(){ - try { - List allProjects = projectDao.getAll(); - return new ResponseEntity(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 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 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 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 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 getProjectDmps(@RequestBody Project project) { - try { - Set 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 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 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 userProjects = new HashMap(); - - 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 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 users = new HashSet(); -// 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 updateProjectOfUser(@RequestBody Project project){ -// -// if(project.getId()==null) -// return ResponseEntity.status(HttpStatus.NOT_MODIFIED).body("Cannot update, id was null"); -// return setProject(project); -// -// } - - - - - -} - diff --git a/dmp-backend/src/main/java/rest/entities/Registries.java b/dmp-backend/src/main/java/rest/entities/Registries.java deleted file mode 100644 index 8895005cd..000000000 --- a/dmp-backend/src/main/java/rest/entities/Registries.java +++ /dev/null @@ -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 listExternalRegistries(@RequestParam(value="query", required=false) String query ){ - try { - List> 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 listRegistries(){ - try { - List 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 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 listLabelIds(){ - try { - List 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 getAllRegistries(){ - try { - List allRegistries = registryDao.getAll(); - - return new ResponseEntity(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 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 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!\"}"); - } - - } - - - - - -} - diff --git a/dmp-backend/src/main/java/rest/entities/Researchers.java b/dmp-backend/src/main/java/rest/entities/Researchers.java deleted file mode 100644 index 9355e8c49..000000000 --- a/dmp-backend/src/main/java/rest/entities/Researchers.java +++ /dev/null @@ -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 listExternalResearchers(@RequestParam(value="query", required=false) String query ){ - try { - List> 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 listResearchers(){ - try { - List 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 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 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 getAllResearchers(){ - try { - List allResearchers = researcherDao.getAll(); - - return new ResponseEntity(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 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 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!\"}"); - } - - } - - - - -} - diff --git a/dmp-backend/src/main/java/rest/entities/Services.java b/dmp-backend/src/main/java/rest/entities/Services.java deleted file mode 100644 index 7de1362cb..000000000 --- a/dmp-backend/src/main/java/rest/entities/Services.java +++ /dev/null @@ -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 listExternalServices(@RequestParam(value="query", required=false) String query ){ - try { - List> 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 listServices(){ - try { - List 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 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 getAllServices(){ - try { - List allServices = serviceDao.getAll(); - - return new ResponseEntity(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 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 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!\"}"); - } - - } - - - - -} - diff --git a/dmp-backend/src/main/java/rest/entities/Users.java b/dmp-backend/src/main/java/rest/entities/Users.java deleted file mode 100644 index 8f51edfd1..000000000 --- a/dmp-backend/src/main/java/rest/entities/Users.java +++ /dev/null @@ -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 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(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 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(SerializerProvider.toJson(userInfo), HttpStatus.OK); - } - catch(Exception ex) { - ex.printStackTrace(); - return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - - - - - - - - -} -