argos/dmp-backend/src/main/java/eu/eudat/dao/entities/UserInfoDaoImpl.java

122 lines
3.4 KiB
Java

package eu.eudat.dao.entities;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import javax.persistence.NoResultException;
import javax.persistence.TypedQuery;
import eu.eudat.dao.JpaDao;
import eu.eudat.entities.DMP;
import eu.eudat.entities.UserInfo;
import eu.eudat.entities.security.UserAuth;
import org.springframework.stereotype.Component;
@Component("userInfoDao")
public class UserInfoDaoImpl extends JpaDao<UserInfo, UUID> implements UserInfoDao {
public UserInfo loadDetails(UserInfo t) {
// TODO Auto-generated method stub
return null;
}
@Override
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", 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();
}
catch(NoResultException ex) {
return null;
}
}
@Override
public UserInfo getByAuthenticationId(String authenticationID) {
UserAuth userauth = new UserAuth();
userauth.setId(UUID.fromString(authenticationID));
String queryString = "FROM UserInfo userInfo where userInfo.authentication = :auth";
TypedQuery<UserInfo> typedQuery = entityManager.createQuery(queryString, UserInfo.class);
typedQuery.setParameter("auth", userauth);
try {
return typedQuery.getSingleResult();
}
catch(NoResultException ex) {
return null;
}
}
@Override
public UserInfo getByMail(String email) {
String queryString = "FROM UserInfo userInfo where userInfo.email = :email";
TypedQuery<UserInfo> typedQuery = entityManager.createQuery(queryString, UserInfo.class);
typedQuery.setParameter("email", email);
try {
return typedQuery.getSingleResult();
}
catch(Exception ex) { //no need to distinguish between eu.eudat.exceptions for the moment
return null;
}
}
@Override
public UserInfo getByUsername(String username) {
String queryString = "select ui from UserInfo ui join UserAuth ui.authentication ua where ua.username=:username";
TypedQuery<UserInfo> typedQuery = entityManager.createQuery(queryString, UserInfo.class);
typedQuery.setParameter("username", username);
try {
return typedQuery.getSingleResult();
}
catch(Exception ex) { //no need to distinguish between eu.eudat.exceptions for the moment
return null;
}
}
@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 eu.eudat.exceptions for the moment
ex.printStackTrace();
return null;
}
}
}