Merge DEV/BELARUS/HEAD-2010_02_22 to HEAD

18814 : Implementation of sub-tasks SAIL-326, SAIL-327 and SAIL-329 is complete.



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@18831 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2010-02-25 03:58:32 +00:00
parent 66363a5254
commit fc172da640
27 changed files with 1050 additions and 745 deletions

View File

@@ -0,0 +1,8 @@
<webscript>
<shortname>Get Inherited Rules Collection</shortname>
<description>Gets a list of all inherited rules for a given node. The node can be specified either using a node reference or a query path.</description>
<url>/api/node/{store_type}/{store_id}/{id}/ruleset/inheritedrules?ruleType={rule_type?}</url>
<format default="json">argument</format>
<authentication>user</authentication>
<transaction allow="readonly">required</transaction>
</webscript>

View File

@@ -0,0 +1,10 @@
<#import "rule.lib.ftl" as ruleLib/>
{
"data" :
[
<#list inheritedRuleRefs as inheritedRuleRef>
<@ruleLib.ruleRefOwningSummaryJSON ruleRef=inheritedRuleRef />
<#if inheritedRuleRef_has_next>,</#if>
</#list>
]
}

View File

@@ -1,3 +1,3 @@
<#import "rule.lib.ftl" as ruleLib/> <#import "rule.lib.ftl" as ruleLib/>
<@ruleLib.ruleJSON rule=rule /> <@ruleLib.ruleRefJSON ruleRef=ruleRef />

View File

@@ -40,7 +40,7 @@
<@parameterValuesJSON parameterValues=actionCondition.parameterValues /> <@parameterValuesJSON parameterValues=actionCondition.parameterValues />
}, },
</#if> </#if>
"url" : "${"/api/node/" + storeType + "/" + storeId + "/" + id + "/ruleset/rules/" + rule.nodeRef.id + "/action/conditions/" + actionCondition.id}" "url" : "${"/api/node/" + ruleRef.owningFileInfo.nodeRef.storeRef.protocol + "/" + ruleRef.owningFileInfo.nodeRef.storeRef.identifier + "/" + ruleRef.owningFileInfo.nodeRef.id + "/ruleset/rules/" + ruleRef.rule.nodeRef.id + "/action/conditions/" + actionCondition.id}"
}<#if (actionCondition_has_next)>,</#if> }<#if (actionCondition_has_next)>,</#if>
</#list> </#list>
], ],
@@ -48,42 +48,68 @@
<#if action.compensatingAction??> <#if action.compensatingAction??>
"compensatingAction" : <@actionJSON action=action.compensatingAction />, "compensatingAction" : <@actionJSON action=action.compensatingAction />,
</#if> </#if>
"url" : "${"/api/node/" + storeType + "/" + storeId + "/" + id + "/ruleset/rules/" + rule.nodeRef.id + "/action/actions/" + action.id}" "url" : "${"/api/node/" + ruleRef.owningFileInfo.nodeRef.storeRef.protocol + "/" + ruleRef.owningFileInfo.nodeRef.storeRef.identifier + "/" + ruleRef.owningFileInfo.nodeRef.id + "/ruleset/rules/" + ruleRef.rule.nodeRef.id + "/action/actions/" + action.id}"
} }
</#escape> </#escape>
</#macro> </#macro>
<#-- renders a complete rule object --> <#-- renders a complete rule object -->
<#macro ruleJSON rule> <#macro ruleRefJSON ruleRef>
<#escape x as jsonUtils.encodeJSONString(x)> <#escape x as jsonUtils.encodeJSONString(x)>
{ {
"id" : "${rule.nodeRef.id}", "id" : "${ruleRef.rule.nodeRef.id}",
"title" : "${rule.title}", "title" : "${ruleRef.rule.title}",
<#if rule.description??> <#if ruleRef.rule.description??>
"description" : "${rule.description}", "description" : "${ruleRef.rule.description}",
</#if> </#if>
"ruleType" : [<#list rule.ruleTypes as ruleType>"${ruleType}"<#if (ruleType_has_next)>, </#if></#list>], "ruleType" : [<#list ruleRef.rule.ruleTypes as ruleType>"${ruleType}"<#if (ruleType_has_next)>, </#if></#list>],
"applyToChildren" : ${rule.appliedToChildren?string}, "applyToChildren" : ${ruleRef.rule.appliedToChildren?string},
"executeAsynchronously" : ${rule.executeAsynchronously?string}, "executeAsynchronously" : ${ruleRef.rule.executeAsynchronously?string},
"disabled" : ${rule.ruleDisabled?string}, "disabled" : ${ruleRef.rule.ruleDisabled?string},
"action" : <@actionJSON action=rule.action />, "action" : <@actionJSON action=ruleRef.rule.action />,
"url" : "${"/api/node/" + storeType + "/" + storeId + "/" + id + "/ruleset/rules/" + rule.nodeRef.id}" "owningNode" :
{
"nodeRef" : "${ruleRef.owningFileInfo.nodeRef}",
"name" : "${ruleRef.owningFileInfo.name}"
},
"url" : "${"/api/node/" + ruleRef.owningFileInfo.nodeRef.storeRef.protocol + "/" + ruleRef.owningFileInfo.nodeRef.storeRef.identifier + "/" + ruleRef.owningFileInfo.nodeRef.id + "/ruleset/rules/" + ruleRef.rule.nodeRef.id}"
} }
</#escape> </#escape>
</#macro> </#macro>
<#-- renders a summary rule object --> <#-- renders a summary rule object with owning nodeRef -->
<#macro rulesummaryJSON rule> <#macro ruleRefOwningSummaryJSON ruleRef>
<#escape x as jsonUtils.encodeJSONString(x)> <#escape x as jsonUtils.encodeJSONString(x)>
{ {
"id" : "${rule.nodeRef.id}", "id" : "${ruleRef.rule.nodeRef.id}",
"title" : "${rule.title}", "title" : "${ruleRef.rule.title}",
<#if rule.description??> <#if ruleRef.rule.description??>
"description" : "${rule.description}", "description" : "${ruleRef.rule.description}",
</#if> </#if>
"ruleType" : [<#list rule.ruleTypes as ruleType>"${ruleType}"<#if (ruleType_has_next)>, </#if></#list>], "ruleType" : [<#list ruleRef.rule.ruleTypes as ruleType>"${ruleType}"<#if (ruleType_has_next)>, </#if></#list>],
"disabled" : ${rule.ruleDisabled?string}, "disabled" : ${ruleRef.rule.ruleDisabled?string},
"url" : "${"/api/node/" + storeType + "/" + storeId + "/" + id + "/ruleset/rules/" + rule.nodeRef.id}" "owningNode" :
{
"nodeRef" : "${ruleRef.owningFileInfo.nodeRef}",
"name" : "${ruleRef.owningFileInfo.name}"
},
"url" : "${"/api/node/" + ruleRef.owningFileInfo.nodeRef.storeRef.protocol + "/" + ruleRef.owningFileInfo.nodeRef.storeRef.identifier + "/" + ruleRef.owningFileInfo.nodeRef.id + "/ruleset/rules/" + ruleRef.rule.nodeRef.id}"
}
</#escape>
</#macro>
<#-- renders a summary rule object without owning nodeRef -->
<#macro ruleRefSummaryJSON ruleRef>
<#escape x as jsonUtils.encodeJSONString(x)>
{
"id" : "${ruleRef.rule.nodeRef.id}",
"title" : "${ruleRef.rule.title}",
<#if ruleRef.rule.description??>
"description" : "${ruleRef.rule.description}",
</#if>
"ruleType" : [<#list ruleRef.rule.ruleTypes as ruleType>"${ruleType}"<#if (ruleType_has_next)>, </#if></#list>],
"disabled" : ${ruleRef.rule.ruleDisabled?string},
"url" : "${"/api/node/" + ruleRef.owningFileInfo.nodeRef.storeRef.protocol + "/" + ruleRef.owningFileInfo.nodeRef.storeRef.identifier + "/" + ruleRef.owningFileInfo.nodeRef.id + "/ruleset/rules/" + ruleRef.rule.nodeRef.id}"
} }
</#escape> </#escape>
</#macro> </#macro>
@@ -97,8 +123,14 @@
${val?string} ${val?string}
<#elseif val?is_date == true> <#elseif val?is_date == true>
"${val?string("EEE MMM dd HH:mm:ss zzz yyyy")}" "${val?string("EEE MMM dd HH:mm:ss zzz yyyy")}"
<#elseif val?is_sequence>
[
<#list val as element>
"${jsonUtils.encodeJSONString(element?string)}"<#if (element_has_next)>,</#if>
</#list>
]
<#else> <#else>
"${jsonUtils.encodeJSONString(val?string)}" "${jsonUtils.encodeJSONString(shortQName(val?string))}"
</#if> </#if>
<#if (parameterValue_has_next)>,</#if> <#if (parameterValue_has_next)>,</#if>
</#list> </#list>

View File

@@ -2,5 +2,5 @@
{ {
"data" : "data" :
<@ruleLib.rulesummaryJSON rule=rule /> <@ruleLib.ruleRefSummaryJSON ruleRef=ruleRef />
} }

View File

@@ -1,3 +1,3 @@
<#import "rule.lib.ftl" as ruleLib/> <#import "rule.lib.ftl" as ruleLib/>
<@ruleLib.ruleJSON rule=rule /> <@ruleLib.ruleRefJSON ruleRef=ruleRef />

View File

@@ -1,6 +1,6 @@
<webscript> <webscript>
<shortname>Get Rules Collection</shortname> <shortname>Get Rules Collection</shortname>
<description>Gets a list of all the rules for a given node. The node can be specified either using a node reference or a query path.</description> <description>Gets a list of all owned rules for a given node. The node can be specified either using a node reference or a query path.</description>
<url>/api/node/{store_type}/{store_id}/{id}/ruleset/rules?ruleType={rule_type?}</url> <url>/api/node/{store_type}/{store_id}/{id}/ruleset/rules?ruleType={rule_type?}</url>
<format default="json">argument</format> <format default="json">argument</format>
<authentication>user</authentication> <authentication>user</authentication>

View File

@@ -2,9 +2,9 @@
{ {
"data" : "data" :
[ [
<#list rules as rule> <#list ruleRefs as ruleRef>
<@ruleLib.rulesummaryJSON rule=rule /> <@ruleLib.ruleRefOwningSummaryJSON ruleRef=ruleRef />
<#if rule_has_next>,</#if> <#if ruleRef_has_next>,</#if>
</#list> </#list>
] ]
} }

View File

@@ -7,16 +7,8 @@
"rules" : "rules" :
[ [
<#list ruleset.rules as ruleRef> <#list ruleset.rules as ruleRef>
{ <@ruleLib.ruleRefOwningSummaryJSON ruleRef=ruleRef />
"id" : "${ruleRef.rule.nodeRef.id}", <#if ruleRef_has_next>,</#if>
"title" : "${ruleRef.rule.title}",
<#if ruleRef.rule.description??>
"description" : "${ruleRef.rule.description}",
</#if>
"ruleType" : [<#list ruleRef.rule.ruleTypes as ruleType>"${ruleType}"<#if (ruleType_has_next)>, </#if></#list>],
"disabled" : ${ruleRef.rule.ruleDisabled?string},
"url" : "${"/api/node/" + ruleRef.owningNodeRef.storeRef.protocol + "/" + ruleRef.owningNodeRef.storeRef.identifier + "/" + ruleRef.owningNodeRef.id + "/ruleset/rules/" + ruleRef.rule.nodeRef.id}"
}<#if ruleRef_has_next>,</#if>
</#list> </#list>
], ],
</#if> </#if>
@@ -24,27 +16,19 @@
"inheritedRules" : "inheritedRules" :
[ [
<#list ruleset.inheritedRules as inheritedRuleRef> <#list ruleset.inheritedRules as inheritedRuleRef>
{ <@ruleLib.ruleRefOwningSummaryJSON ruleRef=inheritedRuleRef />
"id" : "${inheritedRuleRef.rule.nodeRef.id}", <#if inheritedRuleRef_has_next>,</#if>
"title" : "${inheritedRuleRef.rule.title}",
<#if inheritedRuleRef.rule.description??>
"description" : "${inheritedRuleRef.rule.description}",
</#if>
"ruleType" : [<#list inheritedRuleRef.rule.ruleTypes as ruleType>"${ruleType}"<#if (ruleType_has_next)>, </#if></#list>],
"disabled" : ${inheritedRuleRef.rule.ruleDisabled?string},
"url" : "${"/api/node/" + inheritedRuleRef.owningNodeRef.storeRef.protocol + "/" + inheritedRuleRef.owningNodeRef.storeRef.identifier + "/" + inheritedRuleRef.owningNodeRef.id + "/ruleset/rules/" + inheritedRuleRef.rule.nodeRef.id}"
}<#if inheritedRuleRef_has_next>,</#if>
</#list> </#list>
], ],
</#if> </#if>
<#if ruleset.linkedToRuleSet??> <#if ruleset.linkedToRuleSet??>
"linkedToRuleSet" : "${ruleset.linkedToRuleSet}", "linkedToRuleSet" : "${"/api/node/" + ruleset.linkedToRuleSet.storeRef.protocol + "/" + ruleset.linkedToRuleSet.storeRef.identifier + "/" + ruleset.linkedToRuleSet.id + "/ruleset"}",
</#if> </#if>
<#if ruleset.linkedFromRuleSets?? && ruleset.linkedFromRuleSets?size &gt; 0> <#if ruleset.linkedFromRuleSets?? && ruleset.linkedFromRuleSets?size &gt; 0>
"linkedFromRuleSets" : "linkedFromRuleSets" :
[ [
<#list ruleset.linkedFromRuleSets as linkedFromRuleSet> <#list ruleset.linkedFromRuleSets as linkedFromRuleSet>
"${linkedFromRuleSet}"<#if linkedFromRuleSet_has_next>,</#if> "${"/api/node/" + linkedFromRuleSet.storeRef.protocol + "/" + linkedFromRuleSet.storeRef.identifier + "/" + linkedFromRuleSet.id + "/ruleset"}"<#if linkedFromRuleSet_has_next>,</#if>
</#list> </#list>
], ],
</#if> </#if>

View File

@@ -597,6 +597,7 @@
<property name="ruleService" ref="RuleService"/> <property name="ruleService" ref="RuleService"/>
<property name="actionService" ref="ActionService"/> <property name="actionService" ref="ActionService"/>
<property name="dictionaryService" ref="DictionaryService"/> <property name="dictionaryService" ref="DictionaryService"/>
<property name="fileFolderService" ref="FileFolderService"/>
<property name="namespaceService" ref="NamespaceService" /> <property name="namespaceService" ref="NamespaceService" />
</bean> </bean>
@@ -626,10 +627,14 @@
<bean id="webscript.org.alfresco.repository.rule.rule.put" class="org.alfresco.repo.web.scripts.rule.RulePut" parent="abstractRuleWebScript"> <bean id="webscript.org.alfresco.repository.rule.rule.put" class="org.alfresco.repo.web.scripts.rule.RulePut" parent="abstractRuleWebScript">
</bean> </bean>
<!-- get all rules for node web script --> <!-- get all owned rules for node web script -->
<bean id="webscript.org.alfresco.repository.rule.rules.get" class="org.alfresco.repo.web.scripts.rule.RulesGet" parent="abstractRuleWebScript"> <bean id="webscript.org.alfresco.repository.rule.rules.get" class="org.alfresco.repo.web.scripts.rule.RulesGet" parent="abstractRuleWebScript">
</bean> </bean>
<!-- get all inherited rules for node web script -->
<bean id="webscript.org.alfresco.repository.rule.inheritedrules.get" class="org.alfresco.repo.web.scripts.rule.InheritedRulesGet" parent="abstractRuleWebScript">
</bean>
<!-- get ruleset for node web script --> <!-- get ruleset for node web script -->
<bean id="webscript.org.alfresco.repository.rule.ruleset.get" class="org.alfresco.repo.web.scripts.rule.RulesetGet" parent="abstractRuleWebScript"> <bean id="webscript.org.alfresco.repository.rule.ruleset.get" class="org.alfresco.repo.web.scripts.rule.RulesetGet" parent="abstractRuleWebScript">
</bean> </bean>

View File

@@ -46,6 +46,7 @@ import org.alfresco.service.cmr.action.ActionService;
import org.alfresco.service.cmr.action.ParameterDefinition; import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.repository.StoreRef;
@@ -69,19 +70,20 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
*/ */
public abstract class AbstractRuleWebScript extends DeclarativeWebScript public abstract class AbstractRuleWebScript extends DeclarativeWebScript
{ {
public static final SimpleDateFormat dateFormate = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"); public static final SimpleDateFormat dateFormate = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
protected NodeService nodeService; protected NodeService nodeService;
protected RuleService ruleService; protected RuleService ruleService;
protected DictionaryService dictionaryService; protected DictionaryService dictionaryService;
protected ActionService actionService; protected ActionService actionService;
protected FileFolderService fileFolderService;
protected NamespaceService namespaceService; protected NamespaceService namespaceService;
private static final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); private static final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
private static Map<String, QName> propertyTypes = null; private static Map<String, Map<String, QName>> propertyTypes = null;
/** /**
* Sets the node service instance * Sets the node service instance
* *
@@ -91,7 +93,7 @@ public abstract class AbstractRuleWebScript extends DeclarativeWebScript
{ {
this.nodeService = nodeService; this.nodeService = nodeService;
} }
/** /**
* Set rule service instance * Set rule service instance
* *
@@ -101,7 +103,7 @@ public abstract class AbstractRuleWebScript extends DeclarativeWebScript
{ {
this.ruleService = ruleService; this.ruleService = ruleService;
} }
/** /**
* Set dictionary service instance * Set dictionary service instance
* *
@@ -111,7 +113,7 @@ public abstract class AbstractRuleWebScript extends DeclarativeWebScript
{ {
this.dictionaryService = dictionaryService; this.dictionaryService = dictionaryService;
} }
/** /**
* Set action service instance * Set action service instance
* *
@@ -121,7 +123,17 @@ public abstract class AbstractRuleWebScript extends DeclarativeWebScript
{ {
this.actionService = actionService; this.actionService = actionService;
} }
/**
* Set file folder service instance
*
* @param fileFolderService the fileFolderService to set
*/
public void setFileFolderService(FileFolderService fileFolderService)
{
this.fileFolderService = fileFolderService;
}
/** /**
* Set namespace service instance * Set namespace service instance
* *
@@ -131,7 +143,7 @@ public abstract class AbstractRuleWebScript extends DeclarativeWebScript
{ {
this.namespaceService = namespaceService; this.namespaceService = namespaceService;
} }
/** /**
* Parses the request and providing it's valid returns the NodeRef. * Parses the request and providing it's valid returns the NodeRef.
* *
@@ -147,138 +159,210 @@ public abstract class AbstractRuleWebScript extends DeclarativeWebScript
String storeType = templateVars.get("store_type"); String storeType = templateVars.get("store_type");
String storeId = templateVars.get("store_id"); String storeId = templateVars.get("store_id");
String nodeId = templateVars.get("id"); String nodeId = templateVars.get("id");
// create the NodeRef and ensure it is valid // create the NodeRef and ensure it is valid
StoreRef storeRef = new StoreRef(storeType, storeId); StoreRef storeRef = new StoreRef(storeType, storeId);
NodeRef nodeRef = new NodeRef(storeRef, nodeId); NodeRef nodeRef = new NodeRef(storeRef, nodeId);
if (!this.nodeService.exists(nodeRef)) if (!this.nodeService.exists(nodeRef))
{ {
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find node: " + throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find node: " + nodeRef.toString());
nodeRef.toString());
} }
return nodeRef; return nodeRef;
} }
protected QName getPropertyType(String propertyName) protected QName getPropertyType(String name, boolean isAction, String propertyName)
{ {
QName result = null;
if (propertyTypes == null) if (propertyTypes == null)
{ {
// no parameter types was cached propertyTypes = new HashMap<String, Map<String, QName>>();
propertyTypes = new HashMap<String, QName>();
// get parameters for all action definitions // get parameters for all action definitions
List<ActionDefinition> actionDefinitions = actionService.getActionDefinitions(); List<ActionDefinition> actionDefinitions = actionService.getActionDefinitions();
for (ActionDefinition actionDefinition : actionDefinitions) for (ActionDefinition actionDefinition : actionDefinitions)
{ {
List<ParameterDefinition> parameterDefinitions = actionDefinition.getParameterDefinitions(); List<ParameterDefinition> parameterDefinitions = actionDefinition.getParameterDefinitions();
Map<String, QName> parameters = new HashMap<String, QName>();
for (ParameterDefinition parameterDefinition : parameterDefinitions)
{
try
{
// cache parameter
lock.writeLock().lock();
propertyTypes.put(parameterDefinition.getName(), parameterDefinition.getType());
}
finally
{
lock.writeLock().unlock();
}
}
}
// get parameters for all action condition definitions
List<ActionConditionDefinition> actionConditionDefinitions = actionService.getActionConditionDefinitions();
for (ActionConditionDefinition actionConditionDefinition : actionConditionDefinitions)
{
List<ParameterDefinition> parameterDefinitions = actionConditionDefinition.getParameterDefinitions();
for (ParameterDefinition parameterDefinition : parameterDefinitions) for (ParameterDefinition parameterDefinition : parameterDefinitions)
{ {
try String parameterName = parameterDefinition.getName();
{ QName parameterType = parameterDefinition.getType();
// cache parameter parameters.put(parameterName, parameterType);
lock.writeLock().lock(); }
propertyTypes.put(parameterDefinition.getName(), parameterDefinition.getType());
} try
finally {
{ // cache parameter
lock.writeLock().unlock(); lock.writeLock().lock();
} propertyTypes.put(actionDefinition.getName(), parameters);
}
finally
{
lock.writeLock().unlock();
}
}
// get parameters for all action condition definitions
List<ActionConditionDefinition> actionConditionDefinitions = actionService.getActionConditionDefinitions();
for (ActionConditionDefinition actionConditionDefinition : actionConditionDefinitions)
{
List<ParameterDefinition> parameterDefinitions = actionConditionDefinition.getParameterDefinitions();
Map<String, QName> parameters = new HashMap<String, QName>();
for (ParameterDefinition parameterDefinition : parameterDefinitions)
{
String parameterName = parameterDefinition.getName();
QName parameterType = parameterDefinition.getType();
parameters.put(parameterName, parameterType);
}
try
{
lock.writeLock().lock();
propertyTypes.put(actionConditionDefinition.getName(), parameters);
}
finally
{
lock.writeLock().unlock();
} }
} }
} }
QName result = null; if (propertyTypes.containsKey(name))
try
{ {
// getting cached parameter type Map<String, QName> parameters;
lock.readLock().lock(); try
result = propertyTypes.get(propertyName); {
lock.readLock().lock();
parameters = propertyTypes.get(name);
}
finally
{
lock.readLock().unlock();
}
result = parameters.get(propertyName);
return result;
} }
finally else
{ {
lock.readLock().unlock(); if (isAction)
{
ActionDefinition actionDefinition = actionService.getActionDefinition(name);
List<ParameterDefinition> parameterDefinitions = actionDefinition.getParameterDefinitions();
Map<String, QName> parameters = new HashMap<String, QName>();
for (ParameterDefinition parameterDefinition : parameterDefinitions)
{
String parameterName = parameterDefinition.getName();
QName parameterType = parameterDefinition.getType();
parameters.put(parameterName, parameterType);
if (parameterName.equals(propertyName))
{
result = parameterType;
}
}
try
{
// cache parameter
lock.writeLock().lock();
propertyTypes.put(name, parameters);
}
finally
{
lock.writeLock().unlock();
}
}
else
{
ActionConditionDefinition actionConditionDefinition = actionService.getActionConditionDefinition(name);
List<ParameterDefinition> parameterDefinitions = actionConditionDefinition.getParameterDefinitions();
Map<String, QName> parameters = new HashMap<String, QName>();
for (ParameterDefinition parameterDefinition : parameterDefinitions)
{
String parameterName = parameterDefinition.getName();
QName parameterType = parameterDefinition.getType();
parameters.put(parameterName, parameterType);
if (parameterName.equals(propertyName))
{
result = parameterType;
}
}
try
{
lock.writeLock().lock();
propertyTypes.put(name, parameters);
}
finally
{
lock.writeLock().unlock();
}
}
} }
return result; return result;
} }
protected Rule parseJsonRule(JSONObject jsonRule) throws JSONException protected Rule parseJsonRule(JSONObject jsonRule) throws JSONException
{ {
Rule result = new Rule(); Rule result = new Rule();
if (jsonRule.has("title") == false || jsonRule.getString("title").length() == 0) if (jsonRule.has("title") == false || jsonRule.getString("title").length() == 0)
{ {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Title missing when creating rule");
"Title missing when creating rule");
} }
result.setTitle(jsonRule.getString("title")); result.setTitle(jsonRule.getString("title"));
result.setDescription(jsonRule.has("description") ? jsonRule.getString("description") : ""); result.setDescription(jsonRule.has("description") ? jsonRule.getString("description") : "");
if (jsonRule.has("ruleType") == false || jsonRule.getJSONArray("ruleType").length() == 0) if (jsonRule.has("ruleType") == false || jsonRule.getJSONArray("ruleType").length() == 0)
{ {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Rule type missing when creating rule");
"Rule type missing when creating rule");
} }
JSONArray types = jsonRule.getJSONArray("ruleType"); JSONArray types = jsonRule.getJSONArray("ruleType");
List<String> ruleTypes = new ArrayList<String>(); List<String> ruleTypes = new ArrayList<String>();
for (int i = 0; i < types.length(); i++) for (int i = 0; i < types.length(); i++)
{ {
ruleTypes.add(types.getString(i)); ruleTypes.add(types.getString(i));
} }
result.setRuleTypes(ruleTypes); result.setRuleTypes(ruleTypes);
result.applyToChildren(jsonRule.has("applyToChildren") ? jsonRule.getBoolean("applyToChildren") : false); result.applyToChildren(jsonRule.has("applyToChildren") ? jsonRule.getBoolean("applyToChildren") : false);
result.setExecuteAsynchronously(jsonRule.has("executeAsynchronously") ? jsonRule.getBoolean("executeAsynchronously") : false); result.setExecuteAsynchronously(jsonRule.has("executeAsynchronously") ? jsonRule.getBoolean("executeAsynchronously") : false);
result.setRuleDisabled(jsonRule.has("disabled") ? jsonRule.getBoolean("disabled") : false); result.setRuleDisabled(jsonRule.has("disabled") ? jsonRule.getBoolean("disabled") : false);
JSONObject jsonAction = jsonRule.getJSONObject("action"); JSONObject jsonAction = jsonRule.getJSONObject("action");
// parse action object // parse action object
Action ruleAction = parseJsonAction(jsonAction); Action ruleAction = parseJsonAction(jsonAction);
result.setAction(ruleAction); result.setAction(ruleAction);
return result; return result;
} }
protected ActionImpl parseJsonAction(JSONObject jsonAction) throws JSONException protected ActionImpl parseJsonAction(JSONObject jsonAction) throws JSONException
{ {
ActionImpl result = null; ActionImpl result = null;
String actionId = jsonAction.has("id") ? jsonAction.getString("id") : GUID.generate(); String actionId = jsonAction.has("id") ? jsonAction.getString("id") : GUID.generate();
if (jsonAction.getString("actionDefinitionName").equalsIgnoreCase("composite-action")) if (jsonAction.getString("actionDefinitionName").equalsIgnoreCase("composite-action"))
{ {
result = new CompositeActionImpl(null, actionId); result = new CompositeActionImpl(null, actionId);
@@ -287,160 +371,176 @@ public abstract class AbstractRuleWebScript extends DeclarativeWebScript
{ {
result = new ActionImpl(null, actionId, jsonAction.getString("actionDefinitionName")); result = new ActionImpl(null, actionId, jsonAction.getString("actionDefinitionName"));
} }
// Post Action Queue parameter // Post Action Queue parameter
if (jsonAction.has("actionedUponNode")) if (jsonAction.has("actionedUponNode"))
{ {
NodeRef actionedUponNode = new NodeRef(jsonAction.getString("actionedUponNode")); NodeRef actionedUponNode = new NodeRef(jsonAction.getString("actionedUponNode"));
result.setNodeRef(actionedUponNode); result.setNodeRef(actionedUponNode);
} }
if (jsonAction.has("description")) if (jsonAction.has("description"))
{ {
result.setDescription(jsonAction.getString("description")); result.setDescription(jsonAction.getString("description"));
} }
if (jsonAction.has("title")) if (jsonAction.has("title"))
{ {
result.setTitle(jsonAction.getString("title")); result.setTitle(jsonAction.getString("title"));
} }
if (jsonAction.has("parameterValues")) if (jsonAction.has("parameterValues"))
{ {
JSONObject jsonParameterValues = jsonAction.getJSONObject("parameterValues"); JSONObject jsonParameterValues = jsonAction.getJSONObject("parameterValues");
result.setParameterValues(parseJsonParameterValues(jsonParameterValues)); result.setParameterValues(parseJsonParameterValues(jsonParameterValues, result.getActionDefinitionName(), true));
} }
if (jsonAction.has("executeAsync")) if (jsonAction.has("executeAsync"))
{ {
result.setExecuteAsynchronously(jsonAction.getBoolean("executeAsync")); result.setExecuteAsynchronously(jsonAction.getBoolean("executeAsync"));
} }
if (jsonAction.has("runAsUser")) if (jsonAction.has("runAsUser"))
{ {
result.setRunAsUser(jsonAction.getString("runAsUser")); result.setRunAsUser(jsonAction.getString("runAsUser"));
} }
if (jsonAction.has("actions")) if (jsonAction.has("actions"))
{ {
JSONArray jsonActions = jsonAction.getJSONArray("actions"); JSONArray jsonActions = jsonAction.getJSONArray("actions");
for (int i = 0; i < jsonActions.length(); i++) for (int i = 0; i < jsonActions.length(); i++)
{ {
JSONObject innerJsonAction = jsonActions.getJSONObject(i); JSONObject innerJsonAction = jsonActions.getJSONObject(i);
Action innerAction = parseJsonAction(innerJsonAction); Action innerAction = parseJsonAction(innerJsonAction);
// we assume that only composite-action contains actions json array, so should be no cast exception // we assume that only composite-action contains actions json array, so should be no cast exception
((CompositeActionImpl)result).addAction(innerAction); ((CompositeActionImpl) result).addAction(innerAction);
} }
} }
if (jsonAction.has("conditions")) if (jsonAction.has("conditions"))
{ {
JSONArray jsonConditions = jsonAction.getJSONArray("conditions"); JSONArray jsonConditions = jsonAction.getJSONArray("conditions");
for (int i = 0; i < jsonConditions.length(); i++) for (int i = 0; i < jsonConditions.length(); i++)
{ {
JSONObject jsonCondition = jsonConditions.getJSONObject(i); JSONObject jsonCondition = jsonConditions.getJSONObject(i);
// parse action conditions // parse action conditions
ActionCondition actionCondition = parseJsonActionCondition(jsonCondition); ActionCondition actionCondition = parseJsonActionCondition(jsonCondition);
result.getActionConditions().add(actionCondition); result.getActionConditions().add(actionCondition);
} }
} }
if (jsonAction.has("compensatingAction")) if (jsonAction.has("compensatingAction"))
{ {
Action compensatingAction = parseJsonAction(jsonAction.getJSONObject("compensatingAction")); Action compensatingAction = parseJsonAction(jsonAction.getJSONObject("compensatingAction"));
result.setCompensatingAction(compensatingAction); result.setCompensatingAction(compensatingAction);
} }
return result; return result;
} }
protected ActionConditionImpl parseJsonActionCondition(JSONObject jsonActionCondition) throws JSONException protected ActionConditionImpl parseJsonActionCondition(JSONObject jsonActionCondition) throws JSONException
{ {
String id = jsonActionCondition.has("id") ? jsonActionCondition.getString("id"): GUID.generate(); String id = jsonActionCondition.has("id") ? jsonActionCondition.getString("id") : GUID.generate();
ActionConditionImpl result = new ActionConditionImpl(id, jsonActionCondition.getString("conditionDefinitionName")); ActionConditionImpl result = new ActionConditionImpl(id, jsonActionCondition.getString("conditionDefinitionName"));
if (jsonActionCondition.has("invertCondition")) if (jsonActionCondition.has("invertCondition"))
{ {
result.setInvertCondition(jsonActionCondition.getBoolean("invertCondition")); result.setInvertCondition(jsonActionCondition.getBoolean("invertCondition"));
} }
if (jsonActionCondition.has("parameterValues")) if (jsonActionCondition.has("parameterValues"))
{ {
JSONObject jsonParameterValues = jsonActionCondition.getJSONObject("parameterValues"); JSONObject jsonParameterValues = jsonActionCondition.getJSONObject("parameterValues");
result.setParameterValues(parseJsonParameterValues(jsonParameterValues)); result.setParameterValues(parseJsonParameterValues(jsonParameterValues, result.getActionConditionDefinitionName(), false));
} }
return result; return result;
} }
protected Map<String, Serializable> parseJsonParameterValues(JSONObject jsonParameterValues) throws JSONException @SuppressWarnings("unchecked")
protected Map<String, Serializable> parseJsonParameterValues(JSONObject jsonParameterValues, String name, boolean isAction) throws JSONException
{ {
Map<String, Serializable> parameterValues = new HashMap<String, Serializable>(); Map<String, Serializable> parameterValues = new HashMap<String, Serializable>();
// get parameters names // get parameters names
JSONArray names = jsonParameterValues.names(); JSONArray names = jsonParameterValues.names();
if (names != null) if (names == null)
{ {
for (int i = 0; i < names.length(); i++) return null;
}
for (int i = 0; i < names.length(); i++)
{
String propertyName = names.getString(i);
Object propertyValue = jsonParameterValues.get(propertyName);
// get parameter repository type
QName typeQName = getPropertyType(name, isAction, propertyName);
if (typeQName == null)
{ {
String propertyName = names.getString(i); if (propertyValue.toString().equals("true") || propertyValue.toString().equals("false"))
Object propertyValue = jsonParameterValues.get(propertyName);
// get parameter repository type
QName typeQName = getPropertyType(propertyName);
if (typeQName == null)
{ {
if (propertyValue.toString().equals("true") || propertyValue.toString().equals("false")) typeQName = DataTypeDefinition.BOOLEAN;
{
typeQName = DataTypeDefinition.BOOLEAN;
}
else
{
typeQName = DataTypeDefinition.TEXT;
}
} }
else
Serializable value = null; {
typeQName = DataTypeDefinition.TEXT;
if (typeQName.equals(DataTypeDefinition.ANY)) }
}
Serializable value = null;
if (typeQName.equals(DataTypeDefinition.QNAME))
{
value = QName.createQName(propertyValue.toString(), namespaceService);
}
if (typeQName.equals(DataTypeDefinition.ANY))
{
try
{
value = dateFormate.parse(propertyValue.toString());
}
catch (ParseException e)
{ {
try try
{ {
value = dateFormate.parse(propertyValue.toString()); value = Long.valueOf(propertyValue.toString());
} }
catch (ParseException e) catch (NumberFormatException e1)
{ {
try if (propertyValue instanceof JSONArray)
{ {
value = Long.valueOf(propertyValue.toString()); value = new ArrayList<String>();
} JSONArray array = (JSONArray) propertyValue;
catch (NumberFormatException e1) for (int j = 0; j < array.length(); j++)
{ {
// do nothing ((List<String>) value).add(array.getString(j));
}
} }
} }
} }
if (value == null)
{
// convert to correct repository type
value = (Serializable)DefaultTypeConverter.INSTANCE.convert(dictionaryService.getDataType(typeQName), propertyValue);
}
parameterValues.put(propertyName, value);
} }
if (value == null)
{
// convert to correct repository type
value = (Serializable) DefaultTypeConverter.INSTANCE.convert(dictionaryService.getDataType(typeQName), propertyValue);
}
parameterValues.put(propertyName, value);
} }
return parameterValues; return parameterValues;
} }
} }

View File

@@ -43,17 +43,17 @@ public class ActionConditionDefinitionsGet extends AbstractRuleWebScript
{ {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static Log logger = LogFactory.getLog(ActionConditionDefinitionsGet.class); private static Log logger = LogFactory.getLog(ActionConditionDefinitionsGet.class);
@Override @Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{ {
Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> model = new HashMap<String, Object>();
// get all action condition definitions // get all action condition definitions
List<ActionConditionDefinition> actionconditiondefinitions = actionService.getActionConditionDefinitions(); List<ActionConditionDefinition> actionconditiondefinitions = actionService.getActionConditionDefinitions();
model.put("actionconditiondefinitions", actionconditiondefinitions); model.put("actionconditiondefinitions", actionconditiondefinitions);
return model; return model;
} }
} }

View File

@@ -46,27 +46,26 @@ public class ActionConstraintGet extends AbstractRuleWebScript
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static Log logger = LogFactory.getLog(ActionConstraintGet.class); private static Log logger = LogFactory.getLog(ActionConstraintGet.class);
@Override @Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{ {
Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> model = new HashMap<String, Object>();
// get request parameters // get request parameters
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars(); Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String name = templateVars.get("name"); String name = templateVars.get("name");
// get specified parameter constraint // get specified parameter constraint
ParameterConstraint parameterConstraint = actionService.getParameterConstraint(name); ParameterConstraint parameterConstraint = actionService.getParameterConstraint(name);
if (parameterConstraint == null) if (parameterConstraint == null)
{ {
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find parameter constraint with name: " + throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find parameter constraint with name: " + name);
name);
} }
model.put("actionConstraint", parameterConstraint); model.put("actionConstraint", parameterConstraint);
return model; return model;
} }
} }

View File

@@ -42,31 +42,30 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
*/ */
public class ActionConstraintsGet extends AbstractRuleWebScript public class ActionConstraintsGet extends AbstractRuleWebScript
{ {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static Log logger = LogFactory.getLog(ActionConstraintsGet.class); private static Log logger = LogFactory.getLog(ActionConstraintsGet.class);
@Override @Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{ {
Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> model = new HashMap<String, Object>();
// get request parameters // get request parameters
String[] names = req.getParameterValues("name"); String[] names = req.getParameterValues("name");
List<ParameterConstraint> parameterConstraints = null; List<ParameterConstraint> parameterConstraints = null;
if (names != null && names.length > 0) if (names != null && names.length > 0)
{ {
// filter is present in request // filter is present in request
parameterConstraints = new ArrayList<ParameterConstraint>(); parameterConstraints = new ArrayList<ParameterConstraint>();
// find specified parameter constraints // find specified parameter constraints
for (String name : names) for (String name : names)
{ {
ParameterConstraint parameterConstraint = actionService.getParameterConstraint(name); ParameterConstraint parameterConstraint = actionService.getParameterConstraint(name);
if (parameterConstraint != null) if (parameterConstraint != null)
{ {
parameterConstraints.add(parameterConstraint); parameterConstraints.add(parameterConstraint);
@@ -78,9 +77,9 @@ public class ActionConstraintsGet extends AbstractRuleWebScript
// no filter was provided, return all parameter constraints // no filter was provided, return all parameter constraints
parameterConstraints = actionService.getParameterConstraints(); parameterConstraints = actionService.getParameterConstraints();
} }
model.put("actionConstraints", parameterConstraints); model.put("actionConstraints", parameterConstraints);
return model; return model;
} }
} }

View File

@@ -48,12 +48,12 @@ public class ActionDefinitionsGet extends AbstractRuleWebScript
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{ {
Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> model = new HashMap<String, Object>();
// get all action definitions // get all action definitions
List<ActionDefinition> actiondefinitions = actionService.getActionDefinitions(); List<ActionDefinition> actiondefinitions = actionService.getActionDefinitions();
model.put("actiondefinitions", actiondefinitions); model.put("actiondefinitions", actiondefinitions);
return model; return model;
} }
} }

View File

@@ -48,36 +48,36 @@ public class ActionQueuePost extends AbstractRuleWebScript
{ {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static Log logger = LogFactory.getLog(ActionQueuePost.class); private static Log logger = LogFactory.getLog(ActionQueuePost.class);
public static final String STATUS = "actionExecStatus"; public static final String STATUS = "actionExecStatus";
public static final String STATUS_SUCCESS = "success"; public static final String STATUS_SUCCESS = "success";
public static final String STATUS_FAIL = "fail"; public static final String STATUS_FAIL = "fail";
public static final String STATUS_QUEUED = "queued"; public static final String STATUS_QUEUED = "queued";
@Override @Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{ {
Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> model = new HashMap<String, Object>();
// get request parameters // get request parameters
boolean async = Boolean.parseBoolean(req.getParameter("async")); boolean async = Boolean.parseBoolean(req.getParameter("async"));
ActionImpl action = null; ActionImpl action = null;
JSONObject json = null; JSONObject json = null;
try try
{ {
// read request json // read request json
json = new JSONObject(new JSONTokener(req.getContent().getContent())); json = new JSONObject(new JSONTokener(req.getContent().getContent()));
// parse request json // parse request json
action = parseJsonAction(json); action = parseJsonAction(json);
NodeRef actionedUponNode = action.getNodeRef(); NodeRef actionedUponNode = action.getNodeRef();
// clear nodeRef for action // clear nodeRef for action
action.setNodeRef(null); action.setNodeRef(null);
json.remove("actionedUponNode"); json.remove("actionedUponNode");
if (async) if (async)
{ {
model.put(STATUS, STATUS_QUEUED); model.put(STATUS, STATUS_QUEUED);
@@ -86,31 +86,29 @@ public class ActionQueuePost extends AbstractRuleWebScript
{ {
model.put(STATUS, STATUS_SUCCESS); model.put(STATUS, STATUS_SUCCESS);
} }
try try
{ {
actionService.executeAction(action, actionedUponNode, true, async); actionService.executeAction(action, actionedUponNode, true, async);
} }
catch(Throwable e) catch (Throwable e)
{ {
model.put(STATUS, STATUS_FAIL); model.put(STATUS, STATUS_FAIL);
model.put("exception", e); model.put("exception", e);
} }
model.put("actionedUponNode", actionedUponNode.toString()); model.put("actionedUponNode", actionedUponNode.toString());
model.put("action", json); model.put("action", json);
} }
catch (IOException iox) catch (IOException iox)
{ {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from req.", iox);
"Could not read content from req.", iox);
} }
catch (JSONException je) catch (JSONException je)
{ {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from req.", je);
"Could not parse JSON from req.", je);
} }
return model; return model;
} }
} }

View File

@@ -0,0 +1,87 @@
/*
* Copyright (C) 2005-2009 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 recieved 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.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.web.scripts.rule.ruleset.RuleRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.rule.Rule;
import org.alfresco.service.cmr.rule.RuleType;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* @author unknown
*
*/
public class InheritedRulesGet extends AbstractRuleWebScript
{
@SuppressWarnings("unused")
private static Log logger = LogFactory.getLog(InheritedRulesGet.class);
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
Map<String, Object> model = new HashMap<String, Object>();
// get request parameters
NodeRef nodeRef = parseRequestForNodeRef(req);
String ruleType = req.getParameter("ruleType");
RuleType type = ruleService.getRuleType(ruleType);
if (type == null)
{
ruleType = null;
}
// get all rules (including inherited) filtered by rule type
List<Rule> inheritedRules = ruleService.getRules(nodeRef, true, ruleType);
// get owned rules (excluding inherited) filtered by rule type
List<Rule> ownedRules = ruleService.getRules(nodeRef, false, ruleType);
// remove owned rules
inheritedRules.removeAll(ownedRules);
List<RuleRef> inheritedRuleRefs = new ArrayList<RuleRef>();
for (Rule rule : inheritedRules)
{
inheritedRuleRefs.add(new RuleRef(rule, fileFolderService.getFileInfo(ruleService.getOwningNodeRef(rule))));
}
model.put("inheritedRuleRefs", inheritedRuleRefs);
return model;
}
}

View File

@@ -47,23 +47,23 @@ public class RuleDelete extends AbstractRuleWebScript
{ {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static Log logger = LogFactory.getLog(RuleDelete.class); private static Log logger = LogFactory.getLog(RuleDelete.class);
@Override @Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{ {
Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> model = new HashMap<String, Object>();
NodeRef nodeRef = parseRequestForNodeRef(req); NodeRef nodeRef = parseRequestForNodeRef(req);
// get request parameters // get request parameters
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars(); Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String ruleId = templateVars.get("rule_id"); String ruleId = templateVars.get("rule_id");
Rule ruleToDelete = null; Rule ruleToDelete = null;
// get all rules for given nodeRef // get all rules for given nodeRef
List<Rule> rules = ruleService.getRules(nodeRef); List<Rule> rules = ruleService.getRules(nodeRef, false);
// filter by rule id // filter by rule id
for (Rule rule : rules) for (Rule rule : rules)
{ {
@@ -73,16 +73,15 @@ public class RuleDelete extends AbstractRuleWebScript
break; break;
} }
} }
if (ruleToDelete == null) if (ruleToDelete == null)
{ {
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find rule with id: " + throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find rule with id: " + ruleId);
ruleId);
} }
// delete rule // delete rule
ruleService.removeRule(nodeRef, ruleToDelete); ruleService.removeRule(nodeRef, ruleToDelete);
return model; return model;
} }
} }

View File

@@ -30,6 +30,7 @@ import java.util.Map;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.alfresco.repo.web.scripts.rule.ruleset.RuleRef;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.rule.Rule; import org.alfresco.service.cmr.rule.Rule;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@@ -47,23 +48,23 @@ public class RuleGet extends AbstractRuleWebScript
{ {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static Log logger = LogFactory.getLog(RuleGet.class); private static Log logger = LogFactory.getLog(RuleGet.class);
@Override @Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{ {
Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> model = new HashMap<String, Object>();
NodeRef nodeRef = parseRequestForNodeRef(req); NodeRef nodeRef = parseRequestForNodeRef(req);
// get request parameters // get request parameters
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars(); Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String ruleId = templateVars.get("rule_id"); String ruleId = templateVars.get("rule_id");
Rule ruleToReturn = null; Rule ruleToReturn = null;
// get all rules for given nodeRef // get all rules for given nodeRef
List<Rule> rules = ruleService.getRules(nodeRef); List<Rule> rules = ruleService.getRules(nodeRef);
// filter by rule id // filter by rule id
for (Rule rule : rules) for (Rule rule : rules)
{ {
@@ -73,18 +74,16 @@ public class RuleGet extends AbstractRuleWebScript
break; break;
} }
} }
if (ruleToReturn == null) if (ruleToReturn == null)
{ {
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find rule with id: " + throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find rule with id: " + ruleId);
ruleId);
} }
model.put("rule", ruleToReturn); RuleRef ruleRefToReturn = new RuleRef(ruleToReturn, fileFolderService.getFileInfo(ruleService.getOwningNodeRef(ruleToReturn)));
model.put("storeType", nodeRef.getStoreRef().getProtocol());
model.put("storeId", nodeRef.getStoreRef().getIdentifier()); model.put("ruleRef", ruleRefToReturn);
model.put("id", nodeRef.getId());
return model; return model;
} }
} }

View File

@@ -28,6 +28,7 @@ import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.alfresco.repo.web.scripts.rule.ruleset.RuleRef;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.rule.Rule; import org.alfresco.service.cmr.rule.Rule;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@@ -45,48 +46,45 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
* *
*/ */
public class RulePost extends AbstractRuleWebScript public class RulePost extends AbstractRuleWebScript
{ {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static Log logger = LogFactory.getLog(RulePost.class); private static Log logger = LogFactory.getLog(RulePost.class);
@Override @Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{ {
Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> model = new HashMap<String, Object>();
// get request parameters // get request parameters
NodeRef nodeRef = parseRequestForNodeRef(req); NodeRef nodeRef = parseRequestForNodeRef(req);
Rule rule = null; Rule rule = null;
JSONObject json = null; JSONObject json = null;
try try
{ {
// read request json // read request json
json = new JSONObject(new JSONTokener(req.getContent().getContent())); json = new JSONObject(new JSONTokener(req.getContent().getContent()));
// parse request json // parse request json
rule = parseJsonRule(json); rule = parseJsonRule(json);
// create rule // create rule
ruleService.saveRule(nodeRef, rule); ruleService.saveRule(nodeRef, rule);
model.put("rule", rule); RuleRef ruleRef = new RuleRef(rule, fileFolderService.getFileInfo(ruleService.getOwningNodeRef(rule)));
model.put("storeType", nodeRef.getStoreRef().getProtocol());
model.put("storeId", nodeRef.getStoreRef().getIdentifier()); model.put("ruleRef", ruleRef);
model.put("id", nodeRef.getId());
} }
catch (IOException iox) catch (IOException iox)
{ {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from req.", iox);
"Could not read content from req.", iox);
} }
catch (JSONException je) catch (JSONException je)
{ {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from req.", je);
"Could not parse JSON from req.", je);
} }
return model; return model;
} }
} }

View File

@@ -35,6 +35,7 @@ import javax.servlet.http.HttpServletResponse;
import org.alfresco.repo.action.ActionConditionImpl; import org.alfresco.repo.action.ActionConditionImpl;
import org.alfresco.repo.action.ActionImpl; import org.alfresco.repo.action.ActionImpl;
import org.alfresco.repo.action.CompositeActionImpl; import org.alfresco.repo.action.CompositeActionImpl;
import org.alfresco.repo.web.scripts.rule.ruleset.RuleRef;
import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionCondition; import org.alfresco.service.cmr.action.ActionCondition;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
@@ -61,20 +62,20 @@ public class RulePut extends RulePost
@Override @Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{ {
Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> model = new HashMap<String, Object>();
// get request parameters // get request parameters
NodeRef nodeRef = parseRequestForNodeRef(req); NodeRef nodeRef = parseRequestForNodeRef(req);
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars(); Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String ruleId = templateVars.get("rule_id"); String ruleId = templateVars.get("rule_id");
Rule ruleToUpdate = null; Rule ruleToUpdate = null;
// get all rules for given nodeRef // get all rules for given nodeRef
List<Rule> rules = ruleService.getRules(nodeRef); List<Rule> rules = ruleService.getRules(nodeRef);
//filter by rule id //filter by rule id
for (Rule rule : rules) for (Rule rule : rules)
{ {
@@ -84,99 +85,95 @@ public class RulePut extends RulePost
break; break;
} }
} }
if (ruleToUpdate == null) if (ruleToUpdate == null)
{ {
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find rule with id: " + throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find rule with id: " + ruleId);
ruleId);
} }
JSONObject json = null; JSONObject json = null;
try try
{ {
// read request json // read request json
json = new JSONObject(new JSONTokener(req.getContent().getContent())); json = new JSONObject(new JSONTokener(req.getContent().getContent()));
// parse request json // parse request json
updateRuleFromJSON(json, ruleToUpdate); updateRuleFromJSON(json, ruleToUpdate);
// save changes // save changes
ruleService.saveRule(nodeRef, ruleToUpdate); ruleService.saveRule(nodeRef, ruleToUpdate);
model.put("rule", ruleToUpdate); RuleRef updatedRuleRef = new RuleRef(ruleToUpdate, fileFolderService.getFileInfo(ruleService.getOwningNodeRef(ruleToUpdate)));
model.put("storeType", nodeRef.getStoreRef().getProtocol());
model.put("storeId", nodeRef.getStoreRef().getIdentifier()); model.put("ruleRef", updatedRuleRef);
model.put("id", nodeRef.getId());
} }
catch (IOException iox) catch (IOException iox)
{ {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from req.", iox);
"Could not read content from req.", iox);
} }
catch (JSONException je) catch (JSONException je)
{ {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from req.", je);
"Could not parse JSON from req.", je);
} }
return model; return model;
} }
protected void updateRuleFromJSON(JSONObject jsonRule, Rule ruleToUpdate) throws JSONException protected void updateRuleFromJSON(JSONObject jsonRule, Rule ruleToUpdate) throws JSONException
{ {
if (jsonRule.has("title")) if (jsonRule.has("title"))
{ {
ruleToUpdate.setTitle(jsonRule.getString("title")); ruleToUpdate.setTitle(jsonRule.getString("title"));
} }
if (jsonRule.has("description")) if (jsonRule.has("description"))
{ {
ruleToUpdate.setDescription(jsonRule.getString("description")); ruleToUpdate.setDescription(jsonRule.getString("description"));
} }
if (jsonRule.has("ruleType")) if (jsonRule.has("ruleType"))
{ {
JSONArray jsonTypes = jsonRule.getJSONArray("ruleType"); JSONArray jsonTypes = jsonRule.getJSONArray("ruleType");
List<String> types = new ArrayList<String>(); List<String> types = new ArrayList<String>();
for (int i = 0; i < jsonTypes.length(); i++) for (int i = 0; i < jsonTypes.length(); i++)
{ {
types.add(jsonTypes.getString(i)); types.add(jsonTypes.getString(i));
} }
ruleToUpdate.setRuleTypes(types); ruleToUpdate.setRuleTypes(types);
} }
if (jsonRule.has("applyToChildren")) if (jsonRule.has("applyToChildren"))
{ {
ruleToUpdate.applyToChildren(jsonRule.getBoolean("applyToChildren")); ruleToUpdate.applyToChildren(jsonRule.getBoolean("applyToChildren"));
} }
if (jsonRule.has("executeAsynchronously")) if (jsonRule.has("executeAsynchronously"))
{ {
ruleToUpdate.setExecuteAsynchronously(jsonRule.getBoolean("executeAsynchronously")); ruleToUpdate.setExecuteAsynchronously(jsonRule.getBoolean("executeAsynchronously"));
} }
if (jsonRule.has("disabled")) if (jsonRule.has("disabled"))
{ {
ruleToUpdate.setRuleDisabled(jsonRule.getBoolean("disabled")); ruleToUpdate.setRuleDisabled(jsonRule.getBoolean("disabled"));
} }
if (jsonRule.has("action")) if (jsonRule.has("action"))
{ {
JSONObject jsonAction = jsonRule.getJSONObject("action"); JSONObject jsonAction = jsonRule.getJSONObject("action");
// update rule action // update rule action
Action action = updateActionFromJson(jsonAction, (ActionImpl)ruleToUpdate.getAction()); Action action = updateActionFromJson(jsonAction, (ActionImpl) ruleToUpdate.getAction());
ruleToUpdate.setAction(action); ruleToUpdate.setAction(action);
} }
} }
protected Action updateActionFromJson(JSONObject jsonAction, ActionImpl actionToUpdate) throws JSONException protected Action updateActionFromJson(JSONObject jsonAction, ActionImpl actionToUpdate) throws JSONException
{ {
ActionImpl result = null; ActionImpl result = null;
if (jsonAction.has("id")) if (jsonAction.has("id"))
{ {
// update existing action // update existing action
@@ -186,82 +183,82 @@ public class RulePut extends RulePost
{ {
// create new object as id was not sent by client // create new object as id was not sent by client
result = parseJsonAction(jsonAction); result = parseJsonAction(jsonAction);
return result; return result;
} }
if (jsonAction.has("description")) if (jsonAction.has("description"))
{ {
result.setDescription(jsonAction.getString("description")); result.setDescription(jsonAction.getString("description"));
} }
if (jsonAction.has("title")) if (jsonAction.has("title"))
{ {
result.setTitle(jsonAction.getString("title")); result.setTitle(jsonAction.getString("title"));
} }
if (jsonAction.has("parameterValues")) if (jsonAction.has("parameterValues"))
{ {
JSONObject jsonParameterValues = jsonAction.getJSONObject("parameterValues"); JSONObject jsonParameterValues = jsonAction.getJSONObject("parameterValues");
result.setParameterValues(parseJsonParameterValues(jsonParameterValues)); result.setParameterValues(parseJsonParameterValues(jsonParameterValues, result.getActionDefinitionName(), true));
} }
if (jsonAction.has("executeAsync")) if (jsonAction.has("executeAsync"))
{ {
result.setExecuteAsynchronously(jsonAction.getBoolean("executeAsync")); result.setExecuteAsynchronously(jsonAction.getBoolean("executeAsync"));
} }
if (jsonAction.has("runAsUser")) if (jsonAction.has("runAsUser"))
{ {
result.setRunAsUser(jsonAction.getString("runAsUser")); result.setRunAsUser(jsonAction.getString("runAsUser"));
} }
if (jsonAction.has("actions")) if (jsonAction.has("actions"))
{ {
JSONArray jsonActions = jsonAction.getJSONArray("actions"); JSONArray jsonActions = jsonAction.getJSONArray("actions");
if (jsonActions.length() == 0) if (jsonActions.length() == 0)
{ {
// empty array was sent -> clear list // empty array was sent -> clear list
((CompositeActionImpl)result).getActions().clear(); ((CompositeActionImpl) result).getActions().clear();
} }
else else
{ {
List<Action> existingActions = ((CompositeActionImpl)result).getActions(); List<Action> existingActions = ((CompositeActionImpl) result).getActions();
List<Action> newActions = new ArrayList<Action>(); List<Action> newActions = new ArrayList<Action>();
for (int i = 0; i < jsonActions.length(); i++) for (int i = 0; i < jsonActions.length(); i++)
{ {
JSONObject innerJsonAction = jsonActions.getJSONObject(i); JSONObject innerJsonAction = jsonActions.getJSONObject(i);
if (innerJsonAction.has("id")) if (innerJsonAction.has("id"))
{ {
// update existing object // update existing object
String actionId = innerJsonAction.getString("id"); String actionId = innerJsonAction.getString("id");
Action existingAction = getAction(existingActions, actionId); Action existingAction = getAction(existingActions, actionId);
existingActions.remove(existingAction); existingActions.remove(existingAction);
Action updatedAction = updateActionFromJson(innerJsonAction, (ActionImpl)existingAction); Action updatedAction = updateActionFromJson(innerJsonAction, (ActionImpl) existingAction);
newActions.add(updatedAction); newActions.add(updatedAction);
} }
else else
{ {
//create new action as id was not sent //create new action as id was not sent
newActions.add(parseJsonAction(innerJsonAction)); newActions.add(parseJsonAction(innerJsonAction));
} }
} }
existingActions.clear(); existingActions.clear();
for (Action action : newActions) for (Action action : newActions)
{ {
existingActions.add(action); existingActions.add(action);
} }
} }
} }
if (jsonAction.has("conditions")) if (jsonAction.has("conditions"))
{ {
JSONArray jsonConditions = jsonAction.getJSONArray("conditions"); JSONArray jsonConditions = jsonAction.getJSONArray("conditions");
if (jsonConditions.length() == 0) if (jsonConditions.length() == 0)
{ {
// empty array was sent -> clear list // empty array was sent -> clear list
@@ -271,20 +268,20 @@ public class RulePut extends RulePost
{ {
List<ActionCondition> existingConditions = result.getActionConditions(); List<ActionCondition> existingConditions = result.getActionConditions();
List<ActionCondition> newConditions = new ArrayList<ActionCondition>(); List<ActionCondition> newConditions = new ArrayList<ActionCondition>();
for (int i = 0; i < jsonConditions.length(); i++) for (int i = 0; i < jsonConditions.length(); i++)
{ {
JSONObject jsonCondition = jsonConditions.getJSONObject(i); JSONObject jsonCondition = jsonConditions.getJSONObject(i);
if (jsonCondition.has("id")) if (jsonCondition.has("id"))
{ {
// update existing object // update existing object
String conditionId = jsonCondition.getString("id"); String conditionId = jsonCondition.getString("id");
ActionCondition existingCondition = getCondition(existingConditions, conditionId); ActionCondition existingCondition = getCondition(existingConditions, conditionId);
existingConditions.remove(existingCondition); existingConditions.remove(existingCondition);
ActionCondition updatedActionCondition = updateActionConditionFromJson(jsonCondition, (ActionConditionImpl)existingCondition); ActionCondition updatedActionCondition = updateActionConditionFromJson(jsonCondition, (ActionConditionImpl) existingCondition);
newConditions.add(updatedActionCondition); newConditions.add(updatedActionCondition);
} }
else else
@@ -292,31 +289,31 @@ public class RulePut extends RulePost
// create new object as id was not sent // create new object as id was not sent
newConditions.add(parseJsonActionCondition(jsonCondition)); newConditions.add(parseJsonActionCondition(jsonCondition));
} }
} }
existingConditions.clear(); existingConditions.clear();
for (ActionCondition condition : newConditions) for (ActionCondition condition : newConditions)
{ {
existingConditions.add(condition); existingConditions.add(condition);
} }
} }
} }
if (jsonAction.has("compensatingAction")) if (jsonAction.has("compensatingAction"))
{ {
JSONObject jsonCompensatingAction = jsonAction.getJSONObject("compensatingAction"); JSONObject jsonCompensatingAction = jsonAction.getJSONObject("compensatingAction");
Action compensatingAction = updateActionFromJson(jsonCompensatingAction, (ActionImpl)actionToUpdate.getCompensatingAction()); Action compensatingAction = updateActionFromJson(jsonCompensatingAction, (ActionImpl) actionToUpdate.getCompensatingAction());
actionToUpdate.setCompensatingAction(compensatingAction); actionToUpdate.setCompensatingAction(compensatingAction);
} }
return result; return result;
} }
protected ActionCondition updateActionConditionFromJson(JSONObject jsonCondition, ActionConditionImpl conditionToUpdate) throws JSONException protected ActionCondition updateActionConditionFromJson(JSONObject jsonCondition, ActionConditionImpl conditionToUpdate) throws JSONException
{ {
ActionConditionImpl result = null; ActionConditionImpl result = null;
if (jsonCondition.has("id")) if (jsonCondition.has("id"))
{ {
// update exiting object // update exiting object
@@ -328,21 +325,21 @@ public class RulePut extends RulePost
result = parseJsonActionCondition(jsonCondition); result = parseJsonActionCondition(jsonCondition);
return result; return result;
} }
if (jsonCondition.has("invertCondition")) if (jsonCondition.has("invertCondition"))
{ {
result.setInvertCondition(jsonCondition.getBoolean("invertCondition")); result.setInvertCondition(jsonCondition.getBoolean("invertCondition"));
} }
if (jsonCondition.has("parameterValues")) if (jsonCondition.has("parameterValues"))
{ {
JSONObject jsonParameterValues = jsonCondition.getJSONObject("parameterValues"); JSONObject jsonParameterValues = jsonCondition.getJSONObject("parameterValues");
result.setParameterValues(parseJsonParameterValues(jsonParameterValues)); result.setParameterValues(parseJsonParameterValues(jsonParameterValues, result.getActionConditionDefinitionName(), false));
} }
return result; return result;
} }
private Action getAction(List<Action> actions, String id) private Action getAction(List<Action> actions, String id)
{ {
Action result = null; Action result = null;
@@ -354,22 +351,22 @@ public class RulePut extends RulePost
break; break;
} }
} }
return result; return result;
} }
private ActionCondition getCondition(List<ActionCondition> conditions, String id) private ActionCondition getCondition(List<ActionCondition> conditions, String id)
{ {
ActionCondition result = null; ActionCondition result = null;
for (ActionCondition сondition : conditions) for (ActionCondition сondition : conditions)
{ {
if (сondition.getId().equalsIgnoreCase(id)) if (сondition.getId().equalsIgnoreCase(id))
{ {
result = сondition; result = сondition;
break; break;
} }
} }
return result; return result;
} }
} }

View File

@@ -44,17 +44,17 @@ public class RuleTypesGet extends AbstractRuleWebScript
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static Log logger = LogFactory.getLog(RuleTypesGet.class); private static Log logger = LogFactory.getLog(RuleTypesGet.class);
@Override @Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{ {
Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> model = new HashMap<String, Object>();
// get all rule types // get all rule types
List<RuleType> ruletypes = ruleService.getRuleTypes(); List<RuleType> ruletypes = ruleService.getRuleTypes();
model.put("ruletypes", ruletypes); model.put("ruletypes", ruletypes);
return model; return model;
} }
} }

View File

@@ -24,10 +24,12 @@
*/ */
package org.alfresco.repo.web.scripts.rule; package org.alfresco.repo.web.scripts.rule;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.alfresco.repo.web.scripts.rule.ruleset.RuleRef;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.rule.Rule; import org.alfresco.service.cmr.rule.Rule;
import org.alfresco.service.cmr.rule.RuleType; import org.alfresco.service.cmr.rule.RuleType;
@@ -45,31 +47,35 @@ public class RulesGet extends AbstractRuleWebScript
{ {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static Log logger = LogFactory.getLog(RulesGet.class); private static Log logger = LogFactory.getLog(RulesGet.class);
@Override @Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{ {
Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> model = new HashMap<String, Object>();
// get request parameters // get request parameters
NodeRef nodeRef = parseRequestForNodeRef(req); NodeRef nodeRef = parseRequestForNodeRef(req);
String ruleType = req.getParameter("ruleType"); String ruleType = req.getParameter("ruleType");
RuleType type = ruleService.getRuleType(ruleType); RuleType type = ruleService.getRuleType(ruleType);
if (type == null) if (type == null)
{ {
ruleType = null; ruleType = null;
} }
// get all rules (including inherited) filtered by rule type // get all rules (excluding inherited) filtered by rule type
List<Rule> rules = ruleService.getRules(nodeRef, true, ruleType); List<Rule> rules = ruleService.getRules(nodeRef, false, ruleType);
model.put("rules", rules); List<RuleRef> ruleRefs = new ArrayList<RuleRef>();
model.put("storeType", nodeRef.getStoreRef().getProtocol());
model.put("storeId", nodeRef.getStoreRef().getIdentifier()); for (Rule rule : rules)
model.put("id", nodeRef.getId()); {
ruleRefs.add(new RuleRef(rule, fileFolderService.getFileInfo(ruleService.getOwningNodeRef(rule))));
}
model.put("ruleRefs", ruleRefs);
return model; return model;
} }
} }

View File

@@ -51,52 +51,55 @@ public class RulesetGet extends AbstractRuleWebScript
@Override @Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{ {
Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> model = new HashMap<String, Object>();
// get request parameters // get request parameters
NodeRef nodeRef = parseRequestForNodeRef(req); NodeRef nodeRef = parseRequestForNodeRef(req);
String ruleType = req.getParameter("ruleType"); String ruleType = req.getParameter("ruleType");
RuleType type = ruleService.getRuleType(ruleType); RuleType type = ruleService.getRuleType(ruleType);
if (type == null) if (type == null)
{ {
ruleType = null; ruleType = null;
} }
RuleSet ruleset = new RuleSet(); RuleSet ruleset = new RuleSet();
// get all "owned" rules // get all "owned" rules
List<Rule> ownedRules = ruleService.getRules(nodeRef, false, ruleType); List<Rule> ownedRules = ruleService.getRules(nodeRef, false, ruleType);
// get all rules (including inherited) // get all rules (including inherited)
List<Rule> inheritedRules = ruleService.getRules(nodeRef, true, ruleType); List<Rule> inheritedRules = ruleService.getRules(nodeRef, true, ruleType);
// remove "owned" rules // remove "owned" rules
inheritedRules.removeAll(ownedRules); inheritedRules.removeAll(ownedRules);
List<RuleRef> rulesToSet = new ArrayList<RuleRef>(); List<RuleRef> rulesToSet = new ArrayList<RuleRef>();
for (Rule rule : ownedRules) for (Rule rule : ownedRules)
{ {
rulesToSet.add(new RuleRef(rule, ruleService.getOwningNodeRef(rule))); rulesToSet.add(new RuleRef(rule, fileFolderService.getFileInfo(ruleService.getOwningNodeRef(rule))));
} }
ruleset.setRules(rulesToSet); ruleset.setRules(rulesToSet);
List<RuleRef> inheritedRulesToSet = new ArrayList<RuleRef>(); List<RuleRef> inheritedRulesToSet = new ArrayList<RuleRef>();
for (Rule rule : inheritedRules) for (Rule rule : inheritedRules)
{ {
inheritedRulesToSet.add(new RuleRef(rule, ruleService.getOwningNodeRef(rule))); inheritedRulesToSet.add(new RuleRef(rule, fileFolderService.getFileInfo(ruleService.getOwningNodeRef(rule))));
} }
ruleset.setInheritedRules(inheritedRulesToSet); ruleset.setInheritedRules(inheritedRulesToSet);
ruleset.setLinkedToRuleSet(ruleService.getLinkedToRuleNode(nodeRef));
ruleset.setLinkedFromRuleSets(ruleService.getLinkedFromRuleNodes(nodeRef));
ruleset.setRulesetNodeRef(nodeRef); ruleset.setRulesetNodeRef(nodeRef);
model.put("ruleset", ruleset); model.put("ruleset", ruleset);
return model; return model;
} }
} }

View File

@@ -24,11 +24,9 @@
*/ */
package org.alfresco.repo.web.scripts.rule.ruleset; package org.alfresco.repo.web.scripts.rule.ruleset;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.rule.Rule; import org.alfresco.service.cmr.rule.Rule;
/** /**
* Rule object for REST API * Rule object for REST API
* *
@@ -40,17 +38,17 @@ public class RuleRef
/** Serial version UID */ /** Serial version UID */
private static final long serialVersionUID = -923276130307938661L; private static final long serialVersionUID = -923276130307938661L;
private NodeRef owningNodeRef; private FileInfo owningFileInfo;
private Rule rule; private Rule rule;
public RuleRef(Rule rule, NodeRef owningNodeRef) public RuleRef(Rule rule, FileInfo owningFileInfo)
{ {
this.rule = rule; this.rule = rule;
this.owningNodeRef = owningNodeRef; this.owningFileInfo = owningFileInfo;
} }
/** /**
* Set the rule * Set the rule
* *
@@ -60,7 +58,7 @@ public class RuleRef
{ {
this.rule = rule; this.rule = rule;
} }
/** /**
* Return the rule * Return the rule
* *
@@ -70,24 +68,24 @@ public class RuleRef
{ {
return rule; return rule;
} }
/** /**
* Set the owning node reference for rule * Set the owning file info reference for rule
* *
* @param owningNodeRef the owning node reference to set * @param owningNodeRef the owning file info reference to set
*/ */
public void setOwningNodeRef(NodeRef owningNodeRef) public void setOwningFileInfo(FileInfo owningFileInfo)
{ {
this.owningNodeRef = owningNodeRef; this.owningFileInfo = owningFileInfo;
} }
/** /**
* Returns the owning node reference for a rule. * Returns the owning file info reference for a rule.
* *
* @return the owning node reference * @return the owning file info reference
*/ */
public NodeRef getOwningNodeRef() public FileInfo getOwningFileInfo()
{ {
return owningNodeRef; return owningFileInfo;
} }
} }

View File

@@ -35,19 +35,19 @@ import org.alfresco.service.cmr.repository.NodeRef;
*/ */
public class RuleSet implements Serializable public class RuleSet implements Serializable
{ {
private static final long serialVersionUID = 6985140035928444095L; private static final long serialVersionUID = 6985140035928444095L;
private List<RuleRef> rules = null; private List<RuleRef> rules = null;
private List<RuleRef> inheritedRules = null; private List<RuleRef> inheritedRules = null;
private NodeRef rulesetNodeRef; private NodeRef rulesetNodeRef;
private NodeRef linkedToRuleSet; private NodeRef linkedToRuleSet;
private List<NodeRef> linkedFromRuleSets; private List<NodeRef> linkedFromRuleSets;
/** /**
* Set list of the rules "owned" by this rule set * Set list of the rules "owned" by this rule set
* *
@@ -57,7 +57,7 @@ public class RuleSet implements Serializable
{ {
this.rules = rules; this.rules = rules;
} }
/** /**
* Get list of the rules "owned" by this rule set * Get list of the rules "owned" by this rule set
* *
@@ -67,7 +67,7 @@ public class RuleSet implements Serializable
{ {
return rules; return rules;
} }
/** /**
* Set list of the rules inherited by this rule set from parent * Set list of the rules inherited by this rule set from parent
* *
@@ -77,7 +77,7 @@ public class RuleSet implements Serializable
{ {
this.inheritedRules = inheritedRules; this.inheritedRules = inheritedRules;
} }
/** /**
* Get list of the rules inherited by this rule set from parent * Get list of the rules inherited by this rule set from parent
* *
@@ -87,7 +87,7 @@ public class RuleSet implements Serializable
{ {
return inheritedRules; return inheritedRules;
} }
/** /**
* Set the nodeRef to which this ruleset belongs * Set the nodeRef to which this ruleset belongs
* *
@@ -97,7 +97,7 @@ public class RuleSet implements Serializable
{ {
this.rulesetNodeRef = rulesetNodeRef; this.rulesetNodeRef = rulesetNodeRef;
} }
/** /**
* Get the nodeRef to which this ruleset belongs * Get the nodeRef to which this ruleset belongs
* *
@@ -107,7 +107,7 @@ public class RuleSet implements Serializable
{ {
return rulesetNodeRef; return rulesetNodeRef;
} }
/** /**
* Set the nodeRef to which this ruleset linked to * Set the nodeRef to which this ruleset linked to
* *
@@ -117,7 +117,7 @@ public class RuleSet implements Serializable
{ {
this.linkedToRuleSet = linkedToRuleSet; this.linkedToRuleSet = linkedToRuleSet;
} }
/** /**
* Get the nodeRef to which this ruleset linked to * Get the nodeRef to which this ruleset linked to
* *
@@ -127,7 +127,7 @@ public class RuleSet implements Serializable
{ {
return linkedToRuleSet; return linkedToRuleSet;
} }
/** /**
* Set the list of nodeRefs that link to this ruleset * Set the list of nodeRefs that link to this ruleset
* *
@@ -137,7 +137,7 @@ public class RuleSet implements Serializable
{ {
this.linkedFromRuleSets = linkedFromRuleSets; this.linkedFromRuleSets = linkedFromRuleSets;
} }
/** /**
* Get the list of nodeRefs that link to this ruleset * Get the list of nodeRefs that link to this ruleset
* *