예제 #1
0
  private static void setPreferenceList(String name, Collection values) throws Exception {
    PreferencesEdit prefsEdit = null;
    String userId = M_sm.getCurrentSessionUserId();
    try {
      prefsEdit = M_ps.edit(userId);
    } catch (IdUnusedException e) {
      prefsEdit = M_ps.add(userId);
    }
    try {
      ResourcePropertiesEdit props = prefsEdit.getPropertiesEdit(PREFS_KEY);

      if (values == null) {
        props.removeProperty(name);
      } else {
        List existing = props.getPropertyList(name);
        Iterator it = values.iterator();
        while (it.hasNext()) {
          String value = (String) it.next();
          if (existing == null || !existing.contains(value))
            props.addPropertyToList(name, value.toString());
        }
      }
    } catch (Exception e) {
      if (prefsEdit != null) M_ps.cancel(prefsEdit);
      M_ps.cancel(prefsEdit);
      throw e;
    }
    M_ps.commit(prefsEdit);
  }
예제 #2
0
  public void saveMedia(String agent, String mediaLocation) {
    try {

      SecurityService.pushAdvisor(
          new SecurityAdvisor() {
            public SecurityAdvice isAllowed(String userId, String function, String reference) {
              return SecurityAdvice.ALLOWED;
            }
          });
      File media = new File(mediaLocation);
      byte[] mediaByte = getMediaStream(mediaLocation);
      String mimeType = MimeTypesLocator.getInstance().getContentType(media);

      String fullname = media.getName().trim();
      String collectionId = getPrivateCollection();
      currentItem.setImageMapSrc("/access/content" + collectionId + fullname);

      ResourcePropertiesEdit resourceProperties =
          AssessmentService.getContentHostingService().newResourceProperties();
      resourceProperties.addProperty(ResourceProperties.PROP_DISPLAY_NAME, fullname);

      AssessmentService.getContentHostingService()
          .addResource(
              collectionId + fullname,
              mimeType,
              mediaByte,
              resourceProperties,
              NotificationService.NOTI_NONE);
    } catch (Exception e) {
      log.warn(e);
    } finally {
      SecurityService.popAdvisor();
    }
  }
예제 #3
0
  /** Handle the configure context's update button */
  public void doSave(RunData data, Context context) {
    // TODO: if we do limit the initState() calls, we need to make sure we get a new one after this
    // call -ggolden

    String peid = ((JetspeedRunData) data).getJs_peid();
    SessionState state = ((JetspeedRunData) data).getPortletSessionState(peid);
    ParameterParser params = data.getParameters();
    String parentId = params.getString("parentSite");

    if (!SiteService.allowUpdateSite(parentId)) {
      addAlert(state, rb.getString("error.cannot.update"));
      return;
    }

    try {
      Site site;
      site = SiteService.getSite(getSiteId(state));
      ResourcePropertiesEdit rpe = site.getPropertiesEdit();
      rpe.addProperty("sakai:parent-id", parentId);
      SiteService.save(site);
      SessionManager.getCurrentToolSession().setAttribute(LINK_MODE, MODE_DONE);
      scheduleTopRefresh();
    } catch (Exception e) {
      addAlert(state, rb.getString("error.cannot.update"));
    }
  }
예제 #4
0
  /** Setup the velocity context and choose the template for the response. */
  public String buildMainPanelContext(
      VelocityPortlet portlet, Context context, RunData rundata, SessionState state) {
    // set the resource bundle with our strings
    context.put("tlang", rb);

    context.put("doSave", BUTTON + "doSave");
    context.put("doCancel", BUTTON + "doCancel");
    context.put("doRemove", BUTTON + "doRemove");
    try {
      Site site;
      String siteId = getSiteId(state);

      site = SiteService.getSite(siteId);
      String parentId = site.getProperties().getProperty("sakai:parent-id");
      context.put("currentSite", site);
      if (parentId != null) {
        // Make sure parent site exists before we show it.
        // If the parent site does not exist, clear the property
        try {
          Site parentSite = SiteService.getSite(parentId);
          context.put("parentId", parentId);
          context.put("parentTitle", parentSite.getTitle());
          return "sakai_link";
        } catch (Exception e) {
          addAlert(state, rb.getFormattedMessage("alert.parent.removed", new Object[] {parentId}));
          ResourcePropertiesEdit rpe = site.getPropertiesEdit();
          rpe.removeProperty("sakai:parent-id");
          SiteService.save(site);
        }
      }

      // Give the user a list of sites to select as parent
      List<Site> sites =
          SiteService.getSites(
              org.sakaiproject.site.api.SiteService.SelectionType.UPDATE,
              null,
              null,
              null,
              SortType.TITLE_ASC,
              null);

      List<Site> goodSites = new ArrayList<Site>();
      // Do not include any sites which point to us as a parent
      // Do not include ourself in the candidate list
      for (Iterator i = sites.iterator(); i.hasNext(); ) {
        Site thisSite = (Site) i.next();
        String pid = thisSite.getProperties().getProperty("sakai:parent-id");
        if (siteId.equals(pid)) continue;
        if (siteId.equals(thisSite.getId())) continue;
        goodSites.add(thisSite);
      }
      if (goodSites.size() > 0) context.put("sites", goodSites);
    } catch (Exception e) {
      addAlert(state, rb.getString("error.cannot.access"));
    }

    return "sakai_link";
  }
예제 #5
0
  public String getPrivateCollection() {
    String collectionId =
        Entity.SEPARATOR
            + "private"
            + REFERENCE_ROOT
            + Entity.SEPARATOR
            + ToolManager.getCurrentPlacement().getContext()
            + Entity.SEPARATOR;

    try {
      AssessmentService.getContentHostingService().checkCollection(collectionId);
    } catch (IdUnusedException e) {
      try {
        ResourcePropertiesEdit resourceProperties =
            AssessmentService.getContentHostingService().newResourceProperties();
        resourceProperties.addProperty(
            ResourceProperties.PROP_DISPLAY_NAME, ToolManager.getCurrentPlacement().getContext());
        // resourceProperties.addProperty(ResourceProperties.PROP_HIDDEN_WITH_ACCESSIBLE_CONTENT,
        // "true");

        ContentCollectionEdit edit =
            (ContentCollectionEdit)
                AssessmentService.getContentHostingService()
                    .addCollection(collectionId, resourceProperties);

        edit.setPublicAccess();
        AssessmentService.getContentHostingService().commitCollection(edit);
      } catch (Exception ee) {
        log.warn(ee.getMessage());
      }
    } catch (Exception e) {
      log.warn(e.getMessage());
    }

    try {
      if (
      /*!"true".equals(AssessmentService.getContentHostingService().getProperties(Entity.SEPARATOR + "private"+ Entity.SEPARATOR).get(ResourceProperties.PROP_HIDDEN_WITH_ACCESSIBLE_CONTENT)) || */ !AssessmentService
          .getContentHostingService()
          .isPubView(collectionId)) {

        ContentCollectionEdit edit =
            AssessmentService.getContentHostingService().editCollection(collectionId);
        ResourcePropertiesEdit resourceProperties = edit.getPropertiesEdit();
        // resourceProperties.addProperty(ResourceProperties.PROP_HIDDEN_WITH_ACCESSIBLE_CONTENT,
        // "true");

        edit.setPublicAccess();

        AssessmentService.getContentHostingService().commitCollection(edit);
      }
    } catch (Exception e) {
      log.warn(e.getMessage());
    }

    return collectionId + "uploads" + Entity.SEPARATOR;
  }
예제 #6
0
  @Override
  public void setDefaultPrivacyState(String userId, String visibility) {
    if (userId == null) {
      log.warn("Cannot set priavacy status for a null userId");
      return;
    }

    if (visibility == null) {
      visibility = PrivacyManager.VISIBLE;
    }

    PreferencesEdit editPref;
    try {
      editPref = preferencesService.edit(userId);

      ResourcePropertiesEdit props = editPref.getPropertiesEdit(PRIVACY_PREFS);
      props.addProperty(PrivacyManager.DEFAULT_PRIVACY_KEY, visibility);

      preferencesService.commit(editPref);
    } catch (PermissionException e) {
      log.warn(
          "You do not have the appropriate permissions to edit preferences for user: "******". "
              + e.getMessage());
    } catch (InUseException e) {
      log.warn(
          "Preferences for user: "******" are currently being edited. " + e.getMessage());
    } catch (IdUnusedException e) {
      try {
        editPref = preferencesService.add(userId);

        ResourcePropertiesEdit props = editPref.getPropertiesEdit(PRIVACY_PREFS);
        props.addProperty(PrivacyManager.DEFAULT_PRIVACY_KEY, visibility);

        preferencesService.commit(editPref);
      } catch (PermissionException e1) {
        // TODO Auto-generated catch block
        log.warn(
            "You do not have the appropriate permissions to edit preferences for user: "******". "
                + e1.getMessage());
      } catch (IdUsedException e1) {
        log.warn(
            "No preferences for user: "******" found intially, attempted to add new preferences. "
                + e1.getMessage());
      }
    }
  }
예제 #7
0
  private static void clearPreferenceList(String name) throws Exception {
    PreferencesEdit prefsEdit = null;
    try {
      prefsEdit = M_ps.edit(M_sm.getCurrentSessionUserId());
      ResourcePropertiesEdit props = prefsEdit.getPropertiesEdit(PREFS_KEY);

      props.removeProperty(name);
    } catch (Exception e) {
      M_ps.cancel(prefsEdit);
      throw e;
    }
    M_ps.commit(prefsEdit);
  }
예제 #8
0
  protected void addLiveSyllabusProperties(BaseResourceEdit r) {
    ResourcePropertiesEdit p = r.getPropertiesEdit();

    String current = SessionManager.getCurrentSessionUserId();
    p.addProperty(ResourceProperties.PROP_CREATOR, current);
    p.addProperty(ResourceProperties.PROP_MODIFIED_BY, current);

    String now = TimeService.newTime().toString();
    p.addProperty(ResourceProperties.PROP_CREATION_DATE, now);
    p.addProperty(ResourceProperties.PROP_MODIFIED_DATE, now);

    p.addProperty(ResourceProperties.PROP_IS_COLLECTION, "false");
  }
예제 #9
0
  @WebMethod
  @Path("/addSubmissionAttachment")
  @Produces("text/plain")
  @GET
  public String addSubmissionAttachment(
      @WebParam(name = "sessionId", partName = "sessionId") @QueryParam("sessionId")
          String sessionId,
      @WebParam(name = "context", partName = "context") @QueryParam("context") String context,
      @WebParam(name = "submissionId", partName = "submissionId") @QueryParam("submissionId")
          String submissionId,
      @WebParam(name = "attachmentName", partName = "attachmentName") @QueryParam("attachmentName")
          String attachmentName,
      @WebParam(name = "attachmentMimeType", partName = "attachmentMimeType")
          @QueryParam("attachmentMimeType")
          String attachmentMimeType,
      @WebParam(name = "attachmentData", partName = "attachmentData") @QueryParam("attachmentData")
          String attachmentData) {

    try {
      // establish the session
      Session s = establishSession(sessionId);
      AssignmentSubmissionEdit sub = assignmentService.editSubmission(submissionId);

      // create the attachmment
      Base64 decode = new Base64();
      // byte[] photoData = null;
      // photoData = decode.decodeToByteArray(attachmentData);
      byte[] photoData = decode.decode(attachmentData);
      LOG.info("File of size: " + photoData + " found");

      byte[] content = photoData;

      ResourcePropertiesEdit rpe = contentHostingService.newResourceProperties();
      rpe.addProperty(rpe.PROP_DISPLAY_NAME, attachmentName);

      ContentResource file =
          contentHostingService.addAttachmentResource(
              attachmentName, context, "Assignments", attachmentMimeType, content, rpe);
      LOG.info("attachment name is : " + attachmentName);
      LOG.info("file has lenght of: " + file.getContentLength());

      Reference ref = entityManager.newReference(file.getReference());
      sub.addSubmittedAttachment(ref);
      assignmentService.commitEdit(sub);
      return "Success!";
    } catch (Exception e) {
      LOG.error("WS addSubmissionAttachment(): " + e.getClass().getName() + " : " + e.getMessage());
      return e.getClass().getName() + " : " + e.getMessage();
    }
  }
예제 #10
0
  @WebMethod
  @Path("/undeleteAssignments")
  @Produces("text/plain")
  @GET
  public String undeleteAssignments(
      @WebParam(name = "sessionId", partName = "sessionId") @QueryParam("sessionId")
          String sessionId,
      @WebParam(name = "context", partName = "context") @QueryParam("context") String context) {
    try {
      // establish the session
      Session s = establishSession(sessionId);

      Iterator assingments = assignmentService.getAssignmentsForContext(context);
      while (assingments.hasNext()) {
        Assignment ass = (Assignment) assingments.next();
        ResourceProperties rp = ass.getProperties();

        try {
          String deleted = rp.getProperty(ResourceProperties.PROP_ASSIGNMENT_DELETED);

          LOG.info("Assignment " + ass.getTitle() + " deleted status: " + deleted);
          if (deleted != null) {
            AssignmentEdit ae = assignmentService.editAssignment(ass.getId());
            ResourcePropertiesEdit rpe = ae.getPropertiesEdit();
            LOG.info("undeleting" + ass.getTitle() + " for site " + context);
            rpe.removeProperty(ResourceProperties.PROP_ASSIGNMENT_DELETED);

            assignmentService.commitEdit(ae);
          }
        } catch (IdUnusedException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (PermissionException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (InUseException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    } catch (Exception e) {
      LOG.error("WS undeleteAssignments(): " + e.getClass().getName() + " : " + e.getMessage());
      return e.getClass().getName() + " : " + e.getMessage();
    }

    return "success";
  }
예제 #11
0
  /** doRemove - Clear the parent id value */
  public void doRemove(RunData data, Context context) {
    // access the portlet element id to find our state
    String peid = ((JetspeedRunData) data).getJs_peid();
    SessionState state = ((JetspeedRunData) data).getPortletSessionState(peid);

    try {
      Site site;
      site = SiteService.getSite(getSiteId(state));
      ResourcePropertiesEdit rpe = site.getPropertiesEdit();
      rpe.removeProperty("sakai:parent-id");
      SiteService.save(site);
      SessionManager.getCurrentToolSession().setAttribute(LINK_MODE, MODE_DONE);
      scheduleTopRefresh();
    } catch (Exception e) {
      addAlert(state, rb.getString("error.cannot.remove"));
    }
  }
예제 #12
0
    /**
     * Take all values from this object.
     *
     * @param user The user object to take values from.
     */
    protected void setAll(Digest digest) {
      m_id = digest.getId();

      m_properties = new BaseResourcePropertiesEdit();
      m_properties.addAll(digest.getProperties());

      m_ranges = new Hashtable();
      // %%% deep enough? -ggolden
      m_ranges.putAll(((BaseDigest) digest).m_ranges);
    }
예제 #13
0
    // permission convert
    public BaseResourceEdit(String siteId) {
      m_id = null;

      m_data = null;

      m_reference = Entity.SEPARATOR + siteId;

      m_properties = new BaseResourcePropertiesEdit();

      m_properties.addProperty(ResourceProperties.PROP_DISPLAY_NAME, "");
    }
예제 #14
0
    // permission convert
    public BaseResourceEdit(String id, SyllabusData data, String siteId) {
      m_id = id;

      m_data = data;

      m_reference = Entity.SEPARATOR + siteId + Entity.SEPARATOR + m_id;

      m_properties = new BaseResourcePropertiesEdit();

      m_properties.addProperty(ResourceProperties.PROP_DISPLAY_NAME, data.getTitle());
    }
예제 #15
0
  private static void setPreferenceString(String name, String value) throws Exception {
    PreferencesEdit prefsEdit = null;
    String userId = M_sm.getCurrentSessionUserId();
    try {
      prefsEdit = M_ps.edit(userId);
    } catch (IdUnusedException e) {
      prefsEdit = M_ps.add(userId);
    }
    try {
      ResourcePropertiesEdit props = prefsEdit.getPropertiesEdit(PREFS_KEY);

      if (value == null) {
        props.removeProperty(name);
      } else {
        props.addProperty(name, value.toString());
      }
    } catch (Exception e) {
      if (prefsEdit != null) M_ps.cancel(prefsEdit);
      throw e;
    }
    M_ps.commit(prefsEdit);
  }
예제 #16
0
    public BaseResourceEdit(String id, SyllabusData data) {
      Placement placement = ToolManager.getCurrentPlacement();
      String currentSiteId = placement.getContext();

      m_id = id;

      m_data = data;

      m_reference = Entity.SEPARATOR + currentSiteId + Entity.SEPARATOR + m_id;

      m_properties = new BaseResourcePropertiesEdit();

      m_properties.addProperty(ResourceProperties.PROP_DISPLAY_NAME, data.getTitle());
    }
예제 #17
0
    public Element toXml(Document doc, Stack stack) {
      Element syllabus = doc.createElement("syllabus");

      if (stack.isEmpty()) {
        doc.appendChild(syllabus);
      } else {
        ((Element) stack.peek()).appendChild(syllabus);
      }

      stack.push(syllabus);

      syllabus.setAttribute("id", m_id);
      syllabus.setAttribute("subject", m_data.getTitle());
      syllabus.setAttribute("body", m_data.getAsset());

      m_properties.toXml(doc, stack);

      stack.pop();

      return syllabus;
    }
예제 #18
0
  /**
   * Construct as a copy of another.
   *
   * @param other The other to copy.
   * @param site The site in which this group lives.
   * @param exact If true, we copy id - else we generate a new one.
   */
  protected BaseGroup(BaseSiteService siteService, Group other, Site site, boolean exact) {
    this.siteService = siteService;
    if (site == null) M_log.warn("BaseGroup(other, site...) created with null site");

    BaseGroup bOther = (BaseGroup) other;

    m_site = (Site) site;

    if (exact) {
      m_id = bOther.m_id;
    } else {
      m_id = IdManager.createUuid();
    }

    m_title = bOther.m_title;
    m_description = bOther.m_description;

    m_properties = new BaseResourcePropertiesEdit();
    m_properties.addAll(other.getProperties());
    ((BaseResourcePropertiesEdit) m_properties)
        .setLazy(((BaseResourceProperties) other.getProperties()).isLazy());
  }
예제 #19
0
    /** @inheritDoc */
    public Element toXml(Document doc, Stack stack) {
      Element digest = doc.createElement("digest");

      if (stack.isEmpty()) {
        doc.appendChild(digest);
      } else {
        ((Element) stack.peek()).appendChild(digest);
      }

      stack.push(digest);

      digest.setAttribute("id", getId());

      // properties
      m_properties.toXml(doc, stack);

      // for each message range
      for (Iterator it = m_ranges.entrySet().iterator(); it.hasNext(); ) {
        Map.Entry entry = (Map.Entry) it.next();

        Element messages = doc.createElement("messages");
        digest.appendChild(messages);
        messages.setAttribute("period", (String) entry.getKey());

        // for each message
        for (Iterator iMsgs = ((List) entry.getValue()).iterator(); iMsgs.hasNext(); ) {
          DigestMessage msg = (DigestMessage) iMsgs.next();

          Element message = doc.createElement("message");
          messages.appendChild(message);
          Xml.encodeAttribute(message, "subject", msg.getSubject());
          Xml.encodeAttribute(message, "body", msg.getBody());
        }
      }

      stack.pop();

      return digest;
    }