Example #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);
  }
Example #2
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";
  }
Example #3
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);
  }
Example #4
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";
  }
Example #5
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"));
    }
  }
Example #6
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);
  }