2017-10-12 14:04:38 +02:00
|
|
|
package rest.entities;
|
2017-09-14 12:37:36 +02:00
|
|
|
|
2017-10-27 12:52:12 +02:00
|
|
|
|
2017-12-09 23:31:07 +01:00
|
|
|
import java.util.*;
|
2017-10-06 19:20:05 +02:00
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import javax.transaction.Transactional;
|
2017-09-14 12:37:36 +02:00
|
|
|
|
2017-12-09 23:31:07 +01:00
|
|
|
import models.criteria.DataRepositoryCriteria;
|
|
|
|
import models.criteria.OrganisationCriteria;
|
|
|
|
import models.criteria.ResearcherCriteria;
|
|
|
|
import models.criteria.ServiceCriteria;
|
|
|
|
import models.dmp.DataManagementPlan;
|
2017-12-14 18:07:09 +01:00
|
|
|
import models.dmp.DataManagementPlanTableRequest;
|
|
|
|
import models.helpers.DataTableData;
|
|
|
|
import models.project.ProjectTableRequest;
|
|
|
|
|
2017-09-14 12:37:36 +02:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
2017-10-20 17:11:40 +02:00
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
2017-09-14 12:37:36 +02:00
|
|
|
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.ResponseBody;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
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;
|
2017-10-20 17:11:40 +02:00
|
|
|
import dao.entities.UserInfoDao;
|
2017-09-14 12:37:36 +02:00
|
|
|
import entities.DMP;
|
|
|
|
import entities.Dataset;
|
2017-12-14 18:07:09 +01:00
|
|
|
import entities.Project;
|
2017-10-20 17:11:40 +02:00
|
|
|
import entities.UserInfo;
|
2017-10-04 11:48:21 +02:00
|
|
|
import entities.responses.IDLabelPair;
|
2017-10-20 17:11:40 +02:00
|
|
|
import helpers.SerializerProvider;
|
2017-12-14 18:07:09 +01:00
|
|
|
import managers.DataManagementPlanManager;
|
|
|
|
import managers.ProjectManager;
|
2017-12-09 23:31:07 +01:00
|
|
|
import utilities.builders.DomainModelConverter;
|
2017-09-14 12:37:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@CrossOrigin
|
2017-10-04 11:48:21 +02:00
|
|
|
public class DMPs {
|
2017-09-14 12:37:36 +02:00
|
|
|
|
|
|
|
@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;
|
2017-10-20 17:11:40 +02:00
|
|
|
@Autowired private UserInfoDao userInfoDao;
|
2017-09-14 12:37:36 +02:00
|
|
|
|
|
|
|
|
2017-09-27 18:15:39 +02:00
|
|
|
|
2017-09-14 12:37:36 +02:00
|
|
|
// FETCH BY DMP(S)
|
|
|
|
|
2017-12-14 18:07:09 +01:00
|
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.POST, value = { "/dmps/getPaged" }, consumes = "application/json", produces="application/json")
|
|
|
|
public @ResponseBody ResponseEntity<DataTableData<models.dmp.DataManagementPlan>> getPaged(@RequestBody DataManagementPlanTableRequest dataManagementPlanTableRequest) {
|
|
|
|
try {
|
|
|
|
DataTableData<models.dmp.DataManagementPlan> dataTable = new DataManagementPlanManager().getPaged(dMPDao, dataManagementPlanTableRequest);
|
|
|
|
|
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(dataTable);
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/dmps/getSingle/{id}" }, produces="application/json")
|
|
|
|
public @ResponseBody ResponseEntity<models.dmp.DataManagementPlan> getPaged(@PathVariable String id) {
|
|
|
|
try {
|
|
|
|
models.dmp.DataManagementPlan project = new DataManagementPlanManager().getSingle(dMPDao, id);
|
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(project);
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@RequestMapping(method = RequestMethod.POST, value = { "/dmps/add" }, consumes = "application/json", produces="application/json")
|
|
|
|
public @ResponseBody ResponseEntity<entities.DMP> addDmp(@RequestBody models.dmp.DataManagementPlan dataManagementPlan) {
|
|
|
|
entities.DMP createdProject = dMPDao.update(dataManagementPlan.toDataModel());
|
|
|
|
return ResponseEntity.status(HttpStatus.CREATED).body(createdProject);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-10-06 19:20:05 +02:00
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/dmps" }, produces="text/plain")
|
2017-09-14 12:37:36 +02:00
|
|
|
public @ResponseBody ResponseEntity<Object> listDMPs(){
|
|
|
|
try {
|
|
|
|
List<UUID> allIDs = dMPDao.listAllIDs();
|
2017-10-27 12:52:12 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDs));
|
2017-09-14 12:37:36 +02:00
|
|
|
}
|
|
|
|
catch(Exception ex) {
|
2017-10-27 12:52:12 +02:00
|
|
|
ex.printStackTrace();
|
2017-09-14 12:37:36 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
|
|
|
}
|
|
|
|
}
|
2017-10-04 11:48:21 +02:00
|
|
|
|
2017-10-06 19:20:05 +02:00
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/dmps/{id}" }, produces="application/json")
|
|
|
|
public @ResponseBody ResponseEntity<Object> getDMP(@PathVariable("id") String id){
|
2017-10-04 11:48:21 +02:00
|
|
|
try {
|
2017-10-06 19:20:05 +02:00
|
|
|
DMP dmp = dMPDao.read(UUID.fromString(id));
|
2017-12-09 23:31:07 +01:00
|
|
|
DataManagementPlan dataManagementPlan = new DataManagementPlan();
|
|
|
|
dataManagementPlan.fromDataModel(dmp);
|
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(dataManagementPlan);
|
2017-10-04 11:48:21 +02:00
|
|
|
}
|
|
|
|
catch(Exception ex) {
|
2017-10-20 17:11:40 +02:00
|
|
|
ex.printStackTrace();
|
2017-10-06 19:20:05 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Erroneous input: "+ex.getMessage());
|
2017-10-04 11:48:21 +02:00
|
|
|
}
|
|
|
|
}
|
2017-09-14 12:37:36 +02:00
|
|
|
|
2017-10-06 19:20:05 +02:00
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/dmp/listDMPLabelID" }, produces="text/plain")
|
|
|
|
public @ResponseBody ResponseEntity<Object> listDmpLabelID(){
|
2017-09-14 12:37:36 +02:00
|
|
|
try {
|
2017-10-06 19:20:05 +02:00
|
|
|
List<IDLabelPair> allIDLabels = dMPDao.listAllIDsLabels();
|
2017-10-27 12:52:12 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(allIDLabels));
|
2017-09-14 12:37:36 +02:00
|
|
|
}
|
|
|
|
catch(Exception ex) {
|
2017-10-27 12:52:12 +02:00
|
|
|
ex.printStackTrace();
|
2017-10-06 19:20:05 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
2017-09-14 12:37:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This should be called on extreme cases. It's computationally intensive
|
|
|
|
*/
|
2017-10-06 19:20:05 +02:00
|
|
|
@RequestMapping(method = RequestMethod.GET, value = { "/dmp/getAll" }, produces="application/json")
|
2017-09-14 12:37:36 +02:00
|
|
|
public @ResponseBody ResponseEntity<Object> getAllDMPs(){
|
2017-10-20 17:11:40 +02:00
|
|
|
|
2017-09-14 12:37:36 +02:00
|
|
|
try {
|
|
|
|
List<DMP> allDMPs = dMPDao.getAll();
|
2017-10-27 12:52:12 +02:00
|
|
|
return new ResponseEntity<Object>(SerializerProvider.toJson(allDMPs), HttpStatus.OK);
|
2017-09-14 12:37:36 +02:00
|
|
|
}
|
|
|
|
catch(Exception ex) {
|
2017-10-24 18:33:51 +02:00
|
|
|
ex.printStackTrace();
|
2017-10-06 19:20:05 +02:00
|
|
|
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
2017-09-14 12:37:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-06 19:20:05 +02:00
|
|
|
@Transactional
|
|
|
|
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/create" }, consumes = "application/json", produces="application/json")
|
2017-10-23 18:06:24 +02:00
|
|
|
public @ResponseBody ResponseEntity<Object> createDMP(@RequestBody DMP dmp) {
|
2017-10-06 19:20:05 +02:00
|
|
|
try {
|
2017-10-27 12:52:12 +02:00
|
|
|
DMP createdDmp = dMPDao.update(dmp);
|
|
|
|
return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(createdDmp));
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
2017-10-06 19:20:05 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not create DMP!\"");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-10-23 18:06:24 +02:00
|
|
|
@Transactional
|
|
|
|
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/update" }, consumes = "application/json", produces="application/json")
|
2017-12-11 10:48:18 +01:00
|
|
|
public @ResponseBody ResponseEntity<Object> updateDMP(@RequestBody DataManagementPlan dataManagementPlan) {
|
2017-11-02 15:25:05 +01:00
|
|
|
|
2017-12-11 10:48:18 +01:00
|
|
|
DMP newDmp = dataManagementPlan.toDataModel();
|
|
|
|
if(newDmp.getOrganisations()!=null&&!newDmp.getOrganisations().isEmpty()){
|
|
|
|
for(entities.Organisation organisation: newDmp.getOrganisations()){
|
|
|
|
OrganisationCriteria criteria = new OrganisationCriteria();
|
|
|
|
criteria.setLike(organisation.getReference());
|
|
|
|
List<entities.Organisation> entries = this.organisationDao.listBy(criteria);
|
|
|
|
if(entries!=null&&!entries.isEmpty())organisation.setId(entries.get(0).getId());
|
|
|
|
else organisation = this.organisationDao.create(organisation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(newDmp.getResearchers()!=null&&!newDmp.getResearchers().isEmpty()){
|
|
|
|
for(entities.Researcher researcher : newDmp.getResearchers()){
|
|
|
|
ResearcherCriteria criteria = new ResearcherCriteria();
|
|
|
|
criteria.setLike(researcher.getReference());
|
|
|
|
List<entities.Researcher> entries = this.researcherDao.listBy(criteria);
|
|
|
|
if(entries!=null&&!entries.isEmpty())researcher.setId(entries.get(0).getId());
|
|
|
|
else researcher = this.researcherDao.create(researcher);
|
|
|
|
}
|
|
|
|
}
|
2017-11-03 18:55:04 +01:00
|
|
|
|
2017-12-11 10:48:18 +01:00
|
|
|
DMP previousDmp = dMPDao.read(dataManagementPlan.getId());
|
|
|
|
previousDmp.setResearchers(newDmp.getResearchers());
|
|
|
|
previousDmp.setOrganisations(newDmp.getOrganisations());
|
|
|
|
previousDmp.setLabel(dataManagementPlan.getLabel());
|
|
|
|
previousDmp.setVersion(dataManagementPlan.getVersion());
|
|
|
|
previousDmp.setStatus((short)dataManagementPlan.getStatus());
|
|
|
|
//if(!previousDmp.getProject().getId().equals(newDmp.getProject().getId()))previousDmp.setProject(projectDao.read(newDmp.getProject().getId()));
|
2017-11-03 18:55:04 +01:00
|
|
|
|
2017-10-23 18:06:24 +02:00
|
|
|
try {
|
2017-12-11 10:48:18 +01:00
|
|
|
DMP updatedDMP = dMPDao.update(previousDmp);
|
2017-10-27 12:52:12 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(updatedDMP));
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
2017-10-23 18:06:24 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not update DMP!\"");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-20 17:11:40 +02:00
|
|
|
|
2017-09-14 12:37:36 +02:00
|
|
|
|
2017-10-24 18:33:51 +02:00
|
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/getdatasets" }, consumes = "application/json", produces="application/json")
|
|
|
|
public @ResponseBody ResponseEntity<Object> getDatasetsOfDMP(@RequestBody DMP dmp) {
|
|
|
|
try {
|
2017-11-02 15:25:05 +01:00
|
|
|
List<Dataset> datasets = datasetDao.getDatasetsOfDmp(dmp.getId());
|
2017-10-27 12:52:12 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(datasets));
|
|
|
|
} catch (Exception e) {
|
2017-10-24 18:33:51 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not get datasets of DMP!\"");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-06 19:20:05 +02:00
|
|
|
@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) {
|
2017-10-20 12:03:55 +02:00
|
|
|
e.printStackTrace();
|
2017-10-06 19:20:05 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete DMP!\"");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-02 17:41:24 +01:00
|
|
|
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/softdelete" }, consumes = "application/json", produces="text/plain")
|
|
|
|
public @ResponseBody ResponseEntity<Object> softDelete(@RequestBody DMP dmp) {
|
|
|
|
|
2017-12-11 10:48:18 +01:00
|
|
|
try{
|
|
|
|
DMP d = dMPDao.read(dmp.getId());
|
|
|
|
d.setStatus(new Short("-1"));
|
|
|
|
dMPDao.update(d);
|
2017-12-11 12:20:48 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body("{\"msg\":\"deleted DMP!\"");
|
2017-11-02 17:41:24 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not soft delete DMP!\"");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-10-06 19:20:05 +02:00
|
|
|
|
|
|
|
|
2017-10-23 18:06:24 +02:00
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
//// 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 {
|
2017-11-17 01:43:16 +01:00
|
|
|
//List<DMP> nonDeleted = userInfoDao.getDmpsOfUser(userID);
|
|
|
|
List<DMP> nonDeleted = dMPDao.getDMPsOfUser(userID);
|
2017-11-07 13:20:13 +01:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(nonDeleted));
|
2017-10-23 18:06:24 +02:00
|
|
|
}
|
|
|
|
catch(Exception ex) {
|
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
|
|
|
}
|
|
|
|
|
2017-09-14 12:37:36 +02:00
|
|
|
}
|
|
|
|
|
2017-11-02 15:25:05 +01:00
|
|
|
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/createofuser" }, produces="text/plain", consumes = "application/json")
|
2017-12-09 23:31:07 +01:00
|
|
|
public @ResponseBody ResponseEntity<Object> createDmpOfUser(@RequestBody DataManagementPlan dataManagementPlan){
|
2017-10-23 18:06:24 +02:00
|
|
|
|
2017-10-27 12:52:12 +02:00
|
|
|
|
|
|
|
String userID = null;
|
2017-10-23 18:06:24 +02:00
|
|
|
try {
|
2017-10-27 12:52:12 +02:00
|
|
|
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");
|
2017-10-23 18:06:24 +02:00
|
|
|
}
|
|
|
|
|
2017-10-27 12:52:12 +02:00
|
|
|
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");
|
2017-10-23 18:06:24 +02:00
|
|
|
|
|
|
|
try {
|
2017-12-09 23:31:07 +01:00
|
|
|
DMP dmp = dataManagementPlan.toDataModel();
|
|
|
|
|
|
|
|
if(dmp.getOrganisations()!=null&&!dmp.getOrganisations().isEmpty()){
|
|
|
|
for(entities.Organisation organisation: dmp.getOrganisations()){
|
|
|
|
OrganisationCriteria criteria = new OrganisationCriteria();
|
|
|
|
criteria.setLike(organisation.getReference());
|
|
|
|
List<entities.Organisation> entries = this.organisationDao.listBy(criteria);
|
|
|
|
if(entries!=null&&!entries.isEmpty())organisation.setId(entries.get(0).getId());
|
|
|
|
else organisation = this.organisationDao.create(organisation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dmp.getResearchers()!=null&&!dmp.getResearchers().isEmpty()){
|
|
|
|
for(entities.Researcher researcher : dmp.getResearchers()){
|
|
|
|
ResearcherCriteria criteria = new ResearcherCriteria();
|
|
|
|
criteria.setLike(researcher.getReference());
|
|
|
|
List<entities.Researcher> entries = this.researcherDao.listBy(criteria);
|
|
|
|
if(entries!=null&&!entries.isEmpty())researcher.setId(entries.get(0).getId());
|
|
|
|
else researcher = this.researcherDao.create(researcher);
|
|
|
|
}
|
|
|
|
}
|
2017-10-27 12:52:12 +02:00
|
|
|
dmp.setId(null);
|
2017-10-23 18:06:24 +02:00
|
|
|
|
2017-11-17 01:43:16 +01:00
|
|
|
dmp.setCreator(userInfo);
|
2017-12-09 23:31:07 +01:00
|
|
|
dmp.setProject(this.projectDao.read(dataManagementPlan.getProject().getId()));
|
2017-10-27 12:52:12 +02:00
|
|
|
Set<UserInfo> users = new HashSet<UserInfo>();
|
|
|
|
users.add(userInfo);
|
|
|
|
dmp.setUsers(users);
|
2017-10-23 18:06:24 +02:00
|
|
|
|
2017-11-03 18:55:04 +01:00
|
|
|
dmp.setCreated(new Date());
|
|
|
|
dmp.setModified(new Date());
|
|
|
|
dmp.setStatus(new Short("0"));
|
|
|
|
|
2017-10-27 12:52:12 +02:00
|
|
|
DMP newdmp = dMPDao.create(dmp);
|
2017-10-23 18:06:24 +02:00
|
|
|
|
2017-10-27 12:52:12 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(newdmp));
|
2017-10-23 18:06:24 +02:00
|
|
|
}
|
|
|
|
catch(Exception ex) {
|
2017-11-03 18:55:04 +01:00
|
|
|
ex.printStackTrace();
|
2017-10-23 18:06:24 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
|
2017-11-07 13:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@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());
|
|
|
|
|
2017-11-08 09:31:03 +01:00
|
|
|
|
2017-11-07 13:20:13 +01:00
|
|
|
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"));
|
|
|
|
|
2017-11-08 09:31:03 +01:00
|
|
|
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";
|
2017-11-07 13:20:13 +01:00
|
|
|
clone.setVersion(clone.getVersion()+1);
|
2017-11-08 09:31:03 +01:00
|
|
|
clone.setLabel(cloneLabel);
|
2017-11-07 13:20:13 +01:00
|
|
|
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());
|
2017-10-23 18:06:24 +02:00
|
|
|
}
|
|
|
|
|
2017-09-21 13:08:40 +02:00
|
|
|
}
|
2017-10-23 18:06:24 +02:00
|
|
|
|
|
|
|
|
2017-10-27 12:52:12 +02:00
|
|
|
@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());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2017-09-14 12:37:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-11-03 18:55:04 +01:00
|
|
|
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());
|
|
|
|
|
2017-11-02 15:25:05 +01:00
|
|
|
newone.setDataset(existing.getDataset());
|
|
|
|
newone.setOrganisations(existing.getOrganisations());
|
|
|
|
newone.setResearchers(existing.getResearchers());
|
|
|
|
newone.setUsers(existing.getUsers());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-14 12:37:36 +02:00
|
|
|
}
|
|
|
|
|