criteria application for queries with pagination

This commit is contained in:
ikalyvas 2017-12-17 23:34:24 +02:00
parent b0923b87d9
commit f3fdfa1dbf
47 changed files with 1454 additions and 1257 deletions

View File

@ -14,8 +14,7 @@ import eu.eudat.models.criteria.ResearcherCriteria;
import eu.eudat.models.dmp.DataManagementPlan;
import eu.eudat.models.dmp.DataManagementPlanTableRequest;
import eu.eudat.models.helpers.DataTableData;
import eu.eudat.models.responses.ResponseItem;
import eu.eudat.models.helpers.responses.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ -96,365 +95,365 @@ public class DMPs {
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/dmps/add" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<eu.eudat.entities.DMP> addDmp(@RequestBody eu.eudat.models.dmp.DataManagementPlan dataManagementPlan) {
eu.eudat.entities.DMP createdProject = dMPDao.update(dataManagementPlan.toDataModel());
eu.eudat.entities.DMP createdProject = dMPDao.createOrUpdate(dataManagementPlan.toDataModel());
return ResponseEntity.status(HttpStatus.CREATED).body(createdProject);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@RequestMapping(method = RequestMethod.GET, value = { "/dmps" }, produces="text/plain")
public @ResponseBody ResponseEntity<List<UUID>> listDMPs(){
try {
List<UUID> allIDs = dMPDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(allIDs);
}
catch(Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/dmps/{id}" }, produces="application/json")
public @ResponseBody ResponseEntity<DataManagementPlan> getDMP(@PathVariable("id") String id){
try {
DMP dmp = dMPDao.read(UUID.fromString(id));
DataManagementPlan dataManagementPlan = new DataManagementPlan();
dataManagementPlan.fromDataModel(dmp);
return ResponseEntity.status(HttpStatus.OK).body(dataManagementPlan);
}
catch(Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/dmp/listDMPLabelID" }, produces="text/plain")
public @ResponseBody ResponseEntity<List<IDLabelPair>> listDmpLabelID(){
try {
List<IDLabelPair> allIDLabels = dMPDao.listAllIDsLabels();
return ResponseEntity.status(HttpStatus.OK).body(allIDLabels);
}
catch(Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
/**
* This should be called on extreme cases. It's computationally intensive
*/
@RequestMapping(method = RequestMethod.GET, value = { "/dmp/getAll" }, produces="application/json")
public @ResponseBody ResponseEntity<Object> getAllDMPs(){
try {
List<DMP> allDMPs = dMPDao.getAll();
return ResponseEntity.status(HttpStatus.OK).body(allDMPs);
}
catch(Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null );
}
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/create" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<DMP> createDMP(@RequestBody DMP dmp) {
try {
DMP createdDmp = dMPDao.update(dmp);
return ResponseEntity.status(HttpStatus.CREATED).body(createdDmp);
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/update" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<DMP> updateDMP(@RequestBody DataManagementPlan dataManagementPlan) {
DMP newDmp = dataManagementPlan.toDataModel();
if(newDmp.getOrganisations()!=null&&!newDmp.getOrganisations().isEmpty()){
for(eu.eudat.entities.Organisation organisation: newDmp.getOrganisations()){
OrganisationCriteria criteria = new OrganisationCriteria();
criteria.setLike(organisation.getReference());
List<eu.eudat.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(eu.eudat.entities.Researcher researcher : newDmp.getResearchers()){
ResearcherCriteria criteria = new ResearcherCriteria();
criteria.setLike(researcher.getReference());
List<eu.eudat.entities.Researcher> entries = this.researcherDao.listBy(criteria);
if(entries!=null&&!entries.isEmpty())researcher.setId(entries.get(0).getId());
else researcher = this.researcherDao.create(researcher);
}
}
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()));
try {
DMP updatedDMP = dMPDao.update(previousDmp);
return ResponseEntity.status(HttpStatus.CREATED).body(updatedDMP);
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/getdatasets" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<List<Dataset>> getDatasetsOfDMP(@RequestBody DMP dmp) {
try {
List<Dataset> datasets = datasetDao.getDatasetsOfDmp(dmp.getId());
return ResponseEntity.status(HttpStatus.OK).body(datasets);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/delete" }, consumes = "application/json", produces="text/plain")
public @ResponseBody ResponseEntity<Object> delete(@RequestBody DMP dmp) {
DMP d = new DMP();
d.setId(dmp.getId());
try {
dMPDao.delete(d);
return ResponseEntity.status(HttpStatus.CREATED).body("DELETED!");
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete DMP!\"");
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/softdelete" }, consumes = "application/json", produces="text/plain")
public @ResponseBody ResponseEntity<Object> softDelete(@RequestBody DMP dmp) {
try{
DMP d = dMPDao.read(dmp.getId());
d.setStatus(new Short("-1"));
dMPDao.update(d);
return ResponseEntity.status(HttpStatus.OK).body("{\"msg\":\"deleted 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<List<DMP>> getDmpsOfUser(){
String userID = null;
try {
userID = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
} catch(NullPointerException ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
try {
//List<DMP> nonDeleted = userInfoDao.getDmpsOfUser(userID);
List<DMP> nonDeleted = dMPDao.getDMPsOfUser(userID);
return ResponseEntity.status(HttpStatus.OK).body(nonDeleted);
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/createofuser" }, produces="text/plain", consumes = "application/json")
public @ResponseBody ResponseEntity<DMP> createDmpOfUser(@RequestBody DataManagementPlan dataManagementPlan){
String userID = null;
try {
userID = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
} catch(NullPointerException ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
UserInfo userInfo = userInfoDao.read(UUID.fromString(userID));
if(userInfo==null) //this should normally never happer
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
try {
DMP dmp = dataManagementPlan.toDataModel();
if(dmp.getOrganisations()!=null&&!dmp.getOrganisations().isEmpty()){
for(eu.eudat.entities.Organisation organisation: dmp.getOrganisations()){
OrganisationCriteria criteria = new OrganisationCriteria();
criteria.setLike(organisation.getReference());
List<eu.eudat.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(eu.eudat.entities.Researcher researcher : dmp.getResearchers()){
ResearcherCriteria criteria = new ResearcherCriteria();
criteria.setLike(researcher.getReference());
List<eu.eudat.entities.Researcher> entries = this.researcherDao.listBy(criteria);
if(entries!=null&&!entries.isEmpty())researcher.setId(entries.get(0).getId());
else researcher = this.researcherDao.create(researcher);
}
}
dmp.setId(null);
dmp.setCreator(userInfo);
dmp.setProject(this.projectDao.read(dataManagementPlan.getProject().getId()));
Set<UserInfo> users = new HashSet<UserInfo>();
users.add(userInfo);
dmp.setUsers(users);
dmp.setCreated(new Date());
dmp.setModified(new Date());
dmp.setStatus(new Short("0"));
DMP newdmp = dMPDao.create(dmp);
return ResponseEntity.status(HttpStatus.OK).body(newdmp);
}
catch(Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/cloneforuser" }, produces="text/plain", consumes = "application/json")
public @ResponseBody ResponseEntity<DMP> 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(null);
}
UserInfo userInfo = userInfoDao.read(UUID.fromString(userID));
if(userInfo==null) //this should normally never happer
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
DMP clone = dMPDao.read(dmp.getId());
try {
Set<UserInfo> users = new HashSet<UserInfo>();
users.add(userInfo);
clone.setUsers(users);
clone.setCreated(new Date());
clone.setModified(new Date());
clone.setStatus(new Short("0"));
String cloneLabel = dmp.getLabel();
if(cloneLabel==null || cloneLabel.isEmpty()) //if the provided label is null or empty, use parent's label + "_clone"
cloneLabel = clone.getLabel()+"_clone";
clone.setVersion(clone.getVersion()+1);
clone.setLabel(cloneLabel);
clone.setPrevious(clone.getId());
clone.setId(null);
clone = dMPDao.create(clone);
return ResponseEntity.status(HttpStatus.OK).body(clone);
}
catch(Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/dmp/adduser" }, produces="text/plain")
public @ResponseBody ResponseEntity<DMP> 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(null);
}
final UserInfo userInfo = userInfoDao.read(UUID.fromString(userID));
if(userInfo==null) //this should normally never happer
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
if(dmp==null || dmp.getId()==null)
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
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(updateddmp);
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
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());
}
// @RequestMapping(method = RequestMethod.GET, value = { "/dmps" }, produces="text/plain")
// public @ResponseBody ResponseEntity<List<UUID>> listDMPs(){
// try {
// List<UUID> allIDs = dMPDao.listAllIDs();
// return ResponseEntity.status(HttpStatus.OK).body(allIDs);
// }
// catch(Exception ex) {
// ex.printStackTrace();
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
// }
// }
//
// @RequestMapping(method = RequestMethod.GET, value = { "/dmps/{id}" }, produces="application/json")
// public @ResponseBody ResponseEntity<DataManagementPlan> getDMP(@PathVariable("id") String id){
// try {
// DMP dmp = dMPDao.read(UUID.fromString(id));
// DataManagementPlan dataManagementPlan = new DataManagementPlan();
// dataManagementPlan.fromDataModel(dmp);
// return ResponseEntity.status(HttpStatus.OK).body(dataManagementPlan);
// }
// catch(Exception ex) {
// ex.printStackTrace();
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
// }
// }
//
// @RequestMapping(method = RequestMethod.GET, value = { "/dmp/listDMPLabelID" }, produces="text/plain")
// public @ResponseBody ResponseEntity<List<IDLabelPair>> listDmpLabelID(){
// try {
// List<IDLabelPair> allIDLabels = dMPDao.listAllIDsLabels();
// return ResponseEntity.status(HttpStatus.OK).body(allIDLabels);
// }
// catch(Exception ex) {
// ex.printStackTrace();
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
// }
// }
//
//
// /**
// * This should be called on extreme cases. It's computationally intensive
// */
// @RequestMapping(method = RequestMethod.GET, value = { "/dmp/getAll" }, produces="application/json")
// public @ResponseBody ResponseEntity<Object> getAllDMPs(){
//
// try {
// List<DMP> allDMPs = dMPDao.getAll();
// return ResponseEntity.status(HttpStatus.OK).body(allDMPs);
// }
// catch(Exception ex) {
// ex.printStackTrace();
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null );
// }
// }
//
//
// @Transactional
// @RequestMapping(method = RequestMethod.POST, value = { "/dmp/create" }, consumes = "application/json", produces="application/json")
// public @ResponseBody ResponseEntity<DMP> createDMP(@RequestBody DMP dmp) {
// try {
// DMP createdDmp = dMPDao.update(dmp);
// return ResponseEntity.status(HttpStatus.CREATED).body(createdDmp);
// } catch (Exception e) {
// e.printStackTrace();
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
// }
//
// }
//
// @Transactional
// @RequestMapping(method = RequestMethod.POST, value = { "/dmp/update" }, consumes = "application/json", produces="application/json")
// public @ResponseBody ResponseEntity<DMP> updateDMP(@RequestBody DataManagementPlan dataManagementPlan) {
//
// DMP newDmp = dataManagementPlan.toDataModel();
// if(newDmp.getOrganisations()!=null&&!newDmp.getOrganisations().isEmpty()){
// for(eu.eudat.entities.Organisation organisation: newDmp.getOrganisations()){
// OrganisationCriteria criteria = new OrganisationCriteria();
// criteria.setLike(organisation.getReference());
// List<eu.eudat.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(eu.eudat.entities.Researcher researcher : newDmp.getResearchers()){
// ResearcherCriteria criteria = new ResearcherCriteria();
// criteria.setLike(researcher.getReference());
// List<eu.eudat.entities.Researcher> entries = this.researcherDao.listBy(criteria);
// if(entries!=null&&!entries.isEmpty())researcher.setId(entries.get(0).getId());
// else researcher = this.researcherDao.create(researcher);
// }
// }
//
// 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()));
//
// try {
// DMP updatedDMP = dMPDao.update(previousDmp);
// return ResponseEntity.status(HttpStatus.CREATED).body(updatedDMP);
// } catch (Exception e) {
// e.printStackTrace();
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
// }
//
// }
//
//
//
//
//
// @RequestMapping(method = RequestMethod.POST, value = { "/dmp/getdatasets" }, consumes = "application/json", produces="application/json")
// public @ResponseBody ResponseEntity<List<Dataset>> getDatasetsOfDMP(@RequestBody DMP dmp) {
// try {
// List<Dataset> datasets = datasetDao.getDatasetsOfDmp(dmp.getId());
// return ResponseEntity.status(HttpStatus.OK).body(datasets);
// } catch (Exception e) {
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
// }
//
// }
//
//
//
// @RequestMapping(method = RequestMethod.POST, value = { "/dmp/delete" }, consumes = "application/json", produces="text/plain")
// public @ResponseBody ResponseEntity<Object> delete(@RequestBody DMP dmp) {
//
// DMP d = new DMP();
// d.setId(dmp.getId());
// try {
// dMPDao.delete(d);
// return ResponseEntity.status(HttpStatus.CREATED).body("DELETED!");
// } catch (Exception e) {
// e.printStackTrace();
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not Delete DMP!\"");
// }
//
// }
//
// @RequestMapping(method = RequestMethod.POST, value = { "/dmp/softdelete" }, consumes = "application/json", produces="text/plain")
// public @ResponseBody ResponseEntity<Object> softDelete(@RequestBody DMP dmp) {
//
// try{
// DMP d = dMPDao.read(dmp.getId());
// d.setStatus(new Short("-1"));
// dMPDao.update(d);
// return ResponseEntity.status(HttpStatus.OK).body("{\"msg\":\"deleted 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<List<DMP>> getDmpsOfUser(){
//
// String userID = null;
// try {
// userID = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
// } catch(NullPointerException ex) {
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
// }
//
// try {
// //List<DMP> nonDeleted = userInfoDao.getDmpsOfUser(userID);
// List<DMP> nonDeleted = dMPDao.getDMPsOfUser(userID);
// return ResponseEntity.status(HttpStatus.OK).body(nonDeleted);
// }
// catch(Exception ex) {
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
// }
//
// }
//
// @RequestMapping(method = RequestMethod.POST, value = { "/dmp/createofuser" }, produces="text/plain", consumes = "application/json")
// public @ResponseBody ResponseEntity<DMP> createDmpOfUser(@RequestBody DataManagementPlan dataManagementPlan){
//
//
// String userID = null;
// try {
// userID = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
// } catch(NullPointerException ex) {
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
// }
//
// UserInfo userInfo = userInfoDao.read(UUID.fromString(userID));
//
// if(userInfo==null) //this should normally never happer
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
//
// try {
// DMP dmp = dataManagementPlan.toDataModel();
//
// if(dmp.getOrganisations()!=null&&!dmp.getOrganisations().isEmpty()){
// for(eu.eudat.entities.Organisation organisation: dmp.getOrganisations()){
// OrganisationCriteria criteria = new OrganisationCriteria();
// criteria.setLike(organisation.getReference());
// List<eu.eudat.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(eu.eudat.entities.Researcher researcher : dmp.getResearchers()){
// ResearcherCriteria criteria = new ResearcherCriteria();
// criteria.setLike(researcher.getReference());
// List<eu.eudat.entities.Researcher> entries = this.researcherDao.listBy(criteria);
// if(entries!=null&&!entries.isEmpty())researcher.setId(entries.get(0).getId());
// else researcher = this.researcherDao.create(researcher);
// }
// }
// dmp.setId(null);
//
// dmp.setCreator(userInfo);
// dmp.setProject(this.projectDao.read(dataManagementPlan.getProject().getId()));
// Set<UserInfo> users = new HashSet<UserInfo>();
// users.add(userInfo);
// dmp.setUsers(users);
//
// dmp.setCreated(new Date());
// dmp.setModified(new Date());
// dmp.setStatus(new Short("0"));
//
// DMP newdmp = dMPDao.create(dmp);
//
// return ResponseEntity.status(HttpStatus.OK).body(newdmp);
// }
// catch(Exception ex) {
// ex.printStackTrace();
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
// }
//
// }
//
// @RequestMapping(method = RequestMethod.POST, value = { "/dmp/cloneforuser" }, produces="text/plain", consumes = "application/json")
// public @ResponseBody ResponseEntity<DMP> 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(null);
// }
//
// UserInfo userInfo = userInfoDao.read(UUID.fromString(userID));
//
// if(userInfo==null) //this should normally never happer
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
//
// DMP clone = dMPDao.read(dmp.getId());
//
//
// try {
//
// Set<UserInfo> users = new HashSet<UserInfo>();
// users.add(userInfo);
// clone.setUsers(users);
//
// clone.setCreated(new Date());
// clone.setModified(new Date());
// clone.setStatus(new Short("0"));
//
// String cloneLabel = dmp.getLabel();
// if(cloneLabel==null || cloneLabel.isEmpty()) //if the provided label is null or empty, use parent's label + "_clone"
// cloneLabel = clone.getLabel()+"_clone";
// clone.setVersion(clone.getVersion()+1);
// clone.setLabel(cloneLabel);
// clone.setPrevious(clone.getId());
//
//
// clone.setId(null);
//
// clone = dMPDao.create(clone);
//
// return ResponseEntity.status(HttpStatus.OK).body(clone);
// }
// catch(Exception ex) {
// ex.printStackTrace();
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
// }
//
// }
//
//
// @RequestMapping(method = RequestMethod.POST, value = { "/dmp/adduser" }, produces="text/plain")
// public @ResponseBody ResponseEntity<DMP> 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(null);
// }
//
// final UserInfo userInfo = userInfoDao.read(UUID.fromString(userID));
//
// if(userInfo==null) //this should normally never happer
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
//
// if(dmp==null || dmp.getId()==null)
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
//
// 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(updateddmp);
// }
// catch(Exception ex) {
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
// }
//
// }
//
//
//
//
// private static void addNullAndForeignElems(DMP existing, DMP newone) {
//
// newone.setModified(new Date());
// if(newone.getStatus()==null)
// newone.setStatus(existing.getStatus());
// if(newone.getCreated()==null)
// newone.setCreated(existing.getCreated());
//
// newone.setDataset(existing.getDataset());
// newone.setOrganisations(existing.getOrganisations());
// newone.setResearchers(existing.getResearchers());
// newone.setUsers(existing.getUsers());
// }
}

View File

@ -1,34 +1,18 @@
package eu.eudat.controllers;
import java.util.Map;
import java.util.UUID;
import eu.eudat.models.responses.ResponseItem;
import eu.eudat.models.helpers.responses.ResponseItem;
import eu.eudat.models.security.Principal;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import eu.eudat.dao.entities.DMPDao;
import eu.eudat.dao.entities.DMPProfileDao;
import eu.eudat.dao.entities.DataRepositoryDao;
import eu.eudat.dao.entities.DatasetDao;
import eu.eudat.dao.entities.DatasetProfileDao;
import eu.eudat.dao.entities.DatasetProfileRulesetDao;
import eu.eudat.dao.entities.DatasetProfileViewstyleDao;
import eu.eudat.dao.entities.OrganisationDao;
import eu.eudat.dao.entities.ProjectDao;
import eu.eudat.dao.entities.RegistryDao;
import eu.eudat.dao.entities.ResearcherDao;
import eu.eudat.dao.entities.ServiceDao;
import eu.eudat.managers.DashBoardManager;
import eu.eudat.managers.UserManager;
import eu.eudat.models.dashboard.DashBoardStatistics;
@RestController

View File

@ -76,73 +76,73 @@ public class DataRepositories {
// MANAGE DATAREPOSITORy(IES)
@RequestMapping(method = RequestMethod.GET, value = { "/datarepos" })
public @ResponseBody ResponseEntity<List<UUID>> listDataRepositories(){
try {
List<UUID> allIDs = dataRepositoryDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(allIDs);
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/datarepos/{id}" })
public @ResponseBody ResponseEntity<DataRepository> getDataRepository(@PathVariable("id") String id) {
try {
DataRepository dataRepository = dataRepositoryDao.read(UUID.fromString(id));
return ResponseEntity.status(HttpStatus.OK).body(dataRepository);
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/datarepo/getAll" }, produces="application/json")
public @ResponseBody ResponseEntity<List<DataRepository>> getAllDataRepositories(){
try {
List<DataRepository> allDataRepositories = dataRepositoryDao.getAll();
return ResponseEntity.status(HttpStatus.OK).body(allDataRepositories);
}
catch(Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/datarepo/create" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<DataRepository> setOrganisation(@RequestBody DataRepository dataRepository) {
try {
DataRepository createdDataRepository = dataRepositoryDao.update(dataRepository);
return ResponseEntity.status(HttpStatus.CREATED).body(createdDataRepository);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/datarepo/delete" }, consumes = "application/json", produces="text/plain")
public @ResponseBody ResponseEntity<Object> delete(@RequestBody DataRepository dataRepository) {
DataRepository dr = new DataRepository();
dr.setId(dataRepository.getId());
try {
dataRepositoryDao.delete(dr);
return ResponseEntity.status(HttpStatus.CREATED).body("{\"msg\":\"Deleted data repository!\"}");
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not delete data repository!\"}");
}
}
// @RequestMapping(method = RequestMethod.GET, value = { "/datarepos" })
// public @ResponseBody ResponseEntity<List<UUID>> listDataRepositories(){
// try {
// List<UUID> allIDs = dataRepositoryDao.listAllIDs();
// return ResponseEntity.status(HttpStatus.OK).body(allIDs);
// }
// catch(Exception ex) {
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
// }
// }
//
//
// @RequestMapping(method = RequestMethod.GET, value = { "/datarepos/{id}" })
// public @ResponseBody ResponseEntity<DataRepository> getDataRepository(@PathVariable("id") String id) {
// try {
// DataRepository dataRepository = dataRepositoryDao.read(UUID.fromString(id));
// return ResponseEntity.status(HttpStatus.OK).body(dataRepository);
// }
// catch(Exception ex) {
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
// }
// }
//
//
//
// @RequestMapping(method = RequestMethod.GET, value = { "/datarepo/getAll" }, produces="application/json")
// public @ResponseBody ResponseEntity<List<DataRepository>> getAllDataRepositories(){
//
// try {
// List<DataRepository> allDataRepositories = dataRepositoryDao.getAll();
//
// return ResponseEntity.status(HttpStatus.OK).body(allDataRepositories);
//
// }
// catch(Exception ex) {
// ex.printStackTrace();
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
// }
//
// }
//
//
// @Transactional
// @RequestMapping(method = RequestMethod.POST, value = { "/datarepo/create" }, consumes = "application/json", produces="application/json")
// public @ResponseBody ResponseEntity<DataRepository> setOrganisation(@RequestBody DataRepository dataRepository) {
// try {
// DataRepository createdDataRepository = dataRepositoryDao.update(dataRepository);
// return ResponseEntity.status(HttpStatus.CREATED).body(createdDataRepository);
// } catch (Exception e) {
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
// }
// }
//
//
// @RequestMapping(method = RequestMethod.POST, value = { "/datarepo/delete" }, consumes = "application/json", produces="text/plain")
// public @ResponseBody ResponseEntity<Object> delete(@RequestBody DataRepository dataRepository) {
//
// DataRepository dr = new DataRepository();
// dr.setId(dataRepository.getId());
// try {
// dataRepositoryDao.delete(dr);
// return ResponseEntity.status(HttpStatus.CREATED).body("{\"msg\":\"Deleted data repository!\"}");
// } catch (Exception e) {
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not delete data repository!\"}");
// }
//
// }
}

View File

@ -42,7 +42,7 @@ public class DatasetProfileController {
@RequestMapping(method = RequestMethod.GET, value = { "/datasetprofile/get/{id}" }, produces="application/json")
public ResponseEntity<Object> getSingle(@PathVariable String id){
try {
eu.eudat.entities.Dataset dataset = datasetDao.read(UUID.fromString(id));
eu.eudat.entities.Dataset dataset = datasetDao.find(UUID.fromString(id));
eu.eudat.models.user.composite.DatasetProfile datasetprofile = UserManager.generateDatasetProfileModel(dataset.getProfile());
datasetprofile.setStatus(dataset.getStatus());
if(dataset.getProperties()!=null){
@ -62,13 +62,13 @@ public class DatasetProfileController {
@RequestMapping(method = RequestMethod.POST, value = { "/datasetprofile/save/{id}" }, consumes="application/json",produces="application/json")
public ResponseEntity<Object> updateDataset(@PathVariable String id,@RequestBody PropertiesModel properties){
try {
eu.eudat.entities.Dataset dataset = datasetDao.read(UUID.fromString(id));
eu.eudat.entities.Dataset dataset = datasetDao.find(UUID.fromString(id));
Map<String,Object> values = new HashMap();
properties.toMap(values);
JSONObject jobject = new JSONObject(values);
dataset.setProperties(jobject.toString());
dataset.setStatus((short)properties.getStatus());
datasetDao.update(dataset);
datasetDao.createOrUpdate(dataset); //TODO
return ResponseEntity.status(HttpStatus.OK).body(properties);
}
@ -80,7 +80,7 @@ public class DatasetProfileController {
@RequestMapping(method = RequestMethod.POST, value = { "/search/autocomplete" }, consumes="application/json",produces="application/json")
public ResponseEntity<Object> getDataForAutocomplete(@RequestBody AutoCompleteLookupItem lookupItem){
try {
eu.eudat.entities.Dataset dataset = datasetDao.read(UUID.fromString(lookupItem.getProfileID()));
eu.eudat.entities.Dataset dataset = datasetDao.find(UUID.fromString(lookupItem.getProfileID()));
Document viewStyleDoc = XmlBuilder.fromXml(dataset.getProfile().getViewstyle().getDefinition());
Element field = viewStyleDoc.getElementById(lookupItem.getFieldID());
eu.eudat.entities.xmlmodels.viewstyledefinition.Field modelfield = new eu.eudat.entities.xmlmodels.viewstyledefinition.Field();

View File

@ -9,12 +9,9 @@ import eu.eudat.entities.Dataset;
import eu.eudat.entities.DatasetProfile;
import eu.eudat.entities.UserInfo;
import eu.eudat.managers.DatasetManager;
import eu.eudat.managers.ProjectManager;
import eu.eudat.models.dataset.DatasetTableRequest;
import eu.eudat.models.helpers.DataTableData;
import eu.eudat.models.project.Project;
import eu.eudat.models.project.ProjectTableRequest;
import eu.eudat.models.responses.ResponseItem;
import eu.eudat.models.helpers.responses.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ -98,256 +95,256 @@ public class Datasets {
// FETCH BY DATASET(S)
@RequestMapping(method = RequestMethod.GET, value = { "/datasets" })
public @ResponseBody ResponseEntity<List<UUID>> listDatasets(){
try {
List<UUID> allIDs = datasetDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(allIDs);
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/datasets/{id}" })
public @ResponseBody ResponseEntity<eu.eudat.models.dataset.Dataset> getDataset(@PathVariable("id") String id) {
try {
Dataset ds = datasetDao.read(UUID.fromString(id));
eu.eudat.models.dataset.Dataset dataset = new eu.eudat.models.dataset.Dataset();
dataset.fromDataModel(ds);
return ResponseEntity.status(HttpStatus.OK).body(dataset);
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
/**
* This should be called on extreme cases. It's computationally intensive
*/
@RequestMapping(method = RequestMethod.GET, value = { "/dataset/getAll" })
public @ResponseBody ResponseEntity<List<Dataset>> getAllDatasets(){
try {
List<Dataset> allDatasets = datasetDao.getAll();
return ResponseEntity.status(HttpStatus.OK).body(allDatasets);
}
catch(Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/dataset/create" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Dataset> createDataset(@RequestBody eu.eudat.models.dataset.Dataset modeldataset) {
String userID = null;
try {
userID = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
} catch(NullPointerException ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
UserInfo userInfo = userInfoDao.read(UUID.fromString(userID));
if(userInfo==null) //this should normally never happer
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
Dataset dataset = modeldataset.toDataModel();
if(dataset.getDataRepositories()!=null&&!dataset.getDataRepositories().isEmpty()){
for(eu.eudat.entities.DataRepository dataRepo : dataset.getDataRepositories()){
DataRepositoryCriteria criteria = new DataRepositoryCriteria();
criteria.setLike(dataRepo.getReference());
List<eu.eudat.entities.DataRepository> entries = this.dataRepositoryDao.listBy(criteria);
if(entries!=null&&!entries.isEmpty())dataRepo.setId(entries.get(0).getId());
else dataRepo = this.dataRepositoryDao.create(dataRepo);
}
}
if(dataset.getServices()!=null&&!dataset.getServices().isEmpty()){
for(eu.eudat.entities.Service service : dataset.getServices()){
ServiceCriteria criteria = new ServiceCriteria();
criteria.setLike(service.getReference());
List<eu.eudat.entities.Service> entries = this.serviceDao.listBy(criteria);
if(entries!=null&&!entries.isEmpty())service.setId(entries.get(0).getId());
else service = this.serviceDao.create(service);
}
}
if(dataset.getRegistries()!=null&&!dataset.getRegistries().isEmpty()){
for(eu.eudat.entities.Registry registry : dataset.getRegistries()){
RegistryCriteria criteria = new RegistryCriteria();
criteria.setLike(registry.getReference());
List<eu.eudat.entities.Registry> entries = this.registryDao.listBy(criteria);
if(entries!=null&&!entries.isEmpty())registry.setId( entries.get(0).getId());
else registry = this.registryDao.create(registry);
}
}
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(dataset);
}
catch(Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/dataset/update" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> updateDataset(@RequestBody eu.eudat.models.dataset.Dataset modeldataset) {
Dataset dataset = modeldataset.toDataModel();
if(dataset.getDataRepositories()!=null&&!dataset.getDataRepositories().isEmpty()){
for(eu.eudat.entities.DataRepository dataRepo : dataset.getDataRepositories()){
DataRepositoryCriteria criteria = new DataRepositoryCriteria();
criteria.setLike(dataRepo.getReference());
List<eu.eudat.entities.DataRepository> entries = this.dataRepositoryDao.listBy(criteria);
if(entries!=null&&!entries.isEmpty())dataRepo.setId(entries.get(0).getId());
else dataRepo = this.dataRepositoryDao.create(dataRepo);
}
}
if(dataset.getServices()!=null&&!dataset.getServices().isEmpty()){
for(eu.eudat.entities.Service service : dataset.getServices()){
ServiceCriteria criteria = new ServiceCriteria();
criteria.setLike(service.getReference());
List<eu.eudat.entities.Service> entries = this.serviceDao.listBy(criteria);
if(entries!=null&&!entries.isEmpty())service.setId(entries.get(0).getId());
else service = this.serviceDao.create(service);
}
}
if(dataset.getRegistries()!=null&&!dataset.getRegistries().isEmpty()){
for(eu.eudat.entities.Registry registry : dataset.getRegistries()){
RegistryCriteria criteria = new RegistryCriteria();
criteria.setLike(registry.getReference());
List<eu.eudat.entities.Registry> entries = this.registryDao.listBy(criteria);
if(entries!=null&&!entries.isEmpty())registry.setId( entries.get(0).getId());
else registry = this.registryDao.create(registry);
}
}
Dataset olddataset = datasetDao.read(modeldataset.getId());
olddataset.getServices().clear();
olddataset.setServices(dataset.getServices());
olddataset.getDataRepositories().clear();
olddataset.setDataRepositories(dataset.getDataRepositories());
olddataset.getRegistries().clear();
olddataset.setRegistries(dataset.getRegistries());
olddataset.setLabel(modeldataset.getLabel());
olddataset.setDescription(modeldataset.getDescription());
//SafeCleanAttribs.clean(dataset);
if("".equals(dataset.getReference())) dataset.setReference(null);
if("".equals(dataset.getProperties())) dataset.setProperties(null);
try {
dataset = datasetDao.update(olddataset);
return ResponseEntity.status(HttpStatus.CREATED).body(dataset);
}
catch(Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Could not create or update Dataset! Reason: " + ex.getMessage());
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/dataset/delete" }, consumes = "application/json")
public @ResponseBody ResponseEntity<Object> deleteDataset(@RequestBody Dataset dataset) {
//if we want to make sure it won't cascade up to other (child) components, we can just unhook them by setting them = new ones
// e.g: DMP dmp = new DMP() and then dataset.setDMP(dmp)
try {
datasetDao.delete(dataset);
RestResponse rr = new RestResponse("Deleted dataset with id: "+dataset.getId().toString(), dataset.getId().toString());
return ResponseEntity.status(HttpStatus.OK).body(rr.toString());
}
catch(Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Could not delete Dataset! Reason: " + e.getMessage());
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/dataset/softdelete" }, consumes = "application/json", produces="text/plain")
public @ResponseBody ResponseEntity<Object> softDelete(@RequestBody Dataset dataset) {
try {
Dataset d = datasetDao.read(dataset.getId());
d.setStatus(new Short("-1"));
dataset = datasetDao.update(d);
return ResponseEntity.status(HttpStatus.OK).body("{\"msg\":\"Deleted dataset!\"");
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not soft delete dataset!\"");
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/dataset/assignDMPToDataset" })
public @ResponseBody ResponseEntity<Object> assignDMPToDataset(@RequestParam("datasetID") String datasetID, @RequestParam("dmpID") String dmpID) {
Dataset dataset = null;
try {
dataset = datasetDao.read(UUID.fromString(datasetID));
if(dataset==null || dataset.getId()==null) throw new Exception("Could not find a Dataset by this id");
DMP dmp = new DMP();
dmp.setId(UUID.fromString(dmpID));
dataset.setDmp(dmp);
datasetDao.update(dataset);
return ResponseEntity.status(HttpStatus.OK).build();
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/dataset/assignProfileToDataset" })
public @ResponseBody ResponseEntity<Object> assignProfileToDataset(@RequestParam("datasetID") String datasetID, @RequestParam("profileID") String profileID) {
Dataset dataset = null;
try {
dataset = datasetDao.read(UUID.fromString(datasetID));
if(dataset==null || dataset.getId()==null) throw new Exception("Could not find a Dataset by this id");
DatasetProfile profile = new DatasetProfile();
profile.setId(UUID.fromString(profileID));
dataset.setProfile(profile);
datasetDao.update(dataset);
return ResponseEntity.status(HttpStatus.OK).build();
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}
// @RequestMapping(method = RequestMethod.GET, value = { "/datasets" })
// public @ResponseBody ResponseEntity<List<UUID>> listDatasets(){
// try {
// List<UUID> allIDs = datasetDao.listAllIDs();
// return ResponseEntity.status(HttpStatus.OK).body(allIDs);
// }
// catch(Exception ex) {
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
// }
// }
//
//
// @RequestMapping(method = RequestMethod.GET, value = { "/datasets/{id}" })
// public @ResponseBody ResponseEntity<eu.eudat.models.dataset.Dataset> getDataset(@PathVariable("id") String id) {
// try {
// Dataset ds = datasetDao.read(UUID.fromString(id));
// eu.eudat.models.dataset.Dataset dataset = new eu.eudat.models.dataset.Dataset();
// dataset.fromDataModel(ds);
// return ResponseEntity.status(HttpStatus.OK).body(dataset);
// }
// catch(Exception ex) {
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
// }
// }
//
//
// /**
// * This should be called on extreme cases. It's computationally intensive
// */
// @RequestMapping(method = RequestMethod.GET, value = { "/dataset/getAll" })
// public @ResponseBody ResponseEntity<List<Dataset>> getAllDatasets(){
//
// try {
// List<Dataset> allDatasets = datasetDao.getAll();
// return ResponseEntity.status(HttpStatus.OK).body(allDatasets);
// }
// catch(Exception ex) {
// ex.printStackTrace();
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
// }
//
// }
//
//
// @RequestMapping(method = RequestMethod.POST, value = { "/dataset/create" }, consumes = "application/json", produces="application/json")
// public @ResponseBody ResponseEntity<Dataset> createDataset(@RequestBody eu.eudat.models.dataset.Dataset modeldataset) {
//
// String userID = null;
// try {
// userID = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
// } catch(NullPointerException ex) {
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
// }
//
// UserInfo userInfo = userInfoDao.read(UUID.fromString(userID));
//
// if(userInfo==null) //this should normally never happer
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
//
//
// Dataset dataset = modeldataset.toDataModel();
// if(dataset.getDataRepositories()!=null&&!dataset.getDataRepositories().isEmpty()){
// for(eu.eudat.entities.DataRepository dataRepo : dataset.getDataRepositories()){
// DataRepositoryCriteria criteria = new DataRepositoryCriteria();
// criteria.setLike(dataRepo.getReference());
// List<eu.eudat.entities.DataRepository> entries = this.dataRepositoryDao.listBy(criteria);
// if(entries!=null&&!entries.isEmpty())dataRepo.setId(entries.get(0).getId());
// else dataRepo = this.dataRepositoryDao.create(dataRepo);
// }
// }
//
// if(dataset.getServices()!=null&&!dataset.getServices().isEmpty()){
// for(eu.eudat.entities.Service service : dataset.getServices()){
// ServiceCriteria criteria = new ServiceCriteria();
// criteria.setLike(service.getReference());
// List<eu.eudat.entities.Service> entries = this.serviceDao.listBy(criteria);
// if(entries!=null&&!entries.isEmpty())service.setId(entries.get(0).getId());
// else service = this.serviceDao.create(service);
// }
// }
//
// if(dataset.getRegistries()!=null&&!dataset.getRegistries().isEmpty()){
// for(eu.eudat.entities.Registry registry : dataset.getRegistries()){
// RegistryCriteria criteria = new RegistryCriteria();
// criteria.setLike(registry.getReference());
// List<eu.eudat.entities.Registry> entries = this.registryDao.listBy(criteria);
// if(entries!=null&&!entries.isEmpty())registry.setId( entries.get(0).getId());
// else registry = this.registryDao.create(registry);
// }
// }
//
// 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(dataset);
// }
// catch(Exception e) {
// e.printStackTrace();
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
// }
//
// }
//
//
// @RequestMapping(method = RequestMethod.POST, value = { "/dataset/update" }, consumes = "application/json", produces="application/json")
// public @ResponseBody ResponseEntity<Object> updateDataset(@RequestBody eu.eudat.models.dataset.Dataset modeldataset) {
//
// Dataset dataset = modeldataset.toDataModel();
//
// if(dataset.getDataRepositories()!=null&&!dataset.getDataRepositories().isEmpty()){
// for(eu.eudat.entities.DataRepository dataRepo : dataset.getDataRepositories()){
// DataRepositoryCriteria criteria = new DataRepositoryCriteria();
// criteria.setLike(dataRepo.getReference());
// List<eu.eudat.entities.DataRepository> entries = this.dataRepositoryDao.listBy(criteria);
// if(entries!=null&&!entries.isEmpty())dataRepo.setId(entries.get(0).getId());
// else dataRepo = this.dataRepositoryDao.create(dataRepo);
// }
// }
//
// if(dataset.getServices()!=null&&!dataset.getServices().isEmpty()){
// for(eu.eudat.entities.Service service : dataset.getServices()){
// ServiceCriteria criteria = new ServiceCriteria();
// criteria.setLike(service.getReference());
// List<eu.eudat.entities.Service> entries = this.serviceDao.listBy(criteria);
// if(entries!=null&&!entries.isEmpty())service.setId(entries.get(0).getId());
// else service = this.serviceDao.create(service);
// }
// }
//
// if(dataset.getRegistries()!=null&&!dataset.getRegistries().isEmpty()){
// for(eu.eudat.entities.Registry registry : dataset.getRegistries()){
// RegistryCriteria criteria = new RegistryCriteria();
// criteria.setLike(registry.getReference());
// List<eu.eudat.entities.Registry> entries = this.registryDao.listBy(criteria);
// if(entries!=null&&!entries.isEmpty())registry.setId( entries.get(0).getId());
// else registry = this.registryDao.create(registry);
// }
// }
//
// Dataset olddataset = datasetDao.read(modeldataset.getId());
//
// olddataset.getServices().clear();
// olddataset.setServices(dataset.getServices());
//
// olddataset.getDataRepositories().clear();
// olddataset.setDataRepositories(dataset.getDataRepositories());
// olddataset.getRegistries().clear();
// olddataset.setRegistries(dataset.getRegistries());
//
// olddataset.setLabel(modeldataset.getLabel());
// olddataset.setDescription(modeldataset.getDescription());
// //SafeCleanAttribs.clean(dataset);
//
// if("".equals(dataset.getReference())) dataset.setReference(null);
// if("".equals(dataset.getProperties())) dataset.setProperties(null);
//
// try {
// dataset = datasetDao.update(olddataset);
// return ResponseEntity.status(HttpStatus.CREATED).body(dataset);
// }
// catch(Exception ex) {
// ex.printStackTrace();
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Could not create or update Dataset! Reason: " + ex.getMessage());
// }
//
// }
//
//
// @RequestMapping(method = RequestMethod.POST, value = { "/dataset/delete" }, consumes = "application/json")
// public @ResponseBody ResponseEntity<Object> deleteDataset(@RequestBody Dataset dataset) {
//
// //if we want to make sure it won't cascade up to other (child) components, we can just unhook them by setting them = new ones
// // e.g: DMP dmp = new DMP() and then dataset.setDMP(dmp)
// try {
// datasetDao.delete(dataset);
// RestResponse rr = new RestResponse("Deleted dataset with id: "+dataset.getId().toString(), dataset.getId().toString());
// return ResponseEntity.status(HttpStatus.OK).body(rr.toString());
// }
// catch(Exception e) {
// e.printStackTrace();
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Could not delete Dataset! Reason: " + e.getMessage());
// }
// }
//
//
//
// @RequestMapping(method = RequestMethod.POST, value = { "/dataset/softdelete" }, consumes = "application/json", produces="text/plain")
// public @ResponseBody ResponseEntity<Object> softDelete(@RequestBody Dataset dataset) {
// try {
//
// Dataset d = datasetDao.read(dataset.getId());
// d.setStatus(new Short("-1"));
// dataset = datasetDao.update(d);
// return ResponseEntity.status(HttpStatus.OK).body("{\"msg\":\"Deleted dataset!\"");
// } catch (Exception e) {
// e.printStackTrace();
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"msg\":\"Could not soft delete dataset!\"");
// }
//
// }
//
//
// @RequestMapping(method = RequestMethod.GET, value = { "/dataset/assignDMPToDataset" })
// public @ResponseBody ResponseEntity<Object> assignDMPToDataset(@RequestParam("datasetID") String datasetID, @RequestParam("dmpID") String dmpID) {
//
// Dataset dataset = null;
// try {
// dataset = datasetDao.read(UUID.fromString(datasetID));
// if(dataset==null || dataset.getId()==null) throw new Exception("Could not find a Dataset by this id");
// DMP dmp = new DMP();
// dmp.setId(UUID.fromString(dmpID));
// dataset.setDmp(dmp);
// datasetDao.update(dataset);
// return ResponseEntity.status(HttpStatus.OK).build();
// }
// catch(Exception ex) {
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
// }
//
// }
//
//
// @RequestMapping(method = RequestMethod.GET, value = { "/dataset/assignProfileToDataset" })
// public @ResponseBody ResponseEntity<Object> assignProfileToDataset(@RequestParam("datasetID") String datasetID, @RequestParam("profileID") String profileID) {
//
// Dataset dataset = null;
// try {
// dataset = datasetDao.read(UUID.fromString(datasetID));
// if(dataset==null || dataset.getId()==null) throw new Exception("Could not find a Dataset by this id");
// DatasetProfile profile = new DatasetProfile();
// profile.setId(UUID.fromString(profileID));
// dataset.setProfile(profile);
// datasetDao.update(dataset);
// return ResponseEntity.status(HttpStatus.OK).build();
// }
// catch(Exception ex) {
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
// }
//
// }
//
//
//

View File

@ -1,11 +1,7 @@
package eu.eudat.controllers;
import eu.eudat.managers.DataManagementPlanManager;
import eu.eudat.models.dmp.DataManagementPlan;
import eu.eudat.models.dmp.DataManagementPlanTableRequest;
import eu.eudat.models.helpers.DataTableData;
import eu.eudat.models.login.Credentials;
import eu.eudat.models.responses.ResponseItem;
import eu.eudat.models.helpers.responses.ResponseItem;
import eu.eudat.models.security.Principal;
import eu.eudat.security.CustomAuthenticationProvider;
import org.springframework.beans.factory.annotation.Autowired;

View File

@ -1,24 +1,18 @@
package eu.eudat.controllers;
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 eu.eudat.models.responses.ResponseItem;
import org.apache.commons.lang3.SerializationUtils;
import eu.eudat.models.helpers.responses.*;
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;
@ -28,11 +22,6 @@ 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 eu.eudat.dao.entities.DMPDao;
import eu.eudat.dao.entities.DMPProfileDao;
import eu.eudat.dao.entities.DataRepositoryDao;
@ -47,27 +36,16 @@ import eu.eudat.dao.entities.ResearcherDao;
import eu.eudat.dao.entities.ServiceDao;
import eu.eudat.dao.entities.UserInfoDao;
import eu.eudat.entities.DMP;
import eu.eudat.entities.DMPProfile;
import eu.eudat.entities.DataRepository;
import eu.eudat.entities.Dataset;
import eu.eudat.entities.DatasetProfile;
import eu.eudat.entities.DatasetProfileRuleset;
import eu.eudat.entities.Organisation;
import eu.eudat.entities.Project;
import eu.eudat.entities.Registry;
import eu.eudat.entities.Researcher;
import eu.eudat.entities.Service;
import eu.eudat.entities.UserInfo;
import eu.eudat.entities.responses.IDLabelPair;
import eu.eudat.helpers.Transformers;
import eu.eudat.managers.ProjectManager;
import eu.eudat.models.helpers.DataTableData;
import eu.eudat.models.project.ProjectTableRequest;
import eu.eudat.proxy.config.exceptions.HugeResultSet;
import eu.eudat.proxy.config.exceptions.NoURLFound;
import eu.eudat.proxy.fetching.RemoteFetcher;
import eu.eudat.responses.RestResponse;
@RestController
@ -121,7 +99,7 @@ public class Projects {
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/projects/add" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseItem<eu.eudat.entities.Project> addProject(@RequestBody eu.eudat.models.project.Project project) {
Project createdProject = projectDao.update(project.toDataModel());
Project createdProject = projectDao.createOrUpdate(project.toDataModel());
return new ResponseItem<eu.eudat.entities.Project>().payload(createdProject).status(HttpStatus.OK);
}
@ -145,219 +123,219 @@ public class Projects {
// MANAGE PROJECT(S)
@RequestMapping(method = RequestMethod.GET, value = { "/projects" }, produces="application/json")
public @ResponseBody ResponseEntity<List<UUID>> listProjects(){
try {
List<UUID> allIDs = projectDao.listAllIDs();
return ResponseEntity.status(HttpStatus.OK).body(allIDs);
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/projects/{id}" }, produces="application/json")
public @ResponseBody ResponseEntity<Project> getProject(@PathVariable("id") String id) {
try {
Project project = projectDao.read(UUID.fromString(id));
System.out.println(project.getId().toString());
return ResponseEntity.status(HttpStatus.OK).body(project);
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/project/listAllLabelIDs" }, produces="application/json")
public @ResponseBody ResponseEntity<List<IDLabelPair>> listLabelIds(){
try {
List<IDLabelPair> allIDs = projectDao.listAllIDsLabels();
return ResponseEntity.status(HttpStatus.OK).body(allIDs);
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
@RequestMapping(method = RequestMethod.GET, value = { "/project/getAll" }, produces="application/json")
public @ResponseBody ResponseEntity<Object> getAllProjects(){
try {
List<Project> allProjects = projectDao.getAll();
return ResponseEntity.status(HttpStatus.OK).body(allProjects);
}
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")
public @ResponseBody ResponseEntity<Project> createProject(@RequestBody Project project) {
Project createdProject = projectDao.update(project);
return ResponseEntity.status(HttpStatus.CREATED).body(createdProject);
}
@RequestMapping(method = RequestMethod.POST, value = { "/project/update" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Project> updateProject(@RequestBody Project project) {
Project updatedProject = projectDao.update(project);
return ResponseEntity.status(HttpStatus.CREATED).body(updatedProject);
}
@RequestMapping(method = RequestMethod.POST, value = { "/project/delete" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Project> delete(@RequestBody Project project) {
Project p = new Project();
p.setId(project.getId());
try {
projectDao.delete(p);
return ResponseEntity.status(HttpStatus.CREATED).body(null);
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
@RequestMapping(method = RequestMethod.POST, value = { "/project/softdelete" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> softDelete(@RequestBody Project project) {
project.setStatus(new Short("-1"));
try {
projectDao.update(project);
return ResponseEntity.status(HttpStatus.CREATED).body(null);
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = { "/project/getdmps" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> getProjectDmps(@RequestBody Project project) {
try {
Set<DMP> dmps = projectDao.read(project.getId()).getDmps();
return ResponseEntity.status(HttpStatus.CREATED).body(dmps);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
////////////////////////////////
//// USER - RELATED ACTIONS ////
////////////////////////////////
@RequestMapping(method = RequestMethod.GET, value = { "/project/getofuser" }, produces="text/plain")
public @ResponseBody ResponseEntity<Object> getProjectsOfUser(){
String userID = null;
try {
userID = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
} catch(NullPointerException ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("You have not logged in. You shouldn't be here");
}
UserInfo userInfo = userInfoDao.read(UUID.fromString(userID));
if(userInfo==null) //this should normally never happen
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("There's no such a user on the system. You shouldn't be here");
try {
List<Project> userProjects = projectDao.getProjectsOfUser(userID);
return ResponseEntity.status(HttpStatus.OK).body(userProjects);
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
/*
* OLD ONE
Map<UUID, Researcher> userProjects = new HashMap<UUID, Researcher>();
userInfo.getDmps().forEach( dmp -> {
Researcher 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<Project> 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(null);
}
UserInfo userInfo = userInfoDao.read(UUID.fromString(userID));
if(userInfo==null) //this should normally never happer
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
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);
// @RequestMapping(method = RequestMethod.GET, value = { "/projects" }, produces="application/json")
// public @ResponseBody ResponseEntity<List<UUID>> listProjects(){
// try {
// List<UUID> allIDs = projectDao.listAllIDs();
// return ResponseEntity.status(HttpStatus.OK).body(allIDs);
// }
// catch(Exception ex) {
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
// }
// }
//
// Set<UserInfo> users = new HashSet<UserInfo>();
// users.add(userInfo);
// newdmp.setUsers(users);
// @RequestMapping(method = RequestMethod.GET, value = { "/projects/{id}" }, produces="application/json")
// public @ResponseBody ResponseEntity<Project> getProject(@PathVariable("id") String id) {
// try {
// Project project = projectDao.read(UUID.fromString(id));
//
// System.out.println(project.getId().toString());
//
// return ResponseEntity.status(HttpStatus.OK).body(project);
// }
// catch(Exception ex) {
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
// }
// }
//
//
// @RequestMapping(method = RequestMethod.GET, value = { "/project/listAllLabelIDs" }, produces="application/json")
// public @ResponseBody ResponseEntity<List<IDLabelPair>> listLabelIds(){
// try {
// List<IDLabelPair> allIDs = projectDao.listAllIDsLabels();
// return ResponseEntity.status(HttpStatus.OK).body(allIDs);
// }
// catch(Exception ex) {
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
// }
// }
//
//
// @RequestMapping(method = RequestMethod.GET, value = { "/project/getAll" }, produces="application/json")
// public @ResponseBody ResponseEntity<Object> getAllProjects(){
// try {
// List<Project> allProjects = projectDao.getAll();
// return ResponseEntity.status(HttpStatus.OK).body(allProjects);
// }
// 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")
// public @ResponseBody ResponseEntity<Project> createProject(@RequestBody Project project) {
// Project createdProject = projectDao.update(project);
// return ResponseEntity.status(HttpStatus.CREATED).body(createdProject);
// }
//
//
//
// @RequestMapping(method = RequestMethod.POST, value = { "/project/update" }, consumes = "application/json", produces="application/json")
// public @ResponseBody ResponseEntity<Project> updateProject(@RequestBody Project project) {
// Project updatedProject = projectDao.update(project);
// return ResponseEntity.status(HttpStatus.CREATED).body(updatedProject);
// }
//
//
// @RequestMapping(method = RequestMethod.POST, value = { "/project/delete" }, consumes = "application/json", produces="application/json")
// public @ResponseBody ResponseEntity<Project> delete(@RequestBody Project project) {
//
// Project p = new Project();
// p.setId(project.getId());
// try {
// projectDao.delete(p);
// return ResponseEntity.status(HttpStatus.CREATED).body(null);
// } catch (Exception e) {
// e.printStackTrace();
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
// }
//
// }
//
//
//
// @RequestMapping(method = RequestMethod.POST, value = { "/project/softdelete" }, consumes = "application/json", produces="application/json")
// public @ResponseBody ResponseEntity<Object> softDelete(@RequestBody Project project) {
//
// project.setStatus(new Short("-1"));
//
// try {
// projectDao.update(project);
// return ResponseEntity.status(HttpStatus.CREATED).body(null);
// } catch (Exception e) {
// e.printStackTrace();
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
// }
//
// }
//
//
// @Transactional
// @RequestMapping(method = RequestMethod.POST, value = { "/project/getdmps" }, consumes = "application/json", produces="application/json")
// public @ResponseBody ResponseEntity<Object> getProjectDmps(@RequestBody Project project) {
// try {
// Set<DMP> dmps = projectDao.read(project.getId()).getDmps();
// return ResponseEntity.status(HttpStatus.CREATED).body(dmps);
// } catch (Exception e) {
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
// }
// }
//
//
//
// ////////////////////////////////
// //// USER - RELATED ACTIONS ////
// ////////////////////////////////
//
//
// @RequestMapping(method = RequestMethod.GET, value = { "/project/getofuser" }, produces="text/plain")
// public @ResponseBody ResponseEntity<Object> getProjectsOfUser(){
//
// String userID = null;
// try {
// userID = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
// } catch(NullPointerException ex) {
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("You have not logged in. You shouldn't be here");
// }
//
// UserInfo userInfo = userInfoDao.read(UUID.fromString(userID));
//
// if(userInfo==null) //this should normally never happen
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("There's no such a user on the system. You shouldn't be here");
//
//
// try {
// List<Project> userProjects = projectDao.getProjectsOfUser(userID);
// return ResponseEntity.status(HttpStatus.OK).body(userProjects);
// }
// catch(Exception ex) {
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
// }
//
//
// /*
// * OLD ONE
// Map<UUID, Researcher> userProjects = new HashMap<UUID, Researcher>();
//
// userInfo.getDmps().forEach( dmp -> {
// Researcher 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<Project> 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(null);
// }
//
// UserInfo userInfo = userInfoDao.read(UUID.fromString(userID));
//
//
// if(userInfo==null) //this should normally never happer
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
//
// try {
//
// project.setId(null);
// project.setStatus(new Short("0"));
// project.setCreationUser(userInfo);
// project.setCreated(new Date());
// project.setModified(new Date());
//
// Project newproj = projectDao.create(project);
//
//// DMP newdmp = new DMP();
//// newdmp.setId(null);
//// newdmp.setLabel("Auto-Generated");
//// newdmp.setCreated(new Date());
//// newdmp.setVersion(1);
//// newdmp.setStatus(new Short("0"));
//// newdmp.setProject(newproj);
////
//// Set<UserInfo> users = new HashSet<UserInfo>();
//// users.add(userInfo);
//// newdmp.setUsers(users);
////
//// newdmp = dMPDao.create(newdmp);
//
// return ResponseEntity.status(HttpStatus.OK).body(newproj);
// }
// catch(Exception ex) {
// ex.printStackTrace();
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
// }
//
// }
//
// newdmp = dMPDao.create(newdmp);
return ResponseEntity.status(HttpStatus.OK).body(newproj);
}
catch(Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
// @Transactional
// @RequestMapping(method = RequestMethod.POST, value = { "/project/updateofuser" }, produces="text/plain")
// public @ResponseBody ResponseEntity<Object> updateProjectOfUser(@RequestBody Researcher project){

View File

@ -0,0 +1,42 @@
package eu.eudat.dao.databaselayer.context;
import eu.eudat.entities.DataEntity;
import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.hibernatequeryablelist.QueryableHibernateList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import java.util.List;
/**
* Created by giannis on 7/16/2017.
*/
@Repository("databaseCtx")
public class DatabaseContext<T extends DataEntity<T>> {
@Autowired
private EntityManager entityManager;
public QueryableList<T> getQueryable(Class<T> type) {
return new QueryableHibernateList<>(this.entityManager, type).setEntity(type);
}
public T createOrUpdate(T item, Class<T> type) {
if (item.getKeys()[0] != null) {
T oldItem = entityManager.find(type, item.getKeys()[0]);
oldItem.update(item);
entityManager.merge(oldItem);
return oldItem;
} else entityManager.persist(item);
return item;
}
public long count(Class<T> entityClass) {
return ((Number) entityManager.createQuery("select count(e) from " + entityClass.getSimpleName() + " e").getSingleResult()).longValue();
}
}

View File

@ -0,0 +1,27 @@
package eu.eudat.dao.databaselayer.service;
import eu.eudat.dao.databaselayer.context.DatabaseContext;
import eu.eudat.entities.DataEntity;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Created by giannis on 7/17/2017.
*/
@Service("databaseService")
public class DatabaseService<T extends DataEntity<T>> {
@Autowired
private DatabaseContext<T> databaseCtx;
public QueryableList<T> getQueryable(Class<T> tClass) {
return this.databaseCtx.getQueryable(tClass);
}
public T createOrUpdate(T item, Class<T> tClass) {
return this.databaseCtx.createOrUpdate(item, tClass);
}
public Long count(Class<T> tClass){return this.databaseCtx.count(tClass);}
}

View File

@ -6,17 +6,19 @@ import java.util.UUID;
import eu.eudat.dao.Dao;
import eu.eudat.entities.DMP;
import eu.eudat.entities.responses.IDLabelPair;
import eu.eudat.models.criteria.DataManagementPlanCriteria;
import eu.eudat.models.dmp.DataManagementPlanTableRequest;
import eu.eudat.queryable.QueryableList;
import org.springframework.stereotype.Service;
public interface DMPDao extends Dao<DMP, UUID> {
public interface DMPDao {
public List<UUID> listAllIDs();
public QueryableList<DMP> getWithCriteria(DataManagementPlanCriteria criteria);
List<IDLabelPair> listAllIDsLabels();
DMP createOrUpdate(DMP item);
List<DMP> getDMPsOfUser(String userID);
DMP find(UUID id);
public List<DMP> getWithCriteria(DataManagementPlanTableRequest dataManagementPlanTableRequest);
Long count();
}

View File

@ -10,65 +10,46 @@ import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import eu.eudat.dao.databaselayer.service.DatabaseService;
import eu.eudat.entities.Project;
import eu.eudat.models.criteria.DataManagementPlanCriteria;
import eu.eudat.queryable.QueryableList;
import org.hibernate.query.Query;
import eu.eudat.dao.JpaDao;
import eu.eudat.entities.DMP;
import eu.eudat.entities.responses.IDLabelPair;
import eu.eudat.models.dmp.DataManagementPlanTableRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component("dMPDao")
public class DMPDaoImpl extends JpaDao<DMP, UUID> implements DMPDao {
public class DMPDaoImpl implements DMPDao {
public DMP loadDetails(DMP t) {
// TODO Auto-generated method stub
return null;
@Autowired
DatabaseService<DMP> databaseService;
@Override
public QueryableList<DMP> getWithCriteria(DataManagementPlanCriteria criteria) {
QueryableList<DMP> query = databaseService.getQueryable(DMP.class);
if(criteria.getLike()!=null&&!criteria.getLike().isEmpty())query.where((builder, root) -> builder.like(root.get("label"),"%"+criteria.getLike()+"%"));
if(criteria.getPeriodEnd()!=null)query.where((builder, root) -> builder.lessThan(root.get("created"),criteria.getPeriodEnd()));
if(criteria.getPeriodStart()!=null)query.where((builder, root) -> builder.greaterThan(root.get("created"),criteria.getPeriodStart()));
return query;
}
@Override
public List<UUID> listAllIDs() {
String queryString = "SELECT dmp.id FROM DMP dmp where dmp.status>=0";
TypedQuery<UUID> typedQuery = entityManager.createQuery(queryString, UUID.class);
return typedQuery.getResultList();
}
@Override
public List<IDLabelPair> listAllIDsLabels() {
String queryString = "SELECT dmp.id, dmp.label FROM DMP dmp where dmp.status>=0";
Query query = (Query) entityManager.createQuery(queryString);
List<Object[]> rows = query.list();
return rows.stream().map(row -> {
return new IDLabelPair(row[0].toString(), row[1].toString());
})
.collect(Collectors.toList());
public DMP createOrUpdate(DMP item) {
return this.databaseService.createOrUpdate(item,DMP.class);
}
@Override
public List<DMP> getDMPsOfUser(String userID) {
String queryString = "select dmp from DMP dmp where dmp.creator.id=:userid and dmp.status >= 0";
TypedQuery<DMP> typedQuery = entityManager.createQuery(queryString, DMP.class);
typedQuery.setParameter("userid", UUID.fromString(userID));
try {
return typedQuery.getResultList();
}
catch(Exception ex) { //no need to distinguish between eu.eudat.exceptions for the moment
ex.printStackTrace();
return null;
}
public DMP find(UUID id) {
return databaseService.getQueryable(DMP.class).where((builder, root) -> builder.equal((root.get("id")),id)).toList().get(0);
}
@Override
public List<DMP> getWithCriteria(DataManagementPlanTableRequest dataManagementPlanTableRequest) {
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<DMP> criteriaQuery = criteriaBuilder .createQuery(DMP.class);
Root<DMP> root = criteriaQuery.from(DMP.class);
TypedQuery<DMP> typedQuery = entityManager.createQuery(criteriaQuery);
typedQuery.setFirstResult(dataManagementPlanTableRequest.getOffset());
typedQuery.setMaxResults(dataManagementPlanTableRequest.getLength());
return typedQuery.getResultList();
public Long count(){
return this.databaseService.count(DMP.class);
}
}

View File

@ -9,12 +9,7 @@ import eu.eudat.entities.responses.IDLabelPair;
import eu.eudat.models.criteria.Criteria;
import org.springframework.stereotype.Service;
public interface DataRepositoryDao extends Dao<DataRepository, UUID> {
List<UUID> listAllIDs();
List<IDLabelPair> listAllIDsLabels();
public interface DataRepositoryDao {
List<DataRepository> listBy(Criteria<DataRepository> criteria);
DataRepository createOrUpdate(DataRepository item);
}

View File

@ -9,52 +9,33 @@ import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import eu.eudat.dao.databaselayer.service.DatabaseService;
import eu.eudat.queryable.QueryableList;
import org.hibernate.query.Query;
import eu.eudat.dao.JpaDao;
import eu.eudat.entities.DataRepository;
import eu.eudat.entities.responses.IDLabelPair;
import eu.eudat.models.criteria.Criteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
@Component("dataRepositoryDao")
public class DataRepositoryDaoImpl extends JpaDao<DataRepository, UUID> implements DataRepositoryDao {
public DataRepository loadDetails(DataRepository t) {
// TODO Auto-generated method stub
return null;
}
@Override
public List<UUID> listAllIDs() {
String queryString = "SELECT dataRepository.id FROM DataRepository dataRepository";
TypedQuery<UUID> typedQuery = entityManager.createQuery(queryString, UUID.class);
return typedQuery.getResultList();
}
@Override
public List<IDLabelPair> listAllIDsLabels() {
String queryString = "SELECT dataRepository.id, dataRepository.label FROM DataRepository dataRepository";
Query query = (Query) entityManager.createQuery(queryString);
List<Object[]> rows = query.list();
return rows.stream().map(row -> {
return new IDLabelPair(row[0].toString(), row[1].toString());
})
.collect(Collectors.toList());
}
public class DataRepositoryDaoImpl implements DataRepositoryDao{
@Autowired
DatabaseService<DataRepository> databaseService;
@Override
public List<DataRepository> listBy(Criteria<DataRepository> criteria) {
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<DataRepository> criteriaQuery = criteriaBuilder .createQuery(DataRepository.class);
Root<DataRepository> root = criteriaQuery.from(DataRepository.class);
criteriaQuery.where(criteriaBuilder.equal(root.get("reference"), criteria.getLike()));
TypedQuery<DataRepository> typedQuery = entityManager.createQuery(criteriaQuery);
return typedQuery.getResultList();
QueryableList<DataRepository> query = databaseService.getQueryable(DataRepository.class);
if(criteria.getLike()!=null)query.where((builder, root) -> builder.equal(root.get("reference"),criteria.getLike()));
return query.toList();
}
@Override
public DataRepository createOrUpdate(DataRepository item) {
return databaseService.createOrUpdate(item,DataRepository.class);
}
}

View File

@ -7,19 +7,23 @@ import eu.eudat.dao.Dao;
import eu.eudat.entities.Dataset;
import eu.eudat.entities.Project;
import eu.eudat.entities.responses.IDLabelPair;
import eu.eudat.models.criteria.DatasetCriteria;
import eu.eudat.models.criteria.ProjectCriteria;
import eu.eudat.models.dataset.DatasetTableRequest;
import eu.eudat.models.project.ProjectTableRequest;
import eu.eudat.queryable.QueryableList;
import org.springframework.stereotype.Service;
public interface DatasetDao extends Dao<Dataset, UUID> {
public interface DatasetDao {
public List<UUID> listAllIDs();
public QueryableList<Dataset> getWithCriteria(DatasetCriteria criteria);
List<IDLabelPair> listAllIDsLabels();
Dataset createOrUpdate(Dataset item);
List<Dataset> getDatasetsOfDmp(UUID dmpID);
Dataset find(UUID id);
Long count();
public List<Dataset> getWithCriteria(DatasetTableRequest datasetTableRequest);
}

View File

@ -12,56 +12,40 @@ import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import eu.eudat.dao.JpaDao;
import eu.eudat.dao.databaselayer.service.DatabaseService;
import eu.eudat.entities.Dataset;
import eu.eudat.entities.Project;
import eu.eudat.entities.responses.IDLabelPair;
import eu.eudat.models.criteria.DatasetCriteria;
import eu.eudat.models.dataset.DatasetTableRequest;
import eu.eudat.queryable.QueryableList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component("datasetDao")
public class DatasetDaoImpl extends JpaDao<Dataset, UUID> implements DatasetDao {
public class DatasetDaoImpl implements DatasetDao {
public Dataset loadDetails(Dataset t) {
// TODO Auto-generated method stub
return null;
@Autowired
DatabaseService<Dataset> databaseService;
@Override
public QueryableList<Dataset> getWithCriteria(DatasetCriteria criteria) {
QueryableList<Dataset> query = databaseService.getQueryable(Dataset.class);
if(criteria.getLike()!=null&&!criteria.getLike().isEmpty())query.where((builder, root) -> builder.like(root.get("label"),"%"+criteria.getLike()+"%"));
return query;
}
@Override
public List<UUID> listAllIDs() {
String queryString = "SELECT dataset.id FROM Dataset dataset where dataset.status>=0";
TypedQuery<UUID> typedQuery = entityManager.createQuery(queryString, UUID.class);
return typedQuery.getResultList();
}
@Override
public List<IDLabelPair> listAllIDsLabels() {
String queryString = "SELECT dataset.id, dataset.label FROM Dataset dataset where dataset.status>=0";
Query query = (Query) entityManager.createQuery(queryString);
List<Object[]> rows = query.getResultList();
return rows.stream().map(row -> {
return new IDLabelPair(row[0].toString(), row[1].toString());
})
.collect(Collectors.toList());
public Dataset createOrUpdate(Dataset item) {
return databaseService.createOrUpdate(item,Dataset.class);
}
@Override
public List<Dataset> getDatasetsOfDmp(UUID dmpID) {
String queryString = "FROM Dataset dataset where dataset.dmp.id=:dmpID and dataset.status>=0";
Query query = (Query) entityManager.createQuery(queryString);
query.setParameter("dmpID", dmpID);
List<Dataset> datasets = (List<Dataset>) query.getResultList();
return datasets;
public Dataset find(UUID id) {
return databaseService.getQueryable(Dataset.class).where((builder, root) -> builder.equal((root.get("id")),id)).toList().get(0);
}
@Override
public List<Dataset> getWithCriteria(DatasetTableRequest datasetTableRequest) {
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Dataset> criteriaQuery = criteriaBuilder .createQuery(Dataset.class);
Root<Dataset> root = criteriaQuery.from(Dataset.class);
TypedQuery<Dataset> typedQuery = entityManager.createQuery(criteriaQuery);
typedQuery.setFirstResult(datasetTableRequest.getOffset());
typedQuery.setMaxResults(datasetTableRequest.getLength());
return typedQuery.getResultList();
public Long count(){
return this.databaseService.count(Dataset.class);
}
}

View File

@ -6,6 +6,6 @@ import eu.eudat.dao.Dao;
import eu.eudat.entities.DatasetService;
import org.springframework.stereotype.Service;
public interface DatasetServiceDao extends Dao<DatasetService, UUID> {
public interface DatasetServiceDao {
}

View File

@ -6,17 +6,18 @@ import java.util.UUID;
import eu.eudat.dao.Dao;
import eu.eudat.entities.Project;
import eu.eudat.entities.responses.IDLabelPair;
import eu.eudat.models.criteria.ProjectCriteria;
import eu.eudat.models.project.ProjectTableRequest;
import eu.eudat.queryable.QueryableList;
import org.springframework.stereotype.Service;
public interface ProjectDao extends Dao<Project, UUID> {
public interface ProjectDao {
public List<UUID> listAllIDs();
QueryableList<Project> getWithCriteria(ProjectCriteria criteria);
public List<IDLabelPair> listAllIDsLabels();
Project createOrUpdate(Project item);
public List<Project> getProjectsOfUser(String userID);
public List<Project> getWithCriteria(ProjectTableRequest projectTableRequest);
Project find(UUID id);
Long count();
}

View File

@ -9,70 +9,44 @@ import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import eu.eudat.dao.databaselayer.service.DatabaseService;
import eu.eudat.models.criteria.ProjectCriteria;
import eu.eudat.queryable.QueryableList;
import org.hibernate.query.Query;
import eu.eudat.dao.JpaDao;
import eu.eudat.entities.Project;
import eu.eudat.entities.responses.IDLabelPair;
import eu.eudat.models.project.ProjectTableRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component("projectDao")
public class ProjectDaoImpl extends JpaDao<Project, UUID> implements ProjectDao {
public class ProjectDaoImpl implements ProjectDao {
public Project loadDetails(Project t) {
// TODO Auto-generated method stub
return null;
@Autowired
DatabaseService<Project> databaseService;
@Override
public QueryableList<Project> getWithCriteria(ProjectCriteria criteria) {
QueryableList<Project> query = databaseService.getQueryable(Project.class);
if(criteria.getLike()!=null&&!criteria.getLike().isEmpty())query.where((builder, root) -> builder.like(root.get("label"),"%"+criteria.getLike()+"%"));
if(criteria.getPeriodEnd()!=null)query.where((builder, root) -> builder.lessThan(root.get("created"),criteria.getPeriodEnd()));
if(criteria.getPeriodStart()!=null)query.where((builder, root) -> builder.greaterThan(root.get("created"),criteria.getPeriodStart()));
return query;
}
@Override
public List<UUID> listAllIDs() {
String queryString = "SELECT project.id FROM Project project";
TypedQuery<UUID> typedQuery = entityManager.createQuery(queryString, UUID.class);
return typedQuery.getResultList();
}
@Override
public List<IDLabelPair> listAllIDsLabels() {
String queryString = "SELECT project.id, project.label FROM Project project";
Query query = (Query) entityManager.createQuery(queryString);
List<Object[]> rows = query.list();
return rows.stream().map(row -> {
return new IDLabelPair(row[0].toString(), row[1].toString());
})
.collect(Collectors.toList());
}
public List<Project> getProjectsOfUser(String userID){
String queryString = "select p from Project p where p.creationUser.id=:userid and project.status >= 0";
TypedQuery<Project> typedQuery = entityManager.createQuery(queryString, Project.class);
typedQuery.setParameter("userid", UUID.fromString(userID));
try {
return typedQuery.getResultList();
}
catch(Exception ex) { //no need to distinguish between eu.eudat.exceptions for the moment
ex.printStackTrace();
return null;
}
public Project createOrUpdate(Project item) {
return databaseService.createOrUpdate(item,Project.class);
}
@Override
public List<Project> getWithCriteria(ProjectTableRequest projectTableRequest) {
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Project> criteriaQuery = criteriaBuilder .createQuery(Project.class);
Root<Project> root = criteriaQuery.from(Project.class);
TypedQuery<Project> typedQuery = entityManager.createQuery(criteriaQuery);
typedQuery.setFirstResult(projectTableRequest.getOffset());
typedQuery.setMaxResults(projectTableRequest.getLength());
return typedQuery.getResultList();
public Project find(UUID id) {
return databaseService.getQueryable(Project.class).where((builder, root) -> builder.equal((root.get("id")),id)).toList().get(0);
}
public Long count(){
return this.databaseService.count(Project.class);
}
}

View File

@ -27,7 +27,7 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
@Entity
@Table(name="\"DMP\"")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id", scope = DMP.class)
public class DMP implements Serializable,DataEntity {
public class DMP implements Serializable,DataEntity<DMP> {
private static final long serialVersionUID = -8263056535208547615L;
@ -251,6 +251,16 @@ public class DMP implements Serializable,DataEntity {
this.researchers = researchers;
}
@Override
public void update(DMP entity) {
}
@Override
public Object[] getKeys() {
return new UUID[]{this.id == null ? null : this.id};
}
/*

View File

@ -1,4 +1,7 @@
package eu.eudat.entities;
public interface DataEntity {
public interface DataEntity<T> {
void update(T entity);
Object[] getKeys();
}

View File

@ -25,7 +25,7 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
@Entity
@Table(name="\"DataRepository\"")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
public class DataRepository implements Serializable,DataEntity {
public class DataRepository implements Serializable,DataEntity<DataRepository> {
private static final long serialVersionUID = 4162323701450468639L;
@ -162,5 +162,13 @@ public class DataRepository implements Serializable,DataEntity {
this.datasets = datasets;
}
@Override
public void update(DataRepository entity) {
}
@Override
public Object[] getKeys() {
return new UUID[]{this.id == null ? null : this.id};
}
}

View File

@ -26,7 +26,7 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
@Entity
@Table(name="\"Dataset\"")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
public class Dataset implements Serializable,DataEntity {
public class Dataset implements DataEntity<Dataset> {
private static final long serialVersionUID = 3575723814399553259L;
@ -255,7 +255,13 @@ public class Dataset implements Serializable,DataEntity {
}
@Override
public void update(Dataset entity) {
}
@Override
public Object[] getKeys() {
return new UUID[]{this.id == null ? null : this.id};
}
}

View File

@ -26,7 +26,7 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
@Entity
@Table(name="\"DatasetProfile\"")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
public class DatasetProfile implements Serializable,DataEntity {
public class DatasetProfile implements Serializable,DataEntity<DatasetProfile> {
private static final long serialVersionUID = 8203086344232867334L;
@ -178,5 +178,13 @@ public class DatasetProfile implements Serializable,DataEntity {
}
@Override
public void update(DatasetProfile entity) {
}
@Override
public Object[] getKeys() {
return new UUID[]{this.id == null ? null : this.id};
}
}

View File

@ -26,7 +26,7 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
@Entity
@Table(name="\"Organisation\"")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
public class Organisation implements Serializable,DataEntity {
public class Organisation implements Serializable,DataEntity<Organisation> {
private static final long serialVersionUID = 3614146195740867782L;
@ -165,5 +165,13 @@ public class Organisation implements Serializable,DataEntity {
}
@Override
public void update(Organisation entity) {
}
@Override
public Object[] getKeys() {
return new UUID[]{this.id == null ? null : this.id};
}
}

View File

@ -29,7 +29,7 @@ import com.fasterxml.jackson.databind.SerializationFeature;
@Entity
@Table(name="\"Project\"")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
public class Project implements Serializable,DataEntity {
public class Project implements Serializable,DataEntity<Project> {
private static final long serialVersionUID = -767048645098311154L;
@ -227,6 +227,13 @@ public class Project implements Serializable,DataEntity {
}
}
@Override
public void update(Project entity) {
}
@Override
public Object[] getKeys() {
return new UUID[]{this.id == null ? null : this.id};
}
}

View File

@ -26,7 +26,7 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
@Entity
@Table(name="\"Registry\"")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
public class Registry implements Serializable,DataEntity {
public class Registry implements Serializable,DataEntity<Registry> {
private static final long serialVersionUID = -277572262583178090L;
@ -162,5 +162,13 @@ public class Registry implements Serializable,DataEntity {
}
@Override
public void update(Registry entity) {
}
@Override
public Object[] getKeys() {
return new UUID[]{this.id == null ? null : this.id};
}
}

View File

@ -26,7 +26,7 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
@Entity
@Table(name="\"Researcher\"")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
public class Researcher implements Serializable,DataEntity {
public class Researcher implements Serializable,DataEntity<Researcher> {
private static final long serialVersionUID = -2513186824704729896L;
@ -164,5 +164,13 @@ public class Researcher implements Serializable,DataEntity {
}
@Override
public void update(Researcher entity) {
}
@Override
public Object[] getKeys() {
return new UUID[]{this.id == null ? null : this.id};
}
}

View File

@ -26,7 +26,7 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
@Entity
@Table(name="\"Service\"")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
public class Service implements Serializable,DataEntity {
public class Service implements Serializable,DataEntity<Service> {
private static final long serialVersionUID = 163279108676904730L;
@ -161,5 +161,13 @@ public class Service implements Serializable,DataEntity {
}
@Override
public void update(Service entity) {
}
@Override
public Object[] getKeys() {
return new UUID[]{this.id == null ? null : this.id};
}
}

View File

@ -18,7 +18,7 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
@Entity
@Table(name="\"UserInfo\"")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
public class UserInfo implements Serializable,DataEntity{
public class UserInfo implements Serializable,DataEntity<UserInfo>{
private static final long serialVersionUID = 1225151430484658395L;
@ -154,4 +154,14 @@ public class UserInfo implements Serializable,DataEntity{
public void setCredentials(Set<Credential> credentials) {
this.credentials = credentials;
}
@Override
public void update(UserInfo entity) {
}
@Override
public Object[] getKeys() {
return new Object[0];
}
}

View File

@ -9,7 +9,7 @@ import java.util.UUID;
*/
@Entity
@Table(name="\"UserToken\"")
public class UserToken implements DataEntity{
public class UserToken implements DataEntity<UserToken>{
private static final long serialVersionUID = 1225151430484658395L;
@ -59,4 +59,14 @@ public class UserToken implements DataEntity{
public void setExpiresAt(Date expiresAt) {
this.expiresAt = expiresAt;
}
@Override
public void update(UserToken entity) {
}
@Override
public Object[] getKeys() {
return new UUID[]{this.token == null ? null : this.token};
}
}

View File

@ -4,14 +4,18 @@ import java.util.List;
import java.util.UUID;
import eu.eudat.dao.entities.DMPDao;
import eu.eudat.entities.DMP;
import eu.eudat.models.dmp.DataManagementPlanTableRequest;
import eu.eudat.models.helpers.DataTableData;
import eu.eudat.queryable.QueryableList;
import eu.eudat.utilities.builders.DomainModelConverter;
public class DataManagementPlanManager {
public DataTableData<eu.eudat.models.dmp.DataManagementPlan> getPaged(DMPDao dmpsRepository, DataManagementPlanTableRequest dataManagementPlanTableRequest) throws IllegalAccessException, InstantiationException{
List<eu.eudat.models.dmp.DataManagementPlan> datamanagementPlans = new DomainModelConverter<eu.eudat.entities.DMP, eu.eudat.models.dmp.DataManagementPlan>().fromDataModel( dmpsRepository.getWithCriteria(dataManagementPlanTableRequest), eu.eudat.models.dmp.DataManagementPlan.class);
QueryableList<DMP> items = dmpsRepository.getWithCriteria(dataManagementPlanTableRequest.getCriteria());
QueryableList<DMP> pagedItems = PaginationManager.applyPaging(items,dataManagementPlanTableRequest);
List<eu.eudat.models.dmp.DataManagementPlan> datamanagementPlans = new DomainModelConverter<eu.eudat.entities.DMP, eu.eudat.models.dmp.DataManagementPlan>().fromDataModel( pagedItems.toList(), eu.eudat.models.dmp.DataManagementPlan.class);
DataTableData<eu.eudat.models.dmp.DataManagementPlan> dataTable = new DataTableData<eu.eudat.models.dmp.DataManagementPlan>();
dataTable.setData(datamanagementPlans);
dataTable.setTotalCount(dmpsRepository.count());
@ -20,7 +24,7 @@ public class DataManagementPlanManager {
public eu.eudat.models.dmp.DataManagementPlan getSingle(DMPDao dmpsRepository, String id) throws InstantiationException, IllegalAccessException{
eu.eudat.models.dmp.DataManagementPlan datamanagementPlan = new eu.eudat.models.dmp.DataManagementPlan();
datamanagementPlan.fromDataModel(dmpsRepository.read(UUID.fromString(id)));
datamanagementPlan.fromDataModel(dmpsRepository.find(UUID.fromString(id)));
return datamanagementPlan;
}
}

View File

@ -7,6 +7,7 @@ import eu.eudat.models.dataset.DatasetTableRequest;
import eu.eudat.models.helpers.DataTableData;
import eu.eudat.models.project.Project;
import eu.eudat.models.project.ProjectTableRequest;
import eu.eudat.queryable.QueryableList;
import eu.eudat.utilities.builders.DomainModelConverter;
import java.util.List;
@ -18,7 +19,9 @@ import java.util.UUID;
public class DatasetManager {
public DataTableData<Dataset> getPaged(DatasetDao datatasetRepository, DatasetTableRequest datasetTableRequest) throws IllegalAccessException, InstantiationException{
List<Dataset> datasets = new DomainModelConverter<eu.eudat.entities.Dataset, Dataset>().fromDataModel( datatasetRepository.getWithCriteria(datasetTableRequest), eu.eudat.models.dataset.Dataset.class);
QueryableList<eu.eudat.entities.Dataset> items = datatasetRepository.getWithCriteria(datasetTableRequest.getCriteria());
QueryableList<eu.eudat.entities.Dataset> pagedItems = PaginationManager.applyPaging( items ,datasetTableRequest);
List<Dataset> datasets = new DomainModelConverter<eu.eudat.entities.Dataset, Dataset>().fromDataModel( pagedItems.toList(), eu.eudat.models.dataset.Dataset.class);
DataTableData<eu.eudat.models.dataset.Dataset> dataTable = new DataTableData<eu.eudat.models.dataset.Dataset>();
dataTable.setData(datasets);
dataTable.setTotalCount(datatasetRepository.count());
@ -27,7 +30,7 @@ public class DatasetManager {
public eu.eudat.models.dataset.Dataset getSingle(DatasetDao datatasetRepository, String id) throws InstantiationException, IllegalAccessException{
eu.eudat.models.dataset.Dataset dataset = new eu.eudat.models.dataset.Dataset();
dataset.fromDataModel(datatasetRepository.read(UUID.fromString(id)));
dataset.fromDataModel(datatasetRepository.find(UUID.fromString(id)));
return dataset;
}
}

View File

@ -0,0 +1,13 @@
package eu.eudat.managers;
import eu.eudat.models.helpers.requests.TableRequest;
import eu.eudat.queryable.QueryableList;
public class PaginationManager {
public static <T> QueryableList<T> applyPaging(QueryableList<T> items, TableRequest tableRequest){
if(tableRequest.getLength()!=null)items.take(tableRequest.getLength());
if(tableRequest.getOffset()!=null)items.skip(tableRequest.getOffset());
return items;
}
}

View File

@ -7,12 +7,15 @@ import eu.eudat.dao.entities.ProjectDao;
import eu.eudat.models.helpers.DataTableData;
import eu.eudat.models.project.Project;
import eu.eudat.models.project.ProjectTableRequest;
import eu.eudat.queryable.QueryableList;
import eu.eudat.utilities.builders.DomainModelConverter;
public class ProjectManager {
public DataTableData<eu.eudat.models.project.Project> getPaged(ProjectDao projectRepository, ProjectTableRequest projectTableRequest) throws IllegalAccessException, InstantiationException{
List<eu.eudat.models.project.Project> projects = new DomainModelConverter<eu.eudat.entities.Project, Project>().fromDataModel( projectRepository.getWithCriteria(projectTableRequest), eu.eudat.models.project.Project.class);
QueryableList<eu.eudat.entities.Project> items = projectRepository.getWithCriteria(projectTableRequest.getCriteria());
QueryableList<eu.eudat.entities.Project> pagedItems = PaginationManager.applyPaging(items,projectTableRequest);
List<eu.eudat.models.project.Project> projects = new DomainModelConverter<eu.eudat.entities.Project, Project>().fromDataModel(pagedItems.toList(), eu.eudat.models.project.Project.class);
DataTableData<eu.eudat.models.project.Project> dataTable = new DataTableData<eu.eudat.models.project.Project>();
dataTable.setData(projects);
dataTable.setTotalCount(projectRepository.count());
@ -21,7 +24,7 @@ public class ProjectManager {
public eu.eudat.models.project.Project getSingle(ProjectDao projectRepository, String id) throws InstantiationException, IllegalAccessException{
eu.eudat.models.project.Project project = new eu.eudat.models.project.Project();
project.fromDataModel(projectRepository.read(UUID.fromString(id)));
project.fromDataModel(projectRepository.find(UUID.fromString(id)));
return project;
}
}

View File

@ -2,6 +2,25 @@ package eu.eudat.models.criteria;
import eu.eudat.entities.DMP;
public class DataManagementPlanCriteria extends Criteria<DMP>{
import java.util.Date;
public class DataManagementPlanCriteria extends Criteria<DMP>{
private Date periodStart;
private Date periodEnd;
public Date getPeriodStart() {
return periodStart;
}
public void setPeriodStart(Date periodStart) {
this.periodStart = periodStart;
}
public Date getPeriodEnd() {
return periodEnd;
}
public void setPeriodEnd(Date periodEnd) {
this.periodEnd = periodEnd;
}
}

View File

@ -2,6 +2,25 @@ package eu.eudat.models.criteria;
import eu.eudat.entities.Project;
public class ProjectCriteria extends Criteria<Project>{
import java.util.Date;
public class ProjectCriteria extends Criteria<Project>{
private Date periodStart;
private Date periodEnd;
public Date getPeriodStart() {
return periodStart;
}
public void setPeriodStart(Date periodStart) {
this.periodStart = periodStart;
}
public Date getPeriodEnd() {
return periodEnd;
}
public void setPeriodEnd(Date periodEnd) {
this.periodEnd = periodEnd;
}
}

View File

@ -2,37 +2,11 @@ package eu.eudat.models.dataset;
import eu.eudat.models.criteria.DatasetCriteria;
import eu.eudat.models.criteria.ProjectCriteria;
import eu.eudat.models.helpers.requests.RequestItem;
import eu.eudat.models.helpers.requests.TableRequest;
/**
* Created by ikalyvas on 12/15/2017.
*/
public class DatasetTableRequest {
private int length;
private int offset;
private DatasetCriteria criteria;
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
public int getOffset() {
return offset;
}
public void setOffset(int offset) {
this.offset = offset;
}
public DatasetCriteria getCriteria() {
return criteria;
}
public void setCriteria(DatasetCriteria criteria) {
this.criteria = criteria;
}
public class DatasetTableRequest extends TableRequest<DatasetCriteria> {
}

View File

@ -1,36 +1,8 @@
package eu.eudat.models.dmp;
import eu.eudat.models.criteria.DataManagementPlanCriteria;
import eu.eudat.models.helpers.requests.RequestItem;
import eu.eudat.models.helpers.requests.TableRequest;
public class DataManagementPlanTableRequest {
private Integer length;
private Integer offset;
private DataManagementPlanCriteria criteria;
public Integer getLength() {
return length;
}
public void setLength(Integer length) {
this.length = length;
}
public Integer getOffset() {
return offset;
}
public void setOffset(Integer offset) {
this.offset = offset;
}
public DataManagementPlanCriteria getCriteria() {
return criteria;
}
public void setCriteria(DataManagementPlanCriteria criteria) {
this.criteria = criteria;
}
public class DataManagementPlanTableRequest extends TableRequest<DataManagementPlanCriteria> {
}

View File

@ -0,0 +1,13 @@
package eu.eudat.models.helpers.requests;
public abstract class RequestItem<T>{
private T criteria;
public T getCriteria() {
return criteria;
}
public void setCriteria(T criteria) {
this.criteria = criteria;
}
}

View File

@ -0,0 +1,22 @@
package eu.eudat.models.helpers.requests;
public abstract class TableRequest<T> extends RequestItem<T> {
private Integer length;
private Integer offset;
public Integer getLength() {
return length;
}
public void setLength(Integer length) {
this.length = length;
}
public Integer getOffset() {
return offset;
}
public void setOffset(Integer offset) {
this.offset = offset;
}
}

View File

@ -1,4 +1,4 @@
package eu.eudat.models.responses;
package eu.eudat.models.helpers.responses;
import org.springframework.http.HttpStatus;

View File

@ -1,36 +1,8 @@
package eu.eudat.models.project;
import eu.eudat.models.criteria.ProjectCriteria;
import eu.eudat.models.helpers.requests.RequestItem;
import eu.eudat.models.helpers.requests.TableRequest;
public class ProjectTableRequest {
private int length;
private int offset;
private ProjectCriteria criteria;
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
public int getOffset() {
return offset;
}
public void setOffset(int offset) {
this.offset = offset;
}
public ProjectCriteria getCriteria() {
return criteria;
}
public void setCriteria(ProjectCriteria criteria) {
this.criteria = criteria;
}
public class ProjectTableRequest extends TableRequest<ProjectCriteria> {
}

View File

@ -0,0 +1,24 @@
package eu.eudat.queryable;
import eu.eudat.queryable.predicates.OrderByPredicate;
import eu.eudat.queryable.predicates.SelectPredicate;
import eu.eudat.queryable.predicates.SinglePredicate;
import java.util.List;
public interface QueryableList<T> {
QueryableList<T> where(SinglePredicate<T> predicate);
<R> List<R> select(SelectPredicate<T, R> predicate);
List<T> toList();
QueryableList<T> skip(Integer offset);
QueryableList<T> take(Integer length);
QueryableList<T> distinct();
QueryableList<T> orderBy(OrderByPredicate<T> predicate);
}

View File

@ -0,0 +1,96 @@
package eu.eudat.queryable.hibernatequeryablelist;
import eu.eudat.queryable.QueryableList;
import eu.eudat.queryable.predicates.OrderByPredicate;
import eu.eudat.queryable.predicates.SelectPredicate;
import eu.eudat.queryable.predicates.SinglePredicate;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.LinkedList;
import java.util.List;
public class QueryableHibernateList<T> implements QueryableList<T> {
private EntityManager manager;
private CriteriaQuery<T> query;
private Class<T> tClass;
private Root<T> root;
private LinkedList<Predicate> predicates = new LinkedList<Predicate>();
private Integer length;
private Integer offset;
public QueryableHibernateList(EntityManager manager, Class<T> tClass) {
this.manager = manager;
this.tClass = tClass;
}
public QueryableHibernateList<T> setManager(EntityManager manager) {
this.manager = manager;
return this;
}
public QueryableHibernateList<T> setEntity(Class<T> type) {
CriteriaBuilder builder = this.manager.getCriteriaBuilder();
this.query = builder.createQuery(type);
this.root = this.query.from(this.tClass);
return this;
}
public void initiateQueryableList(Class<T> type) {
CriteriaBuilder builder = this.manager.getCriteriaBuilder();
this.query = builder.createQuery(type);
}
@Override
public QueryableList<T> skip(Integer offset) {
this.offset = offset;
return this;
}
@Override
public QueryableList<T> take(Integer length) {
this.length = length;
return this;
}
public QueryableList<T> where(SinglePredicate<T> predicate) {
this.predicates.add(predicate.applyPredicate(this.manager.getCriteriaBuilder(), this.root));
return this;
}
public <R> List<R> select(SelectPredicate<T, R> predicate) {
List<T> list = this.toList();
List<R> newlist = new LinkedList<R>();
for (T item : list) {
newlist.add(predicate.applySelection(item));
}
return newlist;
}
public QueryableList<T> distinct() {
this.query.distinct(true);
return this;
}
public QueryableList<T> orderBy(OrderByPredicate<T> predicate) {
this.query.orderBy(predicate.applyPredicate(this.manager.getCriteriaBuilder(), this.root));
return this;
}
public List<T> toList() {
Predicate[] array = new Predicate[this.predicates.size()];
this.predicates.toArray(array);
this.query.where(array);
TypedQuery<T> typedQuery = this.manager.createQuery(this.query);
if(this.offset!=null)typedQuery.setFirstResult(this.offset);
if(this.length!=null)typedQuery.setMaxResults(this.length);
return typedQuery.getResultList();
}
}

View File

@ -0,0 +1,10 @@
package eu.eudat.queryable.predicates;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Order;
import javax.persistence.criteria.Root;
public interface OrderByPredicate<T> {
Order applyPredicate(CriteriaBuilder builder, Root<T> root);
}

View File

@ -0,0 +1,5 @@
package eu.eudat.queryable.predicates;
public interface SelectPredicate<T, R> {
R applySelection(T item);
}

View File

@ -0,0 +1,9 @@
package eu.eudat.queryable.predicates;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
public interface SinglePredicate<T> {
Predicate applyPredicate(CriteriaBuilder builder, Root<T> root);
}