This commit is contained in:
satyr 2017-11-17 02:43:16 +02:00
parent 67d95de255
commit 946a626789
10 changed files with 117 additions and 15 deletions

View File

@ -15,6 +15,6 @@ public interface DMPDao extends Dao<DMP, UUID> {
List<IDLabelPair> listAllIDsLabels(); List<IDLabelPair> listAllIDsLabels();
List<DMP> getDMPsOfUser(String userID);
} }

View File

@ -41,6 +41,24 @@ public class DMPDaoImpl extends JpaDao<DMP, UUID> implements DMPDao {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@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 exceptions for the moment
ex.printStackTrace();
return null;
}
}
} }

View File

@ -13,4 +13,6 @@ public interface ProjectDao extends Dao<Project, UUID> {
public List<IDLabelPair> listAllIDsLabels(); public List<IDLabelPair> listAllIDsLabels();
public List<Project> getProjectsOfUser(String userID);
} }

View File

@ -9,6 +9,7 @@ import javax.persistence.TypedQuery;
import org.hibernate.query.Query; import org.hibernate.query.Query;
import dao.JpaDao; import dao.JpaDao;
import entities.DMP;
import entities.Project; import entities.Project;
import entities.responses.IDLabelPair; import entities.responses.IDLabelPair;
@ -38,5 +39,24 @@ public class ProjectDaoImpl extends JpaDao<Project, UUID> implements ProjectDao
.collect(Collectors.toList()); .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 exceptions for the moment
ex.printStackTrace();
return null;
}
}
} }

View File

@ -77,6 +77,11 @@ public class DMP implements Serializable {
private DMPProfile profile; private DMPProfile profile;
@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "\"Creator\"", nullable = true)
private UserInfo creator;
@OneToMany(fetch = FetchType.LAZY) @OneToMany(fetch = FetchType.LAZY)
@JoinTable(name="\"DMPOrganisation\"", @JoinTable(name="\"DMPOrganisation\"",
joinColumns={@JoinColumn(name="\"DMP\"", referencedColumnName="\"ID\"")}, joinColumns={@JoinColumn(name="\"DMP\"", referencedColumnName="\"ID\"")},
@ -125,7 +130,16 @@ public class DMP implements Serializable {
this.description = description; this.description = description;
} }
public UserInfo getCreator() {
return creator;
}
public void setCreator(UserInfo creator) {
this.creator = creator;
}
public Short getStatus() { public Short getStatus() {
return status; return status;

View File

@ -106,6 +106,10 @@ public class Dataset implements Serializable {
@Column(name = "\"Modified\"") @Column(name = "\"Modified\"")
private Date modified = new Date(); private Date modified = new Date();
@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "\"Creator\"", nullable = true)
private UserInfo creator;
@Column(name = "\"Description\"") @Column(name = "\"Description\"")
private String description; private String description;
@ -113,13 +117,20 @@ public class Dataset implements Serializable {
public String getDescription() { public String getDescription() {
return description; return description;
} }
public void setDescription(String description) { public void setDescription(String description) {
this.description = description; this.description = description;
} }
public UserInfo getCreator() {
return creator;
}
public void setCreator(UserInfo creator) {
this.creator = creator;
}
public Short getStatus() { public Short getStatus() {
return status; return status;
} }

View File

@ -80,9 +80,11 @@ public class Project implements Serializable {
@Column(name = "\"Status\"", nullable = false) @Column(name = "\"Status\"", nullable = false)
private Short status; private Short status;
@Type(type="org.hibernate.type.PostgresUUIDType")
@Column(name = "\"CreationUser\"") @OneToOne(fetch = FetchType.EAGER)
private UUID creationUser; @JoinColumn(name = "\"CreationUser\"", nullable = true)
private UserInfo creationUser;
@Column(name = "\"Created\"") @Column(name = "\"Created\"")
private Date created = null; private Date created = null;
@ -210,15 +212,14 @@ public class Project implements Serializable {
public void setDmps(Set<DMP> dmps) { public void setDmps(Set<DMP> dmps) {
this.dmps = dmps; this.dmps = dmps;
} }
public UserInfo getCreationUser() {
public UUID getCreationUser() {
return creationUser; return creationUser;
} }
public void setCreationUser(UUID creationUser) { public void setCreationUser(UserInfo creationUser) {
this.creationUser = creationUser; this.creationUser = creationUser;
} }

View File

@ -153,7 +153,6 @@ public class DMPs {
addNullAndForeignElems(previousDmp, dmp); addNullAndForeignElems(previousDmp, dmp);
try { try {
DMP updatedDMP = dMPDao.update(dmp); DMP updatedDMP = dMPDao.update(dmp);
return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(updatedDMP)); return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(updatedDMP));
@ -233,7 +232,8 @@ public class DMPs {
} }
try { try {
List<DMP> nonDeleted = userInfoDao.getDmpsOfUser(userID); //List<DMP> nonDeleted = userInfoDao.getDmpsOfUser(userID);
List<DMP> nonDeleted = dMPDao.getDMPsOfUser(userID);
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(nonDeleted)); return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(nonDeleted));
} }
catch(Exception ex) { catch(Exception ex) {
@ -262,6 +262,8 @@ public class DMPs {
dmp.setId(null); dmp.setId(null);
dmp.setCreator(userInfo);
Set<UserInfo> users = new HashSet<UserInfo>(); Set<UserInfo> users = new HashSet<UserInfo>();
users.add(userInfo); users.add(userInfo);
dmp.setUsers(users); dmp.setUsers(users);
@ -269,6 +271,7 @@ public class DMPs {
dmp.setCreated(new Date()); dmp.setCreated(new Date());
dmp.setModified(new Date()); dmp.setModified(new Date());
dmp.setStatus(new Short("0")); dmp.setStatus(new Short("0"));
dmp.setProfileData(null);
DMP newdmp = dMPDao.create(dmp); DMP newdmp = dMPDao.create(dmp);

View File

@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
@ -43,6 +44,7 @@ import dao.entities.ProjectDao;
import dao.entities.RegistryDao; import dao.entities.RegistryDao;
import dao.entities.ResearcherDao; import dao.entities.ResearcherDao;
import dao.entities.ServiceDao; import dao.entities.ServiceDao;
import dao.entities.UserInfoDao;
import entities.DMP; import entities.DMP;
import entities.DMPProfile; import entities.DMPProfile;
import entities.Dataset; import entities.Dataset;
@ -51,6 +53,7 @@ import entities.DatasetProfileRuleset;
import entities.DatasetProfileViewstyle; import entities.DatasetProfileViewstyle;
import entities.Organisation; import entities.Organisation;
import entities.Project; import entities.Project;
import entities.UserInfo;
import helpers.SafeCleanAttribs; import helpers.SafeCleanAttribs;
import helpers.SerializerProvider; import helpers.SerializerProvider;
import helpers.Transformers; import helpers.Transformers;
@ -73,6 +76,7 @@ public class Datasets {
@Autowired private RegistryDao registryDao; @Autowired private RegistryDao registryDao;
@Autowired private ResearcherDao researcherDao; @Autowired private ResearcherDao researcherDao;
@Autowired private ServiceDao serviceDao; @Autowired private ServiceDao serviceDao;
@Autowired private UserInfoDao userInfoDao;
// FETCH BY DATASET(S) // FETCH BY DATASET(S)
@ -124,10 +128,27 @@ public class Datasets {
@RequestMapping(method = RequestMethod.POST, value = { "/dataset/create" }, consumes = "application/json", produces="application/json") @RequestMapping(method = RequestMethod.POST, value = { "/dataset/create" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> createDataset(@RequestBody Dataset dataset) { public @ResponseBody ResponseEntity<Object> createDataset(@RequestBody Dataset dataset) {
String userID = null;
try {
userID = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
} catch(NullPointerException ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("You have not logged in. You shouldn't be here");
}
UserInfo userInfo = userInfoDao.read(UUID.fromString(userID));
if(userInfo==null) //this should normally never happer
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("There's no such a user on the system. You shouldn't be here");
dataset.setId(null); dataset.setId(null);
dataset.setCreated(new Date()); dataset.setCreated(new Date());
dataset.setModified(new Date()); dataset.setModified(new Date());
dataset.setStatus(new Short("0")); dataset.setStatus(new Short("0"));
dataset.setCreator(userInfo);
try { try {
dataset = datasetDao.create(dataset); dataset = datasetDao.create(dataset);
return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(dataset)); return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(dataset));

View File

@ -219,6 +219,17 @@ public class Projects {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("There's no such a user on the system. You shouldn't be here"); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("There's no such a user on the system. You shouldn't be here");
try {
List<Project> userProjects = projectDao.getProjectsOfUser(userID);
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(userProjects));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
/*
* OLD ONE
Map<UUID, Project> userProjects = new HashMap<UUID, Project>(); Map<UUID, Project> userProjects = new HashMap<UUID, Project>();
userInfo.getDmps().forEach( dmp -> { userInfo.getDmps().forEach( dmp -> {
@ -232,6 +243,7 @@ public class Projects {
catch(Exception ex) { catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
} }
*/
} }
@ -257,7 +269,7 @@ public class Projects {
project.setId(null); project.setId(null);
project.setStatus(new Short("0")); project.setStatus(new Short("0"));
project.setCreationUser(userInfo.getId()); project.setCreationUser(userInfo);
project.setCreated(new Date()); project.setCreated(new Date());
project.setModified(new Date()); project.setModified(new Date());