Exemplo n.º 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);
    }
  }
Exemplo n.º 2
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();
  }
Exemplo n.º 3
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;
  }