mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
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:
@@ -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>
|
@@ -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>
|
||||||
|
]
|
||||||
|
}
|
@@ -1,3 +1,3 @@
|
|||||||
<#import "rule.lib.ftl" as ruleLib/>
|
<#import "rule.lib.ftl" as ruleLib/>
|
||||||
|
|
||||||
<@ruleLib.ruleJSON rule=rule />
|
<@ruleLib.ruleRefJSON ruleRef=ruleRef />
|
@@ -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>
|
||||||
|
@@ -2,5 +2,5 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
"data" :
|
"data" :
|
||||||
<@ruleLib.rulesummaryJSON rule=rule />
|
<@ruleLib.ruleRefSummaryJSON ruleRef=ruleRef />
|
||||||
}
|
}
|
@@ -1,3 +1,3 @@
|
|||||||
<#import "rule.lib.ftl" as ruleLib/>
|
<#import "rule.lib.ftl" as ruleLib/>
|
||||||
|
|
||||||
<@ruleLib.ruleJSON rule=rule />
|
<@ruleLib.ruleRefJSON ruleRef=ruleRef />
|
@@ -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>
|
||||||
|
@@ -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>
|
||||||
]
|
]
|
||||||
}
|
}
|
@@ -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 > 0>
|
<#if ruleset.linkedFromRuleSets?? && ruleset.linkedFromRuleSets?size > 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>
|
||||||
|
@@ -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>
|
||||||
|
@@ -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;
|
||||||
@@ -76,11 +77,12 @@ public abstract class AbstractRuleWebScript extends DeclarativeWebScript
|
|||||||
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
|
||||||
@@ -122,6 +124,16 @@ 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
|
||||||
*
|
*
|
||||||
@@ -154,74 +166,148 @@ public abstract class AbstractRuleWebScript extends DeclarativeWebScript
|
|||||||
|
|
||||||
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)
|
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
|
// get parameters for all action condition definitions
|
||||||
List<ActionConditionDefinition> actionConditionDefinitions = actionService.getActionConditionDefinitions();
|
List<ActionConditionDefinition> actionConditionDefinitions = actionService.getActionConditionDefinitions();
|
||||||
|
|
||||||
for (ActionConditionDefinition actionConditionDefinition : actionConditionDefinitions)
|
for (ActionConditionDefinition actionConditionDefinition : actionConditionDefinitions)
|
||||||
{
|
{
|
||||||
List<ParameterDefinition> parameterDefinitions = actionConditionDefinition.getParameterDefinitions();
|
List<ParameterDefinition> parameterDefinitions = actionConditionDefinition.getParameterDefinitions();
|
||||||
|
Map<String, QName> parameters = new HashMap<String, QName>();
|
||||||
|
|
||||||
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
|
{
|
||||||
{
|
lock.writeLock().lock();
|
||||||
lock.writeLock().unlock();
|
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;
|
||||||
@@ -233,8 +319,7 @@ public abstract class AbstractRuleWebScript extends DeclarativeWebScript
|
|||||||
|
|
||||||
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"));
|
||||||
@@ -243,8 +328,7 @@ public abstract class AbstractRuleWebScript extends DeclarativeWebScript
|
|||||||
|
|
||||||
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");
|
||||||
@@ -308,7 +392,7 @@ public abstract class AbstractRuleWebScript extends DeclarativeWebScript
|
|||||||
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"))
|
||||||
@@ -332,7 +416,7 @@ public abstract class AbstractRuleWebScript extends DeclarativeWebScript
|
|||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -362,7 +446,7 @@ public abstract class AbstractRuleWebScript extends DeclarativeWebScript
|
|||||||
|
|
||||||
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"));
|
||||||
|
|
||||||
@@ -375,70 +459,86 @@ public abstract class AbstractRuleWebScript extends DeclarativeWebScript
|
|||||||
{
|
{
|
||||||
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
|
||||||
|
{
|
||||||
|
typeQName = DataTypeDefinition.TEXT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Serializable value = null;
|
Serializable value = null;
|
||||||
|
|
||||||
if (typeQName.equals(DataTypeDefinition.ANY))
|
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;
|
||||||
|
@@ -61,8 +61,7 @@ public class ActionConstraintGet extends AbstractRuleWebScript
|
|||||||
|
|
||||||
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);
|
||||||
|
@@ -46,7 +46,6 @@ 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)
|
||||||
{
|
{
|
||||||
|
@@ -91,7 +91,7 @@ public class ActionQueuePost extends AbstractRuleWebScript
|
|||||||
{
|
{
|
||||||
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);
|
||||||
@@ -102,13 +102,11 @@ public class ActionQueuePost extends AbstractRuleWebScript
|
|||||||
}
|
}
|
||||||
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;
|
||||||
|
87
source/java/org/alfresco/repo/web/scripts/rule/InheritedRulesGet.java
Executable file
87
source/java/org/alfresco/repo/web/scripts/rule/InheritedRulesGet.java
Executable 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;
|
||||||
|
}
|
||||||
|
}
|
@@ -62,7 +62,7 @@ public class RuleDelete extends AbstractRuleWebScript
|
|||||||
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)
|
||||||
@@ -76,8 +76,7 @@ public class RuleDelete extends AbstractRuleWebScript
|
|||||||
|
|
||||||
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
|
||||||
|
@@ -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;
|
||||||
@@ -76,14 +77,12 @@ public class RuleGet extends AbstractRuleWebScript
|
|||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@@ -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;
|
||||||
@@ -71,20 +72,17 @@ public class RulePost extends AbstractRuleWebScript
|
|||||||
// 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;
|
||||||
|
@@ -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;
|
||||||
@@ -87,8 +88,7 @@ public class RulePut extends RulePost
|
|||||||
|
|
||||||
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;
|
||||||
@@ -104,20 +104,17 @@ public class RulePut extends RulePost
|
|||||||
// 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;
|
||||||
@@ -167,7 +164,7 @@ public class RulePut extends RulePost
|
|||||||
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);
|
||||||
}
|
}
|
||||||
@@ -202,7 +199,7 @@ public class RulePut extends RulePost
|
|||||||
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"))
|
||||||
@@ -221,11 +218,11 @@ public class RulePut extends RulePost
|
|||||||
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++)
|
||||||
@@ -240,7 +237,7 @@ public class RulePut extends RulePost
|
|||||||
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
|
||||||
@@ -284,7 +281,7 @@ public class RulePut extends RulePost
|
|||||||
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
|
||||||
@@ -306,7 +303,7 @@ public class RulePut extends RulePost
|
|||||||
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);
|
||||||
}
|
}
|
||||||
@@ -337,7 +334,7 @@ public class RulePut extends RulePost
|
|||||||
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;
|
||||||
|
@@ -28,18 +28,16 @@ import java.text.MessageFormat;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.rule.RuleModel;
|
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||||
import org.alfresco.repo.web.scripts.BaseWebScriptTest;
|
import org.alfresco.repo.web.scripts.BaseWebScriptTest;
|
||||||
|
import org.alfresco.service.cmr.action.ActionService;
|
||||||
|
import org.alfresco.service.cmr.action.ParameterConstraint;
|
||||||
import org.alfresco.service.cmr.model.FileFolderService;
|
import org.alfresco.service.cmr.model.FileFolderService;
|
||||||
import org.alfresco.service.cmr.model.FileInfo;
|
|
||||||
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;
|
||||||
import org.alfresco.service.cmr.rule.Rule;
|
import org.alfresco.service.cmr.rule.Rule;
|
||||||
import org.alfresco.service.cmr.rule.RuleService;
|
import org.alfresco.service.cmr.rule.RuleService;
|
||||||
import org.alfresco.service.cmr.search.SearchService;
|
|
||||||
import org.alfresco.service.namespace.NamespaceService;
|
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
@@ -69,73 +67,70 @@ public class RuleServiceTest extends BaseWebScriptTest
|
|||||||
private static final String URL_QUEUE_ACTION = "/api/actionQueue?async={0}";
|
private static final String URL_QUEUE_ACTION = "/api/actionQueue?async={0}";
|
||||||
|
|
||||||
private static final String URL_RULES = "/api/node/{0}/{1}/{2}/ruleset/rules";
|
private static final String URL_RULES = "/api/node/{0}/{1}/{2}/ruleset/rules";
|
||||||
|
private static final String URL_INHERITED_RULES = "/api/node/{0}/{1}/{2}/ruleset/inheritedrules";
|
||||||
private static final String URL_RULESET = "/api/node/{0}/{1}/{2}/ruleset";
|
private static final String URL_RULESET = "/api/node/{0}/{1}/{2}/ruleset";
|
||||||
private static final String URL_RULE = "/api/node/{0}/{1}/{2}/ruleset/rules/{3}";
|
private static final String URL_RULE = "/api/node/{0}/{1}/{2}/ruleset/rules/{3}";
|
||||||
|
|
||||||
|
private static final String TEST_STORE_IDENTIFIER = "test_store-" + System.currentTimeMillis();
|
||||||
private static final String TEST_FOLDER = "test_folder-" + System.currentTimeMillis();
|
private static final String TEST_FOLDER = "test_folder-" + System.currentTimeMillis();
|
||||||
|
private static final String TEST_FOLDER_2 = "test_folder-2-" + System.currentTimeMillis();
|
||||||
private static final String COMPANY_HOME_PATH = "/app:company_home";
|
|
||||||
|
|
||||||
private NodeService nodeService;
|
private NodeService nodeService;
|
||||||
private FileFolderService fileFolderService;
|
private FileFolderService fileFolderService;
|
||||||
private NamespaceService namespaceService;
|
|
||||||
private SearchService searchService;
|
|
||||||
private AuthenticationComponent authenticationComponent;
|
private AuthenticationComponent authenticationComponent;
|
||||||
private RuleService ruleService;
|
private RuleService ruleService;
|
||||||
|
private ActionService actionService;
|
||||||
|
|
||||||
private NodeRef testNodeRef;
|
private NodeRef testNodeRef;
|
||||||
private NodeRef companyHome;
|
private NodeRef testNodeRef2;
|
||||||
|
private NodeRef testWorkNodeRef;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception
|
protected void setUp() throws Exception
|
||||||
{
|
{
|
||||||
super.setUp();
|
super.setUp();
|
||||||
this.nodeService = (NodeService)getServer().getApplicationContext().getBean("NodeService");
|
this.nodeService = (NodeService) getServer().getApplicationContext().getBean("NodeService");
|
||||||
this.fileFolderService = (FileFolderService)getServer().getApplicationContext().getBean("FileFolderService");
|
this.fileFolderService = (FileFolderService) getServer().getApplicationContext().getBean("FileFolderService");
|
||||||
this.namespaceService = (NamespaceService)getServer().getApplicationContext().getBean("NamespaceService");
|
this.ruleService = (RuleService) getServer().getApplicationContext().getBean("RuleService");
|
||||||
this.searchService = (SearchService)getServer().getApplicationContext().getBean("SearchService");
|
this.actionService = (ActionService) getServer().getApplicationContext().getBean("ActionService");
|
||||||
this.ruleService = (RuleService)getServer().getApplicationContext().getBean("RuleService");
|
this.authenticationComponent = (AuthenticationComponent) getServer().getApplicationContext().getBean("authenticationComponent");
|
||||||
this.authenticationComponent = (AuthenticationComponent)getServer().getApplicationContext().getBean("authenticationComponent");
|
|
||||||
|
|
||||||
this.authenticationComponent.setSystemUserAsCurrentUser();
|
this.authenticationComponent.setSystemUserAsCurrentUser();
|
||||||
|
|
||||||
createTestFolder();
|
createTestFolders();
|
||||||
|
|
||||||
|
assertNotNull(testWorkNodeRef);
|
||||||
assertNotNull(testNodeRef);
|
assertNotNull(testNodeRef);
|
||||||
assertNotNull(companyHome);
|
assertNotNull(testNodeRef2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createTestFolder()
|
private void createTestFolders()
|
||||||
{
|
{
|
||||||
NodeRef storeRootNodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
|
StoreRef testStore = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, TEST_STORE_IDENTIFIER);
|
||||||
|
|
||||||
NodeRef companyHomeNodeRef;
|
if (!nodeService.exists(testStore))
|
||||||
|
|
||||||
List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, COMPANY_HOME_PATH, null, namespaceService, false);
|
|
||||||
|
|
||||||
if (nodeRefs.size() > 1)
|
|
||||||
{
|
{
|
||||||
throw new RuntimeException("Multiple possible roots for : \n" + " root path: " + COMPANY_HOME_PATH + "\n" + " results: " + nodeRefs);
|
testStore = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, TEST_STORE_IDENTIFIER);
|
||||||
}
|
}
|
||||||
else if (nodeRefs.size() == 0)
|
|
||||||
|
NodeRef rootNodeRef = nodeService.getRootNode(testStore);
|
||||||
|
|
||||||
|
testWorkNodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}testnode"), ContentModel.TYPE_FOLDER).getChildRef();
|
||||||
|
|
||||||
|
testNodeRef = fileFolderService.create(testWorkNodeRef, TEST_FOLDER, ContentModel.TYPE_FOLDER).getNodeRef();
|
||||||
|
testNodeRef2 = fileFolderService.create(testWorkNodeRef, TEST_FOLDER_2, ContentModel.TYPE_FOLDER).getNodeRef();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String formatRulesUrl(NodeRef nodeRef, boolean inherited)
|
||||||
|
{
|
||||||
|
if (inherited)
|
||||||
{
|
{
|
||||||
throw new RuntimeException("No root found for : \n" + " root path: " + COMPANY_HOME_PATH);
|
return MessageFormat.format(URL_INHERITED_RULES, nodeRef.getStoreRef().getProtocol(), nodeRef.getStoreRef().getIdentifier(), nodeRef.getId());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
companyHomeNodeRef = nodeRefs.get(0);
|
return MessageFormat.format(URL_RULES, nodeRef.getStoreRef().getProtocol(), nodeRef.getStoreRef().getIdentifier(), nodeRef.getId());
|
||||||
companyHome = companyHomeNodeRef;
|
|
||||||
}
|
}
|
||||||
FileInfo fileInfo = fileFolderService.create(companyHomeNodeRef, TEST_FOLDER, ContentModel.TYPE_FOLDER);
|
|
||||||
|
|
||||||
testNodeRef = fileInfo.getNodeRef();
|
|
||||||
|
|
||||||
this.nodeService.addAspect(testNodeRef, RuleModel.ASPECT_RULES, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String formatRulesUrl(NodeRef nodeRef)
|
|
||||||
{
|
|
||||||
return MessageFormat.format(URL_RULES, nodeRef.getStoreRef().getProtocol(), nodeRef.getStoreRef().getIdentifier(), nodeRef.getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String formatRulesetUrl(NodeRef nodeRef)
|
private String formatRulesetUrl(NodeRef nodeRef)
|
||||||
@@ -162,25 +157,26 @@ public class RuleServiceTest extends BaseWebScriptTest
|
|||||||
protected void tearDown() throws Exception
|
protected void tearDown() throws Exception
|
||||||
{
|
{
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
|
nodeService.deleteNode(testNodeRef2);
|
||||||
fileFolderService.delete(testNodeRef);
|
nodeService.deleteNode(testNodeRef);
|
||||||
|
nodeService.deleteNode(testWorkNodeRef);
|
||||||
this.authenticationComponent.clearCurrentSecurityContext();
|
this.authenticationComponent.clearCurrentSecurityContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
private JSONObject createRule() throws Exception
|
private JSONObject createRule(NodeRef ruleOwnerNodeRef) throws Exception
|
||||||
{
|
{
|
||||||
JSONObject jsonRule = buildTestRule();
|
JSONObject jsonRule = buildTestRule();
|
||||||
|
|
||||||
Response response = sendRequest(new PostRequest(formatRulesUrl(testNodeRef), jsonRule.toString(), "application/json"), 200);
|
Response response = sendRequest(new PostRequest(formatRulesUrl(ruleOwnerNodeRef, false), jsonRule.toString(), "application/json"), 200);
|
||||||
|
|
||||||
JSONObject result = new JSONObject(response.getContentAsString());
|
JSONObject result = new JSONObject(response.getContentAsString());
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JSONArray getNodeRules() throws Exception
|
private JSONArray getNodeRules(NodeRef nodeRef, boolean inherited) throws Exception
|
||||||
{
|
{
|
||||||
Response response = sendRequest(new GetRequest(formatRulesUrl(testNodeRef)), 200);
|
Response response = sendRequest(new GetRequest(formatRulesUrl(nodeRef, inherited)), 200);
|
||||||
JSONObject result = new JSONObject(response.getContentAsString());
|
JSONObject result = new JSONObject(response.getContentAsString());
|
||||||
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
@@ -207,9 +203,13 @@ public class RuleServiceTest extends BaseWebScriptTest
|
|||||||
assertEquals(1, ruleType.length());
|
assertEquals(1, ruleType.length());
|
||||||
assertEquals("outbound", ruleType.getString(0));
|
assertEquals("outbound", ruleType.getString(0));
|
||||||
|
|
||||||
assertFalse(result.getBoolean("applyToChildren"));
|
assertTrue(result.getBoolean("applyToChildren"));
|
||||||
assertFalse(result.getBoolean("executeAsynchronously"));
|
assertFalse(result.getBoolean("executeAsynchronously"));
|
||||||
assertFalse(result.getBoolean("disabled"));
|
assertFalse(result.getBoolean("disabled"));
|
||||||
|
assertTrue(result.has("owningNode"));
|
||||||
|
JSONObject owningNode = result.getJSONObject("owningNode");
|
||||||
|
assertTrue(owningNode.has("nodeRef"));
|
||||||
|
assertTrue(owningNode.has("name"));
|
||||||
assertTrue(result.has("url"));
|
assertTrue(result.has("url"));
|
||||||
|
|
||||||
JSONObject jsonAction = result.getJSONObject("action");
|
JSONObject jsonAction = result.getJSONObject("action");
|
||||||
@@ -281,7 +281,7 @@ public class RuleServiceTest extends BaseWebScriptTest
|
|||||||
assertEquals(before.has("url"), after.has("url"));
|
assertEquals(before.has("url"), after.has("url"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkRuleset(JSONObject result, String ruleId) throws Exception
|
private void checkRuleset(JSONObject result, int rulesCount, String[] ruleIds, int inhRulesCount, String[] parentRuleIds) throws Exception
|
||||||
{
|
{
|
||||||
assertNotNull("Response is null.", result);
|
assertNotNull("Response is null.", result);
|
||||||
|
|
||||||
@@ -289,21 +289,51 @@ public class RuleServiceTest extends BaseWebScriptTest
|
|||||||
|
|
||||||
JSONObject data = result.getJSONObject("data");
|
JSONObject data = result.getJSONObject("data");
|
||||||
|
|
||||||
assertTrue(data.has("rules"));
|
if (data.has("rules"))
|
||||||
|
{
|
||||||
|
JSONArray rulesArray = data.getJSONArray("rules");
|
||||||
|
|
||||||
assertEquals(1, data.getJSONArray("rules").length());
|
assertEquals(rulesCount, rulesArray.length());
|
||||||
|
|
||||||
JSONObject ruleSummary = data.getJSONArray("rules").getJSONObject(0);
|
for (int i = 0; i < rulesArray.length(); i++)
|
||||||
|
{
|
||||||
|
JSONObject ruleSum = rulesArray.getJSONObject(i);
|
||||||
|
assertTrue(ruleSum.has("id"));
|
||||||
|
assertEquals(ruleIds[i], ruleSum.getString("id"));
|
||||||
|
assertTrue(ruleSum.has("title"));
|
||||||
|
assertTrue(ruleSum.has("ruleType"));
|
||||||
|
assertTrue(ruleSum.has("disabled"));
|
||||||
|
assertTrue(ruleSum.has("owningNode"));
|
||||||
|
JSONObject owningNode = ruleSum.getJSONObject("owningNode");
|
||||||
|
assertTrue(owningNode.has("nodeRef"));
|
||||||
|
assertTrue(owningNode.has("name"));
|
||||||
|
assertTrue(ruleSum.has("url"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
assertEquals(ruleId, ruleSummary.getString("id"));
|
if (data.has("inheritedRules"))
|
||||||
|
{
|
||||||
|
JSONArray inheritedRulesArray = data.getJSONArray("inheritedRules");
|
||||||
|
|
||||||
assertTrue(ruleSummary.has("title"));
|
assertEquals(inhRulesCount, inheritedRulesArray.length());
|
||||||
assertTrue(ruleSummary.has("ruleType"));
|
|
||||||
assertTrue(ruleSummary.has("disabled"));
|
|
||||||
assertTrue(ruleSummary.has("url"));
|
|
||||||
|
|
||||||
assertFalse(data.has("inheritedRules"));
|
for (int i = 0; i < inheritedRulesArray.length(); i++)
|
||||||
|
{
|
||||||
|
JSONObject ruleSum = inheritedRulesArray.getJSONObject(i);
|
||||||
|
assertTrue(ruleSum.has("id"));
|
||||||
|
assertEquals(parentRuleIds[i], ruleSum.getString("id"));
|
||||||
|
assertTrue(ruleSum.has("title"));
|
||||||
|
assertTrue(ruleSum.has("ruleType"));
|
||||||
|
assertTrue(ruleSum.has("disabled"));
|
||||||
|
assertTrue(ruleSum.has("owningNode"));
|
||||||
|
JSONObject owningNode = ruleSum.getJSONObject("owningNode");
|
||||||
|
assertTrue(owningNode.has("nodeRef"));
|
||||||
|
assertTrue(owningNode.has("name"));
|
||||||
|
assertTrue(ruleSum.has("url"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assertTrue(data.has("url"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetRuleTypes() throws Exception
|
public void testGetRuleTypes() throws Exception
|
||||||
@@ -406,7 +436,17 @@ public class RuleServiceTest extends BaseWebScriptTest
|
|||||||
|
|
||||||
public void testGetActionConstraint() throws Exception
|
public void testGetActionConstraint() throws Exception
|
||||||
{
|
{
|
||||||
Response response = sendRequest(new GetRequest(formateActionConstraintUrl("ac-compare-operations")), 200);
|
|
||||||
|
List<ParameterConstraint> constraints = actionService.getParameterConstraints();
|
||||||
|
|
||||||
|
if (constraints.size() == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String name = constraints.get(0).getName();
|
||||||
|
|
||||||
|
Response response = sendRequest(new GetRequest(formateActionConstraintUrl(name)), 200);
|
||||||
JSONObject result = new JSONObject(response.getContentAsString());
|
JSONObject result = new JSONObject(response.getContentAsString());
|
||||||
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
@@ -433,7 +473,7 @@ public class RuleServiceTest extends BaseWebScriptTest
|
|||||||
{
|
{
|
||||||
String url = formateQueueActionUrl(false);
|
String url = formateQueueActionUrl(false);
|
||||||
|
|
||||||
JSONObject copyAction = buildCopyAction(companyHome);
|
JSONObject copyAction = buildCopyAction(testWorkNodeRef);
|
||||||
|
|
||||||
copyAction.put("actionedUponNode", testNodeRef);
|
copyAction.put("actionedUponNode", testNodeRef);
|
||||||
|
|
||||||
@@ -498,7 +538,7 @@ public class RuleServiceTest extends BaseWebScriptTest
|
|||||||
|
|
||||||
public void testCreateRule() throws Exception
|
public void testCreateRule() throws Exception
|
||||||
{
|
{
|
||||||
JSONObject result = createRule();
|
JSONObject result = createRule(testNodeRef);
|
||||||
|
|
||||||
checkRuleSummary(result);
|
checkRuleSummary(result);
|
||||||
|
|
||||||
@@ -510,32 +550,75 @@ public class RuleServiceTest extends BaseWebScriptTest
|
|||||||
|
|
||||||
public void testGetRulesCollection() throws Exception
|
public void testGetRulesCollection() throws Exception
|
||||||
{
|
{
|
||||||
JSONArray data = getNodeRules();
|
JSONArray data = getNodeRules(testNodeRef, false);
|
||||||
|
|
||||||
assertEquals(0, data.length());
|
assertEquals(0, data.length());
|
||||||
|
|
||||||
createRule();
|
createRule(testNodeRef);
|
||||||
|
|
||||||
data = getNodeRules();
|
data = getNodeRules(testNodeRef, false);
|
||||||
|
|
||||||
assertEquals(1, data.length());
|
assertEquals(1, data.length());
|
||||||
|
|
||||||
|
for (int i = 0; i < data.length(); i++)
|
||||||
|
{
|
||||||
|
JSONObject ruleSum = data.getJSONObject(i);
|
||||||
|
assertTrue(ruleSum.has("id"));
|
||||||
|
assertTrue(ruleSum.has("title"));
|
||||||
|
assertTrue(ruleSum.has("ruleType"));
|
||||||
|
assertTrue(ruleSum.has("disabled"));
|
||||||
|
assertTrue(ruleSum.has("owningNode"));
|
||||||
|
JSONObject owningNode = ruleSum.getJSONObject("owningNode");
|
||||||
|
assertTrue(owningNode.has("nodeRef"));
|
||||||
|
assertTrue(owningNode.has("name"));
|
||||||
|
assertTrue(ruleSum.has("url"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetInheritedRulesCollection() throws Exception
|
||||||
|
{
|
||||||
|
JSONArray data = getNodeRules(testNodeRef, true);
|
||||||
|
|
||||||
|
assertEquals(0, data.length());
|
||||||
|
|
||||||
|
createRule(testWorkNodeRef);
|
||||||
|
|
||||||
|
data = getNodeRules(testNodeRef, true);
|
||||||
|
|
||||||
|
assertEquals(1, data.length());
|
||||||
|
|
||||||
|
for (int i = 0; i < data.length(); i++)
|
||||||
|
{
|
||||||
|
JSONObject ruleSum = data.getJSONObject(i);
|
||||||
|
assertTrue(ruleSum.has("id"));
|
||||||
|
assertTrue(ruleSum.has("title"));
|
||||||
|
assertTrue(ruleSum.has("ruleType"));
|
||||||
|
assertTrue(ruleSum.has("disabled"));
|
||||||
|
assertTrue(ruleSum.has("owningNode"));
|
||||||
|
JSONObject owningNode = ruleSum.getJSONObject("owningNode");
|
||||||
|
assertTrue(owningNode.has("nodeRef"));
|
||||||
|
assertTrue(owningNode.has("name"));
|
||||||
|
assertTrue(ruleSum.has("url"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetRuleset() throws Exception
|
public void testGetRuleset() throws Exception
|
||||||
{
|
{
|
||||||
JSONObject jsonRule = createRule();
|
JSONObject parentRule = createRule(testWorkNodeRef);
|
||||||
|
String[] parentRuleIds = new String[] { parentRule.getJSONObject("data").getString("id") };
|
||||||
|
|
||||||
String ruleId = jsonRule.getJSONObject("data").getString("id");
|
JSONObject jsonRule = createRule(testNodeRef);
|
||||||
|
String[] ruleIds = new String[] { jsonRule.getJSONObject("data").getString("id") };
|
||||||
|
|
||||||
Response response = sendRequest(new GetRequest(formatRulesetUrl(testNodeRef)), 200);
|
Response response = sendRequest(new GetRequest(formatRulesetUrl(testNodeRef)), 200);
|
||||||
JSONObject result = new JSONObject(response.getContentAsString());
|
JSONObject result = new JSONObject(response.getContentAsString());
|
||||||
|
|
||||||
checkRuleset(result, ruleId);
|
checkRuleset(result, 1, ruleIds, 1, parentRuleIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetRuleDetails() throws Exception
|
public void testGetRuleDetails() throws Exception
|
||||||
{
|
{
|
||||||
JSONObject jsonRule = createRule();
|
JSONObject jsonRule = createRule(testNodeRef);
|
||||||
|
|
||||||
String ruleId = jsonRule.getJSONObject("data").getString("id");
|
String ruleId = jsonRule.getJSONObject("data").getString("id");
|
||||||
|
|
||||||
@@ -547,7 +630,7 @@ public class RuleServiceTest extends BaseWebScriptTest
|
|||||||
|
|
||||||
public void testUpdateRule() throws Exception
|
public void testUpdateRule() throws Exception
|
||||||
{
|
{
|
||||||
JSONObject jsonRule = createRule();
|
JSONObject jsonRule = createRule(testNodeRef);
|
||||||
|
|
||||||
String ruleId = jsonRule.getJSONObject("data").getString("id");
|
String ruleId = jsonRule.getJSONObject("data").getString("id");
|
||||||
|
|
||||||
@@ -576,7 +659,7 @@ public class RuleServiceTest extends BaseWebScriptTest
|
|||||||
|
|
||||||
public void testDeleteRule() throws Exception
|
public void testDeleteRule() throws Exception
|
||||||
{
|
{
|
||||||
JSONObject jsonRule = createRule();
|
JSONObject jsonRule = createRule(testNodeRef);
|
||||||
|
|
||||||
assertEquals(1, ruleService.getRules(testNodeRef).size());
|
assertEquals(1, ruleService.getRules(testNodeRef).size());
|
||||||
|
|
||||||
@@ -607,8 +690,8 @@ public class RuleServiceTest extends BaseWebScriptTest
|
|||||||
// build parameterValues
|
// build parameterValues
|
||||||
JSONObject parameterValues = new JSONObject();
|
JSONObject parameterValues = new JSONObject();
|
||||||
parameterValues.put("destination-folder", destination);
|
parameterValues.put("destination-folder", destination);
|
||||||
parameterValues.put("assoc-name", QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy"));
|
parameterValues.put("assoc-name", "cm:copy");
|
||||||
parameterValues.put("assoc-type", ContentModel.ASSOC_CONTAINS);
|
parameterValues.put("assoc-type", "cm:contains");
|
||||||
|
|
||||||
// add parameterValues
|
// add parameterValues
|
||||||
result.put("parameterValues", parameterValues);
|
result.put("parameterValues", parameterValues);
|
||||||
@@ -631,7 +714,7 @@ public class RuleServiceTest extends BaseWebScriptTest
|
|||||||
|
|
||||||
result.put("ruleType", ruleType);
|
result.put("ruleType", ruleType);
|
||||||
|
|
||||||
result.put("applyToChildren", false);
|
result.put("applyToChildren", true);
|
||||||
|
|
||||||
result.put("executeAsynchronously", false);
|
result.put("executeAsynchronously", false);
|
||||||
|
|
||||||
@@ -674,7 +757,7 @@ public class RuleServiceTest extends BaseWebScriptTest
|
|||||||
|
|
||||||
if (addCompensatingAction)
|
if (addCompensatingAction)
|
||||||
{
|
{
|
||||||
result.put("compensatingAction", buildTestAction("executeScript", false, false));
|
result.put("compensatingAction", buildTestAction("script", false, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@@ -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;
|
||||||
@@ -62,13 +64,17 @@ public class RulesGet extends AbstractRuleWebScript
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
@@ -80,19 +80,22 @@ public class RulesetGet extends AbstractRuleWebScript
|
|||||||
|
|
||||||
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);
|
||||||
|
@@ -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
|
||||||
*
|
*
|
||||||
@@ -41,14 +39,14 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -72,22 +70,22 @@ public class RuleRef
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user