Source Code Cross Referenced for OspMigrationJob.java in  » ERP-CRM-Financial » sakai » org » theospi » portfolio » 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 » ERP CRM Financial » sakai » org.theospi.portfolio.migration 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**********************************************************************************
0002:         * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/migration/api-impl/src/java/org/theospi/portfolio/migration/OspMigrationJob.java $
0003:         * $Id: OspMigrationJob.java 22527 2007-03-13 13:45:54Z chmaurer@iupui.edu $
0004:         ***********************************************************************************
0005:         *
0006:         * Copyright (c) 2006 The Sakai Foundation.
0007:         *
0008:         * Licensed under the Educational Community License, Version 1.0 (the "License");
0009:         * you may not use this file except in compliance with the License.
0010:         * You may obtain a copy of the License at
0011:         *
0012:         *      http://www.opensource.org/licenses/ecl1.php
0013:         *
0014:         * Unless required by applicable law or agreed to in writing, software
0015:         * distributed under the License is distributed on an "AS IS" BASIS,
0016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0017:         * See the License for the specific language governing permissions and
0018:         * limitations under the License.
0019:         *
0020:         **********************************************************************************/package org.theospi.portfolio.migration;
0021:
0022:        import java.io.ByteArrayInputStream;
0023:        import java.io.ByteArrayOutputStream;
0024:        import java.io.IOException;
0025:        import java.io.InputStream;
0026:        import java.sql.Connection;
0027:        import java.sql.ResultSet;
0028:        import java.sql.SQLException;
0029:        import java.sql.Statement;
0030:        import java.util.ArrayList;
0031:        import java.util.Date;
0032:        import java.util.HashMap;
0033:        import java.util.HashSet;
0034:        import java.util.Iterator;
0035:        import java.util.List;
0036:        import java.util.Map;
0037:        import java.util.Set;
0038:
0039:        import javax.sql.DataSource;
0040:
0041:        import org.apache.commons.logging.Log;
0042:        import org.apache.commons.logging.LogFactory;
0043:        import org.quartz.Job;
0044:        import org.quartz.JobExecutionContext;
0045:        import org.quartz.JobExecutionException;
0046:        import org.sakaiproject.authz.api.SecurityService;
0047:        import org.sakaiproject.component.cover.ServerConfigurationService;
0048:        import org.sakaiproject.content.api.ContentCollectionEdit;
0049:        import org.sakaiproject.content.api.ContentHostingService;
0050:        import org.sakaiproject.content.api.ContentResource;
0051:        import org.sakaiproject.db.cover.SqlService;
0052:        import org.sakaiproject.entity.api.ResourceProperties;
0053:        import org.sakaiproject.entity.api.ResourcePropertiesEdit;
0054:        import org.sakaiproject.event.cover.NotificationService;
0055:        import org.sakaiproject.exception.IdUsedException;
0056:        import org.sakaiproject.metaobj.shared.mgt.AgentManager;
0057:        import org.sakaiproject.metaobj.shared.mgt.IdManager;
0058:        import org.sakaiproject.metaobj.shared.mgt.MetaobjEntityManager;
0059:        import org.sakaiproject.metaobj.shared.model.Agent;
0060:        import org.sakaiproject.metaobj.shared.model.ElementBean;
0061:        import org.sakaiproject.metaobj.shared.model.Id;
0062:        import org.sakaiproject.metaobj.shared.model.IdentifiableObject;
0063:        import org.sakaiproject.metaobj.shared.model.StructuredArtifactDefinitionBean;
0064:        import org.sakaiproject.metaobj.shared.mgt.StructuredArtifactDefinitionManager;
0065:        import org.sakaiproject.metaobj.utils.xml.SchemaFactory;
0066:        import org.sakaiproject.metaobj.utils.xml.SchemaNode;
0067:        import org.sakaiproject.site.api.SiteService;
0068:        import org.sakaiproject.site.api.ToolConfiguration;
0069:        import org.sakaiproject.tool.cover.SessionManager;
0070:        import org.theospi.portfolio.guidance.mgt.GuidanceManager;
0071:        import org.theospi.portfolio.guidance.model.Guidance;
0072:        import org.theospi.portfolio.help.model.Glossary;
0073:        import org.theospi.portfolio.help.model.GlossaryEntry;
0074:        import org.theospi.portfolio.security.AuthorizationFacade;
0075:        import org.theospi.portfolio.security.impl.AllowAllSecurityAdvisor;
0076:        import org.theospi.portfolio.security.Authorization;
0077:        import org.theospi.portfolio.shared.model.ItemDefinitionMimeType;
0078:        import org.theospi.portfolio.matrix.MatrixFunctionConstants;
0079:        import org.theospi.portfolio.matrix.DefaultScaffoldingBean;
0080:        import org.theospi.portfolio.review.mgt.ReviewManager;
0081:        import org.theospi.portfolio.review.model.Review;
0082:        import org.theospi.portfolio.matrix.MatrixManager;
0083:        import org.theospi.portfolio.matrix.model.Attachment;
0084:        import org.theospi.portfolio.matrix.model.Cell;
0085:        import org.theospi.portfolio.matrix.model.Matrix;
0086:        import org.theospi.portfolio.matrix.model.Scaffolding;
0087:        import org.theospi.portfolio.matrix.model.ScaffoldingCell;
0088:        import org.theospi.portfolio.matrix.model.Criterion;
0089:        import org.theospi.portfolio.matrix.model.Level;
0090:        import org.theospi.portfolio.matrix.model.WizardPageDefinition;
0091:        import org.theospi.portfolio.matrix.model.WizardPageForm;
0092:        import org.theospi.portfolio.migration.model.impl.FormWrapper;
0093:        import org.theospi.portfolio.presentation.PresentationManager;
0094:        import org.theospi.portfolio.presentation.model.Presentation;
0095:        import org.theospi.portfolio.presentation.model.PresentationComment;
0096:        import org.theospi.portfolio.presentation.model.PresentationItem;
0097:        import org.theospi.portfolio.presentation.model.PresentationItemDefinition;
0098:        import org.theospi.portfolio.presentation.model.PresentationLog;
0099:        import org.theospi.portfolio.presentation.model.PresentationTemplate;
0100:        import org.theospi.portfolio.presentation.model.TemplateFileRef;
0101:        import org.theospi.portfolio.presentation.model.impl.HibernatePresentationProperties;
0102:        import org.theospi.portfolio.style.model.Style;
0103:        import org.theospi.portfolio.workflow.mgt.WorkflowManager;
0104:
0105:        /**
0106:         *
0107:         */
0108:        public class OspMigrationJob implements  Job {
0109:
0110:            protected final transient Log logger = LogFactory
0111:                    .getLog(getClass());
0112:
0113:            private DataSource dataSource;
0114:            private IdManager idManager;
0115:            private AgentManager agentManager;
0116:            private AuthorizationFacade authzManager;
0117:            private Glossary glossaryManager;
0118:            private GuidanceManager guidanceManager;
0119:            private StructuredArtifactDefinitionManager structuredArtifactDefinitionManager;
0120:            private PresentationManager presentationManager;
0121:            private MatrixManager matrixManager;
0122:            private ReviewManager reviewManager;
0123:            private WorkflowManager workflowManager;
0124:            private SiteService siteService;
0125:            private SecurityService securityService;
0126:            private ContentHostingService contentHosting;
0127:            private DefaultScaffoldingBean defaultScaffoldingBean;
0128:            private Statement stmt;
0129:            private Map tableMap = new HashMap();
0130:            private List authzToolFunctions;
0131:            private List matrixForms;
0132:
0133:            private Map userUniquenessMap;
0134:
0135:            private static final String MIGRATED_FOLDER = "migratedMatrixForms";
0136:            private static final String MIGRATED_FOLDER_PATH = "/"
0137:                    + MIGRATED_FOLDER + "/";
0138:            private static final String EXPECTATION_FORM_ID_VALUE = "expectationForm";
0139:            private static final String INTELLECTUAL_GROWTH_FORM_ID_VALUE = "intellectualGrowthForm";
0140:            private static final String FEEDBACK_FORM_ID_VALUE = "feedbackForm";
0141:            private static final String EVALUATION_FORM_ID_VALUE = "evaluationForm";
0142:
0143:            public final static String FORM_TYPE = "form";
0144:
0145:            private Id feedbackFormId, evaluationFormId, intelGrowthFormId,
0146:                    expectationFormId;
0147:
0148:            public void execute(JobExecutionContext jobExecutionContext)
0149:                    throws JobExecutionException {
0150:                logger.info("Quartz job started: " + this .getClass().getName());
0151:                Connection connection = null;
0152:                try {
0153:
0154:                    feedbackFormId = idManager.getId(FEEDBACK_FORM_ID_VALUE);
0155:                    evaluationFormId = idManager
0156:                            .getId(EVALUATION_FORM_ID_VALUE);
0157:                    intelGrowthFormId = idManager
0158:                            .getId(INTELLECTUAL_GROWTH_FORM_ID_VALUE);
0159:                    expectationFormId = idManager
0160:                            .getId(EXPECTATION_FORM_ID_VALUE);
0161:
0162:                    String developerFlag = ServerConfigurationService
0163:                            .getString("osp.migration.developer");
0164:
0165:                    boolean isDeveloper = developerFlag
0166:                            .equalsIgnoreCase("true");
0167:
0168:                    connection = SqlService.borrowConnection(); // getDataSource().getConnection();
0169:
0170:                    if (isDeveloper)
0171:                        developerClearAllTables(connection);
0172:
0173:                    userUniquenessMap = new HashMap();
0174:
0175:                    initMatrixForms();
0176:                    //createFeedbackForm("admin", "testform", "foobar");
0177:
0178:                    runAuthzMigration(connection, isDeveloper);
0179:                    runGlossaryMigration(connection, isDeveloper);
0180:                    runMatrixMigration(connection, isDeveloper);
0181:                    runPresentationTemplateMigration(connection, isDeveloper);
0182:                    runPresentationMigration(connection, isDeveloper);
0183:
0184:                    userUniquenessMap = null;
0185:
0186:                } catch (SQLException e) {
0187:                    logger.error("Quartz job errored: "
0188:                            + this .getClass().getName(), e);
0189:                    throw new JobExecutionException(e);
0190:                } finally {
0191:                    if (connection != null) {
0192:                        try {
0193:                            SqlService.returnConnection(connection); //connection.close();
0194:                        } catch (Exception e) {
0195:                            // can't do anything with this.
0196:                        }
0197:                    }
0198:                }
0199:
0200:                logger.info("Quartz job fininshed: "
0201:                        + this .getClass().getName());
0202:            }
0203:
0204:            private Id saveForm(String owner, String name, byte[] fileContent,
0205:                    String formType) {
0206:                getSecurityService().pushAdvisor(new AllowAllSecurityAdvisor());
0207:
0208:                org.sakaiproject.tool.api.Session sakaiSession = SessionManager
0209:                        .getCurrentSession();
0210:                String userId = sakaiSession.getUserId();
0211:                sakaiSession.setUserId(owner);
0212:                sakaiSession.setUserEid(owner);
0213:
0214:                String description = "";
0215:                String folder = "/user/" + owner;
0216:                String type = "application/x-osp";
0217:
0218:                try {
0219:                    ContentCollectionEdit groupCollection = getContentHosting()
0220:                            .addCollection(folder);
0221:                    groupCollection.getPropertiesEdit().addProperty(
0222:                            ResourceProperties.PROP_DISPLAY_NAME, owner);
0223:                    getContentHosting().commitCollection(groupCollection);
0224:                } catch (IdUsedException e) {
0225:                    // ignore... it is already there.
0226:                } catch (Exception e) {
0227:                    throw new RuntimeException(e);
0228:                }
0229:
0230:                folder = "/user/" + owner + MIGRATED_FOLDER_PATH;
0231:
0232:                try {
0233:                    ContentCollectionEdit groupCollection = getContentHosting()
0234:                            .addCollection(folder);
0235:                    groupCollection.getPropertiesEdit().addProperty(
0236:                            ResourceProperties.PROP_DISPLAY_NAME,
0237:                            MIGRATED_FOLDER);
0238:                    groupCollection.getPropertiesEdit().addProperty(
0239:                            ResourceProperties.PROP_DESCRIPTION,
0240:                            "Folder for Migrated Matrix Forms");
0241:                    getContentHosting().commitCollection(groupCollection);
0242:                } catch (IdUsedException e) {
0243:                    // ignore... it is already there.
0244:                } catch (Exception e) {
0245:                    throw new RuntimeException(e);
0246:                }
0247:
0248:                try {
0249:                    ResourcePropertiesEdit resourceProperties = getContentHosting()
0250:                            .newResourceProperties();
0251:                    resourceProperties.addProperty(
0252:                            ResourceProperties.PROP_DISPLAY_NAME, name);
0253:                    resourceProperties.addProperty(
0254:                            ResourceProperties.PROP_DESCRIPTION, description);
0255:                    resourceProperties.addProperty(
0256:                            ResourceProperties.PROP_CONTENT_ENCODING, "UTF-8");
0257:                    resourceProperties.addProperty(
0258:                            ResourceProperties.PROP_STRUCTOBJ_TYPE, formType);
0259:                    resourceProperties.addProperty(
0260:                            ContentHostingService.PROP_ALTERNATE_REFERENCE,
0261:                            MetaobjEntityManager.METAOBJ_ENTITY_PREFIX);
0262:
0263:                    ContentResource resource = getContentHosting().addResource(
0264:                            name, folder, 0, type, fileContent,
0265:                            resourceProperties, NotificationService.NOTI_NONE);
0266:                    return idManager.getId(getContentHosting().getUuid(
0267:                            resource.getId()));
0268:                } catch (Exception e) {
0269:                    throw new RuntimeException(e);
0270:                } finally {
0271:                    getSecurityService().popAdvisor();
0272:                    sakaiSession.setUserEid(userId);
0273:                    sakaiSession.setUserId(userId);
0274:                }
0275:            }
0276:
0277:            private Id createFeedbackForm(String owner, String title,
0278:                    String comment) {
0279:                String formId = FEEDBACK_FORM_ID_VALUE;
0280:                ElementBean feedbackForm = setupForm(formId);
0281:                feedbackForm.put("comment", comment.replace('\u0000', ' '));
0282:                byte[] xml = feedbackForm.toXmlString().getBytes();
0283:                return saveForm(owner, title, xml, formId);
0284:            }
0285:
0286:            private Id createEvaluationForm(String owner, String title,
0287:                    String grade, String comment) {
0288:                String formId = EVALUATION_FORM_ID_VALUE;
0289:                ElementBean evalForm = setupForm(formId);
0290:                evalForm.put("grade", grade);
0291:                if (comment == null)
0292:                    comment = "";
0293:                evalForm.put("comment", comment.replace('\u0000', ' '));
0294:                byte[] xml = evalForm.toXmlString().getBytes();
0295:                return saveForm(owner, title, xml, formId);
0296:            }
0297:
0298:            private Id createReflectionForm(String owner, String title,
0299:                    String evidence) {
0300:                String formId = INTELLECTUAL_GROWTH_FORM_ID_VALUE;
0301:                ElementBean feedbackForm = setupForm(formId);
0302:                if (evidence == null)
0303:                    evidence = "";
0304:                feedbackForm.put("evidence", evidence.replace('\u0000', ' '));
0305:                byte[] xml = feedbackForm.toXmlString().getBytes();
0306:                return saveForm(owner, title, xml, formId);
0307:            }
0308:
0309:            private Id createExpectationForm(String owner, String title,
0310:                    String evidence, String connect) {
0311:                String formId = EXPECTATION_FORM_ID_VALUE;
0312:                ElementBean feedbackForm = setupForm(formId);
0313:                if (evidence == null)
0314:                    evidence = "";
0315:                if (connect == null)
0316:                    connect = "";
0317:                feedbackForm.put("evidence", evidence.replace('\u0000', ' '));
0318:                feedbackForm.put("connect", connect.replace('\u0000', ' '));
0319:                byte[] xml = feedbackForm.toXmlString().getBytes();
0320:                return saveForm(owner, title, xml, formId);
0321:            }
0322:
0323:            private ElementBean setupForm(String formId) {
0324:                StructuredArtifactDefinitionBean bean = structuredArtifactDefinitionManager
0325:                        .loadHome(idManager.getId(formId));
0326:                SchemaFactory schemaFactory = SchemaFactory.getInstance();
0327:                SchemaNode schema = schemaFactory.getSchema(
0328:                        new ByteArrayInputStream(bean.getSchema())).getChild(
0329:                        bean.getDocumentRoot());
0330:                ElementBean form = new ElementBean(bean.getDocumentRoot(),
0331:                        schema);
0332:                return form;
0333:            }
0334:
0335:            private void developerClearAllTables(Connection con)
0336:                    throws JobExecutionException {
0337:                logger.info("Quartz task started: developerClearAllTables()");
0338:                String sql = "";
0339:                try {
0340:                    stmt = con.createStatement();
0341:                    Statement innerstmt = con.createStatement();
0342:
0343:                    sql = "SET FOREIGN_KEY_CHECKS=0";
0344:                    stmt.executeUpdate(sql);
0345:
0346:                    sql = "DELETE FROM content_resource WHERE RESOURCE_ID LIKE '%"
0347:                            + MIGRATED_FOLDER + "%'";
0348:                    stmt.executeUpdate(sql);
0349:
0350:                    sql = "TRUNCATE content_resource_lock";
0351:                    stmt.executeUpdate(sql);
0352:
0353:                    sql = "show tables like 'osp_%'";
0354:                    ResultSet rs = stmt.executeQuery(sql);
0355:                    try {
0356:                        while (rs.next()) {
0357:                            String tableName = rs.getString(1);
0358:                            sql = "TRUNCATE " + tableName;
0359:                            if (!tableName.endsWith("_BKP"))
0360:                                innerstmt.executeUpdate(sql);
0361:                        }
0362:                    } finally {
0363:                        try {
0364:                            innerstmt.close();
0365:                            rs.close();
0366:                        } catch (Exception e) {
0367:                        }
0368:                    }
0369:
0370:                } catch (Exception e) {
0371:                    logger.error("error truncating data with this sql: " + sql);
0372:                    logger.error("", e);
0373:                    throw new JobExecutionException(e);
0374:                } finally {
0375:                    logger
0376:                            .info("Quartz task finished: developerClearAllTables()");
0377:                    try {
0378:                        sql = "SET FOREIGN_KEY_CHECKS=1";
0379:                        stmt.executeUpdate(sql);
0380:                        stmt.close();
0381:                    } catch (Exception e) {
0382:                    }
0383:                }
0384:            }
0385:
0386:            protected void initMatrixForms() {
0387:                logger.info("Quartz task started: initMatrixForms()");
0388:                getSecurityService().pushAdvisor(new AllowAllSecurityAdvisor());
0389:
0390:                org.sakaiproject.tool.api.Session sakaiSession = SessionManager
0391:                        .getCurrentSession();
0392:                String userId = sakaiSession.getUserId();
0393:                sakaiSession.setUserId("admin");
0394:                sakaiSession.setUserEid("admin");
0395:                List forms = new ArrayList();
0396:
0397:                try {
0398:                    for (Iterator i = getMatrixForms().iterator(); i.hasNext();) {
0399:                        forms.add(processDefinedForm((FormWrapper) i.next()));
0400:                    }
0401:
0402:                    for (Iterator i = forms.iterator(); i.hasNext();) {
0403:                        StructuredArtifactDefinitionBean form = (StructuredArtifactDefinitionBean) i
0404:                                .next();
0405:                        structuredArtifactDefinitionManager.save(form);
0406:                    }
0407:
0408:                } finally {
0409:                    getSecurityService().popAdvisor();
0410:                    sakaiSession.setUserEid(userId);
0411:                    sakaiSession.setUserId(userId);
0412:                }
0413:                logger.info("Quartz task finished: initMatrixForms()");
0414:            }
0415:
0416:            protected StructuredArtifactDefinitionBean processDefinedForm(
0417:                    FormWrapper wrapper) {
0418:                StructuredArtifactDefinitionBean form = structuredArtifactDefinitionManager
0419:                        .loadHome(getIdManager().getId(wrapper.getIdValue()));
0420:
0421:                if (form == null) {
0422:                    form = new StructuredArtifactDefinitionBean();
0423:                    form.setCreated(new Date());
0424:                    form.setNewId(getIdManager().getId(wrapper.getIdValue()));
0425:                }
0426:
0427:                updateForm(wrapper, form);
0428:
0429:                return form;
0430:            }
0431:
0432:            protected void updateForm(FormWrapper wrapper,
0433:                    StructuredArtifactDefinitionBean form) {
0434:                if (form.getId() == null) {
0435:
0436:                }
0437:
0438:                form.setSchema(loadResource(wrapper.getXsdFileLocation())
0439:                        .toByteArray());
0440:                form.setModified(new Date());
0441:                form.setDescription(wrapper.getDescription());
0442:                form
0443:                        .setGlobalState(StructuredArtifactDefinitionBean.STATE_PUBLISHED);
0444:                form
0445:                        .setSiteState(StructuredArtifactDefinitionBean.STATE_UNPUBLISHED);
0446:                form.setDocumentRoot(wrapper.getDocumentRoot());
0447:                form.setInstruction(wrapper.getInstruction());
0448:                form.setExternalType(wrapper.getExternalType());
0449:
0450:                form.setSiteId(null);
0451:                form.setOwner(getAgentManager().getAgent("admin"));
0452:            }
0453:
0454:            protected ByteArrayOutputStream loadResource(String name) {
0455:                ByteArrayOutputStream bos = new ByteArrayOutputStream();
0456:                InputStream is = getClass().getResourceAsStream(name);
0457:
0458:                try {
0459:                    int c = is.read();
0460:                    while (c != -1) {
0461:                        bos.write(c);
0462:                        c = is.read();
0463:                    }
0464:                    bos.flush();
0465:                } catch (IOException e) {
0466:                    throw new RuntimeException(e);
0467:                } finally {
0468:                    try {
0469:                        is.close();
0470:                    } catch (IOException e) {
0471:                        // can't do anything now..
0472:                    }
0473:                }
0474:                return bos;
0475:            }
0476:
0477:            protected void runAuthzMigration(Connection con, boolean isDeveloper)
0478:                    throws JobExecutionException {
0479:                logger.info("Quartz task started: runAuthzMigration()");
0480:                String tableName = getOldTableName("osp_authz_simple");
0481:                String sql = "select * from " + tableName;
0482:
0483:                try {
0484:                    stmt = con.createStatement();
0485:                    ResultSet rs = stmt.executeQuery(sql);
0486:                    try {
0487:                        while (rs.next()) {
0488:                            //String id = rs.getString("id");
0489:                            String qual = rs.getString("qualifier_id");
0490:                            String agentStr = rs.getString("agent_id");
0491:                            String func = rs.getString("function_name");
0492:                            // Transformations on the authz stuff that needs to 
0493:                            // change from a tool_id to a site_id
0494:                            try {
0495:                                if (getAuthzToolFunctions().contains(func)) {
0496:                                    ToolConfiguration toolConfig = siteService
0497:                                            .findTool(qual);
0498:                                    if (toolConfig != null) {
0499:                                        qual = toolConfig.getContext();
0500:                                    }
0501:                                }
0502:                                if (func
0503:                                        .equalsIgnoreCase(MatrixFunctionConstants.REVIEW_MATRIX)) {
0504:                                    func = MatrixFunctionConstants.EVALUATE_MATRIX;
0505:                                }
0506:
0507:                                Agent agent = agentManager.getAgent(agentStr);
0508:
0509:                                // there needs to be an agent or else the authorization is invalid
0510:                                if (agent == null)
0511:                                    logger
0512:                                            .error("OSP Migration error: agent was null: "
0513:                                                    + agentStr);
0514:                                else if (agent.getId() == null)
0515:                                    logger
0516:                                            .error("OSP Migration error: agent id was null: "
0517:                                                    + agentStr);
0518:                                else if (agent.getId().getValue() == null)
0519:                                    logger
0520:                                            .error("OSP Migration error: agent id value was null: "
0521:                                                    + agentStr);
0522:                                else if (qual == null)
0523:                                    logger
0524:                                            .error("OSP Migration error: qualifier was null: "
0525:                                                    + qual);
0526:                                else
0527:                                    authzManager.createAuthorization(agent,
0528:                                            func, idManager.getId(qual));
0529:                            } catch (Exception e) {
0530:                                if (!isDeveloper)
0531:                                    throw e;
0532:                            }
0533:                        }
0534:                    } finally {
0535:                        rs.close();
0536:                    }
0537:
0538:                    //This will create new authorizations for the review and view functions
0539:                    sql = "select distinct ss.site_id, role_name, '"
0540:                            + MatrixFunctionConstants.USE_SCAFFOLDING
0541:                            + "' as func "
0542:                            + "From sakai_site_tool st JOIN sakai_site ss ON st.site_id = ss.site_id "
0543:                            + "JOIN SAKAI_REALM r ON r.realm_id = CONCAT('/site/', ss.site_id) "
0544:                            + "JOIN sakai_realm_rl_fn rf ON r.REALM_KEY = rf.REALM_KEY "
0545:                            + " JOIN sakai_realm_role rr ON rf.ROLE_KEY = rr.ROLE_KEY "
0546:                            + "where st.registration = 'osp.matrix' "
0547:                            + "and role_name in ('access', 'member', 'student') "
0548:                            + "union "
0549:                            + "select distinct ss.site_id, role_name, '"
0550:                            + MatrixFunctionConstants.REVIEW_MATRIX
0551:                            + "' as func "
0552:                            + "From sakai_site_tool st JOIN sakai_site ss ON st.site_id = ss.site_id "
0553:                            + "JOIN SAKAI_REALM r ON r.realm_id = CONCAT('/site/', ss.site_id) "
0554:                            + "JOIN sakai_realm_rl_fn rf ON r.REALM_KEY = rf.REALM_KEY "
0555:                            + " JOIN sakai_realm_role rr ON rf.ROLE_KEY = rr.ROLE_KEY "
0556:                            + "where st.registration = 'osp.matrix' "
0557:                            + "and role_name in ('maintain', 'project owner', 'instructor')";
0558:
0559:                    stmt = con.createStatement();
0560:                    rs = stmt.executeQuery(sql);
0561:                    try {
0562:                        while (rs.next()) {
0563:                            //String id = rs.getString("id");
0564:                            String siteId = rs.getString("site_id");
0565:                            String role = rs.getString("role_name");
0566:                            String func = rs.getString("func");
0567:
0568:                            String agent = "/site/" + siteId + "/" + role;
0569:                            try {
0570:                                // the agent has already been verified as they are coming from the db
0571:                                authzManager.createAuthorization(agentManager
0572:                                        .getAgent(agent), func, idManager
0573:                                        .getId(siteId));
0574:                            } catch (Exception e) {
0575:                                if (!isDeveloper)
0576:                                    throw e;
0577:                            }
0578:                        }
0579:                    } finally {
0580:                        rs.close();
0581:                    }
0582:
0583:                } catch (Exception e) {
0584:                    logger.error("error selecting data with this sql: " + sql);
0585:                    logger.error("", e);
0586:                    throw new JobExecutionException(e);
0587:                } finally {
0588:                    try {
0589:                        stmt.close();
0590:                    } catch (Exception e) {
0591:                    }
0592:                }
0593:                logger.info("Quartz task fininshed: runAuthzMigration()");
0594:            }
0595:
0596:            protected void runGlossaryMigration(Connection con,
0597:                    boolean isDeveloper) throws JobExecutionException {
0598:                logger.info("Quartz task started: runGlossaryMigration()");
0599:                String tableName = getOldTableName("osp_help_glossary");
0600:                String tableName2 = getOldTableName("osp_help_glossary_desc");
0601:                String sql = "select g.id, g.term, g.description, g.worksite_id, "
0602:                        + "gd.long_description from "
0603:                        + tableName
0604:                        + " g, "
0605:                        + tableName2 + " gd where g.id = gd.entry_id";
0606:
0607:                try {
0608:                    stmt = con.createStatement();
0609:                    ResultSet rs = stmt.executeQuery(sql);
0610:                    try {
0611:                        while (rs.next()) {
0612:                            String id = rs.getString("id");
0613:                            String term = rs.getString("term");
0614:                            String desc = rs.getString("description");
0615:                            String longDesc = rs.getString("long_description");
0616:                            String site_id = rs.getString("worksite_id");
0617:
0618:                            Id theId = idManager.getId(id);
0619:
0620:                            GlossaryEntry entry = new GlossaryEntry(term, desc);
0621:                            entry.setId(theId);
0622:                            entry.setWorksiteId(site_id);
0623:                            entry.getLongDescriptionObject().setEntryId(theId);
0624:                            entry.getLongDescriptionObject()
0625:                                    .setLongDescription(longDesc);
0626:                            glossaryManager.addEntry(entry);
0627:
0628:                        }
0629:                    } finally {
0630:                        rs.close();
0631:                    }
0632:                } catch (Exception e) {
0633:                    logger.error("error selecting data with this sql: " + sql);
0634:                    logger.error("", e);
0635:                    throw new JobExecutionException(e);
0636:                } finally {
0637:                    try {
0638:                        stmt.close();
0639:                    } catch (Exception e) {
0640:                    }
0641:                }
0642:                logger.info("Quartz task fininshed: runGlossaryMigration()");
0643:            }
0644:
0645:            protected void runMatrixMigration(Connection con,
0646:                    boolean isDeveloper) throws JobExecutionException {
0647:                logger.info("Quartz task started: runMatrixMigration()");
0648:
0649:                String tableName = getOldTableName("osp_scaffolding"), tableName2 = null, tableName3 = null;
0650:                String sql = "select * from " + tableName;
0651:
0652:                Statement matrixInnerStmt = null, innerStmt = null;
0653:                try {
0654:                    List additionalForms = new ArrayList();
0655:                    additionalForms.add(expectationFormId.getValue());
0656:
0657:                    matrixInnerStmt = con.createStatement();
0658:                    innerStmt = con.createStatement();
0659:                    stmt = con.createStatement();
0660:
0661:                    ResultSet rs = stmt.executeQuery(sql);
0662:
0663:                    try {
0664:                        while (rs.next()) {
0665:                            String id = rs.getString("id");
0666:                            String owner = rs.getString("ownerid");
0667:                            String title = rs.getString("title");
0668:                            String description = rs.getString("description");
0669:                            String documentRoot = rs.getString("documentroot");
0670:                            String privacyxsdid = rs.getString("privacyxsdid");
0671:                            String worksite = rs.getString("worksiteId");
0672:                            boolean published = rs.getBoolean("published");
0673:                            String publishedBy = rs.getString("publishedBy");
0674:                            Date publishedDate = rs.getDate("publishedDate");
0675:
0676:                            String columnLabel = defaultScaffoldingBean
0677:                                    .getColumnLabel(); //rs.getString("columnLabel");
0678:                            String rowLabel = defaultScaffoldingBean
0679:                                    .getRowLabel(); //rs.getString("rowLabel");
0680:                            String readyColor = "";//defaultScaffoldingBean.getReadyColor(); //rs.getString("readyColor");
0681:                            String pendingColor = "";//defaultScaffoldingBean.getPendingColor(); //rs.getString("pendingColor");
0682:                            String completedColor = "";//defaultScaffoldingBean.getCompletedColor(); //rs.getString("completedColor");
0683:                            String lockColor = "";//defaultScaffoldingBean.getLockedColor(); //rs.getString("lockColor");
0684:                            int workflowOption = Scaffolding.HORIZONTAL_PROGRESSION; //rs.getInt("workflowOption");
0685:                            String exposed_page_id = ""; //rs.getString("exposed_page_id");
0686:                            String style_id = ""; //rs.getString("style_id");
0687:
0688:                            Scaffolding scaffolding = new Scaffolding();
0689:                            Id sid = idManager.getId(id);
0690:                            scaffolding.setId(null);
0691:                            scaffolding.setNewId(sid);
0692:                            Agent scaffAgent = agentManager.getAgent(owner);
0693:
0694:                            if (scaffAgent == null) {
0695:                                logger
0696:                                        .error("OSP Migration Error: The scaffolding owner agent couldn't be found: "
0697:                                                + owner);
0698:                                continue;
0699:                            } else if (scaffAgent.getId() == null) {
0700:                                logger
0701:                                        .error("OSP Migration Error: The scaffolding owner agent id couldn't be found: "
0702:                                                + owner);
0703:                                continue;
0704:                            } else if (scaffAgent.getId().getValue() == null) {
0705:                                logger
0706:                                        .error("OSP Migration Error: The scaffolding owner agent id value couldn't be found: "
0707:                                                + owner);
0708:                                continue;
0709:                            }
0710:
0711:                            scaffolding.setOwner(scaffAgent);
0712:                            scaffolding.setTitle(title);
0713:                            scaffolding.setDescription(description);
0714:                            scaffolding
0715:                                    .setWorksiteId(idManager.getId(worksite));
0716:                            scaffolding.setPublished(published);
0717:                            if (publishedBy != null)
0718:                                scaffolding.setPublishedBy(agentManager
0719:                                        .getAgent(publishedBy));
0720:                            scaffolding.setColumnLabel(columnLabel);
0721:                            scaffolding.setPublishedDate(publishedDate);
0722:                            scaffolding.setRowLabel(rowLabel);
0723:
0724:                            scaffolding.setReadyColor(readyColor);
0725:                            scaffolding.setPendingColor(pendingColor);
0726:                            scaffolding.setCompletedColor(completedColor);
0727:                            scaffolding.setLockedColor(lockColor);
0728:                            scaffolding.setWorkflowOption(workflowOption);
0729:                            scaffolding.setExposedPageId(exposed_page_id);
0730:
0731:                            Style style = null; //new Style();
0732:
0733:                            //style.setId(idManager.getId(style_id));
0734:                            scaffolding.setStyle(style);
0735:
0736:                            //*****************  run through the criteria
0737:                            tableName = getOldTableName("osp_scaffolding_criteria");
0738:                            tableName2 = getOldTableName("osp_matrix_label");
0739:                            sql = "select * from " + tableName + " join "
0740:                                    + tableName2 + " on ELT=ID"
0741:                                    + " where parent_id='" + id
0742:                                    + "' order by seq_num";
0743:
0744:                            ResultSet rss = innerStmt.executeQuery(sql);
0745:
0746:                            Map criteriaMap = new HashMap();
0747:
0748:                            try {
0749:                                while (rss.next()) {
0750:                                    int sequenceNumber = rss.getInt("seq_num");
0751:                                    Id lid = idManager.getId(rss
0752:                                            .getString("elt"));
0753:                                    String color = rss.getString("color");
0754:                                    String textColor = null;
0755:                                    String ldescription = rss
0756:                                            .getString("description");
0757:
0758:                                    Criterion criterion = new Criterion();
0759:
0760:                                    criterion.setId(null);
0761:                                    criterion.setNewId(lid);
0762:                                    criterion.setColor(color);
0763:                                    criterion.setTextColor(textColor);
0764:                                    criterion.setScaffolding(scaffolding);
0765:                                    criterion.setDescription(ldescription);
0766:                                    criterion.setSequenceNumber(sequenceNumber);
0767:
0768:                                    scaffolding.add(criterion);
0769:
0770:                                    criteriaMap.put(lid.getValue(), criterion);
0771:                                }
0772:                            } finally {
0773:                                rss.close();
0774:                            }
0775:
0776:                            //*****************  run through the levels
0777:                            tableName = getOldTableName("osp_scaffolding_levels");
0778:                            tableName2 = getOldTableName("osp_matrix_label");
0779:                            sql = "select * from " + tableName + " join "
0780:                                    + tableName2 + " on ELT=ID"
0781:                                    + " where scaffolding_id='" + id
0782:                                    + "' order by seq_num";
0783:
0784:                            rss = innerStmt.executeQuery(sql);
0785:
0786:                            Map levelMap = new HashMap();
0787:
0788:                            try {
0789:                                while (rss.next()) {
0790:                                    int sequenceNumber = rss.getInt("seq_num");
0791:                                    Id lid = idManager.getId(rss
0792:                                            .getString("elt"));
0793:                                    String color = rss.getString("color");
0794:                                    String textColor = null;
0795:                                    String ldescription = rss
0796:                                            .getString("description");
0797:
0798:                                    Level level = new Level();
0799:
0800:                                    level.setId(null);
0801:                                    level.setNewId(lid);
0802:                                    level.setColor(color);
0803:                                    level.setTextColor(textColor);
0804:                                    level.setScaffolding(scaffolding);
0805:                                    level.setDescription(ldescription);
0806:                                    level.setSequenceNumber(sequenceNumber);
0807:
0808:                                    scaffolding.add(level);
0809:
0810:                                    levelMap.put(lid.getValue(), level);
0811:                                }
0812:                            } finally {
0813:                                rss.close();
0814:                            }
0815:
0816:                            //*****************  run through the scells
0817:                            tableName = getOldTableName("osp_scaffolding_cell");
0818:                            sql = "select * from " + tableName
0819:                                    + " where scaffolding_id='" + id + "' ";
0820:
0821:                            rss = innerStmt.executeQuery(sql);
0822:
0823:                            Map scaffoldingCellMap = new HashMap();
0824:                            Map scaffoldingCellExpheadMap = new HashMap();
0825:
0826:                            try {
0827:                                while (rss.next()) {
0828:                                    Id cid = idManager.getId(rss
0829:                                            .getString("id"));
0830:                                    String criterionStr = rss
0831:                                            .getString("rootcriterion_id");
0832:                                    String levelStr = rss.getString("level_id");
0833:                                    String expectationheader = rss
0834:                                            .getString("expectationheader");
0835:                                    String initialStatus = rss
0836:                                            .getString("initialstatus");
0837:                                    String gradablereflection = rss
0838:                                            .getString("gradablereflection");
0839:
0840:                                    Level level = (Level) levelMap
0841:                                            .get(levelStr);
0842:                                    Criterion criterion = (Criterion) criteriaMap
0843:                                            .get(criterionStr);
0844:                                    ScaffoldingCell cell = new ScaffoldingCell();
0845:
0846:                                    cell.setId(null);
0847:                                    cell.setNewId(cid);
0848:                                    cell.setInitialStatus(initialStatus);
0849:                                    cell.setLevel(level);
0850:                                    cell.setRootCriterion(criterion);
0851:                                    cell.setScaffolding(scaffolding);
0852:                                    WizardPageDefinition page = cell
0853:                                            .getWizardPageDefinition();
0854:
0855:                                    page.setNewId(idManager.createId());
0856:                                    page.setSiteId(worksite);
0857:                                    page
0858:                                            .setTitle((criterion
0859:                                                    .getDescription() != null ? criterion
0860:                                                    .getDescription()
0861:                                                    : "")
0862:                                                    + " - "
0863:                                                    + (level.getDescription() != null ? level
0864:                                                            .getDescription()
0865:                                                            : ""));
0866:
0867:                                    cell.setEvaluationDevice(evaluationFormId);
0868:                                    cell.setEvaluationDeviceType(FORM_TYPE);
0869:                                    cell.setReflectionDevice(intelGrowthFormId);
0870:                                    cell.setReflectionDeviceType(FORM_TYPE);
0871:                                    cell.setReviewDevice(feedbackFormId);
0872:                                    cell.setReviewDeviceType(FORM_TYPE);
0873:                                    cell.setAdditionalForms(additionalForms);
0874:
0875:                                    // this needs to be after setting the forms
0876:                                    page
0877:                                            .setEvalWorkflows(new HashSet(
0878:                                                    getWorkflowManager()
0879:                                                            .createEvalWorkflows(
0880:                                                                    page)));
0881:
0882:                                    scaffolding.add(cell);
0883:                                    scaffoldingCellMap
0884:                                            .put(cid.getValue(), cell);
0885:                                    scaffoldingCellExpheadMap.put(cid
0886:                                            .getValue(), expectationheader);
0887:
0888:                                    List scellAuthzs = authzManager
0889:                                            .getAuthorizations(
0890:                                                    null,
0891:                                                    MatrixFunctionConstants.EVALUATE_MATRIX,
0892:                                                    cid);
0893:
0894:                                    for (Iterator i = scellAuthzs.iterator(); i
0895:                                            .hasNext();) {
0896:                                        Authorization a = (Authorization) i
0897:                                                .next();
0898:
0899:                                        authzManager.createAuthorization(a
0900:                                                .getAgent(), a.getFunction(),
0901:                                                page.getNewId());
0902:                                        authzManager.deleteAuthorization(a
0903:                                                .getAgent(), a.getFunction(), a
0904:                                                .getQualifier());
0905:                                    }
0906:                                }
0907:                            } finally {
0908:                                rss.close();
0909:                            }
0910:
0911:                            // save the scaffolding!
0912:                            Id scaffId = (Id) matrixManager.save(scaffolding);
0913:                            scaffolding = matrixManager.getScaffolding(scaffId);
0914:
0915:                            // migrate the expectations into the guidance.instruction of the cell
0916:
0917:                            tableName = getOldTableName("osp_scaffolding_cell");
0918:                            tableName2 = getOldTableName("osp_expectation");
0919:                            tableName3 = getOldTableName("osp_matrix_label");
0920:                            sql = "select SCAFFOLDING_CELL_ID, " + tableName3
0921:                                    + ".ID, DESCRIPTION " + " FROM "
0922:                                    + tableName + " JOIN " + tableName2
0923:                                    + " ON " + tableName
0924:                                    + ".ID=SCAFFOLDING_CELL_ID " + " JOIN "
0925:                                    + tableName3 + " ON ELT=" + tableName3
0926:                                    + ".ID " + " where scaffolding_id='" + id
0927:                                    + "' ORDER BY SCAFFOLDING_CELL_ID, SEQ_NUM";
0928:
0929:                            rss = innerStmt.executeQuery(sql);
0930:
0931:                            String lastScaffoldingCellId = "", guidanceText = null, scaffoldingCellId = null;
0932:
0933:                            try {
0934:                                while (rss.next()) {
0935:                                    scaffoldingCellId = rss
0936:                                            .getString("SCAFFOLDING_CELL_ID");
0937:
0938:                                    if (!scaffoldingCellId
0939:                                            .equals(lastScaffoldingCellId)) {
0940:                                        if (guidanceText != null) {
0941:                                            ScaffoldingCell scell = (ScaffoldingCell) scaffoldingCellMap
0942:                                                    .get(lastScaffoldingCellId);
0943:                                            Guidance guide = guidanceManager
0944:                                                    .createNew(
0945:                                                            "",
0946:                                                            worksite,
0947:                                                            scell
0948:                                                                    .getWizardPageDefinition()
0949:                                                                    .getId(),
0950:                                                            MatrixFunctionConstants.VIEW_SCAFFOLDING_GUIDANCE,
0951:                                                            MatrixFunctionConstants.EDIT_SCAFFOLDING_GUIDANCE);
0952:                                            guidanceText += "</ul>";
0953:                                            guide.getInstruction().setText(
0954:                                                    guidanceText);
0955:                                            scell.setGuidance(guide);
0956:                                            matrixManager
0957:                                                    .storeScaffoldingCell(scell);
0958:                                        }
0959:                                        lastScaffoldingCellId = scaffoldingCellId;
0960:                                        //starts a new cell
0961:                                        String expHeader = (String) scaffoldingCellExpheadMap
0962:                                                .get(scaffoldingCellId);
0963:                                        guidanceText = expHeader + "\n<ul>";
0964:                                    }
0965:                                    if (guidanceText.length() > 0)
0966:                                        guidanceText += "\n<br />";
0967:                                    guidanceText += "<li>"
0968:                                            + rss.getString("DESCRIPTION")
0969:                                            + "</li>";
0970:                                }
0971:
0972:                                if (guidanceText != null) {
0973:                                    ScaffoldingCell scell = (ScaffoldingCell) scaffoldingCellMap
0974:                                            .get(scaffoldingCellId);
0975:                                    Guidance guide = guidanceManager
0976:                                            .createNew(
0977:                                                    "",
0978:                                                    worksite,
0979:                                                    scell
0980:                                                            .getWizardPageDefinition()
0981:                                                            .getId(),
0982:                                                    MatrixFunctionConstants.VIEW_SCAFFOLDING_GUIDANCE,
0983:                                                    MatrixFunctionConstants.EDIT_SCAFFOLDING_GUIDANCE);
0984:                                    guidanceText += "</ul>";
0985:                                    guide.getInstruction()
0986:                                            .setText(guidanceText);
0987:                                    scell.setGuidance(guide);
0988:                                    matrixManager.storeScaffoldingCell(scell);
0989:                                }
0990:                            } finally {
0991:                                rss.close();
0992:                            }
0993:
0994:                            //*****************  run through the user matrices
0995:                            tableName = getOldTableName("osp_matrix_tool");
0996:                            tableName2 = getOldTableName("osp_matrix");
0997:                            tableName3 = getOldTableName("osp_matrix_cell");
0998:                            sql = "select "
0999:                                    + tableName3
1000:                                    + ".id, matrix_id, owner, status, reflection_id, scaffolding_cell_id "
1001:                                    + " from " + tableName + " join "
1002:                                    + tableName2 + " on matrixtool_id="
1003:                                    + tableName + ".id " + " join "
1004:                                    + tableName3 + " on matrix_id="
1005:                                    + tableName2 + ".id "
1006:                                    + " where scaffolding_id='" + id
1007:                                    + "' order by owner";
1008:
1009:                            rss = innerStmt.executeQuery(sql);
1010:
1011:                            tableName = getOldTableName("osp_reflection");
1012:                            tableName2 = getOldTableName("osp_reflection_item");
1013:                            tableName3 = getOldTableName("osp_reviewer_item");
1014:
1015:                            String lastOwner = "";
1016:                            Matrix matrix = null;
1017:                            boolean badCell = false, badMatrix = false;
1018:                            int intelGrowthIndex = 1;
1019:
1020:                            try {
1021:                                while (rss.next()) {
1022:
1023:                                    String mcidStr = rss.getString("id");
1024:                                    Id mcid = idManager.getId(mcidStr);
1025:                                    String mowner = rss.getString("owner");
1026:                                    String status = rss.getString("status");
1027:                                    String scaffolding_cell_id = rss
1028:                                            .getString("scaffolding_cell_id");
1029:
1030:                                    if (!mowner.equals(lastOwner)) {
1031:                                        if (matrix != null && !badCell) {
1032:                                            if (matrix.getOwner() == null)
1033:                                                logger
1034:                                                        .error("OSP Migration Error: The matrix owner agent couldn't be found: "
1035:                                                                + lastOwner);
1036:                                            else if (matrix.getOwner().getId() == null)
1037:                                                logger
1038:                                                        .error("OSP Migration Error: The matrix owner agent id couldn't be found: "
1039:                                                                + lastOwner);
1040:                                            else if (matrix.getOwner().getId()
1041:                                                    .getValue() == null)
1042:                                                logger
1043:                                                        .error("OSP Migration Error: The matrix owner agent id value couldn't be found: "
1044:                                                                + lastOwner);
1045:                                            else
1046:                                                matrixManager.save(matrix);
1047:                                        }
1048:
1049:                                        lastOwner = mowner;
1050:
1051:                                        matrix = new Matrix();
1052:
1053:                                        matrix.setOwner(agentManager
1054:                                                .getAgent(mowner));
1055:                                        matrix.setScaffolding(scaffolding);
1056:
1057:                                        badMatrix = matrix.getOwner() == null
1058:                                                || matrix.getOwner().getId() == null
1059:                                                || matrix.getOwner().getId()
1060:                                                        .getValue() == null;
1061:                                        badCell = false;
1062:                                    }
1063:                                    badCell = scaffolding_cell_id == null
1064:                                            || badMatrix;
1065:
1066:                                    if (!badCell) {
1067:                                        ScaffoldingCell sCell = (ScaffoldingCell) scaffoldingCellMap
1068:                                                .get(scaffolding_cell_id);
1069:
1070:                                        boolean isReady = status
1071:                                                .equals(MatrixFunctionConstants.READY_STATUS);
1072:                                        Cell cell = new Cell();
1073:                                        cell.setNewId(mcid);
1074:                                        cell.getWizardPage().setNewId(
1075:                                                idManager.createId());
1076:                                        cell.getWizardPage().setOwner(
1077:                                                matrix.getOwner());
1078:                                        cell.setScaffoldingCell(sCell);
1079:                                        cell.setStatus(status);
1080:
1081:                                        Set attachments = new HashSet();
1082:                                        String cellAttachmentTable = getOldTableName("osp_cell_attachment");
1083:                                        sql = "select * from "
1084:                                                + cellAttachmentTable
1085:                                                + " where cell_id='" + mcidStr
1086:                                                + "'";
1087:                                        ResultSet rsCellFiles = matrixInnerStmt
1088:                                                .executeQuery(sql);
1089:                                        try {
1090:                                            while (rsCellFiles.next()) {
1091:                                                String attid = rsCellFiles
1092:                                                        .getString("id");
1093:                                                String artifact = rsCellFiles
1094:                                                        .getString("artifactId");
1095:                                                Attachment att = new Attachment();
1096:                                                att.setNewId(idManager
1097:                                                        .getId(attid));
1098:                                                att.setArtifactId(idManager
1099:                                                        .getId(artifact));
1100:                                                att.setWizardPage(cell
1101:                                                        .getWizardPage());
1102:                                                attachments.add(att);
1103:                                                if (!isReady)
1104:                                                    contentHosting
1105:                                                            .lockObject(
1106:                                                                    artifact,
1107:                                                                    cell
1108:                                                                            .getWizardPage()
1109:                                                                            .getNewId()
1110:                                                                            .getValue(),
1111:                                                                    "cell atts locked on submit",
1112:                                                                    true);
1113:                                            }
1114:                                            cell.setAttachments(attachments);
1115:                                        } finally {
1116:                                            rsCellFiles.close();
1117:                                        }
1118:
1119:                                        // get the intellectual growth
1120:                                        sql = "SELECT ID, GROWTHSTATEMENT FROM "
1121:                                                + tableName
1122:                                                + " WHERE CELL_ID='"
1123:                                                + mcidStr
1124:                                                + "'";
1125:                                        ResultSet intelGrowthRS = matrixInnerStmt
1126:                                                .executeQuery(sql);
1127:                                        try {
1128:                                            if (intelGrowthRS.next()) {
1129:                                                String reflection_id = intelGrowthRS
1130:                                                        .getString(1);
1131:                                                String growth = intelGrowthRS
1132:                                                        .getString(2);
1133:
1134:                                                // save the intellectual growth
1135:                                                Integer anId = incUser(matrix
1136:                                                        .getOwner().getId()
1137:                                                        .getValue());
1138:                                                Id reflectionForm = createReflectionForm(
1139:                                                        matrix.getOwner()
1140:                                                                .getId()
1141:                                                                .getValue(),
1142:                                                        "IntGrowth "
1143:                                                                + scaffolding
1144:                                                                        .getTitle()
1145:                                                                + " "
1146:                                                                + sCell
1147:                                                                        .getRootCriterion()
1148:                                                                        .getDescription()
1149:                                                                + " "
1150:                                                                + sCell
1151:                                                                        .getLevel()
1152:                                                                        .getDescription()
1153:                                                                + " - "
1154:                                                                + anId
1155:                                                                        .toString(),
1156:                                                        growth);
1157:                                                Review review = reviewManager
1158:                                                        .createNew("", worksite);
1159:                                                review
1160:                                                        .setDeviceId(intelGrowthFormId
1161:                                                                .getValue());// form idvalue
1162:                                                review.setParent(cell
1163:                                                        .getWizardPage()
1164:                                                        .getNewId().getValue());// wizard page
1165:                                                review
1166:                                                        .setType(Review.REFLECTION_TYPE);//contant
1167:                                                review
1168:                                                        .setReviewContent(reflectionForm);
1169:                                                getReviewManager().saveReview(
1170:                                                        review);
1171:
1172:                                                if (!isReady)
1173:                                                    contentHosting
1174:                                                            .lockObject(
1175:                                                                    reflectionForm
1176:                                                                            .getValue(),
1177:                                                                    review
1178:                                                                            .getId()
1179:                                                                            .getValue(),
1180:                                                                    "reflection submitted",
1181:                                                                    true);
1182:
1183:                                                sql = "SELECT CONNECTTEXT, EVIDENCE FROM "
1184:                                                        + tableName2
1185:                                                        + " WHERE REFLECTION_ID='"
1186:                                                        + reflection_id
1187:                                                        + "' ORDER BY SEQ_NUM";
1188:                                                ResultSet reflectionRS = matrixInnerStmt
1189:                                                        .executeQuery(sql);
1190:                                                Set pageForms = new HashSet();
1191:                                                try {
1192:                                                    while (reflectionRS.next()) {
1193:                                                        String connect_text = reflectionRS
1194:                                                                .getString("CONNECTTEXT");
1195:                                                        String evidence = reflectionRS
1196:                                                                .getString("EVIDENCE");
1197:
1198:                                                        // save the expectation
1199:                                                        anId = incUser(matrix
1200:                                                                .getOwner()
1201:                                                                .getId()
1202:                                                                .getValue());
1203:                                                        Id expectationForm = createExpectationForm(
1204:                                                                matrix
1205:                                                                        .getOwner()
1206:                                                                        .getId()
1207:                                                                        .getValue(),
1208:                                                                "Reflection "
1209:                                                                        + scaffolding
1210:                                                                                .getTitle()
1211:                                                                        + " "
1212:                                                                        + sCell
1213:                                                                                .getRootCriterion()
1214:                                                                                .getDescription()
1215:                                                                        + " "
1216:                                                                        + sCell
1217:                                                                                .getLevel()
1218:                                                                                .getDescription()
1219:                                                                        + " - "
1220:                                                                        + anId
1221:                                                                                .toString(),
1222:                                                                evidence,
1223:                                                                connect_text);
1224:
1225:                                                        WizardPageForm pageForm = new WizardPageForm();
1226:
1227:                                                        pageForm
1228:                                                                .setArtifactId(expectationForm);
1229:                                                        pageForm
1230:                                                                .setFormType(EXPECTATION_FORM_ID_VALUE);
1231:                                                        pageForm
1232:                                                                .setWizardPage(cell
1233:                                                                        .getWizardPage());
1234:
1235:                                                        if (!isReady)
1236:                                                            contentHosting
1237:                                                                    .lockObject(
1238:                                                                            expectationForm
1239:                                                                                    .getValue(),
1240:                                                                            cell
1241:                                                                                    .getWizardPage()
1242:                                                                                    .getNewId()
1243:                                                                                    .getValue(),
1244:                                                                            "expectation submitted",
1245:                                                                            true);
1246:
1247:                                                        pageForms.add(pageForm);
1248:                                                    }
1249:                                                    cell.getWizardPage()
1250:                                                            .setPageForms(
1251:                                                                    pageForms);
1252:                                                } finally {
1253:                                                    reflectionRS.close();
1254:                                                }
1255:                                            }
1256:                                        } finally {
1257:                                            intelGrowthRS.close();
1258:                                        }
1259:
1260:                                        //
1261:                                        sql = "SELECT ID, REVIEWER_ID, COMMENTS, GRADE, STATUS, CREATED, MODIFIED FROM "
1262:                                                + tableName3
1263:                                                + " WHERE CELL_ID='"
1264:                                                + mcidStr
1265:                                                + "'";
1266:                                        ResultSet evalRS = matrixInnerStmt
1267:                                                .executeQuery(sql);
1268:                                        try {
1269:                                            while (evalRS.next()) {
1270:                                                String riid = evalRS
1271:                                                        .getString("ID");
1272:                                                String reviewer_id = evalRS
1273:                                                        .getString("REVIEWER_ID");
1274:                                                String comment = evalRS
1275:                                                        .getString("COMMENTS");
1276:                                                String grade = evalRS
1277:                                                        .getString("GRADE");
1278:                                                String ri_status = evalRS
1279:                                                        .getString("STATUS");
1280:                                                String ri_created = evalRS
1281:                                                        .getString("CREATED");
1282:                                                String ri_modified = evalRS
1283:                                                        .getString("MODIFIED");
1284:
1285:                                                // save the Reviews
1286:                                                //Skip if the reviewer is null
1287:                                                if (reviewer_id != null
1288:                                                        && !reviewer_id
1289:                                                                .equalsIgnoreCase("")) {
1290:                                                    Integer anId = incUser(reviewer_id);
1291:                                                    Id evaluationForm = createEvaluationForm(
1292:                                                            reviewer_id,
1293:                                                            "Review "
1294:                                                                    + scaffolding
1295:                                                                            .getTitle()
1296:                                                                    + " "
1297:                                                                    + sCell
1298:                                                                            .getRootCriterion()
1299:                                                                            .getDescription()
1300:                                                                    + " "
1301:                                                                    + sCell
1302:                                                                            .getLevel()
1303:                                                                            .getDescription()
1304:                                                                    + " - "
1305:                                                                    + anId
1306:                                                                            .toString(),
1307:                                                            grade, comment);
1308:
1309:                                                    Review review = reviewManager
1310:                                                            .createNew("",
1311:                                                                    worksite);
1312:                                                    review
1313:                                                            .setDeviceId(evaluationFormId
1314:                                                                    .getValue());// form idvalue
1315:                                                    Id pageId = resolveId(cell
1316:                                                            .getWizardPage());
1317:                                                    review.setParent(pageId
1318:                                                            .getValue());// wizard page
1319:                                                    review
1320:                                                            .setType(Review.EVALUATION_TYPE);//contant
1321:                                                    review
1322:                                                            .setReviewContent(evaluationForm);
1323:                                                    review = getReviewManager()
1324:                                                            .saveReview(review);
1325:
1326:                                                    contentHosting
1327:                                                            .lockObject(
1328:                                                                    evaluationForm
1329:                                                                            .getValue(),
1330:                                                                    review
1331:                                                                            .getId()
1332:                                                                            .getValue(),
1333:                                                                    "evaluation is once off",
1334:                                                                    true);
1335:                                                }
1336:                                            }
1337:                                        } finally {
1338:                                            evalRS.close();
1339:                                        }
1340:
1341:                                        matrix.add(cell);
1342:                                    }
1343:                                } // end while(rss.next()) -- looping through each matrix
1344:                            } finally {
1345:                                rss.close();
1346:                            }
1347:
1348:                            if (matrix != null && !badCell) {
1349:                                if (matrix.getOwner() == null)
1350:                                    logger
1351:                                            .error("OSP Migration Error: The matrix owner agent couldn't be found: "
1352:                                                    + lastOwner);
1353:                                else if (matrix.getOwner().getId() == null)
1354:                                    logger
1355:                                            .error("OSP Migration Error: The matrix owner agent id couldn't be found: "
1356:                                                    + lastOwner);
1357:                                else if (matrix.getOwner().getId().getValue() == null)
1358:                                    logger
1359:                                            .error("OSP Migration Error: The matrix owner agent id value couldn't be found: "
1360:                                                    + lastOwner);
1361:                                else
1362:                                    matrixManager.save(matrix);
1363:                            }
1364:
1365:                        } // end while(rs.next()) -- looping through each scaffolding
1366:
1367:                    } finally {
1368:                        rs.close();
1369:                    }
1370:
1371:                } catch (Exception e) {
1372:                    logger.error("error selecting data with this sql: " + sql);
1373:                    logger.error("", e);
1374:                    throw new JobExecutionException(e);
1375:                } finally {
1376:                    try {
1377:                        stmt.close();
1378:                        innerStmt.close();
1379:                        matrixInnerStmt.close();
1380:                    } catch (Exception e) {
1381:                    }
1382:                }
1383:                logger.info("Quartz task fininshed: runMatrixMigration()");
1384:
1385:            }
1386:
1387:            protected void runPresentationTemplateMigration(Connection con,
1388:                    boolean isDeveloper) throws JobExecutionException {
1389:                logger
1390:                        .info("Quartz task started: runPresentationTemplateMigration()");
1391:                String templateTableName = getOldTableName("osp_presentation_template");
1392:                String sql = "select * from " + templateTableName;
1393:
1394:                try {
1395:                    stmt = con.createStatement();
1396:                    ResultSet rs = stmt.executeQuery(sql);
1397:                    try {
1398:                        while (rs.next()) {
1399:                            String id = rs.getString("id");
1400:                            String name = rs.getString("name");
1401:                            String desc = rs.getString("description");
1402:                            boolean includeHeaderAndFooter = rs
1403:                                    .getBoolean("includeHeaderAndFooter");
1404:                            //boolean includeComments = rs.getBoolean("includeComments");
1405:                            boolean published = rs.getBoolean("published");
1406:                            String owner = rs.getString("owner_id");
1407:                            String renderer = rs.getString("renderer");
1408:                            String markup = rs.getString("markup");
1409:                            String propertyPage = rs.getString("propertyPage");
1410:                            String documentRoot = rs.getString("documentRoot");
1411:                            Date created = rs.getDate("created");
1412:                            Date modified = rs.getDate("modified");
1413:                            String siteId = rs.getString("site_id");
1414:                            Id tid = idManager.getId(id);
1415:
1416:                            PresentationTemplate template = new PresentationTemplate();
1417:                            template.setId(null);
1418:                            template.setNewId(tid);
1419:                            template.setName(name);
1420:                            template.setDescription(desc);
1421:                            template
1422:                                    .setIncludeHeaderAndFooter(includeHeaderAndFooter);
1423:                            template.setPublished(published);
1424:                            template.setOwner(agentManager.getAgent(owner));
1425:                            template.setRenderer(idManager.getId(renderer));
1426:                            template.setMarkup(markup);
1427:                            template.setPropertyPage(idManager
1428:                                    .getId(propertyPage));
1429:                            template.setDocumentRoot(documentRoot);
1430:                            template.setCreated(created);
1431:                            template.setModified(modified);
1432:                            template.setSiteId(siteId);
1433:
1434:                            Set itemDefs = createTemplateItemDefs(con, template);
1435:                            template.setItems(itemDefs);
1436:
1437:                            Set fileRefs = createTemplateFileRefs(con, template);
1438:                            template.setFiles(fileRefs);
1439:
1440:                            if (template.getOwner() == null)
1441:                                logger
1442:                                        .error("OSP Migration Error: The template owner agent couldn't be found: "
1443:                                                + owner);
1444:                            else if (template.getOwner().getId() == null)
1445:                                logger
1446:                                        .error("OSP Migration Error: The template owner agent id couldn't be found: "
1447:                                                + owner);
1448:                            else if (template.getOwner().getId().getValue() == null)
1449:                                logger
1450:                                        .error("OSP Migration Error: The template owner agent id value couldn't be found: "
1451:                                                + owner);
1452:                            else
1453:                                presentationManager.storeTemplate(template,
1454:                                        false, false);
1455:
1456:                        }
1457:                    } finally {
1458:                        rs.close();
1459:                    }
1460:                } catch (Exception e) {
1461:                    logger.error("error selecting data with this sql: " + sql);
1462:                    logger.error("", e);
1463:                    throw new JobExecutionException(e);
1464:                } finally {
1465:                    try {
1466:                        stmt.close();
1467:                    } catch (Exception e) {
1468:                    }
1469:                }
1470:                logger
1471:                        .info("Quartz task fininshed: runPresentationTemplateMigration()");
1472:            }
1473:
1474:            protected void runPresentationMigration(Connection con,
1475:                    boolean isDeveloper) throws JobExecutionException {
1476:                logger.info("Quartz task started: runPresentationMigration()");
1477:                String templateTableName = getOldTableName("osp_presentation");
1478:                String sql = "select * from " + templateTableName;
1479:
1480:                try {
1481:                    stmt = con.createStatement();
1482:                    ResultSet rs = stmt.executeQuery(sql);
1483:                    try {
1484:                        while (rs.next()) {
1485:                            String id = rs.getString("id");
1486:                            String owner = rs.getString("owner_id");
1487:                            String templateId = rs.getString("template_id");
1488:                            String name = rs.getString("name");
1489:                            String desc = rs.getString("description");
1490:                            boolean isDefault = rs.getBoolean("isDefault");
1491:                            boolean isPublic = rs.getBoolean("isPublic");
1492:
1493:                            Date expiresOn = rs.getDate("expiresOn");
1494:                            Date created = rs.getDate("created");
1495:                            Date modified = rs.getDate("modified");
1496:                            //Blob properties = rs.getBlob("properties");
1497:                            String toolId = rs.getString("tool_id");
1498:                            Id pid = idManager.getId(id);
1499:
1500:                            Presentation presentation = new Presentation();
1501:                            presentation.setNewObject(true);
1502:                            presentation.setId(null);
1503:                            presentation.setNewId(pid);
1504:                            presentation.setName(name);
1505:                            presentation.setDescription(desc);
1506:                            presentation.setIsDefault(isDefault);
1507:                            presentation.setIsPublic(isPublic);
1508:                            presentation.setOwner(agentManager.getAgent(owner));
1509:                            presentation.setExpiresOn(expiresOn);
1510:                            presentation.setCreated(created);
1511:                            presentation.setModified(modified);
1512:                            presentation.setToolId(toolId);
1513:
1514:                            if (presentation.getOwner() == null) {
1515:                                logger
1516:                                        .error("OSP Migration Error: The presentation owner agent couldn't be found: "
1517:                                                + owner);
1518:                                continue;
1519:                            } else if (presentation.getOwner().getId() == null) {
1520:                                logger
1521:                                        .error("OSP Migration Error: The presentation owner agent id couldn't be found: "
1522:                                                + owner);
1523:                                continue;
1524:                            } else if (presentation.getOwner().getId()
1525:                                    .getValue() == null) {
1526:                                logger
1527:                                        .error("OSP Migration Error: The presentation owner agent id value couldn't be found: "
1528:                                                + owner);
1529:                                continue;
1530:                            }
1531:
1532:                            String siteId = "";
1533:                            try {
1534:                                siteId = siteService.findTool(toolId)
1535:                                        .getContext();
1536:                            } catch (NullPointerException npe) {
1537:                                logger
1538:                                        .warn("Quartz task warning: runPresentationMigration().  Can't find context for toolId: "
1539:                                                + toolId);
1540:                                siteId = "dataMigrationError";
1541:                            }
1542:
1543:                            presentation.setSiteId(siteId);
1544:
1545:                            HibernatePresentationProperties hpp = new HibernatePresentationProperties();
1546:                            String[] names = { "properties" };
1547:                            Object props = hpp.nullSafeGet(rs, names, null);
1548:                            presentation.setProperties((ElementBean) props);
1549:                            presentation
1550:                                    .setPresentationType(Presentation.TEMPLATE_TYPE);
1551:                            PresentationTemplate template = presentationManager
1552:                                    .getPresentationTemplate(idManager
1553:                                            .getId(templateId));
1554:                            presentation.setTemplate(template);
1555:
1556:                            //TODO template no longer has comments, replace line below
1557:                            //presentation.setAllowComments(template.isIncludeComments());
1558:
1559:                            Set items = createPresentationItems(con,
1560:                                    presentation);
1561:                            presentation.setItems(items);
1562:
1563:                            presentationManager.storePresentation(presentation,
1564:                                    false, false);
1565:
1566:                            createPresentationComments(con, presentation);
1567:                            createPresentationLogs(con, presentation);
1568:
1569:                        }
1570:                    } finally {
1571:                        rs.close();
1572:                    }
1573:                } catch (Exception e) {
1574:                    logger.error("error selecting data with this sql: " + sql);
1575:                    logger.error("", e);
1576:                    throw new JobExecutionException(e);
1577:                } finally {
1578:                    try {
1579:                        stmt.close();
1580:                    } catch (Exception e) {
1581:                    }
1582:                }
1583:                logger
1584:                        .info("Quartz task fininshed: runPresentationMigration()");
1585:            }
1586:
1587:            protected Set createTemplateItemDefs(Connection con,
1588:                    PresentationTemplate template) throws JobExecutionException {
1589:                Set itemDefs = new HashSet();
1590:                String itemDefTableName = getOldTableName("osp_presentation_item_def");
1591:                String sql = "select * from " + itemDefTableName
1592:                        + " where template_id = '"
1593:                        + resolveId(template).getValue() + "'";
1594:                Statement innerstmt = null;
1595:                try {
1596:
1597:                    innerstmt = con.createStatement();
1598:                    ResultSet rs2 = innerstmt.executeQuery(sql);
1599:                    try {
1600:                        while (rs2.next()) {
1601:
1602:                            String id = rs2.getString("id");
1603:                            String name = rs2.getString("name");
1604:                            String title = rs2.getString("title");
1605:                            String description = rs2.getString("description");
1606:                            boolean allowMultiple = rs2
1607:                                    .getBoolean("allowMultiple");
1608:                            String type = rs2.getString("type");
1609:                            String externalType = rs2
1610:                                    .getString("external_type");
1611:                            int seq = rs2.getInt("sequence_no");
1612:                            //String templateId = rs2.getString("template_id");
1613:
1614:                            Id defid = idManager.getId(id);
1615:                            PresentationItemDefinition pid = new PresentationItemDefinition();
1616:                            pid.setId(null);
1617:                            pid.setNewId(defid);
1618:                            pid.setName(name);
1619:                            pid.setTitle(title);
1620:                            pid.setDescription(description);
1621:                            pid.setAllowMultiple(allowMultiple);
1622:                            pid.setType(type);
1623:                            pid.setExternalType(externalType);
1624:                            pid.setSequence(seq);
1625:                            pid.setPresentationTemplate(template);
1626:                            Set mimeTypes = createTemplateItemDefMimeTypes(con,
1627:                                    pid);
1628:                            pid.setMimeTypes(mimeTypes);
1629:
1630:                            itemDefs.add(pid);
1631:                        }
1632:
1633:                    } finally {
1634:                        rs2.close();
1635:                    }
1636:                } catch (Exception e) {
1637:                    logger.error("error selecting data with this sql: " + sql);
1638:                    logger.error("", e);
1639:                    throw new JobExecutionException(e);
1640:                } finally {
1641:                    try {
1642:                        innerstmt.close();
1643:                    } catch (Exception e) {
1644:                    }
1645:                }
1646:                return itemDefs;
1647:            }
1648:
1649:            protected Set createTemplateFileRefs(Connection con,
1650:                    PresentationTemplate template) throws JobExecutionException {
1651:                Set fileRefs = new HashSet();
1652:                String fileRefTableName = getOldTableName("osp_template_file_ref");
1653:                String sql = "select * from " + fileRefTableName
1654:                        + " where template_id = '"
1655:                        + resolveId(template).getValue() + "'";
1656:                Statement innerstmt = null;
1657:                try {
1658:
1659:                    innerstmt = con.createStatement();
1660:                    ResultSet rs2 = innerstmt.executeQuery(sql);
1661:                    try {
1662:                        while (rs2.next()) {
1663:
1664:                            String id = rs2.getString("id");
1665:                            String fileId = rs2.getString("file_id");
1666:                            String fileTypeId = rs2.getString("file_type_id");
1667:                            String usage = rs2.getString("usage_desc");
1668:                            //String templateId = rs2.getString("template_id");
1669:
1670:                            Id refid = idManager.getId(id);
1671:                            TemplateFileRef tfr = new TemplateFileRef();
1672:                            tfr.setId(null);
1673:                            tfr.setNewId(refid);
1674:                            tfr.setFileId(fileId);
1675:                            tfr.setFileType(fileTypeId);
1676:                            tfr.setUsage(usage);
1677:
1678:                            tfr.setPresentationTemplate(template);
1679:
1680:                            fileRefs.add(tfr);
1681:                        }
1682:
1683:                    } finally {
1684:                        rs2.close();
1685:                    }
1686:                } catch (Exception e) {
1687:                    logger.error("error selecting data with this sql: " + sql);
1688:                    logger.error("", e);
1689:                    throw new JobExecutionException(e);
1690:                } finally {
1691:                    try {
1692:                        innerstmt.close();
1693:                    } catch (Exception e) {
1694:                    }
1695:                }
1696:                return fileRefs;
1697:            }
1698:
1699:            protected Set createTemplateItemDefMimeTypes(Connection con,
1700:                    PresentationItemDefinition itemDef)
1701:                    throws JobExecutionException {
1702:                Set mimeTypes = new HashSet();
1703:                String itemDefMimeTypeTableName = getOldTableName("osp_pres_itemdef_mimetype");
1704:                String sql = "select * from " + itemDefMimeTypeTableName
1705:                        + " where item_def_id = '"
1706:                        + resolveId(itemDef).getValue() + "'";
1707:                Statement innerstmt = null;
1708:                try {
1709:
1710:                    innerstmt = con.createStatement();
1711:                    ResultSet rs2 = innerstmt.executeQuery(sql);
1712:                    try {
1713:                        while (rs2.next()) {
1714:
1715:                            String primary = rs2.getString("primaryMimeType");
1716:                            String secondary = rs2
1717:                                    .getString("secondaryMimeType");
1718:
1719:                            ItemDefinitionMimeType mimeType = new ItemDefinitionMimeType(
1720:                                    primary, secondary);
1721:
1722:                            mimeTypes.add(mimeType);
1723:                        }
1724:
1725:                    } finally {
1726:                        rs2.close();
1727:                    }
1728:                } catch (Exception e) {
1729:                    logger.error("error selecting data with this sql: " + sql);
1730:                    logger.error("", e);
1731:                    throw new JobExecutionException(e);
1732:                } finally {
1733:                    try {
1734:                        innerstmt.close();
1735:                    } catch (Exception e) {
1736:                    }
1737:                }
1738:                return mimeTypes;
1739:            }
1740:
1741:            protected Set createPresentationItems(Connection con,
1742:                    Presentation presentation) throws JobExecutionException {
1743:                Set items = new HashSet();
1744:                String itemTableName = getOldTableName("osp_presentation_item");
1745:                String sql = "select * from " + itemTableName
1746:                        + " where presentation_id = '"
1747:                        + resolveId(presentation).getValue() + "'";
1748:                Statement innerstmt = null;
1749:                try {
1750:
1751:                    innerstmt = con.createStatement();
1752:                    ResultSet rs2 = innerstmt.executeQuery(sql);
1753:                    try {
1754:                        while (rs2.next()) {
1755:
1756:                            String artifactId = rs2.getString("artifact_id");
1757:                            String itemDef = rs2
1758:                                    .getString("item_definition_id");
1759:
1760:                            PresentationItem item = new PresentationItem();
1761:                            item.setArtifactId(idManager.getId(artifactId));
1762:                            item.setDefinition(presentationManager
1763:                                    .getPresentationItemDefinition(idManager
1764:                                            .getId(itemDef)));
1765:
1766:                            items.add(item);
1767:                        }
1768:
1769:                    } finally {
1770:                        rs2.close();
1771:                    }
1772:                } catch (Exception e) {
1773:                    logger.error("error selecting data with this sql: " + sql);
1774:                    logger.error("", e);
1775:                    throw new JobExecutionException(e);
1776:                } finally {
1777:                    try {
1778:                        innerstmt.close();
1779:                    } catch (Exception e) {
1780:                    }
1781:                }
1782:                return items;
1783:            }
1784:
1785:            protected void createPresentationComments(Connection con,
1786:                    Presentation presentation) throws JobExecutionException {
1787:                String commentTableName = getOldTableName("osp_presentation_comment");
1788:                String sql = "select * from " + commentTableName
1789:                        + " where presentation_id = '"
1790:                        + resolveId(presentation).getValue() + "'";
1791:                Statement innerstmt = null;
1792:                try {
1793:
1794:                    innerstmt = con.createStatement();
1795:                    ResultSet rs2 = innerstmt.executeQuery(sql);
1796:                    try {
1797:                        while (rs2.next()) {
1798:
1799:                            String id = rs2.getString("id");
1800:                            String title = rs2.getString("title");
1801:                            String commentText = rs2.getString("commentText");
1802:                            String owner = rs2.getString("creator_id");
1803:                            byte visibility = rs2.getByte("visibility");
1804:                            Date created = rs2.getDate("created");
1805:
1806:                            Id cid = idManager.getId(id);
1807:                            PresentationComment comment = new PresentationComment();
1808:                            comment.setId(null);
1809:                            comment.setNewId(cid);
1810:                            comment.setTitle(title);
1811:                            comment.setComment(commentText);
1812:                            comment.setCreator(agentManager.getAgent(idManager
1813:                                    .getId(owner)));
1814:                            comment.setPresentation(presentation);
1815:                            comment.setVisibility(visibility);
1816:                            comment.setCreated(created);
1817:                            presentationManager.createComment(comment, false,
1818:                                    false);
1819:                        }
1820:
1821:                    } finally {
1822:                        rs2.close();
1823:                    }
1824:                } catch (Exception e) {
1825:                    logger.error("error selecting data with this sql: " + sql);
1826:                    logger.error("", e);
1827:                    throw new JobExecutionException(e);
1828:                } finally {
1829:                    try {
1830:                        innerstmt.close();
1831:                    } catch (Exception e) {
1832:                    }
1833:                }
1834:            }
1835:
1836:            protected void createPresentationLogs(Connection con,
1837:                    Presentation presentation) throws JobExecutionException {
1838:                String logTableName = getOldTableName("osp_presentation_log");
1839:                String sql = "select * from " + logTableName
1840:                        + " where presentation_id = '"
1841:                        + resolveId(presentation).getValue() + "'";
1842:                Statement innerstmt = null;
1843:                try {
1844:
1845:                    innerstmt = con.createStatement();
1846:                    ResultSet rs2 = innerstmt.executeQuery(sql);
1847:                    try {
1848:                        while (rs2.next()) {
1849:
1850:                            String id = rs2.getString("id");
1851:                            String viewer = rs2.getString("viewer_id");
1852:                            Date viewed = rs2.getDate("view_date");
1853:
1854:                            Id lid = idManager.getId(id);
1855:                            PresentationLog log = new PresentationLog();
1856:                            log.setId(null);
1857:                            log.setNewId(lid);
1858:                            log.setViewer(agentManager.getAgent(idManager
1859:                                    .getId(viewer)));
1860:                            log.setViewDate(viewed);
1861:                            log.setPresentation(presentation);
1862:                            presentationManager.storePresentationLog(log);
1863:                        }
1864:
1865:                    } finally {
1866:                        rs2.close();
1867:                    }
1868:                } catch (Exception e) {
1869:                    logger.error("error selecting data with this sql: " + sql);
1870:                    logger.error("", e);
1871:                    throw new JobExecutionException(e);
1872:                } finally {
1873:                    try {
1874:                        innerstmt.close();
1875:                    } catch (Exception e) {
1876:                    }
1877:                }
1878:            }
1879:
1880:            private Integer incUser(String userId) {
1881:                Integer accessTimes = (Integer) userUniquenessMap.get(userId);
1882:
1883:                if (accessTimes == null)
1884:                    accessTimes = new Integer(1);
1885:                else
1886:                    accessTimes = new Integer(accessTimes.intValue() + 1);
1887:                userUniquenessMap.put(userId, accessTimes);
1888:                return accessTimes;
1889:            }
1890:
1891:            private Id resolveId(IdentifiableObject obj) {
1892:                if (obj.getId() == null)
1893:                    return obj.getNewId();
1894:                return obj.getId();
1895:            }
1896:
1897:            protected String getOldTableName(String tableName) {
1898:                return (String) getTableMap().get(tableName);
1899:            }
1900:
1901:            public DataSource getDataSource() {
1902:                return dataSource;
1903:            }
1904:
1905:            public void setDataSource(DataSource dataSource) {
1906:                this .dataSource = dataSource;
1907:            }
1908:
1909:            public IdManager getIdManager() {
1910:                return idManager;
1911:            }
1912:
1913:            public void setIdManager(IdManager idManager) {
1914:                this .idManager = idManager;
1915:            }
1916:
1917:            public AgentManager getAgentManager() {
1918:                return agentManager;
1919:            }
1920:
1921:            public void setAgentManager(AgentManager agentManager) {
1922:                this .agentManager = agentManager;
1923:            }
1924:
1925:            public AuthorizationFacade getAuthzManager() {
1926:                return authzManager;
1927:            }
1928:
1929:            public void setAuthzManager(AuthorizationFacade authzManager) {
1930:                this .authzManager = authzManager;
1931:            }
1932:
1933:            public Map getTableMap() {
1934:                return tableMap;
1935:            }
1936:
1937:            public void setTableMap(Map tableMap) {
1938:                this .tableMap = tableMap;
1939:            }
1940:
1941:            public Glossary getGlossaryManager() {
1942:                return glossaryManager;
1943:            }
1944:
1945:            public void setGlossaryManager(Glossary glossaryManager) {
1946:                this .glossaryManager = glossaryManager;
1947:            }
1948:
1949:            public MatrixManager getMatrixManager() {
1950:                return matrixManager;
1951:            }
1952:
1953:            public void setMatrixManager(MatrixManager matrixManager) {
1954:                this .matrixManager = matrixManager;
1955:            }
1956:
1957:            public PresentationManager getPresentationManager() {
1958:                return presentationManager;
1959:            }
1960:
1961:            public void setPresentationManager(
1962:                    PresentationManager presentationManager) {
1963:                this .presentationManager = presentationManager;
1964:            }
1965:
1966:            public StructuredArtifactDefinitionManager getStructuredArtifactDefinitionManager() {
1967:                return structuredArtifactDefinitionManager;
1968:            }
1969:
1970:            public void setStructuredArtifactDefinitionManager(
1971:                    StructuredArtifactDefinitionManager structuredArtifactDefinitionManager) {
1972:                this .structuredArtifactDefinitionManager = structuredArtifactDefinitionManager;
1973:            }
1974:
1975:            public SiteService getSiteService() {
1976:                return siteService;
1977:            }
1978:
1979:            public void setSiteService(SiteService siteService) {
1980:                this .siteService = siteService;
1981:            }
1982:
1983:            public List getAuthzToolFunctions() {
1984:                return authzToolFunctions;
1985:            }
1986:
1987:            public void setAuthzToolFunctions(List authzToolFunctions) {
1988:                this .authzToolFunctions = authzToolFunctions;
1989:            }
1990:
1991:            public List getMatrixForms() {
1992:                return matrixForms;
1993:            }
1994:
1995:            public void setMatrixForms(List matrixForms) {
1996:                this .matrixForms = matrixForms;
1997:            }
1998:
1999:            public SecurityService getSecurityService() {
2000:                return securityService;
2001:            }
2002:
2003:            public void setSecurityService(SecurityService securityService) {
2004:                this .securityService = securityService;
2005:            }
2006:
2007:            public ContentHostingService getContentHosting() {
2008:                return contentHosting;
2009:            }
2010:
2011:            public void setContentHosting(ContentHostingService contentHosting) {
2012:                this .contentHosting = contentHosting;
2013:            }
2014:
2015:            public GuidanceManager getGuidanceManager() {
2016:                return guidanceManager;
2017:            }
2018:
2019:            public void setGuidanceManager(GuidanceManager guidanceManager) {
2020:                this .guidanceManager = guidanceManager;
2021:            }
2022:
2023:            public ReviewManager getReviewManager() {
2024:                return reviewManager;
2025:            }
2026:
2027:            public void setReviewManager(ReviewManager reviewManager) {
2028:                this .reviewManager = reviewManager;
2029:            }
2030:
2031:            public DefaultScaffoldingBean getDefaultScaffoldingBean() {
2032:                return defaultScaffoldingBean;
2033:            }
2034:
2035:            public void setDefaultScaffoldingBean(
2036:                    DefaultScaffoldingBean defaultScaffoldingBean) {
2037:                this .defaultScaffoldingBean = defaultScaffoldingBean;
2038:            }
2039:
2040:            /**
2041:             * @return Returns the workflowManager.
2042:             */
2043:            public WorkflowManager getWorkflowManager() {
2044:                return workflowManager;
2045:            }
2046:
2047:            /**
2048:             * @param workflowManager The workflowManager to set.
2049:             */
2050:            public void setWorkflowManager(WorkflowManager workflowManager) {
2051:                this.workflowManager = workflowManager;
2052:            }
2053:
2054:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.