1 17 package org.alfresco.web.bean.wizard; 18 19 import java.io.Serializable ; 20 import java.text.MessageFormat ; 21 import java.util.ArrayList ; 22 import java.util.HashMap ; 23 import java.util.List ; 24 import java.util.Map ; 25 import java.util.ResourceBundle ; 26 27 import javax.faces.context.FacesContext; 28 import javax.faces.event.ActionEvent; 29 import javax.faces.model.DataModel; 30 import javax.faces.model.ListDataModel; 31 import javax.faces.model.SelectItem; 32 import javax.transaction.UserTransaction ; 33 34 import org.alfresco.config.Config; 35 import org.alfresco.config.ConfigElement; 36 import org.alfresco.config.ConfigService; 37 import org.alfresco.error.AlfrescoRuntimeException; 38 import org.alfresco.model.ContentModel; 39 import org.alfresco.repo.action.evaluator.CompareMimeTypeEvaluator; 40 import org.alfresco.repo.action.evaluator.ComparePropertyValueEvaluator; 41 import org.alfresco.repo.action.evaluator.HasAspectEvaluator; 42 import org.alfresco.repo.action.evaluator.InCategoryEvaluator; 43 import org.alfresco.repo.action.evaluator.IsSubTypeEvaluator; 44 import org.alfresco.repo.action.executer.CheckInActionExecuter; 45 import org.alfresco.repo.action.executer.SimpleWorkflowActionExecuter; 46 import org.alfresco.repo.action.executer.SpecialiseTypeActionExecuter; 47 import org.alfresco.service.cmr.action.Action; 48 import org.alfresco.service.cmr.action.ActionCondition; 49 import org.alfresco.service.cmr.action.ActionConditionDefinition; 50 import org.alfresco.service.cmr.dictionary.TypeDefinition; 51 import org.alfresco.service.cmr.repository.MimetypeService; 52 import org.alfresco.service.cmr.repository.NodeRef; 53 import org.alfresco.service.cmr.rule.Rule; 54 import org.alfresco.service.cmr.rule.RuleService; 55 import org.alfresco.service.cmr.rule.RuleType; 56 import org.alfresco.service.namespace.QName; 57 import org.alfresco.web.app.Application; 58 import org.alfresco.web.bean.RulesBean; 59 import org.alfresco.web.bean.repository.Node; 60 import org.alfresco.web.bean.repository.Repository; 61 import org.alfresco.web.data.IDataContainer; 62 import org.alfresco.web.data.QuickSort; 63 import org.alfresco.web.ui.common.Utils; 64 import org.apache.commons.logging.Log; 65 import org.apache.commons.logging.LogFactory; 66 67 72 public class NewRuleWizard extends BaseActionWizard 73 { 74 public static final String PROP_ACTION_NAME = "actionName"; 76 public static final String PROP_ACTION_SUMMARY = "actionSummary"; 77 78 public static final String PROP_CONDITION_NAME = "conditionName"; 80 public static final String PROP_CONDITION_SUMMARY = "conditionSummary"; 81 public static final String PROP_CONDITION_NOT = "notcondition"; 82 public static final String PROP_PROPERTY = "property"; 83 public static final String PROP_CONTAINS_TEXT = "containstext"; 84 public static final String PROP_MODEL_TYPE = "modeltype"; 85 public static final String PROP_MIMETYPE = "mimetype"; 86 public static final String PROP_MODEL_ASPECT = "modelaspect"; 87 public static final String PROP_TYPE_OR_ASPECT = "typeoraspect"; 88 89 private static Log logger = LogFactory.getLog(NewRuleWizard.class); 90 91 private static final String ERROR = "error_rule"; 92 93 private static final String WIZARD_TITLE_ID = "new_rule_title"; 95 private static final String WIZARD_TITLE_EDIT_ID = "new_rule_title_edit"; 96 private static final String WIZARD_DESC_ID = "new_rule_desc"; 97 private static final String WIZARD_DESC_EDIT_ID = "new_rule_desc_edit"; 98 private static final String STEP1_TITLE_ID = "new_rule_step1_title"; 99 private static final String STEP2_TITLE_ID = "new_rule_step2_title"; 100 private static final String STEP3_TITLE_ID = "new_rule_step3_title"; 101 private static final String FINISH_INSTRUCTION_ID = "new_rule_finish_instruction"; 102 private static final String FINISH_INSTRUCTION_EDIT_ID = "new_rule_finish_instruction_edit"; 103 104 private String title; 106 private String description; 107 private String type; 108 private String condition; 109 private boolean runInBackground; 110 private boolean applyToSubSpaces; 111 private boolean editingAction; 112 private boolean editingCondition; 113 114 protected RuleService ruleService; 115 protected RulesBean rulesBean; 116 117 private List <SelectItem> modelTypes; 118 private List <SelectItem> mimeTypes; 119 private List <SelectItem> types; 120 private List <SelectItem> conditions; 121 private List <SelectItem> typesAndAspects; 122 private Map <String , String > conditionDescriptions; 123 private Map <String , Serializable > currentConditionProperties; 124 125 private List <Map <String , Serializable >> allActionsProperties; 126 private List <Map <String , Serializable >> allConditionsProperties; 127 128 private DataModel allActionsDataModel; 129 private DataModel allConditionsDataModel; 130 131 private boolean isFinished = false; 132 133 138 public synchronized String finish() 139 { 140 String outcome = FINISH_OUTCOME; 141 142 if (isFinished == false) 143 { 144 isFinished = true; 145 146 UserTransaction tx = null; 147 148 try 149 { 150 tx = Repository.getUserTransaction(FacesContext.getCurrentInstance()); 151 tx.begin(); 152 153 Node currentSpace = browseBean.getActionSpace(); 156 157 Rule rule = null; 158 159 if (this.editMode) 160 { 161 rule = this.rulesBean.getCurrentRule(); 163 164 rule.removeAllActionConditions(); 166 rule.removeAllActions(); 167 } 168 else 169 { 170 rule = this.ruleService.createRule(this.getType()); 171 } 172 173 rule.setTitle(this.title); 175 rule.setDescription(this.description); 176 rule.applyToChildren(this.applyToSubSpaces); 177 rule.setExecuteAsynchronously(this.runInBackground); 178 179 for (Map <String , Serializable > condParams : this.allConditionsProperties) 181 { 182 Map <String , Serializable > repoCondParams = buildConditionParams(condParams); 183 184 ActionCondition condition = this.actionService.createActionCondition( 186 (String )condParams.get(PROP_CONDITION_NAME)); 187 condition.setParameterValues(repoCondParams); 188 189 Boolean not = (Boolean )condParams.get(PROP_CONDITION_NOT); 191 condition.setInvertCondition(((Boolean )not).booleanValue()); 192 193 rule.addActionCondition(condition); 194 } 195 196 for (Map <String , Serializable > actionParams : this.allActionsProperties) 198 { 199 String actionName = (String )actionParams.get(PROP_ACTION_NAME); 202 this.action = actionName; 203 this.currentActionProperties = actionParams; 204 Map <String , Serializable > repoActionParams = buildActionParams(); 205 206 Action action = this.actionService.createAction(actionName); 208 action.setParameterValues(repoActionParams); 209 rule.addAction(action); 210 } 211 212 this.ruleService.saveRule(currentSpace.getNodeRef(), rule); 214 215 if (logger.isDebugEnabled()) 216 { 217 logger.debug(this.editMode ? "Updated" : "Added" + " rule '" + this.title + "'"); 218 } 219 220 tx.commit(); 222 } 223 catch (Throwable e) 224 { 225 try { if (tx != null) {tx.rollback();} } catch (Exception ex) {} 227 Utils.addErrorMessage(MessageFormat.format(Application.getMessage( 228 FacesContext.getCurrentInstance(), ERROR), e.getMessage()), e); 229 outcome = null; 230 231 isFinished = false; 232 } 233 } 234 235 return outcome; 236 } 237 238 243 public DataModel getAllConditionsDataModel() 244 { 245 if (this.allConditionsDataModel == null) 246 { 247 this.allConditionsDataModel = new ListDataModel(); 248 } 249 250 this.allConditionsDataModel.setWrappedData(this.allConditionsProperties); 251 252 return this.allConditionsDataModel; 253 } 254 255 260 public String promptForConditionValues() 261 { 262 String outcome = null; 263 264 this.editingCondition = false; 266 267 if ("no-condition".equals(this.condition)) 268 { 269 HashMap <String , Serializable > condProps = new HashMap <String , Serializable >(3); 270 condProps.put(PROP_CONDITION_NAME, this.condition); 271 condProps.put(PROP_CONDITION_SUMMARY, Application.getMessage( 272 FacesContext.getCurrentInstance(), "condition_no_condition")); 273 condProps.put(PROP_CONDITION_NOT, Boolean.FALSE); 274 this.allConditionsProperties.add(condProps); 275 276 279 if (logger.isDebugEnabled()) 280 logger.debug("Add 'no-condition' condition to list"); 281 } 282 else if (this.condition != null) 283 { 284 HashMap <String , Serializable > condProps = new HashMap <String , Serializable >(3); 285 condProps.put(PROP_CONDITION_NAME, this.condition); 286 this.currentConditionProperties = condProps; 287 outcome = this.condition; 288 289 if (logger.isDebugEnabled()) 290 logger.debug("Added '" + this.condition + "' condition to list"); 291 } 292 293 this.condition = null; 295 296 return outcome; 297 } 298 299 304 public String editCondition() 305 { 306 Map conditionToEdit = (Map )this.allConditionsDataModel.getRowData(); 309 this.condition = (String )conditionToEdit.get(PROP_CONDITION_NAME); 310 this.currentConditionProperties = conditionToEdit; 311 312 this.editingCondition = true; 314 315 return this.condition; 316 } 317 318 323 public String addCondition() 324 { 325 String summary = buildConditionSummary(this.currentConditionProperties); 326 327 if (summary != null) 328 { 329 this.currentConditionProperties.put(PROP_CONDITION_SUMMARY, summary); 330 } 331 332 if (this.editingCondition) 333 { 334 this.condition = null; 335 } 336 else 337 { 338 this.allConditionsProperties.add(this.currentConditionProperties); 339 } 340 341 return "condition"; 343 } 344 345 350 public String removeCondition() 351 { 352 Map conditionToRemove = (Map )this.allConditionsDataModel.getRowData(); 355 this.allConditionsProperties.remove(conditionToRemove); 356 357 this.condition = null; 359 360 return null; 362 } 363 364 369 public String cancelAddCondition() 370 { 371 if (this.editingCondition) 372 { 373 this.condition = null; 374 } 375 else 376 { 377 this.currentConditionProperties.clear(); 378 } 379 380 381 return "condition"; 382 } 383 384 389 public DataModel getAllActionsDataModel() 390 { 391 if (this.allActionsDataModel == null) 392 { 393 this.allActionsDataModel = new ListDataModel(); 394 } 395 396 this.allActionsDataModel.setWrappedData(this.allActionsProperties); 397 398 return this.allActionsDataModel; 399 } 400 401 406 public String promptForActionValues() 407 { 408 this.editingAction = false; 410 411 HashMap <String , Serializable > actionProps = new HashMap <String , Serializable >(3); 412 actionProps.put(PROP_ACTION_NAME, this.action); 413 this.currentActionProperties = actionProps; 414 415 String outcome = this.action; 416 417 if (SimpleWorkflowActionExecuter.NAME.equals(this.action)) 418 { 419 this.currentActionProperties.put("approveAction", "move"); 420 this.currentActionProperties.put("rejectStepPresent", "yes"); 421 this.currentActionProperties.put("rejectAction", "move"); 422 423 if (logger.isDebugEnabled()) 424 logger.debug("Added '" + SimpleWorkflowActionExecuter.NAME + 425 "' action to list"); 426 } 427 else if (CheckInActionExecuter.NAME.equals(this.action)) 428 { 429 this.currentActionProperties.put(PROP_CHECKIN_MINOR, new Boolean (true)); 430 431 if (logger.isDebugEnabled()) 432 logger.debug("Added '" + CheckInActionExecuter.NAME + 433 "' action to list"); 434 } 435 else if ("extract-metadata".equals(this.action)) 436 { 437 actionProps.put(PROP_ACTION_SUMMARY, buildActionSummary(actionProps)); 439 this.allActionsProperties.add(actionProps); 440 441 outcome = null; 442 443 if (logger.isDebugEnabled()) 444 logger.debug("Added 'extract-metadata' action to list"); 445 } 446 else 447 { 448 if (logger.isDebugEnabled()) 449 logger.debug("Added '" + this.action + "' action to list"); 450 } 451 452 this.action = null; 454 455 return outcome; 456 } 457 458 463 public String editAction() 464 { 465 Map actionToEdit = (Map )this.allActionsDataModel.getRowData(); 468 this.action = (String )actionToEdit.get(PROP_ACTION_NAME); 469 this.currentActionProperties = actionToEdit; 470 471 this.editingAction = true; 473 474 return this.action; 475 } 476 477 482 public String addAction() 483 { 484 String summary = buildActionSummary(this.currentActionProperties); 485 486 if (summary != null) 487 { 488 this.currentActionProperties.put(PROP_ACTION_SUMMARY, summary); 489 } 490 491 if (this.editingAction) 492 { 493 this.action = null; 494 } 495 else 496 { 497 this.allActionsProperties.add(this.currentActionProperties); 498 } 499 500 return "action"; 502 } 503 504 509 public String removeAction() 510 { 511 Map actionToRemove = (Map )this.allActionsDataModel.getRowData(); 514 this.allActionsProperties.remove(actionToRemove); 515 516 this.action = null; 518 519 return null; 521 } 522 523 528 public String cancelAddAction() 529 { 530 if (this.editingAction) 531 { 532 this.condition = null; 533 } 534 else 535 { 536 this.currentActionProperties.clear(); 537 } 538 539 return "action"; 540 } 541 542 545 public String getWizardDescription() 546 { 547 if (this.editMode) 548 { 549 return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_DESC_EDIT_ID); 550 } 551 else 552 { 553 return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_DESC_ID); 554 } 555 } 556 557 560 public String getWizardTitle() 561 { 562 if (this.editMode) 563 { 564 return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_TITLE_EDIT_ID); 565 } 566 else 567 { 568 return Application.getMessage(FacesContext.getCurrentInstance(), WIZARD_TITLE_ID); 569 } 570 } 571 572 575 public String getStepDescription() 576 { 577 String stepDesc = null; 578 579 switch (this.currentStep) 580 { 581 case 4: 582 { 583 stepDesc = Application.getMessage(FacesContext.getCurrentInstance(), SUMMARY_DESCRIPTION_ID); 584 break; 585 } 586 default: 587 { 588 stepDesc = ""; 589 } 590 } 591 592 return stepDesc; 593 } 594 595 598 public String getStepTitle() 599 { 600 String stepTitle = null; 601 602 switch (this.currentStep) 603 { 604 case 1: 605 { 606 stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP1_TITLE_ID); 607 break; 608 } 609 case 2: 610 { 611 stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP2_TITLE_ID); 612 break; 613 } 614 case 3: 615 { 616 stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), STEP3_TITLE_ID); 617 break; 618 } 619 case 4: 620 { 621 stepTitle = Application.getMessage(FacesContext.getCurrentInstance(), SUMMARY_TITLE_ID); 622 break; 623 } 624 default: 625 { 626 stepTitle = ""; 627 } 628 } 629 630 return stepTitle; 631 } 632 633 636 public String getStepInstructions() 637 { 638 String stepInstruction = null; 639 640 switch (this.currentStep) 641 { 642 case 4: 643 { 644 if (this.editMode) 645 { 646 stepInstruction = Application.getMessage(FacesContext.getCurrentInstance(), FINISH_INSTRUCTION_EDIT_ID); 647 } 648 else 649 { 650 stepInstruction = Application.getMessage(FacesContext.getCurrentInstance(), FINISH_INSTRUCTION_ID); 651 } 652 break; 653 } 654 default: 655 { 656 stepInstruction = Application.getMessage(FacesContext.getCurrentInstance(), DEFAULT_INSTRUCTION_ID); 657 } 658 } 659 660 return stepInstruction; 661 } 662 663 666 public void init() 667 { 668 super.init(); 669 670 this.title = null; 671 this.description = null; 672 this.type = "inbound"; 673 this.condition = null; 674 this.action = null; 675 this.applyToSubSpaces = false; 676 this.runInBackground = false; 677 this.conditions = null; 678 this.conditionDescriptions = null; 679 680 this.allConditionsProperties = new ArrayList <Map <String , Serializable >>(); 681 this.allActionsProperties = new ArrayList <Map <String , Serializable >>(); 682 683 this.isFinished = false; 684 } 685 686 692 public void startWizardForEdit(ActionEvent event) 693 { 694 this.rulesBean.setupRuleAction(event); 696 697 super.startWizardForEdit(event); 699 } 700 701 706 public void populate() 707 { 708 Rule rule = this.rulesBean.getCurrentRule(); 710 711 if (rule == null) 712 { 713 throw new AlfrescoRuntimeException("Failed to locate the current rule"); 714 } 715 716 this.type = rule.getRuleTypeName(); 718 this.title = rule.getTitle(); 719 this.description = rule.getDescription(); 720 this.applyToSubSpaces = rule.isAppliedToChildren(); 721 this.runInBackground = rule.getExecuteAsychronously(); 722 723 List <ActionCondition> conditions = rule.getActionConditions(); 725 for (ActionCondition condition : conditions) 726 { 727 Map <String , Serializable > params = populateCondition(condition); 728 this.allConditionsProperties.add(params); 729 } 730 731 List <Action> actions = rule.getActions(); 732 for (Action action : actions) 733 { 734 this.currentActionProperties = new HashMap <String , Serializable >(3); 738 this.action = action.getActionDefinitionName(); 739 populateActionFromProperties(action.getParameterValues()); 740 741 this.currentActionProperties.put(PROP_ACTION_NAME, this.action); 743 this.currentActionProperties.put(PROP_ACTION_SUMMARY, 745 buildActionSummary(this.currentActionProperties)); 746 747 this.allActionsProperties.add(this.currentActionProperties); 749 } 750 751 this.action = null; 753 } 754 755 758 public String getSummary() 759 { 760 StringBuilder conditionsSummary = new StringBuilder (); 762 for (Map <String , Serializable > props : this.allConditionsProperties) 763 { 764 conditionsSummary.append(props.get(PROP_CONDITION_SUMMARY)); 765 conditionsSummary.append("<br/>"); 766 } 767 768 StringBuilder actionsSummary = new StringBuilder (); 770 for (Map <String , Serializable > props : this.allActionsProperties) 771 { 772 actionsSummary.append(props.get(PROP_ACTION_SUMMARY)); 773 actionsSummary.append("<br/>"); 774 } 775 776 ResourceBundle bundle = Application.getBundle(FacesContext.getCurrentInstance()); 777 778 String backgroundYesNo = this.runInBackground ? bundle.getString("yes") : bundle.getString("no"); 779 String subSpacesYesNo = this.applyToSubSpaces ? bundle.getString("yes") : bundle.getString("no"); 780 781 return buildSummary( 782 new String [] {bundle.getString("rule_type"), bundle.getString("name"), bundle.getString("description"), 783 bundle.getString("apply_to_sub_spaces"), bundle.getString("run_in_background"), 784 bundle.getString("conditions"), bundle.getString("actions")}, 785 new String [] {this.type, this.title, this.description, subSpacesYesNo, backgroundYesNo, 786 conditionsSummary.toString(), actionsSummary.toString()}); 787 } 788 789 792 public String back() 793 { 794 this.action = null; 796 this.condition = null; 797 798 return super.back(); 799 } 800 801 804 public String next() 805 { 806 this.action = null; 808 this.condition = null; 809 810 return super.next(); 811 } 812 813 816 public String getDescription() 817 { 818 return description; 819 } 820 821 824 public void setDescription(String description) 825 { 826 this.description = description; 827 } 828 829 832 public String getTitle() 833 { 834 return title; 835 } 836 837 840 public void setTitle(String title) 841 { 842 this.title = title; 843 } 844 845 848 public boolean getRunInBackground() 849 { 850 return this.runInBackground; 851 } 852 853 856 public void setRunInBackground(boolean runInBackground) 857 { 858 this.runInBackground = runInBackground; 859 } 860 861 864 public boolean getApplyToSubSpaces() 865 { 866 return this.applyToSubSpaces; 867 } 868 869 872 public void setApplyToSubSpaces(boolean applyToSubSpaces) 873 { 874 this.applyToSubSpaces = applyToSubSpaces; 875 } 876 877 880 public String getType() 881 { 882 return type; 883 } 884 885 888 public void setType(String type) 889 { 890 this.type = type; 891 } 892 893 896 public String getCondition() 897 { 898 return this.condition; 899 } 900 901 904 public void setCondition(String condition) 905 { 906 this.condition = condition; 907 } 908 909 912 public void setRuleService(RuleService ruleService) 913 { 914 this.ruleService = ruleService; 915 } 916 917 920 public void setMimetypeService(MimetypeService mimetypeService) 921 { 922 this.mimetypeService = mimetypeService; 923 } 924 925 930 public void setRulesBean(RulesBean rulesBean) 931 { 932 this.rulesBean = rulesBean; 933 } 934 935 938 public List <SelectItem> getActions() 939 { 940 if (this.actions == null) 941 { 942 super.getActions(); 943 944 this.actions.add(0, new SelectItem("null", 946 Application.getMessage(FacesContext.getCurrentInstance(), "select_an_action"))); 947 } 948 949 return this.actions; 950 } 951 952 957 public List <SelectItem> getModelTypes() 958 { 959 if (this.modelTypes == null) 960 { 961 ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance()); 962 Config wizardCfg = svc.getConfig("Action Wizards"); 963 if (wizardCfg != null) 964 { 965 ConfigElement typesCfg = wizardCfg.getConfigElement("types"); 966 if (typesCfg != null) 967 { 968 FacesContext context = FacesContext.getCurrentInstance(); 969 this.modelTypes = new ArrayList <SelectItem>(); 970 for (ConfigElement child : typesCfg.getChildren()) 971 { 972 QName idQName = Repository.resolveToQName(child.getAttribute("name")); 973 974 String label = null; 976 String msgId = child.getAttribute("displayLabelId"); 977 if (msgId != null) 978 { 979 label = Application.getMessage(context, msgId); 980 } 981 982 if (label == null) 984 { 985 label = child.getAttribute("displayLabel"); 986 } 987 988 if (label == null) 990 { 991 TypeDefinition typeDef = this.dictionaryService.getType(idQName); 992 if (typeDef != null) 993 { 994 label = typeDef.getTitle(); 995 } 996 else 997 { 998 label = idQName.getLocalName(); 999 } 1000 } 1001 1002 this.modelTypes.add(new SelectItem(idQName.toString(), label)); 1003 } 1004 1005 QuickSort sorter = new QuickSort(this.modelTypes, "label", true, IDataContainer.SORT_CASEINSENSITIVE); 1007 sorter.sort(); 1008 } 1009 else 1010 { 1011 logger.warn("Could not find types configuration element"); 1012 } 1013 } 1014 else 1015 { 1016 logger.warn("Could not find Action Wizards configuration section"); 1017 } 1018 } 1019 1020 return this.modelTypes; 1021 } 1022 1023 1028 public List <SelectItem> getMimeTypes() 1029 { 1030 if (this.mimeTypes == null) 1031 { 1032 this.mimeTypes = new ArrayList <SelectItem>(50); 1033 1034 Map <String , String > mimeTypes = mimetypeService.getDisplaysByMimetype(); 1035 for (String mimeType : mimeTypes.keySet()) 1036 { 1037 this.mimeTypes.add(new SelectItem(mimeType, mimeTypes.get(mimeType))); 1038 } 1039 1040 QuickSort sorter = new QuickSort(this.mimeTypes, "label", true, IDataContainer.SORT_CASEINSENSITIVE); 1042 sorter.sort(); 1043 } 1044 1045 return this.mimeTypes; 1046 } 1047 1048 1051 public List <SelectItem> getConditions() 1052 { 1053 if (this.conditions == null) 1054 { 1055 List <ActionConditionDefinition> ruleConditions = this.actionService.getActionConditionDefinitions(); 1056 this.conditions = new ArrayList <SelectItem>(ruleConditions.size()); 1057 for (ActionConditionDefinition ruleConditionDef : ruleConditions) 1058 { 1059 this.conditions.add(new SelectItem(ruleConditionDef.getName(), 1061 ruleConditionDef.getTitle())); 1062 } 1063 1064 QuickSort sorter = new QuickSort(this.conditions, "label", true, IDataContainer.SORT_CASEINSENSITIVE); 1066 sorter.sort(); 1067 1068 this.conditions.add(0, new SelectItem("null", 1070 Application.getMessage(FacesContext.getCurrentInstance(), "select_a_condition"))); 1071 } 1072 1073 return this.conditions; 1074 } 1075 1076 1079 public Map <String , String > getConditionDescriptions() 1080 { 1081 if (this.conditionDescriptions == null) 1082 { 1083 List <ActionConditionDefinition> ruleConditions = this.actionService.getActionConditionDefinitions(); 1084 this.conditionDescriptions = new HashMap <String , String >(ruleConditions.size()); 1085 for (ActionConditionDefinition ruleConditionDef : ruleConditions) 1086 { 1087 this.conditionDescriptions.put(ruleConditionDef.getName(), 1088 ruleConditionDef.getDescription()); 1089 } 1090 } 1091 1092 return this.conditionDescriptions; 1093 } 1094 1095 1098 public List <SelectItem> getTypes() 1099 { 1100 if (this.types == null) 1101 { 1102 List <RuleType> ruleTypes = this.ruleService.getRuleTypes(); 1103 this.types = new ArrayList <SelectItem>(ruleTypes.size()); 1104 for (RuleType ruleType : ruleTypes) 1105 { 1106 this.types.add(new SelectItem(ruleType.getName(), ruleType.getDisplayLabel())); 1107 } 1108 } 1109 1110 return this.types; 1111 } 1112 1113 1116 public Map <String , Serializable > getConditionProperties() 1117 { 1118 return this.currentConditionProperties; 1119 } 1120 1121 1124 protected String determineOutcomeForStep(int step) 1125 { 1126 String outcome = null; 1127 1128 switch(step) 1129 { 1130 case 1: 1131 { 1132 outcome = "details"; 1133 break; 1134 } 1135 case 2: 1136 { 1137 outcome = "condition"; 1138 break; 1139 } 1140 case 3: 1141 { 1142 outcome = "action"; 1143 break; 1144 } 1145 case 4: 1146 { 1147 outcome = "summary"; 1148 break; 1149 } 1150 default: 1151 { 1152 outcome = CANCEL_OUTCOME; 1153 } 1154 } 1155 1156 return outcome; 1157 } 1158 1159 1165 protected Map <String , Serializable > buildConditionParams(Map <String , Serializable > params) 1166 { 1167 Map <String , Serializable > repoParams = new HashMap <String , Serializable >(params.size()); 1168 1169 String condName = (String )params.get(PROP_CONDITION_NAME); 1170 if (condName.equals(ComparePropertyValueEvaluator.NAME)) 1171 { 1172 repoParams.put(ComparePropertyValueEvaluator.PARAM_VALUE, params.get(PROP_CONTAINS_TEXT)); 1173 } 1174 else if (condName.equals(InCategoryEvaluator.NAME)) 1175 { 1176 repoParams.put(InCategoryEvaluator.PARAM_CATEGORY_VALUE, params.get(PROP_CATEGORY)); 1178 1179 repoParams.put(InCategoryEvaluator.PARAM_CATEGORY_ASPECT, ContentModel.ASPECT_GEN_CLASSIFIABLE); 1181 } 1182 else if (condName.equals(IsSubTypeEvaluator.NAME)) 1183 { 1184 repoParams.put(IsSubTypeEvaluator.PARAM_TYPE, QName.createQName((String )params.get(PROP_MODEL_TYPE))); 1186 } 1187 else if (condName.equals(HasAspectEvaluator.NAME)) 1188 { 1189 repoParams.put(HasAspectEvaluator.PARAM_ASPECT, QName.createQName((String )params.get(PROP_ASPECT))); 1191 } 1192 else if (condName.equals(CompareMimeTypeEvaluator.NAME)) 1193 { 1194 repoParams.put(CompareMimeTypeEvaluator.PARAM_VALUE, params.get(PROP_MIMETYPE)); 1195 } 1196 1197 return repoParams; 1198 } 1199 1200 1205 protected Map <String , Serializable > populateCondition(ActionCondition condition) 1206 { 1207 Map <String , Serializable > condProps = new HashMap <String , Serializable >(3); 1209 String name = condition.getActionConditionDefinitionName(); 1210 condProps.put(PROP_CONDITION_NAME, name); 1211 1212 Map <String , Serializable > repoCondProps = condition.getParameterValues(); 1214 if (name.equals(ComparePropertyValueEvaluator.NAME)) 1215 { 1216 condProps.put(PROP_CONTAINS_TEXT, (String )repoCondProps.get(ComparePropertyValueEvaluator.PARAM_VALUE)); 1217 } 1218 else if (name.equals(InCategoryEvaluator.NAME)) 1219 { 1220 NodeRef catNodeRef = (NodeRef)repoCondProps.get(InCategoryEvaluator.PARAM_CATEGORY_VALUE); 1221 condProps.put(PROP_CATEGORY, catNodeRef); 1222 } 1223 else if (name.equals(IsSubTypeEvaluator.NAME)) 1224 { 1225 condProps.put(PROP_MODEL_TYPE, ((QName)repoCondProps.get(IsSubTypeEvaluator.PARAM_TYPE)).toString()); 1226 } 1227 else if (name.equals(HasAspectEvaluator.NAME)) 1228 { 1229 condProps.put(PROP_ASPECT, ((QName)repoCondProps.get(HasAspectEvaluator.PARAM_ASPECT)).toString()); 1230 } 1231 else if (name.equals(CompareMimeTypeEvaluator.NAME)) 1232 { 1233 condProps.put(PROP_MIMETYPE, repoCondProps.get(CompareMimeTypeEvaluator.PARAM_VALUE)); 1234 } 1235 1236 condProps.put(PROP_CONDITION_NOT, Boolean.valueOf(condition.getInvertCondition())); 1238 1239 condProps.put(PROP_CONDITION_SUMMARY, buildConditionSummary(condProps)); 1241 1242 return condProps; 1243 } 1244 1245 1250 protected String buildConditionSummary(Map <String , Serializable > props) 1251 { 1252 String summaryResult = null; 1253 1254 String condName = (String )props.get(PROP_CONDITION_NAME); 1255 if (condName != null) 1256 { 1257 StringBuilder summary = new StringBuilder (); 1258 1259 String msgId = "condition_" + condName.replace('-', '_'); 1260 1261 Boolean not = (Boolean )props.get(PROP_CONDITION_NOT); 1264 if (not.booleanValue()) 1265 { 1266 msgId = msgId + "_not"; 1267 } 1268 1269 if (logger.isDebugEnabled()) 1270 logger.debug("Looking up condition summary string: " + msgId); 1271 1272 summary.append(Application.getMessage(FacesContext.getCurrentInstance(), msgId)); 1273 summary.append(" "); 1274 1275 if ("in-category".equals(condName)) 1277 { 1278 String name = Repository.getNameForNode(this.nodeService, (NodeRef)props.get(PROP_CATEGORY)); 1279 summary.append("'").append(name).append("'"); 1280 } 1281 else if ("compare-property-value".equals(condName)) 1282 { 1283 summary.append("'"); 1284 summary.append(props.get(PROP_CONTAINS_TEXT)); 1285 summary.append("'"); 1286 } 1287 else if ("is-subtype".equals(condName)) 1288 { 1289 String typeName = (String )props.get(PROP_MODEL_TYPE); 1291 for (SelectItem item : this.getModelTypes()) 1292 { 1293 if (item.getValue().equals(typeName)) 1294 { 1295 summary.append("'").append(item.getLabel()).append("'"); 1296 break; 1297 } 1298 } 1299 } 1300 else if ("has-aspect".equals(condName)) 1301 { 1302 String aspectName = (String )props.get(PROP_ASPECT); 1304 for (SelectItem item : this.getAspects()) 1305 { 1306 if (item.getValue().equals(aspectName)) 1307 { 1308 summary.append("'").append(item.getLabel()).append("'"); 1309 break; 1310 } 1311 } 1312 } 1313 else if (CompareMimeTypeEvaluator.NAME.equals(condName)) 1314 { 1315 String mimetype = (String )props.get(PROP_MIMETYPE); 1316 for (SelectItem item : this.getMimeTypes()) 1317 { 1318 if (item.getValue().equals(mimetype)) 1319 { 1320 summary.append("'").append(item.getLabel()).append("'"); 1321 break; 1322 } 1323 } 1324 } 1325 1326 summaryResult = summary.toString(); 1327 } 1328 1329 return summaryResult; 1330 } 1331 1332 1337 protected String buildActionSummary(Map <String , Serializable > props) 1338 { 1339 String summaryResult = null; 1340 1341 String actionName = (String )this.currentActionProperties.get(PROP_ACTION_NAME); 1342 if (actionName != null) 1343 { 1344 StringBuilder summary = new StringBuilder (); 1345 summary.append(Application.getMessage(FacesContext.getCurrentInstance(), 1346 "action_" + actionName.replace('-', '_'))); 1347 summary.append(" "); 1348 1349 if ("add-features".equals(actionName)) 1351 { 1352 String aspect = (String )this.currentActionProperties.get(PROP_ASPECT); 1353 1354 for (SelectItem item : this.getAspects()) 1356 { 1357 if (item.getValue().equals(aspect)) 1358 { 1359 summary.append("'").append(item.getLabel()).append("'"); 1360 break; 1361 } 1362 } 1363 } 1364 else if ("simple-workflow".equals(actionName)) 1365 { 1366 String approveStepName = (String )this.currentActionProperties.get(PROP_APPROVE_STEP_NAME); 1368 String approveAction = (String )this.currentActionProperties.get(PROP_APPROVE_ACTION); 1369 NodeRef approveFolder = (NodeRef)this.currentActionProperties.get(PROP_APPROVE_FOLDER); 1370 String approveFolderName = Repository.getNameForNode(this.nodeService, approveFolder); 1371 String approveMsg = MessageFormat.format(summary.toString(), 1372 new Object [] {Application.getMessage(FacesContext.getCurrentInstance(), approveAction), 1373 approveFolderName, approveStepName}); 1374 1375 String rejectStep = (String )this.currentActionProperties.get(PROP_REJECT_STEP_PRESENT); 1376 1377 String rejectMsg = null; 1378 if (rejectStep != null && "yes".equals(rejectStep)) 1379 { 1380 String rejectStepName = (String )this.currentActionProperties.get(PROP_REJECT_STEP_NAME); 1381 String rejectAction = (String )this.currentActionProperties.get(PROP_REJECT_ACTION); 1382 NodeRef rejectFolder = (NodeRef)this.currentActionProperties.get(PROP_REJECT_FOLDER); 1383 String rejectFolderName = Repository.getNameForNode(this.nodeService, rejectFolder); 1384 rejectMsg = MessageFormat.format(summary.toString(), 1385 new Object [] {Application.getMessage(FacesContext.getCurrentInstance(), rejectAction), 1386 rejectFolderName, rejectStepName}); 1387 } 1388 1389 summary = new StringBuilder (approveMsg); 1390 if (rejectMsg != null) 1391 { 1392 summary.append(" "); 1393 summary.append(rejectMsg); 1394 } 1395 } 1396 else if ("link-category".equals(actionName)) 1397 { 1398 NodeRef cat = (NodeRef)this.currentActionProperties.get(PROP_CATEGORY); 1399 String name = Repository.getNameForNode(this.nodeService, cat); 1400 summary.append("'").append(name).append("'"); 1401 } 1402 else if ("transform".equals(actionName)) 1403 { 1404 NodeRef space = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION); 1405 String name = Repository.getNameForNode(this.nodeService, space); 1406 String transformer = (String )this.currentActionProperties.get(PROP_TRANSFORMER); 1407 1408 for (SelectItem item : this.getTransformers()) 1410 { 1411 if (item.getValue().equals(transformer)) 1412 { 1413 transformer = item.getLabel(); 1414 break; 1415 } 1416 } 1417 1418 String msg = MessageFormat.format(summary.toString(), new Object [] {name, transformer}); 1420 summary = new StringBuilder (msg); 1421 } 1422 else if ("transform-image".equals(actionName)) 1423 { 1424 NodeRef space = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION); 1425 String name = Repository.getNameForNode(this.nodeService, space); 1426 String transformer = (String )this.currentActionProperties.get(PROP_IMAGE_TRANSFORMER); 1427 String option = (String )this.currentActionProperties.get(PROP_TRANSFORM_OPTIONS); 1428 1429 for (SelectItem item : this.getImageTransformers()) 1431 { 1432 if (item.getValue().equals(transformer)) 1433 { 1434 transformer = item.getLabel(); 1435 break; 1436 } 1437 } 1438 1439 String msg = MessageFormat.format(summary.toString(), new Object [] {name, transformer, option}); 1441 summary = new StringBuilder (msg); 1442 } 1443 else if ("copy".equals(actionName) || "move".equals(actionName) || "check-out".equals(actionName)) 1444 { 1445 NodeRef space = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION); 1446 String spaceName = Repository.getNameForNode(this.nodeService, space); 1447 summary.append("'").append(spaceName).append("'"); 1448 } 1449 else if ("mail".equals(actionName)) 1450 { 1451 String address = (String )this.currentActionProperties.get(PROP_TO); 1452 summary.append("'").append(address).append("'"); 1453 } 1454 else if ("check-in".equals(actionName)) 1455 { 1456 String comment = (String )this.currentActionProperties.get(PROP_CHECKIN_DESC); 1457 Boolean minorChange = (Boolean )this.currentActionProperties.get(PROP_CHECKIN_MINOR); 1458 String change = null; 1459 if (minorChange != null && minorChange.booleanValue()) 1460 { 1461 change = Application.getMessage(FacesContext.getCurrentInstance(), "minor_change"); 1462 } 1463 else 1464 { 1465 change = Application.getMessage(FacesContext.getCurrentInstance(), "major_change"); 1466 } 1467 1468 String msg = MessageFormat.format(summary.toString(), new Object [] {change, comment}); 1470 summary = new StringBuilder (msg); 1471 } 1472 else if ("import".equals(actionName)) 1473 { 1474 NodeRef space = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION); 1475 String spaceName = Repository.getNameForNode(this.nodeService, space); 1476 summary.append("'").append(spaceName).append("'"); 1477 } 1478 else if (SpecialiseTypeActionExecuter.NAME.equals(actionName) == true) 1479 { 1480 String label = null; 1481 String objectType = (String )this.currentActionProperties.get(PROP_OBJECT_TYPE); 1482 for (SelectItem item : getObjectTypes()) 1483 { 1484 if (item.getValue().equals(objectType) == true) 1485 { 1486 label = item.getLabel(); 1487 break; 1488 } 1489 } 1490 1491 summary.append("'").append(label).append("'"); 1492 } 1493 1494 summaryResult = summary.toString(); 1495 } 1496 1497 return summaryResult; 1498 } 1499} 1500 | Popular Tags |