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<DMP> getDMPsOfUser(String userID);
}

View File

@ -41,6 +41,24 @@ public class DMPDaoImpl extends JpaDao<DMP, UUID> implements DMPDao {
.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<Project> getProjectsOfUser(String userID);
}

View File

@ -9,6 +9,7 @@ import javax.persistence.TypedQuery;
import org.hibernate.query.Query;
import dao.JpaDao;
import entities.DMP;
import entities.Project;
import entities.responses.IDLabelPair;
@ -38,5 +39,24 @@ public class ProjectDaoImpl extends JpaDao<Project, UUID> implements ProjectDao
.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;
@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "\"Creator\"", nullable = true)
private UserInfo creator;
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name="\"DMPOrganisation\"",
joinColumns={@JoinColumn(name="\"DMP\"", referencedColumnName="\"ID\"")},
@ -125,7 +130,16 @@ public class DMP implements Serializable {
this.description = description;
}
public UserInfo getCreator() {
return creator;
}
public void setCreator(UserInfo creator) {
this.creator = creator;
}
public Short getStatus() {
return status;

View File

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

View File

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

View File

@ -153,7 +153,6 @@ public class DMPs {
addNullAndForeignElems(previousDmp, dmp);
try {
DMP updatedDMP = dMPDao.update(dmp);
return ResponseEntity.status(HttpStatus.CREATED).body(SerializerProvider.toJson(updatedDMP));
@ -233,7 +232,8 @@ public class DMPs {
}
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));
}
catch(Exception ex) {
@ -262,6 +262,8 @@ public class DMPs {
dmp.setId(null);
dmp.setCreator(userInfo);
Set<UserInfo> users = new HashSet<UserInfo>();
users.add(userInfo);
dmp.setUsers(users);
@ -269,6 +271,7 @@ public class DMPs {
dmp.setCreated(new Date());
dmp.setModified(new Date());
dmp.setStatus(new Short("0"));
dmp.setProfileData(null);
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.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;
@ -43,6 +44,7 @@ import dao.entities.ProjectDao;
import dao.entities.RegistryDao;
import dao.entities.ResearcherDao;
import dao.entities.ServiceDao;
import dao.entities.UserInfoDao;
import entities.DMP;
import entities.DMPProfile;
import entities.Dataset;
@ -51,6 +53,7 @@ import entities.DatasetProfileRuleset;
import entities.DatasetProfileViewstyle;
import entities.Organisation;
import entities.Project;
import entities.UserInfo;
import helpers.SafeCleanAttribs;
import helpers.SerializerProvider;
import helpers.Transformers;
@ -73,6 +76,7 @@ public class Datasets {
@Autowired private RegistryDao registryDao;
@Autowired private ResearcherDao researcherDao;
@Autowired private ServiceDao serviceDao;
@Autowired private UserInfoDao userInfoDao;
// FETCH BY DATASET(S)
@ -124,10 +128,27 @@ public class Datasets {
@RequestMapping(method = RequestMethod.POST, value = { "/dataset/create" }, consumes = "application/json", produces="application/json")
public @ResponseBody ResponseEntity<Object> createDataset(@RequestBody Dataset dataset) {
String userID = null;
try {
userID = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
} catch(NullPointerException ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("You have not logged in. You shouldn't be here");
}
UserInfo userInfo = userInfoDao.read(UUID.fromString(userID));
if(userInfo==null) //this should normally never happer
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("There's no such a user on the system. You shouldn't be here");
dataset.setId(null);
dataset.setCreated(new Date());
dataset.setModified(new Date());
dataset.setStatus(new Short("0"));
dataset.setCreator(userInfo);
try {
dataset = datasetDao.create(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");
try {
List<Project> userProjects = projectDao.getProjectsOfUser(userID);
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(userProjects));
}
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
/*
* OLD ONE
Map<UUID, Project> userProjects = new HashMap<UUID, Project>();
userInfo.getDmps().forEach( dmp -> {
@ -232,6 +243,7 @@ public class Projects {
catch(Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Serialization issue: "+ex.getMessage());
}
*/
}
@ -257,7 +269,7 @@ public class Projects {
project.setId(null);
project.setStatus(new Short("0"));
project.setCreationUser(userInfo.getId());
project.setCreationUser(userInfo);
project.setCreated(new Date());
project.setModified(new Date());