Source Code Cross Referenced for MigrationModule22_24.java in  » Portal » jboss-portal-2.6.4 » org » jboss » portal » migration » 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 » jboss portal 2.6.4 » org.jboss.portal.migration 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /******************************************************************************
002:         * JBoss, a division of Red Hat                                               *
003:         * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
004:         * contributors as indicated by the @authors tag. See the                     *
005:         * copyright.txt in the distribution for a full listing of                    *
006:         * individual contributors.                                                   *
007:         *                                                                            *
008:         * This is free software; you can redistribute it and/or modify it            *
009:         * under the terms of the GNU Lesser General Public License as                *
010:         * published by the Free Software Foundation; either version 2.1 of           *
011:         * the License, or (at your option) any later version.                        *
012:         *                                                                            *
013:         * This software is distributed in the hope that it will be useful,           *
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU           *
016:         * Lesser General Public License for more details.                            *
017:         *                                                                            *
018:         * You should have received a copy of the GNU Lesser General Public           *
019:         * License along with this software; if not, write to the Free                *
020:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA         *
021:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.                   *
022:         ******************************************************************************/package org.jboss.portal.migration;
023:
024:        import org.apache.log4j.Logger;
025:        import org.hibernate.Query;
026:        import org.hibernate.ScrollMode;
027:        import org.hibernate.ScrollableResults;
028:        import org.hibernate.SessionFactory;
029:        import org.hibernate.cfg.Configuration;
030:        import org.hibernate.criterion.Restrictions;
031:        import org.jboss.portal.migration.bean.Create;
032:        import org.jboss.portal.migration.bean.DataSourceDS;
033:        import org.jboss.portal.migration.helper.Finder;
034:        import org.jboss.portal.migration.helper.Tools;
035:        import org.jboss.portal.migration.model22.impl.instance.Instance22Impl;
036:        import org.jboss.portal.migration.model22.impl.instance.InstancePreference22Impl;
037:        import org.jboss.portal.migration.model22.impl.portal.ObjectNode22;
038:        import org.jboss.portal.migration.model22.impl.role.Role22Impl;
039:        import org.jboss.portal.migration.model22.impl.security.HbmSecurityConstraint;
040:        import org.jboss.portal.migration.model22.impl.security.SecurityPolicy;
041:        import org.jboss.portal.migration.model22.impl.user.User22Impl;
042:        import org.jboss.portal.migration.model22.impl.user.UserPreference22Impl;
043:        import org.jboss.portal.migration.model22.impl.user.UserPreferences22Impl;
044:        import org.jboss.portal.migration.model22.impl.user.UserPreferencesGroup22Impl;
045:        import org.jboss.portal.migration.model24.identity.Role24Impl;
046:        import org.jboss.portal.migration.model24.identity.User24Impl;
047:        import org.jboss.portal.migration.model24.instance.Instance24Impl;
048:        import org.jboss.portal.migration.model24.instance.InstanceSecurityBinding;
049:        import org.jboss.portal.migration.model24.instance.UserInstance24;
050:        import org.jboss.portal.migration.model24.portal.ObjectNode24;
051:        import org.jboss.portal.migration.model24.portal.ObjectNodeSecurityConstraint;
052:        import org.jboss.portal.migration.model24.portal.PortalObject24Impl;
053:        import org.jboss.portal.migration.model24.portlet.PersistentState24;
054:        import org.jboss.portal.migration.model24.portlet.PersistentStateEntry24;
055:
056:        import javax.faces.context.FacesContext;
057:        import java.net.URL;
058:        import java.util.HashMap;
059:        import java.util.Iterator;
060:        import java.util.List;
061:        import java.util.Map;
062:        import java.util.Set;
063:
064:        /**
065:         * Handles batch processing tasks for migration from 2.2 to 2.4.
066:         * <p/>
067:         * TODO: Move all CMS migration methods to use StatelessSession process.
068:         *
069:         * @author <a href="mailto:roy@jboss.org">Roy Russo</a>
070:         * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw Dawidowicz</a>
071:         * @version $Revision: 8784 $
072:         */
073:        public class MigrationModule22_24 extends MigrationModule {
074:            private static final String SQL_REPOSITORYENTRY = "FROM RepositoryEntry";
075:            private static final String SQL_CMSENTRY = "FROM CMSEntry";
076:            private static final String SQL_VERSIONENTRY = "FROM VersionEntry";
077:            private static final String SQL_VERSIONBINVAL = "FROM VersionBinVal";
078:            private static final String SQL_VERSIONNODE = "FROM VersionNode";
079:            private static final String SQL_VERSIONPROP = "FROM VersionProp";
080:            private static final String SQL_VERSIONREFS = "FROM VersionRefs";
081:            private static final String SQL_WSPBINVAL = "FROM WSPBinVal";
082:            private static final String SQL_WSPNODE = "FROM WSPNode";
083:            private static final String SQL_WSPPROP = "FROM WSPProp";
084:            private static final String SQL_WSPREFS = "FROM WSPRefs";
085:
086:            private static final String SQL_ROLE = "SELECT key FROM Role22Impl order by key asc";
087:            private static final String SQL_USER = "SELECT key FROM User22Impl order by key asc";
088:            private static final String SQL_OBJECT = "SELECT key FROM PortalObject22Impl";
089:
090:            private final Logger log = Logger.getLogger(getClass());
091:
092:            public void init() throws Exception {
093:                URL url_24 = Create.class
094:                        .getResource("/schema24/hibernate_24.cfg.xml");
095:                URL url_22 = Create.class
096:                        .getResource("/schema22/hibernate_22.cfg.xml");
097:
098:                try {
099:                    Configuration TOhibernateConfiguration = new Configuration()
100:                            .configure(url_24);
101:                    Configuration FROMhibernConfiguration = new Configuration()
102:                            .configure(url_22);
103:
104:                    // to session config
105:                    FacesContext context = FacesContext.getCurrentInstance();
106:                    DataSourceDS dsBean = (DataSourceDS) context
107:                            .getApplication().createValueBinding(
108:                                    "#{datasource}").getValue(context);
109:                    TOhibernateConfiguration.setProperty(
110:                            "hibernate.connection.datasource", "java:/"
111:                                    + dsBean.getDatasource24());
112:                    if (TOhibernateConfiguration
113:                            .getProperty("hibernate.dialect") == null) // allow dialect override
114:                    {
115:                        TOhibernateConfiguration.setProperty(
116:                                "hibernate.dialect", dsBean.getDialect24());
117:                    }
118:
119:                    SessionFactory TOhibernateSessionFactory = TOhibernateConfiguration
120:                            .buildSessionFactory();
121:                    this .setToSessionFactory(TOhibernateSessionFactory);
122:
123:                    // from session config
124:                    FROMhibernConfiguration.setProperty(
125:                            "hibernate.connection.datasource", "java:/"
126:                                    + dsBean.getDatasource22());
127:                    if (FROMhibernConfiguration
128:                            .getProperty("hibernate.dialect") == null) // allow dialect override
129:                    {
130:                        FROMhibernConfiguration.setProperty(
131:                                "hibernate.dialect", dsBean.getDialect22());
132:                    }
133:
134:                    SessionFactory FROMhibernateSessionFactory = FROMhibernConfiguration
135:                            .buildSessionFactory();
136:                    this .setFromSessionFactory(FROMhibernateSessionFactory);
137:
138:                    // needed for schema exports:
139:                    this .setToConfiguration(TOhibernateConfiguration);
140:                    this .setFromConfiguration(FROMhibernConfiguration);
141:                } catch (Exception e) {
142:                    e.printStackTrace();
143:                }
144:            }
145:
146:            /**
147:             * Generic method that uses the StatelessSession to replicate tables, given a source SQL Select.
148:             *
149:             * @param SQL
150:             * @throws Exception
151:             */
152:            private void migrateStateless(String SQL) throws Exception {
153:                this .nextFromStatelessSession();
154:                this .nextToStatelessSession();
155:
156:                ScrollableResults items = fromStatelessSession.createQuery(SQL)
157:                        .scroll(ScrollMode.FORWARD_ONLY);
158:                while (items.next()) {
159:                    this .toStatelessSession.insert(items.get(0));
160:                }
161:            }
162:
163:            /** @throws Exception  */
164:            private void migrateRoles() throws Exception {
165:                this .nextToSession();
166:                this .nextFromSession();
167:
168:                Query query = this .fromSession.createQuery(SQL_ROLE);
169:                Iterator iterator = query.iterate();
170:                List list = Tools.toList(iterator);
171:                int count = 0;
172:                for (Iterator i = list.iterator(); i.hasNext();) {
173:                    Long key = (Long) i.next();
174:
175:                    Role22Impl role = (Role22Impl) this .fromSession.get(
176:                            Role22Impl.class, key);
177:                    log.debug("Migrating role with id: " + key + "; and name: "
178:                            + role.getName());
179:                    //this.fromSession.evict(user);
180:                    //this.toSession.replicate(user, ReplicationMode.OVERWRITE);
181:                    Role24Impl role24 = MigrationUtils.cloneRoleTo24(role);
182:
183:                    this .toSession.save(role24);
184:
185:                    if ((++count % 20 == 0)) {
186:                        this .fromSession.flush();
187:                        this .fromSession.clear();
188:                        this .toSession.flush();
189:                        this .toSession.clear();
190:                    }
191:
192:                    this .nextToSession();
193:                    this .nextFromSession();
194:                }
195:            }
196:
197:            /** @throws Exception  */
198:            private void migrateUsers() throws Exception {
199:                this .nextToSession();
200:                this .nextFromSession();
201:
202:                Query query = this .fromSession.createQuery(SQL_USER);
203:                Iterator iterator = query.iterate();
204:                List list = Tools.toList(iterator);
205:                int count = 0;
206:                for (Iterator i = list.iterator(); i.hasNext();) {
207:                    Long key = (Long) i.next();
208:
209:                    User22Impl user = (User22Impl) this .fromSession.get(
210:                            User22Impl.class, key);
211:                    log.debug("Migrating user with id: " + key + "; and name: "
212:                            + user.getUserName());
213:                    //this.fromSession.evict(user);
214:                    //this.toSession.replicate(user, ReplicationMode.OVERWRITE);
215:                    User24Impl user24 = MigrationUtils.cloneUserTo24(user);
216:
217:                    this .toSession.save(user24);
218:
219:                    if ((++count % 20 == 0)) {
220:                        this .fromSession.flush();
221:                        this .fromSession.clear();
222:                        this .toSession.flush();
223:                        this .toSession.clear();
224:                    }
225:                }
226:                this .nextToSession();
227:                this .nextFromSession();
228:            }
229:
230:            /** migrate relations between users and roles */
231:            private void migrateUserRoleRelations() throws Exception {
232:                log.info("Migration: migrating users in roles membership...");
233:                //make new tx and session
234:                this .nextFromSession();
235:                this .nextToSession();
236:
237:                Query query = this .fromSession
238:                        .createQuery("SELECT key FROM User22Impl order by key");
239:                Iterator iterator = query.iterate();
240:                List list = Tools.toList(iterator);
241:                int count = 0;
242:                for (Iterator i = list.iterator(); i.hasNext();) {
243:                    Long u22id = (Long) i.next();
244:                    User22Impl user22 = (User22Impl) fromSession.get(
245:                            User22Impl.class, u22id);
246:                    Set roles = user22.getRoles();
247:                    User24Impl user24 = Finder.findUser24ByUserName(toSession,
248:                            user22.getUserName());
249:
250:                    //prevent data inconsistency process break
251:                    if (user24 == null) {
252:                        log
253:                                .error("Migration error - can't find migrated user with id: "
254:                                        + u22id);
255:                        continue;
256:                    }
257:
258:                    log
259:                            .debug("Migrating roles relationship for user with name: "
260:                                    + user24.getUserName());
261:                    for (Iterator j = roles.iterator(); j.hasNext();) {
262:                        Role22Impl role22 = (Role22Impl) j.next();
263:                        String r22Name = role22.getName();
264:                        Role24Impl role24 = Finder.findRole24ByName(toSession,
265:                                r22Name);
266:                        user24.getRoles().add(role24);
267:                        role24.users.add(user24);
268:                    }
269:
270:                    if ((++count % 20 == 0)) {
271:                        this .fromSession.flush();
272:                        this .fromSession.clear();
273:                        this .toSession.flush();
274:                        this .toSession.clear();
275:                    }
276:
277:                }
278:                this .nextToSession();
279:                this .nextFromSession();
280:
281:            }
282:
283:            /**
284:             * Method finds root node of ObjectNode table and fire recurrence migration
285:             *
286:             * @throws Exception
287:             */
288:            private void migrateObjectNodes() throws Exception {
289:                this .nextFromSession();
290:                this .nextToSession();
291:
292:                log.info("Stratgin Portal Objects migration...");
293:
294:                Query query = this .fromSession
295:                        .createQuery("FROM ObjectNode22 ORDER BY parent_key asc ");
296:                for (Iterator iterator = query.iterate(); iterator.hasNext();) {
297:                    ObjectNode22 objectnode = (ObjectNode22) iterator.next();
298:                    if (objectnode.getParent() == null) // copies the root node
299:                    {
300:                        log.info("Migrating root node");
301:
302:                        migrateObjectNode(objectnode);
303:
304:                        //as we found root node we stop iteration
305:                        break;
306:                    }
307:                }
308:
309:                this .nextFromSession();
310:                this .nextToSession();
311:
312:            }
313:
314:            /**
315:             * Recurrence migration of ObjectNode
316:             *
317:             * @param node22
318:             * @return
319:             */
320:            private ObjectNode24 migrateObjectNode(ObjectNode22 node22)
321:                    throws Exception {
322:                if (node22 != null) {
323:                    log.info("Migrating ObjectNode: " + node22.getPath());
324:                    ObjectNode24 node24 = MigrationUtils
325:                            .cloneObjectNode22To24(node22);
326:
327:                    //first save to keep preety key order
328:                    toSession.save(node24);
329:
330:                    //toSession.flush();
331:
332:                    //Iterate over each child
333:                    if (node22.getChildren() != null) {
334:                        Map children = new HashMap();
335:                        for (Iterator i = node22.getChildren().values()
336:                                .iterator(); i.hasNext();) {
337:                            ObjectNode22 child22 = (ObjectNode22) i.next();
338:
339:                            //recurrence call to migrate child node
340:                            ObjectNode24 child24 = migrateObjectNode(child22);
341:
342:                            //link migrated child to current node
343:                            child24.setParent(node24);
344:                            children.put(child24.getName(), child24);
345:
346:                        }
347:
348:                        node24.setChildren(children);
349:
350:                        //migrate related PortalObject
351:                        PortalObject24Impl object24 = MigrationUtils
352:                                .clonePortalObject(node22.getObject());
353:
354:                        if (object24 != null) {
355:                            log.info("Migrating related PortalObject: "
356:                                    + node22.getObject().getName());
357:                            node24.setObject(object24);
358:                            object24.setObjectNode(node24);
359:                            toSession.save(object24);
360:                        }
361:                    }
362:
363:                    return node24;
364:                } else {
365:                    return null;
366:                }
367:            }
368:
369:            /**
370:             * migrate Instance22Impl table with instance prefs
371:             *
372:             * @throws Exception
373:             */
374:            private void migrateInstances() throws Exception {
375:                this .nextFromSession();
376:                this .nextToSession();
377:
378:                log.info("Starting Portlet Instances migration...");
379:
380:                Query query = this .fromSession
381:                        .createQuery("SELECT key FROM Instance22Impl ORDER BY key");
382:                //query.iterate();
383:
384:                int count = 0;
385:                for (Iterator i = query.list().iterator(); i.hasNext();) {
386:                    Long key22 = (Long) i.next();
387:                    Instance22Impl instance22 = (Instance22Impl) this .fromSession
388:                            .get(Instance22Impl.class, key22);
389:
390:                    log.debug("Migrating instance: "
391:                            + instance22.getInstanceId());
392:
393:                    //migrate instance object and persist
394:                    Instance24Impl instance24 = MigrationUtils
395:                            .cloneInstance22ImplTo24(instance22);
396:                    this .toSession.save(instance24);
397:
398:                    //if there are some prefs for this instance migrate them
399:                    if ((instance22.getPreferencesMap() != null)
400:                            && (instance22.getPreferencesMap().size() > 0)) {
401:                        //create clone
402:                        PersistentState24 state24 = new PersistentState24();
403:                        state24.setPortletId(instance22.getComponentRef());
404:
405:                        //persist clone
406:                        toSession.save(state24);
407:
408:                        //construct entries map
409:                        Map newEntries = new HashMap();
410:                        for (Iterator j = instance22.getPreferencesMap()
411:                                .values().iterator(); j.hasNext();) {
412:                            InstancePreference22Impl pref22 = (InstancePreference22Impl) j
413:                                    .next();
414:
415:                            log.debug("Migrating instance preference: "
416:                                    + pref22.getName());
417:
418:                            PersistentStateEntry24 entry = MigrationUtils
419:                                    .cloneInstancePrefToPortletState(pref22);
420:
421:                            //persist entry
422:                            toSession.save(entry);
423:                            newEntries.put(entry.getName(), entry);
424:                        }
425:
426:                        //set entries map
427:                        state24.setEntries(newEntries);
428:
429:                        toSession.flush();
430:
431:                        //and update instance portlet ref for the clone
432:                        instance24.setPortletRef("local._" + state24.getKey());
433:                    }
434:
435:                    if ((++count % 20 == 0)) {
436:                        this .fromSession.flush();
437:                        this .fromSession.clear();
438:                        this .toSession.flush();
439:                        this .toSession.clear();
440:                    }
441:                }
442:            }
443:
444:            /**
445:             * migrate user prefs - AFTER portlet instances were migrated
446:             *
447:             * @throws Exception
448:             */
449:            private void migrateUserPreferences() throws Exception {
450:                nextFromSession();
451:                nextToSession();
452:
453:                log
454:                        .info("Starting migration of user preferences for portlet instances...");
455:
456:                Query query = fromSession
457:                        .createQuery("SELECT key FROM UserPreferencesGroup22Impl ORDER BY key");
458:
459:                int count = 0;
460:
461:                for (Iterator i = query.iterate(); i.hasNext();) {
462:                    //so we grab prefs group
463:                    Long groupKey = (Long) i.next();
464:                    UserPreferencesGroup22Impl prefGroup = (UserPreferencesGroup22Impl) fromSession
465:                            .get(UserPreferencesGroup22Impl.class, groupKey);
466:
467:                    //and get 2.4 user corresponding to that group
468:                    User24Impl user24 = (User24Impl) toSession.createCriteria(
469:                            User24Impl.class).add(
470:                            Restrictions.eq("userName", prefGroup.groupId))
471:                            .uniqueResult();
472:
473:                    //avoid data inconsistency break whole process
474:                    if (user24 == null) {
475:                        log
476:                                .error("Migration error - can't find migrated user with id: "
477:                                        + prefGroup.groupId);
478:                        continue;
479:                    }
480:
481:                    log.debug("Migrating preferences for user: "
482:                            + user24.getUserName());
483:
484:                    //and iterate ofer pref sets
485:                    for (Iterator j = prefGroup.prefMap.values().iterator(); j
486:                            .hasNext();) {
487:                        UserPreferences22Impl prefSet = (UserPreferences22Impl) j
488:                                .next();
489:
490:                        //for each pref set we must create a clone
491:
492:                        //create clone
493:                        PersistentState24 state24 = new PersistentState24();
494:
495:                        Instance22Impl instance22 = (Instance22Impl) fromSession
496:                                .createCriteria(Instance22Impl.class).add(
497:                                        Restrictions.eq("instanceId", prefSet
498:                                                .getId())).uniqueResult();
499:                        state24.setPortletId(instance22.getComponentRef());
500:
501:                        //persist clone
502:                        toSession.save(state24);
503:
504:                        //construct entries map
505:                        Map newEntries = new HashMap();
506:                        for (Iterator k = prefSet.map.values().iterator(); k
507:                                .hasNext();) {
508:                            UserPreference22Impl pref22 = (UserPreference22Impl) k
509:                                    .next();
510:
511:                            log.debug("Migrating preference: "
512:                                    + pref22.getName());
513:
514:                            PersistentStateEntry24 entry = MigrationUtils
515:                                    .cloneUserPrefToPortletState(pref22);
516:
517:                            //persist entry
518:                            toSession.save(entry);
519:                            newEntries.put(entry.getName(), entry);
520:                        }
521:
522:                        //set entries map
523:                        state24.setEntries(newEntries);
524:
525:                        //and update 2.4 instance to reference to the created clone
526:                        UserInstance24 userInstance24 = new UserInstance24();
527:                        Instance24Impl instance24 = (Instance24Impl) toSession
528:                                .createCriteria(Instance24Impl.class).add(
529:                                        Restrictions.eq("instanceId", prefSet
530:                                                .getId())).uniqueResult();
531:                        userInstance24.setInstance(instance24);
532:                        userInstance24.setUserId(user24.getKey().toString());
533:                        userInstance24.setPortletRef("local._"
534:                                + state24.getKey());
535:
536:                        toSession.save(userInstance24);
537:                    }
538:
539:                    if ((++count % 20 == 0)) {
540:                        this .fromSession.flush();
541:                        this .fromSession.clear();
542:                        this .toSession.flush();
543:                        this .toSession.clear();
544:                    }
545:
546:                }
547:
548:            }
549:
550:            private void migrateSecurityPolicy() throws Exception {
551:                nextFromSession();
552:                nextToSession();
553:
554:                log.info("Starting migrating security policies...");
555:
556:                /*//at first just create allow permissions for every context object
557:                //TODO: change this to migrate true portal permissions
558:                Query portalQuery = toSession.createQuery("FROM Context24Impl");
559:                for (Iterator portals = portalQuery.iterate(); portals.hasNext();)
560:                {
561:                   Context24Impl context = (Context24Impl)portals.next();
562:                   log.debug("Updating security for context: " + context.getObjectNode().getPath() );
563:                   ObjectNodeSecurityConstraint constraint = new ObjectNodeSecurityConstraint();
564:                   constraint.setRole("__unchecked__");
565:                   Set actions = new HashSet();
566:                   actions.add("view");
567:                   constraint.setActions(actions);
568:                   constraint.setObjectNode(context.getObjectNode());
569:
570:                   if (context.getObjectNode().getSecurityConstraints() == null)
571:                   {
572:                      context.getObjectNode().setSecurityConstraints(new HashMap());
573:                   }
574:                   //Map constraints = new HashMap();
575:                   context.getObjectNode().getSecurityConstraints().put(context.getObjectNode().getKey(), constraint);
576:                   //portal.getObjectNode().setSecurityConstraints(constraints);
577:
578:                   toSession.save(constraint);
579:                }*/
580:
581:                //at first just create allow permissions for every portal object
582:                //TODO: change this to migrate true portal permissions
583:                /*Query portalQuery = toSession.createQuery("FROM Portal24Impl");
584:                for (Iterator portals = portalQuery.iterate(); portals.hasNext();)
585:                {
586:                   Portal24Impl portal = (Portal24Impl)portals.next();
587:                   log.info("Updating security for portal: " + portal.getObjectNode().getPath() );
588:                   ObjectNodeSecurityConstraint constraint = new ObjectNodeSecurityConstraint();
589:                   constraint.setRole("__unchecked__");
590:                   Set actions = new HashSet();
591:                   actions.add("view");
592:                   constraint.setActions(actions);
593:                   constraint.setObjectNode(portal.getObjectNode());
594:
595:                   if (portal.getObjectNode().getSecurityConstraints() == null)
596:                   {
597:                      portal.getObjectNode().setSecurityConstraints(new HashMap());
598:                   }
599:                   //Map constraints = new HashMap();
600:                   portal.getObjectNode().getSecurityConstraints().put(portal.getObjectNode().getKey(), constraint);
601:                   //portal.getObjectNode().setSecurityConstraints(constraints);
602:
603:                   toSession.save(constraint);
604:                }*/
605:
606:                //then iterate and convert permissions for nodes and instances
607:                Query query = fromSession
608:                        .createQuery("SELECT key FROM SecurityPolicy ORDER BY key");
609:
610:                int count = 0;
611:                for (Iterator i = query.iterate(); i.hasNext();) {
612:                    Long key = (Long) i.next();
613:
614:                    SecurityPolicy sp = (SecurityPolicy) fromSession.get(
615:                            SecurityPolicy.class, key);
616:
617:                    String parentRef = sp.getParentReference();
618:
619:                    log.info("Migrating policy from: " + sp.getReference());
620:
621:                    String path = "";
622:
623:                    if (parentRef.equals("/")) {
624:                        //TODO:for now we just enable unchecked view of every portal we migrated little earlier
625:                    } else if (parentRef.equals("/portalobject")) {
626:                        path = cutPath(sp.getParentReference(), sp
627:                                .getReference());
628:                        log.info("Migrating portalobject: " + path);
629:
630:                        ObjectNode24 objectNode24 = (ObjectNode24) toSession
631:                                .createCriteria(ObjectNode24.class).add(
632:                                        Restrictions.eq("path", path))
633:                                .uniqueResult();
634:                        if (objectNode24 == null) {
635:                            log
636:                                    .error("Critical state: can't find ObjectNode for extracted path: "
637:                                            + path);
638:                        }
639:                        if (objectNode24.getSecurityConstraints() == null) {
640:                            objectNode24.setSecurityConstraints(new HashMap());
641:                        }
642:
643:                        //Map bindings = new HashMap();
644:                        for (Iterator ctrs = sp.getConstraints().iterator(); ctrs
645:                                .hasNext();) {
646:                            HbmSecurityConstraint hsc = (HbmSecurityConstraint) ctrs
647:                                    .next();
648:                            ObjectNodeSecurityConstraint nodeConstraint = MigrationUtils
649:                                    .cloneConstraintToObjectNodeConstraint(hsc);
650:                            nodeConstraint.setObjectNode(objectNode24);
651:                            objectNode24.getSecurityConstraints().put(
652:                                    objectNode24.getKey(), nodeConstraint);
653:                            log.debug("Security Constraint for node: "
654:                                    + objectNode24.getKey());
655:                            toSession.save(nodeConstraint);
656:
657:                        }
658:                        //objectNode24.setSecurityConstraints(bindings);
659:
660:                        //objectNode24.
661:                    } else if (parentRef.equals("/instance")) {
662:                        path = cutPath(sp.getParentReference(), sp
663:                                .getReference());
664:                        log.debug("Migrating instance: " + path);
665:
666:                        Instance24Impl instance24 = (Instance24Impl) toSession
667:                                .createCriteria(Instance24Impl.class).add(
668:                                        Restrictions.eq("instanceId", path))
669:                                .uniqueResult();
670:                        if (instance24 == null) {
671:                            log
672:                                    .error("Critical state: can't find InstanceImpl for extracted instanceId: "
673:                                            + path);
674:                        }
675:                        if (instance24.getSecurityBindings() == null) {
676:                            instance24.setSecurityBindings(new HashMap());
677:                        }
678:
679:                        //Map bindings = new HashMap();
680:                        for (Iterator ctrs = sp.getConstraints().iterator(); ctrs
681:                                .hasNext();) {
682:                            HbmSecurityConstraint hsc = (HbmSecurityConstraint) ctrs
683:                                    .next();
684:                            InstanceSecurityBinding instanceConstraint = MigrationUtils
685:                                    .cloneConstraintToInstanceConstraint(hsc);
686:                            instanceConstraint.instance = instance24;
687:                            instance24.getSecurityBindings().put(
688:                                    instance24.getKey(), instanceConstraint);
689:                            toSession.save(instanceConstraint);
690:                            //bindings.put(instance24.getKey(), instanceConstraint);
691:                        }
692:                        //instance24.setSecurityBindings(bindings);
693:                    }
694:
695:                    if ((++count % 20 == 0)) {
696:                        this .fromSession.flush();
697:                        this .fromSession.clear();
698:                        this .toSession.flush();
699:                        this .toSession.clear();
700:                    }
701:                }
702:
703:            }
704:
705:            private String cutPath(String parentRef, String reference) {
706:
707:                String path = reference.substring(parentRef.length() + 1);
708:
709:                //replace "+" chars with spaces
710:                path = path.replaceAll("\\+", " ");
711:                //log.info("Produced path: " + path);
712:                return path;
713:
714:            }
715:
716:            public void migrateCMSData() throws Exception {
717:                migrateStateless(SQL_CMSENTRY);
718:                migrateStateless(SQL_REPOSITORYENTRY);
719:                migrateStateless(SQL_VERSIONENTRY);
720:
721:                migrateStateless(SQL_VERSIONBINVAL);
722:                migrateStateless(SQL_VERSIONNODE);
723:                migrateStateless(SQL_VERSIONPROP);
724:                migrateStateless(SQL_VERSIONREFS);
725:                migrateStateless(SQL_WSPBINVAL);
726:                migrateStateless(SQL_WSPNODE);
727:                migrateStateless(SQL_WSPPROP);
728:                migrateStateless(SQL_WSPREFS);
729:            }
730:
731:            public void migrateUsersRoles() throws Exception {
732:                log.info("Initializing users and roles migration");
733:                migrateUsers();
734:                migrateRoles();
735:                migrateUserRoleRelations();
736:            }
737:
738:            public void migratePortalObjects() throws Exception {
739:                migrateObjectNodes();
740:
741:            }
742:
743:            public void migratePortletInstances() throws Exception {
744:                migrateInstances();
745:                migrateUserPreferences();
746:            }
747:
748:            public void migrateSecurity() throws Exception {
749:                migrateSecurityPolicy();
750:            }
751:
752:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.