From ec2827fa2832998cbf9e978a3929ca5170a25d88 Mon Sep 17 00:00:00 2001 From: Roy Wetherall Date: Tue, 12 Jan 2010 16:38:43 +0000 Subject: [PATCH] Removed existing Rule REST implementation since it is incomplete and may confuse upcomming development. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@17983 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco/repository/rule/action.lib.ftl | 48 - .../repository/rule/actiondef.get.desc.xml | 8 - .../repository/rule/actiondef.get.json.ftl | 4 - .../repository/rule/actiondef.lib.ftl | 33 - .../repository/rule/actiondefs.get.desc.xml | 10 - .../repository/rule/actiondefs.get.json.ftl | 8 - .../repository/rule/actionqueue.post.desc.xml | 8 - .../repository/rule/actionqueue.post.json.ftl | 3 - .../rule/actionqueueitemstatus.lib.ftl | 11 - .../repository/rule/condition.lib.ftl | 17 - .../repository/rule/conditiondef.get.desc.xml | 8 - .../repository/rule/conditiondef.get.json.ftl | 4 - .../repository/rule/conditiondef.lib.ftl | 26 - .../rule/conditiondefs.get.desc.xml | 8 - .../rule/conditiondefs.get.json.ftl | 8 - .../alfresco/repository/rule/paramdef.lib.ftl | 12 - .../repository/rule/rule.delete.desc.xml | 10 - .../repository/rule/rule.delete.json.ftl | 3 - .../repository/rule/rule.get.desc.xml | 10 - .../repository/rule/rule.get.json.ftl | 2 - .../org/alfresco/repository/rule/rule.lib.ftl | 25 - .../repository/rule/rule.put.desc.xml | 10 - .../repository/rule/rule.put.json.ftl | 2 - .../repository/rule/rules.delete.desc.xml | 10 - .../repository/rule/rules.delete.json.ftl | 3 - .../repository/rule/rules.get.desc.xml | 10 - .../repository/rule/rules.get.json.ftl | 8 - .../repository/rule/rules.post.desc.xml | 10 - .../repository/rule/rules.post.json.ftl | 2 - .../web-scripts-application-context.xml | 96 -- .../repo/web/scripts/rule/ActionDefGet.java | 93 -- .../repo/web/scripts/rule/ActionDefsGet.java | 129 -- .../scripts/rule/ActionQueueItemStatus.java | 113 -- .../web/scripts/rule/ActionQueuePost.java | 162 --- .../web/scripts/rule/ConditionDefGet.java | 93 -- .../web/scripts/rule/ConditionDefsGet.java | 82 -- .../repo/web/scripts/rule/RuleDelete.java | 140 -- .../repo/web/scripts/rule/RuleGet.java | 152 --- .../repo/web/scripts/rule/RulePut.java | 168 --- .../web/scripts/rule/RuleServiceTest.java | 1180 ----------------- .../repo/web/scripts/rule/RulesDelete.java | 116 -- .../repo/web/scripts/rule/RulesGet.java | 162 --- .../repo/web/scripts/rule/RulesHelper.java | 987 -------------- .../repo/web/scripts/rule/RulesPost.java | 145 -- 44 files changed, 4139 deletions(-) delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/action.lib.ftl delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/actiondef.get.desc.xml delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/actiondef.get.json.ftl delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/actiondef.lib.ftl delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/actiondefs.get.desc.xml delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/actiondefs.get.json.ftl delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/actionqueue.post.desc.xml delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/actionqueue.post.json.ftl delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/actionqueueitemstatus.lib.ftl delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/condition.lib.ftl delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/conditiondef.get.desc.xml delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/conditiondef.get.json.ftl delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/conditiondef.lib.ftl delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/conditiondefs.get.desc.xml delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/conditiondefs.get.json.ftl delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/paramdef.lib.ftl delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.delete.desc.xml delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.delete.json.ftl delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.get.desc.xml delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.get.json.ftl delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.lib.ftl delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.put.desc.xml delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.put.json.ftl delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/rules.delete.desc.xml delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/rules.delete.json.ftl delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/rules.get.desc.xml delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/rules.get.json.ftl delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/rules.post.desc.xml delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/rule/rules.post.json.ftl delete mode 100644 source/java/org/alfresco/repo/web/scripts/rule/ActionDefGet.java delete mode 100644 source/java/org/alfresco/repo/web/scripts/rule/ActionDefsGet.java delete mode 100644 source/java/org/alfresco/repo/web/scripts/rule/ActionQueueItemStatus.java delete mode 100644 source/java/org/alfresco/repo/web/scripts/rule/ActionQueuePost.java delete mode 100644 source/java/org/alfresco/repo/web/scripts/rule/ConditionDefGet.java delete mode 100644 source/java/org/alfresco/repo/web/scripts/rule/ConditionDefsGet.java delete mode 100644 source/java/org/alfresco/repo/web/scripts/rule/RuleDelete.java delete mode 100644 source/java/org/alfresco/repo/web/scripts/rule/RuleGet.java delete mode 100644 source/java/org/alfresco/repo/web/scripts/rule/RulePut.java delete mode 100644 source/java/org/alfresco/repo/web/scripts/rule/RuleServiceTest.java delete mode 100644 source/java/org/alfresco/repo/web/scripts/rule/RulesDelete.java delete mode 100644 source/java/org/alfresco/repo/web/scripts/rule/RulesGet.java delete mode 100644 source/java/org/alfresco/repo/web/scripts/rule/RulesHelper.java delete mode 100644 source/java/org/alfresco/repo/web/scripts/rule/RulesPost.java diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/action.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/action.lib.ftl deleted file mode 100644 index a82dc36217..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/action.lib.ftl +++ /dev/null @@ -1,48 +0,0 @@ -<#import "condition.lib.ftl" as conditionLib/> - -<#macro actionJSON action rule> -{ - "id" : "${action.id}", - "actionDefinitionName" : "${action.actionDefinitionName}", - <#if action.title?exists> - "title" : "${action.title}", - - <#if action.description?exists> - "description" : "${action.description}", - - "executeAsync" : "${action.executeAsychronously?string("true", "false")}", - <#if action.parameterValues?exists> - "parameterValues" : - { - <#list action.parameterValues?keys as parameterKey> - "${parameterKey}" : "${action.parameterValues[parameterKey]}" - <#if parameterKey_has_next>, - - }, - - <#if action.actions?exists> - "actions" : - { - <#list action.actions as nestedAction> - "${nestedAction.id}" : <@actionJSON action=nestedAction rule=rule/> - <#if nestedAction_has_next>, - - }, - - <#if action.actionConditions?exists> - "conditions" : - { - <#list action.actionConditions as condition> - "${condition.id}" : <@conditionLib.conditionJSON condition=condition rule=rule/> - <#if condition_has_next>, - - }, - - <#if action.compensatingAction?exists> - "compensatingAction" : <@actionJSON action=action.compensatingAction/>, - - "url" : "${url.serviceContext + "/api/rules/" + rule.nodeRef.storeRef.protocol + "/" - + rule.nodeRef.storeRef.identifier + "/" + rule.nodeRef.id + "/actions/" - + action.id}" -} - diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/actiondef.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/actiondef.get.desc.xml deleted file mode 100644 index fbceaeb12b..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/actiondef.get.desc.xml +++ /dev/null @@ -1,8 +0,0 @@ - - Get Action Definition - Get an action definition given its name - /api/rules/actiondefs/{actionDefinitionName} - argument - user - required - \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/actiondef.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/actiondef.get.json.ftl deleted file mode 100644 index 0835b86e12..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/actiondef.get.json.ftl +++ /dev/null @@ -1,4 +0,0 @@ -<#import "actiondef.lib.ftl" as actionDefLib/> - -<@actionDefLib.actionDefJSON actiondef=actiondef/> - \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/actiondef.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/actiondef.lib.ftl deleted file mode 100644 index 24d93f8bd2..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/actiondef.lib.ftl +++ /dev/null @@ -1,33 +0,0 @@ -<#import "paramdef.lib.ftl" as paramDefLib/> - -<#macro actionDefJSON actiondef> - <#escape x as jsonUtils.encodeJSONString(x)> - { - "name" : "${actiondef.name}", - <#if actiondef.title?exists> - "title" : "${actiondef.title}", - - <#if actiondef.description?exists> - "description" : "${actiondef.description}", - - "adhocPropertiesAllowed" : "${actiondef.adhocPropertiesAllowed?string("true", "false")}", - "applicableTypes" : - [ - <#list actiondef.applicableTypes as applicableType> - "${applicableType.getLocalName()}" - <#if applicableType_has_next>, - - ], - <#if actiondef.parameterDefinitions?exists> - "parameterDefinitions" : - [ - <#list actiondef.parameterDefinitions as paramDef> - <@paramDefLib.paramDefJSON paramDef=paramDef/> - <#if paramDef_has_next>, - - ], - - "url" : "${url.serviceContext + "/api/rules/actiondefs/" + actiondef.name}" - } - - diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/actiondefs.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/actiondefs.get.desc.xml deleted file mode 100644 index ac02a62d07..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/actiondefs.get.desc.xml +++ /dev/null @@ -1,10 +0,0 @@ - - Get Action Definitions - Get the collection of action definitions, optionally scoped by node reference or path - /api/rules/actiondefs - /api/node/{store_type}/{store_id}/{id}/actiondefs - /api/path/{store_type}/{store_id}/{id}/actiondefs - argument - user - required - \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/actiondefs.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/actiondefs.get.json.ftl deleted file mode 100644 index 58ce3fbe19..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/actiondefs.get.json.ftl +++ /dev/null @@ -1,8 +0,0 @@ -<#import "actiondef.lib.ftl" as actionDefLib/> - -[ - <#list actiondefs as actiondef> - <@actionDefLib.actionDefJSON actiondef=actiondef/> - <#if actiondef_has_next>, - -] \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/actionqueue.post.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/actionqueue.post.desc.xml deleted file mode 100644 index f8b9e58c86..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/actionqueue.post.desc.xml +++ /dev/null @@ -1,8 +0,0 @@ - - Add to Action Queue - Add an Action Queue Item to the Action Queue for execution - /api/actionqueue - argument - user - required - diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/actionqueue.post.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/actionqueue.post.json.ftl deleted file mode 100644 index ca79ae0516..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/actionqueue.post.json.ftl +++ /dev/null @@ -1,3 +0,0 @@ -<#import "actionqueueitemstatus.lib.ftl" as actionQItemStatusLib/> - -<@actionQItemStatusLib.actionQItemStatusJSON actionQItemStatus=actionQItemStatus/> \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/actionqueueitemstatus.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/actionqueueitemstatus.lib.ftl deleted file mode 100644 index 9c337a12c3..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/actionqueueitemstatus.lib.ftl +++ /dev/null @@ -1,11 +0,0 @@ -<#macro actionQItemStatusJSON actionQItemStatus> - <#escape x as jsonUtils.encodeJSONString(x)> - { - "actionQueueItemStatusUrl" : "${url.serviceContext + "/api/actionqueue/items/" - + actionQItemStatus.actionQueueItemId + "/status"}", - "actionQueueItemId" : "{actionQItemStatus.actionQueueItemId}", - "status" : "${actionQItemStatus.status}", - "actionId" : "${actionQItemStatus.actionId}" - } - - diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/condition.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/condition.lib.ftl deleted file mode 100644 index 384ded2747..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/condition.lib.ftl +++ /dev/null @@ -1,17 +0,0 @@ -<#macro conditionJSON condition rule> -{ - "id" : "${condition.id}", - "conditionDefinitionName" : "${condition.actionConditionDefinitionName}", - "invertCondition" : "${condition.invertCondition?string("true", "false")}", - "parameterValues" : - { - <#list condition.parameterValues?keys as parameterKey> - "${parameterKey}" : "${condition.parameterValues[parameterKey]}" - <#if parameterKey_has_next>, - - }, - "url" : "${url.serviceContext + "/api/rules/" + rule.nodeRef.storeRef.protocol + "/" - + rule.nodeRef.storeRef.identifier + "/" + rule.nodeRef.id + "/conditions/" - + condition.id}" - } - diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/conditiondef.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/conditiondef.get.desc.xml deleted file mode 100644 index 1720a92ad8..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/conditiondef.get.desc.xml +++ /dev/null @@ -1,8 +0,0 @@ - - Get Condition Definition - Get a condition definition given its name - /api/rules/conditiondefs/{conditionDefinitionName} - argument - user - required - \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/conditiondef.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/conditiondef.get.json.ftl deleted file mode 100644 index bac65e023c..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/conditiondef.get.json.ftl +++ /dev/null @@ -1,4 +0,0 @@ -<#import "conditiondef.lib.ftl" as conditionDefLib/> - -<@conditionDefLib.conditionDefJSON conditiondef=conditiondef/> - \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/conditiondef.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/conditiondef.lib.ftl deleted file mode 100644 index e902d7c35f..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/conditiondef.lib.ftl +++ /dev/null @@ -1,26 +0,0 @@ -<#import "paramdef.lib.ftl" as paramDefLib/> - -<#macro conditionDefJSON conditiondef> - <#escape x as jsonUtils.encodeJSONString(x)> - { - "name" : "${conditiondef.name}", - <#if conditiondef.title?exists> - "title" : "${conditiondef.title}", - - <#if conditiondef.description?exists> - "description" : "${conditiondef.description}", - - "adhocPropertiesAllowed" : "${conditiondef.adhocPropertiesAllowed?string("true", "false")}", - <#if conditiondef.parameterDefinitions?exists> - "parameterDefinitions" : - [ - <#list conditiondef.parameterDefinitions as paramDef> - <@paramDefLib.paramDefJSON paramDef=paramDef/> - <#if paramDef_has_next>, - - ], - - "url" : "${url.serviceContext + "/api/rules/conditiondefs/" + conditiondef.name}" - } - - diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/conditiondefs.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/conditiondefs.get.desc.xml deleted file mode 100644 index 1413d7b3cb..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/conditiondefs.get.desc.xml +++ /dev/null @@ -1,8 +0,0 @@ - - Get Condition Definitions - Get the collection of condition definitions - /api/rules/conditiondefs - argument - user - required - \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/conditiondefs.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/conditiondefs.get.json.ftl deleted file mode 100644 index 296f33a61d..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/conditiondefs.get.json.ftl +++ /dev/null @@ -1,8 +0,0 @@ -<#import "conditiondef.lib.ftl" as conditionDefLib/> - -[ - <#list conditiondefs as conditiondef> - <@conditionDefLib.conditionDefJSON conditiondef=conditiondef/> - <#if conditiondef_has_next>, - -] \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/paramdef.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/paramdef.lib.ftl deleted file mode 100644 index 16121763ff..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/paramdef.lib.ftl +++ /dev/null @@ -1,12 +0,0 @@ -<#macro paramDefJSON paramDef> -{ - "name" : "${paramDef.name}", - <#if paramDef.displayLabel?exists> - "displayLabel" : "${paramDef.displayLabel}", - - "type" : "${paramDef.type}", - "multiValued" : ${paramDef.multiValued?string("true", "false")}, - "mandatory" : "${paramDef.mandatory?string("true", "false")}", - "url" : "${url.serviceContext + "/api/rules/parameterdefs/" + paramDef.name}" - } - \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.delete.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.delete.desc.xml deleted file mode 100644 index 51ac1bf85d..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.delete.desc.xml +++ /dev/null @@ -1,10 +0,0 @@ - - Delete Rule - Delete the rule identified by the specified rule node id. - /api/rules/{store_type}/{store_id}/{rule_id} - /api/node/{store_type}/{store_id}/{id}/rules/{rule_id} - /api/path/{store_type}/{store_id}/{id}/rules/{rule_id} - argument - user - required - \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.delete.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.delete.json.ftl deleted file mode 100644 index f81dc51f8d..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.delete.json.ftl +++ /dev/null @@ -1,3 +0,0 @@ -{ - "success": true -} \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.get.desc.xml deleted file mode 100644 index 309d8903a7..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.get.desc.xml +++ /dev/null @@ -1,10 +0,0 @@ - - Get Rule - Get the rule identified by the specified rule node reference. - /api/rules/{store_type}/{store_id}/{rule_id} - /api/node/{store_type}/{store_id}/{id}/rules/{rule_id} - /api/path/{store_type}/{store_id}/{id}/rules/{rule_id} - argument - user - required - \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.get.json.ftl deleted file mode 100644 index 71a03617ae..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.get.json.ftl +++ /dev/null @@ -1,2 +0,0 @@ -<#import "rule.lib.ftl" as ruleLib/> -<@ruleLib.ruleJSON rule=rule owningNodeRef=owningNodeRef/> \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.lib.ftl deleted file mode 100644 index be962e2380..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.lib.ftl +++ /dev/null @@ -1,25 +0,0 @@ -<#import "action.lib.ftl" as actionLib/> - -<#macro ruleJSON rule owningNodeRef> - <#escape x as jsonUtils.encodeJSONString(x)> - { - "ruleNodeRef" : "${rule.nodeRef}", - "title" : "${rule.title}", - "description" : "${rule.description}", - "ruleTypes" : - [ - <#list rule.ruleTypes as ruleType> - "${ruleType}" - <#if ruleType_has_next>, - - ], - "action" : <@actionLib.actionJSON action=rule.action rule=rule/>, - "owningNodeRef" : "${owningNodeRef}", - "executeAsync" : ${rule.executeAsynchronously?string("true", "false")}, - "ruleDisabled" : ${rule.ruleDisabled?string("true", "false")}, - "appliedToChildren" : ${rule.appliedToChildren?string("true", "false")}, - "url" : "${url.serviceContext + "/api/rules/" + rule.nodeRef.storeRef.protocol + "/" - + rule.nodeRef.storeRef.identifier + "/" + rule.nodeRef.id}" - } - - \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.put.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.put.desc.xml deleted file mode 100644 index d775144db6..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.put.desc.xml +++ /dev/null @@ -1,10 +0,0 @@ - - Put Rule - Update the rule identified by the specified rule node reference. - /api/rules/{store_type}/{store_id}/{rule_id} - /api/node/{store_type}/{store_id}/{id}/rules/{rule_id} - /api/path/{store_type}/{store_id}/{id}/rules/{rule_id} - argument - user - required - \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.put.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.put.json.ftl deleted file mode 100644 index 71a03617ae..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rule.put.json.ftl +++ /dev/null @@ -1,2 +0,0 @@ -<#import "rule.lib.ftl" as ruleLib/> -<@ruleLib.ruleJSON rule=rule owningNodeRef=owningNodeRef/> \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rules.delete.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rules.delete.desc.xml deleted file mode 100644 index 5601bde72d..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rules.delete.desc.xml +++ /dev/null @@ -1,10 +0,0 @@ - - Delete Rules - Delete the collection of rules which have been applied to the given rule owning node node. - /api/node/{store_type}/{store_id}/{id}/rules - /api/path/{store_type}/{store_id}/{id}/rules - /api/rules/appliedtonode/{store_type}/{store_id}/{id} - argument - user - required - \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rules.delete.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rules.delete.json.ftl deleted file mode 100644 index f81dc51f8d..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rules.delete.json.ftl +++ /dev/null @@ -1,3 +0,0 @@ -{ - "success": true -} \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rules.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rules.get.desc.xml deleted file mode 100644 index 64ca127a67..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rules.get.desc.xml +++ /dev/null @@ -1,10 +0,0 @@ - - Get Rules - Get the collection of rules which have been applied to the given (actionable) node. If the optional 'includeInherited' parameter is not provided, then rules inherited from the given node's parents are included by default. If the optional 'ruleTypeName' parameter is provided, then only rules of that specific given rule type are returned - /api/node/{store_type}/{store_id}/{id}/rules?includeInherited={includeInherited?}&ruleTypeName={ruleTypeName?} - /api/path/{store_type}/{store_id}/{id}/rules?includeInherited={includeInherited?}&ruleTypeName={ruleTypeName?} - /api/rules/appliedtonode/{store_type}/{store_id}/{id}?includeInherited={includeInherited?}&ruleTypeName={ruleTypeName?} - argument - user - required - \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rules.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rules.get.json.ftl deleted file mode 100644 index 6a5e1c6ee8..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rules.get.json.ftl +++ /dev/null @@ -1,8 +0,0 @@ -<#import "rule.lib.ftl" as ruleLib/> - -[ - <#list rules as rule> - <@ruleLib.ruleJSON rule=rule owningNodeRef=owningNodeRef/> - <#if rule_has_next>, - -] diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rules.post.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rules.post.desc.xml deleted file mode 100644 index a03b1f7df3..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rules.post.desc.xml +++ /dev/null @@ -1,10 +0,0 @@ - - Create Rule - Creates a rule in the rule collection associated with the given actionable node - /api/node/{store_type}/{store_id}/{id}/rules - /api/path/{store_type}/{store_id}/{id}/rules - /api/rules/appliedtonode/{store_type}/{store_id}/{id} - argument - user - required - diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rules.post.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rules.post.json.ftl deleted file mode 100644 index 71a03617ae..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rule/rules.post.json.ftl +++ /dev/null @@ -1,2 +0,0 @@ -<#import "rule.lib.ftl" as ruleLib/> -<@ruleLib.ruleJSON rule=rule owningNodeRef=owningNodeRef/> \ No newline at end of file diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml index 33d4b4f60f..d3474ecb44 100644 --- a/config/alfresco/web-scripts-application-context.xml +++ b/config/alfresco/web-scripts-application-context.xml @@ -536,102 +536,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/source/java/org/alfresco/repo/web/scripts/rule/ActionDefGet.java b/source/java/org/alfresco/repo/web/scripts/rule/ActionDefGet.java deleted file mode 100644 index b16731311d..0000000000 --- a/source/java/org/alfresco/repo/web/scripts/rule/ActionDefGet.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have received a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" - */ -package org.alfresco.repo.web.scripts.rule; - -import java.util.HashMap; -import java.util.Map; - -import org.alfresco.service.cmr.action.ActionDefinition; -import org.alfresco.service.cmr.action.ActionService; -import org.springframework.extensions.webscripts.DeclarativeWebScript; -import org.springframework.extensions.webscripts.Status; -import org.springframework.extensions.webscripts.WebScriptException; -import org.springframework.extensions.webscripts.WebScriptRequest; - -/** - * Web Script to GET an action definition given its name - * - * @author glen johnson at alfresco dot com - */ -public class ActionDefGet extends DeclarativeWebScript -{ - // model property keys - private static final String MODEL_PROP_KEY_ACTION_DEF = "actiondef"; - - // private constants - private static final String REQ_PARAM_ACTION_DEF_NAME = "actionDefinitionName"; - - // properties for services - private ActionService actionService; - - /** - * Set the actionService property. - * - * @param actionService The action service instance to set - */ - public void setActionService(ActionService actionService) - { - this.actionService = actionService; - } - - /* - * (non-Javadoc) - * - * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl( - * org.alfresco.web.scripts.WebScriptRequest, - * org.alfresco.web.scripts.WebScriptResponse) - */ - @Override - protected Map executeImpl(WebScriptRequest req, - Status status) - { - // initialise model to pass on for template to render - Map model = new HashMap(); - - // get actionDefinitionName URL template variable - String actionDefName = req.getServiceMatch().getTemplateVars().get(REQ_PARAM_ACTION_DEF_NAME); - if ((actionDefName == null) || (actionDefName.length() == 0)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "The 'actionDefinitionName' URL parameter has not been provided in URL"); - } - - // get an action definition with the given action definition name - ActionDefinition actionDef = this.actionService.getActionDefinition(actionDefName); - - // add objects to model for the template to render - model.put(MODEL_PROP_KEY_ACTION_DEF, actionDef); - - return model; - } -} diff --git a/source/java/org/alfresco/repo/web/scripts/rule/ActionDefsGet.java b/source/java/org/alfresco/repo/web/scripts/rule/ActionDefsGet.java deleted file mode 100644 index 9b2c8c672a..0000000000 --- a/source/java/org/alfresco/repo/web/scripts/rule/ActionDefsGet.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have received a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" - */ -package org.alfresco.repo.web.scripts.rule; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.alfresco.service.cmr.action.ActionDefinition; -import org.alfresco.service.cmr.action.ActionService; -import org.alfresco.service.cmr.repository.NodeRef; -import org.springframework.extensions.webscripts.DeclarativeWebScript; -import org.springframework.extensions.webscripts.Status; -import org.springframework.extensions.webscripts.WebScriptRequest; - -/** - * Web Script to GET the action definition collection - * This can optionally be scoped by by either - * - a node reference in the form /api/node/{store_type}/{store_id}/{id} on the URL - * - a node path in the form /api/path/{store_type}/{store_id}/{id} on the URL - * - * @author glen johnson at alfresco dot com - */ -public class ActionDefsGet extends DeclarativeWebScript -{ - // private constants - private static final String REQ_URL_TEMPL_VAR_STORE_TYPE = "store_type"; - private static final String REQ_URL_TEMPL_VAR_STORE_ID = "store_id"; - private static final String REQ_URL_TEMPL_VAR_ID = "id"; - - // model property keys - private static final String MODEL_PROP_KEY_ACTION_DEFS = "actiondefs"; - - // properties for services & dependencies - private ActionService actionService; - private RulesHelper rulesHelper; - - /** - * Set the actionService property. - * - * @param actionService The action service instance to set - */ - public void setActionService(ActionService actionService) - { - this.actionService = actionService; - } - - /** - * Set the rules helper - * - * @param rulesHelper the rulesHelper to set - */ - public void setRulesHelper(RulesHelper rulesHelper) - { - this.rulesHelper = rulesHelper; - } - - /* - * (non-Javadoc) - * - * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl( - * org.alfresco.web.scripts.WebScriptRequest, - * org.alfresco.web.scripts.WebScriptResponse) - */ - @Override - protected Map executeImpl(WebScriptRequest req, - Status status) - { - // initialise model to pass on for template to render - Map model = new HashMap(); - - // get the template variables for store_type, store_id and id - String storeType = req.getServiceMatch().getTemplateVars().get(REQ_URL_TEMPL_VAR_STORE_TYPE); - String storeId = req.getServiceMatch().getTemplateVars().get(REQ_URL_TEMPL_VAR_STORE_ID); - String id = req.getServiceMatch().getTemplateVars().get(REQ_URL_TEMPL_VAR_ID); - - // work out which of storeType, storeId, id template variables have been given - boolean storeTypeGiven = (storeType != null) && (storeType.length() > 0); - boolean storeIdGiven = (storeId != null) && (storeId.length() > 0); - boolean idGiven = (id != null) && (id.length() > 0); - - List actionDefs = null; - - // - // if either a node reference or path are provided to scope the action - // definition collection by, then obtain a reference to that node - // - if ((storeTypeGiven && storeIdGiven && idGiven)) - { - // get the node reference to scope the action definitions by - NodeRef scopeByNodeRef = this.rulesHelper.getNodeRefFromWebScriptUrl(req, storeType, storeId, id); - - // get all the action definitions that are applicable for the node reference - actionDefs = this.actionService.getActionDefinitions(scopeByNodeRef); - } - // else not scoped by noderef, so get all the condition definitions - else - { - actionDefs = this.actionService.getActionDefinitions(); - } - - // add objects to model for the template to render - model.put(MODEL_PROP_KEY_ACTION_DEFS, actionDefs); - - return model; - } -} diff --git a/source/java/org/alfresco/repo/web/scripts/rule/ActionQueueItemStatus.java b/source/java/org/alfresco/repo/web/scripts/rule/ActionQueueItemStatus.java deleted file mode 100644 index 9b35a7c355..0000000000 --- a/source/java/org/alfresco/repo/web/scripts/rule/ActionQueueItemStatus.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have received a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" - */ -package org.alfresco.repo.web.scripts.rule; - -/** - * This class defines a bean that encapsulates the - * properties present in ActionQueueItemStatus Details - * returned from the Action Queue resource - * - * @author glen johnson at alfresco com - */ -public class ActionQueueItemStatus -{ - // bean property member variables - - /** - * ID allocated to the action queue item when it is added to the action queue resource - */ - private String actionQueueItemId; - - /** - * Execution status for the respective action queue item - * Value is one of "PENDING", "COMPLETE" - */ - private String status = null; - - /** - * ID of the action (associated with this status) which is part of the action queue item - */ - private String actionId; - - /** - * Return the ID of the action queue item - * - * @return the action queue item ID - */ - public String getActionQueueItemId() - { - return actionQueueItemId; - } - - /** - * Sets the ID of the action queue item - * - * @param actionQueueItemId the action queue item id to set - */ - public void setActionQueueItemId(String actionQueueItemId) - { - this.actionQueueItemId = actionQueueItemId; - } - - /** - * Get the status - * - * @return the status - */ - public String getStatus() - { - return status; - } - - /** - * Set the status - * - * @param status the status to set - */ - public void setStatus(String status) - { - this.status = status; - } - - /** - * Get the action id - * - * @return the actionId - */ - public String getActionId() - { - return actionId; - } - - /** - * Set the action ID - * - * @param actionId the actionId to set - */ - public void setActionId(String actionId) - { - this.actionId = actionId; - } -} diff --git a/source/java/org/alfresco/repo/web/scripts/rule/ActionQueuePost.java b/source/java/org/alfresco/repo/web/scripts/rule/ActionQueuePost.java deleted file mode 100644 index 9d31aa7d70..0000000000 --- a/source/java/org/alfresco/repo/web/scripts/rule/ActionQueuePost.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have received a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" - */ -package org.alfresco.repo.web.scripts.rule; - -import java.util.HashMap; -import java.util.Map; - -import org.alfresco.service.cmr.action.Action; -import org.alfresco.service.cmr.action.ActionService; -import org.alfresco.service.cmr.repository.NodeRef; -import org.springframework.extensions.webscripts.DeclarativeWebScript; -import org.springframework.extensions.webscripts.Status; -import org.springframework.extensions.webscripts.WebScriptException; -import org.springframework.extensions.webscripts.WebScriptRequest; -import org.json.JSONException; -import org.json.JSONObject; - -/** - * Web Script to POST an Action Queue Item onto the Action Queue - * - * @author glen johnson at alfresco dot com - */ -public class ActionQueuePost extends DeclarativeWebScript -{ - // model property keys - private static final String MODEL_PROP_KEY_ACTION_Q_ITEM_STATUS = "actionQItemStatus"; - - // properties for services - private ActionService actionService; - - // properties for dependencies - private RulesHelper rulesHelper; - - /** - * @param actionService the actionService to set - */ - public void setActionService(ActionService actionService) - { - this.actionService = actionService; - } - - /** - * Set the rules helper property - * - * @param rulesHelper the rulesHelper to set - */ - public void setRulesHelper(RulesHelper rulesHelper) - { - this.rulesHelper = rulesHelper; - } - - /* - * (non-Javadoc) - * - * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl( - * org.alfresco.web.scripts.WebScriptRequest, - * org.alfresco.web.scripts.WebScriptResponse) - */ - @SuppressWarnings("unchecked") - @Override - protected Map executeImpl(WebScriptRequest req, - Status status) - { - // initialise model to pass on to template for rendering - Map model = new HashMap(); - - // get the posted action queue item JSON object by parsing request content - Object contentObj = req.parseContent(); - if (contentObj == null || !(contentObj instanceof JSONObject)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Web Script request content must be a JSON Object. " - + "Request content is either a JSON Array or not of MIME-type application/json"); - } - - JSONObject actionJson = null; - Action action = null; - boolean checkConditions = true; - boolean executeAsynchronously = false; - NodeRef actionedUponNodeRef = null; - try - { - // get action queue item JSON object cast from contentObj - JSONObject actionQueueItemJson = (JSONObject)contentObj; - - // get action JSON object from actionQueueItem JSON - actionJson = actionQueueItemJson.getJSONObject("action"); - - // get the action from the action JSON object - action = this.rulesHelper.getActionFromJson(actionJson, null); - - // Get 'checkConditions' and 'executeAsynchronously' properties off action queue item - checkConditions = actionQueueItemJson.optBoolean("checkConditions", true); - executeAsynchronously = actionQueueItemJson.optBoolean( - "executeAsync", action.getExecuteAsychronously()); - - // get the actioned-upon node reference - String nodeRefStr = actionQueueItemJson.getString("nodeRef"); - actionedUponNodeRef = new NodeRef(nodeRefStr); - } - catch (JSONException je) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "Problem retrieving properties from ActionQueueItem Details sent in the request content.", je); - } - - // apply rule to actionable node - this.actionService.executeAction(action, actionedUponNodeRef, checkConditions, executeAsynchronously); - - // create the action queue item status bean - // to be rendered by the template - ActionQueueItemStatus actionQItemStatus = new ActionQueueItemStatus(); - - // - // set the action queue item id on the action queue item status bean - // - - String actionedUponNodeId = actionedUponNodeRef.getId(); - String actionId = action.getId(); - String actionQItemId = actionId + ":" + actionedUponNodeId; - actionQItemStatus.setActionQueueItemId(actionQItemId); - - // set the action id on the action queue item status bean - actionQItemStatus.setActionId(actionId); - - // set the status on the action queue item status bean - if (executeAsynchronously == true) - { - actionQItemStatus.setStatus(RulesHelper.ACTION_QUEUE_ITEM_STATUS_PENDING); - } - else - { - actionQItemStatus.setStatus(RulesHelper.ACTION_QUEUE_ITEM_STATUS_COMPLETE); - } - - // add objects to model for the template to render - model.put(MODEL_PROP_KEY_ACTION_Q_ITEM_STATUS, actionQItemStatus); - - return model; - } -} diff --git a/source/java/org/alfresco/repo/web/scripts/rule/ConditionDefGet.java b/source/java/org/alfresco/repo/web/scripts/rule/ConditionDefGet.java deleted file mode 100644 index 16f73bb321..0000000000 --- a/source/java/org/alfresco/repo/web/scripts/rule/ConditionDefGet.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have received a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" - */ -package org.alfresco.repo.web.scripts.rule; - -import java.util.HashMap; -import java.util.Map; - -import org.alfresco.service.cmr.action.ActionConditionDefinition; -import org.alfresco.service.cmr.action.ActionService; -import org.springframework.extensions.webscripts.DeclarativeWebScript; -import org.springframework.extensions.webscripts.Status; -import org.springframework.extensions.webscripts.WebScriptException; -import org.springframework.extensions.webscripts.WebScriptRequest; - -/** - * Web Script to GET a condition definition given its name - * - * @author glen johnson at alfresco dot com - */ -public class ConditionDefGet extends DeclarativeWebScript -{ - // model property keys - private static final String MODEL_PROP_KEY_CONDITION_DEF = "conditiondef"; - - // private constants - private static final String REQ_PARAM_CONDITION_DEF_NAME = "conditionDefinitionName"; - - // properties for services - private ActionService actionService; - - /** - * Set the actionService property. - * - * @param actionService The action service instance to set - */ - public void setActionService(ActionService actionService) - { - this.actionService = actionService; - } - - /* - * (non-Javadoc) - * - * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl( - * org.alfresco.web.scripts.WebScriptRequest, - * org.alfresco.web.scripts.WebScriptResponse) - */ - @Override - protected Map executeImpl(WebScriptRequest req, - Status status) - { - // initialise model to pass on for template to render - Map model = new HashMap(); - - // get conditionDefinitionName URL template variable - String conditionDefName = req.getServiceMatch().getTemplateVars().get(REQ_PARAM_CONDITION_DEF_NAME); - if ((conditionDefName == null) || (conditionDefName.length() == 0)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "The 'conditionDefinitionName' URL parameter has not been provided in URL"); - } - - // get a condition definition with the given condition definition name - ActionConditionDefinition conditionDef = this.actionService.getActionConditionDefinition(conditionDefName); - - // add objects to model for the template to render - model.put(MODEL_PROP_KEY_CONDITION_DEF, conditionDef); - - return model; - } -} diff --git a/source/java/org/alfresco/repo/web/scripts/rule/ConditionDefsGet.java b/source/java/org/alfresco/repo/web/scripts/rule/ConditionDefsGet.java deleted file mode 100644 index 7b43cb6217..0000000000 --- a/source/java/org/alfresco/repo/web/scripts/rule/ConditionDefsGet.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have received a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" - */ -package org.alfresco.repo.web.scripts.rule; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.alfresco.service.cmr.action.ActionConditionDefinition; -import org.alfresco.service.cmr.action.ActionService; -import org.springframework.extensions.webscripts.DeclarativeWebScript; -import org.springframework.extensions.webscripts.Status; -import org.springframework.extensions.webscripts.WebScriptRequest; - -/** - * Web Script to GET the condition definition collection - * - * @author glen johnson at alfresco dot com - */ -public class ConditionDefsGet extends DeclarativeWebScript -{ - // model property keys - private static final String MODEL_PROP_KEY_CONDITION_DEFS = "conditiondefs"; - - // properties for services - private ActionService actionService; - - /** - * Set the actionService property. - * - * @param actionService The action service instance to set - */ - public void setActionService(ActionService actionService) - { - this.actionService = actionService; - } - - /* - * (non-Javadoc) - * - * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl( - * org.alfresco.web.scripts.WebScriptRequest, - * org.alfresco.web.scripts.WebScriptResponse) - */ - @Override - protected Map executeImpl(WebScriptRequest req, - Status status) - { - // initialise model to pass on for template to render - Map model = new HashMap(); - - // get all the condition definitions - List conditionDefs = this.actionService.getActionConditionDefinitions(); - - // add objects to model for the template to render - model.put(MODEL_PROP_KEY_CONDITION_DEFS, conditionDefs); - - return model; - } -} diff --git a/source/java/org/alfresco/repo/web/scripts/rule/RuleDelete.java b/source/java/org/alfresco/repo/web/scripts/rule/RuleDelete.java deleted file mode 100644 index a488c908c8..0000000000 --- a/source/java/org/alfresco/repo/web/scripts/rule/RuleDelete.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have received a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" - */ -package org.alfresco.repo.web.scripts.rule; - -import java.util.Map; - -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.rule.Rule; -import org.alfresco.service.cmr.rule.RuleService; -import org.springframework.extensions.webscripts.DeclarativeWebScript; -import org.springframework.extensions.webscripts.Status; -import org.springframework.extensions.webscripts.WebScriptException; -import org.springframework.extensions.webscripts.WebScriptRequest; - -/** - * Web Script to DELETE the rule identified by the given rule node id. - * - * NOTE - - * that if a value is provided for the 'id' URL template variable {id}, - * i.e. either of the following URL patterns have been used - * /api/node/{store_type}/{store_id}/{id}/rules/{rule_id} or - * /api/path/{store_type}/{store_id}/{id}/rules/{rule_id} - * then the rule owning node ref supplied therein will be ignored, - * as these URL templates are just provided for convenience and the - * rule owning node ref is retrieved by using the rule's identifying node - * ref (supplied in {rule_id}) - * - * @author glen johnson at alfresco dot com - */ -public class RuleDelete extends DeclarativeWebScript -{ - // private constants - private static final String REQ_TEMPL_VAR_STORE_TYPE = "store_type"; - private static final String REQ_TEMPL_VAR_STORE_ID = "store_id"; - private static final String REQ_TEMPL_VAR_RULE_NODE_ID = "rule_id"; - - // properties for services - private RuleService ruleService; - - // dependencies - private RulesHelper rulesHelper; - - /** - * Set the ruleService property. - * - * @param ruleService The rule service instance to set - */ - public void setRuleService(RuleService ruleService) - { - this.ruleService = ruleService; - } - - /** - * Set the rules helper property - * - * @param rulesHelper the rulesHelper to set - */ - public void setRulesHelper(RulesHelper rulesHelper) - { - this.rulesHelper = rulesHelper; - } - - /* - * (non-Javadoc) - * - * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl( - * org.alfresco.web.scripts.WebScriptRequest, - * org.alfresco.web.scripts.WebScriptResponse) - */ - @Override - protected Map executeImpl(WebScriptRequest req, - Status status) - { - String storeType = req.getServiceMatch().getTemplateVars().get(REQ_TEMPL_VAR_STORE_TYPE); - // Handle if 'store_type' URL template token not provided - if ((storeType == null) || (storeType.length() == 0)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "The 'store_type' URL template token has not been provided in URL"); - } - - String storeId = req.getServiceMatch().getTemplateVars().get(REQ_TEMPL_VAR_STORE_ID); - // Handle if 'storeId' URL template token not provided - if ((storeId == null) || (storeId.length() == 0)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "The 'storeId' URL template token has not been provided in URL"); - } - - String ruleNodeId = req.getServiceMatch().getTemplateVars().get(REQ_TEMPL_VAR_RULE_NODE_ID); - // Handle if 'rule_id' URL template token not provided - if ((ruleNodeId == null) || (ruleNodeId.length() == 0)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "The 'rule_id' URL template token has not been provided in URL"); - } - - // create the rule's identifying node reference from the given - // URL template tokens - NodeRef ruleNodeRef = this.rulesHelper.getNodeRefFromWebScriptUrl(req, storeType, storeId, ruleNodeId); - - // if ruleNodeRef referred to by {store_type} {store_id} {rule_id} is 'null' then the rule identified by that - // given node id or node path no longer exists - if (ruleNodeRef == null) - { - throw new WebScriptException(Status.STATUS_NOT_FOUND, "Rule identified by rule node/path - 'store_type': " - + storeType + " 'store_id': " + storeId + " and 'rule_id': " + ruleNodeId + " could not be found"); - } - - Rule rule = this.ruleService.getRule(ruleNodeRef); - NodeRef ruleOwningNodeRef = this.ruleService.getOwningNodeRef(rule); - - // delete rule - this.ruleService.removeRule(ruleOwningNodeRef, rule); - - return null; - } -} diff --git a/source/java/org/alfresco/repo/web/scripts/rule/RuleGet.java b/source/java/org/alfresco/repo/web/scripts/rule/RuleGet.java deleted file mode 100644 index cebbb91b93..0000000000 --- a/source/java/org/alfresco/repo/web/scripts/rule/RuleGet.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have received a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" - */ -package org.alfresco.repo.web.scripts.rule; - -import java.util.HashMap; -import java.util.Map; - -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.rule.Rule; -import org.alfresco.service.cmr.rule.RuleService; -import org.springframework.extensions.webscripts.DeclarativeWebScript; -import org.springframework.extensions.webscripts.Status; -import org.springframework.extensions.webscripts.WebScriptException; -import org.springframework.extensions.webscripts.WebScriptRequest; - -/** - * Web Script to GET the rule identified by the given rule node reference. - * - * NOTE - - * that if a value is provided for the 'id' URL template variable {id}, - * i.e. either of the following URL patterns have been used - * /api/node/{store_type}/{store_id}/{id}/rules/{rule_id} or - * /api/path/{store_type}/{store_id}/{id}/rules/{rule_id} - * then the rule owning node ref supplied therein will be ignored, - * as these URL templates are just provided for convenience and the - * rule owning node ref is retrieved by using the rule's identifying node - * ref (supplied in {rule_id}) - * - * @author glen johnson at alfresco dot com - */ -public class RuleGet extends DeclarativeWebScript -{ - // private constants - private static final String REQ_TEMPL_VAR_STORE_TYPE = "store_type"; - private static final String REQ_TEMPL_VAR_STORE_ID = "store_id"; - private static final String REQ_TEMPL_VAR_RULE_NODE_ID = "rule_id"; - - // model property keys - private static final String MODEL_PROP_KEY_RULE = "rule"; - private static final String MODEL_PROP_KEY_OWNING_NODE_REF = "owningNodeRef"; - - // properties for services - private RuleService ruleService; - - // dependencies - private RulesHelper rulesHelper; - - /** - * Set the ruleService property. - * - * @param ruleService The rule service instance to set - */ - public void setRuleService(RuleService ruleService) - { - this.ruleService = ruleService; - } - - /** - * Set the rules helper property - * - * @param rulesHelper the rulesHelper to set - */ - public void setRulesHelper(RulesHelper rulesHelper) - { - this.rulesHelper = rulesHelper; - } - - /* - * (non-Javadoc) - * - * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl( - * org.alfresco.web.scripts.WebScriptRequest, - * org.alfresco.web.scripts.WebScriptResponse) - */ - @Override - protected Map executeImpl(WebScriptRequest req, - Status status) - { - // initialise model to pass on for template to render - Map model = new HashMap(); - - String storeType = req.getServiceMatch().getTemplateVars().get(REQ_TEMPL_VAR_STORE_TYPE); - // Handle if 'store_type' URL template token not provided - if ((storeType == null) || (storeType.length() == 0)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "The 'store_type' URL template token has not been provided in URL"); - } - - String storeId = req.getServiceMatch().getTemplateVars().get(REQ_TEMPL_VAR_STORE_ID); - // Handle if 'storeId' URL template token not provided - if ((storeId == null) || (storeId.length() == 0)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "The 'storeId' URL template token has not been provided in URL"); - } - - String ruleNodeId = req.getServiceMatch().getTemplateVars().get(REQ_TEMPL_VAR_RULE_NODE_ID); - // Handle if 'ruleNodeId' URL template token not provided - if ((ruleNodeId == null) || (ruleNodeId.length() == 0)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "The 'ruleNodeId' URL template token has not been provided in URL"); - } - - // create the rule node reference from the given - // URL template tokens - NodeRef ruleNodeRef = this.rulesHelper.getNodeRefFromWebScriptUrl(req, storeType, storeId, ruleNodeId); - - // if ruleNodeRef referred to by {store_type} {store_id} {rule_id} is 'null' then the rule identified by that - // given node id or node path no longer exists - if (ruleNodeRef == null) - { - throw new WebScriptException(Status.STATUS_NOT_FOUND, "Rule identified by rule node/path - 'store_type': " - + storeType + " 'store_id': " + storeId + " and 'rule_id': " + ruleNodeId + " could not be found"); - } - - // get rule identified by the given rule node reference - Rule rule = this.ruleService.getRule(ruleNodeRef); - - // get rule's owning node - NodeRef ruleOwningNodeRef = this.ruleService.getOwningNodeRef(rule); - - // add objects to model for the template to render - model.put(MODEL_PROP_KEY_RULE, rule); - model.put(MODEL_PROP_KEY_OWNING_NODE_REF, ruleOwningNodeRef.toString()); - - return model; - } -} diff --git a/source/java/org/alfresco/repo/web/scripts/rule/RulePut.java b/source/java/org/alfresco/repo/web/scripts/rule/RulePut.java deleted file mode 100644 index b0b7faa108..0000000000 --- a/source/java/org/alfresco/repo/web/scripts/rule/RulePut.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have received a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" - */ -package org.alfresco.repo.web.scripts.rule; - -import java.util.HashMap; -import java.util.Map; - -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.rule.Rule; -import org.alfresco.service.cmr.rule.RuleService; -import org.springframework.extensions.webscripts.DeclarativeWebScript; -import org.springframework.extensions.webscripts.Status; -import org.springframework.extensions.webscripts.WebScriptException; -import org.springframework.extensions.webscripts.WebScriptRequest; -import org.json.JSONObject; - -/** - * Web Script to PUT (update) the rule identified by the given rule node reference. - * - * NOTE - - * that if a value is provided for the 'id' URL template variable {id}, - * i.e. either of the following URL patterns have been used - * /api/node/{store_type}/{store_id}/{id}/rules/{rule_id} or - * /api/path/{store_type}/{store_id}/{id}/rules/{rule_id} - * then the rule owning node ref supplied therein will be ignored, - * as these URL templates are just provided for convenience and the - * rule owning node ref is retrieved by using the rule's identifying node - * ref (supplied in {rule_id}) - * - * @author glen johnson at alfresco dot com - */ -public class RulePut extends DeclarativeWebScript -{ - // private constants - private static final String REQ_TEMPL_VAR_STORE_TYPE = "store_type"; - private static final String REQ_TEMPL_VAR_STORE_ID = "store_id"; - private static final String REQ_TEMPL_VAR_RULE_NODE_ID = "rule_id"; - - // model property keys - private static final String MODEL_PROP_KEY_RULE = "rule"; - private static final String MODEL_PROP_KEY_OWNING_NODE_REF = "owningNodeRef"; - - // properties for services - private RuleService ruleService; - - // dependencies - private RulesHelper rulesHelper; - - /** - * Set the ruleService property. - * - * @param ruleService The rule service instance to set - */ - public void setRuleService(RuleService ruleService) - { - this.ruleService = ruleService; - } - - /** - * Set the rules helper - * - * @param rulesHelper the rulesHelper to set - */ - public void setRulesHelper(RulesHelper rulesHelper) - { - this.rulesHelper = rulesHelper; - } - - /* - * (non-Javadoc) - * - * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl( - * org.alfresco.web.scripts.WebScriptRequest, - * org.alfresco.web.scripts.WebScriptResponse) - */ - @SuppressWarnings("unchecked") - @Override - protected Map executeImpl(WebScriptRequest req, - Status status) - { - // initialise model to pass on for template to render - Map model = new HashMap(); - - String storeType = req.getServiceMatch().getTemplateVars().get(REQ_TEMPL_VAR_STORE_TYPE); - // Handle if 'store_type' URL template token not provided - if ((storeType == null) || (storeType.length() == 0)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "The 'store_type' URL template token has not been provided in URL"); - } - - String storeId = req.getServiceMatch().getTemplateVars().get(REQ_TEMPL_VAR_STORE_ID); - // Handle if 'storeId' URL template token not provided - if ((storeId == null) || (storeId.length() == 0)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "The 'storeId' URL template token has not been provided in URL"); - } - - String ruleNodeId = req.getServiceMatch().getTemplateVars().get(REQ_TEMPL_VAR_RULE_NODE_ID); - // Handle if 'ruleNodeId' URL template token not provided - if ((ruleNodeId == null) || (ruleNodeId.length() == 0)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "The 'ruleNodeId' URL template token has not been provided in URL"); - } - - // create the rule node reference from the given - // URL template tokens - NodeRef ruleNodeRef = this.rulesHelper.getNodeRefFromWebScriptUrl(req, storeType, storeId, ruleNodeId); - - // if ruleNodeRef referred to by {store_type} {store_id} {rule_id} is 'null' then the rule identified by that - // given node id or node path no longer exists - if (ruleNodeRef == null) - { - throw new WebScriptException(Status.STATUS_NOT_FOUND, "Rule identified by rule node/path - 'store_type': " - + storeType + " 'store_id': " + storeId + " and 'rule_id': " + ruleNodeId + " could not be found"); - } - - // get the rule JSON object sent in the request content (when PUTting the Rule) - Object contentObj = req.parseContent(); - if (contentObj == null || !(contentObj instanceof JSONObject)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Web Script request content must be a JSON Object. " - + "Request content is either a JSON Array or not of MIME-type application/json"); - } - JSONObject ruleJson = (JSONObject)contentObj; - - // update the rule object identified by the given rule node reference - // with the details in the rule JSON - Rule rule = this.rulesHelper.getRuleFromJson(ruleJson, ruleNodeRef); - - // get owning node ref that rule was - // previous applied to - NodeRef ruleOwningNodeRef = this.ruleService.getOwningNodeRef(rule); - - // re-apply rule to owning node - this.ruleService.saveRule(ruleOwningNodeRef, rule); - - // add objects to model for the template to render - model.put(MODEL_PROP_KEY_RULE, rule); - model.put(MODEL_PROP_KEY_OWNING_NODE_REF, ruleOwningNodeRef.toString()); - - return model; - } -} diff --git a/source/java/org/alfresco/repo/web/scripts/rule/RuleServiceTest.java b/source/java/org/alfresco/repo/web/scripts/rule/RuleServiceTest.java deleted file mode 100644 index 999c63f793..0000000000 --- a/source/java/org/alfresco/repo/web/scripts/rule/RuleServiceTest.java +++ /dev/null @@ -1,1180 +0,0 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have received a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" - */ -package org.alfresco.repo.web.scripts.rule; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.alfresco.model.ContentModel; -import org.alfresco.repo.action.evaluator.CompareMimeTypeEvaluator; -import org.alfresco.repo.action.evaluator.ComparePropertyValueEvaluator; -import org.alfresco.repo.action.executer.CompositeActionExecuter; -import org.alfresco.repo.action.executer.CopyActionExecuter; -import org.alfresco.repo.action.executer.MoveActionExecuter; -import org.alfresco.repo.security.authentication.AuthenticationComponent; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; -import org.alfresco.repo.web.scripts.BaseWebScriptTest; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.rule.RuleType; -import org.alfresco.service.cmr.security.AuthenticationService; -import org.alfresco.service.cmr.security.PersonService; -import org.alfresco.service.namespace.NamespaceService; -import org.alfresco.service.namespace.QName; -import org.alfresco.util.PropertyMap; -import org.springframework.extensions.webscripts.Status; -import org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest; -import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest; -import org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest; -import org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest; -import org.springframework.extensions.webscripts.TestWebScriptServer.Response; -import org.json.JSONArray; -import org.json.JSONObject; - -/** - * Test Case class with unit tests for Rule REST API - * - * @author Glen Johnson at Alfresco dot com - */ -public class RuleServiceTest extends BaseWebScriptTest -{ - // member variables for service instances - private AuthenticationService authenticationService; - private AuthenticationComponent authenticationComponent; - private NodeService nodeService; - private PersonService personService; - - private NodeRef owningNodeRef1; - private NodeRef testDestFolder1; - private NodeRef testDestFolder2; - - // private constants - private static final String RULES_USER = "Rules.User"; - private static final String RULES_USER_PASSWORD = "password"; - private static final String RULES_TEST_OWNING_FOLDER_1 = "rulesTestOwningFolder1"; - private static final String RULES_TEST_DEST_FOLDER_1 = "rulesTestDestinationFolder1"; - private static final String RULES_TEST_DEST_FOLDER_2 = "rulesTestDestinationFolder2"; - - @Override - protected void setUp() throws Exception - { - super.setUp(); - - // get references to services - this.authenticationService = (AuthenticationService) getServer().getApplicationContext().getBean( - "AuthenticationService"); - this.authenticationComponent = (AuthenticationComponent) getServer().getApplicationContext().getBean( - "AuthenticationComponent"); - this.nodeService = (NodeService) getServer().getApplicationContext().getBean("NodeService"); - this.personService = (PersonService) getServer().getApplicationContext().getBean("PersonService"); - - // - // various setup operations which need to be run as system user - // - AuthenticationUtil.runAs(new RunAsWork() - { - public Object doWork() throws Exception - { - createUserAndAssocPerson(RULES_USER); - - return null; - } - }, AuthenticationUtil.getSystemUserName()); - - // Do tests as inviter user - this.authenticationComponent.setCurrentUser(RULES_USER); - - // create a folder (as the rule owning node) under the current user's home space - NodeRef personRef = this.personService.getPerson(RULES_USER); - NodeRef userHomeRef = (NodeRef)nodeService.getProperty(personRef, ContentModel.PROP_HOMEFOLDER); - this.owningNodeRef1 = this.nodeService.createNode(userHomeRef, ContentModel.ASSOC_CONTAINS, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, RULES_TEST_OWNING_FOLDER_1), - ContentModel.TYPE_FOLDER).getChildRef(); - - // create other folders for testing purposes - this.testDestFolder1 = this.nodeService.createNode(userHomeRef, ContentModel.ASSOC_CONTAINS, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, RULES_TEST_DEST_FOLDER_1), - ContentModel.TYPE_FOLDER).getChildRef(); - this.testDestFolder2 = this.nodeService.createNode(userHomeRef, ContentModel.ASSOC_CONTAINS, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, RULES_TEST_DEST_FOLDER_2), - ContentModel.TYPE_FOLDER).getChildRef(); - } - - @Override - protected void tearDown() throws Exception - { - super.tearDown(); - - // delete the actionable node created in setUp() - // TODO uncomment this when I am no longer comparing - // insync with JSF Web Client - // - // this.nodeService.deleteNode(this.actionableNodeRef); - - // - // run various teardown operations which need to be run as 'admin' - // - // TODO uncomment this when I am no longer comparing - // insync with JSF Web Client - // - // RunAsWork runAsWork = new RunAsWork() - // { - // public Object doWork() throws Exception - // { - // deleteUserAndAssocPerson(RULES_USER); - // - // return null; - // } - // ; - // AuthenticationUtil.runAs(runAsWork, AuthenticationUtil.getSystemUserName()); - } - - /** - * Get a URL to the Rule Collection associated with the given rule owning - * node - * - * @param ruleOwningNodeRef - * the rule owning node reference - * @return the URL to the rule collection associated with the given - * rule owning node - */ - private String getRulesNodeBasedUrl(NodeRef ruleOwningNodeRef, - Boolean includeInherited, String ruleTypeName) - { - boolean includeInheritedParamGiven = includeInherited != null; - boolean ruleTypeNameParamGiven = (ruleTypeName != null) && (ruleTypeName.length() > 0); - boolean parameterGiven = (includeInheritedParamGiven || ruleTypeNameParamGiven); - - String url = "/api/node/" - + ruleOwningNodeRef.getStoreRef().getProtocol() + "/" - + ruleOwningNodeRef.getStoreRef().getIdentifier() + "/" - + ruleOwningNodeRef.getId() + "/rules"; - - if (parameterGiven) - { - url += "?"; - } - - if (includeInheritedParamGiven) - { - url += "includeInherited=" + includeInherited.toString(); - - if (ruleTypeNameParamGiven) - { - url += "&"; - } - } - - if (ruleTypeNameParamGiven) - { - url += "ruleTypeName=" + ruleTypeName; - } - - return url; - } - - /** - * Get a URL to the Rule Collection associated with the given rule owning - * node (without adding any parameters) - * - * @param ruleOwningNodeRef - * the rule owning node reference - * @return the URL to the rule collection associated with the given - * rule owning node - */ - private String getRulesNodeBasedUrl(NodeRef ruleOwningNodeRef) - { - return getRulesNodeBasedUrl(ruleOwningNodeRef, null, null); - } - - private void createUserAndAssocPerson(String userName) - { - // if user with given user name doesn't already exist then create user - if (this.authenticationService.authenticationExists(userName) == false) - { - // create user - this.authenticationService.createAuthentication(userName, - RULES_USER_PASSWORD.toCharArray()); - } - - // if person node with given user name doesn't already exist then create - // person - if (this.personService.personExists(userName) == false) - { - // create person properties - PropertyMap personProps = new PropertyMap(); - personProps.put(ContentModel.PROP_USERNAME, userName); - personProps.put(ContentModel.PROP_FIRSTNAME, "FirstName123"); - personProps.put(ContentModel.PROP_LASTNAME, "LastName123"); - personProps.put(ContentModel.PROP_EMAIL, "Test.RulesUser@alfresco.com"); - personProps.put(ContentModel.PROP_JOBTITLE, "JobTitle123"); - personProps.put(ContentModel.PROP_ORGANIZATION, "Organisation123"); - - // create person node for user - this.personService.createPerson(personProps); - } - } - - /** - * Create and return a Condition JSON object - * - * @param id ID of the condition - * @param parameterValues An associative array (map) of parameter values for the condition. - * Pass in null if there are no parameter values associated with this condition. - * @param conditionDefName The definition name for this condition. - * @param invertCondition Indicates whether the condition result should be inverted/negated. - * @param conditionUrl URL to the condition resource - * - * @return the constructed condition - */ - private JSONObject getConditionJsonObject(String id, JSONObject parameterValues, - String conditionDefName, boolean invertCondition, String conditionUrl) - throws Exception - { - // Construct condition JSON object - JSONObject condition = new JSONObject(); - - condition.put("id", id); - condition.put("parameterValues", parameterValues); - condition.put("conditionDefinitionName", conditionDefName); - condition.put("invertCondition", invertCondition); - condition.put("url", conditionUrl); - - return condition; - } - - /** - * Create and return an Action JSON object - * - * @param id ID of the action - * @param actionDefName The name of the action definition that relates to this action. - * @param title The title of the action. - * @param description The description of the action. - * @param executeAsync Indicates whether to run the action asynchronously or not. - * @param parameterValues Associative array (map) of parameter values associated with this action. - * Pass in null if there are no parameter values associated with the action. - * @param conditions Associative array of Condition Details for the condition resources associated with this action. - * Pass in null if there are no conditions associated with the action. - * @param actions Associative array of Action Details for the action resources associated with this action. - * Pass in null if this action is not a composite action (and thus no actions - * are associated with it). - * @param compensatingAction Action Details for the compensating action. - * Pass in null if this action does not have a compensating action - * @param actionUrl URL to the action resource - * - * @return the constructed action - */ - private JSONObject getActionJsonObject (String id, String actionDefName, String title, String description, - boolean executeAsync, JSONObject parameterValues, JSONArray conditions, - JSONArray actions, JSONObject compensatingAction, String actionUrl) - throws Exception - { - // Construct action JSON object - JSONObject action = new JSONObject(); - - action.put("id", id); - action.put("actionDefinitionName", actionDefName); - action.put("title", title); - action.put("description", description); - action.put("executeAsync", executeAsync); - action.put("parameterValues", parameterValues); - action.put("conditions", conditions); - action.put("actions", actions); - action.put("compensatingAction", compensatingAction); - action.put("url", actionUrl); - - return action; - } - - /** - * Create and return a Rule JSON object - * - * @param owningNodeRef The owning (actionable) node reference to which this rule applies - * @param ruleNodeRef The node that uniquely represents this rule - * @param title The title of the rule - * @param description The description of the rule - * @param ruleTypes The rule types associated with this rule - * @param action The action associated with this rule - * @param executeAsync Indicates whether the rule should execute the action asynchronously or not - * @param ruleDisabled Indicates whether or not this rule is marked as disabled or not - * @param appliedToChildren Indicates whether the rule is applied to all the children of the associated actionable node - * @param ruleUrl URL to the rule resource - * - * @return the constructed rule - */ - private JSONObject getRuleJsonObject (NodeRef owningNodeRef, NodeRef ruleNodeRef, String title, - String description, List ruleTypes, JSONObject action, boolean executeAsync, - boolean ruleDisabled, boolean appliedToChildren, String ruleUrl) - throws Exception - { - // Construct rule JSON object - JSONObject rule = new JSONObject(); - - if (owningNodeRef != null) - { - rule.put("owningNodeRef", owningNodeRef.toString()); - } - if (ruleNodeRef != null) - { - rule.put("ruleNodeRef", ruleNodeRef.toString()); - } - rule.put("title", title); - rule.put("description", description); - rule.put("ruleTypes", new JSONArray(ruleTypes)); - rule.put("action", action); - rule.put("executeAsync", executeAsync); - rule.put("ruleDisabled", ruleDisabled); - rule.put("appliedToChildren", appliedToChildren); - rule.put("url", ruleUrl); - - return rule; - } - - /** - * Creates a rule in the rule collection associated with the given rule owning node - * - * @param ruleOwningNodeRef the rule owning node with which the rule collection is associated - * @param ruleJson The rule JSON object to POST to the collection - * - * @return the created rule returned as a JSON object - * @throws Exception - */ - private JSONObject postRules(NodeRef ruleOwningNodeRef, JSONObject ruleJson) throws Exception - { - // Construct rule collection URL for POST rules - String rulesURL = getRulesNodeBasedUrl(ruleOwningNodeRef); - - Response response = sendRequest(new PostRequest(rulesURL, ruleJson.toString(), "application/json"), - Status.STATUS_OK); - JSONObject result = new JSONObject(response.getContentAsString()); - - return result; - } - - /** - * Check that getting the rule collection resource associated with the given actionable node - * returns with the expected HTTP status code - * - * @param ruleOwningNodeRef the actionable node for which we want to retrieve rules associated with - * it i.e. the rules applied to it - * @param expectedStatus the HTTP status that we expect to be returned by this operation - * @return the rules collection returned as an array of Rule Details encapsulated in a JSON object - * @throws Exception - */ - private JSONArray getRules(NodeRef ruleOwningNodeRef, Boolean includeInherited, String ruleTypeName, int expectedStatus) - throws Exception - { - // Construct rule collection URL for GET rules - String rulesUrl = getRulesNodeBasedUrl(ruleOwningNodeRef, includeInherited, ruleTypeName); - - Response response = sendRequest(new GetRequest(rulesUrl), expectedStatus); - - JSONArray result = new JSONArray(response.getContentAsString()); - - return result; - } - - public void testDeleteRules() throws Exception - { - // - // First POST a Rule to the Rule Collection associated with rule owning NodeRef - owningNodeRef1 - // - - // create condition parameters - JSONObject condCompMimeTypeParams = new JSONObject(); - condCompMimeTypeParams.put(ComparePropertyValueEvaluator.PARAM_VALUE, "image/png"); - - // create conditions - JSONObject conditionCompMimeType = getConditionJsonObject(null, condCompMimeTypeParams, "compare-mime-type", false, null); - JSONArray conditions = new JSONArray(); - conditions.put(conditionCompMimeType); - - // create nested action parameters - JSONObject actionCopyParamsJson = new JSONObject(); - actionCopyParamsJson.put(MoveActionExecuter.PARAM_ASSOC_QNAME, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy").toString()); - actionCopyParamsJson.put(MoveActionExecuter.PARAM_DESTINATION_FOLDER, this.testDestFolder1.toString()); - actionCopyParamsJson.put(MoveActionExecuter.PARAM_ASSOC_TYPE_QNAME, ContentModel.ASSOC_CONTAINS.toString()); - - // create nested actions - JSONObject actionCopyJson = getActionJsonObject(null, CopyActionExecuter.NAME, "CopyTitle", "CopyDesc", false, - actionCopyParamsJson, null, null, null, null); - JSONArray nestedActions = new JSONArray(); - nestedActions.put(actionCopyJson); - - // create rule's composite action - JSONObject compoActionJson = getActionJsonObject(null, CompositeActionExecuter.NAME, "Rule1Action", "Rule1ActionDesc", - false, null, conditions, nestedActions, null, null); - - // create rule to POST - List ruleTypes = new ArrayList(); - ruleTypes.add(RuleType.UPDATE); - JSONObject ruleJson = getRuleJsonObject(this.owningNodeRef1, null, "Rule1", "Rule1Desc", ruleTypes, - compoActionJson, false, false, false, null); - - // POST rule JSON to rules collection resource associated with rule owning node ref owningNodeRef1 - postRules(this.owningNodeRef1, ruleJson); - - // - // DELETE all Rules owned by NodeRef - owningNodeRef1 - // and validate that owningNodeRef1 does not have any - // rules left applied against it thereafter - // - - // construct url to the Rule Collection resource that we wish to delete (associated with rule owning node - // NodeRef owningNodeRef1) - String url = "/api/node/" + this.owningNodeRef1.getStoreRef().getProtocol() + "/" - + this.owningNodeRef1.getStoreRef().getIdentifier() + "/" + this.owningNodeRef1.getId() + "/rules"; - - // DELETE all rules owned by NodeRef owningNodeRef1 - sendRequest(new DeleteRequest(url), Status.STATUS_OK); - - // make sure that there are no rules associated with - // rule owning NodeRef owningNodeRef1 anymore - Response responseGetRules = sendRequest(new GetRequest(url), Status.STATUS_OK); - JSONArray getRulesJson = new JSONArray(responseGetRules.getContentAsString()); - - assertTrue(getRulesJson.length() == 0); - } - - public void testDeleteRule() throws Exception - { - // - // First POST a Rule and get the identifying rule node ref - // from the Rule Details returned - // - - // create condition parameters - JSONObject condCompMimeTypeParams = new JSONObject(); - condCompMimeTypeParams.put(ComparePropertyValueEvaluator.PARAM_VALUE, "image/png"); - - // create conditions - JSONObject conditionCompMimeType = getConditionJsonObject(null, condCompMimeTypeParams, "compare-mime-type", false, null); - JSONArray conditions = new JSONArray(); - conditions.put(conditionCompMimeType); - - // create nested action parameters - JSONObject actionCopyParamsJson = new JSONObject(); - actionCopyParamsJson.put(MoveActionExecuter.PARAM_ASSOC_QNAME, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy").toString()); - actionCopyParamsJson.put(MoveActionExecuter.PARAM_DESTINATION_FOLDER, this.testDestFolder1.toString()); - actionCopyParamsJson.put(MoveActionExecuter.PARAM_ASSOC_TYPE_QNAME, ContentModel.ASSOC_CONTAINS.toString()); - - // create nested action - JSONObject actionCopyJson = getActionJsonObject(null, CopyActionExecuter.NAME, "CopyTitle", "CopyDesc", false, - actionCopyParamsJson, null, null, null, null); - JSONArray nestedActions = new JSONArray(); - nestedActions.put(actionCopyJson); - - // create rule's composite action - JSONObject compoActionJson = getActionJsonObject(null, CompositeActionExecuter.NAME, "Rule1Action", "Rule1ActionDesc", - false, null, conditions, nestedActions, null, null); - - // create rule to POST - List ruleTypes = new ArrayList(); - ruleTypes.add(RuleType.UPDATE); - JSONObject ruleJson = getRuleJsonObject(this.owningNodeRef1, null, "Rule1", "Rule1Desc", ruleTypes, - compoActionJson, false, false, false, null); - - // POST rule JSON to rules collection resource - JSONObject resultPostRule = postRules(this.owningNodeRef1, ruleJson); - - String ruleNodeRefStr = resultPostRule.getString("ruleNodeRef"); - NodeRef ruleNodeRef = new NodeRef(ruleNodeRefStr); - - // - // DELETE Rule with rule node ref of Rule just POSTed - // and validate that the Rule has been deleted - // - - // construct url to Rule resource we wish to delete - String url = "/api/rules/" + ruleNodeRef.getStoreRef().getProtocol() + "/" - + ruleNodeRef.getStoreRef().getIdentifier() + "/" + ruleNodeRef.getId(); - - // delete the rule just POSTed - sendRequest(new DeleteRequest(url), Status.STATUS_OK); - - // make sure that the rule just deleted no longer exists - sendRequest(new GetRequest(url), Status.STATUS_NOT_FOUND); - } - - @SuppressWarnings("unchecked") - public void testGetRule() throws Exception - { - // - // First POST a Rule and get the identifying rule node ref - // from the Rule Details returned - // - - // create condition parameters - JSONObject condCompMimeTypeParams = new JSONObject(); - condCompMimeTypeParams.put(ComparePropertyValueEvaluator.PARAM_VALUE, "image/png"); - - // create conditions JSON array - JSONObject conditionCompMimeType = getConditionJsonObject(null, condCompMimeTypeParams, "compare-mime-type", false, null); - JSONArray conditions = new JSONArray(); - conditions.put(conditionCompMimeType); - - // create parameters for nested actions - JSONObject actionCopyParamsJson = new JSONObject(); - actionCopyParamsJson.put(MoveActionExecuter.PARAM_ASSOC_QNAME, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy").toString()); - actionCopyParamsJson.put(MoveActionExecuter.PARAM_DESTINATION_FOLDER, this.testDestFolder1.toString()); - actionCopyParamsJson.put(MoveActionExecuter.PARAM_ASSOC_TYPE_QNAME, ContentModel.ASSOC_CONTAINS.toString()); - - // create nested actions - JSONObject actionCopyJson = getActionJsonObject(null, CopyActionExecuter.NAME, "CopyTitle", "CopyDesc", false, - actionCopyParamsJson, null, null, null, null); - JSONArray nestedActions = new JSONArray(); - nestedActions.put(actionCopyJson); - - // create rule's root action - JSONObject ruleActionJson = getActionJsonObject(null, CompositeActionExecuter.NAME, "Rule1Action", "Rule1ActionDesc", - false, null, conditions, nestedActions, null, null); - - // create rule JSON - List ruleTypes = new ArrayList(); - ruleTypes.add(RuleType.UPDATE); - JSONObject ruleJson = getRuleJsonObject(null, null, "Rule1", "Rule1Desc", ruleTypes, - ruleActionJson, false, false, false, null); - - // POST rule JSON to rules collection resource - JSONObject resultPostRule = postRules(this.owningNodeRef1, ruleJson); - - String ruleNodeRefStr = resultPostRule.getString("ruleNodeRef"); - NodeRef ruleNodeRef = new NodeRef(ruleNodeRefStr); - - // - // GET Rule with rule node ref of Rule just POSTed - // and validate that the Rule returned by GET Rule - // is the same as that for the rule just POSTed - // - String getRuleRulesBasedUrl = "/api/rules/" + ruleNodeRef.getStoreRef().getProtocol() + "/" - + ruleNodeRef.getStoreRef().getIdentifier() + "/" + ruleNodeRef.getId(); - - Response response = sendRequest(new GetRequest(getRuleRulesBasedUrl), Status.STATUS_OK); - JSONObject resultGetRule = new JSONObject(response.getContentAsString()); - - // - // validate properties returned in GET Rule response - // - - // - // check rule properties - // - assertEquals(this.owningNodeRef1.toString(), resultGetRule.getString("owningNodeRef")); - assertEquals(ruleNodeRefStr, resultGetRule.getString("ruleNodeRef")); - assertEquals("Rule1", resultGetRule.getString("title")); - assertEquals("Rule1Desc", resultGetRule.getString("description")); - assertEquals(false, resultGetRule.getBoolean("executeAsync")); - assertEquals(false, resultGetRule.getBoolean("ruleDisabled")); - assertEquals(false, resultGetRule.getBoolean("appliedToChildren")); - - // - // check rule types - // - JSONArray resultRuleTypes = resultGetRule.getJSONArray("ruleTypes"); - assertEquals(1, resultRuleTypes.length()); - assertEquals(RuleType.UPDATE, resultRuleTypes.getString(0)); - - // retrieve ID for copy action - JSONObject resultRuleAction = resultGetRule.getJSONObject("action"); - JSONObject resultNestedActions = resultRuleAction.getJSONObject("actions"); - Iterator actionKeysIter = resultNestedActions.keys(); - String resultCopyActionID = null; - while (actionKeysIter.hasNext()) - { - String key = actionKeysIter.next(); - - JSONObject resultAction = resultNestedActions.getJSONObject(key); - String actionDefName = resultAction.getString("actionDefinitionName"); - - if (actionDefName.equals(CopyActionExecuter.NAME)) - { - resultCopyActionID = resultAction.getString("id"); - break; - } - } - - assertNotNull(resultCopyActionID); - - // retrieve copy action - JSONObject resCopyAction = resultNestedActions.getJSONObject(resultCopyActionID); - - // - // check copy action properties - // - assertEquals(CopyActionExecuter.NAME, resCopyAction.getString("actionDefinitionName")); - assertEquals("CopyTitle", resCopyAction.getString("title")); - assertEquals("CopyDesc" , resCopyAction.getString("description")); - assertEquals(false, resCopyAction.getBoolean("executeAsync")); - - // - // check copy action parameters - // - JSONObject resCopyActionParams = resCopyAction.getJSONObject("parameterValues"); - assertEquals(QName.createQName( - NamespaceService.CONTENT_MODEL_1_0_URI, "copy").toString(), - resCopyActionParams.getString(MoveActionExecuter.PARAM_ASSOC_QNAME)); - assertEquals(this.testDestFolder1.toString(), resCopyActionParams.getString(MoveActionExecuter.PARAM_DESTINATION_FOLDER)); - assertEquals(ContentModel.ASSOC_CONTAINS.toString(), resCopyActionParams.getString(MoveActionExecuter.PARAM_ASSOC_TYPE_QNAME)); - - // retrieve ID for compare MIME-type condition - JSONObject resultConditions = resultRuleAction.getJSONObject("conditions"); - Iterator condKeysIter = resultConditions.keys(); - String resultCondCompMimeTypeID = null; - while (condKeysIter.hasNext()) - { - String key = condKeysIter.next(); - - JSONObject resultCondition = resultConditions.getJSONObject(key); - String condDefName = resultCondition.getString("conditionDefinitionName"); - - if (condDefName.equals(CompareMimeTypeEvaluator.NAME)) - { - resultCondCompMimeTypeID = resultCondition.getString("id"); - break; - } - } - - assertNotNull(resultCondCompMimeTypeID); - - // - // retrieve compare MIME-type condition - // - JSONObject resCompMimeTypeCond = resultConditions.getJSONObject(resultCondCompMimeTypeID); - - // - // check compare MIME type condition's properties - // - assertEquals(CompareMimeTypeEvaluator.NAME, resCompMimeTypeCond.getString("conditionDefinitionName")); - assertEquals(false, resCompMimeTypeCond.getBoolean("invertCondition")); - - // - // retrieve compare MIME-type condition's parameter JSON and check its value - // - JSONObject resCondCmpMimeTypeParams = resCompMimeTypeCond.getJSONObject("parameterValues"); - assertEquals("image/png", resCondCmpMimeTypeParams.getString(ComparePropertyValueEvaluator.PARAM_VALUE)); - } - - public void testGetRules() throws Exception - { - // - // First POST a Rule - // - - // create condition parameters - JSONObject condCompMimeTypeParams = new JSONObject(); - condCompMimeTypeParams.put(ComparePropertyValueEvaluator.PARAM_VALUE, "image/png"); - - // create conditions - JSONObject conditionCompMimeType = getConditionJsonObject(null, condCompMimeTypeParams, "compare-mime-type", false, null); - JSONArray conditions = new JSONArray(); - conditions.put(conditionCompMimeType); - - // create parameters for nested actions - JSONObject actionCopyParamsJson = new JSONObject(); - actionCopyParamsJson.put(MoveActionExecuter.PARAM_ASSOC_QNAME, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy").toString()); - actionCopyParamsJson.put(MoveActionExecuter.PARAM_DESTINATION_FOLDER, this.testDestFolder1.toString()); - actionCopyParamsJson.put(MoveActionExecuter.PARAM_ASSOC_TYPE_QNAME, ContentModel.ASSOC_CONTAINS.toString()); - - // create nested actions - JSONObject actionCopyJson = getActionJsonObject(null, CopyActionExecuter.NAME, "CopyTitle", "CopyDesc", false, - actionCopyParamsJson, null, null, null, null); - JSONArray nestedActions = new JSONArray(); - nestedActions.put(actionCopyJson); - - // create rule's composite action - JSONObject compoActionJson = getActionJsonObject(null, CompositeActionExecuter.NAME, "Rule1Action", "Rule1ActionDesc", - false, null, conditions, nestedActions, null, null); - - // create rule to POST - List ruleTypes = new ArrayList(); - ruleTypes.add(RuleType.UPDATE); - JSONObject ruleJson = getRuleJsonObject(this.owningNodeRef1, null, "Rule1", "Rule1Desc", ruleTypes, - compoActionJson, false, false, false, null); - - // POST rule JSON to rules collection resource - postRules(this.owningNodeRef1, ruleJson); - - // - // GET Rules and test to make sure that POSTed rule is in return Rules collection - // - - JSONArray result = getRules(this.owningNodeRef1, null, null, Status.STATUS_OK); - - boolean postedRuleFound = false; - for (int i=0; i < result.length(); i++) - { - JSONObject resultRuleJson = result.getJSONObject(i); - String ruleTitle = resultRuleJson.getString("title"); - - if (ruleTitle.equals("Rule1")) - { - postedRuleFound = true; - } - } - - assertTrue(postedRuleFound == true); - } - - @SuppressWarnings("unchecked") - public void testPutRule() throws Exception - { - // ------------------------- - // Create a Rule - POST Rule - // ------------------------- - - // create condition parameters - JSONObject condCompMimeTypeParams = new JSONObject(); - condCompMimeTypeParams.put(ComparePropertyValueEvaluator.PARAM_VALUE, "image/png"); - - // - // create conditions JSON - // - JSONObject conditionCompMimeType = getConditionJsonObject(null, condCompMimeTypeParams, "compare-mime-type", false, null); - JSONArray conditions = new JSONArray(); - conditions.put(conditionCompMimeType); - - // - // create parameters for nested actions JSON - // - JSONObject actionCopyParamsJson = new JSONObject(); - actionCopyParamsJson.put(MoveActionExecuter.PARAM_ASSOC_QNAME, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy").toString()); - actionCopyParamsJson.put(MoveActionExecuter.PARAM_DESTINATION_FOLDER, this.testDestFolder1.toString()); - actionCopyParamsJson.put(MoveActionExecuter.PARAM_ASSOC_TYPE_QNAME, ContentModel.ASSOC_CONTAINS.toString()); - - // - // create nested actions JSON - // - JSONObject actionCopyJson = getActionJsonObject(null, CopyActionExecuter.NAME, "CopyTitle", "CopyDesc", false, - actionCopyParamsJson, null, null, null, null); - JSONArray nestedActions = new JSONArray(); - nestedActions.put(actionCopyJson); - - // - // create rule's composite action JSON - // - JSONObject compoActionJson = getActionJsonObject(null, CompositeActionExecuter.NAME, "Rule1Action", "Rule1ActionDesc", - false, null, conditions, nestedActions, null, null); - - // - // create rule to POST JSON - // - List ruleTypes = new ArrayList(); - ruleTypes.add(RuleType.UPDATE); - JSONObject ruleJson = getRuleJsonObject(this.owningNodeRef1, null, "Rule", "RuleDesc", ruleTypes, - compoActionJson, false, false, false, null); - - // - // POST rule JSON to rules collection resource JSON - // - JSONObject resultRuleJson = postRules(this.owningNodeRef1, ruleJson); - - // get the rule node ref from the rule details returned so that - // we can retrieve the rule later - String ruleNodeRefStr = resultRuleJson.getString("ruleNodeRef"); - NodeRef ruleNodeRef = new NodeRef(ruleNodeRefStr); - - // -------------------------- - // Update the Rule - PUT Rule - // -------------------------- - - // create parameter for compare MIME-type condition with updated parameter value - JSONObject putCondCompMimeTypeParams = new JSONObject(); - putCondCompMimeTypeParams.put(ComparePropertyValueEvaluator.PARAM_VALUE, "image/jpeg"); - - // retrieve ID for compare MIME-type condition - JSONObject resultRuleAction = resultRuleJson.getJSONObject("action"); - JSONObject resultConditions = resultRuleAction.getJSONObject("conditions"); - Iterator condKeysIter = resultConditions.keys(); - String resultCondCompMimeTypeID = null; - while (condKeysIter.hasNext()) - { - String key = condKeysIter.next(); - - JSONObject resultCondition = resultConditions.getJSONObject(key); - String condDefName = resultCondition.getString("conditionDefinitionName"); - - if (condDefName.equals("compare-mime-type")) - { - resultCondCompMimeTypeID = resultCondition.getString("id"); - break; - } - } - - assertNotNull(resultCondCompMimeTypeID); - - // create compare MIME-type condition with updated condition parameters and updated properties - JSONObject putConditionCompMimeType = new JSONObject(); - putConditionCompMimeType.put("id", resultCondCompMimeTypeID); - putConditionCompMimeType.put("parameterValues", putCondCompMimeTypeParams); - putConditionCompMimeType.put("conditionDefinitionName", "compare-mime-type"); - putConditionCompMimeType.put("invertCondition", true); - - // create conditions JSON array and add updated compare MIME-type condition - JSONArray putConditions = new JSONArray(); - putConditions.put(putConditionCompMimeType); - - // create parameters for copy action JSON with updated parameter values - JSONObject putCopyActionParams = new JSONObject(); - putCopyActionParams.put(MoveActionExecuter.PARAM_DESTINATION_FOLDER, this.testDestFolder2.toString()); - - // retrieve ID for copy action - JSONObject resultActions = resultRuleAction.getJSONObject("actions"); - Iterator actionKeysIter = resultActions.keys(); - String resultCopyActionID = null; - while (actionKeysIter.hasNext()) - { - String key = actionKeysIter.next(); - - JSONObject resultAction = resultActions.getJSONObject(key); - String actionDefName = resultAction.getString("actionDefinitionName"); - - if (actionDefName.equals(CopyActionExecuter.NAME)) - { - resultCopyActionID = resultAction.getString("id"); - break; - } - } - - assertNotNull(resultCopyActionID); - - // create copy action with updated action parameters and updated properties - JSONObject putCopyAction = new JSONObject(); - putCopyAction.put("id", resultCopyActionID); - putCopyAction.put("actionDefinitionName", CopyActionExecuter.NAME); - putCopyAction.put("title", "CopyTitleUpdated"); - putCopyAction.put("description", "CopyDescUpdated"); - putCopyAction.put("executeAsync", true); - putCopyAction.put("parameterValues", putCopyActionParams); - - // create nested actions JSON array and add updated copy action - JSONArray putNestedActions = new JSONArray(); - putNestedActions.put(putCopyAction); - - // create rule action JSON (root action) with updated properties, conditions and nested actions - JSONObject putRuleAction = new JSONObject(); - putRuleAction.put("id", resultRuleAction.getString("id")); - putRuleAction.put("actionDefinitionName", CompositeActionExecuter.NAME); - putRuleAction.put("actions", putNestedActions); - putRuleAction.put("conditions", putConditions); - - // create updated rule types JSON array - JSONArray putRuleTypes = new JSONArray(); - putRuleTypes.put(RuleType.INBOUND); - - // create rule JSON with updated composite action, updated rule types and updated rule properties - JSONObject putRuleJson = new JSONObject(); - putRuleJson.put("title", "RuleTitleUpdated"); - putRuleJson.put("description", "RuleDescUpdated"); - putRuleJson.put("ruleTypes", putRuleTypes); - putRuleJson.put("action", putRuleAction); - putRuleJson.put("executeAsync", true); - putRuleJson.put("ruleDisabled", true); - - // - // update rule resource with updated rule JSON with PUT Rule - // - - String url = "/api/rules/" + ruleNodeRef.getStoreRef().getProtocol() + "/" - + ruleNodeRef.getStoreRef().getIdentifier() + "/" + ruleNodeRef.getId(); - - sendRequest(new PutRequest(url, putRuleJson.toString(), "application/json"), - Status.STATUS_OK); - - // ----------------------------------------------- - // Get the updated Rule - GET Rule - // and validate that the response thereof contains - // the updated field values - // ----------------------------------------------- - - // - // get the updated rule - // - Response responseGetRule = sendRequest(new GetRequest(url), Status.STATUS_OK); - JSONObject resGetRule = new JSONObject(responseGetRule.getContentAsString()); - - // - // check updated rule fields - // - assertEquals("RuleTitleUpdated", resGetRule.getString("title")); - assertEquals("RuleDescUpdated", resGetRule.getString("description")); - assertEquals(true, resGetRule.getBoolean("executeAsync")); - assertEquals(true, resGetRule.getBoolean("ruleDisabled")); - - // - // retrieve updated copy action - // - JSONObject resRuleAction = resGetRule.getJSONObject("action"); - JSONObject resNestedActions = resRuleAction.getJSONObject("actions"); - String copyActionId = putCopyAction.getString("id"); - JSONObject resCopyAction = resNestedActions.getJSONObject(copyActionId); - - // - // check updated copy action fields - // - assertEquals(CopyActionExecuter.NAME, resCopyAction.getString("actionDefinitionName")); - assertEquals("CopyTitleUpdated", resCopyAction.getString("title")); - assertEquals("CopyDescUpdated" , resCopyAction.getString("description")); - assertEquals(true, resCopyAction.getBoolean("executeAsync")); - - // - // check updated copy action parameters - // - JSONObject resCopyActionParams = resCopyAction.getJSONObject("parameterValues"); - assertEquals(this.testDestFolder2.toString(), resCopyActionParams.getString(MoveActionExecuter.PARAM_DESTINATION_FOLDER)); - - // - // retrieve updated compare MIME-type condition - // - JSONObject resConditions = resRuleAction.getJSONObject("conditions"); - String compMimeTypeCondId = putConditionCompMimeType.getString("id"); - JSONObject resCompMimeTypeCond = resConditions.getJSONObject(compMimeTypeCondId); - - // - // check updated compare MIME type condition's fields - // - assertEquals(true, resCompMimeTypeCond.getBoolean("invertCondition")); - - // - // retrieve compare MIME-type condition's parameter JSON and check its value - // - JSONObject resCondCmpMimeTypeParams = resCompMimeTypeCond.getJSONObject("parameterValues"); - assertEquals("image/jpeg", resCondCmpMimeTypeParams.getString(ComparePropertyValueEvaluator.PARAM_VALUE)); - } - - public void testPostRules() throws Exception - { - // create condition parameters for compare MIME type condition - JSONObject condCompMimeTypeParams = new JSONObject(); - condCompMimeTypeParams.put(ComparePropertyValueEvaluator.PARAM_VALUE, "image/png"); - - // create compare MIME type condition - JSONObject conditionCompMimeType = getConditionJsonObject(null, condCompMimeTypeParams, "compare-mime-type", false, null); - JSONArray conditions = new JSONArray(); - conditions.put(conditionCompMimeType); - - // create action parameters for copy action - JSONObject actionCopyParamsJson = new JSONObject(); - actionCopyParamsJson.put(MoveActionExecuter.PARAM_ASSOC_QNAME, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy").toString()); - actionCopyParamsJson.put(MoveActionExecuter.PARAM_DESTINATION_FOLDER, this.testDestFolder1.toString()); - actionCopyParamsJson.put(MoveActionExecuter.PARAM_ASSOC_TYPE_QNAME, ContentModel.ASSOC_CONTAINS.toString()); - - // create copy action and add to nested actions - JSONObject actionCopyJson = getActionJsonObject(null, CopyActionExecuter.NAME, "CopyActionTitle", "CopyActionDesc", false, - actionCopyParamsJson, null, null, null, null); - JSONArray nestedActions = new JSONArray(); - nestedActions.put(actionCopyJson); - - // create rule's composite action - JSONObject compoActionJson = getActionJsonObject(null, CompositeActionExecuter.NAME, "Rule1Action", "Rule1ActionDesc", - false, null, conditions, nestedActions, null, null); - - // create rule to POST - List ruleTypes = new ArrayList(); - ruleTypes.add(RuleType.UPDATE); - JSONObject ruleJson = getRuleJsonObject(this.owningNodeRef1, null, "Rule1", "Rule1Desc", ruleTypes, - compoActionJson, false, false, false, null); - - // POST RuleJson to Rules Collection - JSONObject resultRule = postRules(this.owningNodeRef1, ruleJson); - - // - // validate rule result - // - - assertEquals(this.owningNodeRef1.toString(), resultRule.getString("owningNodeRef")); - assertEquals("Rule1", resultRule.getString("title")); - assertEquals("Rule1Desc", resultRule.getString("description")); - - // validate that rule types sent in rule JSON are the same as that returned - // there should only be one, namely "update" - JSONArray resultRuleTypes = resultRule.getJSONArray("ruleTypes"); - assertTrue(resultRuleTypes.length() == 1); - assertEquals(RuleType.UPDATE, resultRuleTypes.getString(0)); - - assertEquals(false, resultRule.getBoolean("executeAsync")); - assertEquals(false, resultRule.getBoolean("ruleDisabled")); - assertEquals(false, resultRule.getBoolean("appliedToChildren")); - - // validate rule's composite action from rule in result JSON - JSONObject resultCompoAction = resultRule.getJSONObject("action"); - - assertEquals(CompositeActionExecuter.NAME, resultCompoAction.getString("actionDefinitionName")); - assertEquals("Rule1Action", resultCompoAction.getString("title")); - assertEquals("Rule1ActionDesc", resultCompoAction.getString("description")); - assertEquals(false, resultCompoAction.getBoolean("executeAsync")); - - // validate condition in rule's composite action from the result JSON - // there should only be one, namely the compare MIME type condition - JSONObject resultConditions = resultCompoAction.getJSONObject("conditions"); - String resultcondCompMimeTypeKey = resultConditions.names().getString(0); - JSONObject resultcondCompMimeType = resultConditions.getJSONObject(resultcondCompMimeTypeKey); - - assertEquals("compare-mime-type", resultcondCompMimeType.getString("conditionDefinitionName")); - assertEquals(false, resultcondCompMimeType.getBoolean("invertCondition")); - - // validate parameter values in compare MIME type condition - JSONObject resultCondParamVals = resultcondCompMimeType.getJSONObject("parameterValues"); - assertEquals("image/png", resultCondParamVals.getString(ComparePropertyValueEvaluator.PARAM_VALUE)); - - // validate nested action in rule's composite action from the result JSON - // there should only be one nested action, namely the copy action - JSONObject resultNestedActions = resultCompoAction.getJSONObject("actions"); - String resultActionCopyKey = resultNestedActions.names().getString(0); - JSONObject resultCopyAction = resultNestedActions.getJSONObject(resultActionCopyKey); - - assertEquals(CopyActionExecuter.NAME, resultCopyAction.getString("actionDefinitionName")); - assertEquals("CopyActionTitle", resultCopyAction.getString("title")); - assertEquals("CopyActionDesc", resultCopyAction.getString("description")); - assertEquals(false, resultCopyAction.getBoolean("executeAsync")); - - // validate parameter values in copy action - JSONObject resultActionParamVals = resultCopyAction.getJSONObject("parameterValues"); - assertEquals(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy").toString(), - resultActionParamVals.getString(MoveActionExecuter.PARAM_ASSOC_QNAME)); - assertEquals(this.testDestFolder1.toString(), - resultActionParamVals.getString(MoveActionExecuter.PARAM_DESTINATION_FOLDER)); - assertEquals(ContentModel.ASSOC_CONTAINS.toString(), - resultActionParamVals.getString(MoveActionExecuter.PARAM_ASSOC_TYPE_QNAME)); - } - - public void testPostActionQueue() throws Exception - { - // construct ActionQueue resource URL - String url = "/api/actionqueue"; - - // - // construct action JSON to put into action queue item - // (which will, in turn, be posted to the action queue) - // - - // create action parameters for copy action - JSONObject actionCopyParamsJson = new JSONObject(); - actionCopyParamsJson.put(MoveActionExecuter.PARAM_ASSOC_QNAME, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy").toString()); - actionCopyParamsJson.put(MoveActionExecuter.PARAM_DESTINATION_FOLDER, this.testDestFolder1.toString()); - actionCopyParamsJson.put(MoveActionExecuter.PARAM_ASSOC_TYPE_QNAME, ContentModel.ASSOC_CONTAINS.toString()); - - // create copy action - JSONObject actionCopyJson = getActionJsonObject(null, CopyActionExecuter.NAME, "CopyActionTitle", - "CopyActionDesc", false, actionCopyParamsJson, null, null, null, null); - - // - // create action queue item json - // - - JSONObject actionQueueItemJson = new JSONObject(); - actionQueueItemJson.put("action", actionCopyJson); - actionQueueItemJson.put("nodeRef", this.testDestFolder1.toString()); - actionQueueItemJson.put("checkConditions", true); - actionQueueItemJson.put("executeAsync", false); - - Response response = sendRequest(new PostRequest(url, actionQueueItemJson.toString(), "application/json"), - Status.STATUS_OK); - JSONObject result = new JSONObject(response.getContentAsString()); - - assertNotNull(result); - - assertEquals("COMPLETE", result.getString("status")); - } - - public void testGetConditionDefs() throws Exception - { - // construct condition definition collection resource URL - String url = "/api/rules/conditiondefs"; - - Response response = sendRequest(new GetRequest(url), - Status.STATUS_OK); - JSONArray result = new JSONArray(response.getContentAsString()); - - assertTrue(result.length() > 0); - } - - public void testGetConditionDef() throws Exception - { - String conditionDefName = "compare-property-value"; - // construct condition definition resource URL - String url = "/api/rules/conditiondefs/" + conditionDefName; - - Response response = sendRequest(new GetRequest(url), - Status.STATUS_OK); - JSONObject result = new JSONObject(response.getContentAsString()); - - assertNotNull(result); - - assertEquals("compare-property-value", result.getString("name")); - - assertEquals(false, result.getBoolean("adhocPropertiesAllowed")); - } - - public void testGetActionDefs() throws Exception - { - // construct action definition collection resource URL - String url = "/api/rules/actiondefs"; - - Response response = sendRequest(new GetRequest(url), - Status.STATUS_OK); - JSONArray result = new JSONArray(response.getContentAsString()); - - assertTrue(result.length() > 0); - } - - public void testGetActionDef() throws Exception - { - String actionDefName = "transform"; - // construct action definition resource URL - String url = "/api/rules/actiondefs/" + actionDefName; - - Response response = sendRequest(new GetRequest(url), - Status.STATUS_OK); - JSONObject result = new JSONObject(response.getContentAsString()); - - assertNotNull(result); - - // validate applicable types in returned action definition - boolean applicableTypeContentFound = false; - JSONArray applicableTypes = result.getJSONArray("applicableTypes"); - for (int i=0; i < applicableTypes.length(); i++) - { - String applicableType = applicableTypes.getString(i); - if (applicableType.equals("content")) - { - applicableTypeContentFound = true; - } - } - assertTrue(applicableTypeContentFound == true); - - assertEquals("transform", result.getString("name")); - - assertEquals(false, result.getBoolean("adhocPropertiesAllowed")); - } -} diff --git a/source/java/org/alfresco/repo/web/scripts/rule/RulesDelete.java b/source/java/org/alfresco/repo/web/scripts/rule/RulesDelete.java deleted file mode 100644 index 5302c63559..0000000000 --- a/source/java/org/alfresco/repo/web/scripts/rule/RulesDelete.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have received a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" - */ -package org.alfresco.repo.web.scripts.rule; - -import java.util.Map; - -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.rule.RuleService; -import org.springframework.extensions.webscripts.DeclarativeWebScript; -import org.springframework.extensions.webscripts.Status; -import org.springframework.extensions.webscripts.WebScriptException; -import org.springframework.extensions.webscripts.WebScriptRequest; - -/** - * Web Script to DELETE the rule collection associated with the given rule owning node. - * - * @author glen johnson at alfresco dot com - */ -public class RulesDelete extends DeclarativeWebScript -{ - // private constants - private static final String REQ_TEMPL_VAR_STORE_TYPE = "store_type"; - private static final String REQ_TEMPL_VAR_STORE_ID = "store_id"; - private static final String REQ_TEMPL_VAR_NODE_ID = "id"; - - // properties for services - private RuleService ruleService; - - // properties for dependencies - private RulesHelper rulesHelper; - - /** - * Set the ruleService property. - * - * @param ruleService The rule service instance to set - */ - public void setRuleService(RuleService ruleService) - { - this.ruleService = ruleService; - } - - /** - * @param rulesHelper the rulesHelper to set - */ - public void setRulesHelper(RulesHelper rulesHelper) - { - this.rulesHelper = rulesHelper; - } - - /* - * (non-Javadoc) - * - * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl( - * org.alfresco.web.scripts.WebScriptRequest, - * org.alfresco.web.scripts.WebScriptResponse) - */ - @Override - protected Map executeImpl(WebScriptRequest req, - Status status) - { - String storeType = req.getServiceMatch().getTemplateVars().get(REQ_TEMPL_VAR_STORE_TYPE); - // Handle if 'store_type' URL template token not provided - if ((storeType == null) || (storeType.length() == 0)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "The 'store_type' URL template token has not been provided in URL"); - } - - String storeId = req.getServiceMatch().getTemplateVars().get(REQ_TEMPL_VAR_STORE_ID); - // Handle if 'storeId' URL template token not provided - if ((storeId == null) || (storeId.length() == 0)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "The 'storeId' URL template token has not been provided in URL"); - } - - String nodeId = req.getServiceMatch().getTemplateVars().get(REQ_TEMPL_VAR_NODE_ID); - // Handle if 'nodeId' URL template token not provided - if ((nodeId == null) || (nodeId.length() == 0)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "The 'nodeId' URL template token has not been provided in URL"); - } - - // create the rule owning node reference from the given - // URL template tokens - NodeRef ruleOwningNodeRef = this.rulesHelper.getNodeRefFromWebScriptUrl(req, storeType, storeId, nodeId); - - // delete rule collection associated with the rule owning node - this.ruleService.removeAllRules(ruleOwningNodeRef); - - return null; - } -} diff --git a/source/java/org/alfresco/repo/web/scripts/rule/RulesGet.java b/source/java/org/alfresco/repo/web/scripts/rule/RulesGet.java deleted file mode 100644 index 43eb7098b8..0000000000 --- a/source/java/org/alfresco/repo/web/scripts/rule/RulesGet.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have received a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" - */ -package org.alfresco.repo.web.scripts.rule; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.rule.Rule; -import org.alfresco.service.cmr.rule.RuleService; -import org.springframework.extensions.webscripts.DeclarativeWebScript; -import org.springframework.extensions.webscripts.Status; -import org.springframework.extensions.webscripts.WebScriptException; -import org.springframework.extensions.webscripts.WebScriptRequest; - -/** - * Web Script to GET the rule collection associated with the given rule owning node. - * The following optional parameters can be provided: - * - * - includeInherited: if provided, then this parameter indicates whether or not to include rules - * inherited from the owning node's parents. If this parameter is not provided , then rules - * inherited from the node's parents are included by default. - * - * - ruleTypeName: if this parameter is provided, then only rules of this given rule type are returned. - * If this parameter is not provided then rules of all types will be returned. - * - * @author glen johnson at alfresco dot com - */ -public class RulesGet extends DeclarativeWebScript -{ - // private constants - private static final String REQ_TEMPL_VAR_STORE_TYPE = "store_type"; - private static final String REQ_TEMPL_VAR_STORE_ID = "store_id"; - private static final String REQ_TEMPL_VAR_NODE_ID = "id"; - - private static final String REQ_PARAM_INCLUDE_INHERITED = "includeInherited"; - private static final String REQ_PARAM_RULE_TYPE_NAME = "ruleTypeName"; - - // model property keys - private static final String MODEL_PROP_KEY_RULES = "rules"; - private static final String MODEL_PROP_KEY_OWNING_NODE_REF = "owningNodeRef"; - - // properties for services - private RuleService ruleService; - - // properties for dependencies - private RulesHelper rulesHelper; - - /** - * Set the ruleService property. - * - * @param ruleService The rule service instance to set - */ - public void setRuleService(RuleService ruleService) - { - this.ruleService = ruleService; - } - - /** - * @param rulesHelper the rulesHelper to set - */ - public void setRulesHelper(RulesHelper rulesHelper) - { - this.rulesHelper = rulesHelper; - } - - /* - * (non-Javadoc) - * - * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl( - * org.alfresco.web.scripts.WebScriptRequest, - * org.alfresco.web.scripts.WebScriptResponse) - */ - @Override - protected Map executeImpl(WebScriptRequest req, - Status status) - { - // initialise model to pass on for template to render - Map model = new HashMap(); - - String storeType = req.getServiceMatch().getTemplateVars().get(REQ_TEMPL_VAR_STORE_TYPE); - // Handle if 'store_type' URL template token not provided - if ((storeType == null) || (storeType.length() == 0)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "The 'store_type' URL template token has not been provided in URL"); - } - - String storeId = req.getServiceMatch().getTemplateVars().get(REQ_TEMPL_VAR_STORE_ID); - // Handle if 'storeId' URL template token not provided - if ((storeId == null) || (storeId.length() == 0)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "The 'storeId' URL template token has not been provided in URL"); - } - - String nodeId = req.getServiceMatch().getTemplateVars().get(REQ_TEMPL_VAR_NODE_ID); - // Handle if 'nodeId' URL template token not provided - if ((nodeId == null) || (nodeId.length() == 0)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "The 'nodeId' URL template token has not been provided in URL"); - } - - // - // get URL parameters - // - - // get the 'includeInherited' parameter. The value defaults to 'true' if - // the parameter has not been provided - boolean includeInherited = true; - String includeInheritedParam = req.getParameter(REQ_PARAM_INCLUDE_INHERITED); - if ((includeInheritedParam != null) && (includeInheritedParam.length() > 0)) - { - includeInherited = Boolean.parseBoolean(includeInheritedParam); - } - - // get the 'ruleTypeName' parameter. The value defaults to 'null' if - // the parameter has not been provided - String ruleTypeName = null; - String ruleTypeNameParam = req.getParameter(REQ_PARAM_RULE_TYPE_NAME); - if ((ruleTypeNameParam != null) && (ruleTypeNameParam.length() > 0)) - { - ruleTypeName = ruleTypeNameParam; - } - - // create the rule owning node reference from the given URL template tokens - NodeRef owningNodeRef = this.rulesHelper.getNodeRefFromWebScriptUrl(req, storeType, storeId, nodeId); - - // get rule collection associated with the rule owning node - List rules = this.ruleService.getRules(owningNodeRef, includeInherited, ruleTypeName); - - // add objects to model for the template to render - model.put(MODEL_PROP_KEY_RULES, rules); - model.put(MODEL_PROP_KEY_OWNING_NODE_REF, owningNodeRef.toString()); - - return model; - } -} diff --git a/source/java/org/alfresco/repo/web/scripts/rule/RulesHelper.java b/source/java/org/alfresco/repo/web/scripts/rule/RulesHelper.java deleted file mode 100644 index 3b598e83e8..0000000000 --- a/source/java/org/alfresco/repo/web/scripts/rule/RulesHelper.java +++ /dev/null @@ -1,987 +0,0 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have received a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" - */ -package org.alfresco.repo.web.scripts.rule; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.alfresco.repo.model.Repository; -import org.alfresco.service.ServiceRegistry; -import org.alfresco.service.cmr.action.Action; -import org.alfresco.service.cmr.action.ActionCondition; -import org.alfresco.service.cmr.action.ActionService; -import org.alfresco.service.cmr.action.CompositeAction; -import org.alfresco.service.cmr.action.ParameterDefinition; -import org.alfresco.service.cmr.action.ParameterizedItem; -import org.alfresco.service.cmr.action.ParameterizedItemDefinition; -import org.alfresco.service.cmr.dictionary.DataTypeDefinition; -import org.alfresco.service.cmr.dictionary.DictionaryService; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter; -import org.alfresco.service.cmr.rule.Rule; -import org.alfresco.service.cmr.rule.RuleService; -import org.alfresco.service.cmr.rule.RuleType; -import org.alfresco.service.namespace.QName; -import org.springframework.extensions.webscripts.Status; -import org.springframework.extensions.webscripts.WebScriptException; -import org.springframework.extensions.webscripts.WebScriptRequest; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -/** - * Class to hold helper methods for the Rules / Actions - * REST API - * - * @author glen johnson at alfresco com - */ -public class RulesHelper -{ - // public constants for ActionQueueItem Statuses - public static final String ACTION_QUEUE_ITEM_STATUS_PENDING = "PENDING"; - public static final String ACTION_QUEUE_ITEM_STATUS_COMPLETE = "COMPLETE"; - - // private constants - private static final String COMPOSITE_ACTION_DEF_NAME = "composite-action"; - private static final String REQ_URL_PART_NODE_REF = "/api/node"; - private static final String REQ_URL_PART_NODE_PATH = "/api/path"; - private static final String REQ_URL_PART_RULE_NODE_REF = "/api/rules"; - - // service dependencies - private ServiceRegistry serviceRegistry; - - // dependencies - private Repository repositoryContext = null; - - // list of valid rule type names - List validRuleTypeNames = null; - - /** - * Set the service registry - * - * @param serviceRegistry the service registry - */ - public void setServiceRegistry(ServiceRegistry serviceRegistry) - { - this.serviceRegistry = serviceRegistry; - } - - /** - * Set the repository context - * - * @param repositoryContext the repositoryContext to set - */ - public void setRepositoryContext(Repository repositoryContext) - { - this.repositoryContext = repositoryContext; - } - - /** - * Init method. - */ - public void init() - { - // Register a list of valid rule type names - RuleService ruleService = this.serviceRegistry.getRuleService(); - validRuleTypeNames = new ArrayList(); - - List validRuleTypes = ruleService.getRuleTypes(); - for (RuleType ruleType : validRuleTypes) - { - validRuleTypeNames.add(ruleType.getName()); - } - } - - /** - * Return if the given rule type name is a valid rule type - * - * @param ruleTypeName The rule type for which we want to test validity - * - * @return Whether or not the given rule type name is valid - */ - public boolean isValidRuleTypeName(String ruleTypeName) - { - return validRuleTypeNames.contains(ruleTypeName); - } - - /** - * Return a Rule object created/updated from a given rule JSON object (Rule Details sent). - * - * If a node reference is passed into the
ruleNodeRefToUpdate
parameter, - * then this indicates that an existing rule (identified by that node - * reference) is to be updated from the given rule JSON object. If a 'null' - * node reference is passed in, then this indicates that a new rule is to - * be created from scratch. - * - * @param ruleJson the rule JSON object to create/update the rule from - * @param ruleNodeRefToUpdate The node reference of the rule to update. - * Set to
null
if a new rule is to be created from scratch. - * - * @return The rule created from the given rule JSON object - */ - public Rule getRuleFromJson(JSONObject ruleJson, NodeRef ruleNodeRefToUpdate) - { - // get a reference to the rule service - RuleService ruleService = this.serviceRegistry.getRuleService(); - - // set a boolean flag indicating whether or not to update an existing rule - boolean update = (ruleNodeRefToUpdate != null); - - // - // update/create a rule object from the given rule JSON object - // - Rule rule = null; - if (update == true) - { - // we are doing an update of an existing rule so get - // the rule identified by the given rule node reference - // so that it can be updated with the rule details - // in the given rule JSON object - rule = ruleService.getRule(ruleNodeRefToUpdate); - } - else - { - // we are not doing an update, so create a new rule from scratch - rule = new Rule(); - } - - // - // set rule properties - // - - try - { - if ((ruleJson.isNull("title") == true) && (update == false)) - { - // the "title" field is missing in the rule details, - // and we are creating a new rule, - // but the "title" field is mandatory, so throw an exception - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "A new rule is being created but the 'title' " - + "field, which is mandatory, has not been included in the rule details"); - } - // otherwise just go ahead and set the value if the field is present - // to over both creating and updating scenarios - else if (ruleJson.isNull("title") == false) - { - String ruleTitle = ruleJson.getString("title"); - rule.setTitle(ruleTitle); - } - } - catch (JSONException je) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "There was a problem reading the 'title' property " - + "in the received Rule JSON. It may contain invalid characters", je); - } - - try - { - if (ruleJson.isNull("description") == false) - { - rule.setDescription(ruleJson.getString("description")); - } - } - catch (JSONException je) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "There was a problem reading the 'description' property " - + "in the received Rule JSON. It may contain invalid characters. The title of the offending rule is '" - + ruleJson.optString("title") + "'", je); - } - - - // set values from the respective Boolean fields below, but if the - // if the value given for a field does not equate to either - // 'true' or 'false', then set it to a default value of false - - if (ruleJson.isNull("executeAsync") == false) - { - rule.setExecuteAsynchronously(ruleJson.optBoolean("executeAsync", false)); - } - - - if (ruleJson.isNull("ruleDisabled") == false) - { - rule.setRuleDisabled(ruleJson.optBoolean("ruleDisabled", false)); - } - - - if (ruleJson.isNull("appliedToChildren") == false) - { - rule.applyToChildren(ruleJson.optBoolean("appliedToChildren", false)); - } - - // - // set rule types present in the rule details onto the rule - // - - try - { - if ((ruleJson.isNull("ruleTypes") == true) && (update == false)) - { - // the "ruleTypes" field is mandatory for rule creation. it is missing in the rule details - // from which we are creating a new rule, so throw an exception - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "A new rule is being created but the 'ruleTypes' " - + "property, which is mandatory, has not been included in the rule details. The title of the " - + "offending rule is '" + ruleJson.optString("title") + "'"); - } - else if (ruleJson.isNull("ruleTypes") == false) - { - List ruleTypes = new ArrayList(); - JSONArray ruleTypesJson = ruleJson.getJSONArray("ruleTypes"); - int numRuleTypes = ruleTypesJson.length(); - - // make sure that at least one rule type has been sent in the rule details - if (numRuleTypes < 1) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "At least one rule type needs to be present in " - + "in the rule details sent in the request content. The title of the " - + "offending rule is '" + ruleJson.optString("title") + "'"); - } - - // add to the rule the rule type names sent in the rule details - for (int i=0; i < numRuleTypes; i++) - { - String ruleTypeNameJson = ruleTypesJson.getString(i); - if (isValidRuleTypeName(ruleTypeNameJson)) - { - ruleTypes.add(ruleTypeNameJson); - } - else - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "An invalid rule type name was given in the " - + "rule details sent in the request content. Invalid rule type name given is: '" - + ruleTypeNameJson + "'. The title of the offending rule containing the invalid rule type " - + "is '" + ruleJson.optString("title") + "'"); - } - } - rule.setRuleTypes(ruleTypes); - } - } - catch (JSONException je) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "There was a problem reading the 'ruleTypes' " - + "property in the received Rule JSON. It may not be a JSON Array or one of the rule types " - + "therein may contain invalid characters. The title of the offending rule is '" - + ruleJson.optString("title") + "'", je); - } - - if ((ruleJson.isNull("action") == true) && (update == false)) - { - // the "action" field is mandatory, it is missing in the rule details, - // and we are creating a new rule so throw an exception - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "A new rule is being created but the 'action' " - + "field, which is mandatory, has not been included in the rule details. The title of the " - + "offending rule is '" + ruleJson.optString("title") + "'"); - } - else - { - // set the action supplied in the rule details onto the rule - JSONObject ruleActionJson; - try - { - ruleActionJson = ruleJson.getJSONObject("action"); - } - catch (JSONException je) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "There was a problem reading the 'action' " - + "property in the received rule JSON. It is mandatory and may be missing from the " - + "rule JSON. The title of the offending rule is '" + ruleJson.optString("title") + "'", je); - } - - // if we're doing an update then the rule should already have - // this action set on it, so get the action object already on - // the rule - Action ruleActionToUpdate = null; - if (update == true) - { - String ruleActionJsonId; - try - { - ruleActionJsonId = ruleActionJson.getString("id"); - } - catch (JSONException je) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "There was a problem reading the 'id' " - + "property in the rule's root action from the received rule JSON. It is mandatory when " - + "updating a rule and may be missing from the received rule JSON. The title of the " - + "offending rule is '" + ruleJson.optString("title") + "'", je); - } - - ruleActionToUpdate = rule.getAction(); - - // throw a web script exception if the ID of the rule's action, - // already persisted to the repository, is not the same as the one - // given for the rule action's ID in the rule details that we - // wish to perform the rule update with - if (ruleActionToUpdate.getId().equals(ruleActionJsonId) == false) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "The ID sent in the rule details " - + "of the action directly associated with the rule we wish to update does not match " - + " the rule's action already persisted in the repository. The rule's nodeRef is: '" - + ruleNodeRefToUpdate + "', the action ID provided in the rule details is '" - + ruleActionJsonId + "', and the ID for the rule's action already persisted in the" - + " repository is '" + ruleActionToUpdate.getId() + "'"); - } - } - - - Action action = getActionFromJson(ruleActionJson, ruleActionToUpdate); - rule.setAction(action); - } - - return rule; - } - - /** - * Return an Action object created/updated from a given action JSON object (Action Details sent). - * - * If an action object is passed into the
actionToUpdate
parameter, - * then this indicates that this action is to be updated from the action details - * provided in the given JSON object and then returned. - * If a 'null' is passed into this parameter, then this indicates that a new action is to - * be created from scratch, populated with the action details provided in the given JSON object - * and then returned. - * - * @param actionJson the action JSON object used to create/update the action with - * @param actionToUpdate The action to be updated. - * Set to
null
if a new action is to be created from scratch. - * - * @return The action created/updated from the given action JSON object - */ - public Action getActionFromJson(JSONObject actionJson, Action actionToUpdate) - { - ActionService actionService = this.serviceRegistry.getActionService(); - - // - // if we are doing an update then set the action, to be returned, to - // the given actionToUpdate (which will then be updated by the action - // details provided in the action JSON - containing the action details sent) - // - - Action action = null; - boolean updateAction = false; - - // if an action has been given to update with fields present in the given action - // JSON object, then set that action to the current action, and set the updateAction - // indicator to true - if (actionToUpdate != null) - { - action = actionToUpdate; - updateAction = true; - } - - // - // create an action object from an "action" JSON object - // - - String actionDefinitionName; - try - { - actionDefinitionName = actionJson.getString("actionDefinitionName"); - } - catch (JSONException je) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "There was a problem reading the " - + "'actionDefinitionName' property from the the received action JSON. It is mandatory " - + "and may be missing from the received action JSON. The 'title' of the offending action is '" - + actionJson.optString("title") + "'", je); - } - JSONArray nestedActionsJson = actionJson.optJSONArray("actions"); - - // if action's definition name denotes that it is a composite action and the - // action JSON object has nested actions, then treat it as a composite action - if ((actionDefinitionName.equals(COMPOSITE_ACTION_DEF_NAME)) == true && (nestedActionsJson != null)) - { - // if we are updating an action which is a composite action, - // but the action definition name in the action JSON is not 'composite-action' - // throw a web script exception - if ((updateAction == true) && ((action instanceof CompositeAction) == false)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "The action you wish to update " - + "is not a composite action object, but the action definition name in the action JSON is " - + "'composite-action'. Thus this action could not be updated with the action JSON sent"); - } - - // TODO remove this look-up map when the back-end provides an easy way to lookup actions - // on a composite action by ID - - // if we are updating an existing composite action then create a map to easily look up the - // nested action objects for each nested action details provided in the action JSON object - Map nestedActionsMap = new HashMap(); - if ((updateAction == true) && ((action instanceof CompositeAction) == true)) - { - List nestedActions = ((CompositeAction)action).getActions(); - for (Action nestedAction: nestedActions) - { - nestedActionsMap.put(nestedAction.getId(), nestedAction); - } - } - // else if we are not updating then create composite action object - // for scratch - else if (updateAction == false) - { - action = actionService.createCompositeAction(); - } - - // recursively add nested actions to this composite action - // as some of those nested actions could also be composite actions - int numNestedActionsJson = nestedActionsJson.length(); - for (int i=0; i < numNestedActionsJson; i++) - { - JSONObject nestedActionJson = nestedActionsJson.optJSONObject(i); - - if (nestedActionJson != null) - { - Action nestedAction = null; - - // if we are doing an action update, then update the nested actions from - // the nested action JSON - if (updateAction == true) - { - String nestedActionJsonID; - try - { - nestedActionJsonID = nestedActionJson.getString("id"); - } - catch (JSONException je) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "There was a problem reading the " - + "'id' property from the received action JSON. It is mandatory when updating an action" - + "and may be missing from the received action JSON. The 'title' of the offending action is '" - + nestedActionJson.optString("title") + "'", je); - } - - // lookup to see if nested action from nested action JSON - // already exists on composite action, in which case, update - // the nested action with the nested action details provided in the - // nested action JSON - Action nestedActionToUpdate = nestedActionsMap.get(nestedActionJsonID); - if (nestedActionToUpdate != null) - { - // first remove the nested action to be updated from the parent - // composite action - ((CompositeAction)action).removeAction(nestedActionToUpdate); - - // update that nested action with the details in the nested action JSON - nestedAction = getActionFromJson(nestedActionJson, nestedActionToUpdate); - } - } - // else we are not doing an action update so just pass in the - // actionToUpdate as 'null' - else - { - nestedAction = getActionFromJson(nestedActionJson, null); - } - - // add the nested action (newly created or just updated) to - // the composite action - ((CompositeAction)action).addAction(nestedAction); - } - } - } - // else if the action definition name denotes that this is not a composite action, - // but nested actions have been provided in the action JSON Object - // then throw a Web Script Exception - else if ((actionDefinitionName.equals(COMPOSITE_ACTION_DEF_NAME) == false) && (nestedActionsJson != null)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Nested actions were sent in the action details " - + "having Title: '" + actionJson.optString("title") + "', but the action definition " - + "name thereof is not '" + COMPOSITE_ACTION_DEF_NAME + "' as expected. Instead, the action's " - + "definition name is '" + actionDefinitionName + "'."); - } - - // if we are not updating an existing action and there are no nested actions in the action JSON, - // just create a new action from the action definition without any recursive nested action handling - if ((updateAction == false) && (nestedActionsJson == null)) - { - action = actionService.createAction(actionDefinitionName); - } - - // - // set action properties - // - - try - { - if ((actionJson.isNull("title") == true) && (updateAction == false)) - { - // the "title" field is missing in the action details, - // and we are creating a new rule, - // but the "title" field is mandatory, so throw an exception - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "A new rule is being created but the 'title' " - + "field, which is mandatory, has not been included in the rule details"); - } - // otherwise go ahead and set the value if the field is present - // to cover both create and update scenarios - else if (actionJson.isNull("title") == false) - { - action.setTitle(actionJson.getString("title")); - } - } - catch (JSONException je) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "There was a problem reading the " - + "'title' property from the received action JSON. It is mandatory and may be " - + "missing from the received action JSON, or else it may contain invalid characters.", je); - } - - if (actionJson.isNull("description") == false) - { - action.setDescription(actionJson.optString("description")); - } - - // If a value has been provided in the action details for the "executeAsync" field - // then set it to the action object. - // If the value given for a field does not equate to either - // 'true' or 'false', then set it to a default value of false - - if (actionJson.isNull("executeAsync") == false) - { - action.setExecuteAsynchronously(actionJson.optBoolean("executeAsync", false)); - } - - // set compensating action on current action if a compensating action is present - // in the action JSON Object - try - { - if (actionJson.isNull("compensatingAction") == false) - { - JSONObject compActionJson = actionJson.getJSONObject("compensatingAction"); - Action compActionToUpdate = null; - - if (updateAction) - { - compActionToUpdate = action.getCompensatingAction(); - } - Action compAction = getActionFromJson(compActionJson, compActionToUpdate); - - action.setCompensatingAction(compAction); - } - } - catch (JSONException je) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "There was a problem reading the " - + "'compensatingAction' property from the received action JSON. The value of the property " - + "may not be a JSON Object or something may be wrong with one of the properties in the JSON " - + "Object for the compensating action itself. The 'title' of the offending action is '" - + actionJson.optString("title") + "'", je); - } - - // get the action's definition - ParameterizedItemDefinition actionDef = actionService.getActionDefinition(actionDefinitionName); - - // if there are parameter values in the action JSON object then - // set them onto the action object - // - JSONObject actionParamValuesJson = actionJson.optJSONObject("parameterValues"); - if (actionParamValuesJson != null) - { - setParameterValuesOnParameterizedItemFromJson(action, actionDef, actionParamValuesJson); - } - - // - // set conditions on the current action - // - - // if action JSON "conditions" property has a value - // then populate the current action's conditions with the - // conditions' details from within the action JSON - if (actionJson.isNull("conditions") == false) - { - JSONArray conditionsJson = actionJson.optJSONArray("conditions"); - - // if conditionsJson is 'null' then throw a web script exception, because this means that - // the conditions property does not contain a JSON Array. The conditions property of an incoming - // action JSON object should be a JSON Array - if (conditionsJson == null) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "The 'conditions' property of the incoming " - + "action JSON titled '" + actionJson.optString("title") + "' is not a JSON Array"); - } - - // If we are updating an existing action, then build up a map - // (keyed by condition ID) of conditions associated with that existing action. - // So for each condition JSON object (inside the incoming action JSON object), - // if the condition ID thereof is found in the map, then update the existing condition - // with the details sent in the JSON - - Map conditionsMap = new HashMap(); - if (updateAction == true) - { - List actionConditions = action.getActionConditions(); - for (ActionCondition actionCondition : actionConditions) - { - conditionsMap.put(actionCondition.getId(), actionCondition); - } - } - - // - // for each condition JSON object (associated with the incoming action JSON object): - // - if we are doing an update then update the corresponding condition object (if one exists) - // with the fields provided in the condition JSON object - // - if we are doing a create then create a new condition from the details provided - // in the condition JSON - - int numConditionsJson = conditionsJson.length(); - for (int conditionJsonIndex = 0; conditionJsonIndex < numConditionsJson; conditionJsonIndex++) - { - ActionCondition condition = null; - - JSONObject conditionJson; - try - { - conditionJson = conditionsJson.getJSONObject(conditionJsonIndex); - } - catch (JSONException je) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "There was a problem reading the " - + "condition held at index " + conditionJsonIndex + " in the JSON Array held in the " - + "'conditions' property from the received action JSON. The value held at that " - + "index may not be a JSON Object. The 'title' of the action with the offending " - + "'conditions' property is '" + actionJson.optString("title") + "'", je); - } - - String conditionDefName = null; - - // if we are doing an update, the current condition JSON has an ID, - // and a condition already exists matching that ID, then set the current - // condition to that existing condition and retrieve its definition name - if ((updateAction == true) && (conditionJson.isNull("id") == false)) - { - String conditionJsonId; - try - { - conditionJsonId = conditionJson.getString("id"); - } - catch (JSONException je) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "There was a problem reading the " - + "'id' property from a condition in the received action JSON. When doing an update " - + "this condition property is mandatory and may be missing from this condition in the " - + "action JSON sent or else the property may contain invalid parameters. " - + "The 'conditionDefinitionName' of the offending condition is '" - + conditionJson.optString("conditionDefinitionName") + "'", je); - } - - // set the current condition being processed to the existing conditions - condition = conditionsMap.get(conditionJsonId); - - // get the condition definition name - if (condition != null) - { - conditionDefName = condition.getActionConditionDefinitionName(); - } - - // remove the condition to be updated from its parent action - // The updated condition is added to the action at the end of the - // loop - action.removeActionCondition(condition); - } - - // if the current condition is still 'null' (we are not updating an existing condition), - // and if the conditionDefinitionName has not been provided in the condition JSON, then - // throw a web script exception because we need to create a new condition using the condition - // definition name provided in the condition JSON object - if ((condition == null) && (conditionJson.isNull("conditionDefinitionName"))) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "A condition details at index: '" - + conditionJsonIndex + "' for action ID '" + action.getId() + " could not be created " - + "because the 'conditionDefinitionName' field is missing from the condition details sent"); - } - - // else condition def name has been provided in the condition details - if (condition == null) - { - try - { - conditionDefName = conditionJson.getString("conditionDefinitionName"); - } - catch (JSONException je) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "There was a problem reading the " - + "'conditionDefinitionName' property from a condition in the received action JSON. " - + "This condition property is mandatory and may be missing from this condition in the " - + "action JSON sent. The 'conditionDefinitionName' of the offending condition is '" - + conditionJson.optString("conditionDefinitionName") + "'", je); - } - - condition = actionService.createActionCondition(conditionDefName); - } - - // get the condition definition object - ParameterizedItemDefinition conditionDef = actionService.getActionConditionDefinition(conditionDefName); - - // - // populate the condition (newly created, or one being updated) - // with fields given in the condition JSONs the condition's properties - // - - // Set the value for the 'invertCondition' field if that field is sent - // in the condition JSON. If the value is sent, but it does not equate to - // either 'true' or 'false', then set it to a default value of false - if (conditionJson.isNull("invertCondition") == false) - { - condition.setInvertCondition(conditionJson.optBoolean("invertCondition")); - } - - // - // if there are parameter values on the condition JSON object - // then apply them to the condition object - // - JSONObject condParamValuesJson = conditionJson.optJSONObject("parameterValues"); - if (condParamValuesJson != null) - { - setParameterValuesOnParameterizedItemFromJson(condition, conditionDef, condParamValuesJson); - } - - // add condition to action object - action.addActionCondition(condition); - } - } - - return action; - } - - /** - * Create and return a multi-valued parameter value from the given JSON object and - * parameter content type (QName) - * - * @param jsonObject The JSON object we want to convert to a multi-valued parameter value - * @param paramName The parameter name - * @param paramDataTypeDef The parameter's content type definition - * @return - */ - @SuppressWarnings("unchecked") - public Serializable getMultiValuedParameterValueFromJsonObject(JSONObject jsonObject, String paramName, - DataTypeDefinition paramDataTypeDef) - { - ArrayList multiParamValue = new ArrayList(jsonObject.length()); - - // - // convert each parameter item String value from the given JSON object to a value - // corresponding to the given parameter content type and add that converted value - // to the multi-parameter array list - // - Iterator keysIterator = jsonObject.keys(); - while (keysIterator.hasNext()) - { - String key = keysIterator.next(); - String paramValueItem = jsonObject.optString(key); - - // if this keyed object from the given JSON object - // is present and can be represented as a String, - // then convert the string to the given parameter content - // type and add it to the multi-parameter array list - if (paramValueItem != null) - { - Object paramValueItemObj = DefaultTypeConverter.INSTANCE.convert(paramDataTypeDef, paramValueItem); - // if the parameter value object, converted using the parameter's data type, is of type Serializable - // then we can go ahead and add it as one of the parameter's values - if (paramValueItemObj instanceof Serializable) - { - multiParamValue.add(paramValueItemObj); - } - else - // otherwise the converted parameter value can't be added - { - throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, - "Whilst building up the multi-valued parameter with name: '" - + paramName + "' and type: '" + paramDataTypeDef.getName() + "' an object was encountered " - + "that doesn't implement Serializable. Object value is: '" + paramValueItemObj - + "' and is of class name '" + paramValueItemObj.getClass().getName() +"'"); - } - } - } - - return multiParamValue; - } - - /** - * Sets the parameter values from the given parameter values JSON object onto the given parameterized item object - * - * @param parameterizedItem The parameterized item object onto which we want to set the parameter values from - * the given parameter values JSON object - * @param parameterizedItemDef The definition for the given parameterized item - * @param paramValuesJson The JSON object containing the parameter values to set into the parameterized item object - */ - @SuppressWarnings("unchecked") - public void setParameterValuesOnParameterizedItemFromJson(ParameterizedItem parameterizedItem, - ParameterizedItemDefinition parameterizedItemDef, JSONObject paramValuesJson) - { - // get a reference to the dictionary service - DictionaryService dictionaryService = this.serviceRegistry.getDictionaryService(); - - Iterator paramIterator = paramValuesJson.keys(); - while (paramIterator.hasNext()) - { - String paramName = paramIterator.next(); - ParameterDefinition paramDef = parameterizedItemDef.getParameterDefintion(paramName); - QName paramType = paramDef.getType(); - DataTypeDefinition paramDataTypeDef = dictionaryService.getDataType(paramType); - boolean isMultiValued = paramDef.isMultiValued(); - boolean isMandatory = paramDef.isMandatory(); - - // throw web script exception if mandatory parameter value not provided - if (paramValuesJson.isNull(paramName) && (isMandatory == true)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Mandatory parameter with name: '" - + paramName + "' expected in sent content, but it was not present. Parameter belongs to " - + "parameterized item with ID: '" + parameterizedItem.getId() + "' and definition name: '" - + parameterizedItemDef.getName() + "'"); - } - // else if a parameter value has been provided then handle this case - else if (paramValuesJson.isNull(paramName) == false) - { - // Try and get the parameter value as a JSON object (multi-valued parameter value). - JSONObject paramValueJsonObj = paramValuesJson.optJSONObject(paramName); - - // throw web script exception if parameter value is not a JSONObject (optJSONObject() returned 'null') - // and parameter's definition says that it should be multi-valued - if ((paramValueJsonObj == null) && (isMultiValued == true)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Multi-valued parameter with name: '" - + paramName + "' expected in sent content, but value provided was not multi-valued." - + "Parameter value given is: " + paramValuesJson.opt(paramName) + ". " - + "Parameter belongs to parameterized item with ID: '" + parameterizedItem.getId() - + "' and definition name: '" + parameterizedItemDef.getName() + "'"); - } - // else throw web script exception if value given is a JSON object - // (optJSONObject(paramName) didn't return 'null'), but parameter's definition says that it shouldn't - // be multi-valued - else if ((paramValueJsonObj != null) && (isMultiValued == false)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Multi-valued parameter with name: '" - + paramName + "' was sent in content, but parameter's definition says that it should not " - + "be multi-valued. Parameter value given is: " + paramValuesJson.opt(paramName) + ". " - + "Parameter belongs to parameterized item with ID: '" + parameterizedItem.getId() - + "' and definition name: '" + parameterizedItemDef.getName() + "'"); - } - // else if value given is a JSON object (optJSONObject(paramName) didn't return 'null'), - // and the parameter's definition says that it should be multi-valued - // then go ahead and add the multi-valued parameter value to the parameterized item - else if ((paramValueJsonObj != null) && (isMultiValued == true)) - { - Serializable multiParamValue = getMultiValuedParameterValueFromJsonObject(paramValueJsonObj, - paramName, paramDataTypeDef); - parameterizedItem.setParameterValue(paramName, multiParamValue); - } - // else if parameter value provided is not a JSON Object (optJSONObject(paramName) returned 'null') - // and the parameter's definition says that the parameter value should not be multi-valued, try and - // retrieve the parameter value as a String instead - else if ((paramValueJsonObj == null) && (isMultiValued == false)) - { - String paramValueStr = paramValuesJson.optString(paramName); - // if parameter value can be retrieved as a String, then add that String parameter - // value to the parameterized item - if (paramValueStr != null) - { - Object paramValueObj = DefaultTypeConverter.INSTANCE.convert(paramDataTypeDef, paramValueStr); - if (paramValueObj instanceof Serializable) - { - parameterizedItem.setParameterValue(paramName, (Serializable)paramValueObj); - } - else - { - throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, - "Whilst adding parameters to a parameterized item (action or condition) " - + "with ID '" + parameterizedItem.getId() + "' the parameter with name: '" - + paramName + "' and type: '" + paramType + "' has a value that doesn't " - + "implement Serializable. Object value is: '" + paramValueObj - + "' and is of class name '" + paramValueObj.getClass().getName() +"'"); - } - } - // else parameter value could not be retrieved as a String value (optString(paramName) returned 'null') - // so give up with trying to process it and throw a web script exception - else - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Parameter with name: '" - + paramName + "' was sent in the request content, but it could not be retrieved and " - + "added to the parameterized item. Parameter value given is: " + paramValuesJson.opt(paramName) + ". " - + "Parameter belongs to parameterized item with ID: '" + parameterizedItem.getId() - + "' and definition name: '" + parameterizedItemDef.getName() + "'"); - } - } - } - } - } - - /** - * Return a node reference to the node represented on a Web Script URL - * by the given store type, store id and id (which is either a node id or node path) - * - * @param request The Web Script request object - * @param storeType The store type associated with the node - * @param storeId The store id associated with the node - * @param id The id (or path) associated with the node - * - * @return The node reference associated with the given store type, store id and id - */ - NodeRef getNodeRefFromWebScriptUrl(WebScriptRequest req, String storeType, String storeId, String id) - { - // work out which of storeType, storeId, id have been passed in - boolean storeTypeGiven = (storeType != null) && (storeType.length() > 0); - boolean storeIdGiven = (storeId != null) && (storeId.length() > 0); - boolean idGiven = (id != null) && (id.length() > 0); - - NodeRef nodeRef = null; - // get the node reference from the storeType, storeId, id - if ((storeTypeGiven && storeIdGiven && idGiven)) - { - // see if given ID is part of either a node reference or a node path - String urlTemplateMatch = req.getServiceMatch().getPath(); - boolean nodeRefGiven = urlTemplateMatch.startsWith(REQ_URL_PART_NODE_REF) || - urlTemplateMatch.startsWith(REQ_URL_PART_RULE_NODE_REF); - boolean nodePathGiven = urlTemplateMatch.startsWith(REQ_URL_PART_NODE_PATH); - - String referenceType = null; - if (nodeRefGiven) - { - referenceType = "node"; - } - else if (nodePathGiven) - { - referenceType = "path"; - } - else - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "{store_type}/{store_id}/{id} in URL is not preceded by either " - + "'" + REQ_URL_PART_NODE_REF + "' or '" + REQ_URL_PART_NODE_PATH + "'"); - } - - String[] reference = new String[3]; - reference[0] = storeType; - reference[1] = storeId; - reference[2] = id; - - nodeRef = this.repositoryContext.findNodeRef(referenceType, reference); - } - - return nodeRef; - } -} diff --git a/source/java/org/alfresco/repo/web/scripts/rule/RulesPost.java b/source/java/org/alfresco/repo/web/scripts/rule/RulesPost.java deleted file mode 100644 index 4d5bf6720f..0000000000 --- a/source/java/org/alfresco/repo/web/scripts/rule/RulesPost.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have received a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" - */ -package org.alfresco.repo.web.scripts.rule; - -import java.util.HashMap; -import java.util.Map; - -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.rule.Rule; -import org.alfresco.service.cmr.rule.RuleService; -import org.springframework.extensions.webscripts.DeclarativeWebScript; -import org.springframework.extensions.webscripts.Status; -import org.springframework.extensions.webscripts.WebScriptException; -import org.springframework.extensions.webscripts.WebScriptRequest; -import org.json.JSONObject; - -/** - * Web Script to POST a Rule to the rule collection associated with the given actionable node. - * - * @author glen johnson at alfresco dot com - */ -public class RulesPost extends DeclarativeWebScript -{ - // private constants - private static final String URL_TEMPL_VAR_STORE_TYPE = "store_type"; - private static final String URL_TEMPL_VAR_STORE_ID = "store_id"; - private static final String URL_TEMPL_VAR_ID = "id"; - - // model property keys - private static final String MODEL_PROP_KEY_RULE = "rule"; - private static final String MODEL_PROP_KEY_OWNING_NODE_REF = "owningNodeRef"; - - // properties for services - private RuleService ruleService; - - // properties for dependencies - private RulesHelper rulesHelper; - - /** - * Set the ruleService property. - * - * @param ruleService The rule service instance to set - */ - public void setRuleService(RuleService ruleService) - { - this.ruleService = ruleService; - } - - /** - * Set the rules helper property - * - * @param rulesHelper the rulesHelper to set - */ - public void setRulesHelper(RulesHelper rulesHelper) - { - this.rulesHelper = rulesHelper; - } - - /* - * (non-Javadoc) - * - * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl( - * org.alfresco.web.scripts.WebScriptRequest, - * org.alfresco.web.scripts.WebScriptResponse) - */ - @SuppressWarnings("unchecked") - @Override - protected Map executeImpl(WebScriptRequest req, - Status status) - { - // initialise model to pass on for template to render - Map model = new HashMap(); - - String storeType = req.getServiceMatch().getTemplateVars().get(URL_TEMPL_VAR_STORE_TYPE); - // Handle if 'store_type' URL template token not provided - if ((storeType == null) || (storeType.length() == 0)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "The 'store_type' URL template token has not been provided in URL"); - } - - String storeId = req.getServiceMatch().getTemplateVars().get(URL_TEMPL_VAR_STORE_ID); - // Handle if 'storeId' URL template token not provided - if ((storeId == null) || (storeId.length() == 0)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "The 'storeId' URL template token has not been provided in URL"); - } - - String id = req.getServiceMatch().getTemplateVars().get(URL_TEMPL_VAR_ID); - // Handle if 'id' URL template token not provided - if ((id == null) || (id.length() == 0)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, - "The 'id' URL template token has not been provided in URL"); - } - - // get the posted rule JSON object by parsing request content - Object contentObj = req.parseContent(); - if (contentObj == null || !(contentObj instanceof JSONObject)) - { - throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Web Script request content must be a JSON Object. " - + "Request content is either a JSON Array or not of MIME-type application/json"); - } - JSONObject ruleJson = (JSONObject)contentObj; - - // get the rule from the rule JSON object - Rule rule = this.rulesHelper.getRuleFromJson(ruleJson, null); - - // create the actionable node reference from the given - // URL template tokens - NodeRef owningNodeRef = this.rulesHelper.getNodeRefFromWebScriptUrl(req, storeType, storeId, id); - - // apply rule to rule owning node - this.ruleService.saveRule(owningNodeRef, rule); - - // add objects to model for the template to render - model.put(MODEL_PROP_KEY_RULE, rule); - model.put(MODEL_PROP_KEY_OWNING_NODE_REF, owningNodeRef.toString()); - - return model; - } -}