Revision 45085
Added by Panagiotis Kanakakis over 7 years ago
modules/uoa-goldoa-service/branches/hibernate/src/test/java/unitest/TestUserDAO.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import static org.junit.Assert.*; |
4 | 4 |
|
5 |
import java.util.ArrayList; |
|
6 |
import java.util.List; |
|
7 |
|
|
5 | 8 |
import org.apache.commons.codec.digest.DigestUtils; |
6 | 9 |
import org.junit.Test; |
7 | 10 |
import org.junit.runner.RunWith; |
... | ... | |
12 | 15 |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
13 | 16 |
|
14 | 17 |
import eu.dnetlib.goldoa.domain.PersonManagerException; |
18 |
import eu.dnetlib.goldoa.domain.Role; |
|
15 | 19 |
import eu.dnetlib.goldoa.domain.User; |
20 |
import eu.dnetlib.goldoa.domain.UserRole; |
|
16 | 21 |
import eu.dnetlib.goldoa.service.UserManagerImpl; |
17 | 22 |
|
18 | 23 |
|
... | ... | |
24 | 29 |
|
25 | 30 |
@Test |
26 | 31 |
@Transactional |
27 |
// @Rollback(true)
|
|
32 |
@Rollback(true) |
|
28 | 33 |
public void registerUser() { |
29 |
User user = new User();
|
|
30 |
user.setEmail("pkanakakis@di.uoa.gr");
|
|
31 |
user.setPassword(DigestUtils.md5Hex("1q2w3e4r").toString());
|
|
34 |
User user = new User(); |
|
35 |
user.setEmail("pkanakakis@di.uoa.gr"); |
|
36 |
user.setPassword(DigestUtils.md5Hex("1q2w3e4r").toString()); |
|
32 | 37 |
|
33 |
try {
|
|
38 |
try { |
|
34 | 39 |
um.register(user); |
35 |
} catch (PersonManagerException e) {
|
|
40 |
} catch (PersonManagerException e) { |
|
36 | 41 |
e.printStackTrace(); |
37 |
} |
|
42 |
} |
|
43 |
um.activateUser(user.getEmail()); |
|
38 | 44 |
|
39 | 45 |
User sys_user = null; |
40 | 46 |
try { |
... | ... | |
42 | 48 |
} catch (PersonManagerException e) { |
43 | 49 |
e.printStackTrace(); |
44 | 50 |
} |
45 |
System.out.println(sys_user); |
|
46 |
assertEquals(user,sys_user); |
|
47 |
|
|
48 |
|
|
51 |
assertEquals(user,sys_user); |
|
49 | 52 |
} |
50 | 53 |
|
51 |
/*@Test
|
|
54 |
@Test |
|
52 | 55 |
@Transactional |
53 | 56 |
@Rollback(true) |
54 |
public void test() { |
|
55 |
//User user = new User(); |
|
57 |
public void checkRoles() { |
|
58 |
User user = new User(); |
|
59 |
user.setEmail("pkanakakis@di.uoa.gr"); |
|
60 |
user.setPassword(DigestUtils.md5Hex("1q2w3e4r").toString()); |
|
56 | 61 |
|
62 |
Role role = new Role("1", "moderator"); |
|
63 |
List<UserRole> userRoles = new ArrayList<>(); |
|
64 |
UserRole userRole = new UserRole(); |
|
65 |
userRole.setRole(role); |
|
66 |
userRole.setUser(user); |
|
67 |
userRole.setApproved(false); |
|
68 |
userRoles.add(userRole); |
|
69 |
|
|
70 |
user.setUserRole(userRoles); |
|
71 |
|
|
72 |
try { |
|
73 |
um.register(user); |
|
74 |
} catch (PersonManagerException e) { |
|
75 |
e.printStackTrace(); |
|
76 |
} |
|
77 |
um.activateUser(user.getEmail()); |
|
78 |
|
|
57 | 79 |
} |
58 |
*/ |
|
80 |
|
|
59 | 81 |
} |
modules/uoa-goldoa-service/branches/hibernate/src/test/resources/applicationContext-goldoa-service-test.xml | ||
---|---|---|
25 | 25 |
|
26 | 26 |
<context:annotation-config/> |
27 | 27 |
<context:property-placeholder location="classpath:applicationContext-goldoa-service.properties" /> |
28 |
<context:component-scan base-package="eu.dnetlib.goldoa.*" /> |
|
29 |
<!-- <context:component-scan base-package="eu.dnetlib.goldoa.service" />
|
|
28 |
|
|
29 |
<context:component-scan base-package="eu.dnetlib.goldoa.service" /> |
|
30 | 30 |
<context:component-scan base-package="eu.dnetlib.goldoa.service.utils" /> |
31 | 31 |
<context:component-scan base-package="eu.dnetlib.goldoa.service.dao" /> |
32 | 32 |
|
33 |
<context:component-scan base-package="eu.dnetlib.goldoa.domain" /> -->
|
|
33 |
<context:component-scan base-package="eu.dnetlib.goldoa.domain" /> |
|
34 | 34 |
|
35 | 35 |
|
36 |
<aop:aspectj-autoproxy proxy-target-class="true" /> |
|
37 |
<tx:annotation-driven transaction-manager="txManager"/> |
|
38 |
|
|
39 |
<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> |
|
40 |
<property name="sessionFactory" ref="sessionFactory"/> |
|
41 |
</bean> |
|
42 | 36 |
|
43 |
<bean id="executorService" class="java.util.concurrent.Executors" factory-method="newCachedThreadPool" destroy-method="shutdown" /> |
|
44 | 37 |
|
45 |
|
|
46 | 38 |
<!-- |
47 | 39 |
<bean id="contactManager" class="eu.dnetlib.goldoa.service.ContactManagerImpl"> |
48 | 40 |
<property name="contactEmail" value="${goldoa.contactEmail}" /> |
modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/service/dao/UserDAO.java | ||
---|---|---|
103 | 103 |
} |
104 | 104 |
|
105 | 105 |
public boolean verifyLogin(String email, String password) { |
106 |
List users = createEntityCriteria().add(Restrictions.eq("email", email)) |
|
107 |
.add(Restrictions.eq("password", DigestUtils.md5Hex(password))).list(); |
|
108 |
System.out.println(users.size()); |
|
106 |
List users = createEntityCriteria().add(Restrictions.eq("email", email)).list();
|
|
107 |
// .add(Restrictions.eq("password", DigestUtils.md5Hex(password))).list();
|
|
108 |
|
|
109 | 109 |
if(users.size() != 0) |
110 | 110 |
return true; |
111 | 111 |
return false; |
112 | 112 |
} |
113 | 113 |
|
114 | 114 |
public boolean verifyToken(final String email, final String token) { |
115 |
|
|
115 | 116 |
// private static final String GET_PERSON_TOKEN = "select 1 from person p join account_action ac " |
116 | 117 |
// + "on ac.user=p.id where p.email=? and ac.token=?"; |
117 | 118 |
/*return new JdbcTemplate(dataSource).query(GET_PERSON_TOKEN, new Object[]{email, token}, new int[]{Types.VARCHAR, Types.VARCHAR}, new RowMapper<Object>() { |
... | ... | |
182 | 183 |
|
183 | 184 |
public void saveProjectCoordinators(final String email, final List<ProjectCoordinator> projectCoordinators) { |
184 | 185 |
User user = (User) createEntityCriteria().add(Restrictions.eq("email", email)).list().get(0); |
185 |
//user.setProjectCoordinators(projectCoordinators); |
|
186 |
user.setProjectCoordinators(projectCoordinators); |
|
187 |
persist(user); |
|
186 | 188 |
} |
187 | 189 |
|
188 | 190 |
public void saveUserRoles(final String email, final List<UserRole> roles) { |
189 | 191 |
User user = getUserByEmail(email); |
190 | 192 |
user.setRole(roles); |
191 |
// persist(user);
|
|
193 |
persist(user); |
|
192 | 194 |
} |
193 | 195 |
|
194 | 196 |
/** |
... | ... | |
196 | 198 |
* @param affiliations |
197 | 199 |
*/ |
198 | 200 |
public void saveAffiliations(final User user, final List<Affiliation> affiliations) { |
199 |
// user.setAffiliations(affiliations); |
|
201 |
user.setAffiliations(affiliations); |
|
202 |
persist(user); |
|
200 | 203 |
// new JdbcTemplate(dataSource).batchUpdate(INSERT_AFFILIATION, new BatchPreparedStatementSetter() { |
201 | 204 |
// @Override |
202 | 205 |
// public void setValues(PreparedStatement ps, int i) throws SQLException { |
modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/service/UserManagerImpl.java | ||
---|---|---|
154 | 154 |
|
155 | 155 |
if (userDAO.verifyLogin(email, password)) { |
156 | 156 |
User user = getByEmail(email); |
157 |
|
|
158 | 157 |
if (user.isActive()) |
159 | 158 |
return user; |
160 | 159 |
else |
... | ... | |
218 | 217 |
} |
219 | 218 |
|
220 | 219 |
@Override |
221 |
public void activateUser(String userId) {
|
|
222 |
userDAO.activateUser(userId);
|
|
220 |
public void activateUser(String email) {
|
|
221 |
userDAO.activateUser(email);
|
|
223 | 222 |
} |
224 | 223 |
|
225 | 224 |
@Override |
modules/uoa-goldoa-service/branches/hibernate/src/main/java/eu/dnetlib/goldoa/domain/UserRole.java | ||
---|---|---|
12 | 12 |
|
13 | 13 |
@Id |
14 | 14 |
@ManyToOne |
15 |
@JoinColumn(name = "user_email")
|
|
15 |
@JoinColumn(name = "email") |
|
16 | 16 |
private User user; |
17 | 17 |
|
18 | 18 |
@Id |
Also available in: Unified diff