blob: 47ad06563bcc16eb54b87cf29ceee7a642258710 [file] [log] [blame]
Michael Hanl72c7b832015-09-03 08:42:15 +02001package de.ids_mannheim.korap.handlers;
2
Michael Hanl72c7b832015-09-03 08:42:15 +02003import java.sql.ResultSet;
4import java.sql.SQLException;
Michael Hanl59bff812015-10-27 23:10:32 +01005import java.sql.Timestamp;
Michael Hanl72c7b832015-09-03 08:42:15 +02006import java.util.Map;
7
margaretha064eb6f2018-07-10 18:33:01 +02008import org.springframework.jdbc.core.RowMapper;
9
margaretha064eb6f2018-07-10 18:33:01 +020010import de.ids_mannheim.korap.config.Attributes;
11import de.ids_mannheim.korap.config.URIParam;
12import de.ids_mannheim.korap.user.KorAPUser;
13import de.ids_mannheim.korap.user.User;
14
Michael Hanl72c7b832015-09-03 08:42:15 +020015/**
16 * @author hanl
17 * @date 14/01/2014
18 */
19public class RowMapperFactory {
20
margaretha35e1ca22023-11-16 22:00:01 +010021 public static class UserMapMapper implements RowMapper<Map<?, ?>> {
Michael Hanl72c7b832015-09-03 08:42:15 +020022
23 @Override
margaretha064eb6f2018-07-10 18:33:01 +020024 public Map<?, ?> mapRow (ResultSet rs, int rowNum) throws SQLException {
Michael Hanl72c7b832015-09-03 08:42:15 +020025 User user = new UserMapper().mapRow(rs, rowNum);
26 return user.toMap();
27 }
28 }
29
30 public static class UserMapper implements RowMapper<User> {
31
32 @Override
Michael Hanl8abaf9e2016-05-23 16:46:35 +020033 public User mapRow (ResultSet rs, int rowNum) throws SQLException {
Michael Hanl72c7b832015-09-03 08:42:15 +020034 User user;
35 switch (rs.getInt("type")) {
36 case 0:
37 user = getKorAP(rs);
38 break;
margaretha35e1ca22023-11-16 22:00:01 +010039 // case 1:
40 // user = getShib(rs);
41 // break;
Michael Hanl72c7b832015-09-03 08:42:15 +020042 default:
43 user = User.UserFactory.getDemoUser();
44 user.setId(rs.getInt("id"));
margaretha35e1ca22023-11-16 22:00:01 +010045 user.setAccountCreation(
46 rs.getTimestamp(Attributes.ACCOUNT_CREATION)
47 .getTime());
Michael Hanl72c7b832015-09-03 08:42:15 +020048 return user;
49 }
50 return user;
51 }
52
Michael Hanl8abaf9e2016-05-23 16:46:35 +020053 private KorAPUser getKorAP (ResultSet rs) throws SQLException {
margaretha35e1ca22023-11-16 22:00:01 +010054 KorAPUser user = User.UserFactory
55 .getUser(rs.getString(Attributes.USERNAME));
Michael Hanl72c7b832015-09-03 08:42:15 +020056 user.setPassword(rs.getString(Attributes.PASSWORD));
57 user.setId(rs.getInt(Attributes.ID));
58 user.setAccountLocked(rs.getBoolean(Attributes.ACCOUNTLOCK));
Michael Hanl19390652016-01-16 11:01:24 +010059 user.setAccountCreation(rs.getLong(Attributes.ACCOUNT_CREATION));
Michael Hanl72c7b832015-09-03 08:42:15 +020060 user.setAccountLink(rs.getString(Attributes.ACCOUNTLINK));
Michael Hanl19390652016-01-16 11:01:24 +010061 long l = rs.getLong(Attributes.URI_EXPIRATION);
Michael Hanl72c7b832015-09-03 08:42:15 +020062
margaretha35e1ca22023-11-16 22:00:01 +010063 URIParam param = new URIParam(rs.getString(Attributes.URI_FRAGMENT),
64 l == 0 ? -1 : new Timestamp(l).getTime());
Michael Hanl72c7b832015-09-03 08:42:15 +020065 user.addField(param);
66 return user;
67 }
68
margaretha35e1ca22023-11-16 22:00:01 +010069 // private ShibbolethUser getShib (ResultSet rs) throws SQLException {
70 // ShibbolethUser user = User.UserFactory.getShibInstance(
71 // rs.getString(Attributes.USERNAME),
72 // rs.getString(Attributes.MAIL), rs.getString(Attributes.CN));
73 // user.setId(rs.getInt(Attributes.ID));
74 // return user;
75 // }
Michael Hanl72c7b832015-09-03 08:42:15 +020076
77 }
78
Michael Hanl72c7b832015-09-03 08:42:15 +020079}