Source Code Cross Referenced for ConvertProfilesToAL.java in  » Portal » uPortal_rel-2-6-1-GA » org » jasig » portal » tools » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » uPortal_rel 2 6 1 GA » org.jasig.portal.tools 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright 2004 The JA-SIG Collaborative.  All rights reserved.
002:         *  See license distributed with this file and
003:         *  available online at http://www.uportal.org/license.html
004:         */
005:
006:        package org.jasig.portal.tools;
007:
008:        import java.io.BufferedReader;
009:        import java.io.InputStreamReader;
010:        import java.sql.Connection;
011:        import java.sql.PreparedStatement;
012:        import java.sql.ResultSet;
013:        import java.sql.SQLException;
014:        import java.util.ArrayList;
015:        import java.util.Enumeration;
016:        import java.util.Hashtable;
017:        import java.util.Iterator;
018:        import java.util.List;
019:
020:        import org.jasig.portal.PortalException;
021:        import org.jasig.portal.RDBMServices;
022:        import org.jasig.portal.StructureStylesheetDescription;
023:        import org.jasig.portal.ThemeStylesheetDescription;
024:        import org.jasig.portal.UserProfile;
025:        import org.jasig.portal.layout.IUserLayoutStore;
026:        import org.jasig.portal.layout.UserLayoutStoreFactory;
027:        import org.jasig.portal.security.IPerson;
028:        import org.jasig.portal.security.PersonFactory;
029:
030:        /**
031:         * ConvertProfilesToAL prepares and upgraded 2.1 database to work with
032:         * Aggregated Layouts and Integrated Modes.  In order to do this, it
033:         * converts the existing template user profiles to use the AL/IM structure and
034:         * theme, and deletes profiles for non-template users.  This results in the
035:         * resetting of layouts for normal users.
036:         *
037:         * @author Al Wold (alwold@asu.edu)
038:         *
039:         * @version $Revision: 35755 $
040:         */
041:        public class ConvertProfilesToAL {
042:            private static IUserLayoutStore uls;
043:
044:            public static void main(String[] args) throws Exception {
045:                RDBMServices.setGetDatasourceFromJndi(false); /*don't try jndi when not in web app */
046:                uls = UserLayoutStoreFactory.getUserLayoutStoreImpl();
047:                BufferedReader br = new BufferedReader(new InputStreamReader(
048:                        System.in));
049:
050:                System.out
051:                        .print("Please enter the max ID for a template user => ");
052:                int lastTemplateUser = Integer.parseInt(br.readLine());
053:
054:                Hashtable structSsList = uls.getStructureStylesheetList();
055:                for (Enumeration e = structSsList.keys(); e.hasMoreElements();) {
056:                    Integer id = (Integer) e.nextElement();
057:                    StructureStylesheetDescription ssd = uls
058:                            .getStructureStylesheetDescription(id.intValue());
059:                    System.out.println(id + ": " + ssd.getStylesheetName());
060:                }
061:                System.out
062:                        .println("==================================================");
063:                System.out
064:                        .print("Please enter the original structure stylesheet => ");
065:                int simpleSsId = Integer.parseInt(br.readLine());
066:                System.out
067:                        .print("Please enter the new structure stylesheet => ");
068:                int alSsId = Integer.parseInt(br.readLine());
069:
070:                Hashtable themeSsList = uls.getThemeStylesheetList();
071:                for (Enumeration e = themeSsList.keys(); e.hasMoreElements();) {
072:                    Integer id = (Integer) e.nextElement();
073:                    ThemeStylesheetDescription tsd = uls
074:                            .getThemeStylesheetDescription(id.intValue());
075:                    System.out.println(id + ": " + tsd.getStylesheetName());
076:                }
077:                System.out
078:                        .println("==================================================");
079:                System.out.print("Please enter the new theme stylesheet => ");
080:                int imSsId = Integer.parseInt(br.readLine());
081:
082:                List ids = getUserIds(lastTemplateUser);
083:                // convert template users
084:                for (Iterator i = ids.iterator(); i.hasNext();) {
085:                    int id = ((Integer) i.next()).intValue();
086:                    convertProfiles(id, simpleSsId, alSsId, imSsId);
087:                }
088:                // delete the rest
089:                deleteUserProfiles(true, lastTemplateUser);
090:                createTemplateProfiles(lastTemplateUser);
091:            }
092:
093:            public static List getUserIds(int lastTemplateUser)
094:                    throws PortalException {
095:                List userIds = new ArrayList();
096:                Connection con = RDBMServices.getConnection();
097:                try {
098:                    String query = "SELECT USER_ID FROM UP_USER WHERE USER_ID <= ?";
099:                    PreparedStatement ps = con.prepareStatement(query);
100:                    ps.setInt(1, lastTemplateUser);
101:                    try {
102:                        ResultSet rs = ps.executeQuery();
103:                        try {
104:                            while (rs.next()) {
105:                                userIds.add(new Integer(rs.getInt(1)));
106:                            }
107:                            return userIds;
108:                        } catch (SQLException sqle) {
109:                            throw new PortalException(sqle);
110:                        } finally {
111:                            rs.close();
112:                        }
113:                    } catch (SQLException sqle) {
114:                        throw new PortalException(sqle);
115:                    } finally {
116:                        ps.close();
117:                    }
118:                } catch (SQLException sqle) {
119:                    throw new PortalException(sqle);
120:                } finally {
121:                    RDBMServices.releaseConnection(con);
122:                }
123:            }
124:
125:            public static void deleteUserProfiles(boolean deleteLayouts,
126:                    int lastTemplateUser) throws Exception {
127:                System.out.print("deleting user profiles...");
128:                Connection con = RDBMServices.getConnection();
129:                try {
130:                    String query1 = "DELETE FROM UP_USER_PROFILE WHERE USER_ID > ?";
131:                    String query2 = "DELETE FROM UP_USER_UA_MAP WHERE USER_ID > ?";
132:                    String query3 = "DELETE FROM UP_SS_USER_PARM WHERE USER_ID > ?";
133:                    String query4 = "DELETE FROM UP_SS_USER_ATTS WHERE USER_ID > ?";
134:                    String query5 = "DELETE FROM UP_USER_LAYOUT WHERE USER_ID > ?";
135:                    String query6 = "DELETE FROM UP_LAYOUT_PARAM WHERE USER_ID > ?";
136:                    String query7 = "DELETE FROM UP_LAYOUT_STRUCT WHERE USER_ID > ?";
137:                    PreparedStatement ps1 = con.prepareStatement(query1);
138:                    PreparedStatement ps2 = con.prepareStatement(query2);
139:                    PreparedStatement ps3 = con.prepareStatement(query3);
140:                    PreparedStatement ps4 = con.prepareStatement(query4);
141:                    PreparedStatement ps5 = con.prepareStatement(query5);
142:                    PreparedStatement ps6 = con.prepareStatement(query6);
143:                    PreparedStatement ps7 = con.prepareStatement(query7);
144:                    ps1.setInt(1, lastTemplateUser);
145:                    ps2.setInt(1, lastTemplateUser);
146:                    ps3.setInt(1, lastTemplateUser);
147:                    ps4.setInt(1, lastTemplateUser);
148:                    ps5.setInt(1, lastTemplateUser);
149:                    ps6.setInt(1, lastTemplateUser);
150:                    ps7.setInt(1, lastTemplateUser);
151:                    try {
152:                        System.out.print("Deleting profiles...");
153:                        ps1.executeUpdate();
154:                        System.out.println("done");
155:                        System.out.print("Deleting profile mappings...");
156:                        ps2.executeUpdate();
157:                        System.out.println("done");
158:                        System.out.print("Deleting structure parameters...");
159:                        ps3.executeUpdate();
160:                        System.out.println("done");
161:                        System.out.print("Deleting theme parameters...");
162:                        ps4.executeUpdate();
163:                        System.out.println("done");
164:                        if (deleteLayouts) {
165:                            System.out.print("Deleting layouts...");
166:                            ps5.executeUpdate();
167:                            System.out.println("done");
168:                            System.out.print("Deleting layout parameters...");
169:                            ps6.executeUpdate();
170:                            System.out.println("done");
171:                            System.out.print("Deleting layout data...");
172:                            ps7.executeUpdate();
173:                            System.out.println("done");
174:                        }
175:                    } catch (SQLException sqle) {
176:                        throw new PortalException(sqle);
177:                    } finally {
178:                        ps1.close();
179:                        ps2.close();
180:                        ps3.close();
181:                        ps4.close();
182:                    }
183:                } catch (SQLException sqle) {
184:                    throw new PortalException(sqle);
185:                } finally {
186:                    RDBMServices.releaseConnection(con);
187:                }
188:                System.out.println("done");
189:            }
190:
191:            public static void convertProfiles(int id, int simpleSsId,
192:                    int alSsId, int imSsId) throws Exception {
193:                System.out.print("converting profiles for ID " + id + "...");
194:                IPerson person = PersonFactory.createPerson();
195:                person.setID(id);
196:                Hashtable list = uls.getUserProfileList(person);
197:                for (Enumeration e = list.keys(); e.hasMoreElements();) {
198:                    UserProfile profile = (UserProfile) list.get(e
199:                            .nextElement());
200:                    if (profile.getStructureStylesheetId() == simpleSsId) {
201:                        profile.setStructureStylesheetId(alSsId);
202:                        profile.setThemeStylesheetId(imSsId);
203:                        uls.updateUserProfile(person, profile);
204:                    }
205:                }
206:                System.out.println("done");
207:            }
208:
209:            public static void createTemplateProfiles(int lastTemplateUser)
210:                    throws PortalException {
211:                System.out.println("creating template profiles...");
212:                Connection con = RDBMServices.getConnection();
213:                try {
214:                    String query = "SELECT USER_ID, USER_DFLT_USR_ID FROM UP_USER WHERE USER_ID > ?";
215:                    String templateQuery = "SELECT USER_ID, PROFILE_ID, PROFILE_NAME, DESCRIPTION "
216:                            + "FROM UP_USER_PROFILE WHERE USER_ID = ?";
217:                    String insert = "INSERT INTO UP_USER_PROFILE (USER_ID, PROFILE_ID, PROFILE_NAME, DESCRIPTION) "
218:                            + "VALUES (?, ?, ?, ?)";
219:                    PreparedStatement selectPs = con.prepareStatement(query);
220:                    PreparedStatement templatePs = con
221:                            .prepareStatement(templateQuery);
222:                    PreparedStatement insertPs = con.prepareStatement(insert);
223:                    selectPs.setInt(1, lastTemplateUser);
224:                    int templateId;
225:                    try {
226:                        ResultSet rs = selectPs.executeQuery();
227:                        while (rs.next()) {
228:                            int id = rs.getInt(1);
229:                            templateId = rs.getInt(2);
230:                            templatePs.setInt(1, templateId);
231:                            ResultSet rs2 = templatePs.executeQuery();
232:                            while (rs2.next()) {
233:                                insertPs.setInt(1, id);
234:                                insertPs.setInt(2, rs2.getInt(2));
235:                                insertPs.setString(3, rs2.getString(3));
236:                                insertPs.setString(4, rs2.getString(4));
237:                                insertPs.executeUpdate();
238:                            }
239:                            rs2.close();
240:                        }
241:                    } catch (SQLException sqle) {
242:                        throw new PortalException(sqle);
243:                    } finally {
244:                        selectPs.close();
245:                        templatePs.close();
246:                        insertPs.close();
247:                    }
248:                } catch (SQLException sqle) {
249:                    throw new PortalException(sqle);
250:                } finally {
251:                    RDBMServices.releaseConnection(con);
252:                }
253:            }
254:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.