Merge branch 'master' of gitlab.eudat.eu:dmp/OpenAIRE-EUDAT-DMP-service-pilot
This commit is contained in:
commit
360cdcb80d
|
@ -1,13 +1,17 @@
|
|||
package dao.entities;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import dao.Dao;
|
||||
import entities.DMP;
|
||||
import entities.UserInfo;
|
||||
|
||||
public interface UserInfoDao extends Dao<UserInfo, UUID> {
|
||||
|
||||
public UserInfo getByIdAndMail(String identification, String email);
|
||||
public UserInfo getUserInfo(String userID);
|
||||
|
||||
public UserInfo getByIdAndMail(String id, String email);
|
||||
|
||||
public UserInfo getByMail(String email);
|
||||
|
||||
|
@ -15,4 +19,6 @@ public interface UserInfoDao extends Dao<UserInfo, UUID> {
|
|||
|
||||
public UserInfo getByUsername(String username);
|
||||
|
||||
public List<DMP> getDmpsOfUser(String userID);
|
||||
|
||||
}
|
|
@ -1,12 +1,14 @@
|
|||
package dao.entities;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.TypedQuery;
|
||||
|
||||
import dao.JpaDao;
|
||||
import entities.DMP;
|
||||
import entities.UserInfo;
|
||||
import entities.security.UserAuth;
|
||||
|
||||
|
@ -21,10 +23,25 @@ public class UserInfoDaoImpl extends JpaDao<UserInfo, UUID> implements UserInfoD
|
|||
|
||||
|
||||
@Override
|
||||
public UserInfo getByIdAndMail(String identification, String email) {
|
||||
String queryString = "FROM UserInfo userInfo where userInfo.identification = :userInfoID and userInfo.email = :userInfoEmail";
|
||||
public UserInfo getUserInfo(String userID) {
|
||||
String queryString = "FROM UserInfo userInfo where userInfo.id = :userInfoID";
|
||||
TypedQuery<UserInfo> typedQuery = entityManager.createQuery(queryString, UserInfo.class);
|
||||
typedQuery.setParameter("userInfoID", identification);
|
||||
typedQuery.setParameter("userInfoID", UUID.fromString(userID));
|
||||
try {
|
||||
return typedQuery.getSingleResult();
|
||||
}
|
||||
catch(NoResultException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public UserInfo getByIdAndMail(String id, String email) {
|
||||
String queryString = "FROM UserInfo userInfo where userInfo.id = :userInfoID and userInfo.email = :userInfoEmail";
|
||||
TypedQuery<UserInfo> typedQuery = entityManager.createQuery(queryString, UserInfo.class);
|
||||
typedQuery.setParameter("userInfoID", UUID.fromString(id));
|
||||
typedQuery.setParameter("userInfoEmail", email);
|
||||
try {
|
||||
return typedQuery.getSingleResult();
|
||||
|
@ -80,6 +97,23 @@ public class UserInfoDaoImpl extends JpaDao<UserInfo, UUID> implements UserInfoD
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DMP> getDmpsOfUser(String userID) {
|
||||
|
||||
String queryString = "select dmp from DMP dmp join dmp.users user where user.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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ import com.fasterxml.jackson.databind.SerializationFeature;
|
|||
|
||||
@Entity
|
||||
@Table(name="\"DMP\"")
|
||||
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
|
||||
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id", scope = DMP.class)
|
||||
public class DMP implements Serializable {
|
||||
|
||||
|
||||
|
|
|
@ -80,6 +80,9 @@ 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;
|
||||
|
||||
@Column(name = "\"Created\"")
|
||||
private Date created = null;
|
||||
|
@ -210,6 +213,16 @@ public class Project implements Serializable {
|
|||
|
||||
|
||||
|
||||
public UUID getCreationUser() {
|
||||
return creationUser;
|
||||
}
|
||||
|
||||
|
||||
public void setCreationUser(UUID creationUser) {
|
||||
this.creationUser = creationUser;
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
try {
|
||||
return new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT).writeValueAsString(this).replace("\"", """);
|
||||
|
|
|
@ -85,10 +85,11 @@ public class UserInfo implements Serializable{
|
|||
private Set<DMP> dmps;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
public Set<DMP> getDmpsNonDeleted(){
|
||||
return getDmps().parallelStream().filter(dmp -> dmp.getStatus()>=0).collect(Collectors.toSet());
|
||||
}
|
||||
*/
|
||||
|
||||
public Set<DMP> getDmps() {
|
||||
return dmps;
|
||||
|
|
|
@ -232,13 +232,8 @@ public class DMPs {
|
|||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("You have not logged in. You shouldn't be here");
|
||||
}
|
||||
|
||||
UserInfo userInfo = userInfoDao.read(UUID.fromString(userID));
|
||||
|
||||
if(userInfo==null) //this should normally never happer
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("There's no such a user on the system. You shouldn't be here");
|
||||
|
||||
try {
|
||||
Set<DMP> nonDeleted = userInfo.getDmpsNonDeleted();
|
||||
List<DMP> nonDeleted = userInfoDao.getDmpsOfUser(userID);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(SerializerProvider.toJson(nonDeleted));
|
||||
}
|
||||
catch(Exception ex) {
|
||||
|
|
|
@ -257,24 +257,25 @@ public class Projects {
|
|||
|
||||
project.setId(null);
|
||||
project.setStatus(new Short("0"));
|
||||
project.setCreationUser(userInfo.getId());
|
||||
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);
|
||||
// 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(SerializerProvider.toJson(newproj));
|
||||
}
|
||||
|
|
|
@ -11,6 +11,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;
|
||||
|
@ -36,6 +37,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.DataRepository;
|
||||
|
@ -47,6 +49,7 @@ import entities.Project;
|
|||
import entities.Registry;
|
||||
import entities.Researcher;
|
||||
import entities.Service;
|
||||
import entities.UserInfo;
|
||||
import helpers.SerializerProvider;
|
||||
import helpers.Transformers;
|
||||
import responses.RestResponse;
|
||||
|
@ -68,6 +71,39 @@ public class Users {
|
|||
@Autowired private RegistryDao registryDao;
|
||||
@Autowired private ResearcherDao researcherDao;
|
||||
@Autowired private ServiceDao serviceDao;
|
||||
@Autowired private UserInfoDao userInfoDao;
|
||||
|
||||
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = { "/user/whoami" }, produces="application/json;charset=UTF-8")
|
||||
public @ResponseBody ResponseEntity<Object> whoami(){
|
||||
|
||||
|
||||
String userID = null;
|
||||
try {
|
||||
userID = SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString();
|
||||
} catch(NullPointerException ex) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("You have not logged in. You shouldn't be here");
|
||||
}
|
||||
|
||||
UserInfo userInfo = userInfoDao.getUserInfo(userID);
|
||||
|
||||
System.out.println(userInfo.getName());
|
||||
|
||||
if(userInfo==null) //this should normally never happer
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("There's no such a user on the system. You shouldn't be here");
|
||||
|
||||
|
||||
try {
|
||||
|
||||
return new ResponseEntity<Object>(SerializerProvider.toJson(userInfo), HttpStatus.OK);
|
||||
}
|
||||
catch(Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
</listener>
|
||||
|
||||
|
||||
<!-- THIS FILTER IS FOR SPRING SECURITY -->
|
||||
<context-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>/WEB-INF/applicationContext.xml,/WEB-INF/spring-security.xml</param-value>
|
||||
|
@ -74,7 +75,6 @@
|
|||
<session-timeout>30</session-timeout>
|
||||
</session-config>
|
||||
|
||||
<!-- THIS FILTER IS FOR SPRING SECURITY -->
|
||||
<filter>
|
||||
<filter-name>springSecurityFilterChain</filter-name>
|
||||
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
|
||||
|
@ -85,6 +85,23 @@
|
|||
</filter-mapping>
|
||||
|
||||
|
||||
<!-- THIS FILTER IS FOR SUPPORTING UNICODE CHARACTERS -->
|
||||
<filter>
|
||||
<filter-name>encodingFilter</filter-name>
|
||||
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
|
||||
<init-param>
|
||||
<param-name>encoding</param-name>
|
||||
<param-value>UTF-8</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>forceEncoding</param-name>
|
||||
<param-value>true</param-value>
|
||||
</init-param>
|
||||
</filter>
|
||||
<filter-mapping>
|
||||
<filter-name>encodingFilter</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
|
||||
|
||||
</web-app>
|
|
@ -3,6 +3,7 @@ import static org.junit.Assert.*;
|
|||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Before;
|
||||
|
@ -17,6 +18,7 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio
|
|||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.type.CollectionType;
|
||||
import com.fasterxml.jackson.databind.type.TypeFactory;
|
||||
|
@ -201,7 +203,7 @@ public class TestRest {
|
|||
}
|
||||
|
||||
|
||||
@Test
|
||||
//@Test
|
||||
public void testDmpClone() {
|
||||
|
||||
System.out.println(dmpsService.getDmpsOfUser().getBody());
|
||||
|
@ -266,5 +268,40 @@ public class TestRest {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProject2() {
|
||||
|
||||
|
||||
// String a = null;
|
||||
// try {
|
||||
// //a = (String)dmpsService.getDmpsOfUser().getBody();
|
||||
//
|
||||
// Set<DMP> dmps = new ObjectMapper().readValue(dmpsService.getDmpsOfUser().getBody().toString(), new TypeReference<Set<DMP>>(){});
|
||||
// System.out.println(dmps);
|
||||
//
|
||||
//// Set<DMP> dmps = SerializerProvider.fromJson((String)dmpsService.getDmpsOfUser().getBody(), new TypeReference<Set<DMP>>(){});
|
||||
// } catch (Exception e) {
|
||||
//
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
|
||||
CollectionType typeReference = TypeFactory.defaultInstance().constructCollectionType(List.class, DMP.class);
|
||||
List<DMP> dmps = null;
|
||||
try {
|
||||
dmps = SerializerProvider.fromJson(dmpsService.getDmpsOfUser().getBody().toString(), typeReference) ;
|
||||
System.out.println(dmps);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Should not have thrown any exception");
|
||||
}
|
||||
|
||||
|
||||
assertEquals("aaa", "aaa");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue