01: package edu.iu.uis.eden.user;
02:
03: import java.sql.PreparedStatement;
04: import java.sql.ResultSet;
05:
06: import junit.framework.TestCase;
07:
08: import org.apache.ojb.broker.PBFactoryException;
09: import org.apache.ojb.broker.PersistenceBroker;
10: import org.apache.ojb.broker.PersistenceBrokerFactory;
11: import org.apache.ojb.broker.accesslayer.LookupException;
12:
13: import edu.iu.uis.eden.SpringServiceLocator;
14: import edu.iu.uis.eden.user.impl.IUWorkflowUser;
15: import edu.iu.uis.eden.util.Utilities;
16: import edu.iu.uis.my.mygds.GdsClient;
17: import edu.iu.uis.my.mygds.GdsException;
18: import edu.iu.uis.sit.util.directory.gds.GdsPerson;
19: import edu.iu.uis.sit.util.directory.gds.IUEduPSEMPLID;
20:
21: public class TestPopulateEdenUserNames extends TestCase {
22:
23: protected void setUp() throws Exception {
24: SpringServiceLocator.setToTestMode(null);
25: }
26:
27: public void testMigrateIds() throws Exception {
28: PersistenceBroker broker = null;
29: try {
30:
31: GdsClient gdsClient = Utilities.getGdsClient();
32:
33: broker = PersistenceBrokerFactory
34: .defaultPersistenceBroker();
35:
36: System.out.println("getting ready to update user records");
37: PreparedStatement ps = broker
38: .serviceConnectionManager()
39: .getConnection()
40: .prepareStatement(
41: "select PRSN_EN_ID, PRSN_UNIV_ID, "
42: + "PRSN_NTWRK_ID, PRSN_UNVL_USR_ID, PRSN_EMAIL_ADDR, PRSN_NM, USR_CRTE_DT, USR_LST_UPDT_DT, PRSN_ID_MSNG_IND, "
43: + "DB_LOCK_VER_NBR from EN.EN_USR_T");
44: ResultSet rs = ps.executeQuery();
45:
46: broker.beginTransaction();
47: while (rs.next()) {
48: GdsPerson gdsPerson = null;
49: String emplId = null;
50: try {
51: emplId = rs.getString(2);
52: gdsPerson = gdsClient
53: .fetchGdsUser(new IUEduPSEMPLID(emplId));
54:
55: } catch (GdsException e) {
56: System.out.println("Error fetching empl id"
57: + emplId);
58: }
59:
60: if (gdsPerson != null) {
61: IUWorkflowUser workflowUser = new IUWorkflowUser();
62: workflowUser.setWorkflowUserId(new WorkflowUserId(
63: rs.getString(1)));
64: workflowUser.setEmplId(new EmplId(emplId));
65: workflowUser.setCreateDate(rs.getTimestamp(7));
66: workflowUser.setLastUpdateDate(rs.getTimestamp(8));
67: workflowUser
68: .setIdentificationMissingIndicator(new Boolean(
69: rs.getBoolean(9)));
70: workflowUser
71: .setAuthenticationUserId(new AuthenticationUserId(
72: rs.getString(3)));
73: workflowUser.setDisplayName(rs.getString(6));
74: workflowUser.setGivenName(gdsPerson.getGivenName());
75: workflowUser.setLastName(gdsPerson.getSn());
76: workflowUser.setEmailAddress(rs.getString(5));
77: workflowUser.setUuId(new UuId(rs.getString(4)));
78: workflowUser.setLockVerNbr(new Integer(rs
79: .getInt(10)));
80: broker.store(workflowUser);
81: }
82: }
83: broker.commitTransaction();
84: rs.close();
85: ps.close();
86: } catch (PBFactoryException e1) {
87: e1.printStackTrace();
88: } catch (LookupException e1) {
89: e1.printStackTrace();
90: } catch (Exception e) {
91: e.printStackTrace();
92: } finally {
93: if (broker != null) {
94: broker.close();
95: }
96: }
97: }
98:
99: }
|