From e17290f94ddfedf235b97d14f1b81143f8895ad6 Mon Sep 17 00:00:00 2001 From: Derek Hulley Date: Fri, 2 Jun 2006 11:47:33 +0000 Subject: [PATCH] merge into HEAD from BRANCHES/V1.3 svn merge svn://www.alfresco.org:3691/alfresco/BRANCHES/V1.3@2980 svn://www.alfresco.org:3691/alfresco/BRANCHES/V1.3@2981 . git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3015 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/web-client-config.xml | 27 + .../web/bean/DocumentDetailsBean.java | 37 +- .../web/bean/actions/BaseActionWizard.java | 684 +++--------------- .../alfresco/web/bean/actions/IHandler.java | 70 ++ .../web/bean/actions/RunActionWizard.java | 11 +- .../actions/handlers/AddFeaturesHandler.java | 64 ++ .../actions/handlers/BaseActionHandler.java | 34 + .../bean/actions/handlers/CheckInHandler.java | 72 ++ .../actions/handlers/CheckOutHandler.java | 63 ++ .../bean/actions/handlers/CopyHandler.java | 63 ++ .../bean/actions/handlers/ImportHandler.java | 58 ++ .../actions/handlers/LinkCategoryHandler.java | 60 ++ .../bean/actions/handlers/MailHandler.java | 144 ++++ .../bean/actions/handlers/MoveHandler.java | 62 ++ .../handlers/RemoveFeaturesHandler.java | 65 ++ .../bean/actions/handlers/ScriptHandler.java | 63 ++ .../handlers/SimpleWorkflowHandler.java | 181 +++++ .../handlers/SpecialiseTypeHandler.java | 63 ++ .../actions/handlers/TransformHandler.java | 85 +++ .../handlers/TransformImageHandler.java | 95 +++ .../web/bean/rules/CreateRuleWizard.java | 275 +++---- .../web/bean/rules/EditRuleWizard.java | 258 ++----- .../rules/handlers/BaseConditionHandler.java | 34 + .../handlers/CompareMimeTypeHandler.java | 63 ++ .../bean/rules/handlers/HasAspectHandler.java | 64 ++ .../rules/handlers/InCategoryHandler.java | 61 ++ .../bean/rules/handlers/IsSubTypeHandler.java | 64 ++ .../rules/handlers/PropertyValueHandler.java | 53 ++ source/web/jsp/actions/actions.jsp | 4 +- source/web/jsp/rules/conditions.jsp | 5 +- 30 files changed, 1862 insertions(+), 1020 deletions(-) create mode 100644 source/java/org/alfresco/web/bean/actions/IHandler.java create mode 100644 source/java/org/alfresco/web/bean/actions/handlers/AddFeaturesHandler.java create mode 100644 source/java/org/alfresco/web/bean/actions/handlers/BaseActionHandler.java create mode 100644 source/java/org/alfresco/web/bean/actions/handlers/CheckInHandler.java create mode 100644 source/java/org/alfresco/web/bean/actions/handlers/CheckOutHandler.java create mode 100644 source/java/org/alfresco/web/bean/actions/handlers/CopyHandler.java create mode 100644 source/java/org/alfresco/web/bean/actions/handlers/ImportHandler.java create mode 100644 source/java/org/alfresco/web/bean/actions/handlers/LinkCategoryHandler.java create mode 100644 source/java/org/alfresco/web/bean/actions/handlers/MailHandler.java create mode 100644 source/java/org/alfresco/web/bean/actions/handlers/MoveHandler.java create mode 100644 source/java/org/alfresco/web/bean/actions/handlers/RemoveFeaturesHandler.java create mode 100644 source/java/org/alfresco/web/bean/actions/handlers/ScriptHandler.java create mode 100644 source/java/org/alfresco/web/bean/actions/handlers/SimpleWorkflowHandler.java create mode 100644 source/java/org/alfresco/web/bean/actions/handlers/SpecialiseTypeHandler.java create mode 100644 source/java/org/alfresco/web/bean/actions/handlers/TransformHandler.java create mode 100644 source/java/org/alfresco/web/bean/actions/handlers/TransformImageHandler.java create mode 100644 source/java/org/alfresco/web/bean/rules/handlers/BaseConditionHandler.java create mode 100644 source/java/org/alfresco/web/bean/rules/handlers/CompareMimeTypeHandler.java create mode 100644 source/java/org/alfresco/web/bean/rules/handlers/HasAspectHandler.java create mode 100644 source/java/org/alfresco/web/bean/rules/handlers/InCategoryHandler.java create mode 100644 source/java/org/alfresco/web/bean/rules/handlers/IsSubTypeHandler.java create mode 100644 source/java/org/alfresco/web/bean/rules/handlers/PropertyValueHandler.java diff --git a/config/alfresco/web-client-config.xml b/config/alfresco/web-client-config.xml index 00d737eccd..d3606609af 100644 --- a/config/alfresco/web-client-config.xml +++ b/config/alfresco/web-client-config.xml @@ -224,6 +224,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/java/org/alfresco/web/bean/DocumentDetailsBean.java b/source/java/org/alfresco/web/bean/DocumentDetailsBean.java index 1a6065b437..f09af0d416 100644 --- a/source/java/org/alfresco/web/bean/DocumentDetailsBean.java +++ b/source/java/org/alfresco/web/bean/DocumentDetailsBean.java @@ -45,14 +45,13 @@ import org.alfresco.service.namespace.QName; import org.alfresco.web.app.Application; import org.alfresco.web.app.context.UIContextService; import org.alfresco.web.app.servlet.DownloadContentServlet; -import org.alfresco.web.bean.actions.BaseActionWizard; +import org.alfresco.web.bean.actions.handlers.SimpleWorkflowHandler; import org.alfresco.web.bean.repository.MapNode; import org.alfresco.web.bean.repository.Node; import org.alfresco.web.bean.repository.Repository; import org.alfresco.web.ui.common.Utils; import org.alfresco.web.ui.common.Utils.URLMode; import org.alfresco.web.ui.common.component.UIActionLink; -import org.apache.log4j.Logger; /** * Backing bean providing access to the details of a document @@ -73,8 +72,6 @@ public class DocumentDetailsBean extends BaseDetailsBean private static final String MSG_ERROR_WORKFLOW_APPROVE = "error_workflow_approve"; private static final String MSG_ERROR_UPDATE_SIMPLEWORKFLOW = "error_update_simpleworkflow"; private static final String MSG_ERROR_UPDATE_CATEGORY = "error_update_category"; - - private static Logger logger = Logger.getLogger(DocumentDetailsBean.class); protected LockService lockService; protected CopyService copyService; @@ -344,7 +341,6 @@ public class DocumentDetailsBean extends BaseDetailsBean try { - FacesContext context = FacesContext.getCurrentInstance(); tx = Repository.getUserTransaction(FacesContext.getCurrentInstance()); tx.begin(); @@ -494,25 +490,25 @@ public class DocumentDetailsBean extends BaseDetailsBean // put the workflow properties in a separate map for use by the JSP this.workflowProperties = new HashMap(7); - this.workflowProperties.put(BaseActionWizard.PROP_APPROVE_STEP_NAME, + this.workflowProperties.put(SimpleWorkflowHandler.PROP_APPROVE_STEP_NAME, approveStepName); - this.workflowProperties.put(BaseActionWizard.PROP_APPROVE_ACTION, + this.workflowProperties.put(SimpleWorkflowHandler.PROP_APPROVE_ACTION, approveMove ? "move" : "copy"); - this.workflowProperties.put(BaseActionWizard.PROP_APPROVE_FOLDER, approveFolder); + this.workflowProperties.put(SimpleWorkflowHandler.PROP_APPROVE_FOLDER, approveFolder); if (rejectStepName == null || rejectMove == null || rejectFolder == null) { - this.workflowProperties.put(BaseActionWizard.PROP_REJECT_STEP_PRESENT, "no"); + this.workflowProperties.put(SimpleWorkflowHandler.PROP_REJECT_STEP_PRESENT, "no"); } else { - this.workflowProperties.put(BaseActionWizard.PROP_REJECT_STEP_PRESENT, + this.workflowProperties.put(SimpleWorkflowHandler.PROP_REJECT_STEP_PRESENT, "yes"); - this.workflowProperties.put(BaseActionWizard.PROP_REJECT_STEP_NAME, + this.workflowProperties.put(SimpleWorkflowHandler.PROP_REJECT_STEP_NAME, rejectStepName); - this.workflowProperties.put(BaseActionWizard.PROP_REJECT_ACTION, + this.workflowProperties.put(SimpleWorkflowHandler.PROP_REJECT_ACTION, rejectMove ? "move" : "copy"); - this.workflowProperties.put(BaseActionWizard.PROP_REJECT_FOLDER, + this.workflowProperties.put(SimpleWorkflowHandler.PROP_REJECT_FOLDER, rejectFolder); } } @@ -546,7 +542,6 @@ public class DocumentDetailsBean extends BaseDetailsBean try { - FacesContext context = FacesContext.getCurrentInstance(); tx = Repository.getUserTransaction(FacesContext.getCurrentInstance()); tx.begin(); @@ -558,11 +553,11 @@ public class DocumentDetailsBean extends BaseDetailsBean // set the approve step name updateProps.put(ContentModel.PROP_APPROVE_STEP, - this.workflowProperties.get(BaseActionWizard.PROP_APPROVE_STEP_NAME)); + this.workflowProperties.get(SimpleWorkflowHandler.PROP_APPROVE_STEP_NAME)); // specify whether the approve step will copy or move the content boolean approveMove = true; - String approveAction = (String)this.workflowProperties.get(BaseActionWizard.PROP_APPROVE_ACTION); + String approveAction = (String)this.workflowProperties.get(SimpleWorkflowHandler.PROP_APPROVE_ACTION); if (approveAction != null && approveAction.equals("copy")) { approveMove = false; @@ -571,12 +566,12 @@ public class DocumentDetailsBean extends BaseDetailsBean // create node ref representation of the destination folder updateProps.put(ContentModel.PROP_APPROVE_FOLDER, - this.workflowProperties.get(BaseActionWizard.PROP_APPROVE_FOLDER)); + this.workflowProperties.get(SimpleWorkflowHandler.PROP_APPROVE_FOLDER)); // determine whether there should be a reject step boolean requireReject = true; String rejectStepPresent = (String)this.workflowProperties.get( - BaseActionWizard.PROP_REJECT_STEP_PRESENT); + SimpleWorkflowHandler.PROP_REJECT_STEP_PRESENT); if (rejectStepPresent != null && rejectStepPresent.equals("no")) { requireReject = false; @@ -586,12 +581,12 @@ public class DocumentDetailsBean extends BaseDetailsBean { // set the reject step name updateProps.put(ContentModel.PROP_REJECT_STEP, - this.workflowProperties.get(BaseActionWizard.PROP_REJECT_STEP_NAME)); + this.workflowProperties.get(SimpleWorkflowHandler.PROP_REJECT_STEP_NAME)); // specify whether the reject step will copy or move the content boolean rejectMove = true; String rejectAction = (String)this.workflowProperties.get( - BaseActionWizard.PROP_REJECT_ACTION); + SimpleWorkflowHandler.PROP_REJECT_ACTION); if (rejectAction != null && rejectAction.equals("copy")) { rejectMove = false; @@ -600,7 +595,7 @@ public class DocumentDetailsBean extends BaseDetailsBean // create node ref representation of the destination folder updateProps.put(ContentModel.PROP_REJECT_FOLDER, - this.workflowProperties.get(BaseActionWizard.PROP_REJECT_FOLDER)); + this.workflowProperties.get(SimpleWorkflowHandler.PROP_REJECT_FOLDER)); } else { diff --git a/source/java/org/alfresco/web/bean/actions/BaseActionWizard.java b/source/java/org/alfresco/web/bean/actions/BaseActionWizard.java index dd05c0ddb5..373c45152f 100644 --- a/source/java/org/alfresco/web/bean/actions/BaseActionWizard.java +++ b/source/java/org/alfresco/web/bean/actions/BaseActionWizard.java @@ -18,21 +18,8 @@ import javax.faces.model.SelectItem; import org.alfresco.config.Config; import org.alfresco.config.ConfigElement; import org.alfresco.config.ConfigService; +import org.alfresco.error.AlfrescoRuntimeException; 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.CopyActionExecuter; -import org.alfresco.repo.action.executer.ImageTransformActionExecuter; -import org.alfresco.repo.action.executer.ImporterActionExecuter; -import org.alfresco.repo.action.executer.LinkCategoryActionExecuter; -import org.alfresco.repo.action.executer.MailActionExecuter; -import org.alfresco.repo.action.executer.MoveActionExecuter; -import org.alfresco.repo.action.executer.RemoveFeaturesActionExecuter; -import org.alfresco.repo.action.executer.ScriptActionExecutor; -import org.alfresco.repo.action.executer.SimpleWorkflowActionExecuter; -import org.alfresco.repo.action.executer.SpecialiseTypeActionExecuter; -import org.alfresco.repo.action.executer.TransformActionExecuter; import org.alfresco.service.cmr.action.ActionDefinition; import org.alfresco.service.cmr.action.ActionService; import org.alfresco.service.cmr.dictionary.AspectDefinition; @@ -43,10 +30,10 @@ import org.alfresco.service.cmr.repository.MimetypeService; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.PersonService; -import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.web.app.Application; import org.alfresco.web.bean.TemplateSupportBean; +import org.alfresco.web.bean.actions.handlers.MailHandler; import org.alfresco.web.bean.repository.Node; import org.alfresco.web.bean.repository.Repository; import org.alfresco.web.bean.wizard.BaseWizardBean; @@ -64,38 +51,10 @@ import org.apache.commons.logging.LogFactory; */ public abstract class BaseActionWizard extends BaseWizardBean { - public static final String PROP_ACTION_NAME = "actionName"; - public static final String PROP_ACTION_SUMMARY = "actionSummary"; - public static final String PROP_CATEGORY = "category"; - public static final String PROP_ASPECT = "aspect"; - public static final String PROP_DESTINATION = "destinationLocation"; - public static final String PROP_APPROVE_STEP_NAME = "approveStepName"; - public static final String PROP_APPROVE_ACTION = "approveAction"; - public static final String PROP_APPROVE_FOLDER = "approveFolder"; - public static final String PROP_REJECT_STEP_PRESENT = "rejectStepPresent"; - public static final String PROP_REJECT_STEP_NAME = "rejectStepName"; - public static final String PROP_REJECT_ACTION = "rejectAction"; - public static final String PROP_REJECT_FOLDER = "rejectFolder"; - public static final String PROP_CHECKIN_DESC = "checkinDescription"; - public static final String PROP_CHECKIN_MINOR = "checkinMinorChange"; - public static final String PROP_TRANSFORMER = "transformer"; - public static final String PROP_IMAGE_TRANSFORMER = "imageTransformer"; - public static final String PROP_TRANSFORM_OPTIONS = "transformOptions"; - public static final String PROP_ENCODING = "encoding"; - public static final String PROP_MESSAGE = "message"; - public static final String PROP_SUBJECT = "subject"; - public static final String PROP_TO = "to"; - public static final String PROP_FROM = "from"; - public static final String PROP_TEMPLATE = "template"; - public static final String PROP_OBJECT_TYPE = "objecttype"; - public static final String PROP_PROPERTY = "property"; - public static final String PROP_CONTAINS_TEXT = "containstext"; - public static final String PROP_MODEL_TYPE = "modeltype"; - public static final String PROP_MIMETYPE = "mimetype"; - public static final String PROP_MODEL_ASPECT = "modelaspect"; - public static final String PROP_TYPE_OR_ASPECT = "typeoraspect"; - public static final String PROP_SCRIPT = "script"; - + protected static final String PROP_ACTION_NAME = "actionName"; + protected static final String PROP_ACTION_SUMMARY = "actionSummary"; + protected static final String NO_PARAMS_MARKER = "noParamsMarker"; + protected ActionService actionService; protected MimetypeService mimetypeService; protected PersonService personService; @@ -121,11 +80,9 @@ public abstract class BaseActionWizard extends BaseWizardBean protected Map currentActionProperties; protected List> allActionsProperties; - protected static final String ACTION_PAGES_LOCATION = "/jsp/actions/"; + protected Map actionHandlers; private static final Log logger = LogFactory.getLog(BaseActionWizard.class); - private static final String IMPORT_ENCODING = "UTF-8"; - // ------------------------------------------------------------------------------ // Wizard implementation @@ -139,22 +96,15 @@ public abstract class BaseActionWizard extends BaseWizardBean this.users = null; this.actions = null; this.emailRecipientsDataModel = null; - this.emailRecipients = new ArrayList(4); this.usingTemplate = null; + this.emailRecipients = new ArrayList(4); this.allActionsProperties = new ArrayList>(); this.currentActionProperties = new HashMap(3); - // default the approve and reject actions - this.currentActionProperties.put(PROP_APPROVE_ACTION, "move"); - this.currentActionProperties.put(PROP_REJECT_STEP_PRESENT, "yes"); - this.currentActionProperties.put(PROP_REJECT_ACTION, "move"); - - // default the checkin minor change - this.currentActionProperties.put(PROP_CHECKIN_MINOR, new Boolean(true)); + initialiseActionHandlers(); } - // ------------------------------------------------------------------------------ // Bean Getters and Setters @@ -528,6 +478,15 @@ public abstract class BaseActionWizard extends BaseWizardBean return this.imageTransformers; } + /** + * Returns the current list of email recipients + * + * @return List of email recipients + */ + public List getEmailRecipients() + { + return this.emailRecipients; + } // ------------------------------------------------------------------------------ // Action event handlers @@ -542,27 +501,29 @@ public abstract class BaseActionWizard extends BaseWizardBean FacesContext context = FacesContext.getCurrentInstance(); this.returnViewId = context.getViewRoot().getViewId(); - String viewId = calculateActionViewId(this.action); + String viewId = null; HashMap actionProps = new HashMap(3); actionProps.put(PROP_ACTION_NAME, this.action); this.currentActionProperties = actionProps; - // determine whether the action being added has any parameters - ActionDefinition actionDef = this.actionService.getActionDefinition(this.action); - if (actionDef.hasParameterDefinitions()) + // get the handler for the action, if there isn't one we presume it + // is a no-parameter action + IHandler handler = this.actionHandlers.get(this.action); + if (handler != null) { - // setup any defaults for the UI and override the viewId if necessary - String overridenViewId = setupUIDefaultsForAction(actionProps); - if (overridenViewId != null) - { - viewId = overridenViewId; - } + // setup any UI defaults the action may have and get the location of + // the JSP used to collect the parameters + handler.setupUIDefaults(actionProps); + viewId = handler.getJSPPath(); } else { // just add the action to the list and use the title as the summary + ActionDefinition actionDef = this.actionService.getActionDefinition(this.action); actionProps.put(PROP_ACTION_SUMMARY, actionDef.getTitle()); + // add the no params marker so we can disable the edit action + actionProps.put(NO_PARAMS_MARKER, "no-params"); this.allActionsProperties.add(actionProps); // come back to the same page we're on now as there are no params to collect @@ -595,8 +556,9 @@ public abstract class BaseActionWizard extends BaseWizardBean FacesContext context = FacesContext.getCurrentInstance(); this.returnViewId = context.getViewRoot().getViewId(); - // refresh the wizard - goToPage(context, calculateActionViewId(this.action)); + // go to the action page (as there is an edit option visible, + // there must be a handler for the action so we don't check) + goToPage(context, this.actionHandlers.get(this.action).getJSPPath()); } /** @@ -605,7 +567,11 @@ public abstract class BaseActionWizard extends BaseWizardBean public void addAction() { FacesContext context = FacesContext.getCurrentInstance(); - String summary = buildActionSummary(); + + // this is called from the actions page so there must be a handler + // present so there's no need to check for null + String summary = this.actionHandlers.get(this.action).generateSummary( + context, this, this.currentActionProperties); if (summary != null) { @@ -709,18 +675,20 @@ public abstract class BaseActionWizard extends BaseWizardBean */ public void insertTemplate(ActionEvent event) { - String template = (String)this.currentActionProperties.get(PROP_TEMPLATE); + String template = (String)this.currentActionProperties.get(MailHandler.PROP_TEMPLATE); if (template != null && template.equals(TemplateSupportBean.NO_SELECTION) == false) { // get the content of the template so the user can get a basic preview of it try { NodeRef templateRef = new NodeRef(Repository.getStoreRef(), template); - ContentService cs = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getContentService(); + ContentService cs = Repository.getServiceRegistry( + FacesContext.getCurrentInstance()).getContentService(); ContentReader reader = cs.getReader(templateRef, ContentModel.PROP_CONTENT); if (reader != null && reader.exists()) { - this.currentActionProperties.put(PROP_MESSAGE, reader.getContentString()); + this.currentActionProperties.put(MailHandler.PROP_MESSAGE, + reader.getContentString()); usingTemplate = template; } @@ -738,7 +706,7 @@ public abstract class BaseActionWizard extends BaseWizardBean */ public void discardTemplate(ActionEvent event) { - this.currentActionProperties.put(PROP_MESSAGE, ""); + this.currentActionProperties.put(MailHandler.PROP_MESSAGE, ""); usingTemplate = null; } @@ -786,7 +754,7 @@ public abstract class BaseActionWizard extends BaseWizardBean // ------------------------------------------------------------------------------ // Helper methods - protected String displayLabelForAuthority(String authority) + public String displayLabelForAuthority(String authority) { String label = authority; @@ -804,515 +772,6 @@ 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)); - } - - return overridenViewId; - } - - /** - * Build the param map for the current Action instance. - *

- * Based on the params set by the UI, build the params needed to create the action. - * - * @return param map - */ - protected Map buildActionParams() - { - // set up parameters maps for the action - Map repoParams = new HashMap(); - - if (AddFeaturesActionExecuter.NAME.equals(this.action)) - { - QName aspect = Repository.resolveToQName((String)this.currentActionProperties.get(PROP_ASPECT)); - repoParams.put(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, aspect); - } - else if (RemoveFeaturesActionExecuter.NAME.equals(this.action)) - { - QName aspect = Repository.resolveToQName((String)this.currentActionProperties.get(PROP_ASPECT)); - repoParams.put(RemoveFeaturesActionExecuter.PARAM_ASPECT_NAME, aspect); - } - else if (CopyActionExecuter.NAME.equals(this.action)) - { - // add the destination space id to the action properties - NodeRef destNodeRef = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION); - repoParams.put(CopyActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef); - - // add the type and name of the association to create when the copy - // is performed - repoParams.put(CopyActionExecuter.PARAM_ASSOC_TYPE_QNAME, - ContentModel.ASSOC_CONTAINS); - repoParams.put(CopyActionExecuter.PARAM_ASSOC_QNAME, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy")); - } - else if (MoveActionExecuter.NAME.equals(this.action)) - { - // add the destination space id to the action properties - NodeRef destNodeRef = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION); - repoParams.put(MoveActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef); - - // add the type and name of the association to create when the move - // is performed - repoParams.put(MoveActionExecuter.PARAM_ASSOC_TYPE_QNAME, - ContentModel.ASSOC_CONTAINS); - repoParams.put(MoveActionExecuter.PARAM_ASSOC_QNAME, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "move")); - } - else if (SimpleWorkflowActionExecuter.NAME.equals(this.action)) - { - // add the approve step name - repoParams.put(SimpleWorkflowActionExecuter.PARAM_APPROVE_STEP, - (String)this.currentActionProperties.get(PROP_APPROVE_STEP_NAME)); - - // add whether the approve step will copy or move the content - boolean approveMove = true; - String approveAction = (String)this.currentActionProperties.get(PROP_APPROVE_ACTION); - if (approveAction != null && approveAction.equals("copy")) - { - approveMove = false; - } - - repoParams.put(SimpleWorkflowActionExecuter.PARAM_APPROVE_MOVE, Boolean.valueOf(approveMove)); - - // add the destination folder of the content - NodeRef approveDestNodeRef = null; - Object approveDestNode = this.currentActionProperties.get(PROP_APPROVE_FOLDER); - if (approveDestNode instanceof NodeRef) - { - approveDestNodeRef = (NodeRef)approveDestNode; - } - else if (approveDestNode instanceof String) - { - approveDestNodeRef = new NodeRef((String)approveDestNode); - } - repoParams.put(SimpleWorkflowActionExecuter.PARAM_APPROVE_FOLDER, approveDestNodeRef); - - // determine whether we have a reject step or not - boolean requireReject = true; - String rejectStepPresent = (String)this.currentActionProperties.get(PROP_REJECT_STEP_PRESENT); - if (rejectStepPresent != null && rejectStepPresent.equals("no")) - { - requireReject = false; - } - - if (requireReject) - { - // add the reject step name - repoParams.put(SimpleWorkflowActionExecuter.PARAM_REJECT_STEP, - (String)this.currentActionProperties.get(PROP_REJECT_STEP_NAME)); - - // add whether the reject step will copy or move the content - boolean rejectMove = true; - String rejectAction = (String)this.currentActionProperties.get(PROP_REJECT_ACTION); - if (rejectAction != null && rejectAction.equals("copy")) - { - rejectMove = false; - } - - repoParams.put(SimpleWorkflowActionExecuter.PARAM_REJECT_MOVE, Boolean.valueOf(rejectMove)); - - // add the destination folder of the content - NodeRef rejectDestNodeRef = null; - Object rejectDestNode = this.currentActionProperties.get(PROP_REJECT_FOLDER); - if (rejectDestNode instanceof NodeRef) - { - rejectDestNodeRef = (NodeRef)rejectDestNode; - } - else if (rejectDestNode instanceof String) - { - rejectDestNodeRef = new NodeRef((String)rejectDestNode); - } - repoParams.put(SimpleWorkflowActionExecuter.PARAM_REJECT_FOLDER, rejectDestNodeRef); - } - } - else if (LinkCategoryActionExecuter.NAME.equals(this.action)) - { - // add the classifiable aspect - repoParams.put(LinkCategoryActionExecuter.PARAM_CATEGORY_ASPECT, - ContentModel.ASPECT_GEN_CLASSIFIABLE); - - // put the selected category in the action params - NodeRef catNodeRef = (NodeRef)this.currentActionProperties.get(PROP_CATEGORY); - repoParams.put(LinkCategoryActionExecuter.PARAM_CATEGORY_VALUE, - catNodeRef); - } - 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 - NodeRef destNodeRef = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION); - repoParams.put(CheckOutActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef); - - // add the type and name of the association to create when the - // check out is performed - repoParams.put(CheckOutActionExecuter.PARAM_ASSOC_TYPE_QNAME, - ContentModel.ASSOC_CONTAINS); - repoParams.put(CheckOutActionExecuter.PARAM_ASSOC_QNAME, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "checkout")); - } - else if (CheckInActionExecuter.NAME.equals(this.action)) - { - // add the description for the checkin to the action params - repoParams.put(CheckInActionExecuter.PARAM_DESCRIPTION, - this.currentActionProperties.get(PROP_CHECKIN_DESC)); - - // add the minor change flag - repoParams.put(CheckInActionExecuter.PARAM_MINOR_CHANGE, - this.currentActionProperties.get(PROP_CHECKIN_MINOR)); - } - else if (TransformActionExecuter.NAME.equals(this.action)) - { - // add the transformer to use - repoParams.put(TransformActionExecuter.PARAM_MIME_TYPE, - this.currentActionProperties.get(PROP_TRANSFORMER)); - - // add the destination space id to the action properties - NodeRef destNodeRef = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION); - repoParams.put(TransformActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef); - - // add the type and name of the association to create when the copy - // is performed - repoParams.put(TransformActionExecuter.PARAM_ASSOC_TYPE_QNAME, - ContentModel.ASSOC_CONTAINS); - repoParams.put(TransformActionExecuter.PARAM_ASSOC_QNAME, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy")); - } - else if (ImageTransformActionExecuter.NAME.equals(this.action)) - { - // add the transformer to use - repoParams.put(ImageTransformActionExecuter.PARAM_MIME_TYPE, - this.currentActionProperties.get(PROP_IMAGE_TRANSFORMER)); - - // add the options - repoParams.put(ImageTransformActionExecuter.PARAM_CONVERT_COMMAND, - this.currentActionProperties.get(PROP_TRANSFORM_OPTIONS)); - - // add the destination space id to the action properties - NodeRef destNodeRef = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION); - repoParams.put(TransformActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef); - - // add the type and name of the association to create when the copy - // is performed - repoParams.put(TransformActionExecuter.PARAM_ASSOC_TYPE_QNAME, - ContentModel.ASSOC_CONTAINS); - repoParams.put(TransformActionExecuter.PARAM_ASSOC_QNAME, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy")); - } - 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()); - for (int i=0; i(20); + + // instantiate each handler and store in the map + for (ConfigElement child : actionHandlerCfg.getChildren()) + { + String actionName = child.getAttribute("name"); + String handlerClass = child.getAttribute("class"); + + if (actionName != null && actionName.length() > 0 && + handlerClass != null && handlerClass.length() > 0) + { + try + { + Class klass = Class.forName(handlerClass); + IHandler handler = (IHandler)klass.newInstance(); + this.actionHandlers.put(actionName, handler); + } + catch (Exception e) + { + throw new AlfrescoRuntimeException("Failed to setup action handler for '" + + actionName + "'", e); + } + } + } + } + else + { + logger.warn("Could not find 'action-handlers' configuration element"); + } + } + else + { + logger.warn("Could not find 'Action Wizards' configuration section"); + } + } } - // ------------------------------------------------------------------------------ // Inner classes diff --git a/source/java/org/alfresco/web/bean/actions/IHandler.java b/source/java/org/alfresco/web/bean/actions/IHandler.java new file mode 100644 index 0000000000..43cb444ff7 --- /dev/null +++ b/source/java/org/alfresco/web/bean/actions/IHandler.java @@ -0,0 +1,70 @@ +package org.alfresco.web.bean.actions; + +import java.io.Serializable; +import java.util.Map; + +import javax.faces.context.FacesContext; + +import org.alfresco.web.bean.wizard.IWizardBean; + +/** + * Interface definition for a handler, classes that are responsible + * for marshalling data between the repository and the action based + * wizards. + * + * @author gavinc + */ +public interface IHandler +{ + /** + * Adds any properties to the given map that need default values + * before the UI is displayed to the user. + * + * @param props The current properties map + */ + public void setupUIDefaults(Map props); + + /** + * By default, a JSP with the same name as the handler will + * be loaded from a default location. If the handler has stored + * it's UI somewhere else the view id can be returned from this method. + * + * @return The path to the JSP for the handler + */ + public String getJSPPath(); + + /** + * Called at the end of the wizard. The properties relevant to + * this handler have to be placed in the repository properties + * map in the correct form for sending to the node service. + * + * @param props The current properties map + * @param repoProps The repository properties map to prepare + */ + public void prepareForSave(Map props, + Map repoProps); + + /** + * Called at the start of the edit wizard. The repository properties + * map holds the current state of this rule. Any properties relevant + * to this handler should be retrieved and setup in the current + * properties map. + * + * @param props The current properties map + * @param repoParams The properties currently in the repository + */ + public void prepareForEdit(Map props, + Map repoProps); + + /** + * Generates a summary string for this handler. The current state of + * the wizard is passed as well as the current properties map. + * + * @param context Faces context + * @param wizard The current wizard + * @param props The properties map + * @return The summary string + */ + public String generateSummary(FacesContext context, IWizardBean wizard, + Map props); +} diff --git a/source/java/org/alfresco/web/bean/actions/RunActionWizard.java b/source/java/org/alfresco/web/bean/actions/RunActionWizard.java index e9b140ad25..d57d42955b 100644 --- a/source/java/org/alfresco/web/bean/actions/RunActionWizard.java +++ b/source/java/org/alfresco/web/bean/actions/RunActionWizard.java @@ -2,6 +2,7 @@ package org.alfresco.web.bean.actions; import java.io.Serializable; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.ResourceBundle; @@ -37,8 +38,14 @@ public class RunActionWizard extends BaseActionWizard // to setup the currentActionProperties and action variables String actionName = (String)actionParams.get(PROP_ACTION_NAME); this.action = actionName; - this.currentActionProperties = actionParams; - Map repoActionParams = buildActionParams(); + + // get the action handler to prepare for the save + Map repoActionParams = new HashMap(); + IHandler handler = this.actionHandlers.get(this.action); + if (handler != null) + { + handler.prepareForSave(actionParams, repoActionParams); + } // add the action to the rule Action action = this.actionService.createAction(actionName); diff --git a/source/java/org/alfresco/web/bean/actions/handlers/AddFeaturesHandler.java b/source/java/org/alfresco/web/bean/actions/handlers/AddFeaturesHandler.java new file mode 100644 index 0000000000..baf02081b6 --- /dev/null +++ b/source/java/org/alfresco/web/bean/actions/handlers/AddFeaturesHandler.java @@ -0,0 +1,64 @@ +package org.alfresco.web.bean.actions.handlers; + +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.Map; + +import javax.faces.context.FacesContext; +import javax.faces.model.SelectItem; + +import org.alfresco.repo.action.executer.AddFeaturesActionExecuter; +import org.alfresco.service.namespace.QName; +import org.alfresco.web.app.Application; +import org.alfresco.web.bean.actions.BaseActionWizard; +import org.alfresco.web.bean.repository.Repository; +import org.alfresco.web.bean.wizard.IWizardBean; + +/** + * Action handler implementation for the "add-features" action. + * + * @author gavinc + */ +public class AddFeaturesHandler extends BaseActionHandler +{ + protected static final String PROP_ASPECT = "aspect"; + + public String getJSPPath() + { + return getJSPPath(AddFeaturesActionExecuter.NAME); + } + + public void prepareForSave(Map actionProps, + Map repoParams) + { + QName aspect = Repository.resolveToQName((String)actionProps.get(PROP_ASPECT)); + repoParams.put(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, aspect); + } + + public void prepareForEdit(Map actionProps, + Map repoParams) + { + QName aspect = (QName)repoParams.get(AddFeaturesActionExecuter.PARAM_ASPECT_NAME); + actionProps.put(PROP_ASPECT, aspect.toString()); + } + + public String generateSummary(FacesContext context, IWizardBean wizard, + Map actionProps) + { + String label = null; + String aspect = (String)actionProps.get(PROP_ASPECT); + + // find the label used by looking through the SelectItem list + for (SelectItem item : ((BaseActionWizard)wizard).getAspects()) + { + if (item.getValue().equals(aspect)) + { + label = item.getLabel(); + break; + } + } + + return MessageFormat.format(Application.getMessage(context, "action_add_features"), + new Object[] {label}); + } +} diff --git a/source/java/org/alfresco/web/bean/actions/handlers/BaseActionHandler.java b/source/java/org/alfresco/web/bean/actions/handlers/BaseActionHandler.java new file mode 100644 index 0000000000..202427b9a6 --- /dev/null +++ b/source/java/org/alfresco/web/bean/actions/handlers/BaseActionHandler.java @@ -0,0 +1,34 @@ +package org.alfresco.web.bean.actions.handlers; + +import java.io.Serializable; +import java.util.Map; + +import org.alfresco.web.bean.actions.IHandler; + +/** + * Base class for all action handler implementations. + * + * @author gavinc + */ +public abstract class BaseActionHandler implements IHandler +{ + protected static final String ACTION_PAGES_LOCATION = "/jsp/actions/"; + protected static final String PROP_DESTINATION = "destinationLocation"; + + public void setupUIDefaults(Map actionProps) + { + // do nothing by default, only those action handlers that need + // to setup defaults need override this method + } + + /** + * Given the action name, generates the default path for the JSP + * + * @param actionName The name of the action + * @return The path to the JSP used for the action + */ + protected String getJSPPath(String actionName) + { + return ACTION_PAGES_LOCATION + actionName + ".jsp"; + } +} diff --git a/source/java/org/alfresco/web/bean/actions/handlers/CheckInHandler.java b/source/java/org/alfresco/web/bean/actions/handlers/CheckInHandler.java new file mode 100644 index 0000000000..174727ed6e --- /dev/null +++ b/source/java/org/alfresco/web/bean/actions/handlers/CheckInHandler.java @@ -0,0 +1,72 @@ +package org.alfresco.web.bean.actions.handlers; + +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.Map; + +import javax.faces.context.FacesContext; + +import org.alfresco.repo.action.executer.CheckInActionExecuter; +import org.alfresco.web.app.Application; +import org.alfresco.web.bean.wizard.IWizardBean; + +/** + * Action handler implementation for the "check-in" action. + * + * @author gavinc + */ +public class CheckInHandler extends BaseActionHandler +{ + protected static final String PROP_CHECKIN_DESC = "checkinDescription"; + protected static final String PROP_CHECKIN_MINOR = "checkinMinorChange"; + + @Override + public void setupUIDefaults(Map actionProps) + { + actionProps.put(PROP_CHECKIN_MINOR, new Boolean(true)); + } + + public String getJSPPath() + { + return getJSPPath(CheckInActionExecuter.NAME); + } + + public void prepareForSave(Map actionProps, + Map repoProps) + { + repoProps.put(CheckInActionExecuter.PARAM_DESCRIPTION, + actionProps.get(PROP_CHECKIN_DESC)); + + repoProps.put(CheckInActionExecuter.PARAM_MINOR_CHANGE, + actionProps.get(PROP_CHECKIN_MINOR)); + } + + public void prepareForEdit(Map actionProps, + Map repoProps) + { + String checkDesc = (String)repoProps.get(CheckInActionExecuter.PARAM_DESCRIPTION); + actionProps.put(PROP_CHECKIN_DESC, checkDesc); + + Boolean minorChange = (Boolean)repoProps.get(CheckInActionExecuter.PARAM_MINOR_CHANGE); + actionProps.put(PROP_CHECKIN_MINOR, minorChange); + } + + public String generateSummary(FacesContext context, IWizardBean wizard, + Map actionProps) + { + String comment = (String)actionProps.get(PROP_CHECKIN_DESC); + Boolean minorChange = (Boolean)actionProps.get(PROP_CHECKIN_MINOR); + String change = null; + if (minorChange != null && minorChange.booleanValue()) + { + change = Application.getMessage(context, "minor_change"); + } + else + { + change = Application.getMessage(context, "major_change"); + } + + return MessageFormat.format(Application.getMessage(context, "action_check_in"), + new Object[] {change, comment}); + } +} diff --git a/source/java/org/alfresco/web/bean/actions/handlers/CheckOutHandler.java b/source/java/org/alfresco/web/bean/actions/handlers/CheckOutHandler.java new file mode 100644 index 0000000000..62ce9551b4 --- /dev/null +++ b/source/java/org/alfresco/web/bean/actions/handlers/CheckOutHandler.java @@ -0,0 +1,63 @@ +package org.alfresco.web.bean.actions.handlers; + +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.Map; + +import javax.faces.context.FacesContext; + +import org.alfresco.model.ContentModel; +import org.alfresco.repo.action.executer.CheckOutActionExecuter; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.service.namespace.QName; +import org.alfresco.web.app.Application; +import org.alfresco.web.bean.repository.Repository; +import org.alfresco.web.bean.wizard.IWizardBean; + +/** + * Action handler implementation for the "check-out" action. + * + * @author gavinc + */ +public class CheckOutHandler extends BaseActionHandler +{ + public String getJSPPath() + { + return getJSPPath(CheckOutActionExecuter.NAME); + } + + public void prepareForSave(Map actionProps, + Map repoProps) + { + // specify the location the checked out working copy should go + // add the destination space id to the action properties + NodeRef destNodeRef = (NodeRef)actionProps.get(PROP_DESTINATION); + repoProps.put(CheckOutActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef); + + // add the type and name of the association to create when the + // check out is performed + repoProps.put(CheckOutActionExecuter.PARAM_ASSOC_TYPE_QNAME, + ContentModel.ASSOC_CONTAINS); + repoProps.put(CheckOutActionExecuter.PARAM_ASSOC_QNAME, + QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "checkout")); + } + + public void prepareForEdit(Map actionProps, + Map repoProps) + { + NodeRef destNodeRef = (NodeRef)repoProps.get(CheckOutActionExecuter.PARAM_DESTINATION_FOLDER); + actionProps.put(PROP_DESTINATION, destNodeRef); + } + + public String generateSummary(FacesContext context, IWizardBean wizard, + Map actionProps) + { + NodeRef space = (NodeRef)actionProps.get(PROP_DESTINATION); + String spaceName = Repository.getNameForNode( + Repository.getServiceRegistry(context).getNodeService(), space); + + return MessageFormat.format(Application.getMessage(context, "action_check_out"), + new Object[] {spaceName}); + } +} diff --git a/source/java/org/alfresco/web/bean/actions/handlers/CopyHandler.java b/source/java/org/alfresco/web/bean/actions/handlers/CopyHandler.java new file mode 100644 index 0000000000..62484472bb --- /dev/null +++ b/source/java/org/alfresco/web/bean/actions/handlers/CopyHandler.java @@ -0,0 +1,63 @@ +package org.alfresco.web.bean.actions.handlers; + +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.Map; + +import javax.faces.context.FacesContext; + +import org.alfresco.model.ContentModel; +import org.alfresco.repo.action.executer.CopyActionExecuter; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.service.namespace.QName; +import org.alfresco.web.app.Application; +import org.alfresco.web.bean.repository.Repository; +import org.alfresco.web.bean.wizard.IWizardBean; + +/** + * Action handler implementation for the "copy" action. + * + * @author gavinc + */ +public class CopyHandler extends BaseActionHandler +{ + public String getJSPPath() + { + return getJSPPath(CopyActionExecuter.NAME); + } + + public void prepareForSave(Map actionProps, + Map repoProps) + { + // add the destination space id to the action properties + NodeRef destNodeRef = (NodeRef)actionProps.get(PROP_DESTINATION); + repoProps.put(CopyActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef); + + // add the type and name of the association to create when the copy + // is performed + repoProps.put(CopyActionExecuter.PARAM_ASSOC_TYPE_QNAME, + ContentModel.ASSOC_CONTAINS); + repoProps.put(CopyActionExecuter.PARAM_ASSOC_QNAME, + QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy")); + } + + public void prepareForEdit(Map actionProps, + Map repoProps) + { + NodeRef destNodeRef = (NodeRef)repoProps.get(CopyActionExecuter.PARAM_DESTINATION_FOLDER); + actionProps.put(PROP_DESTINATION, destNodeRef); + } + + public String generateSummary(FacesContext context, IWizardBean wizard, + Map actionProps) + { + NodeRef space = (NodeRef)actionProps.get(PROP_DESTINATION); + String spaceName = Repository.getNameForNode( + Repository.getServiceRegistry(context).getNodeService(), space); + + return MessageFormat.format(Application.getMessage(context, "action_copy"), + new Object[] {spaceName}); + } + +} diff --git a/source/java/org/alfresco/web/bean/actions/handlers/ImportHandler.java b/source/java/org/alfresco/web/bean/actions/handlers/ImportHandler.java new file mode 100644 index 0000000000..c83c129967 --- /dev/null +++ b/source/java/org/alfresco/web/bean/actions/handlers/ImportHandler.java @@ -0,0 +1,58 @@ +package org.alfresco.web.bean.actions.handlers; + +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.Map; + +import javax.faces.context.FacesContext; + +import org.alfresco.repo.action.executer.ImporterActionExecuter; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.web.app.Application; +import org.alfresco.web.bean.repository.Repository; +import org.alfresco.web.bean.wizard.IWizardBean; + +/** + * Action handler implementation for the "import" action. + * + * @author gavinc + */ +public class ImportHandler extends BaseActionHandler +{ + protected static final String IMPORT_ENCODING = "UTF-8"; + + public String getJSPPath() + { + return getJSPPath(ImporterActionExecuter.NAME); + } + + public void prepareForSave(Map actionProps, + Map repoProps) + { + // add the encoding + repoProps.put(ImporterActionExecuter.PARAM_ENCODING, IMPORT_ENCODING); + + // add the destination for the import + NodeRef destNodeRef = (NodeRef)actionProps.get(PROP_DESTINATION); + repoProps.put(ImporterActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef); + } + + public void prepareForEdit(Map actionProps, + Map repoProps) + { + NodeRef destNodeRef = (NodeRef)repoProps.get( + ImporterActionExecuter.PARAM_DESTINATION_FOLDER); + actionProps.put(PROP_DESTINATION, destNodeRef); + } + + public String generateSummary(FacesContext context, IWizardBean wizard, + Map actionProps) + { + NodeRef space = (NodeRef)actionProps.get(PROP_DESTINATION); + String spaceName = Repository.getNameForNode( + Repository.getServiceRegistry(context).getNodeService(), space); + + return MessageFormat.format(Application.getMessage(context, "action_import"), + new Object[] {spaceName}); + } +} diff --git a/source/java/org/alfresco/web/bean/actions/handlers/LinkCategoryHandler.java b/source/java/org/alfresco/web/bean/actions/handlers/LinkCategoryHandler.java new file mode 100644 index 0000000000..1512f58ede --- /dev/null +++ b/source/java/org/alfresco/web/bean/actions/handlers/LinkCategoryHandler.java @@ -0,0 +1,60 @@ +package org.alfresco.web.bean.actions.handlers; + +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.Map; + +import javax.faces.context.FacesContext; + +import org.alfresco.model.ContentModel; +import org.alfresco.repo.action.executer.LinkCategoryActionExecuter; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.web.app.Application; +import org.alfresco.web.bean.repository.Repository; +import org.alfresco.web.bean.wizard.IWizardBean; + +/** + * Action handler implementation for the "link-category" action. + * + * @author gavinc + */ +public class LinkCategoryHandler extends BaseActionHandler +{ + protected static final String PROP_CATEGORY = "category"; + + public String getJSPPath() + { + return getJSPPath(LinkCategoryActionExecuter.NAME); + } + + public void prepareForSave(Map actionProps, + Map repoProps) + { + // add the classifiable aspect + repoProps.put(LinkCategoryActionExecuter.PARAM_CATEGORY_ASPECT, + ContentModel.ASPECT_GEN_CLASSIFIABLE); + + // put the selected category in the action params + NodeRef catNodeRef = (NodeRef)actionProps.get(PROP_CATEGORY); + repoProps.put(LinkCategoryActionExecuter.PARAM_CATEGORY_VALUE, + catNodeRef); + } + + public void prepareForEdit(Map actionProps, + Map repoProps) + { + NodeRef catNodeRef = (NodeRef)repoProps.get(LinkCategoryActionExecuter.PARAM_CATEGORY_VALUE); + actionProps.put(PROP_CATEGORY, catNodeRef); + } + + public String generateSummary(FacesContext context, IWizardBean wizard, + Map actionProps) + { + NodeRef cat = (NodeRef)actionProps.get(PROP_CATEGORY); + String name = Repository.getNameForNode( + Repository.getServiceRegistry(context).getNodeService(), cat); + + return MessageFormat.format(Application.getMessage(context, "action_link_category"), + new Object[] {name}); + } +} diff --git a/source/java/org/alfresco/web/bean/actions/handlers/MailHandler.java b/source/java/org/alfresco/web/bean/actions/handlers/MailHandler.java new file mode 100644 index 0000000000..1a891d3f09 --- /dev/null +++ b/source/java/org/alfresco/web/bean/actions/handlers/MailHandler.java @@ -0,0 +1,144 @@ +package org.alfresco.web.bean.actions.handlers; + +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.faces.context.FacesContext; + +import org.alfresco.repo.action.executer.MailActionExecuter; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.web.app.Application; +import org.alfresco.web.bean.actions.BaseActionWizard; +import org.alfresco.web.bean.actions.BaseActionWizard.RecipientWrapper; +import org.alfresco.web.bean.repository.Repository; +import org.alfresco.web.bean.wizard.IWizardBean; + +/** + * Action handler implementation for the "mail" action. + * + * @author gavinc + */ +public class MailHandler extends BaseActionHandler +{ + public static final String PROP_TO = "to"; + public static final String PROP_FROM = "from"; + public static final String PROP_MESSAGE = "message"; + public static final String PROP_SUBJECT = "subject"; + public static final String PROP_TEMPLATE = "template"; + + public String getJSPPath() + { + return getJSPPath(MailActionExecuter.NAME); + } + + public void prepareForSave(Map actionProps, + Map repoProps) + { + // get hold of the current wizard so we can extract some data from it + BaseActionWizard wizard = (BaseActionWizard)Application. + getWizardManager().getBean(); + + // add the person(s) it's going to as a list of authorities + List recipients = new ArrayList(wizard.getEmailRecipients().size()); + for (int i=0; i < wizard.getEmailRecipients().size(); i++) + { + RecipientWrapper wrapper = wizard.getEmailRecipients().get(i); + recipients.add(wrapper.getAuthority()); + } + + repoProps.put(MailActionExecuter.PARAM_TO_MANY, (Serializable)recipients); + + // add the actual email text to send + repoProps.put(MailActionExecuter.PARAM_TEXT, actionProps.get(PROP_MESSAGE)); + + // add the subject for the email + repoProps.put(MailActionExecuter.PARAM_SUBJECT, actionProps.get(PROP_SUBJECT)); + + // add the from address + String from = Application.getClientConfig(FacesContext.getCurrentInstance()).getFromEmailAddress(); + repoProps.put(MailActionExecuter.PARAM_FROM, from); + + // add the template if one was selected by the user + if (wizard.getUsingTemplate() != null) + { + repoProps.put(MailActionExecuter.PARAM_TEMPLATE, new NodeRef(Repository.getStoreRef(), + wizard.getUsingTemplate())); + } + } + + public void prepareForEdit(Map actionProps, + Map repoProps) + { + // get hold of the current wizard so we can extract some data from it + BaseActionWizard wizard = (BaseActionWizard)Application. + getWizardManager().getBean(); + + String subject = (String)repoProps.get(MailActionExecuter.PARAM_SUBJECT); + actionProps.put(PROP_SUBJECT, subject); + + String message = (String)repoProps.get(MailActionExecuter.PARAM_TEXT); + actionProps.put(PROP_MESSAGE, message); + + // handle single email or multiple authority recipients + String to = (String)repoProps.get(MailActionExecuter.PARAM_TO); + if (to != null) + { + actionProps.put(PROP_TO, to); + } + else + { + List recipients = (List)repoProps.get(MailActionExecuter.PARAM_TO_MANY); + if (recipients != null && recipients.size() != 0) + { + // rebuild the list of RecipientWrapper objects from the stored action + for (String authority : recipients) + { + wizard.getEmailRecipients().add( + new RecipientWrapper(wizard.displayLabelForAuthority(authority), + authority)); + } + } + } + + NodeRef templateRef = (NodeRef)repoProps.get(MailActionExecuter.PARAM_TEMPLATE); + if (templateRef != null) + { + actionProps.put(PROP_TEMPLATE, templateRef.getId()); + wizard.setUsingTemplate(templateRef.getId()); + } + } + + public String generateSummary(FacesContext context, IWizardBean wizard, + Map actionProps) + { + BaseActionWizard actionWizard = (BaseActionWizard)wizard; + + String addresses = (String)actionProps.get(PROP_TO); + + if (addresses == null || addresses.length() == 0) + { + if (actionWizard.getEmailRecipients().size() != 0) + { + StringBuilder builder = new StringBuilder(); + + for (int i=0; i < actionWizard.getEmailRecipients().size(); i++) + { + RecipientWrapper wrapper = actionWizard.getEmailRecipients().get(i); + if (i != 0) + { + builder.append(", "); + } + builder.append(wrapper.getName()); + } + + addresses = builder.toString(); + } + } + + return MessageFormat.format(Application.getMessage(context, "action_mail"), + new Object[] {addresses}); + } +} diff --git a/source/java/org/alfresco/web/bean/actions/handlers/MoveHandler.java b/source/java/org/alfresco/web/bean/actions/handlers/MoveHandler.java new file mode 100644 index 0000000000..27b257d4b8 --- /dev/null +++ b/source/java/org/alfresco/web/bean/actions/handlers/MoveHandler.java @@ -0,0 +1,62 @@ +package org.alfresco.web.bean.actions.handlers; + +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.Map; + +import javax.faces.context.FacesContext; + +import org.alfresco.model.ContentModel; +import org.alfresco.repo.action.executer.MoveActionExecuter; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.service.namespace.QName; +import org.alfresco.web.app.Application; +import org.alfresco.web.bean.repository.Repository; +import org.alfresco.web.bean.wizard.IWizardBean; + +/** + * Action handler for the "move" action. + * + * @author gavinc + */ +public class MoveHandler extends BaseActionHandler +{ + public String getJSPPath() + { + return getJSPPath(MoveActionExecuter.NAME); + } + + public void prepareForSave(Map actionProps, + Map repoProps) + { + // add the destination space id to the action properties + NodeRef destNodeRef = (NodeRef)actionProps.get(PROP_DESTINATION); + repoProps.put(MoveActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef); + + // add the type and name of the association to create when the move + // is performed + repoProps.put(MoveActionExecuter.PARAM_ASSOC_TYPE_QNAME, + ContentModel.ASSOC_CONTAINS); + repoProps.put(MoveActionExecuter.PARAM_ASSOC_QNAME, + QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "move")); + } + + public void prepareForEdit(Map actionProps, + Map repoProps) + { + NodeRef destNodeRef = (NodeRef)repoProps.get(MoveActionExecuter.PARAM_DESTINATION_FOLDER); + actionProps.put(PROP_DESTINATION, destNodeRef); + } + + public String generateSummary(FacesContext context, IWizardBean wizard, + Map actionProps) + { + NodeRef space = (NodeRef)actionProps.get(PROP_DESTINATION); + String spaceName = Repository.getNameForNode( + Repository.getServiceRegistry(context).getNodeService(), space); + + return MessageFormat.format(Application.getMessage(context, "action_move"), + new Object[] {spaceName}); + } +} diff --git a/source/java/org/alfresco/web/bean/actions/handlers/RemoveFeaturesHandler.java b/source/java/org/alfresco/web/bean/actions/handlers/RemoveFeaturesHandler.java new file mode 100644 index 0000000000..ed0f329c37 --- /dev/null +++ b/source/java/org/alfresco/web/bean/actions/handlers/RemoveFeaturesHandler.java @@ -0,0 +1,65 @@ +package org.alfresco.web.bean.actions.handlers; + +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.Map; + +import javax.faces.context.FacesContext; +import javax.faces.model.SelectItem; + +import org.alfresco.repo.action.executer.RemoveFeaturesActionExecuter; +import org.alfresco.service.namespace.QName; +import org.alfresco.web.app.Application; +import org.alfresco.web.bean.actions.BaseActionWizard; +import org.alfresco.web.bean.repository.Repository; +import org.alfresco.web.bean.wizard.IWizardBean; + +/** + * Action handler for the "remove-features" action. + * + * @author gavinc + */ +public class RemoveFeaturesHandler extends BaseActionHandler +{ + protected static final String PROP_ASPECT = "aspect"; + + public String getJSPPath() + { + return getJSPPath(RemoveFeaturesActionExecuter.NAME); + } + + public void prepareForSave(Map actionProps, + Map repoProps) + { + QName aspect = Repository.resolveToQName((String)actionProps.get(PROP_ASPECT)); + repoProps.put(RemoveFeaturesActionExecuter.PARAM_ASPECT_NAME, aspect); + } + + public void prepareForEdit(Map actionProps, + Map repoProps) + { + QName aspect = (QName)repoProps.get(RemoveFeaturesActionExecuter.PARAM_ASPECT_NAME); + actionProps.put(PROP_ASPECT, aspect.toString()); + } + + public String generateSummary(FacesContext context, IWizardBean wizard, + Map actionProps) + { + String label = null; + String aspect = (String)actionProps.get(PROP_ASPECT); + + // find the label used by looking through the SelectItem list + for (SelectItem item : ((BaseActionWizard)wizard).getAspects()) + { + if (item.getValue().equals(aspect)) + { + label = item.getLabel(); + break; + } + } + + return MessageFormat.format(Application.getMessage(context, "action_remove_features"), + new Object[] {label}); + } + +} diff --git a/source/java/org/alfresco/web/bean/actions/handlers/ScriptHandler.java b/source/java/org/alfresco/web/bean/actions/handlers/ScriptHandler.java new file mode 100644 index 0000000000..d7b2c1f785 --- /dev/null +++ b/source/java/org/alfresco/web/bean/actions/handlers/ScriptHandler.java @@ -0,0 +1,63 @@ +package org.alfresco.web.bean.actions.handlers; + +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.Map; + +import javax.faces.context.FacesContext; + +import org.alfresco.repo.action.executer.ScriptActionExecutor; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.web.app.Application; +import org.alfresco.web.app.servlet.FacesHelper; +import org.alfresco.web.bean.NavigationBean; +import org.alfresco.web.bean.repository.Repository; +import org.alfresco.web.bean.wizard.IWizardBean; + +/** + * Action handler for the "script" action. + * + * @author gavinc + */ +public class ScriptHandler extends BaseActionHandler +{ + protected static final String PROP_SCRIPT = "script"; + + public String getJSPPath() + { + return getJSPPath(ScriptActionExecutor.NAME); + } + + public void prepareForSave(Map actionProps, + Map repoProps) + { + // add the selected script noderef to the action properties + String id = (String)actionProps.get(PROP_SCRIPT); + NodeRef scriptRef = new NodeRef(Repository.getStoreRef(), id); + repoProps.put(ScriptActionExecutor.PARAM_SCRIPTREF, scriptRef); + + NavigationBean navBean = (NavigationBean)FacesHelper.getManagedBean( + FacesContext.getCurrentInstance(), "NavigationBean"); + repoProps.put(ScriptActionExecutor.PARAM_SPACEREF, + navBean.getCurrentNode().getNodeRef()); + } + + public void prepareForEdit(Map actionProps, + Map repoProps) + { + NodeRef scriptRef = (NodeRef)repoProps.get(ScriptActionExecutor.PARAM_SCRIPTREF); + actionProps.put(PROP_SCRIPT, scriptRef.getId()); + } + + public String generateSummary(FacesContext context, IWizardBean wizard, + Map actionProps) + { + String id = (String)actionProps.get(PROP_SCRIPT); + NodeRef scriptRef = new NodeRef(Repository.getStoreRef(), id); + String scriptName = Repository.getNameForNode( + Repository.getServiceRegistry(context).getNodeService(), scriptRef); + + return MessageFormat.format(Application.getMessage(context, "action_script"), + new Object[] {scriptName}); + } +} diff --git a/source/java/org/alfresco/web/bean/actions/handlers/SimpleWorkflowHandler.java b/source/java/org/alfresco/web/bean/actions/handlers/SimpleWorkflowHandler.java new file mode 100644 index 0000000000..504e50279f --- /dev/null +++ b/source/java/org/alfresco/web/bean/actions/handlers/SimpleWorkflowHandler.java @@ -0,0 +1,181 @@ +package org.alfresco.web.bean.actions.handlers; + +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.Map; + +import javax.faces.context.FacesContext; + +import org.alfresco.repo.action.executer.SimpleWorkflowActionExecuter; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.web.app.Application; +import org.alfresco.web.bean.repository.Repository; +import org.alfresco.web.bean.wizard.IWizardBean; + +/** + * Action handler for the "simple-workflow" action. + * + * @author gavinc + */ +public class SimpleWorkflowHandler extends BaseActionHandler +{ + public static final String PROP_APPROVE_STEP_NAME = "approveStepName"; + public static final String PROP_APPROVE_ACTION = "approveAction"; + public static final String PROP_APPROVE_FOLDER = "approveFolder"; + public static final String PROP_REJECT_STEP_PRESENT = "rejectStepPresent"; + public static final String PROP_REJECT_STEP_NAME = "rejectStepName"; + public static final String PROP_REJECT_ACTION = "rejectAction"; + public static final String PROP_REJECT_FOLDER = "rejectFolder"; + + @Override + public void setupUIDefaults(Map actionProps) + { + actionProps.put(PROP_APPROVE_ACTION, "move"); + actionProps.put(PROP_REJECT_STEP_PRESENT, "yes"); + actionProps.put(PROP_REJECT_ACTION, "move"); + } + + public String getJSPPath() + { + return getJSPPath(SimpleWorkflowActionExecuter.NAME); + } + + public void prepareForSave(Map actionProps, + Map repoProps) + { + // add the approve step name + repoProps.put(SimpleWorkflowActionExecuter.PARAM_APPROVE_STEP, + (String)actionProps.get(PROP_APPROVE_STEP_NAME)); + + // add whether the approve step will copy or move the content + boolean approveMove = true; + String approveAction = (String)actionProps.get(PROP_APPROVE_ACTION); + if (approveAction != null && approveAction.equals("copy")) + { + approveMove = false; + } + + repoProps.put(SimpleWorkflowActionExecuter.PARAM_APPROVE_MOVE, Boolean.valueOf(approveMove)); + + // add the destination folder of the content + NodeRef approveDestNodeRef = null; + Object approveDestNode = actionProps.get(PROP_APPROVE_FOLDER); + if (approveDestNode instanceof NodeRef) + { + approveDestNodeRef = (NodeRef)approveDestNode; + } + else if (approveDestNode instanceof String) + { + approveDestNodeRef = new NodeRef((String)approveDestNode); + } + repoProps.put(SimpleWorkflowActionExecuter.PARAM_APPROVE_FOLDER, approveDestNodeRef); + + // determine whether we have a reject step or not + boolean requireReject = true; + String rejectStepPresent = (String)actionProps.get(PROP_REJECT_STEP_PRESENT); + if (rejectStepPresent != null && rejectStepPresent.equals("no")) + { + requireReject = false; + } + + if (requireReject) + { + // add the reject step name + repoProps.put(SimpleWorkflowActionExecuter.PARAM_REJECT_STEP, + (String)actionProps.get(PROP_REJECT_STEP_NAME)); + + // add whether the reject step will copy or move the content + boolean rejectMove = true; + String rejectAction = (String)actionProps.get(PROP_REJECT_ACTION); + if (rejectAction != null && rejectAction.equals("copy")) + { + rejectMove = false; + } + + repoProps.put(SimpleWorkflowActionExecuter.PARAM_REJECT_MOVE, Boolean.valueOf(rejectMove)); + + // add the destination folder of the content + NodeRef rejectDestNodeRef = null; + Object rejectDestNode = actionProps.get(PROP_REJECT_FOLDER); + if (rejectDestNode instanceof NodeRef) + { + rejectDestNodeRef = (NodeRef)rejectDestNode; + } + else if (rejectDestNode instanceof String) + { + rejectDestNodeRef = new NodeRef((String)rejectDestNode); + } + repoProps.put(SimpleWorkflowActionExecuter.PARAM_REJECT_FOLDER, rejectDestNodeRef); + } + } + + public void prepareForEdit(Map actionProps, + Map repoProps) + { + String approveStep = (String)repoProps.get(SimpleWorkflowActionExecuter.PARAM_APPROVE_STEP); + Boolean approveMove = (Boolean)repoProps.get(SimpleWorkflowActionExecuter.PARAM_APPROVE_MOVE); + NodeRef approveFolderNode = (NodeRef)repoProps.get( + SimpleWorkflowActionExecuter.PARAM_APPROVE_FOLDER); + + String rejectStep = (String)repoProps.get(SimpleWorkflowActionExecuter.PARAM_REJECT_STEP); + Boolean rejectMove = (Boolean)repoProps.get(SimpleWorkflowActionExecuter.PARAM_REJECT_MOVE); + NodeRef rejectFolderNode = (NodeRef)repoProps.get( + SimpleWorkflowActionExecuter.PARAM_REJECT_FOLDER); + + actionProps.put(PROP_APPROVE_STEP_NAME, approveStep); + actionProps.put(PROP_APPROVE_ACTION, approveMove ? "move" : "copy"); + actionProps.put(PROP_APPROVE_FOLDER, approveFolderNode); + + if (rejectStep == null && rejectMove == null && rejectFolderNode == null) + { + actionProps.put(PROP_REJECT_STEP_PRESENT, "no"); + actionProps.put(PROP_REJECT_ACTION, "move"); + } + else + { + actionProps.put(PROP_REJECT_STEP_PRESENT, "yes"); + actionProps.put(PROP_REJECT_STEP_NAME, rejectStep); + actionProps.put(PROP_REJECT_ACTION, rejectMove ? "move" : "copy"); + actionProps.put(PROP_REJECT_FOLDER, rejectFolderNode); + } + } + + public String generateSummary(FacesContext context, IWizardBean wizard, + Map actionProps) + { + NodeService nodeService = Repository.getServiceRegistry(context).getNodeService(); + + String approveStepName = (String)actionProps.get(PROP_APPROVE_STEP_NAME); + String approveAction = (String)actionProps.get(PROP_APPROVE_ACTION); + NodeRef approveFolder = (NodeRef)actionProps.get(PROP_APPROVE_FOLDER); + String approveFolderName = Repository.getNameForNode(nodeService, approveFolder); + String approveMsg = MessageFormat.format( + Application.getMessage(context, "action_simple_workflow"), + new Object[] {Application.getMessage(context, approveAction), + approveFolderName, approveStepName}); + + String rejectMsg = null; + String rejectStep = (String)actionProps.get(PROP_REJECT_STEP_PRESENT); + if (rejectStep != null && "yes".equals(rejectStep)) + { + String rejectStepName = (String)actionProps.get(PROP_REJECT_STEP_NAME); + String rejectAction = (String)actionProps.get(PROP_REJECT_ACTION); + NodeRef rejectFolder = (NodeRef)actionProps.get(PROP_REJECT_FOLDER); + String rejectFolderName = Repository.getNameForNode(nodeService, rejectFolder); + rejectMsg = MessageFormat.format( + Application.getMessage(context, "action_simple_workflow"), + new Object[] {Application.getMessage(context, rejectAction), + rejectFolderName, rejectStepName}); + } + + StringBuilder builder = new StringBuilder(approveMsg); + if (rejectMsg != null) + { + builder.append(" "); + builder.append(rejectMsg); + } + + return builder.toString(); + } +} diff --git a/source/java/org/alfresco/web/bean/actions/handlers/SpecialiseTypeHandler.java b/source/java/org/alfresco/web/bean/actions/handlers/SpecialiseTypeHandler.java new file mode 100644 index 0000000000..4e66c15091 --- /dev/null +++ b/source/java/org/alfresco/web/bean/actions/handlers/SpecialiseTypeHandler.java @@ -0,0 +1,63 @@ +package org.alfresco.web.bean.actions.handlers; + +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.Map; + +import javax.faces.context.FacesContext; +import javax.faces.model.SelectItem; + +import org.alfresco.repo.action.executer.SpecialiseTypeActionExecuter; +import org.alfresco.service.namespace.QName; +import org.alfresco.web.app.Application; +import org.alfresco.web.bean.actions.BaseActionWizard; +import org.alfresco.web.bean.wizard.IWizardBean; + +/** + * Action handler for the "specialise-type" action. + * + * @author gavinc + */ +public class SpecialiseTypeHandler extends BaseActionHandler +{ + public static final String PROP_OBJECT_TYPE = "objecttype"; + + public String getJSPPath() + { + return getJSPPath(SpecialiseTypeActionExecuter.NAME); + } + + public void prepareForSave(Map actionProps, + Map repoProps) + { + String objectType = (String)actionProps.get(PROP_OBJECT_TYPE); + repoProps.put(SpecialiseTypeActionExecuter.PARAM_TYPE_NAME, + QName.createQName(objectType)); + } + + public void prepareForEdit(Map actionProps, + Map repoProps) + { + QName specialiseType = (QName)repoProps.get(SpecialiseTypeActionExecuter.PARAM_TYPE_NAME); + actionProps.put(PROP_OBJECT_TYPE, specialiseType.toString()); + } + + public String generateSummary(FacesContext context, IWizardBean wizard, + Map actionProps) + { + String label = null; + String objectType = (String)actionProps.get(PROP_OBJECT_TYPE); + for (SelectItem item : ((BaseActionWizard)wizard).getObjectTypes()) + { + if (item.getValue().equals(objectType) == true) + { + label = item.getLabel(); + break; + } + } + + return MessageFormat.format(Application.getMessage(context, "action_specialise_type"), + new Object[] {label}); + } + +} diff --git a/source/java/org/alfresco/web/bean/actions/handlers/TransformHandler.java b/source/java/org/alfresco/web/bean/actions/handlers/TransformHandler.java new file mode 100644 index 0000000000..e4206ee717 --- /dev/null +++ b/source/java/org/alfresco/web/bean/actions/handlers/TransformHandler.java @@ -0,0 +1,85 @@ +package org.alfresco.web.bean.actions.handlers; + +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.Map; + +import javax.faces.context.FacesContext; +import javax.faces.model.SelectItem; + +import org.alfresco.model.ContentModel; +import org.alfresco.repo.action.executer.TransformActionExecuter; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.service.namespace.QName; +import org.alfresco.web.app.Application; +import org.alfresco.web.bean.actions.BaseActionWizard; +import org.alfresco.web.bean.repository.Repository; +import org.alfresco.web.bean.wizard.IWizardBean; + +/** + * Action handler for the "transform" action. + * + * @author gavinc + */ +public class TransformHandler extends BaseActionHandler +{ + protected static final String PROP_TRANSFORMER = "transformer"; + + public String getJSPPath() + { + return getJSPPath(TransformActionExecuter.NAME); + } + + public void prepareForSave(Map actionProps, + Map repoProps) + { + // add the transformer to use + repoProps.put(TransformActionExecuter.PARAM_MIME_TYPE, + actionProps.get(PROP_TRANSFORMER)); + + // add the destination space id to the action properties + NodeRef destNodeRef = (NodeRef)actionProps.get(PROP_DESTINATION); + repoProps.put(TransformActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef); + + // add the type and name of the association to create when the copy + // is performed + repoProps.put(TransformActionExecuter.PARAM_ASSOC_TYPE_QNAME, + ContentModel.ASSOC_CONTAINS); + repoProps.put(TransformActionExecuter.PARAM_ASSOC_QNAME, + QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy")); + } + + public void prepareForEdit(Map actionProps, + Map repoProps) + { + String transformer = (String)repoProps.get(TransformActionExecuter.PARAM_MIME_TYPE); + actionProps.put(PROP_TRANSFORMER, transformer); + + NodeRef destNodeRef = (NodeRef)repoProps.get(TransformActionExecuter.PARAM_DESTINATION_FOLDER); + actionProps.put(PROP_DESTINATION, destNodeRef); + } + + public String generateSummary(FacesContext context, IWizardBean wizard, + Map actionProps) + { + String label = null; + NodeRef space = (NodeRef)actionProps.get(PROP_DESTINATION); + String name = Repository.getNameForNode( + Repository.getServiceRegistry(context).getNodeService(), space); + String transformer = (String)actionProps.get(PROP_TRANSFORMER); + + // find the label used by looking through the SelectItem list + for (SelectItem item : ((BaseActionWizard)wizard).getTransformers()) + { + if (item.getValue().equals(transformer)) + { + label = item.getLabel(); + break; + } + } + + return MessageFormat.format(Application.getMessage(context, "action_transform"), + new Object[] {name, label}); + } +} diff --git a/source/java/org/alfresco/web/bean/actions/handlers/TransformImageHandler.java b/source/java/org/alfresco/web/bean/actions/handlers/TransformImageHandler.java new file mode 100644 index 0000000000..2bc2a42809 --- /dev/null +++ b/source/java/org/alfresco/web/bean/actions/handlers/TransformImageHandler.java @@ -0,0 +1,95 @@ +package org.alfresco.web.bean.actions.handlers; + +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.Map; + +import javax.faces.context.FacesContext; +import javax.faces.model.SelectItem; + +import org.alfresco.model.ContentModel; +import org.alfresco.repo.action.executer.ImageTransformActionExecuter; +import org.alfresco.repo.action.executer.TransformActionExecuter; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.service.namespace.QName; +import org.alfresco.web.app.Application; +import org.alfresco.web.bean.actions.BaseActionWizard; +import org.alfresco.web.bean.repository.Repository; +import org.alfresco.web.bean.wizard.IWizardBean; + +/** + * Action handler for the "transform-image" action. + * + * @author gavinc + */ +public class TransformImageHandler extends BaseActionHandler +{ + protected static final String PROP_IMAGE_TRANSFORMER = "imageTransformer"; + protected static final String PROP_TRANSFORM_OPTIONS = "transformOptions"; + + public String getJSPPath() + { + return getJSPPath(ImageTransformActionExecuter.NAME); + } + + public void prepareForSave(Map actionProps, + Map repoProps) + { + // add the transformer to use + repoProps.put(ImageTransformActionExecuter.PARAM_MIME_TYPE, + actionProps.get(PROP_IMAGE_TRANSFORMER)); + + // add the options + repoProps.put(ImageTransformActionExecuter.PARAM_CONVERT_COMMAND, + actionProps.get(PROP_TRANSFORM_OPTIONS)); + + // add the destination space id to the action properties + NodeRef destNodeRef = (NodeRef)actionProps.get(PROP_DESTINATION); + repoProps.put(ImageTransformActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef); + + // add the type and name of the association to create when the copy + // is performed + repoProps.put(TransformActionExecuter.PARAM_ASSOC_TYPE_QNAME, + ContentModel.ASSOC_CONTAINS); + repoProps.put(TransformActionExecuter.PARAM_ASSOC_QNAME, + QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy")); + } + + public void prepareForEdit(Map actionProps, + Map repoProps) + { + String transformer = (String)repoProps.get(TransformActionExecuter.PARAM_MIME_TYPE); + actionProps.put(PROP_IMAGE_TRANSFORMER, transformer); + + String options = (String)repoProps.get(ImageTransformActionExecuter.PARAM_CONVERT_COMMAND); + actionProps.put(PROP_TRANSFORM_OPTIONS, options != null ? options : ""); + + NodeRef destNodeRef = (NodeRef)repoProps.get(ImageTransformActionExecuter.PARAM_DESTINATION_FOLDER); + actionProps.put(PROP_DESTINATION, destNodeRef); + } + + public String generateSummary(FacesContext context, IWizardBean wizard, + Map actionProps) + { + String label = null; + NodeRef space = (NodeRef)actionProps.get(PROP_DESTINATION); + String name = Repository.getNameForNode( + Repository.getServiceRegistry(context).getNodeService(), space); + String transformer = (String)actionProps.get(PROP_IMAGE_TRANSFORMER); + String option = (String)actionProps.get(PROP_TRANSFORM_OPTIONS); + + // find the label used by looking through the SelectItem list + for (SelectItem item : ((BaseActionWizard)wizard).getImageTransformers()) + { + if (item.getValue().equals(transformer)) + { + label = item.getLabel(); + break; + } + } + + return MessageFormat.format(Application.getMessage(context, "action_transform_image"), + new Object[] {name, label, option}); + } +} diff --git a/source/java/org/alfresco/web/bean/rules/CreateRuleWizard.java b/source/java/org/alfresco/web/bean/rules/CreateRuleWizard.java index 2da95f2e0a..eb59e93ff3 100644 --- a/source/java/org/alfresco/web/bean/rules/CreateRuleWizard.java +++ b/source/java/org/alfresco/web/bean/rules/CreateRuleWizard.java @@ -1,7 +1,6 @@ package org.alfresco.web.bean.rules; import java.io.Serializable; -import java.text.MessageFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -16,25 +15,21 @@ import javax.faces.model.SelectItem; import org.alfresco.config.Config; import org.alfresco.config.ConfigElement; import org.alfresco.config.ConfigService; -import org.alfresco.model.ContentModel; -import org.alfresco.repo.action.evaluator.CompareMimeTypeEvaluator; -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.error.AlfrescoRuntimeException; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ActionCondition; import org.alfresco.service.cmr.action.ActionConditionDefinition; import org.alfresco.service.cmr.dictionary.TypeDefinition; -import org.alfresco.service.cmr.repository.NodeRef; 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.alfresco.web.app.Application; import org.alfresco.web.bean.actions.BaseActionWizard; +import org.alfresco.web.bean.actions.IHandler; import org.alfresco.web.bean.repository.Node; import org.alfresco.web.bean.repository.Repository; +import org.alfresco.web.bean.rules.handlers.BaseConditionHandler; import org.alfresco.web.data.IDataContainer; import org.alfresco.web.data.QuickSort; import org.alfresco.web.ui.common.Utils; @@ -48,9 +43,8 @@ import org.apache.commons.logging.LogFactory; */ public class CreateRuleWizard extends BaseActionWizard { - public static final String PROP_CONDITION_NAME = "conditionName"; - public static final String PROP_CONDITION_SUMMARY = "conditionSummary"; - public static final String PROP_CONDITION_NOT = "notcondition"; + protected static final String PROP_CONDITION_NAME = "conditionName"; + protected static final String PROP_CONDITION_SUMMARY = "conditionSummary"; protected RuleService ruleService; protected RulesBean rulesBean; @@ -60,6 +54,7 @@ public class CreateRuleWizard extends BaseActionWizard private List types; private List conditions; + protected Map conditionHandlers; protected Map currentConditionProperties; protected List> allConditionsProperties; @@ -73,8 +68,6 @@ public class CreateRuleWizard extends BaseActionWizard protected boolean applyToSubSpaces; protected boolean editingCondition; - protected static final String CONDITION_PAGES_LOCATION = "/jsp/rules/"; - private static final Log logger = LogFactory.getLog(CreateRuleWizard.class); // ------------------------------------------------------------------------------ @@ -94,6 +87,8 @@ public class CreateRuleWizard extends BaseActionWizard this.conditions = null; this.allConditionsProperties = new ArrayList>(); + + initialiseConditionHandlers(); } @Override @@ -488,29 +483,31 @@ public class CreateRuleWizard extends BaseActionWizard FacesContext context = FacesContext.getCurrentInstance(); this.returnViewId = context.getViewRoot().getViewId(); - String viewId = calculateConditionViewId(this.condition); + String viewId = null; HashMap condProps = new HashMap(3); condProps.put(PROP_CONDITION_NAME, this.condition); this.currentConditionProperties = condProps; - // determine whether the condition being added has any parameters - ActionConditionDefinition conditionDef = this.actionService. - getActionConditionDefinition(this.condition); - if (conditionDef.hasParameterDefinitions()) + // get the handler for the condition, if there isn't one we presume it + // is a no-parameter condition + IHandler handler = this.conditionHandlers.get(this.condition); + if (handler != null) { - // setup any defaults for the UI and override the viewId if necessary - String overridenViewId = setupUIDefaultsForCondition(condProps); - if (overridenViewId != null) - { - viewId = overridenViewId; - } + // setup any UI defaults the condition may have and get the location of + // the JSP used to collect the parameters + handler.setupUIDefaults(condProps); + viewId = handler.getJSPPath(); } else { - // just add the condition to the list and use the title as the summary + // just add the action to the list and use the title as the summary + ActionConditionDefinition conditionDef = this.actionService. + getActionConditionDefinition(this.condition); condProps.put(PROP_CONDITION_SUMMARY, conditionDef.getTitle()); - condProps.put(PROP_CONDITION_NOT, Boolean.FALSE); + condProps.put(BaseConditionHandler.PROP_CONDITION_NOT, Boolean.FALSE); + // add the no params marker so we can disable the edit action + condProps.put(NO_PARAMS_MARKER, "no-params"); this.allConditionsProperties.add(condProps); // come back to the same page we're on now as there are no params to collect @@ -543,8 +540,9 @@ public class CreateRuleWizard extends BaseActionWizard FacesContext context = FacesContext.getCurrentInstance(); this.returnViewId = context.getViewRoot().getViewId(); - // refresh the wizard - goToPage(context, calculateConditionViewId(this.condition)); + // go to the condition page (as there is an edit option visible, + // there must be a handler for the condition so we don't check) + goToPage(context, this.conditionHandlers.get(this.condition).getJSPPath()); } /** @@ -553,7 +551,11 @@ public class CreateRuleWizard extends BaseActionWizard public void addCondition() { FacesContext context = FacesContext.getCurrentInstance(); - String summary = buildConditionSummary(); + + // this is called from the actions page so there must be a handler + // present so there's no need to check for null + String summary = this.conditionHandlers.get(this.condition).generateSummary( + context, this, this.currentConditionProperties); if (summary != null) { @@ -654,8 +656,14 @@ public class CreateRuleWizard extends BaseActionWizard { String conditionName = (String)condParams.get(PROP_CONDITION_NAME); this.condition = conditionName; - this.currentConditionProperties = condParams; - Map repoCondParams = buildConditionParams(); + + // get the condition handler to prepare for the save + Map repoCondParams = new HashMap(); + IHandler handler = this.conditionHandlers.get(this.condition); + if (handler != null) + { + handler.prepareForSave(condParams, repoCondParams); + } // add the condition to the rule ActionCondition condition = this.actionService. @@ -663,7 +671,7 @@ public class CreateRuleWizard extends BaseActionWizard condition.setParameterValues(repoCondParams); // specify whether the condition result should be inverted - Boolean not = (Boolean)condParams.get(PROP_CONDITION_NOT); + Boolean not = (Boolean)condParams.get(BaseConditionHandler.PROP_CONDITION_NOT); condition.setInvertCondition(((Boolean)not).booleanValue()); rule.addActionCondition(condition); @@ -676,8 +684,14 @@ public class CreateRuleWizard extends BaseActionWizard // to setup the currentActionProperties and action variables String actionName = (String)actionParams.get(PROP_ACTION_NAME); this.action = actionName; - this.currentActionProperties = actionParams; - Map repoActionParams = buildActionParams(); + + // get the action handler to prepare for the save + Map repoActionParams = new HashMap(); + IHandler handler = this.actionHandlers.get(this.action); + if (handler != null) + { + handler.prepareForSave(actionParams, repoActionParams); + } // add the action to the rule Action action = this.actionService.createAction(actionName); @@ -689,170 +703,53 @@ public class CreateRuleWizard extends BaseActionWizard } /** - * 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 + * Initialises the condition handlers from the current configuration. */ - protected String setupUIDefaultsForCondition(HashMap props) + protected void initialiseConditionHandlers() { - // NOTE: none of the built in conditions have any defaults to setup - - return null; - } - - /** - * Builds the Map of properties for the given condition in the format the repo is expecting - * - * @return The Map the repo is expecting - */ - protected Map buildConditionParams() - { - Map repoParams = new HashMap(); - - if (ComparePropertyValueEvaluator.NAME.equals(this.condition)) + if (this.conditionHandlers == null) { - // add the text to compare - String text = (String)this.currentConditionProperties.get(PROP_CONTAINS_TEXT); - repoParams.put(ComparePropertyValueEvaluator.PARAM_VALUE, text); - } - else if (InCategoryEvaluator.NAME.equals(this.condition)) - { - // put the selected category in the condition params - NodeRef nodeRef = (NodeRef)this.currentConditionProperties.get(PROP_CATEGORY); - repoParams.put(InCategoryEvaluator.PARAM_CATEGORY_VALUE, nodeRef); - - // add the classifiable aspect - repoParams.put(InCategoryEvaluator.PARAM_CATEGORY_ASPECT, ContentModel.ASPECT_GEN_CLASSIFIABLE); - } - else if (IsSubTypeEvaluator.NAME.equals(this.condition)) - { - // add the model type - QName type = QName.createQName((String)this.currentConditionProperties.get(PROP_MODEL_TYPE)); - repoParams.put(IsSubTypeEvaluator.PARAM_TYPE, type); - } - else if (HasAspectEvaluator.NAME.equals(this.condition)) - { - // add the aspect - QName aspect = QName.createQName((String)this.currentConditionProperties.get(PROP_ASPECT)); - repoParams.put(HasAspectEvaluator.PARAM_ASPECT, aspect); - } - else if (CompareMimeTypeEvaluator.NAME.equals(this.condition)) - { - // add the mimetype - String mimeType = (String)this.currentConditionProperties.get(PROP_MIMETYPE); - repoParams.put(CompareMimeTypeEvaluator.PARAM_VALUE, mimeType); - } - - return repoParams; - } - - /** - * Returns a summary string for the current condition - * - * @return The summary or null if a summary could not be built - */ - protected String buildConditionSummary() - { - String summary = null; - FacesContext context = FacesContext.getCurrentInstance(); - Boolean not = (Boolean)this.currentConditionProperties.get(PROP_CONDITION_NOT); - - if (ComparePropertyValueEvaluator.NAME.equals(this.condition)) - { - String msgId = not.booleanValue() ? - "condition_compare_property_value_not" : "condition_compare_property_value"; - - String text = (String)this.currentConditionProperties.get(PROP_CONTAINS_TEXT); - - summary = MessageFormat.format(Application.getMessage(context, msgId), - new Object[] {text}); - } - else if (InCategoryEvaluator.NAME.equals(this.condition)) - { - String msgId = not.booleanValue() ? "condition_in_category_not" : "condition_in_category"; - - String name = Repository.getNameForNode(this.nodeService, - (NodeRef)this.currentConditionProperties.get(PROP_CATEGORY)); - - summary = MessageFormat.format(Application.getMessage(context, msgId), - new Object[] {name}); - } - else if (IsSubTypeEvaluator.NAME.equals(this.condition)) - { - String msgId = not.booleanValue() ? "condition_is_subtype_not" : "condition_is_subtype"; - - String label = null; - String typeName = (String)this.currentConditionProperties.get(PROP_MODEL_TYPE); - for (SelectItem item : this.getModelTypes()) + ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance()); + Config wizardCfg = svc.getConfig("Action Wizards"); + if (wizardCfg != null) { - if (item.getValue().equals(typeName)) + ConfigElement conditionHandlerCfg = wizardCfg.getConfigElement("condition-handlers"); + if (conditionHandlerCfg != null) { - label = item.getLabel(); - break; + this.conditionHandlers = new HashMap(20); + + // instantiate each handler and store in the map + for (ConfigElement child : conditionHandlerCfg.getChildren()) + { + String conditionName = child.getAttribute("name"); + String handlerClass = child.getAttribute("class"); + + if (conditionName != null && conditionName.length() > 0 && + handlerClass != null && handlerClass.length() > 0) + { + try + { + Class klass = Class.forName(handlerClass); + IHandler handler = (IHandler)klass.newInstance(); + this.conditionHandlers.put(conditionName, handler); + } + catch (Exception e) + { + throw new AlfrescoRuntimeException("Failed to setup condition handler for '" + + conditionName + "'", e); + } + } + } + } + else + { + logger.warn("Could not find 'condition-handlers' configuration element"); } } - - summary = MessageFormat.format(Application.getMessage(context, msgId), - new Object[] {label}); - } - else if (HasAspectEvaluator.NAME.equals(this.condition)) - { - String msgId = not.booleanValue() ? "condition_has_aspect_not" : "condition_has_aspect"; - - String label = null; - String aspectName = (String)this.currentConditionProperties.get(PROP_ASPECT); - for (SelectItem item : this.getAspects()) + else { - if (item.getValue().equals(aspectName)) - { - label = item.getLabel(); - break; - } + logger.warn("Could not find 'Action Wizards' configuration section"); } - - summary = MessageFormat.format(Application.getMessage(context, msgId), - new Object[] {label}); } - else if (CompareMimeTypeEvaluator.NAME.equals(this.condition)) - { - String msgId = not.booleanValue() ? "condition_compare_mime_type_not" : "condition_compare_mime_type"; - - String label = null; - String mimetype = (String)this.currentConditionProperties.get(PROP_MIMETYPE); - for (SelectItem item : this.getMimeTypes()) - { - if (item.getValue().equals(mimetype)) - { - label = item.getLabel(); - break; - } - } - - summary = MessageFormat.format(Application.getMessage(context, msgId), - new Object[] {label}); - } - else - { - // as the default case (i.e. for conditions with no parameters) use the title - ActionConditionDefinition conditionDef = this.actionService. - getActionConditionDefinition(this.condition); - summary = conditionDef.getTitle(); - } - - return summary; - } - - /** - * Calculates the viewId for the given condition id - * - * @param conditionId The id of the condition to generate the view id for - * @return The view id - */ - protected String calculateConditionViewId(String conditionId) - { - return CONDITION_PAGES_LOCATION + conditionId + ".jsp"; } } diff --git a/source/java/org/alfresco/web/bean/rules/EditRuleWizard.java b/source/java/org/alfresco/web/bean/rules/EditRuleWizard.java index 2f066d1fd0..437d44063b 100644 --- a/source/java/org/alfresco/web/bean/rules/EditRuleWizard.java +++ b/source/java/org/alfresco/web/bean/rules/EditRuleWizard.java @@ -8,31 +8,14 @@ import java.util.Map; import javax.faces.context.FacesContext; import org.alfresco.error.AlfrescoRuntimeException; -import org.alfresco.repo.action.evaluator.CompareMimeTypeEvaluator; -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.AddFeaturesActionExecuter; -import org.alfresco.repo.action.executer.CheckInActionExecuter; -import org.alfresco.repo.action.executer.CheckOutActionExecuter; -import org.alfresco.repo.action.executer.CopyActionExecuter; -import org.alfresco.repo.action.executer.ImageTransformActionExecuter; -import org.alfresco.repo.action.executer.ImporterActionExecuter; -import org.alfresco.repo.action.executer.LinkCategoryActionExecuter; -import org.alfresco.repo.action.executer.MailActionExecuter; -import org.alfresco.repo.action.executer.MoveActionExecuter; -import org.alfresco.repo.action.executer.RemoveFeaturesActionExecuter; -import org.alfresco.repo.action.executer.ScriptActionExecutor; -import org.alfresco.repo.action.executer.SimpleWorkflowActionExecuter; -import org.alfresco.repo.action.executer.SpecialiseTypeActionExecuter; -import org.alfresco.repo.action.executer.TransformActionExecuter; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ActionCondition; -import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.action.ActionConditionDefinition; +import org.alfresco.service.cmr.action.ActionDefinition; import org.alfresco.service.cmr.rule.Rule; -import org.alfresco.service.namespace.QName; +import org.alfresco.web.bean.actions.IHandler; import org.alfresco.web.bean.repository.Node; +import org.alfresco.web.bean.rules.handlers.BaseConditionHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -69,20 +52,39 @@ public class EditRuleWizard extends CreateRuleWizard this.applyToSubSpaces = rule.isAppliedToChildren(); this.runInBackground = rule.getExecuteAsychronously(); + FacesContext context = FacesContext.getCurrentInstance(); + // populate the conditions list with maps of properties representing each condition List conditions = rule.getActionConditions(); for (ActionCondition condition : conditions) { 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, + this.currentConditionProperties.put(BaseConditionHandler.PROP_CONDITION_NOT, Boolean.valueOf(condition.getInvertCondition())); - this.currentConditionProperties.put(PROP_CONDITION_SUMMARY, buildConditionSummary()); - + + IHandler handler = this.conditionHandlers.get(this.condition); + if (handler != null) + { + // use the handler to populate the properties and summary + handler.prepareForEdit(this.currentConditionProperties, + condition.getParameterValues()); + this.currentConditionProperties.put(PROP_CONDITION_SUMMARY, + handler.generateSummary(context, this, this.currentConditionProperties)); + } + else + { + // there's no handler, so we presume it is a no-paramter + // condition, use the condition title as the summary + ActionConditionDefinition conditionDef = this.actionService. + getActionConditionDefinition(this.condition); + this.currentConditionProperties.put(PROP_CONDITION_SUMMARY, + conditionDef.getTitle()); + // add the no params marker so we can disable the edit action + this.currentConditionProperties.put(NO_PARAMS_MARKER, "no-params"); + } + // add the populated currentConditionProperties to the list this.allConditionsProperties.add(this.currentConditionProperties); } @@ -93,11 +95,25 @@ public class EditRuleWizard extends CreateRuleWizard { 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); - this.currentActionProperties.put(PROP_ACTION_SUMMARY, buildActionSummary()); + + IHandler handler = this.actionHandlers.get(this.action); + if (handler != null) + { + // use the handler to populate the properties and summary + handler.prepareForEdit(this.currentActionProperties, action.getParameterValues()); + this.currentActionProperties.put(PROP_ACTION_SUMMARY, + handler.generateSummary(context, this, this.currentActionProperties)); + } + else + { + // there's no handler, so we presume it is a no-paramter + // action, use the action title as the summary + ActionDefinition actionDef = this.actionService.getActionDefinition(this.action); + this.currentActionProperties.put(PROP_ACTION_SUMMARY, actionDef.getTitle()); + // add the no params marker so we can disable the edit action + this.currentActionProperties.put(NO_PARAMS_MARKER, "no-params"); + } // add the populated currentActionProperties to the list this.allActionsProperties.add(this.currentActionProperties); @@ -151,183 +167,5 @@ public class EditRuleWizard extends CreateRuleWizard // ------------------------------------------------------------------------------ // Helper methods - - /** - * Populates a Map of properties the wizard is expecting for the given condition - * - * @param condition The condition to build the map for - */ - protected void populateCondition(Map conditionProps) - { - if (ComparePropertyValueEvaluator.NAME.equals(this.condition)) - { - String propValue = (String)conditionProps.get(ComparePropertyValueEvaluator.PARAM_VALUE); - this.currentConditionProperties.put(PROP_CONTAINS_TEXT, propValue); - } - else if (InCategoryEvaluator.NAME.equals(this.condition)) - { - NodeRef catNodeRef = (NodeRef)conditionProps.get(InCategoryEvaluator.PARAM_CATEGORY_VALUE); - this.currentConditionProperties.put(PROP_CATEGORY, catNodeRef); - } - else if (IsSubTypeEvaluator.NAME.equals(this.condition)) - { - QName type = (QName)conditionProps.get(IsSubTypeEvaluator.PARAM_TYPE); - this.currentConditionProperties.put(PROP_MODEL_TYPE, type.toString()); - } - else if (HasAspectEvaluator.NAME.equals(this.condition)) - { - QName aspect = (QName)conditionProps.get(HasAspectEvaluator.PARAM_ASPECT); - this.currentConditionProperties.put(PROP_ASPECT, aspect.toString()); - } - else if (CompareMimeTypeEvaluator.NAME.equals(this.condition)) - { - String mimeType = (String)conditionProps.get(CompareMimeTypeEvaluator.PARAM_VALUE); - this.currentConditionProperties.put(PROP_MIMETYPE, mimeType); - } - } - - /** - * Populate the actionProperties member variable with correct props for the current action - * using the supplied property map. - * - * @param actionProps Map to retrieve props appropriate to the current action from - */ - protected void populateAction(Map actionProps) - { - if (AddFeaturesActionExecuter.NAME.equals(this.action)) - { - QName aspect = (QName)actionProps.get(AddFeaturesActionExecuter.PARAM_ASPECT_NAME); - this.currentActionProperties.put(PROP_ASPECT, aspect.toString()); - } - else if (RemoveFeaturesActionExecuter.NAME.equals(this.action)) - { - QName aspect = (QName)actionProps.get(RemoveFeaturesActionExecuter.PARAM_ASPECT_NAME); - this.currentActionProperties.put(PROP_ASPECT, aspect.toString()); - } - else if (CopyActionExecuter.NAME.equals(this.action)) - { - NodeRef destNodeRef = (NodeRef)actionProps.get(CopyActionExecuter.PARAM_DESTINATION_FOLDER); - this.currentActionProperties.put(PROP_DESTINATION, destNodeRef); - } - else if (MoveActionExecuter.NAME.equals(this.action)) - { - NodeRef destNodeRef = (NodeRef)actionProps.get(MoveActionExecuter.PARAM_DESTINATION_FOLDER); - this.currentActionProperties.put(PROP_DESTINATION, destNodeRef); - } - else if (SimpleWorkflowActionExecuter.NAME.equals(this.action)) - { - String approveStep = (String)actionProps.get(SimpleWorkflowActionExecuter.PARAM_APPROVE_STEP); - Boolean approveMove = (Boolean)actionProps.get(SimpleWorkflowActionExecuter.PARAM_APPROVE_MOVE); - NodeRef approveFolderNode = (NodeRef)actionProps.get( - SimpleWorkflowActionExecuter.PARAM_APPROVE_FOLDER); - - String rejectStep = (String)actionProps.get(SimpleWorkflowActionExecuter.PARAM_REJECT_STEP); - Boolean rejectMove = (Boolean)actionProps.get(SimpleWorkflowActionExecuter.PARAM_REJECT_MOVE); - NodeRef rejectFolderNode = (NodeRef)actionProps.get( - SimpleWorkflowActionExecuter.PARAM_REJECT_FOLDER); - - this.currentActionProperties.put(PROP_APPROVE_STEP_NAME, approveStep); - this.currentActionProperties.put(PROP_APPROVE_ACTION, approveMove ? "move" : "copy"); - this.currentActionProperties.put(PROP_APPROVE_FOLDER, approveFolderNode); - - if (rejectStep == null && rejectMove == null && rejectFolderNode == null) - { - this.currentActionProperties.put(PROP_REJECT_STEP_PRESENT, "no"); - } - else - { - this.currentActionProperties.put(PROP_REJECT_STEP_PRESENT, "yes"); - this.currentActionProperties.put(PROP_REJECT_STEP_NAME, rejectStep); - this.currentActionProperties.put(PROP_REJECT_ACTION, rejectMove ? "move" : "copy"); - this.currentActionProperties.put(PROP_REJECT_FOLDER, rejectFolderNode); - } - } - else if (LinkCategoryActionExecuter.NAME.equals(this.action)) - { - NodeRef catNodeRef = (NodeRef)actionProps.get(LinkCategoryActionExecuter.PARAM_CATEGORY_VALUE); - this.currentActionProperties.put(PROP_CATEGORY, catNodeRef); - } - else if (CheckOutActionExecuter.NAME.equals(this.action)) - { - NodeRef destNodeRef = (NodeRef)actionProps.get(CheckOutActionExecuter.PARAM_DESTINATION_FOLDER); - this.currentActionProperties.put(PROP_DESTINATION, destNodeRef); - } - else if (CheckInActionExecuter.NAME.equals(this.action)) - { - String checkDesc = (String)actionProps.get(CheckInActionExecuter.PARAM_DESCRIPTION); - this.currentActionProperties.put(PROP_CHECKIN_DESC, checkDesc); - - Boolean minorChange = (Boolean)actionProps.get(CheckInActionExecuter.PARAM_MINOR_CHANGE); - this.currentActionProperties.put(PROP_CHECKIN_MINOR, minorChange); - } - else if (TransformActionExecuter.NAME.equals(this.action)) - { - String transformer = (String)actionProps.get(TransformActionExecuter.PARAM_MIME_TYPE); - this.currentActionProperties.put(PROP_TRANSFORMER, transformer); - - NodeRef destNodeRef = (NodeRef)actionProps.get(CopyActionExecuter.PARAM_DESTINATION_FOLDER); - this.currentActionProperties.put(PROP_DESTINATION, destNodeRef); - } - else if (ImageTransformActionExecuter.NAME.equals(this.action)) - { - String transformer = (String)actionProps.get(TransformActionExecuter.PARAM_MIME_TYPE); - this.currentActionProperties.put(PROP_IMAGE_TRANSFORMER, transformer); - - String options = (String)actionProps.get(ImageTransformActionExecuter.PARAM_CONVERT_COMMAND); - this.currentActionProperties.put(PROP_TRANSFORM_OPTIONS, options != null ? options : ""); - - NodeRef destNodeRef = (NodeRef)actionProps.get(CopyActionExecuter.PARAM_DESTINATION_FOLDER); - this.currentActionProperties.put(PROP_DESTINATION, destNodeRef); - } - else if (MailActionExecuter.NAME.equals(this.action)) - { - String subject = (String)actionProps.get(MailActionExecuter.PARAM_SUBJECT); - this.currentActionProperties.put(PROP_SUBJECT, subject); - - String message = (String)actionProps.get(MailActionExecuter.PARAM_TEXT); - this.currentActionProperties.put(PROP_MESSAGE, message); - - // handle single email or multiple authority recipients - String to = (String)actionProps.get(MailActionExecuter.PARAM_TO); - if (to != null) - { - this.currentActionProperties.put(PROP_TO, to); - } - else - { - List recipients = (List)actionProps.get(MailActionExecuter.PARAM_TO_MANY); - if (recipients != null && recipients.size() != 0) - { - // rebuild the list of RecipientWrapper objects from the stored action - for (String authority : recipients) - { - this.emailRecipients.add( - new RecipientWrapper(displayLabelForAuthority(authority), authority)); - } - } - } - - NodeRef templateRef = (NodeRef)actionProps.get(MailActionExecuter.PARAM_TEMPLATE); - if (templateRef != null) - { - this.currentActionProperties.put(PROP_TEMPLATE, templateRef.getId()); - this.usingTemplate = templateRef.getId(); - } - } - else if (ImporterActionExecuter.NAME.equals(this.action)) - { - NodeRef destNodeRef = (NodeRef)actionProps.get(ImporterActionExecuter.PARAM_DESTINATION_FOLDER); - this.currentActionProperties.put(PROP_DESTINATION, destNodeRef); - } - else if (SpecialiseTypeActionExecuter.NAME.equals(this.action)) - { - QName specialiseType = (QName)actionProps.get(SpecialiseTypeActionExecuter.PARAM_TYPE_NAME); - this.currentActionProperties.put(PROP_OBJECT_TYPE, specialiseType.toString()); - } - else if (ScriptActionExecutor.NAME.equals(this.action)) - { - NodeRef scriptRef = (NodeRef)actionProps.get(ScriptActionExecutor.PARAM_SCRIPTREF); - this.currentActionProperties.put(PROP_SCRIPT, scriptRef.getId()); - } - } + } diff --git a/source/java/org/alfresco/web/bean/rules/handlers/BaseConditionHandler.java b/source/java/org/alfresco/web/bean/rules/handlers/BaseConditionHandler.java new file mode 100644 index 0000000000..40e16c6e12 --- /dev/null +++ b/source/java/org/alfresco/web/bean/rules/handlers/BaseConditionHandler.java @@ -0,0 +1,34 @@ +package org.alfresco.web.bean.rules.handlers; + +import java.io.Serializable; +import java.util.Map; + +import org.alfresco.web.bean.actions.IHandler; + +/** + * Base class for all condition handler implementations. + * + * @author gavinc + */ +public abstract class BaseConditionHandler implements IHandler +{ + protected static final String CONDITION_PAGES_LOCATION = "/jsp/rules/"; + public static final String PROP_CONDITION_NOT = "notcondition"; + + public void setupUIDefaults(Map conditionProps) + { + // do nothing by default, only those condition handlers that need + // to setup defaults need override this method + } + + /** + * Given the condition name, generates the default path for the JSP + * + * @param conditionName The name of the condition + * @return The path to the JSP used for the condition + */ + protected String getJSPPath(String conditionName) + { + return CONDITION_PAGES_LOCATION + conditionName + ".jsp"; + } +} diff --git a/source/java/org/alfresco/web/bean/rules/handlers/CompareMimeTypeHandler.java b/source/java/org/alfresco/web/bean/rules/handlers/CompareMimeTypeHandler.java new file mode 100644 index 0000000000..ad26c1ee7b --- /dev/null +++ b/source/java/org/alfresco/web/bean/rules/handlers/CompareMimeTypeHandler.java @@ -0,0 +1,63 @@ +package org.alfresco.web.bean.rules.handlers; + +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.Map; + +import javax.faces.context.FacesContext; +import javax.faces.model.SelectItem; + +import org.alfresco.repo.action.evaluator.CompareMimeTypeEvaluator; +import org.alfresco.web.app.Application; +import org.alfresco.web.bean.rules.CreateRuleWizard; +import org.alfresco.web.bean.wizard.IWizardBean; + +/** + * Condition handler for the "compare-mime-type" condition + * + * @author gavinc + */ +public class CompareMimeTypeHandler extends BaseConditionHandler +{ + protected static final String PROP_MIMETYPE = "mimetype"; + + public String getJSPPath() + { + return getJSPPath(CompareMimeTypeEvaluator.NAME); + } + + public void prepareForSave(Map conditionProps, + Map repoProps) + { + String mimeType = (String)conditionProps.get(PROP_MIMETYPE); + repoProps.put(CompareMimeTypeEvaluator.PARAM_VALUE, mimeType); + } + + public void prepareForEdit(Map conditionProps, + Map repoProps) + { + String mimeType = (String)repoProps.get(CompareMimeTypeEvaluator.PARAM_VALUE); + conditionProps.put(PROP_MIMETYPE, mimeType); + } + + public String generateSummary(FacesContext context, IWizardBean wizard, + Map conditionProps) + { + Boolean not = (Boolean)conditionProps.get(PROP_CONDITION_NOT); + String msgId = not.booleanValue() ? "condition_compare_mime_type_not" : "condition_compare_mime_type"; + + String label = null; + String mimetype = (String)conditionProps.get(PROP_MIMETYPE); + for (SelectItem item : ((CreateRuleWizard)wizard).getMimeTypes()) + { + if (item.getValue().equals(mimetype)) + { + label = item.getLabel(); + break; + } + } + + return MessageFormat.format(Application.getMessage(context, msgId), + new Object[] {label}); + } +} diff --git a/source/java/org/alfresco/web/bean/rules/handlers/HasAspectHandler.java b/source/java/org/alfresco/web/bean/rules/handlers/HasAspectHandler.java new file mode 100644 index 0000000000..5510ec6316 --- /dev/null +++ b/source/java/org/alfresco/web/bean/rules/handlers/HasAspectHandler.java @@ -0,0 +1,64 @@ +package org.alfresco.web.bean.rules.handlers; + +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.Map; + +import javax.faces.context.FacesContext; +import javax.faces.model.SelectItem; + +import org.alfresco.repo.action.evaluator.HasAspectEvaluator; +import org.alfresco.service.namespace.QName; +import org.alfresco.web.app.Application; +import org.alfresco.web.bean.rules.CreateRuleWizard; +import org.alfresco.web.bean.wizard.IWizardBean; + +/** + * Condition handler for the "has-aspect" condition. + * + * @author gavinc + */ +public class HasAspectHandler extends BaseConditionHandler +{ + protected static final String PROP_ASPECT = "aspect"; + + public String getJSPPath() + { + return getJSPPath(HasAspectEvaluator.NAME); + } + + public void prepareForSave(Map conditionProps, + Map repoProps) + { + QName aspect = QName.createQName((String)conditionProps.get(PROP_ASPECT)); + repoProps.put(HasAspectEvaluator.PARAM_ASPECT, aspect); + } + + public void prepareForEdit(Map conditionProps, + Map repoProps) + { + QName aspect = (QName)repoProps.get(HasAspectEvaluator.PARAM_ASPECT); + conditionProps.put(PROP_ASPECT, aspect.toString()); + } + + public String generateSummary(FacesContext context, IWizardBean wizard, + Map conditionProps) + { + Boolean not = (Boolean)conditionProps.get(PROP_CONDITION_NOT); + String msgId = not.booleanValue() ? "condition_has_aspect_not" : "condition_has_aspect"; + + String label = null; + String aspectName = (String)conditionProps.get(PROP_ASPECT); + for (SelectItem item : ((CreateRuleWizard)wizard).getAspects()) + { + if (item.getValue().equals(aspectName)) + { + label = item.getLabel(); + break; + } + } + + return MessageFormat.format(Application.getMessage(context, msgId), + new Object[] {label}); + } +} diff --git a/source/java/org/alfresco/web/bean/rules/handlers/InCategoryHandler.java b/source/java/org/alfresco/web/bean/rules/handlers/InCategoryHandler.java new file mode 100644 index 0000000000..1372b4e9fa --- /dev/null +++ b/source/java/org/alfresco/web/bean/rules/handlers/InCategoryHandler.java @@ -0,0 +1,61 @@ +package org.alfresco.web.bean.rules.handlers; + +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.Map; + +import javax.faces.context.FacesContext; + +import org.alfresco.model.ContentModel; +import org.alfresco.repo.action.evaluator.InCategoryEvaluator; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.web.app.Application; +import org.alfresco.web.bean.repository.Repository; +import org.alfresco.web.bean.wizard.IWizardBean; + +/** + * Condition handler for the "in-category" condition. + * + * @author gavinc + */ +public class InCategoryHandler extends BaseConditionHandler +{ + protected static final String PROP_CATEGORY = "category"; + + public String getJSPPath() + { + return getJSPPath(InCategoryEvaluator.NAME); + } + + public void prepareForSave(Map conditionProps, + Map repoProps) + { + // put the selected category in the condition params + NodeRef nodeRef = (NodeRef)conditionProps.get(PROP_CATEGORY); + repoProps.put(InCategoryEvaluator.PARAM_CATEGORY_VALUE, nodeRef); + + // add the classifiable aspect + repoProps.put(InCategoryEvaluator.PARAM_CATEGORY_ASPECT, + ContentModel.ASPECT_GEN_CLASSIFIABLE); + } + + public void prepareForEdit(Map conditionProps, + Map repoProps) + { + NodeRef catNodeRef = (NodeRef)repoProps.get(InCategoryEvaluator.PARAM_CATEGORY_VALUE); + conditionProps.put(PROP_CATEGORY, catNodeRef); + } + + public String generateSummary(FacesContext context, IWizardBean wizard, + Map conditionProps) + { + Boolean not = (Boolean)conditionProps.get(PROP_CONDITION_NOT); + String msgId = not.booleanValue() ? "condition_in_category_not" : "condition_in_category"; + + String name = Repository.getNameForNode(Repository.getServiceRegistry(context). + getNodeService(), (NodeRef)conditionProps.get(PROP_CATEGORY)); + + return MessageFormat.format(Application.getMessage(context, msgId), + new Object[] {name}); + } +} diff --git a/source/java/org/alfresco/web/bean/rules/handlers/IsSubTypeHandler.java b/source/java/org/alfresco/web/bean/rules/handlers/IsSubTypeHandler.java new file mode 100644 index 0000000000..0f5a3fef8c --- /dev/null +++ b/source/java/org/alfresco/web/bean/rules/handlers/IsSubTypeHandler.java @@ -0,0 +1,64 @@ +package org.alfresco.web.bean.rules.handlers; + +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.Map; + +import javax.faces.context.FacesContext; +import javax.faces.model.SelectItem; + +import org.alfresco.repo.action.evaluator.IsSubTypeEvaluator; +import org.alfresco.service.namespace.QName; +import org.alfresco.web.app.Application; +import org.alfresco.web.bean.rules.CreateRuleWizard; +import org.alfresco.web.bean.wizard.IWizardBean; + +/** + * Condition handler to the "is-subtype" condition. + * + * @author gavinc + */ +public class IsSubTypeHandler extends BaseConditionHandler +{ + protected static final String PROP_MODEL_TYPE = "modeltype"; + + public String getJSPPath() + { + return getJSPPath(IsSubTypeEvaluator.NAME); + } + + public void prepareForSave(Map conditionProps, + Map repoProps) + { + QName type = QName.createQName((String)conditionProps.get(PROP_MODEL_TYPE)); + repoProps.put(IsSubTypeEvaluator.PARAM_TYPE, type); + } + + public void prepareForEdit(Map conditionProps, + Map repoProps) + { + QName type = (QName)repoProps.get(IsSubTypeEvaluator.PARAM_TYPE); + conditionProps.put(PROP_MODEL_TYPE, type.toString()); + } + + public String generateSummary(FacesContext context, IWizardBean wizard, + Map conditionProps) + { + Boolean not = (Boolean)conditionProps.get(PROP_CONDITION_NOT); + String msgId = not.booleanValue() ? "condition_is_subtype_not" : "condition_is_subtype"; + + String label = null; + String typeName = (String)conditionProps.get(PROP_MODEL_TYPE); + for (SelectItem item : ((CreateRuleWizard)wizard).getModelTypes()) + { + if (item.getValue().equals(typeName)) + { + label = item.getLabel(); + break; + } + } + + return MessageFormat.format(Application.getMessage(context, msgId), + new Object[] {label}); + } +} diff --git a/source/java/org/alfresco/web/bean/rules/handlers/PropertyValueHandler.java b/source/java/org/alfresco/web/bean/rules/handlers/PropertyValueHandler.java new file mode 100644 index 0000000000..788d2f9263 --- /dev/null +++ b/source/java/org/alfresco/web/bean/rules/handlers/PropertyValueHandler.java @@ -0,0 +1,53 @@ +package org.alfresco.web.bean.rules.handlers; + +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.Map; + +import javax.faces.context.FacesContext; + +import org.alfresco.repo.action.evaluator.ComparePropertyValueEvaluator; +import org.alfresco.web.app.Application; +import org.alfresco.web.bean.wizard.IWizardBean; + +/** + * Condition handler for the "compare-property-value" condition. + * + * @author gavinc + */ +public class PropertyValueHandler extends BaseConditionHandler +{ + public static final String PROP_CONTAINS_TEXT = "containstext"; + + public String getJSPPath() + { + return getJSPPath(ComparePropertyValueEvaluator.NAME); + } + + public void prepareForSave(Map conditionProps, + Map repoProps) + { + String text = (String)conditionProps.get(PROP_CONTAINS_TEXT); + repoProps.put(ComparePropertyValueEvaluator.PARAM_VALUE, text); + } + + public void prepareForEdit(Map conditionProps, + Map repoProps) + { + String propValue = (String)repoProps.get(ComparePropertyValueEvaluator.PARAM_VALUE); + conditionProps.put(PROP_CONTAINS_TEXT, propValue); + } + + public String generateSummary(FacesContext context, IWizardBean wizard, + Map conditionProps) + { + Boolean not = (Boolean)conditionProps.get(PROP_CONDITION_NOT); + String msgId = not.booleanValue() ? + "condition_compare_property_value_not" : "condition_compare_property_value"; + + String text = (String)conditionProps.get(PROP_CONTAINS_TEXT); + + return MessageFormat.format(Application.getMessage(context, msgId), + new Object[] {text}); + } +} diff --git a/source/web/jsp/actions/actions.jsp b/source/web/jsp/actions/actions.jsp index 4e483d7cf4..529b0ff82b 100644 --- a/source/web/jsp/actions/actions.jsp +++ b/source/web/jsp/actions/actions.jsp @@ -111,14 +111,14 @@ - + + value="#{msg.change}" showLink="false" rendered='#{row.noParamsMarker == null}' /> diff --git a/source/web/jsp/rules/conditions.jsp b/source/web/jsp/rules/conditions.jsp index ac26fcd9ac..407a14d1fd 100644 --- a/source/web/jsp/rules/conditions.jsp +++ b/source/web/jsp/rules/conditions.jsp @@ -111,14 +111,13 @@ - + + value="#{msg.change}" showLink="false" rendered='#{row.noParamsMarker == null}' />