示例#1
0
  /*
   * (non-Javadoc)
   *
   * @see org.sakaiproject.service.legacy.entity.ResourceService#importResources(java.lang.String,
   *      java.lang.String, java.util.List)
   */
  public void importEntities(String fromSiteId, String toSiteId, List resourceIds) {
    try {
      logger.debug("importResources: Begin importing syllabus data");

      String fromPage = fromSiteId;
      SyllabusItem fromSyllabusItem = syllabusManager.getSyllabusItemByContextId(fromPage);

      if (fromSyllabusItem != null) {
        Set fromSyDataSet = syllabusManager.getSyllabiForSyllabusItem(fromSyllabusItem);

        if (fromSyDataSet != null && fromSyDataSet.size() > 0) {
          fromSyDataSet = syllabusManager.getSyllabiForSyllabusItem(fromSyllabusItem);

          String toPage = addSyllabusToolToPage(toSiteId, SiteService.getSite(toSiteId).getTitle());
          SyllabusItem toSyItem = syllabusManager.getSyllabusItemByContextId(toPage);

          if (toSyItem == null) {
            toSyItem =
                syllabusManager.createSyllabusItem(
                    UserDirectoryService.getCurrentUser().getId(),
                    toPage,
                    fromSyllabusItem.getRedirectURL());
          } else if (fromSyllabusItem.getRedirectURL() != null) {
            toSyItem.setRedirectURL(fromSyllabusItem.getRedirectURL());
            syllabusManager.saveSyllabusItem(toSyItem);
          }

          Iterator fromSetIter = fromSyDataSet.iterator();
          while (fromSetIter.hasNext()) {
            SyllabusData toSyData = (SyllabusData) fromSetIter.next();
            Integer positionNo =
                new Integer(syllabusManager.findLargestSyllabusPosition(toSyItem).intValue() + 1);

            SyllabusData newToSyData =
                syllabusManager.createSyllabusDataObject(
                    toSyData.getTitle(),
                    positionNo,
                    toSyData.getAsset(),
                    toSyData.getView(),
                    toSyData.getStatus(),
                    toSyData.getEmailNotification());

            syllabusManager.addSyllabusToSyllabusItem(toSyItem, newToSyData);
          }
        } else {
          logger.debug(
              "importResources: no data found for syllabusItem id"
                  + fromSyllabusItem.getSurrogateKey().toString());
        }
      }
      logger.debug("importResources: End importing syllabus data");
    } catch (Exception e) {
      logger.error(e.getMessage(), e);
    }
  }
示例#2
0
  public List getMessages(String id) {
    ArrayList list = new ArrayList();

    SyllabusItem syllabusItem = syllabusManager.getSyllabusItemByContextId(id);
    if (syllabusItem == null) {
      return null;
    }
    Set listSet = syllabusManager.getSyllabiForSyllabusItem(syllabusItem);
    Iterator iter = listSet.iterator();
    while (iter.hasNext()) {
      SyllabusData sd = (SyllabusData) iter.next();
      if (sd.getView().equalsIgnoreCase("yes")
          && (sd.getStatus().equalsIgnoreCase(SyllabusData.ITEM_POSTED))) {
        ArrayList attachList = new ArrayList();
        Set attachSet = syllabusManager.getSyllabusAttachmentsForSyllabusData(sd);
        Iterator attachIter = attachSet.iterator();
        while (attachIter.hasNext()) {
          attachList.add((SyllabusAttachment) attachIter.next());
        }

        GatewaySyllabus gs = new GatewaySyllabusImpl(sd, attachList);

        list.add(gs);
      }
    }

    return list;
  }
示例#3
0
  public Map<String, String> transferCopyEntitiesRefMigrator(
      String fromContext, String toContext, List<String> ids, boolean cleanup) {
    Map<String, String> transversalMap = new HashMap<String, String>();
    try {
      if (cleanup == true) {
        String toSiteId = toContext;

        SyllabusItem fromSyllabusItem = syllabusManager.getSyllabusItemByContextId(toSiteId);

        if (fromSyllabusItem != null) {
          Set fromSyDataSet = syllabusManager.getSyllabiForSyllabusItem(fromSyllabusItem);

          Iterator fromSetIter = fromSyDataSet.iterator();

          while (fromSetIter.hasNext()) {
            SyllabusData fromSyllabusData = (SyllabusData) fromSetIter.next();

            syllabusManager.removeSyllabusFromSyllabusItem(fromSyllabusItem, fromSyllabusData);
          }
        }
      }
    } catch (Exception e) {
      logger.debug("Syllabus transferCopyEntitiesRefMigrator failed" + e);
    }
    transversalMap.putAll(transferCopyEntitiesRefMigrator(fromContext, toContext, ids));

    return transversalMap;
  }
示例#4
0
  /** {@inheritDoc} */
  public void updateEntityReferences(String toContext, Map<String, String> transversalMap) {
    if (transversalMap != null && transversalMap.size() > 0) {
      Set<Entry<String, String>> entrySet = (Set<Entry<String, String>>) transversalMap.entrySet();

      try {
        String toSiteId = toContext;

        SyllabusItem fromSyllabusItem = syllabusManager.getSyllabusItemByContextId(toSiteId);

        if (fromSyllabusItem != null) {
          Set fromSyDataSet = syllabusManager.getSyllabiForSyllabusItem(fromSyllabusItem);

          Iterator fromSetIter = fromSyDataSet.iterator();

          while (fromSetIter.hasNext()) {
            SyllabusData fromSyllabusData = (SyllabusData) fromSetIter.next();

            String msgBody = fromSyllabusData.getAsset();
            StringBuffer msgBodyPreMigrate = new StringBuffer(msgBody);
            boolean updated = false;
            /*
            						Iterator<Entry<String, String>> entryItr = entrySet.iterator();
            						while(entryItr.hasNext()) {
            							Entry<String, String> entry = (Entry<String, String>) entryItr.next();
            							String fromContextRef = entry.getKey();
            							if(msgBody.contains(fromContextRef)){
            								msgBody = msgBody.replace(fromContextRef, entry.getValue());
            								updated = true;
            							}
            						}
            */
            msgBody = LinkMigrationHelper.editLinks(msgBody, "sam_pub");
            msgBody = LinkMigrationHelper.editLinks(msgBody, "/posts/");
            msgBody = LinkMigrationHelper.miagrateAllLinks(entrySet, msgBody);
            if (!msgBody.equals(msgBodyPreMigrate.toString())) {

              //						if(updated){
              fromSyllabusData.setAsset(msgBody);
              syllabusManager.saveSyllabus(fromSyllabusData);
            }
          }
        }
      } catch (Exception e) {
        logger.debug("Syllabus updateEntityReferences failed" + e);
      }
    }
  }
示例#5
0
  /*
   * (non-Javadoc)
   *
   * @see org.sakaiproject.service.legacy.entity.ResourceService#archive(java.lang.String,
   *      org.w3c.dom.Document, java.util.Stack, java.lang.String,
   *      org.sakaiproject.service.legacy.entity.ReferenceVector)
   */
  public String archive(String siteId, Document doc, Stack stack, String arg3, List attachments) {

    StringBuilder results = new StringBuilder();

    try {
      int syDataCount = 0;
      results.append(
          "archiving "
              + getLabel()
              + " context "
              + Entity.SEPARATOR
              + siteId
              + Entity.SEPARATOR
              + SiteService.MAIN_CONTAINER
              + ".\n");
      // start with an element with our very own (service) name
      Element element = doc.createElement(SyllabusService.class.getName());
      ((Element) stack.peek()).appendChild(element);
      stack.push(element);
      if (siteId != null && siteId.trim().length() > 0) {
        Element siteElement = doc.createElement(SITE_ARCHIVE);
        siteElement.setAttribute(SITE_NAME, SiteService.getSite(siteId).getId());
        siteElement.setAttribute(SITE_ID, SiteService.getSite(siteId).getTitle());
        // sakai2        Iterator pageIter = getSyllabusPages(siteId);
        //        if (pageIter != null)
        //        {
        //          while (pageIter.hasNext())
        //          {
        //            String page = (String) pageIter.next();
        //            if (page != null)
        //            {
        //              Element pageElement = doc.createElement(PAGE_ARCHIVE);
        //              pageElement.setAttribute(PAGE_ID, page);
        // sakai2              pageElement.setAttribute(PAGE_NAME, SiteService.getSite(siteId)
        // sakai2                  .getPage(page).getTitle());
        // sakai2              SyllabusItem syllabusItem = syllabusManager
        //                  .getSyllabusItemByContextId(page);
        SyllabusItem syllabusItem = syllabusManager.getSyllabusItemByContextId(siteId);
        if (syllabusItem != null) {
          Element syllabus = doc.createElement(SYLLABUS);
          syllabus.setAttribute(SYLLABUS_ID, syllabusItem.getSurrogateKey().toString());
          syllabus.setAttribute(SYLLABUS_USER_ID, syllabusItem.getUserId());
          syllabus.setAttribute(SYLLABUS_CONTEXT_ID, syllabusItem.getContextId());
          syllabus.setAttribute(SYLLABUS_REDIRECT_URL, syllabusItem.getRedirectURL());

          Set syllabi = syllabusManager.getSyllabiForSyllabusItem(syllabusItem);

          if (syllabi != null && !syllabi.isEmpty()) {
            Iterator syllabiIter = syllabi.iterator();
            while (syllabiIter.hasNext()) {
              SyllabusData syllabusData = (SyllabusData) syllabiIter.next();
              if (syllabusData != null) {
                syDataCount++;
                Element syllabus_data = doc.createElement(SYLLABUS_DATA);
                syllabus_data.setAttribute(
                    SYLLABUS_DATA_ID, syllabusData.getSyllabusId().toString());
                syllabus_data.setAttribute(
                    SYLLABUS_DATA_POSITION, syllabusData.getPosition().toString());
                syllabus_data.setAttribute(SYLLABUS_DATA_TITLE, syllabusData.getTitle());
                syllabus_data.setAttribute(SYLLABUS_DATA_VIEW, syllabusData.getView());
                syllabus_data.setAttribute(SYLLABUS_DATA_STATUS, syllabusData.getStatus());
                syllabus_data.setAttribute(
                    SYLLABUS_DATA_EMAIL_NOTIFICATION, syllabusData.getEmailNotification());
                Element asset = doc.createElement(SYLLABUS_DATA_ASSET);

                try {
                  String encoded =
                      new String(Base64.encodeBase64(syllabusData.getAsset().getBytes()), "UTF-8");
                  asset.setAttribute("syllabus_body-html", encoded);
                } catch (Exception e) {
                  logger.warn("Encode Syllabus - " + e);
                }

                syllabus_data.appendChild(asset);
                syllabus.appendChild(syllabus_data);
              }
            }
            // sakai2                }
            //                pageElement.appendChild(syllabus);
            //              }
            //              siteElement.appendChild(pageElement);
            //            }

            // sakai2
            siteElement.appendChild(syllabus);
          }
          results.append(
              "archiving "
                  + getLabel()
                  + ": ("
                  + syDataCount
                  + ") syllabys items archived successfully.\n");
        } else {
          results.append("archiving " + getLabel() + ": empty syllabus archived.\n");
        }
        ((Element) stack.peek()).appendChild(siteElement);
        stack.push(siteElement);
      }
      stack.pop();

    } catch (DOMException e) {
      logger.error(e.getMessage(), e);
    } catch (IdUnusedException e) {
      logger.error(e.getMessage(), e);
    }
    return results.toString();
  }
示例#6
0
  public Map<String, String> transferCopyEntitiesRefMigrator(
      String fromContext, String toContext, List<String> ids) {
    Map<String, String> transversalMap = new HashMap<String, String>();

    try {
      logger.debug("transfer copy syllbus itmes by transferCopyEntitiesRefMigrator");
      String fromPage = fromContext;
      SyllabusItem fromSyllabusItem = syllabusManager.getSyllabusItemByContextId(fromPage);
      if (fromSyllabusItem != null) {
        Set fromSyDataSet = syllabusManager.getSyllabiForSyllabusItem(fromSyllabusItem);
        if ((fromSyDataSet != null && fromSyDataSet.size() > 0)
            || fromSyllabusItem.getRedirectURL() != null) {
          String toPage =
              addSyllabusToolToPage(toContext, SiteService.getSite(toContext).getTitle());
          SyllabusItem toSyItem = syllabusManager.getSyllabusItemByContextId(toPage);
          if (toSyItem == null) {
            toSyItem =
                syllabusManager.createSyllabusItem(
                    UserDirectoryService.getCurrentUser().getId(),
                    toPage,
                    fromSyllabusItem.getRedirectURL());
          } else if (fromSyllabusItem.getRedirectURL() != null) {
            toSyItem.setRedirectURL(fromSyllabusItem.getRedirectURL());
            syllabusManager.saveSyllabusItem(toSyItem);
          }

          Iterator fromSetIter = fromSyDataSet.iterator();
          while (fromSetIter.hasNext()) {
            SyllabusData toSyData = (SyllabusData) fromSetIter.next();
            Integer positionNo =
                new Integer(syllabusManager.findLargestSyllabusPosition(toSyItem).intValue() + 1);
            SyllabusData newToSyData =
                syllabusManager.createSyllabusDataObject(
                    toSyData.getTitle(),
                    positionNo,
                    toSyData.getAsset(),
                    toSyData.getView(),
                    toSyData.getStatus(),
                    toSyData.getEmailNotification());
            Set attachSet = syllabusManager.getSyllabusAttachmentsForSyllabusData(toSyData);
            Iterator attachIter = attachSet.iterator();
            Set newAttachSet = new TreeSet();
            while (attachIter.hasNext()) {
              SyllabusAttachment thisAttach = (SyllabusAttachment) attachIter.next();
              ContentResource oldAttachment =
                  contentHostingService.getResource(thisAttach.getAttachmentId());
              ContentResource attachment =
                  contentHostingService.addAttachmentResource(
                      oldAttachment
                          .getProperties()
                          .getProperty(ResourceProperties.PROP_DISPLAY_NAME),
                      toContext,
                      ToolManager.getTool("sakai.syllabus").getTitle(),
                      oldAttachment.getContentType(),
                      oldAttachment.getContent(),
                      oldAttachment.getProperties());
              SyllabusAttachment thisSyllabusAttach =
                  syllabusManager.createSyllabusAttachmentObject(
                      attachment.getId(),
                      attachment.getProperties().getProperty(ResourceProperties.PROP_DISPLAY_NAME));
              newAttachSet.add(thisSyllabusAttach);
            }
            newToSyData.setAttachments(newAttachSet);
            syllabusManager.addSyllabusToSyllabusItem(toSyItem, newToSyData);
          }
        } else {
          logger.debug(
              "importResources: no data found for syllabusItem id"
                  + fromSyllabusItem.getSurrogateKey().toString());
        }

        logger.debug("importResources: End importing syllabus data");
      }
    } catch (Exception e) {
      e.printStackTrace();
      logger.error(e.getMessage(), e);
    }

    return transversalMap;
  }