Example #1
0
  @Override
  public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>();

    // Role name
    Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    String roleParam = templateVars.get("rolename");
    if (roleParam == null) {
      throw new WebScriptException(
          Status.STATUS_NOT_FOUND, "No role name was provided on the URL.");
    }

    List<NodeRef> roots = rmService.getRecordsManagementRoots();
    NodeRef root = roots.get(0);

    // Check that the role exists
    if (rmSecurityService.existsRole(root, roleParam) == false) {
      throw new WebScriptException(
          Status.STATUS_NOT_FOUND,
          "The role " + roleParam + " does not exist on the records managment root " + root);
    }

    rmSecurityService.deleteRole(root, roleParam);

    return model;
  }
Example #2
0
  @Override
  public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>();
    JSONObject json = null;
    try {
      // Role name
      Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
      String roleParam = templateVars.get("rolename");
      if (roleParam == null) {
        throw new WebScriptException(
            Status.STATUS_NOT_FOUND, "No role name was provided on the URL.");
      }

      json = new JSONObject(new JSONTokener(req.getContent().getContent()));
      String name = json.getString("name");
      // TODO check
      String displayLabel = json.getString("displayLabel");
      // TODO check

      JSONArray capabilitiesArray = json.getJSONArray("capabilities");
      Set<Capability> capabilites = new HashSet<Capability>(capabilitiesArray.length());
      for (int i = 0; i < capabilitiesArray.length(); i++) {
        Capability capability = rmSecurityService.getCapability(capabilitiesArray.getString(i));
        capabilites.add(capability);
      }

      List<NodeRef> roots = rmService.getRecordsManagementRoots();
      NodeRef root = roots.get(0);

      // Check that the role exists
      if (rmSecurityService.existsRole(root, roleParam) == false) {
        throw new WebScriptException(
            Status.STATUS_NOT_FOUND,
            "The role " + roleParam + " does not exist on the records managment root " + root);
      }

      Role role = rmSecurityService.updateRole(root, name, displayLabel, capabilites);
      model.put("role", role);

    } catch (IOException iox) {
      throw new WebScriptException(
          Status.STATUS_BAD_REQUEST, "Could not read content from req.", iox);
    } catch (JSONException je) {
      throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from req.", je);
    }

    return model;
  }