diff --git a/source/java/org/alfresco/web/bean/actions/BaseActionWizard.java b/source/java/org/alfresco/web/bean/actions/BaseActionWizard.java index c0fb06d3c6..6f874c71a1 100644 --- a/source/java/org/alfresco/web/bean/actions/BaseActionWizard.java +++ b/source/java/org/alfresco/web/bean/actions/BaseActionWizard.java @@ -22,6 +22,7 @@ import org.alfresco.model.ContentModel; import org.alfresco.repo.action.executer.AddFeaturesActionExecuter; import org.alfresco.repo.action.executer.CheckInActionExecuter; import org.alfresco.repo.action.executer.CheckOutActionExecuter; +import org.alfresco.repo.action.executer.ContentMetadataExtracter; import org.alfresco.repo.action.executer.CopyActionExecuter; import org.alfresco.repo.action.executer.ImageTransformActionExecuter; import org.alfresco.repo.action.executer.ImporterActionExecuter; @@ -543,41 +544,15 @@ public abstract class BaseActionWizard extends BaseWizardBean actionProps.put(PROP_ACTION_NAME, this.action); this.currentActionProperties = actionProps; - if (SimpleWorkflowActionExecuter.NAME.equals(this.action)) + // setup any defaults for the UI or handle actions with no parameters + String overridenViewId = setupUIDefaultsForAction(actionProps); + if (overridenViewId != null) { - this.currentActionProperties.put("approveAction", "move"); - this.currentActionProperties.put("rejectStepPresent", "yes"); - this.currentActionProperties.put("rejectAction", "move"); - - if (logger.isDebugEnabled()) - logger.debug("Added '" + SimpleWorkflowActionExecuter.NAME + - "' action to list"); + viewId = overridenViewId; } - else if (CheckInActionExecuter.NAME.equals(this.action)) - { - this.currentActionProperties.put(PROP_CHECKIN_MINOR, new Boolean(true)); - - if (logger.isDebugEnabled()) - logger.debug("Added '" + CheckInActionExecuter.NAME + - "' action to list"); - } - else if ("extract-metadata".equals(this.action)) - { - // This one (currently) has no parameters, so just add it... - actionProps.put(PROP_ACTION_SUMMARY, buildActionSummary(actionProps)); - this.allActionsProperties.add(actionProps); - - // come back to the same page we're on now - viewId = this.returnViewId; - - if (logger.isDebugEnabled()) - logger.debug("Added 'extract-metadata' action to list"); - } - else - { - if (logger.isDebugEnabled()) + + if (logger.isDebugEnabled()) logger.debug("Added '" + this.action + "' action to list"); - } // reset the selected action drop down this.action = null; @@ -615,7 +590,7 @@ public abstract class BaseActionWizard extends BaseWizardBean public void addAction() { FacesContext context = FacesContext.getCurrentInstance(); - String summary = buildActionSummary(this.currentActionProperties); + String summary = buildActionSummary(); if (summary != null) { @@ -826,6 +801,41 @@ public abstract class BaseActionWizard extends BaseWizardBean return label; } + /** + * Sets up any default state required by the UI for collecting the + * action settings. The view id to use for the action UI can also + * be overridden by returing the path to the relevant JSP. + * + * @props The map of properties being used for the current action + * @return An optional overridden JSP to use for action settings collection + */ + protected String setupUIDefaultsForAction(HashMap props) + { + String overridenViewId = null; + + if (SimpleWorkflowActionExecuter.NAME.equals(this.action)) + { + this.currentActionProperties.put("approveAction", "move"); + this.currentActionProperties.put("rejectStepPresent", "yes"); + this.currentActionProperties.put("rejectAction", "move"); + } + else if (CheckInActionExecuter.NAME.equals(this.action)) + { + this.currentActionProperties.put(PROP_CHECKIN_MINOR, new Boolean(true)); + } + else if (ContentMetadataExtracter.NAME.equals(this.action)) + { + // This one (currently) has no parameters, so just add it... + props.put(PROP_ACTION_SUMMARY, buildActionSummary()); + this.allActionsProperties.add(props); + + // come back to the same page we're on now + overridenViewId = this.returnViewId; + } + + return overridenViewId; + } + /** * Build the param map for the current Action instance. *

@@ -838,17 +848,17 @@ public abstract class BaseActionWizard extends BaseWizardBean // set up parameters maps for the action Map actionParams = new HashMap(); - if (this.action.equals(AddFeaturesActionExecuter.NAME)) + if (AddFeaturesActionExecuter.NAME.equals(this.action)) { QName aspect = Repository.resolveToQName((String)this.currentActionProperties.get(PROP_ASPECT)); actionParams.put(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, aspect); } - else if (this.action.equals(RemoveFeaturesActionExecuter.NAME)) + else if (RemoveFeaturesActionExecuter.NAME.equals(this.action)) { QName aspect = Repository.resolveToQName((String)this.currentActionProperties.get(PROP_ASPECT)); actionParams.put(RemoveFeaturesActionExecuter.PARAM_ASPECT_NAME, aspect); } - else if (this.action.equals(CopyActionExecuter.NAME)) + else if (CopyActionExecuter.NAME.equals(this.action)) { // add the destination space id to the action properties NodeRef destNodeRef = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION); @@ -861,7 +871,7 @@ public abstract class BaseActionWizard extends BaseWizardBean actionParams.put(CopyActionExecuter.PARAM_ASSOC_QNAME, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy")); } - else if (this.action.equals(MoveActionExecuter.NAME)) + else if (MoveActionExecuter.NAME.equals(this.action)) { // add the destination space id to the action properties NodeRef destNodeRef = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION); @@ -874,7 +884,7 @@ public abstract class BaseActionWizard extends BaseWizardBean actionParams.put(MoveActionExecuter.PARAM_ASSOC_QNAME, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "move")); } - else if (this.action.equals(SimpleWorkflowActionExecuter.NAME)) + else if (SimpleWorkflowActionExecuter.NAME.equals(this.action)) { // add the approve step name actionParams.put(SimpleWorkflowActionExecuter.PARAM_APPROVE_STEP, @@ -941,7 +951,7 @@ public abstract class BaseActionWizard extends BaseWizardBean actionParams.put(SimpleWorkflowActionExecuter.PARAM_REJECT_FOLDER, rejectDestNodeRef); } } - else if (this.action.equals(LinkCategoryActionExecuter.NAME)) + else if (LinkCategoryActionExecuter.NAME.equals(this.action)) { // add the classifiable aspect actionParams.put(LinkCategoryActionExecuter.PARAM_CATEGORY_ASPECT, @@ -952,7 +962,7 @@ public abstract class BaseActionWizard extends BaseWizardBean actionParams.put(LinkCategoryActionExecuter.PARAM_CATEGORY_VALUE, catNodeRef); } - else if (this.action.equals(CheckOutActionExecuter.NAME)) + else if (CheckOutActionExecuter.NAME.equals(this.action)) { // specify the location the checked out working copy should go // add the destination space id to the action properties @@ -966,7 +976,7 @@ public abstract class BaseActionWizard extends BaseWizardBean actionParams.put(CheckOutActionExecuter.PARAM_ASSOC_QNAME, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "checkout")); } - else if (this.action.equals(CheckInActionExecuter.NAME)) + else if (CheckInActionExecuter.NAME.equals(this.action)) { // add the description for the checkin to the action params actionParams.put(CheckInActionExecuter.PARAM_DESCRIPTION, @@ -976,7 +986,7 @@ public abstract class BaseActionWizard extends BaseWizardBean actionParams.put(CheckInActionExecuter.PARAM_MINOR_CHANGE, this.currentActionProperties.get(PROP_CHECKIN_MINOR)); } - else if (this.action.equals(TransformActionExecuter.NAME)) + else if (TransformActionExecuter.NAME.equals(this.action)) { // add the transformer to use actionParams.put(TransformActionExecuter.PARAM_MIME_TYPE, @@ -993,7 +1003,7 @@ public abstract class BaseActionWizard extends BaseWizardBean actionParams.put(TransformActionExecuter.PARAM_ASSOC_QNAME, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy")); } - else if (this.action.equals(ImageTransformActionExecuter.NAME)) + else if (ImageTransformActionExecuter.NAME.equals(this.action)) { // add the transformer to use actionParams.put(ImageTransformActionExecuter.PARAM_MIME_TYPE, @@ -1014,7 +1024,7 @@ public abstract class BaseActionWizard extends BaseWizardBean actionParams.put(TransformActionExecuter.PARAM_ASSOC_QNAME, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy")); } - else if (this.action.equals(MailActionExecuter.NAME)) + else if (MailActionExecuter.NAME.equals(this.action)) { // add the person(s) it's going to as a list of authorities List recipients = new ArrayList(emailRecipients.size()); @@ -1044,7 +1054,7 @@ public abstract class BaseActionWizard extends BaseWizardBean actionParams.put(MailActionExecuter.PARAM_TEMPLATE, new NodeRef(Repository.getStoreRef(), this.usingTemplate)); } } - else if (this.action.equals(ImporterActionExecuter.NAME)) + else if (ImporterActionExecuter.NAME.equals(this.action)) { // add the encoding actionParams.put(ImporterActionExecuter.PARAM_ENCODING, IMPORT_ENCODING); @@ -1053,13 +1063,13 @@ public abstract class BaseActionWizard extends BaseWizardBean NodeRef destNodeRef = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION); actionParams.put(ImporterActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef); } - else if (this.action.equals(SpecialiseTypeActionExecuter.NAME)) + else if (SpecialiseTypeActionExecuter.NAME.equals(this.action)) { // add the specialisation type String objectType = (String)this.currentActionProperties.get(PROP_OBJECT_TYPE); actionParams.put(SpecialiseTypeActionExecuter.PARAM_TYPE_NAME, QName.createQName(objectType)); } - else if (this.action.equals(ScriptActionExecutor.NAME)) + else if (ScriptActionExecutor.NAME.equals(this.action)) { // add the selected script noderef to the action properties String id = (String)this.currentActionProperties.get(PROP_SCRIPT); @@ -1072,11 +1082,11 @@ public abstract class BaseActionWizard extends BaseWizardBean } /** - * Returns a summary string for the given action parameters + * Returns a summary string for the current action * * @return The summary or null if a summary could not be built */ - protected String buildActionSummary(Map props) + protected String buildActionSummary() { String summaryResult = null; diff --git a/source/java/org/alfresco/web/bean/rules/CreateRuleWizard.java b/source/java/org/alfresco/web/bean/rules/CreateRuleWizard.java index ddf0e64876..6a54989455 100644 --- a/source/java/org/alfresco/web/bean/rules/CreateRuleWizard.java +++ b/source/java/org/alfresco/web/bean/rules/CreateRuleWizard.java @@ -21,6 +21,9 @@ import org.alfresco.repo.action.evaluator.ComparePropertyValueEvaluator; import org.alfresco.repo.action.evaluator.HasAspectEvaluator; import org.alfresco.repo.action.evaluator.InCategoryEvaluator; import org.alfresco.repo.action.evaluator.IsSubTypeEvaluator; +import org.alfresco.repo.action.executer.CheckInActionExecuter; +import org.alfresco.repo.action.executer.ContentMetadataExtracter; +import org.alfresco.repo.action.executer.SimpleWorkflowActionExecuter; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ActionCondition; import org.alfresco.service.cmr.action.ActionConditionDefinition; @@ -535,27 +538,17 @@ public class CreateRuleWizard extends BaseActionWizard HashMap condProps = new HashMap(3); condProps.put(PROP_CONDITION_NAME, this.condition); + this.currentConditionProperties = condProps; - if ("no-condition".equals(this.condition)) + // setup any defaults for the UI or handle actions with no parameters + String overridenViewId = setupUIDefaultsForCondition(condProps); + if (overridenViewId != null) { - condProps.put(PROP_CONDITION_SUMMARY, Application.getMessage( - FacesContext.getCurrentInstance(), "condition_no_condition")); - condProps.put(PROP_CONDITION_NOT, Boolean.FALSE); - this.allConditionsProperties.add(condProps); - - // come back to the same page we're on now - viewId = this.returnViewId; - - if (logger.isDebugEnabled()) - logger.debug("Add 'no-condition' condition to list"); + viewId = overridenViewId; } - else if (this.condition != null) - { - this.currentConditionProperties = condProps; - - if (logger.isDebugEnabled()) + + if (logger.isDebugEnabled()) logger.debug("Added '" + this.condition + "' condition to list"); - } // reset the selected condition drop down this.condition = null; @@ -593,7 +586,7 @@ public class CreateRuleWizard extends BaseActionWizard public void addCondition() { FacesContext context = FacesContext.getCurrentInstance(); - String summary = buildConditionSummary(this.currentConditionProperties); + String summary = buildConditionSummary(); if (summary != null) { @@ -675,6 +668,33 @@ public class CreateRuleWizard extends BaseActionWizard // ------------------------------------------------------------------------------ // Helper methods + /** + * Sets up any default state required by the UI for collecting the + * condition settings. The view id to use for the condition UI can also + * be overridden by returing the path to the relevant JSP. + * + * @props The map of properties being used for the current condition + * @return An optional overridden JSP to use for condition settings collection + */ + protected String setupUIDefaultsForCondition(HashMap props) + { + String overridenViewId = null; + + if ("no-condition".equals(this.condition)) + { + // there are no parameters so just add it + props.put(PROP_CONDITION_SUMMARY, Application.getMessage( + FacesContext.getCurrentInstance(), "condition_no_condition")); + props.put(PROP_CONDITION_NOT, Boolean.FALSE); + this.allConditionsProperties.add(props); + + // come back to the same page we're on now + overridenViewId = this.returnViewId; + } + + return overridenViewId; + } + /** * Builds the Map of properties for the given condition in the format the repo is expecting * @@ -717,15 +737,15 @@ public class CreateRuleWizard extends BaseActionWizard } /** - * Returns a summary string for the given condition parameters + * Returns a summary string for the current condition * * @return The summary or null if a summary could not be built */ - protected String buildConditionSummary(Map props) + protected String buildConditionSummary() { String summaryResult = null; - String condName = (String)props.get(PROP_CONDITION_NAME); + String condName = (String)this.currentConditionProperties.get(PROP_CONDITION_NAME); if (condName != null) { StringBuilder summary = new StringBuilder(); @@ -734,7 +754,7 @@ public class CreateRuleWizard extends BaseActionWizard // JSF is putting the boolean into the map as a Boolean object so we // need to handle that - adding a converter doesn't seem to help! - Boolean not = (Boolean)props.get(PROP_CONDITION_NOT); + Boolean not = (Boolean)this.currentConditionProperties.get(PROP_CONDITION_NOT); if (not.booleanValue()) { msgId = msgId + "_not"; @@ -749,19 +769,20 @@ public class CreateRuleWizard extends BaseActionWizard // define a summary to be added for each condition if (InCategoryEvaluator.NAME.equals(condName)) { - String name = Repository.getNameForNode(this.nodeService, (NodeRef)props.get(PROP_CATEGORY)); + String name = Repository.getNameForNode(this.nodeService, + (NodeRef)this.currentConditionProperties.get(PROP_CATEGORY)); summary.append("'").append(name).append("'"); } else if (ComparePropertyValueEvaluator.NAME.equals(condName)) { summary.append("'"); - summary.append(props.get(PROP_CONTAINS_TEXT)); + summary.append(this.currentConditionProperties.get(PROP_CONTAINS_TEXT)); summary.append("'"); } else if (IsSubTypeEvaluator.NAME.equals(condName)) { // find the label used by looking through the SelectItem list - String typeName = (String)props.get(PROP_MODEL_TYPE); + String typeName = (String)this.currentConditionProperties.get(PROP_MODEL_TYPE); for (SelectItem item : this.getModelTypes()) { if (item.getValue().equals(typeName)) @@ -774,7 +795,7 @@ public class CreateRuleWizard extends BaseActionWizard else if (HasAspectEvaluator.NAME.equals(condName)) { // find the label used by looking through the SelectItem list - String aspectName = (String)props.get(PROP_ASPECT); + String aspectName = (String)this.currentConditionProperties.get(PROP_ASPECT); for (SelectItem item : this.getAspects()) { if (item.getValue().equals(aspectName)) @@ -786,7 +807,7 @@ public class CreateRuleWizard extends BaseActionWizard } else if (CompareMimeTypeEvaluator.NAME.equals(condName)) { - String mimetype = (String)props.get(PROP_MIMETYPE); + String mimetype = (String)this.currentConditionProperties.get(PROP_MIMETYPE); for (SelectItem item : this.getMimeTypes()) { if (item.getValue().equals(mimetype)) diff --git a/source/java/org/alfresco/web/bean/rules/EditRuleWizard.java b/source/java/org/alfresco/web/bean/rules/EditRuleWizard.java index 8e63de05c1..2ab79a1713 100644 --- a/source/java/org/alfresco/web/bean/rules/EditRuleWizard.java +++ b/source/java/org/alfresco/web/bean/rules/EditRuleWizard.java @@ -96,30 +96,39 @@ public class EditRuleWizard extends CreateRuleWizard List conditions = rule.getActionConditions(); for (ActionCondition condition : conditions) { - Map params = populateCondition(condition); - this.allConditionsProperties.add(params); + this.currentConditionProperties = new HashMap(3); + this.condition = condition.getActionConditionDefinitionName(); + populateCondition(condition.getParameterValues()); + + // add the name, summary and not condition flag + this.currentConditionProperties.put(PROP_CONDITION_NAME, this.condition); + this.currentConditionProperties.put(PROP_CONDITION_NOT, + Boolean.valueOf(condition.getInvertCondition())); + this.currentConditionProperties.put(PROP_CONDITION_SUMMARY, buildConditionSummary()); + + // add the populated currentConditionProperties to the list + this.allConditionsProperties.add(this.currentConditionProperties); } + // populate the actions list with maps of properties representing each action List actions = rule.getActions(); for (Action action : actions) { - // use the base class version of populateActionFromProperties(), - // but for this we need to setup the currentActionProperties and - // action variables this.currentActionProperties = new HashMap(3); this.action = action.getActionDefinitionName(); populateAction(action.getParameterValues()); // also add the name and summary this.currentActionProperties.put(PROP_ACTION_NAME, this.action); - // generate the summary - this.currentActionProperties.put(PROP_ACTION_SUMMARY, - buildActionSummary(this.currentActionProperties)); + this.currentActionProperties.put(PROP_ACTION_SUMMARY, buildActionSummary()); // add the populated currentActionProperties to the list this.allActionsProperties.add(this.currentActionProperties); } + // reset the current condition + this.condition = null; + // reset the current action this.action = null; } @@ -129,44 +138,33 @@ public class EditRuleWizard extends CreateRuleWizard * * @param condition The condition to build the map for */ - protected Map populateCondition(ActionCondition condition) + protected void populateCondition(Map conditionProps) { - // find out what the condition is called - Map condProps = new HashMap(3); - String name = condition.getActionConditionDefinitionName(); - condProps.put(PROP_CONDITION_NAME, name); - - // add the appropriate properties - Map repoCondProps = condition.getParameterValues(); - if (name.equals(ComparePropertyValueEvaluator.NAME)) + if (ComparePropertyValueEvaluator.NAME.equals(this.condition)) { - condProps.put(PROP_CONTAINS_TEXT, (String)repoCondProps.get(ComparePropertyValueEvaluator.PARAM_VALUE)); + String propValue = (String)conditionProps.get(ComparePropertyValueEvaluator.PARAM_VALUE); + this.currentConditionProperties.put(PROP_CONTAINS_TEXT, propValue); } - else if (name.equals(InCategoryEvaluator.NAME)) + else if (InCategoryEvaluator.NAME.equals(this.condition)) { - NodeRef catNodeRef = (NodeRef)repoCondProps.get(InCategoryEvaluator.PARAM_CATEGORY_VALUE); - condProps.put(PROP_CATEGORY, catNodeRef); + NodeRef catNodeRef = (NodeRef)conditionProps.get(InCategoryEvaluator.PARAM_CATEGORY_VALUE); + this.currentConditionProperties.put(PROP_CATEGORY, catNodeRef); } - else if (name.equals(IsSubTypeEvaluator.NAME)) + else if (IsSubTypeEvaluator.NAME.equals(this.condition)) { - condProps.put(PROP_MODEL_TYPE, ((QName)repoCondProps.get(IsSubTypeEvaluator.PARAM_TYPE)).toString()); + QName type = (QName)conditionProps.get(IsSubTypeEvaluator.PARAM_TYPE); + this.currentConditionProperties.put(PROP_MODEL_TYPE, type.toString()); } - else if (name.equals(HasAspectEvaluator.NAME)) + else if (HasAspectEvaluator.NAME.equals(this.condition)) { - condProps.put(PROP_ASPECT, ((QName)repoCondProps.get(HasAspectEvaluator.PARAM_ASPECT)).toString()); + QName aspect = (QName)conditionProps.get(HasAspectEvaluator.PARAM_ASPECT); + this.currentConditionProperties.put(PROP_ASPECT, aspect.toString()); } - else if (name.equals(CompareMimeTypeEvaluator.NAME)) + else if (CompareMimeTypeEvaluator.NAME.equals(this.condition)) { - condProps.put(PROP_MIMETYPE, repoCondProps.get(CompareMimeTypeEvaluator.PARAM_VALUE)); + String mimeType = (String)conditionProps.get(CompareMimeTypeEvaluator.PARAM_VALUE); + this.currentConditionProperties.put(PROP_MIMETYPE, mimeType); } - - // specify whether the condition result should be inverted - condProps.put(PROP_CONDITION_NOT, Boolean.valueOf(condition.getInvertCondition())); - - // generate the summary - condProps.put(PROP_CONDITION_SUMMARY, buildConditionSummary(condProps)); - - return condProps; } /**