Source Code Cross Referenced for SyllabusServiceImpl.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » component » app » syllabus » 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.sakaiproject.component.app.syllabus 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**********************************************************************************
0002:         * $URL: https://source.sakaiproject.org/svn/syllabus/tags/sakai_2-4-1/syllabus-impl/src/java/org/sakaiproject/component/app/syllabus/SyllabusServiceImpl.java $
0003:         * $Id: SyllabusServiceImpl.java 28701 2007-04-11 23:28:15Z ajpoland@iupui.edu $
0004:         ***********************************************************************************
0005:         *
0006:         * Copyright (c) 2003, 2004, 2005, 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.sakaiproject.component.app.syllabus;
0021:
0022:        import java.util.ArrayList;
0023:        import java.util.Collection;
0024:        import java.util.Iterator;
0025:        import java.util.List;
0026:        import java.util.Map;
0027:        import java.util.Set;
0028:        import java.util.TreeSet;
0029:        import java.util.Stack;
0030:        import java.util.Vector;
0031:
0032:        import org.apache.commons.codec.binary.Base64;
0033:        import org.apache.commons.logging.Log;
0034:        import org.apache.commons.logging.LogFactory;
0035:        import org.sakaiproject.api.app.syllabus.GatewaySyllabus;
0036:        import org.sakaiproject.api.app.syllabus.SyllabusAttachment;
0037:        import org.sakaiproject.api.app.syllabus.SyllabusData;
0038:        import org.sakaiproject.api.app.syllabus.SyllabusItem;
0039:        import org.sakaiproject.api.app.syllabus.SyllabusManager;
0040:        import org.sakaiproject.api.app.syllabus.SyllabusService;
0041:        import org.sakaiproject.component.cover.ServerConfigurationService;
0042:        import org.sakaiproject.content.api.ContentResource;
0043:        import org.sakaiproject.content.cover.ContentHostingService;
0044:        import org.sakaiproject.entity.api.Edit;
0045:        import org.sakaiproject.entity.api.Entity;
0046:        import org.sakaiproject.entity.api.EntityTransferrer;
0047:        import org.sakaiproject.entity.api.HttpAccess;
0048:        import org.sakaiproject.entity.api.Reference;
0049:        import org.sakaiproject.entity.api.ResourceProperties;
0050:        import org.sakaiproject.entity.api.ResourcePropertiesEdit;
0051:        import org.sakaiproject.entity.cover.EntityManager;
0052:        import org.sakaiproject.event.api.Event;
0053:        import org.sakaiproject.event.api.NotificationEdit;
0054:        import org.sakaiproject.event.api.NotificationService;
0055:        import org.sakaiproject.event.cover.EventTrackingService;
0056:        import org.sakaiproject.exception.IdUnusedException; //permission convert
0057:        import org.sakaiproject.site.api.Group;
0058:        import org.sakaiproject.site.api.Site;
0059:
0060:        import org.sakaiproject.site.cover.SiteService;
0061:        import org.sakaiproject.time.cover.TimeService;
0062:        import org.sakaiproject.tool.api.Placement;
0063:        import org.sakaiproject.tool.cover.SessionManager;
0064:        import org.sakaiproject.tool.cover.ToolManager;
0065:        import org.sakaiproject.user.cover.UserDirectoryService;
0066:        import org.sakaiproject.util.BaseResourcePropertiesEdit;
0067:        import org.sakaiproject.util.Validator;
0068:
0069:        //permission convert
0070:        import org.sakaiproject.authz.cover.SecurityService;
0071:
0072:        import org.w3c.dom.DOMException;
0073:        import org.w3c.dom.Document;
0074:        import org.w3c.dom.Element;
0075:        import org.w3c.dom.Node;
0076:        import org.w3c.dom.NodeList;
0077:
0078:        /**
0079:         * @author rshastri TODO To change the template for this generated type comment go to Window -
0080:         *         Preferences - Java - Code Style - Code Templates
0081:         */
0082:        public class SyllabusServiceImpl implements  SyllabusService,
0083:                EntityTransferrer {
0084:            private static final String SYLLABUS = "syllabus";
0085:            private static final String SYLLABUS_ID = "id";
0086:            private static final String SYLLABUS_USER_ID = "userID";
0087:            private static final String SYLLABUS_REDIRECT_URL = "redirectUrl";
0088:            private static final String SYLLABUS_CONTEXT_ID = "contextId";
0089:            private static final String SYLLABUS_DATA = "syllabus_data";
0090:            private static final String SYLLABUS_DATA_TITLE = "title";
0091:            private static final String SYLLABUS_DATA_POSITION = "position";
0092:            private static final String SYLLABUS_DATA_VIEW = "view";
0093:            private static final String SYLLABUS_DATA_ID = "syllabus_id";
0094:            private static final String SYLLABUS_DATA_EMAIL_NOTIFICATION = "emailNotification";
0095:            private static final String SYLLABUS_DATA_STATUS = "status";
0096:            private static final String SYLLABUS_DATA_ASSET = "asset";
0097:            private static final String SYLLABUS_ATTACHMENT = "attachment";
0098:            private static final String PAGE_ARCHIVE = "pageArchive";
0099:            private static final String SITE_NAME = "siteName";
0100:            private static final String SITE_ID = "siteId";
0101:            private static final String SITE_ARCHIVE = "siteArchive";
0102:            private static final String PAGE_NAME = "pageName";
0103:            private static final String PAGE_ID = "pageId";
0104:            /** Dependency: a SyllabusManager. */
0105:            private SyllabusManager syllabusManager;
0106:
0107:            /** Dependency: a logger component. */
0108:            private Log logger = LogFactory.getLog(SyllabusServiceImpl.class);
0109:
0110:            protected NotificationService notificationService = null;
0111:            protected String m_relativeAccessPoint = null;
0112:
0113:            //sakai2 -- add init and destroy methods  
0114:            public void init() {
0115:
0116:                m_relativeAccessPoint = REFERENCE_ROOT;
0117:
0118:                NotificationEdit edit = notificationService
0119:                        .addTransientNotification();
0120:
0121:                edit.setFunction(EVENT_SYLLABUS_POST_NEW);
0122:                edit.addFunction(EVENT_SYLLABUS_POST_CHANGE);
0123:                edit.addFunction(EVENT_SYLLABUS_DELETE_POST);
0124:                edit.addFunction(EVENT_SYLLABUS_READ);
0125:                edit.addFunction(EVENT_SYLLABUS_DRAFT_NEW);
0126:                edit.addFunction(EVENT_SYLLABUS_DRAFT_CHANGE);
0127:
0128:                edit.setResourceFilter(getAccessPoint(true));
0129:
0130:                edit.setAction(new SiteEmailNotificationSyllabus());
0131:
0132:                EntityManager.registerEntityProducer(this , REFERENCE_ROOT);
0133:            }
0134:
0135:            public void destroy() {
0136:            }
0137:
0138:            /**
0139:             * Establish logger component dependency.
0140:             * 
0141:             * @param logger
0142:             *          the logger component.
0143:             */
0144:            public void setLogger(Log logger) {
0145:                this .logger = logger;
0146:            }
0147:
0148:            /** Dependency: a SyllabusManager component. */
0149:            public void setSyllabusManager(SyllabusManager syllabusManager) {
0150:                this .syllabusManager = syllabusManager;
0151:            }
0152:
0153:            /*
0154:             * (non-Javadoc)
0155:             * 
0156:             * @see org.sakaiproject.service.legacy.entity.ResourceService#getLabel()
0157:             */
0158:            public String getLabel() {
0159:                return "syllabus";
0160:            }
0161:
0162:            /**
0163:             * {@inheritDoc}
0164:             */
0165:            public boolean willArchiveMerge() {
0166:                return true;
0167:            }
0168:
0169:            /**
0170:             * {@inheritDoc}
0171:             */
0172:            public boolean willImport() {
0173:                return true;
0174:            }
0175:
0176:            /**
0177:             * {@inheritDoc}
0178:             */
0179:            public HttpAccess getHttpAccess() {
0180:                return null;
0181:            }
0182:
0183:            /**
0184:             * from StringUtil.java
0185:             */
0186:            protected String[] split(String source, String splitter) {
0187:                // hold the results as we find them
0188:                Vector rv = new Vector();
0189:                int last = 0;
0190:                int next = 0;
0191:                do {
0192:                    // find next splitter in source
0193:                    next = source.indexOf(splitter, last);
0194:                    if (next != -1) {
0195:                        // isolate from last thru before next
0196:                        rv.add(source.substring(last, next));
0197:                        last = next + splitter.length();
0198:                    }
0199:                } while (next != -1);
0200:                if (last < source.length()) {
0201:                    rv.add(source.substring(last, source.length()));
0202:                }
0203:
0204:                // convert to array
0205:                return (String[]) rv.toArray(new String[rv.size()]);
0206:
0207:            } // split
0208:
0209:            /**
0210:             * {@inheritDoc}
0211:             */
0212:            public boolean parseEntityReference(String reference, Reference ref) {
0213:                if (reference.startsWith(REFERENCE_ROOT)) {
0214:                    // /syllabus/siteid/syllabusid
0215:                    String[] parts = split(reference, Entity.SEPARATOR);
0216:
0217:                    String subType = null;
0218:                    String context = null;
0219:                    String id = null;
0220:                    String container = null;
0221:
0222:                    // the first part will be null, then next the service, the third will be "calendar" or "event"
0223:                    if (parts.length > 2) {
0224:                        // the site/context
0225:                        context = parts[2];
0226:
0227:                        // the id
0228:                        if (parts.length > 3) {
0229:                            id = parts[3];
0230:                        }
0231:                    }
0232:
0233:                    ref.set(APPLICATION_ID, subType, id, container, context);
0234:
0235:                    return true;
0236:                }
0237:
0238:                return false;
0239:            }
0240:
0241:            /**
0242:             * {@inheritDoc}
0243:             */
0244:            public String getEntityDescription(Reference ref) {
0245:                return null;
0246:            }
0247:
0248:            /**
0249:             * {@inheritDoc}
0250:             */
0251:            public ResourceProperties getEntityResourceProperties(Reference ref) {
0252:                return null;
0253:            }
0254:
0255:            /**
0256:             * {@inheritDoc}
0257:             */
0258:            public Entity getEntity(Reference ref) {
0259:                return null;
0260:            }
0261:
0262:            /**
0263:             * {@inheritDoc}
0264:             */
0265:            public Collection getEntityAuthzGroups(Reference ref, String userId) {
0266:                //permission convert
0267:                Collection rv = new Vector();
0268:
0269:                try {
0270:                    //for 2.3
0271:                    //			Site site = SiteService.getSite(ref.getContext());
0272:                    //			Collection groups = site.getGroups();
0273:                    //
0274:                    //			if ((SecurityService.isSuperUser()))
0275:                    //			{
0276:                    //				return groups;
0277:                    //			}
0278:                    //
0279:                    //			Collection groupRefs = new Vector();
0280:                    //			for (Iterator i = groups.iterator(); i.hasNext();)
0281:                    //			{
0282:                    //				Group group = (Group) i.next();
0283:                    //				groupRefs.add(group.getReference());
0284:                    //			}
0285:                    //		
0286:                    //			for (Iterator i = groups.iterator(); i.hasNext();)
0287:                    //			{
0288:                    //				Group group = (Group) i.next();
0289:                    //				rv.add(group);
0290:                    //			}
0291:                    //			
0292:                    //			ref.addSiteContextAuthzGroup(rv);
0293:                    if (SYLLABUS.equals(ref.getSubType())) {
0294:                        rv.add(ref.getReference());
0295:
0296:                        ref.addSiteContextAuthzGroup(rv);
0297:                    }
0298:                } catch (Exception e) {
0299:                    logger.error("SyllabusServiceImpl:getEntityAuthzGroups - "
0300:                            + e);
0301:                    e.printStackTrace();
0302:                }
0303:
0304:                return rv;
0305:
0306:            }
0307:
0308:            /**
0309:             * {@inheritDoc}
0310:             */
0311:            public String getEntityUrl(Reference ref) {
0312:                return null;
0313:            }
0314:
0315:            /*
0316:             * (non-Javadoc)
0317:             * 
0318:             * @see org.sakaiproject.service.legacy.entity.ResourceService#archive(java.lang.String,
0319:             *      org.w3c.dom.Document, java.util.Stack, java.lang.String,
0320:             *      org.sakaiproject.service.legacy.entity.ReferenceVector)
0321:             */
0322:            public String archive(String siteId, Document doc, Stack stack,
0323:                    String arg3, List attachments) {
0324:
0325:                StringBuffer results = new StringBuffer();
0326:
0327:                try {
0328:                    int syDataCount = 0;
0329:                    results.append("archiving " + getLabel() + " context "
0330:                            + Entity.SEPARATOR + siteId + Entity.SEPARATOR
0331:                            + SiteService.MAIN_CONTAINER + ".\n");
0332:                    // start with an element with our very own (service) name
0333:                    Element element = doc.createElement(SyllabusService.class
0334:                            .getName());
0335:                    ((Element) stack.peek()).appendChild(element);
0336:                    stack.push(element);
0337:                    if (siteId != null && siteId.trim().length() > 0) {
0338:                        Element siteElement = doc.createElement(SITE_ARCHIVE);
0339:                        siteElement.setAttribute(SITE_NAME, SiteService
0340:                                .getSite(siteId).getId());
0341:                        siteElement.setAttribute(SITE_ID, SiteService.getSite(
0342:                                siteId).getTitle());
0343:                        //sakai2        Iterator pageIter = getSyllabusPages(siteId);
0344:                        //        if (pageIter != null)
0345:                        //        {
0346:                        //          while (pageIter.hasNext())
0347:                        //          {
0348:                        //            String page = (String) pageIter.next();
0349:                        //            if (page != null)
0350:                        //            {
0351:                        //              Element pageElement = doc.createElement(PAGE_ARCHIVE);
0352:                        //              pageElement.setAttribute(PAGE_ID, page);
0353:                        //sakai2              pageElement.setAttribute(PAGE_NAME, SiteService.getSite(siteId)
0354:                        //sakai2                  .getPage(page).getTitle());
0355:                        //sakai2              SyllabusItem syllabusItem = syllabusManager
0356:                        //                  .getSyllabusItemByContextId(page);
0357:                        SyllabusItem syllabusItem = syllabusManager
0358:                                .getSyllabusItemByContextId(siteId);
0359:                        if (syllabusItem != null) {
0360:                            Element syllabus = doc.createElement(SYLLABUS);
0361:                            syllabus.setAttribute(SYLLABUS_ID, syllabusItem
0362:                                    .getSurrogateKey().toString());
0363:                            syllabus.setAttribute(SYLLABUS_USER_ID,
0364:                                    syllabusItem.getUserId());
0365:                            syllabus.setAttribute(SYLLABUS_CONTEXT_ID,
0366:                                    syllabusItem.getContextId());
0367:                            syllabus.setAttribute(SYLLABUS_REDIRECT_URL,
0368:                                    syllabusItem.getRedirectURL());
0369:
0370:                            Set syllabi = syllabusManager
0371:                                    .getSyllabiForSyllabusItem(syllabusItem);
0372:
0373:                            if (syllabi != null && !syllabi.isEmpty()) {
0374:                                Iterator syllabiIter = syllabi.iterator();
0375:                                while (syllabiIter.hasNext()) {
0376:                                    SyllabusData syllabusData = (SyllabusData) syllabiIter
0377:                                            .next();
0378:                                    if (syllabusData != null) {
0379:                                        syDataCount++;
0380:                                        Element syllabus_data = doc
0381:                                                .createElement(SYLLABUS_DATA);
0382:                                        syllabus_data.setAttribute(
0383:                                                SYLLABUS_DATA_ID, syllabusData
0384:                                                        .getSyllabusId()
0385:                                                        .toString());
0386:                                        syllabus_data.setAttribute(
0387:                                                SYLLABUS_DATA_POSITION,
0388:                                                syllabusData.getPosition()
0389:                                                        .toString());
0390:                                        syllabus_data.setAttribute(
0391:                                                SYLLABUS_DATA_TITLE,
0392:                                                syllabusData.getTitle());
0393:                                        syllabus_data.setAttribute(
0394:                                                SYLLABUS_DATA_VIEW,
0395:                                                syllabusData.getView());
0396:                                        syllabus_data.setAttribute(
0397:                                                SYLLABUS_DATA_STATUS,
0398:                                                syllabusData.getStatus());
0399:                                        syllabus_data
0400:                                                .setAttribute(
0401:                                                        SYLLABUS_DATA_EMAIL_NOTIFICATION,
0402:                                                        syllabusData
0403:                                                                .getEmailNotification());
0404:                                        Element asset = doc
0405:                                                .createElement(SYLLABUS_DATA_ASSET);
0406:
0407:                                        try {
0408:                                            String encoded = new String(Base64
0409:                                                    .encodeBase64(syllabusData
0410:                                                            .getAsset()
0411:                                                            .getBytes()),
0412:                                                    "UTF-8");
0413:                                            asset.setAttribute(
0414:                                                    "syllabus_body-html",
0415:                                                    encoded);
0416:                                        } catch (Exception e) {
0417:                                            logger.warn("Encode Syllabus - "
0418:                                                    + e);
0419:                                        }
0420:
0421:                                        syllabus_data.appendChild(asset);
0422:                                        syllabus.appendChild(syllabus_data);
0423:
0424:                                    }
0425:                                }
0426:                                //sakai2                }
0427:                                //                pageElement.appendChild(syllabus);
0428:                                //              }
0429:                                //              siteElement.appendChild(pageElement);
0430:                                //            }
0431:
0432:                                //sakai2
0433:                                siteElement.appendChild(syllabus);
0434:                            }
0435:                            results
0436:                                    .append("archiving "
0437:                                            + getLabel()
0438:                                            + ": ("
0439:                                            + syDataCount
0440:                                            + ") syllabys items archived successfully.\n");
0441:                        } else {
0442:                            results.append("archiving " + getLabel()
0443:                                    + ": empty syllabus archived.\n");
0444:                        }
0445:                        ((Element) stack.peek()).appendChild(siteElement);
0446:                        stack.push(siteElement);
0447:                    }
0448:                    stack.pop();
0449:
0450:                } catch (DOMException e) {
0451:                    logger.error(e.getMessage(), e);
0452:                } catch (IdUnusedException e) {
0453:                    logger.error(e.getMessage(), e);
0454:                }
0455:                return results.toString();
0456:            }
0457:
0458:            /*
0459:             * (non-Javadoc)
0460:             * 
0461:             * @see org.sakaiproject.service.legacy.entity.ResourceService#merge(java.lang.String,
0462:             *      org.w3c.dom.Element, java.lang.String, java.lang.String, java.util.Map, java.util.HashMap,
0463:             *      java.util.Set)
0464:             */
0465:            public String merge(String siteId, Element root,
0466:                    String archivePath, String fromSiteId, Map attachmentNames,
0467:                    Map userIdTrans, Set userListAllowImport) {
0468:                // buffer for the results log
0469:                StringBuffer results = new StringBuffer();
0470:                // populate SyllabusItem
0471:                int syDataCount = 0;
0472:                SyllabusItem syItem = null;
0473:                if (siteId != null && siteId.trim().length() > 0) {
0474:                    try {
0475:                        NodeList allChildrenNodes = root.getChildNodes();
0476:                        int length = allChildrenNodes.getLength();
0477:                        for (int i = 0; i < length; i++) {
0478:                            Node siteNode = allChildrenNodes.item(i);
0479:                            if (siteNode.getNodeType() == Node.ELEMENT_NODE) {
0480:                                Element siteElement = (Element) siteNode;
0481:                                if (siteElement.getTagName().equals(
0482:                                        SITE_ARCHIVE)) {
0483:                                    //sakai2              NodeList pageNodes = siteElement.getChildNodes();
0484:                                    //              int lengthPageNodes = pageNodes.getLength();
0485:                                    //              for (int p = 0; p < lengthPageNodes; p++)
0486:                                    //              {
0487:                                    //                Node pageNode = pageNodes.item(p);
0488:                                    //                if (pageNode.getNodeType() == Node.ELEMENT_NODE)
0489:                                    //                {
0490:                                    //                  Element pageElement = (Element) pageNode;
0491:                                    //                  if (pageElement.getTagName().equals(PAGE_ARCHIVE))
0492:                                    //                  {
0493:                                    //                    NodeList syllabusNodes = pageElement.getChildNodes();
0494:                                    NodeList syllabusNodes = siteElement
0495:                                            .getChildNodes();
0496:                                    int lengthSyllabusNodes = syllabusNodes
0497:                                            .getLength();
0498:                                    for (int sn = 0; sn < lengthSyllabusNodes; sn++) {
0499:                                        Node syNode = syllabusNodes.item(sn);
0500:                                        if (syNode.getNodeType() == Node.ELEMENT_NODE) {
0501:                                            Element syElement = (Element) syNode;
0502:                                            if (syElement.getTagName().equals(
0503:                                                    SYLLABUS)) {
0504:                                                //create a page and all syllabus tool to the page
0505:                                                //sakai2                          String page = addSyllabusToolToPage(siteId,pageElement
0506:                                                //                              .getAttribute(PAGE_NAME));
0507:                                                //                          SyllabusItem syllabusItem = syllabusManager
0508:                                                //                          .createSyllabusItem(UserDirectoryService
0509:                                                //                              .getCurrentUser().getId(), page, syElement
0510:                                                //                              .getAttribute(SYLLABUS_REDIRECT_URL));
0511:                                                String page = addSyllabusToolToPage(
0512:                                                        siteId,
0513:                                                        siteElement
0514:                                                                .getAttribute(SITE_NAME));
0515:                                                //sakai2                          SyllabusItem syllabusItem = syllabusManager
0516:                                                //                          .createSyllabusItem(UserDirectoryService
0517:                                                //                              .getCurrentUser().getId(), page, syElement
0518:                                                //                              .getAttribute(SYLLABUS_REDIRECT_URL));
0519:                                                //sakai2 add--
0520:                                                SyllabusItem syllabusItem = syllabusManager
0521:                                                        .getSyllabusItemByContextId(page);
0522:                                                if (syllabusItem == null) {
0523:                                                    syllabusItem = syllabusManager
0524:                                                            .createSyllabusItem(
0525:                                                                    UserDirectoryService
0526:                                                                            .getCurrentUser()
0527:                                                                            .getId(),
0528:                                                                    page,
0529:                                                                    syElement
0530:                                                                            .getAttribute(SYLLABUS_REDIRECT_URL));
0531:                                                }
0532:                                                //added htripath: get imported redirecturl, even if syllabus item is existing.
0533:                                                else {
0534:                                                    if (syElement
0535:                                                            .getAttribute(SYLLABUS_REDIRECT_URL) != null) {
0536:                                                        syllabusItem
0537:                                                                .setRedirectURL(syElement
0538:                                                                        .getAttribute(SYLLABUS_REDIRECT_URL));
0539:                                                        syllabusManager
0540:                                                                .saveSyllabusItem(syllabusItem);
0541:                                                    }
0542:                                                }
0543:                                                //
0544:                                                NodeList allSyllabiNodes = syElement
0545:                                                        .getChildNodes();
0546:                                                int lengthSyllabi = allSyllabiNodes
0547:                                                        .getLength();
0548:                                                for (int j = 0; j < lengthSyllabi; j++) {
0549:                                                    Node child2 = allSyllabiNodes
0550:                                                            .item(j);
0551:                                                    if (child2.getNodeType() == Node.ELEMENT_NODE) {
0552:
0553:                                                        Element syDataElement = (Element) child2;
0554:                                                        if (syDataElement
0555:                                                                .getTagName()
0556:                                                                .equals(
0557:                                                                        SYLLABUS_DATA)) {
0558:                                                            List attachStringList = new ArrayList();
0559:
0560:                                                            syDataCount = syDataCount + 1;
0561:                                                            SyllabusData syData = new SyllabusDataImpl();
0562:                                                            syData
0563:                                                                    .setView(syDataElement
0564:                                                                            .getAttribute(SYLLABUS_DATA_VIEW));
0565:                                                            syData
0566:                                                                    .setTitle(syDataElement
0567:                                                                            .getAttribute(SYLLABUS_DATA_TITLE));
0568:                                                            syData
0569:                                                                    .setStatus(syDataElement
0570:                                                                            .getAttribute(SYLLABUS_DATA_STATUS));
0571:                                                            syData
0572:                                                                    .setEmailNotification(syDataElement
0573:                                                                            .getAttribute(SYLLABUS_DATA_EMAIL_NOTIFICATION));
0574:
0575:                                                            NodeList allAssetNodes = syDataElement
0576:                                                                    .getChildNodes();
0577:                                                            int lengthSyData = allAssetNodes
0578:                                                                    .getLength();
0579:                                                            for (int k = 0; k < lengthSyData; k++) {
0580:                                                                Node child3 = allAssetNodes
0581:                                                                        .item(k);
0582:                                                                if (child3
0583:                                                                        .getNodeType() == Node.ELEMENT_NODE) {
0584:                                                                    Element assetEle = (Element) child3;
0585:                                                                    if (assetEle
0586:                                                                            .getTagName()
0587:                                                                            .equals(
0588:                                                                                    SYLLABUS_DATA_ASSET)) {
0589:                                                                        String charset = trimToNull(assetEle
0590:                                                                                .getAttribute("charset"));
0591:                                                                        if (charset == null)
0592:                                                                            charset = "UTF-8";
0593:
0594:                                                                        String body = trimToNull(assetEle
0595:                                                                                .getAttribute("syllabus_body-html"));
0596:                                                                        if (body != null) {
0597:                                                                            try {
0598:                                                                                byte[] decoded = Base64
0599:                                                                                        .decodeBase64(body
0600:                                                                                                .getBytes("UTF-8"));
0601:                                                                                body = new String(
0602:                                                                                        decoded,
0603:                                                                                        charset);
0604:                                                                            } catch (Exception e) {
0605:                                                                                logger
0606:                                                                                        .warn("Decode Syllabus: "
0607:                                                                                                + e);
0608:                                                                            }
0609:                                                                        }
0610:
0611:                                                                        if (body == null)
0612:                                                                            body = "";
0613:
0614:                                                                        String ret;
0615:                                                                        ret = trimToNull(body);
0616:
0617:                                                                        syData
0618:                                                                                .setAsset(ret);
0619:                                                                        /*decode
0620:                                                                         NodeList assetStringNodes = assetEle
0621:                                                                         .getChildNodes();
0622:                                                                         int lengthAssetNodes = assetStringNodes
0623:                                                                         .getLength();
0624:                                                                         for (int l = 0; l < lengthAssetNodes; l++)
0625:                                                                         {
0626:                                                                         Node child4 = assetStringNodes.item(l);
0627:                                                                         if (child4.getNodeType() == Node.TEXT_NODE)
0628:                                                                         {
0629:                                                                         Text textNode = (Text) child4;
0630:                                                                         syData.setAsset(textNode.getData());
0631:                                                                         }
0632:                                                                         }*/
0633:                                                                    }
0634:                                                                    if (assetEle
0635:                                                                            .getTagName()
0636:                                                                            .equals(
0637:                                                                                    SYLLABUS_ATTACHMENT)) {
0638:                                                                        Element attachElement = (Element) child3;
0639:                                                                        String oldUrl = attachElement
0640:                                                                                .getAttribute("relative-url");
0641:                                                                        if (oldUrl
0642:                                                                                .startsWith("/content/attachment/")) {
0643:                                                                            String newUrl = (String) attachmentNames
0644:                                                                                    .get(oldUrl);
0645:                                                                            if (newUrl != null) {
0646:                                                                                ////if (newUrl.startsWith("/attachment/"))
0647:                                                                                ////newUrl = "/content".concat(newUrl);
0648:
0649:                                                                                attachElement
0650:                                                                                        .setAttribute(
0651:                                                                                                "relative-url",
0652:                                                                                                Validator
0653:                                                                                                        .escapeQuestionMark(newUrl));
0654:
0655:                                                                                attachStringList
0656:                                                                                        .add(Validator
0657:                                                                                                .escapeQuestionMark(newUrl));
0658:
0659:                                                                            }
0660:                                                                        } else if (oldUrl
0661:                                                                                .startsWith("/content/group/"
0662:                                                                                        + fromSiteId
0663:                                                                                        + "/")) {
0664:                                                                            String newUrl = "/content/group/"
0665:                                                                                    + siteId
0666:                                                                                    + oldUrl
0667:                                                                                            .substring(15 + fromSiteId
0668:                                                                                                    .length());
0669:                                                                            attachElement
0670:                                                                                    .setAttribute(
0671:                                                                                            "relative-url",
0672:                                                                                            Validator
0673:                                                                                                    .escapeQuestionMark(newUrl));
0674:
0675:                                                                            attachStringList
0676:                                                                                    .add(Validator
0677:                                                                                            .escapeQuestionMark(newUrl));
0678:                                                                        }
0679:                                                                    }
0680:                                                                }
0681:                                                            }
0682:
0683:                                                            int initPosition = syllabusManager
0684:                                                                    .findLargestSyllabusPosition(
0685:                                                                            syllabusItem)
0686:                                                                    .intValue() + 1;
0687:                                                            syData = syllabusManager
0688:                                                                    .createSyllabusDataObject(
0689:                                                                            syData
0690:                                                                                    .getTitle(),
0691:                                                                            (new Integer(
0692:                                                                                    initPosition)),
0693:                                                                            syData
0694:                                                                                    .getAsset(),
0695:                                                                            syData
0696:                                                                                    .getView(),
0697:                                                                            syData
0698:                                                                                    .getStatus(),
0699:                                                                            syData
0700:                                                                                    .getEmailNotification());
0701:                                                            Set attachSet = new TreeSet();
0702:                                                            for (int m = 0; m < attachStringList
0703:                                                                    .size(); m++) {
0704:                                                                ContentResource cr = ContentHostingService
0705:                                                                        .getResource((String) attachStringList
0706:                                                                                .get(m));
0707:                                                                ResourceProperties rp = cr
0708:                                                                        .getProperties();
0709:                                                                //                            			SyllabusAttachment tempAttach = syllabusManager.createSyllabusAttachmentObject(
0710:                                                                //                            					(String)attachStringList.get(m),rp.getProperty(ResourceProperties.PROP_DISPLAY_NAME));
0711:                                                                SyllabusAttachment tempAttach = syllabusManager
0712:                                                                        .createSyllabusAttachmentObject(
0713:                                                                                cr
0714:                                                                                        .getId(),
0715:                                                                                rp
0716:                                                                                        .getProperty(ResourceProperties.PROP_DISPLAY_NAME));
0717:                                                                tempAttach
0718:                                                                        .setName(rp
0719:                                                                                .getProperty(ResourceProperties.PROP_DISPLAY_NAME));
0720:                                                                tempAttach
0721:                                                                        .setSize(rp
0722:                                                                                .getProperty(ResourceProperties.PROP_CONTENT_LENGTH));
0723:                                                                tempAttach
0724:                                                                        .setType(rp
0725:                                                                                .getProperty(ResourceProperties.PROP_CONTENT_TYPE));
0726:                                                                tempAttach
0727:                                                                        .setUrl(cr
0728:                                                                                .getUrl());
0729:                                                                tempAttach
0730:                                                                        .setAttachmentId(cr
0731:                                                                                .getId());
0732:
0733:                                                                attachSet
0734:                                                                        .add(tempAttach);
0735:                                                            }
0736:                                                            syData
0737:                                                                    .setAttachments(attachSet);
0738:
0739:                                                            syllabusManager
0740:                                                                    .addSyllabusToSyllabusItem(
0741:                                                                            syllabusItem,
0742:                                                                            syData);
0743:
0744:                                                        }
0745:                                                    }
0746:                                                }
0747:
0748:                                            }
0749:                                        }
0750:                                    }
0751:                                    //sakai2                  }
0752:                                    //sakai2                }
0753:                                    //sakai2              }
0754:                                }
0755:                            }
0756:
0757:                        }
0758:                        results.append("merging syllabus " + siteId + " ("
0759:                                + syDataCount + ") syllabus items.\n");
0760:
0761:                    } catch (DOMException e) {
0762:                        logger.error(e.getMessage(), e);
0763:                        results.append("merging " + getLabel()
0764:                                + " failed during xml parsing.\n");
0765:
0766:                    } catch (Exception e) {
0767:                        logger.error(e.getMessage(), e);
0768:                        results.append("merging " + getLabel() + " failed.\n");
0769:                    }
0770:                }
0771:
0772:                return results.toString();
0773:            }
0774:
0775:            /**
0776:             * @param attribute
0777:             * @return
0778:             */
0779:            private String addSyllabusToolToPage(String siteId, String pageName) {
0780:                /*sakai2  try
0781:                 {
0782:                 SiteEdit siteEdit = SiteService.editSite(siteId);
0783:                 SitePageEdit editPage=siteEdit.addPage();
0784:                 editPage.setTitle(pageName);
0785:                 ToolRegistration reg = ServerConfigurationService.getToolRegistration("sakai.syllabus");
0786:                 editPage.addTool(reg);    
0787:                 SiteService.commitEdit(siteEdit);
0788:                 return editPage.getId();
0789:                 }
0790:                
0791:                 catch (IdUnusedException e)
0792:                 {
0793:                 logger.error(e.getMessage(),e);
0794:                 }
0795:                 catch (PermissionException e)
0796:                 {
0797:                 logger.error(e.getMessage(),e);
0798:                 }
0799:                 catch (InUseException e)
0800:                 {
0801:                 logger.error(e.getMessage(),e);
0802:                 }
0803:                
0804:                 return null;*/
0805:                return siteId;
0806:            }
0807:
0808:            /*
0809:             * (non-Javadoc)
0810:             * 
0811:             * @see org.sakaiproject.service.legacy.entity.ResourceService#importResources(java.lang.String,
0812:             *      java.lang.String, java.util.List)
0813:             */
0814:            public void importEntities(String fromSiteId, String toSiteId,
0815:                    List resourceIds) {
0816:                try {
0817:                    //sakai2    Iterator fromPages = getSyllabusPages(fromSiteId);
0818:                    //    if (fromPages == null || !fromPages.hasNext())
0819:                    //    {
0820:                    //      logger
0821:                    //          .debug("importResources: no source syllabus tool found to be imported");
0822:                    //    }
0823:                    //    else
0824:                    //    {
0825:                    //      Iterator toPages = getSyllabusPages(toSiteId);
0826:                    //      if (toPages == null || !toPages.hasNext())
0827:                    //      {
0828:                    //        logger
0829:                    //            .debug("importResources: no destination syllabus tool found where data can be imported");
0830:                    //      }
0831:                    //      else
0832:                    //      {
0833:                    //        while (fromPages.hasNext())
0834:                    //        {
0835:
0836:                    logger
0837:                            .debug("importResources: Begin importing syllabus data");
0838:                    //sakai2          String fromPage = (String) fromPages.next();
0839:                    //sakai2          toPages = getSyllabusPages(toSiteId);
0840:                    String fromPage = fromSiteId;
0841:                    SyllabusItem fromSyllabusItem = syllabusManager
0842:                            .getSyllabusItemByContextId(fromPage);
0843:                    if (fromSyllabusItem != null) {
0844:                        Set fromSyDataSet = syllabusManager
0845:                                .getSyllabiForSyllabusItem(fromSyllabusItem);
0846:                        if (fromSyDataSet != null && fromSyDataSet.size() > 0) {
0847:                            //sakai2              while (toPages.hasNext())
0848:                            //             {
0849:                            fromSyDataSet = syllabusManager
0850:                                    .getSyllabiForSyllabusItem(fromSyllabusItem);
0851:                            //sakai2                String toPage = (String) toPages.next();
0852:                            // String toPage=addSyllabusToolToPage(toSiteId,SiteService.getSite(fromSiteId).getPage(fromPage).getTitle());
0853:                            //sakai2                SyllabusItem toSyItem = syllabusManager
0854:                            //sakai2                    .getSyllabusItemByContextId(toPage);
0855:                            String toPage = addSyllabusToolToPage(toSiteId,
0856:                                    SiteService.getSite(toSiteId).getTitle());
0857:                            SyllabusItem toSyItem = syllabusManager
0858:                                    .getSyllabusItemByContextId(toPage);
0859:                            if (toSyItem == null) {
0860:                                toSyItem = syllabusManager.createSyllabusItem(
0861:                                        UserDirectoryService.getCurrentUser()
0862:                                                .getId(), toPage,
0863:                                        fromSyllabusItem.getRedirectURL());
0864:                            }
0865:                            Iterator fromSetIter = fromSyDataSet.iterator();
0866:                            while (fromSetIter.hasNext()) {
0867:                                SyllabusData toSyData = (SyllabusData) fromSetIter
0868:                                        .next();
0869:                                Integer positionNo = new Integer(
0870:                                        syllabusManager
0871:                                                .findLargestSyllabusPosition(
0872:                                                        toSyItem).intValue() + 1);
0873:                                SyllabusData newToSyData = syllabusManager
0874:                                        .createSyllabusDataObject(toSyData
0875:                                                .getTitle(), positionNo,
0876:                                                toSyData.getAsset(), toSyData
0877:                                                        .getView(), toSyData
0878:                                                        .getStatus(), toSyData
0879:                                                        .getEmailNotification());
0880:                                syllabusManager.addSyllabusToSyllabusItem(
0881:                                        toSyItem, newToSyData);
0882:                            }
0883:                            //sakai2              }
0884:                        } else {
0885:                            logger
0886:                                    .debug("importResources: no data found for syllabusItem id"
0887:                                            + fromSyllabusItem
0888:                                                    .getSurrogateKey()
0889:                                                    .toString());
0890:                        }
0891:                    }
0892:                    //sakai2        }
0893:                    logger
0894:                            .debug("importResources: End importing syllabus data");
0895:                    //sakai2      }
0896:                    //sakai2    }
0897:                }
0898:                //   catch (IdUnusedException e)
0899:                //   {
0900:                //   logger.error(e.getMessage(),e);
0901:                //   }
0902:                catch (Exception e) {
0903:                    logger.error(e.getMessage(), e);
0904:                }
0905:
0906:            }
0907:
0908:            /**
0909:             * @param siteId
0910:             * @return iterator of pageids containing syllabus tool for given site
0911:             */
0912:            private Iterator getSyllabusPages(String siteId) {
0913:                List syPages = null;
0914:                syPages = new ArrayList();
0915:                syPages.add(siteId);
0916:                return syPages.iterator();
0917:                /*sakai2    if (siteId != null && siteId.trim().length() > 0)
0918:                 {
0919:                 Site site = null;
0920:                 try
0921:                 {
0922:                 site = SiteService.getSite(siteId);
0923:                 }
0924:                 catch (IdUnusedException e)
0925:                 {
0926:                 logger.error("Error retriving site: unused IdUnusedException "
0927:                 + e.getMessage(), e);
0928:                 return null;
0929:                 }
0930:                 List pages = site.getPages();
0931:
0932:                 if (pages != null && pages.size() > 0)
0933:                 {
0934:                 syPages = new ArrayList();
0935:
0936:                 Iterator pageIter = pages.iterator();
0937:                 while (pageIter.hasNext())
0938:                 {
0939:                 SitePage page = (SitePage) pageIter.next();
0940:                 if (page != null)
0941:                 {
0942:                 // process each tool till we see syllabus
0943:                 for (Iterator iTools = page.getTools().iterator(); iTools.hasNext();)
0944:                 {
0945:                 ToolConfiguration tool = (ToolConfiguration) iTools.next();
0946:                 String toolId = tool.getId();
0947:                 if (toolId != null && tool.getToolId().equals("sakai.syllabus"))
0948:                 {
0949:                 syPages.add(page.getId());
0950:                 }
0951:                 }
0952:                 }
0953:                 }
0954:                 }
0955:                 }
0956:                 if (syPages != null && syPages.size() > 0)
0957:                 {
0958:                 return syPages.iterator();
0959:                 }
0960:                 else
0961:                 {
0962:                 return null;
0963:                 }*/
0964:            }
0965:
0966:            public void setNotificationService(
0967:                    NotificationService notificationService) {
0968:                this .notificationService = notificationService;
0969:            }
0970:
0971:            protected String getAccessPoint(boolean relative) {
0972:                return (relative ? "" : ServerConfigurationService
0973:                        .getAccessUrl())
0974:                        + m_relativeAccessPoint;
0975:            }
0976:
0977:            public void postNewSyllabus(SyllabusData data) {
0978:                BaseResourceEdit bre = new BaseResourceEdit(data
0979:                        .getSyllabusId().toString(), data);
0980:
0981:                addLiveSyllabusProperties(bre);
0982:
0983:                bre.setEvent(EVENT_SYLLABUS_POST_NEW);
0984:
0985:                String emailNotify = data.getEmailNotification();
0986:
0987:                int priority;
0988:
0989:                if (emailNotify.equalsIgnoreCase("none")) {
0990:                    priority = NotificationService.NOTI_NONE;
0991:                } else if (emailNotify.equalsIgnoreCase("high")) {
0992:                    priority = NotificationService.NOTI_REQUIRED;
0993:                } else if (emailNotify.equalsIgnoreCase("low")) {
0994:                    priority = NotificationService.NOTI_OPTIONAL;
0995:                } else {
0996:                    priority = NotificationService.NOTI_NONE;
0997:                }
0998:
0999:                Event event = EventTrackingService.newEvent(bre.getEvent(), bre
1000:                        .getReference(), true, priority);
1001:
1002:                EventTrackingService.post(event);
1003:            }
1004:
1005:            public class BaseResourceEdit implements  Entity, Edit {
1006:                protected String m_id = null;
1007:
1008:                protected String m_event = null;
1009:
1010:                protected boolean m_active = false;
1011:
1012:                protected boolean m_isRemoved = false;
1013:
1014:                protected boolean m_bodyUpdated = false;
1015:
1016:                protected ResourcePropertiesEdit m_properties = null;
1017:
1018:                protected String m_reference = null;
1019:
1020:                protected SyllabusData m_data = null;
1021:
1022:                public BaseResourceEdit(String id, SyllabusData data) {
1023:                    Placement placement = ToolManager.getCurrentPlacement();
1024:                    String currentSiteId = placement.getContext();
1025:
1026:                    m_id = id;
1027:
1028:                    m_data = data;
1029:
1030:                    m_reference = Entity.SEPARATOR + currentSiteId
1031:                            + Entity.SEPARATOR + m_id;
1032:
1033:                    m_properties = new BaseResourcePropertiesEdit();
1034:
1035:                    m_properties.addProperty(
1036:                            ResourceProperties.PROP_DISPLAY_NAME, data
1037:                                    .getTitle());
1038:                }
1039:
1040:                //permission convert
1041:                public BaseResourceEdit(String id, SyllabusData data,
1042:                        String siteId) {
1043:                    m_id = id;
1044:
1045:                    m_data = data;
1046:
1047:                    m_reference = Entity.SEPARATOR + siteId + Entity.SEPARATOR
1048:                            + m_id;
1049:
1050:                    m_properties = new BaseResourcePropertiesEdit();
1051:
1052:                    m_properties.addProperty(
1053:                            ResourceProperties.PROP_DISPLAY_NAME, data
1054:                                    .getTitle());
1055:                }
1056:
1057:                //permission convert
1058:                public BaseResourceEdit(String siteId) {
1059:                    m_id = null;
1060:
1061:                    m_data = null;
1062:
1063:                    m_reference = Entity.SEPARATOR + siteId;
1064:
1065:                    m_properties = new BaseResourcePropertiesEdit();
1066:
1067:                    m_properties.addProperty(
1068:                            ResourceProperties.PROP_DISPLAY_NAME, "");
1069:                }
1070:
1071:                public String getUrl() {
1072:                    return getAccessPoint(false) + "/" + m_id;
1073:                }
1074:
1075:                public String getReference() {
1076:                    String this String = getAccessPoint(true) + m_reference;
1077:                    return getAccessPoint(true) + m_reference;
1078:                }
1079:
1080:                /**
1081:                 * @inheritDoc
1082:                 */
1083:                public String getReference(String rootProperty) {
1084:                    return getReference();
1085:                }
1086:
1087:                /**
1088:                 * @inheritDoc
1089:                 */
1090:                public String getUrl(String rootProperty) {
1091:                    return getUrl();
1092:                }
1093:
1094:                public String getId() {
1095:                    return m_id;
1096:                }
1097:
1098:                public ResourceProperties getProperties() {
1099:                    return m_properties;
1100:                }
1101:
1102:                public Element toXml(Document doc, Stack stack) {
1103:                    Element syllabus = doc.createElement("syllabus");
1104:
1105:                    if (stack.isEmpty()) {
1106:                        doc.appendChild(syllabus);
1107:                    } else {
1108:                        ((Element) stack.peek()).appendChild(syllabus);
1109:                    }
1110:
1111:                    stack.push(syllabus);
1112:
1113:                    syllabus.setAttribute("id", m_id);
1114:                    syllabus.setAttribute("subject", m_data.getTitle());
1115:                    syllabus.setAttribute("body", m_data.getAsset());
1116:
1117:                    m_properties.toXml(doc, stack);
1118:
1119:                    stack.pop();
1120:
1121:                    return syllabus;
1122:
1123:                }
1124:
1125:                public boolean isActiveEdit() {
1126:                    return m_active;
1127:                }
1128:
1129:                public ResourcePropertiesEdit getPropertiesEdit() {
1130:                    return m_properties;
1131:                }
1132:
1133:                protected void closeEdit() {
1134:                    m_active = false;
1135:                }
1136:
1137:                protected void activate() {
1138:                    m_active = true;
1139:                }
1140:
1141:                protected String getEvent() {
1142:                    return m_event;
1143:                }
1144:
1145:                protected void setEvent(String event) {
1146:                    m_event = event;
1147:                }
1148:            }
1149:
1150:            protected void addLiveSyllabusProperties(BaseResourceEdit r) {
1151:                ResourcePropertiesEdit p = r.getPropertiesEdit();
1152:
1153:                String current = SessionManager.getCurrentSessionUserId();
1154:                p.addProperty(ResourceProperties.PROP_CREATOR, current);
1155:                p.addProperty(ResourceProperties.PROP_MODIFIED_BY, current);
1156:
1157:                String now = TimeService.newTime().toString();
1158:                p.addProperty(ResourceProperties.PROP_CREATION_DATE, now);
1159:                p.addProperty(ResourceProperties.PROP_MODIFIED_DATE, now);
1160:
1161:                p.addProperty(ResourceProperties.PROP_IS_COLLECTION, "false");
1162:            }
1163:
1164:            public void postChangeSyllabus(SyllabusData data) {
1165:                BaseResourceEdit bre = new BaseResourceEdit(data
1166:                        .getSyllabusId().toString(), data);
1167:
1168:                addLiveSyllabusProperties(bre);
1169:
1170:                bre.setEvent(EVENT_SYLLABUS_POST_CHANGE);
1171:
1172:                String emailNotify = data.getEmailNotification();
1173:
1174:                int priority;
1175:
1176:                if (emailNotify.equalsIgnoreCase("none")) {
1177:                    priority = NotificationService.NOTI_NONE;
1178:                } else if (emailNotify.equalsIgnoreCase("high")) {
1179:                    priority = NotificationService.NOTI_REQUIRED;
1180:                } else if (emailNotify.equalsIgnoreCase("low")) {
1181:                    priority = NotificationService.NOTI_OPTIONAL;
1182:                } else {
1183:                    priority = NotificationService.NOTI_NONE;
1184:                }
1185:
1186:                Event event = EventTrackingService.newEvent(bre.getEvent(), bre
1187:                        .getReference(), true, priority);
1188:
1189:                EventTrackingService.post(event);
1190:            }
1191:
1192:            public void deletePostedSyllabus(SyllabusData data) {
1193:                BaseResourceEdit bre = new BaseResourceEdit(data
1194:                        .getSyllabusId().toString(), data);
1195:
1196:                addLiveSyllabusProperties(bre);
1197:
1198:                bre.setEvent(EVENT_SYLLABUS_DELETE_POST);
1199:
1200:                String emailNotify = data.getEmailNotification();
1201:
1202:                int priority;
1203:
1204:                //for adding more logging info and not send out email notification
1205:                //    if(emailNotify.equalsIgnoreCase("none"))
1206:                //    {
1207:                //      priority = NotificationService.NOTI_NONE;
1208:                //    }
1209:                //    else if(emailNotify.equalsIgnoreCase("high"))
1210:                //    {
1211:                //      priority = NotificationService.NOTI_REQUIRED;
1212:                //    }
1213:                //    else if(emailNotify.equalsIgnoreCase("low"))
1214:                //    {
1215:                //      priority = NotificationService.NOTI_OPTIONAL;
1216:                //    }
1217:                //    else
1218:                //    {
1219:                //      priority = NotificationService.NOTI_NONE;
1220:                //    }
1221:                priority = NotificationService.NOTI_NONE;
1222:
1223:                Event event = EventTrackingService.newEvent(bre.getEvent(), bre
1224:                        .getReference(), true, priority);
1225:
1226:                EventTrackingService.post(event);
1227:            }
1228:
1229:            public String trimToNull(String value) {
1230:                if (value == null)
1231:                    return null;
1232:                value = value.trim();
1233:                if (value.length() == 0)
1234:                    return null;
1235:                return value;
1236:
1237:            }
1238:
1239:            public List getMessages(String id) {
1240:                ArrayList list = new ArrayList();
1241:
1242:                SyllabusItem syllabusItem = syllabusManager
1243:                        .getSyllabusItemByContextId(id);
1244:                if (syllabusItem == null) {
1245:                    return null;
1246:                }
1247:                Set listSet = syllabusManager
1248:                        .getSyllabiForSyllabusItem(syllabusItem);
1249:                Iterator iter = listSet.iterator();
1250:                while (iter.hasNext()) {
1251:                    SyllabusData sd = (SyllabusData) iter.next();
1252:                    if (sd.getView().equalsIgnoreCase("yes")
1253:                            && (sd.getStatus().equalsIgnoreCase("Posted"))) {
1254:                        ArrayList attachList = new ArrayList();
1255:                        Set attachSet = syllabusManager
1256:                                .getSyllabusAttachmentsForSyllabusData(sd);
1257:                        Iterator attachIter = attachSet.iterator();
1258:                        while (attachIter.hasNext()) {
1259:                            attachList.add((SyllabusAttachment) attachIter
1260:                                    .next());
1261:                        }
1262:
1263:                        GatewaySyllabus gs = new GatewaySyllabusImpl(sd,
1264:                                attachList);
1265:
1266:                        list.add(gs);
1267:                    }
1268:                }
1269:
1270:                return list;
1271:            }
1272:
1273:            public String[] myToolIds() {
1274:                String[] toolIds = { "sakai.syllabus" };
1275:                return toolIds;
1276:            }
1277:
1278:            public void transferCopyEntities(String fromContext,
1279:                    String toContext, List ids) {
1280:                try {
1281:                    logger
1282:                            .debug("transer copy syllbus itmes by transferCopyEntities");
1283:                    String fromPage = fromContext;
1284:                    SyllabusItem fromSyllabusItem = syllabusManager
1285:                            .getSyllabusItemByContextId(fromPage);
1286:                    if (fromSyllabusItem != null) {
1287:                        Set fromSyDataSet = syllabusManager
1288:                                .getSyllabiForSyllabusItem(fromSyllabusItem);
1289:                        if (fromSyDataSet != null && fromSyDataSet.size() > 0) {
1290:                            fromSyDataSet = syllabusManager
1291:                                    .getSyllabiForSyllabusItem(fromSyllabusItem);
1292:                            String toPage = addSyllabusToolToPage(toContext,
1293:                                    SiteService.getSite(toContext).getTitle());
1294:                            SyllabusItem toSyItem = syllabusManager
1295:                                    .getSyllabusItemByContextId(toPage);
1296:                            if (toSyItem == null) {
1297:                                toSyItem = syllabusManager.createSyllabusItem(
1298:                                        UserDirectoryService.getCurrentUser()
1299:                                                .getId(), toPage,
1300:                                        fromSyllabusItem.getRedirectURL());
1301:                            }
1302:                            Iterator fromSetIter = fromSyDataSet.iterator();
1303:                            while (fromSetIter.hasNext()) {
1304:                                SyllabusData toSyData = (SyllabusData) fromSetIter
1305:                                        .next();
1306:                                Integer positionNo = new Integer(
1307:                                        syllabusManager
1308:                                                .findLargestSyllabusPosition(
1309:                                                        toSyItem).intValue() + 1);
1310:                                SyllabusData newToSyData = syllabusManager
1311:                                        .createSyllabusDataObject(toSyData
1312:                                                .getTitle(), positionNo,
1313:                                                toSyData.getAsset(), toSyData
1314:                                                        .getView(), toSyData
1315:                                                        .getStatus(), toSyData
1316:                                                        .getEmailNotification());
1317:                                Set attachSet = syllabusManager
1318:                                        .getSyllabusAttachmentsForSyllabusData(toSyData);
1319:                                Iterator attachIter = attachSet.iterator();
1320:                                Set newAttachSet = new TreeSet();
1321:                                while (attachIter.hasNext()) {
1322:                                    SyllabusAttachment this Attach = (SyllabusAttachment) attachIter
1323:                                            .next();
1324:                                    ContentResource oldAttachment = ContentHostingService
1325:                                            .getResource(this Attach
1326:                                                    .getAttachmentId());
1327:                                    ContentResource attachment = ContentHostingService
1328:                                            .addAttachmentResource(
1329:                                                    oldAttachment
1330:                                                            .getProperties()
1331:                                                            .getProperty(
1332:                                                                    ResourceProperties.PROP_DISPLAY_NAME),
1333:                                                    ToolManager
1334:                                                            .getCurrentPlacement()
1335:                                                            .getContext(),
1336:                                                    ToolManager.getTool(
1337:                                                            "sakai.syllabus")
1338:                                                            .getTitle(),
1339:                                                    oldAttachment
1340:                                                            .getContentType(),
1341:                                                    oldAttachment.getContent(),
1342:                                                    oldAttachment
1343:                                                            .getProperties());
1344:                                    SyllabusAttachment this SyllabusAttach = syllabusManager
1345:                                            .createSyllabusAttachmentObject(
1346:                                                    attachment.getId(),
1347:                                                    attachment
1348:                                                            .getProperties()
1349:                                                            .getProperty(
1350:                                                                    ResourceProperties.PROP_DISPLAY_NAME));
1351:                                    newAttachSet.add(this SyllabusAttach);
1352:                                }
1353:                                newToSyData.setAttachments(newAttachSet);
1354:                                syllabusManager.addSyllabusToSyllabusItem(
1355:                                        toSyItem, newToSyData);
1356:                            }
1357:                        } else {
1358:                            logger
1359:                                    .debug("importResources: no data found for syllabusItem id"
1360:                                            + fromSyllabusItem
1361:                                                    .getSurrogateKey()
1362:                                                    .toString());
1363:                        }
1364:
1365:                        logger
1366:                                .debug("importResources: End importing syllabus data");
1367:                    }
1368:                } catch (Exception e) {
1369:                    e.printStackTrace();
1370:                    logger.error(e.getMessage(), e);
1371:                }
1372:            }
1373:
1374:            public void readSyllabus(SyllabusData data) {
1375:                BaseResourceEdit bre = new BaseResourceEdit(data
1376:                        .getSyllabusId().toString(), data);
1377:
1378:                addLiveSyllabusProperties(bre);
1379:
1380:                bre.setEvent(EVENT_SYLLABUS_READ);
1381:
1382:                int priority;
1383:
1384:                priority = NotificationService.NOTI_NONE;
1385:
1386:                Event event = EventTrackingService.newEvent(bre.getEvent(), bre
1387:                        .getReference(), false, priority);
1388:
1389:                EventTrackingService.post(event);
1390:            }
1391:
1392:            public void draftChangeSyllabus(SyllabusData data) {
1393:                BaseResourceEdit bre = new BaseResourceEdit(data
1394:                        .getSyllabusId().toString(), data);
1395:
1396:                addLiveSyllabusProperties(bre);
1397:
1398:                bre.setEvent(EVENT_SYLLABUS_DRAFT_CHANGE);
1399:
1400:                int priority;
1401:
1402:                priority = NotificationService.NOTI_NONE;
1403:
1404:                Event event = EventTrackingService.newEvent(bre.getEvent(), bre
1405:                        .getReference(), true, priority);
1406:
1407:                EventTrackingService.post(event);
1408:            }
1409:
1410:            public void draftNewSyllabus(SyllabusData data) {
1411:                BaseResourceEdit bre = new BaseResourceEdit(data
1412:                        .getSyllabusId().toString(), data);
1413:
1414:                addLiveSyllabusProperties(bre);
1415:
1416:                bre.setEvent(EVENT_SYLLABUS_DRAFT_NEW);
1417:
1418:                int priority;
1419:
1420:                priority = NotificationService.NOTI_NONE;
1421:
1422:                Event event = EventTrackingService.newEvent(bre.getEvent(), bre
1423:                        .getReference(), true, priority);
1424:
1425:                EventTrackingService.post(event);
1426:            }
1427:
1428:            //permission convert
1429:            public String getEntityReference(SyllabusData sd, String this SiteId) {
1430:                BaseResourceEdit bre = new BaseResourceEdit(sd.getSyllabusId()
1431:                        .toString(), sd, this SiteId);
1432:                return bre.getReference();
1433:            }
1434:
1435:            //permission convert
1436:            public String getSyllabusApplicationSiteReference(String this SiteId) {
1437:                BaseResourceEdit bre = new BaseResourceEdit(this SiteId);
1438:                return bre.getReference();
1439:            }
1440:
1441:            //permission convert
1442:            public boolean checkPermission(String lock, String reference) {
1443:                return SecurityService.unlock(lock, reference);
1444:            }
1445:
1446:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.