1 17 package org.alfresco.repo.webservice.action; 18 19 import java.io.Serializable ; 20 import java.rmi.RemoteException ; 21 import java.util.ArrayList ; 22 import java.util.List ; 23 import java.util.Map ; 24 25 import org.alfresco.repo.action.ActionConditionImpl; 26 import org.alfresco.repo.action.ActionImpl; 27 import org.alfresco.repo.action.CompositeActionImpl; 28 import org.alfresco.repo.action.executer.CompositeActionExecuter; 29 import org.alfresco.repo.rule.RuleImpl; 30 import org.alfresco.repo.transaction.TransactionComponent; 31 import org.alfresco.repo.transaction.TransactionUtil; 32 import org.alfresco.repo.transaction.TransactionUtil.TransactionWork; 33 import org.alfresco.repo.webservice.AbstractWebService; 34 import org.alfresco.repo.webservice.Utils; 35 import org.alfresco.repo.webservice.types.NamedValue; 36 import org.alfresco.repo.webservice.types.Predicate; 37 import org.alfresco.repo.webservice.types.Reference; 38 import org.alfresco.service.cmr.action.Action; 39 import org.alfresco.service.cmr.action.ActionCondition; 40 import org.alfresco.service.cmr.action.ActionConditionDefinition; 41 import org.alfresco.service.cmr.action.ActionDefinition; 42 import org.alfresco.service.cmr.action.ActionService; 43 import org.alfresco.service.cmr.action.CompositeAction; 44 import org.alfresco.service.cmr.action.ParameterDefinition; 45 import org.alfresco.service.cmr.action.ParameterizedItem; 46 import org.alfresco.service.cmr.action.ParameterizedItemDefinition; 47 import org.alfresco.service.cmr.dictionary.DataTypeDefinition; 48 import org.alfresco.service.cmr.dictionary.DictionaryService; 49 import org.alfresco.service.cmr.repository.NodeRef; 50 import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter; 51 import org.alfresco.service.cmr.rule.Rule; 52 import org.alfresco.service.cmr.rule.RuleService; 53 import org.alfresco.service.cmr.rule.RuleType; 54 import org.alfresco.util.GUID; 55 import org.apache.commons.logging.Log; 56 import org.apache.commons.logging.LogFactory; 57 58 63 public class ActionWebService extends AbstractWebService implements ActionServiceSoapPort 64 { 65 66 private static Log logger = LogFactory.getLog(ActionWebService.class); 67 68 69 private ActionService actionService; 70 71 72 private RuleService ruleService; 73 74 75 private DictionaryService dictionaryService; 76 77 78 private TransactionComponent transactionService; 79 80 85 public void setActionService(ActionService actionService) 86 { 87 this.actionService = actionService; 88 } 89 90 95 public void setRuleService(RuleService ruleService) 96 { 97 this.ruleService = ruleService; 98 } 99 100 105 public void setDictionaryService(DictionaryService dictionaryService) 106 { 107 this.dictionaryService = dictionaryService; 108 } 109 110 115 public void setTransactionService(TransactionComponent transactionService) 116 { 117 this.transactionService = transactionService; 118 } 119 120 123 public ActionItemDefinition[] getConditionDefinitions() throws RemoteException , 124 ActionFault 125 { 126 try 127 { 128 return TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionWork<ActionItemDefinition[]>() 129 { 130 public ActionItemDefinition[] doWork() throws Exception 131 { 132 return getConditionDefintionsImpl(); 133 } 134 }); 135 } 136 catch (Throwable exception) 137 { 138 if (logger.isDebugEnabled()) 139 { 140 logger.error("Unexpected error occurred", exception); 141 } 142 143 throw new ActionFault(0, exception.getMessage()); 144 } 145 } 146 147 152 private ActionItemDefinition[] getConditionDefintionsImpl() throws RemoteException 153 { 154 List <ActionConditionDefinition> definitions = this.actionService.getActionConditionDefinitions(); 156 157 ActionItemDefinition[] result = new ActionItemDefinition[definitions.size()]; 159 int index = 0; 160 for (ActionConditionDefinition definition : definitions) 161 { 162 result[index] = convertToActionItemDefintion(definition, ActionItemDefinitionType.condition); 163 index++; 164 } 165 166 return result; 167 } 168 169 172 public ActionItemDefinition[] getActionDefinitions() throws RemoteException , 173 ActionFault 174 { 175 try 176 { 177 return TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionWork<ActionItemDefinition[]>() 178 { 179 public ActionItemDefinition[] doWork() throws Exception 180 { 181 return getActionDefinitionsImpl(); 182 } 183 }); 184 } 185 catch (Throwable exception) 186 { 187 if (logger.isDebugEnabled()) 188 { 189 logger.error("Unexpected error occurred", exception); 190 } 191 192 throw new ActionFault(0, exception.getMessage()); 193 } 194 } 195 196 201 private ActionItemDefinition[] getActionDefinitionsImpl() throws RemoteException 202 { 203 List <ActionDefinition> definitions = this.actionService.getActionDefinitions(); 205 206 ActionItemDefinition[] result = new ActionItemDefinition[definitions.size()]; 208 int index = 0; 209 for (ActionDefinition definition : definitions) 210 { 211 result[index] = convertToActionItemDefintion(definition, ActionItemDefinitionType.action); 212 index++; 213 } 214 215 return result; 216 } 217 218 221 public ActionItemDefinition getActionItemDefinition(final String name, final ActionItemDefinitionType definitionType) throws RemoteException , ActionFault 222 { 223 try 224 { 225 return TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionWork<ActionItemDefinition>() 226 { 227 public ActionItemDefinition doWork() throws Exception 228 { 229 return getActionItemDefinitionImpl(name, definitionType); 230 } 231 }); 232 } 233 catch (Throwable exception) 234 { 235 if (logger.isDebugEnabled()) 236 { 237 logger.error("Unexpected error occurred", exception); 238 } 239 240 throw new ActionFault(0, exception.getMessage()); 241 } 242 } 243 244 252 public ActionItemDefinition getActionItemDefinitionImpl(String name, ActionItemDefinitionType definitionType) throws RemoteException , ActionFault 253 { 254 ActionItemDefinition result = null; 255 256 if (definitionType.equals(ActionItemDefinitionType.action) == true) 257 { 258 ActionDefinition actionDefinition = this.actionService.getActionDefinition(name); 259 if (actionDefinition != null) 260 { 261 result = convertToActionItemDefintion(actionDefinition, definitionType); 262 } 263 } 264 else 265 { 266 ActionConditionDefinition conditionDefinition = this.actionService.getActionConditionDefinition(name); 267 if (conditionDefinition != null) 268 { 269 result = convertToActionItemDefintion(conditionDefinition, definitionType); 270 } 271 } 272 273 return result; 274 } 275 276 283 private ActionItemDefinition convertToActionItemDefintion(ParameterizedItemDefinition definition, ActionItemDefinitionType type) 284 { 285 ActionItemDefinition actionItemType = new ActionItemDefinition(); 287 actionItemType.setName(definition.getName()); 288 actionItemType.setType(type); 289 actionItemType.setTitle(definition.getTitle()); 290 actionItemType.setDescription(definition.getDescription()); 291 actionItemType.setAdHocPropertiesAllowed(definition.getAdhocPropertiesAllowed()); 292 293 List <ParameterDefinition> params = definition.getParameterDefinitions(); 295 org.alfresco.repo.webservice.action.ParameterDefinition[] parameterDefinitions = new org.alfresco.repo.webservice.action.ParameterDefinition[params.size()]; 296 int index = 0; 297 for (ParameterDefinition paramDef : params) 298 { 299 org.alfresco.repo.webservice.action.ParameterDefinition parameterDefinition = new org.alfresco.repo.webservice.action.ParameterDefinition( 300 paramDef.getName(), 301 paramDef.getType().toString(), 302 paramDef.isMandatory(), 303 paramDef.getDisplayLabel()); 304 parameterDefinitions[index] = parameterDefinition; 305 index ++; 306 } 307 actionItemType.setParameterDefinition(parameterDefinitions); 308 309 return actionItemType; 310 } 311 312 315 public org.alfresco.repo.webservice.action.RuleType[] getRuleTypes() throws RemoteException , ActionFault 316 { 317 try 318 { 319 return TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionWork<org.alfresco.repo.webservice.action.RuleType[]>() 320 { 321 public org.alfresco.repo.webservice.action.RuleType[] doWork() throws Exception 322 { 323 return getRuleTypesImpl(); 324 } 325 }); 326 } 327 catch (Throwable exception) 328 { 329 if (logger.isDebugEnabled()) 330 { 331 logger.error("Unexpected error occurred", exception); 332 } 333 334 throw new ActionFault(0, exception.getMessage()); 335 } 336 } 337 338 public org.alfresco.repo.webservice.action.RuleType[] getRuleTypesImpl() throws RemoteException , ActionFault 339 { 340 List <RuleType> ruleTypes = this.ruleService.getRuleTypes(); 342 343 org.alfresco.repo.webservice.action.RuleType[] results = new org.alfresco.repo.webservice.action.RuleType[ruleTypes.size()]; 345 int index = 0; 346 for (RuleType ruleType : ruleTypes) 347 { 348 org.alfresco.repo.webservice.action.RuleType webServiceRuleType = new org.alfresco.repo.webservice.action.RuleType( 349 ruleType.getName(), 350 ruleType.getDisplayLabel()); 351 results[index] = webServiceRuleType; 352 index ++; 353 } 354 355 return results; 356 } 357 358 361 public org.alfresco.repo.webservice.action.RuleType getRuleType(final String name) throws RemoteException , ActionFault 362 { 363 try 364 { 365 return TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionWork<org.alfresco.repo.webservice.action.RuleType>() 366 { 367 public org.alfresco.repo.webservice.action.RuleType doWork() throws Exception 368 { 369 return getRuleTypeImpl(name); 370 } 371 }); 372 } 373 catch (Throwable exception) 374 { 375 if (logger.isDebugEnabled()) 376 { 377 logger.error("Unexpected error occurred", exception); 378 } 379 380 throw new ActionFault(0, exception.getMessage()); 381 } 382 } 383 384 public org.alfresco.repo.webservice.action.RuleType getRuleTypeImpl(String name) throws RemoteException , ActionFault 385 { 386 org.alfresco.repo.webservice.action.RuleType result = null; 387 388 RuleType ruleType = this.ruleService.getRuleType(name); 389 if (ruleType != null) 390 { 391 result = new org.alfresco.repo.webservice.action.RuleType(ruleType.getName(), ruleType.getDisplayLabel()); 392 } 393 394 return result; 395 } 396 397 400 public org.alfresco.repo.webservice.action.Action[] getActions(final Reference reference, final ActionFilter filter) throws RemoteException , ActionFault 401 { 402 try 403 { 404 return TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionWork<org.alfresco.repo.webservice.action.Action[]>() 405 { 406 public org.alfresco.repo.webservice.action.Action[] doWork() throws Exception 407 { 408 return getActionsImpl(reference, filter); 409 } 410 }); 411 } 412 catch (Throwable exception) 413 { 414 if (logger.isDebugEnabled()) 415 { 416 logger.error("Unexpected error occurred", exception); 417 } 418 419 throw new ActionFault(0, exception.getMessage()); 420 } 421 } 422 423 private org.alfresco.repo.webservice.action.Action[] getActionsImpl(Reference reference, ActionFilter filter) throws RemoteException , ActionFault 424 { 425 NodeRef nodeRef = Utils.convertToNodeRef(reference, this.nodeService, this.searchService, this.namespaceService); 427 List <Action> actions = this.actionService.getActions(nodeRef); 428 429 org.alfresco.repo.webservice.action.Action[] webServiceActions = new org.alfresco.repo.webservice.action.Action[actions.size()]; 430 431 if (filter != null) 433 { 434 } 436 437 int index = 0; 439 for (Action action : actions) 440 { 441 webServiceActions[index] = convertToWebServiceAction(action); 442 index++; 443 } 444 445 return webServiceActions; 446 } 447 448 private org.alfresco.repo.webservice.action.Action convertToWebServiceAction(Action action) 449 { 450 NamedValue[] namedValues = convertParametersToNamedValues(action); 452 453 List <ActionCondition> conditions = action.getActionConditions(); 455 Condition[] webServiceConditions = new Condition[conditions.size()]; 456 int index2 = 0; 457 for (ActionCondition condition : conditions) 458 { 459 webServiceConditions[index2] = convertToWebServiceCondition(condition); 460 index2++; 461 } 462 463 Action compensatingAction = action.getCompensatingAction(); 465 org.alfresco.repo.webservice.action.Action webServiceCompensatingAction = null; 466 if (compensatingAction != null) 467 { 468 webServiceCompensatingAction = convertToWebServiceAction(compensatingAction); 469 } 470 471 org.alfresco.repo.webservice.action.Action[] childWebServiceActions = null; 473 if (action instanceof CompositeAction) 474 { 475 List <Action> childActions = ((CompositeAction)action).getActions(); 476 childWebServiceActions = new org.alfresco.repo.webservice.action.Action[childActions.size()]; 477 int index3 = 0; 478 for (Action childAction : childActions) 479 { 480 childWebServiceActions[index3] = convertToWebServiceAction(childAction); 481 index3 ++; 482 } 483 } 484 485 NodeRef owningNodeRef = action.getOwningNodeRef(); 487 Reference reference = null; 488 if (owningNodeRef != null) 489 { 490 reference = Utils.convertToReference(owningNodeRef); 491 } 492 493 org.alfresco.repo.webservice.action.Action webServiceAction = new org.alfresco.repo.webservice.action.Action( 495 action.getId(), 496 action.getActionDefinitionName(), 497 action.getTitle(), 498 action.getDescription(), 499 action.getExecuteAsychronously(), 500 namedValues, 501 webServiceConditions, 502 webServiceCompensatingAction, 503 childWebServiceActions, 504 reference); 505 506 return webServiceAction; 507 } 508 509 514 private NamedValue[] convertParametersToNamedValues(ParameterizedItem item) 515 { 516 NamedValue[] namedValues = null; 517 if (item != null) 518 { 519 Map <String , Serializable > params = item.getParameterValues(); 520 namedValues = new NamedValue[params.size()]; 521 int index = 0; 522 for (Map.Entry <String , Serializable > entry : params.entrySet()) 523 { 524 String value = null; 525 try 526 { 527 value = DefaultTypeConverter.INSTANCE.convert(String .class, entry.getValue()); 528 } 529 catch (Throwable exception) 530 { 531 value = entry.getValue().toString(); 532 } 533 namedValues[index] = new NamedValue(entry.getKey(), value); 534 index++; 535 } 536 } 537 return namedValues; 538 } 539 540 545 private Condition convertToWebServiceCondition(ActionCondition condition) 546 { 547 NamedValue[] namedValues = convertParametersToNamedValues(condition); 549 550 Condition webServiceCondition = new Condition( 551 condition.getId(), 552 condition.getActionConditionDefinitionName(), 553 condition.getInvertCondition(), 554 namedValues); 555 556 return webServiceCondition; 557 } 558 559 562 public org.alfresco.repo.webservice.action.Action[] saveActions( 563 final Reference reference, 564 final org.alfresco.repo.webservice.action.Action[] webServiceActions) throws RemoteException , ActionFault 565 { 566 try 567 { 568 return TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionWork<org.alfresco.repo.webservice.action.Action[]>() 569 { 570 public org.alfresco.repo.webservice.action.Action[] doWork() throws Exception 571 { 572 return saveActionsImpl(reference, webServiceActions); 573 } 574 }); 575 } 576 catch (Throwable exception) 577 { 578 if (logger.isDebugEnabled()) 579 { 580 logger.error("Unexpected error occurred", exception); 581 } 582 583 throw new ActionFault(0, exception.getMessage()); 584 } 585 } 586 587 595 private org.alfresco.repo.webservice.action.Action[] saveActionsImpl( 596 Reference reference, 597 org.alfresco.repo.webservice.action.Action[] webServiceActions) throws RemoteException , ActionFault 598 { 599 NodeRef nodeRef = Utils.convertToNodeRef(reference, this.nodeService, this.searchService, this.namespaceService); 601 602 org.alfresco.repo.webservice.action.Action[] results = new org.alfresco.repo.webservice.action.Action[webServiceActions.length]; 604 605 int index = 0; 606 for (org.alfresco.repo.webservice.action.Action webServiceAction : webServiceActions) 607 { 608 Action action = convertToAction(webServiceAction); 610 611 this.actionService.saveAction(nodeRef, action); 613 614 results[index] = convertToWebServiceAction(action); 616 index++; 617 } 618 619 return results; 620 } 621 622 628 private Action convertToAction(org.alfresco.repo.webservice.action.Action webServiceAction) 629 { 630 String id = webServiceAction.getId(); 632 if (id == null || id.length() == 0) 633 { 634 id = GUID.generate(); 635 } 636 637 NodeRef owningNodeRef = null; 639 if (webServiceAction.getReference() != null) 640 { 641 owningNodeRef = Utils.convertToNodeRef( 642 webServiceAction.getReference(), 643 this.nodeService, 644 this.searchService, 645 this.namespaceService); 646 } 647 648 ActionImpl action = null; 650 String actionDefinitionName = webServiceAction.getActionName(); 651 if (CompositeActionExecuter.NAME.equals(actionDefinitionName) == true) 652 { 653 action = new CompositeActionImpl(id, owningNodeRef); 654 } 655 else 656 { 657 action = new ActionImpl(id, actionDefinitionName, owningNodeRef); 658 } 659 660 action.setTitle(webServiceAction.getTitle()); 662 action.setDescription(webServiceAction.getDescription()); 663 if (webServiceAction.isExecuteAsynchronously() == true) 664 { 665 action.setExecuteAsynchronously(true); 666 } 667 668 NamedValue[] namedValues = webServiceAction.getParameters(); 670 for (NamedValue namedValue : namedValues) 671 { 672 DataTypeDefinition propertyType = null; 674 ActionDefinition actionDefintion = this.actionService.getActionDefinition(action.getActionDefinitionName()); 675 ParameterDefinition propertyDefintion = actionDefintion.getParameterDefintion(namedValue.getName()); 676 if (propertyDefintion != null) 677 { 678 propertyType = this.dictionaryService.getDataType(propertyDefintion.getType()); 679 } 680 681 Serializable value = null; 683 if (propertyType != null) 684 { 685 value = (Serializable )DefaultTypeConverter.INSTANCE.convert(propertyType, namedValue.getValue()); 686 } 687 else 688 { 689 value = namedValue.getValue(); 690 } 691 692 action.setParameterValue(namedValue.getName(), value); 694 } 695 696 Condition[] webServiceConditions = webServiceAction.getConditions(); 698 if (webServiceConditions != null) 699 { 700 for (Condition webServiceCondition : webServiceConditions) 701 { 702 action.addActionCondition(convertToActionCondition(webServiceCondition)); 703 } 704 } 705 706 org.alfresco.repo.webservice.action.Action webServiceCompensatingAction = webServiceAction.getCompensatingAction(); 708 if (webServiceCompensatingAction != null) 709 { 710 Action compensatingAction = convertToAction(webServiceCompensatingAction); 711 action.setCompensatingAction(compensatingAction); 712 } 713 714 if (CompositeActionExecuter.NAME.equals(actionDefinitionName) == true) 716 { 717 org.alfresco.repo.webservice.action.Action[] webServiceChildActions = webServiceAction.getActions(); 718 if (webServiceChildActions != null) 719 { 720 for (org.alfresco.repo.webservice.action.Action webServiceChildAction : webServiceChildActions) 721 { 722 Action childAction = convertToAction(webServiceChildAction); 723 ((CompositeAction)action).addAction(childAction); 724 } 725 } 726 } 727 728 return action; 729 } 730 731 736 private ActionCondition convertToActionCondition(Condition webServiceCondition) 737 { 738 String id = webServiceCondition.getId(); 740 if (id == null || id.length() == 0) 741 { 742 id = GUID.generate(); 743 } 744 745 ActionCondition actionCondition = new ActionConditionImpl(id, webServiceCondition.getConditionName()); 747 748 actionCondition.setInvertCondition(webServiceCondition.isInvertCondition()); 750 751 NamedValue[] namedValues = webServiceCondition.getParameters(); 753 for (NamedValue namedValue : namedValues) 754 { 755 DataTypeDefinition propertyType = null; 757 ActionConditionDefinition actionConditionDefintion = this.actionService.getActionConditionDefinition(actionCondition.getActionConditionDefinitionName()); 758 ParameterDefinition propertyDefintion = actionConditionDefintion.getParameterDefintion(namedValue.getName()); 759 if (propertyDefintion != null) 760 { 761 propertyType = this.dictionaryService.getDataType(propertyDefintion.getType()); 762 } 763 764 Serializable value = null; 766 if (propertyType != null) 767 { 768 value = (Serializable )DefaultTypeConverter.INSTANCE.convert(propertyType, namedValue.getValue()); 769 } 770 else 771 { 772 value = namedValue.getValue(); 773 } 774 775 actionCondition.setParameterValue(namedValue.getName(), value); 777 } 778 779 return actionCondition; 780 } 781 782 785 public void removeActions(final Reference reference, final org.alfresco.repo.webservice.action.Action[] webServiceActions) 786 throws RemoteException , ActionFault 787 { 788 try 789 { 790 TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionWork<Object >() 791 { 792 public Object doWork() throws Exception 793 { 794 removeActionsImpl(reference, webServiceActions); 795 return null; 796 } 797 }); 798 } 799 catch (Throwable exception) 800 { 801 if (logger.isDebugEnabled()) 802 { 803 logger.error("Unexpected error occurred", exception); 804 } 805 806 throw new ActionFault(0, exception.getMessage()); 807 } 808 } 809 810 private void removeActionsImpl(Reference reference, org.alfresco.repo.webservice.action.Action[] webServiceActions) 811 throws RemoteException , ActionFault 812 { 813 NodeRef nodeRef = Utils.convertToNodeRef(reference, this.nodeService, this.searchService, this.namespaceService); 815 816 if (webServiceActions == null) 817 { 818 this.actionService.removeAllActions(nodeRef); 820 } 821 else 822 { 823 for (org.alfresco.repo.webservice.action.Action webServiceAction : webServiceActions) 824 { 825 Action action = convertToAction(webServiceAction); 826 this.actionService.removeAction(nodeRef, action); 827 } 828 } 829 } 830 831 834 public ActionExecutionResult[] executeActions(final Predicate predicate, final org.alfresco.repo.webservice.action.Action[] webServiceActions) throws RemoteException , ActionFault 835 { 836 try 837 { 838 return TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionWork<ActionExecutionResult[]>() 839 { 840 public ActionExecutionResult[] doWork() throws Exception 841 { 842 return executeActionsImpl(predicate, webServiceActions); 843 } 844 }); 845 } 846 catch (Throwable exception) 847 { 848 if (logger.isDebugEnabled()) 849 { 850 logger.error("Unexpected error occurred", exception); 851 } 852 853 throw new ActionFault(0, exception.getMessage()); 854 } 855 } 856 857 866 public ActionExecutionResult[] executeActionsImpl(Predicate predicate, org.alfresco.repo.webservice.action.Action[] webServiceActions) throws RemoteException , ActionFault 867 { 868 List <ActionExecutionResult> results = new ArrayList <ActionExecutionResult>(10); 869 870 List <NodeRef> nodeRefs = Utils.resolvePredicate(predicate, this.nodeService, this.searchService, this.namespaceService); 872 for (NodeRef nodeRef : nodeRefs) 873 { 874 ActionExecutionResult executionResult = new ActionExecutionResult(); 876 executionResult.setReference(Utils.convertToReference(nodeRef)); 877 878 List <org.alfresco.repo.webservice.action.Action> executedActions = new ArrayList <org.alfresco.repo.webservice.action.Action>(10); 880 for (org.alfresco.repo.webservice.action.Action webServiceAction : webServiceActions) 881 { 882 Action action = convertToAction(webServiceAction); 884 885 if (this.actionService.evaluateAction(action, nodeRef) == true) 887 { 888 this.actionService.executeAction(action, nodeRef, false); 890 executedActions.add(webServiceAction); 891 } 892 } 893 894 org.alfresco.repo.webservice.action.Action[] executedWebServiceActions = (org.alfresco.repo.webservice.action.Action[])executedActions.toArray(new org.alfresco.repo.webservice.action.Action[executedActions.size()]); 896 executionResult.setActions(executedWebServiceActions); 897 898 results.add(executionResult); 900 } 901 return (ActionExecutionResult[])results.toArray(new ActionExecutionResult[results.size()]); 902 } 903 904 907 public org.alfresco.repo.webservice.action.Rule[] getRules(final Reference reference, final RuleFilter ruleFilter) 908 throws RemoteException , ActionFault 909 { 910 try 911 { 912 return TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionWork<org.alfresco.repo.webservice.action.Rule[]>() 913 { 914 public org.alfresco.repo.webservice.action.Rule[] doWork() throws Exception 915 { 916 return getRulesImpl(reference, ruleFilter); 917 } 918 }); 919 } 920 catch (Throwable exception) 921 { 922 if (logger.isDebugEnabled()) 923 { 924 logger.error("Unexpected error occurred", exception); 925 } 926 927 throw new ActionFault(0, exception.getMessage()); 928 } 929 } 930 931 private org.alfresco.repo.webservice.action.Rule[] getRulesImpl(Reference reference, RuleFilter ruleFilter) 932 throws RemoteException , ActionFault 933 { 934 NodeRef nodeRef = Utils.convertToNodeRef(reference, this.nodeService, this.searchService, this.namespaceService); 936 937 List <Rule> rules = this.ruleService.getRules(nodeRef); 939 940 943 org.alfresco.repo.webservice.action.Rule[] webServiceRules = new org.alfresco.repo.webservice.action.Rule[rules.size()]; 945 int index = 0; 946 for (Rule rule : rules) 947 { 948 webServiceRules[index] = convertToWebServiceRule(rule); 949 index ++; 950 } 951 952 953 return webServiceRules; 954 } 955 956 private org.alfresco.repo.webservice.action.Rule convertToWebServiceRule(Rule rule) 957 { 958 String runAsUserName = null; 961 962 List <ActionCondition> conditions = rule.getActionConditions(); 964 Condition[] webServiceConditions = new Condition[conditions.size()]; 965 int index2 = 0; 966 for (ActionCondition condition : conditions) 967 { 968 webServiceConditions[index2] = convertToWebServiceCondition(condition); 969 index2++; 970 } 971 972 org.alfresco.repo.webservice.action.Action[] childWebServiceActions = null; 974 List <Action> childActions = rule.getActions(); 975 childWebServiceActions = new org.alfresco.repo.webservice.action.Action[childActions.size()]; 976 int index3 = 0; 977 for (Action childAction : childActions) 978 { 979 childWebServiceActions[index3] = convertToWebServiceAction(childAction); 980 index3 ++; 981 } 982 983 NodeRef owningNodeRef = rule.getOwningNodeRef(); 985 Reference reference = null; 986 if (owningNodeRef != null) 987 { 988 reference = Utils.convertToReference(owningNodeRef); 989 } 990 991 org.alfresco.repo.webservice.action.Rule webServiceRule = new org.alfresco.repo.webservice.action.Rule( 993 rule.getId(), 994 rule.getRuleTypeName(), 995 rule.getTitle(), 996 rule.getDescription(), 997 rule.getExecuteAsychronously(), 998 webServiceConditions, 999 childWebServiceActions, 1000 runAsUserName, 1001 reference); 1002 1003 return webServiceRule; 1004 } 1005 1006 1009 public org.alfresco.repo.webservice.action.Rule[] saveRules(final Reference reference, final org.alfresco.repo.webservice.action.Rule[] webServiceRules) 1010 throws RemoteException , ActionFault 1011 { 1012 try 1013 { 1014 return TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionWork<org.alfresco.repo.webservice.action.Rule[]>() 1015 { 1016 public org.alfresco.repo.webservice.action.Rule[] doWork() throws Exception 1017 { 1018 return saveRulesImpl(reference, webServiceRules); 1019 } 1020 }); 1021 } 1022 catch (Throwable exception) 1023 { 1024 if (logger.isDebugEnabled()) 1025 { 1026 logger.error("Unexpected error occurred", exception); 1027 } 1028 1029 throw new ActionFault(0, exception.getMessage()); 1030 } 1031 } 1032 1033 private org.alfresco.repo.webservice.action.Rule[] saveRulesImpl(Reference reference, org.alfresco.repo.webservice.action.Rule[] webServiceRules) 1034 throws RemoteException , ActionFault 1035 { 1036 NodeRef nodeRef = Utils.convertToNodeRef(reference, this.nodeService, this.searchService, this.namespaceService); 1038 1039 org.alfresco.repo.webservice.action.Rule[] results = new org.alfresco.repo.webservice.action.Rule[webServiceRules.length]; 1041 1042 int index = 0; 1043 for (org.alfresco.repo.webservice.action.Rule webServiceRule : webServiceRules) 1044 { 1045 Rule rule = convertToRule(webServiceRule); 1047 1048 this.ruleService.saveRule(nodeRef, rule); 1050 1051 results[index] = convertToWebServiceRule(rule); 1053 index++; 1054 } 1055 1056 return results; 1057 } 1058 1059 1062 public void removeRules(final Reference reference, final org.alfresco.repo.webservice.action.Rule[] webServiceRules) 1063 throws RemoteException , ActionFault 1064 { 1065 try 1066 { 1067 TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionWork<Object >() 1068 { 1069 public Object doWork() throws Exception 1070 { 1071 removeRulesImpl(reference, webServiceRules); 1072 return null; 1073 } 1074 }); 1075 } 1076 catch (Throwable exception) 1077 { 1078 if (logger.isDebugEnabled()) 1079 { 1080 logger.error("Unexpected error occurred", exception); 1081 } 1082 1083 throw new ActionFault(0, exception.getMessage()); 1084 } 1085 } 1086 1087 1094 public void removeRulesImpl(Reference reference, org.alfresco.repo.webservice.action.Rule[] webServiceRules) 1095 throws RemoteException , ActionFault 1096 { 1097 NodeRef nodeRef = Utils.convertToNodeRef(reference, this.nodeService, this.searchService, this.namespaceService); 1099 1100 if (webServiceRules == null) 1101 { 1102 this.ruleService.removeAllRules(nodeRef); 1104 } 1105 else 1106 { 1107 for (org.alfresco.repo.webservice.action.Rule webServiceRule : webServiceRules) 1108 { 1109 Rule rule = convertToRule(webServiceRule); 1110 this.ruleService.removeRule(nodeRef, rule); 1111 } 1112 } 1113 1114 } 1115 1116 1121 private Rule convertToRule(org.alfresco.repo.webservice.action.Rule webServiceRule) 1122 { 1123 String id = webServiceRule.getId(); 1125 if (id == null || id.length() == 0) 1126 { 1127 id = GUID.generate(); 1128 } 1129 1130 NodeRef owningNodeRef = null; 1132 if (webServiceRule.getReference() != null) 1133 { 1134 owningNodeRef = Utils.convertToNodeRef( 1135 webServiceRule.getReference(), 1136 this.nodeService, 1137 this.searchService, 1138 this.namespaceService); 1139 } 1140 1141 String ruleTypeName = webServiceRule.getRuleType(); 1143 1144 RuleImpl rule = new RuleImpl(id, ruleTypeName, owningNodeRef); 1146 1147 rule.setTitle(webServiceRule.getTitle()); 1149 rule.setDescription(webServiceRule.getDescription()); 1150 rule.setExecuteAsynchronously(webServiceRule.isExecuteAsynchronously()); 1151 1152 Condition[] webServiceConditions = webServiceRule.getConditions(); 1154 if (webServiceConditions != null) 1155 { 1156 for (Condition webServiceCondition : webServiceConditions) 1157 { 1158 rule.addActionCondition(convertToActionCondition(webServiceCondition)); 1159 } 1160 } 1161 1162 org.alfresco.repo.webservice.action.Action[] webServiceChildActions = webServiceRule.getActions(); 1164 if (webServiceChildActions != null) 1165 { 1166 for (org.alfresco.repo.webservice.action.Action webServiceChildAction : webServiceChildActions) 1167 { 1168 Action childAction = convertToAction(webServiceChildAction); 1169 rule.addAction(childAction); 1170 } 1171 } 1172 1173 return rule; 1174 } 1175} 1176 | Popular Tags |