Added S(hould)s for Rules/Actions REST API first iteration. GET actiondef, GET conditiondef, DELETE Rules, DELETE Rule

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@11302 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Glen Johnson
2008-10-10 14:49:10 +00:00
parent 7740f5af84
commit d7f3b7cc7d
12 changed files with 487 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have received a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.web.scripts.rule;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.cmr.action.ActionDefinition;
import org.alfresco.service.cmr.action.ActionService;
import org.alfresco.web.scripts.DeclarativeWebScript;
import org.alfresco.web.scripts.Status;
import org.alfresco.web.scripts.WebScriptException;
import org.alfresco.web.scripts.WebScriptRequest;
/**
* Web Script to GET an action definition given its name
*
* @author glen johnson at alfresco dot com
*/
public class ActionDefGet extends DeclarativeWebScript
{
// model property keys
private static final String MODEL_PROP_KEY_ACTION_DEF = "actiondef";
// private constants
private static final String REQ_PARAM_ACTION_DEF_NAME = "actionDefinitionName";
// properties for services
private ActionService actionService;
/**
* Set the actionService property.
*
* @param actionService The action service instance to set
*/
public void setActionService(ActionService actionService)
{
this.actionService = actionService;
}
/*
* (non-Javadoc)
*
* @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(
* org.alfresco.web.scripts.WebScriptRequest,
* org.alfresco.web.scripts.WebScriptResponse)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req,
Status status)
{
// initialise model to pass on for template to render
Map<String, Object> model = new HashMap<String, Object>();
// get URL parameter
String actionDefName = req.getParameter(REQ_PARAM_ACTION_DEF_NAME);
if ((actionDefName == null) || (actionDefName.length() == 0))
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
"The 'actionDefinitionName' URL parameter has not been provided in URL");
}
// get an action definition with the given action definition name
ActionDefinition actionDef = this.actionService.getActionDefinition(actionDefName);
// add objects to model for the template to render
model.put(MODEL_PROP_KEY_ACTION_DEF, actionDef);
return model;
}
}

View File

@@ -0,0 +1,93 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have received a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.web.scripts.rule;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.cmr.action.ActionConditionDefinition;
import org.alfresco.service.cmr.action.ActionService;
import org.alfresco.web.scripts.DeclarativeWebScript;
import org.alfresco.web.scripts.Status;
import org.alfresco.web.scripts.WebScriptException;
import org.alfresco.web.scripts.WebScriptRequest;
/**
* Web Script to GET a condition definition given its name
*
* @author glen johnson at alfresco dot com
*/
public class ConditionDefGet extends DeclarativeWebScript
{
// model property keys
private static final String MODEL_PROP_KEY_CONDITION_DEF = "conditiondef";
// private constants
private static final String REQ_PARAM_CONDITION_DEF_NAME = "conditionDefinitionName";
// properties for services
private ActionService actionService;
/**
* Set the actionService property.
*
* @param actionService The action service instance to set
*/
public void setActionService(ActionService actionService)
{
this.actionService = actionService;
}
/*
* (non-Javadoc)
*
* @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(
* org.alfresco.web.scripts.WebScriptRequest,
* org.alfresco.web.scripts.WebScriptResponse)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req,
Status status)
{
// initialise model to pass on for template to render
Map<String, Object> model = new HashMap<String, Object>();
// get URL parameter
String conditionDefName = req.getParameter(REQ_PARAM_CONDITION_DEF_NAME);
if ((conditionDefName == null) || (conditionDefName.length() == 0))
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
"The 'conditionDefinitionName' URL parameter has not been provided in URL");
}
// get a condition definition with the given condition definition name
ActionConditionDefinition conditionDef = this.actionService.getActionConditionDefinition(conditionDefName);
// add objects to model for the template to render
model.put(MODEL_PROP_KEY_CONDITION_DEF, conditionDef);
return model;
}
}

View File

@@ -0,0 +1,135 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have received a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.web.scripts.rule;
import java.util.Map;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.rule.Rule;
import org.alfresco.service.cmr.rule.RuleService;
import org.alfresco.web.scripts.DeclarativeWebScript;
import org.alfresco.web.scripts.Status;
import org.alfresco.web.scripts.WebScriptException;
import org.alfresco.web.scripts.WebScriptRequest;
/**
* Web Script to DELETE the rule identified by the given rule node id.
*
* @author glen johnson at alfresco dot com
*/
public class RuleDelete extends DeclarativeWebScript
{
// private constants
private static final String REQ_TEMPL_VAR_STORE_TYPE = "store_type";
private static final String REQ_TEMPL_VAR_STORE_ID = "store_id";
private static final String REQ_TEMPL_VAR_RULE_NODE_ID = "rule_id";
private static final String REQ_TEMPL_VAR_RULE_OWNING_NODE_ID = "id";
// properties for services
private RuleService ruleService;
// dependencies
private RulesHelper rulesHelper;
/**
* Set the ruleService property.
*
* @param ruleService The rule service instance to set
*/
public void setRuleService(RuleService ruleService)
{
this.ruleService = ruleService;
}
/**
* Set the rules helper property
*
* @param rulesHelper the rulesHelper to set
*/
public void setRulesHelper(RulesHelper rulesHelper)
{
this.rulesHelper = rulesHelper;
}
/*
* (non-Javadoc)
*
* @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(
* org.alfresco.web.scripts.WebScriptRequest,
* org.alfresco.web.scripts.WebScriptResponse)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req,
Status status)
{
String storeType = req.getServiceMatch().getTemplateVars().get(REQ_TEMPL_VAR_STORE_TYPE);
// Handle if 'store_type' URL template token not provided
if ((storeType == null) || (storeType.length() == 0))
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
"The 'store_type' URL template token has not been provided in URL");
}
String storeId = req.getServiceMatch().getTemplateVars().get(REQ_TEMPL_VAR_STORE_ID);
// Handle if 'storeId' URL template token not provided
if ((storeId == null) || (storeId.length() == 0))
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
"The 'storeId' URL template token has not been provided in URL");
}
String ruleNodeId = req.getServiceMatch().getTemplateVars().get(REQ_TEMPL_VAR_RULE_NODE_ID);
// Handle if 'ruleNodeId' URL template token not provided
if ((ruleNodeId == null) || (ruleNodeId.length() == 0))
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
"The 'rule_id' URL template token has not been provided in URL");
}
String owningNodeId = req.getServiceMatch().getTemplateVars().get(REQ_TEMPL_VAR_RULE_OWNING_NODE_ID);
// Handle if 'owningNodeId' URL template token not provided
if ((owningNodeId == null) || (owningNodeId.length() == 0))
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
"The 'id' URL template token has not been provided in URL");
}
// create the rule's identifying node reference from the given
// URL template tokens
NodeRef ruleNodeRef = this.rulesHelper.getNodeRefFromWebScriptUrl(req, storeType, storeId, ruleNodeId);
// create the rule owning node reference from the given
// URL template tokens
NodeRef ruleOwningNodeRef = this.rulesHelper.getNodeRefFromWebScriptUrl(req, storeType, storeId, owningNodeId);
// get the rule using it's unique identifying node reference
Rule rule = this.ruleService.getRule(ruleNodeRef);
// delete rule
this.ruleService.removeRule(ruleOwningNodeRef, rule);
return null;
}
}

View File

@@ -0,0 +1,116 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have received a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.web.scripts.rule;
import java.util.Map;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.rule.RuleService;
import org.alfresco.web.scripts.DeclarativeWebScript;
import org.alfresco.web.scripts.Status;
import org.alfresco.web.scripts.WebScriptException;
import org.alfresco.web.scripts.WebScriptRequest;
/**
* Web Script to DELETE the rule collection associated with the given rule owning node.
*
* @author glen johnson at alfresco dot com
*/
public class RulesDelete extends DeclarativeWebScript
{
// private constants
private static final String REQ_TEMPL_VAR_STORE_TYPE = "store_type";
private static final String REQ_TEMPL_VAR_STORE_ID = "store_id";
private static final String REQ_TEMPL_VAR_NODE_ID = "id";
// properties for services
private RuleService ruleService;
// properties for dependencies
private RulesHelper rulesHelper;
/**
* Set the ruleService property.
*
* @param ruleService The rule service instance to set
*/
public void setRuleService(RuleService ruleService)
{
this.ruleService = ruleService;
}
/**
* @param rulesHelper the rulesHelper to set
*/
public void setRulesHelper(RulesHelper rulesHelper)
{
this.rulesHelper = rulesHelper;
}
/*
* (non-Javadoc)
*
* @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(
* org.alfresco.web.scripts.WebScriptRequest,
* org.alfresco.web.scripts.WebScriptResponse)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req,
Status status)
{
String storeType = req.getServiceMatch().getTemplateVars().get(REQ_TEMPL_VAR_STORE_TYPE);
// Handle if 'store_type' URL template token not provided
if ((storeType == null) || (storeType.length() == 0))
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
"The 'store_type' URL template token has not been provided in URL");
}
String storeId = req.getServiceMatch().getTemplateVars().get(REQ_TEMPL_VAR_STORE_ID);
// Handle if 'storeId' URL template token not provided
if ((storeId == null) || (storeId.length() == 0))
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
"The 'storeId' URL template token has not been provided in URL");
}
String nodeId = req.getServiceMatch().getTemplateVars().get(REQ_TEMPL_VAR_NODE_ID);
// Handle if 'nodeId' URL template token not provided
if ((nodeId == null) || (nodeId.length() == 0))
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
"The 'nodeId' URL template token has not been provided in URL");
}
// create the rule owning node reference from the given
// URL template tokens
NodeRef ruleOwningNodeRef = this.rulesHelper.getNodeRefFromWebScriptUrl(req, storeType, storeId, nodeId);
// delete rule collection associated with the rule owning node
this.ruleService.removeAllRules(ruleOwningNodeRef);
return null;
}
}