RM-722 (REST API - Add and remove authorities from roles)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@50274 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2013-05-22 15:36:44 +00:00
parent b82d57d75d
commit 615afda2ff
13 changed files with 782 additions and 329 deletions

View File

@@ -0,0 +1,99 @@
/*
* Copyright (C) 2005-2013 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.web.scripts.groups;
import java.util.Map;
import org.alfresco.module.org_alfresco_module_rm.script.admin.RoleDeclarativeWebScript;
import org.alfresco.service.cmr.repository.NodeRef;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.tuckey.web.filters.urlrewrite.utils.StringUtils;
/**
* Abstract class for adding/removing a user/group to/from a role
* This class contains the common methods needed in the sub classes.
*
* @author Tuna Aksoy
* @since 2.1
*/
public class RmChildrenAbstract extends RoleDeclarativeWebScript
{
/** Constants for the url parameters */
private static final String ROLE_ID = "roleId";
private static final String AUTHORITY_NAME = "authorityName";
/**
* Util method for getting the nodeRef from the request
*
* @param req The webscript request
* @return The nodeRef passed in the request
*/
protected NodeRef getFilePlan(WebScriptRequest req)
{
NodeRef filePlan = super.getFilePlan(req);
if (filePlan == null)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "No filePlan was provided on the URL.");
}
return filePlan;
}
/**
* Util method for getting the roleId from the request
*
* @param req The webscript request
* @return The role id passed in the request
*/
protected String getRoleId(WebScriptRequest req)
{
return getParamValue(req, ROLE_ID);
}
/**
* Util method for getting the authorityName from the request
*
* @param req The webscript request
* @return The authorityName passed in the request
*/
protected String getAuthorityName(WebScriptRequest req)
{
return getParamValue(req, AUTHORITY_NAME);
}
/**
* Helper method to get the value of parameter from the request
*
* @param req The webscript request
* @param param The name of the parameter for which the value is requested
* @return The value for the requested parameter
*/
private String getParamValue(WebScriptRequest req, String param)
{
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String authorityName = templateVars.get(param);
if (StringUtils.isBlank(authorityName))
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "No '" + param + "' was provided on the URL.");
}
return authorityName;
}
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2005-2013 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.web.scripts.groups;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.cmr.repository.NodeRef;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Webscript for removing a user or a group from a role
*
* @author Tuna Aksoy
* @since 2.1
*/
public class RmChildrenDelete extends RmChildrenAbstract
{
/**
* @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest,
* org.springframework.extensions.webscripts.Status,
* org.springframework.extensions.webscripts.Cache)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
NodeRef filePlan = getFilePlan(req);
String roleId = getRoleId(req);
String authorityName = getAuthorityName(req);
filePlanRoleService.unassignRoleFromAuthority(filePlan, roleId, authorityName);
return new HashMap<String, Object>();
}
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2005-2013 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.web.scripts.groups;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.cmr.repository.NodeRef;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Webscript for adding a user or a group to a role
*
* @author Tuna Aksoy
* @since 2.1
*/
public class RmChildrenPost extends RmChildrenAbstract
{
/**
* @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest,
* org.springframework.extensions.webscripts.Status,
* org.springframework.extensions.webscripts.Cache)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
NodeRef filePlan = getFilePlan(req);
String roleId = getRoleId(req);
String authorityName = getAuthorityName(req);
filePlanRoleService.assignRoleToAuthority(filePlan, roleId, authorityName);
return new HashMap<String, Object>();
}
}