Merged up to HEAD.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3129 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-06-16 19:18:30 +00:00
parent 77df6eb45d
commit d2f8666983
39 changed files with 2129 additions and 1142 deletions

View File

@@ -186,28 +186,50 @@ public class BrowseBean implements IContextListener
FacesContext fc = FacesContext.getCurrentInstance();
fc.getApplication().getNavigationHandler().handleNavigation(fc, null, "dashboard");
}
else
{
navigateBrowseScreen();
}
}
/**
* @return Returns the browsePageSize.
*/
public int getBrowsePageSize()
public int getPageSizeContent()
{
return this.browsePageSize;
return this.pageSizeContent;
}
/**
* @param browsePageSize The browsePageSize to set.
*/
public void setBrowsePageSize(int browsePageSize)
public void setPageSizeContent(int pageSizeContent)
{
this.browsePageSize = browsePageSize;
this.pageSizeContent = pageSizeContent;
this.pageSizeContentStr = Integer.toString(pageSizeContent);
}
public int getPageSizeSpaces()
{
return this.pageSizeSpaces;
}
public void setPageSizeSpaces(int pageSizeSpaces)
{
this.pageSizeSpaces = pageSizeSpaces;
this.pageSizeSpacesStr = Integer.toString(pageSizeSpaces);
}
public String getPageSizeContentStr()
{
return this.pageSizeContentStr;
}
public void setPageSizeContentStr(String pageSizeContentStr)
{
this.pageSizeContentStr = pageSizeContentStr;
}
public String getPageSizeSpacesStr()
{
return this.pageSizeSpacesStr;
}
public void setPageSizeSpacesStr(String pageSizeSpacesStr)
{
this.pageSizeSpacesStr = pageSizeSpacesStr;
}
/**
* @return Returns the minimum length of a valid search string.
*/
@@ -483,20 +505,19 @@ public class BrowseBean implements IContextListener
if (VIEWMODE_DASHBOARD.equals(viewMode) == false)
{
// set the page size based on the style of display
setBrowsePageSize(this.viewsConfig.getDefaultPageSize(PAGE_NAME_BROWSE,
viewMode));
int pageSize = this.viewsConfig.getDefaultPageSize(PAGE_NAME_BROWSE, viewMode);
setPageSizeContent(pageSize);
setPageSizeSpaces(pageSize);
if (logger.isDebugEnabled())
logger.debug("Browse view page size set to: " + getBrowsePageSize());
logger.debug("Browse view page size set to: " + pageSize);
// in case we left for dashboard
if (isDashboardView() == true)
{
setDashboardView(false);
}
setDashboardView(false);
// push the view mode into the lists
setBrowseViewMode(viewMode);
navigateBrowseScreen();
}
else
{
@@ -565,7 +586,7 @@ public class BrowseBean implements IContextListener
this.dictionaryService.isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false)
{
// create our Node representation
node = new MapNode(nodeRef, this.nodeService, false);
node = new MapNode(nodeRef, this.nodeService, true);
node.addPropertyResolver("icon", this.resolverSpaceIcon);
node.addPropertyResolver("smallIcon", this.resolverSmallIcon);
@@ -575,7 +596,7 @@ public class BrowseBean implements IContextListener
else if (this.dictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT))
{
// create our Node representation
node = new MapNode(nodeRef, this.nodeService, false);
node = new MapNode(nodeRef, this.nodeService, true);
setupCommonBindingProperties(node);
this.contentNodes.add(node);
@@ -584,7 +605,7 @@ public class BrowseBean implements IContextListener
else if (ContentModel.TYPE_FILELINK.equals(type))
{
// create our File Link Node representation
node = new MapNode(nodeRef, this.nodeService, false);
node = new MapNode(nodeRef, this.nodeService, true);
node.addPropertyResolver("url", this.resolverLinkUrl);
node.addPropertyResolver("webdavUrl", this.resolverLinkWebdavUrl);
node.addPropertyResolver("cifsPath", this.resolverLinkCifsPath);
@@ -597,7 +618,7 @@ public class BrowseBean implements IContextListener
else if (ContentModel.TYPE_FOLDERLINK.equals(type))
{
// create our Folder Link Node representation
node = new MapNode(nodeRef, this.nodeService, false);
node = new MapNode(nodeRef, this.nodeService, true);
node.addPropertyResolver("icon", this.resolverSpaceIcon);
node.addPropertyResolver("smallIcon", this.resolverSmallIcon);
@@ -1001,6 +1022,56 @@ public class BrowseBean implements IContextListener
this.navigator.setCurrentNodeId( this.navigator.getCurrentNodeId() );
}
/**
* Update page size based on user selection
*/
public void updateSpacesPageSize(ActionEvent event)
{
try
{
int size = Integer.parseInt(this.pageSizeSpacesStr);
if (size >= 0)
{
this.pageSizeSpaces = size;
}
else
{
// reset to known value if this occurs
this.pageSizeSpacesStr = Integer.toString(this.pageSizeSpaces);
}
}
catch (NumberFormatException err)
{
// reset to known value if this occurs
this.pageSizeSpacesStr = Integer.toString(this.pageSizeSpaces);
}
}
/**
* Update page size based on user selection
*/
public void updateContentPageSize(ActionEvent event)
{
try
{
int size = Integer.parseInt(this.pageSizeContentStr);
if (size >= 0)
{
this.pageSizeContent = size;
}
else
{
// reset to known value if this occurs
this.pageSizeContentStr = Integer.toString(this.pageSizeContent);
}
}
catch (NumberFormatException err)
{
// reset to known value if this occurs
this.pageSizeContentStr = Integer.toString(this.pageSizeContent);
}
}
/**
* Action called when a folder space is clicked.
* Navigate into the space.
@@ -1417,8 +1488,9 @@ public class BrowseBean implements IContextListener
getConfigElement(ViewsConfigElement.CONFIG_ELEMENT_ID);
this.browseViewMode = this.viewsConfig.getDefaultView(PAGE_NAME_BROWSE);
this.browsePageSize = this.viewsConfig.getDefaultPageSize(PAGE_NAME_BROWSE,
this.browseViewMode);
int pageSize = this.viewsConfig.getDefaultPageSize(PAGE_NAME_BROWSE, this.browseViewMode);
setPageSizeContent(pageSize);
setPageSizeSpaces(pageSize);
}
/**
@@ -1704,8 +1776,11 @@ public class BrowseBean implements IContextListener
/** The current browse view mode - set to a well known IRichListRenderer identifier */
private String browseViewMode;
/** The current browse view page size */
private int browsePageSize;
/** The current browse view page sizes */
private int pageSizeSpaces;
private int pageSizeContent;
private String pageSizeSpacesStr;
private String pageSizeContentStr;
/** True if current space has a dashboard (template) view available */
private boolean dashboardView;

View File

@@ -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<String, Serializable>(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
{

View File

@@ -65,11 +65,12 @@ public class GroupsBean implements IContextListener
{
private static final String FILTER_CHILDREN = "children";
private static final String FILTER_ALL = "all";
private static final String DEFAULT_OUTCOME = "finish";
private static final String MSG_ERR_EXISTS = "groups_err_exists";
private static final String MSG_GROUPS = "root_groups";
private static Logger logger = Logger.getLogger(GroupsBean.class);
/** The NodeService to be used by the bean */
@@ -648,15 +649,24 @@ public class GroupsBean implements IContextListener
{
String outcome = DEFAULT_OUTCOME;
FacesContext context = FacesContext.getCurrentInstance();
UserTransaction tx = null;
try
{
FacesContext context = FacesContext.getCurrentInstance();
tx = Repository.getUserTransaction(context);
tx.begin();
// create new Group using Authentication Service
this.authService.createAuthority(AuthorityType.GROUP, getActionGroup(), this.name);
String groupName = this.authService.getName(AuthorityType.GROUP, this.name);
if (this.authService.authorityExists(groupName) == false)
{
this.authService.createAuthority(AuthorityType.GROUP, getActionGroup(), this.name);
}
else
{
Utils.addErrorMessage(Application.getMessage(context, MSG_ERR_EXISTS));
outcome = null;
}
// commit the transaction
tx.commit();
@@ -666,7 +676,7 @@ public class GroupsBean implements IContextListener
// rollback the transaction
try { if (tx != null) {tx.rollback();} } catch (Exception tex) {}
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
context, Repository.ERROR_GENERIC), err.getMessage()), err);
outcome = null;
}

View File

@@ -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<String, Serializable> currentActionProperties;
protected List<Map<String, Serializable>> allActionsProperties;
protected static final String ACTION_PAGES_LOCATION = "/jsp/actions/";
protected Map<String, IHandler> 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<RecipientWrapper>(4);
this.usingTemplate = null;
this.emailRecipients = new ArrayList<RecipientWrapper>(4);
this.allActionsProperties = new ArrayList<Map<String, Serializable>>();
this.currentActionProperties = new HashMap<String, Serializable>(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<RecipientWrapper> 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<String, Serializable> actionProps = new HashMap<String, Serializable>(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<String, Serializable> 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.
* <p>
* Based on the params set by the UI, build the params needed to create the action.
*
* @return param map
*/
protected Map<String, Serializable> buildActionParams()
{
// set up parameters maps for the action
Map<String, Serializable> repoParams = new HashMap<String, Serializable>();
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<String> recipients = new ArrayList<String>(emailRecipients.size());
for (int i=0; i<emailRecipients.size(); i++)
{
RecipientWrapper wrapper = emailRecipients.get(i);
recipients.add(wrapper.authority);
}
repoParams.put(MailActionExecuter.PARAM_TO_MANY, (Serializable)recipients);
// add the actual email text to send
repoParams.put(MailActionExecuter.PARAM_TEXT,
this.currentActionProperties.get(PROP_MESSAGE));
// add the subject for the email
repoParams.put(MailActionExecuter.PARAM_SUBJECT,
this.currentActionProperties.get(PROP_SUBJECT));
// add the from address
String from = Application.getClientConfig(FacesContext.getCurrentInstance()).getFromEmailAddress();
repoParams.put(MailActionExecuter.PARAM_FROM, from);
// add the template if one was selected by the user
if (this.usingTemplate != null)
{
repoParams.put(MailActionExecuter.PARAM_TEMPLATE, new NodeRef(Repository.getStoreRef(), this.usingTemplate));
}
}
else if (ImporterActionExecuter.NAME.equals(this.action))
{
// add the encoding
repoParams.put(ImporterActionExecuter.PARAM_ENCODING, IMPORT_ENCODING);
// add the destination for the import
NodeRef destNodeRef = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION);
repoParams.put(ImporterActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef);
}
else if (SpecialiseTypeActionExecuter.NAME.equals(this.action))
{
// add the specialisation type
String objectType = (String)this.currentActionProperties.get(PROP_OBJECT_TYPE);
repoParams.put(SpecialiseTypeActionExecuter.PARAM_TYPE_NAME, QName.createQName(objectType));
}
else if (ScriptActionExecutor.NAME.equals(this.action))
{
// add the selected script noderef to the action properties
String id = (String)this.currentActionProperties.get(PROP_SCRIPT);
NodeRef scriptRef = new NodeRef(Repository.getStoreRef(), id);
repoParams.put(ScriptActionExecutor.PARAM_SCRIPTREF, scriptRef);
repoParams.put(ScriptActionExecutor.PARAM_SPACEREF, this.navigator.getCurrentNode().getNodeRef());
}
return repoParams;
}
/**
* Returns a summary string for the current action
*
* @return The summary or null if a summary could not be built
*/
protected String buildActionSummary()
{
String summary = null;
FacesContext context = FacesContext.getCurrentInstance();
if (AddFeaturesActionExecuter.NAME.equals(this.action))
{
String label = null;
String aspect = (String)this.currentActionProperties.get(PROP_ASPECT);
// find the label used by looking through the SelectItem list
for (SelectItem item : this.getAspects())
{
if (item.getValue().equals(aspect))
{
label = item.getLabel();
break;
}
}
summary = MessageFormat.format(Application.getMessage(context, "action_add_features"),
new Object[] {label});
}
else if (RemoveFeaturesActionExecuter.NAME.equals(this.action))
{
String label = null;
String aspect = (String)this.currentActionProperties.get(PROP_ASPECT);
// find the label used by looking through the SelectItem list
for (SelectItem item : this.getAspects())
{
if (item.getValue().equals(aspect))
{
label = item.getLabel();
break;
}
}
summary = MessageFormat.format(Application.getMessage(context, "action_remove_features"),
new Object[] {label});
}
else if (CopyActionExecuter.NAME.equals(this.action))
{
NodeRef space = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION);
String spaceName = Repository.getNameForNode(this.nodeService, space);
summary = MessageFormat.format(Application.getMessage(context, "action_copy"),
new Object[] {spaceName});
}
else if (MoveActionExecuter.NAME.equals(this.action))
{
NodeRef space = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION);
String spaceName = Repository.getNameForNode(this.nodeService, space);
summary = MessageFormat.format(Application.getMessage(context, "action_move"),
new Object[] {spaceName});
}
else if (SimpleWorkflowActionExecuter.NAME.equals(this.action))
{
String approveStepName = (String)this.currentActionProperties.get(PROP_APPROVE_STEP_NAME);
String approveAction = (String)this.currentActionProperties.get(PROP_APPROVE_ACTION);
NodeRef approveFolder = (NodeRef)this.currentActionProperties.get(PROP_APPROVE_FOLDER);
String approveFolderName = Repository.getNameForNode(this.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)this.currentActionProperties.get(PROP_REJECT_STEP_PRESENT);
if (rejectStep != null && "yes".equals(rejectStep))
{
String rejectStepName = (String)this.currentActionProperties.get(PROP_REJECT_STEP_NAME);
String rejectAction = (String)this.currentActionProperties.get(PROP_REJECT_ACTION);
NodeRef rejectFolder = (NodeRef)this.currentActionProperties.get(PROP_REJECT_FOLDER);
String rejectFolderName = Repository.getNameForNode(this.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);
}
summary = builder.toString();
}
else if (LinkCategoryActionExecuter.NAME.equals(this.action))
{
NodeRef cat = (NodeRef)this.currentActionProperties.get(PROP_CATEGORY);
String name = Repository.getNameForNode(this.nodeService, cat);
summary = MessageFormat.format(Application.getMessage(context, "action_link_category"),
new Object[] {name});
}
else if (CheckOutActionExecuter.NAME.equals(this.action))
{
NodeRef space = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION);
String spaceName = Repository.getNameForNode(this.nodeService, space);
summary = MessageFormat.format(Application.getMessage(context, "action_check_out"),
new Object[] {spaceName});
}
else if (CheckInActionExecuter.NAME.equals(this.action))
{
String comment = (String)this.currentActionProperties.get(PROP_CHECKIN_DESC);
Boolean minorChange = (Boolean)this.currentActionProperties.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");
}
summary = MessageFormat.format(Application.getMessage(context, "action_check_in"),
new Object[] {change, comment});
}
else if (TransformActionExecuter.NAME.equals(this.action))
{
String label = null;
NodeRef space = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION);
String name = Repository.getNameForNode(this.nodeService, space);
String transformer = (String)this.currentActionProperties.get(PROP_TRANSFORMER);
// find the label used by looking through the SelectItem list
for (SelectItem item : this.getTransformers())
{
if (item.getValue().equals(transformer))
{
label = item.getLabel();
break;
}
}
summary = MessageFormat.format(Application.getMessage(context, "action_transform"),
new Object[] {name, label});
}
else if (ImageTransformActionExecuter.NAME.equals(this.action))
{
String label = null;
NodeRef space = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION);
String name = Repository.getNameForNode(this.nodeService, space);
String transformer = (String)this.currentActionProperties.get(PROP_IMAGE_TRANSFORMER);
String option = (String)this.currentActionProperties.get(PROP_TRANSFORM_OPTIONS);
// find the label used by looking through the SelectItem list
for (SelectItem item : this.getImageTransformers())
{
if (item.getValue().equals(transformer))
{
label = item.getLabel();
break;
}
}
summary = MessageFormat.format(Application.getMessage(context, "action_transform_image"),
new Object[] {name, label, option});
}
else if (MailActionExecuter.NAME.equals(this.action))
{
String addresses = (String)this.currentActionProperties.get(PROP_TO);
if (addresses == null || addresses.length() == 0)
{
if (this.emailRecipients.size() != 0)
{
StringBuilder builder = new StringBuilder();
for (int i=0; i<this.emailRecipients.size(); i++)
{
RecipientWrapper wrapper = this.emailRecipients.get(i);
if (i != 0)
{
builder.append(", ");
}
builder.append(wrapper.getName());
}
addresses = builder.toString();
}
}
summary = MessageFormat.format(Application.getMessage(context, "action_mail"),
new Object[] {addresses});
}
else if (ImporterActionExecuter.NAME.equals(this.action))
{
NodeRef space = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION);
String spaceName = Repository.getNameForNode(this.nodeService, space);
summary = MessageFormat.format(Application.getMessage(context, "action_import"),
new Object[] {spaceName});
}
else if (SpecialiseTypeActionExecuter.NAME.equals(this.action))
{
String label = null;
String objectType = (String)this.currentActionProperties.get(PROP_OBJECT_TYPE);
for (SelectItem item : getObjectTypes())
{
if (item.getValue().equals(objectType) == true)
{
label = item.getLabel();
break;
}
}
summary = MessageFormat.format(Application.getMessage(context, "action_specialise_type"),
new Object[] {label});
}
else if (ScriptActionExecutor.NAME.equals(this.action))
{
String id = (String)this.currentActionProperties.get(PROP_SCRIPT);
NodeRef scriptRef = new NodeRef(Repository.getStoreRef(), id);
String scriptName = Repository.getNameForNode(this.nodeService, scriptRef);
summary = MessageFormat.format(Application.getMessage(context, "action_script"),
new Object[] {scriptName});
}
else
{
// as the default case (i.e. for actions with no parameters) use the title
ActionDefinition actionDef = this.actionService.getActionDefinition(this.action);
summary = actionDef.getTitle();
}
return summary;
}
/**
* Navigates to the given page, used to go back and forth between the
* wizard and the actions settings pages
@@ -1330,17 +789,56 @@ public abstract class BaseActionWizard extends BaseWizardBean
}
/**
* Calculates the viewId for the given action id
*
* @param actionId The id of the action to generate the view id for
* @return The view id
* Initialises the action handlers from the current configuration.
*/
protected String calculateActionViewId(String actionId)
protected void initialiseActionHandlers()
{
return ACTION_PAGES_LOCATION + actionId + ".jsp";
if (this.actionHandlers == null)
{
ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance());
Config wizardCfg = svc.getConfig("Action Wizards");
if (wizardCfg != null)
{
ConfigElement actionHandlerCfg = wizardCfg.getConfigElement("action-handlers");
if (actionHandlerCfg != null)
{
this.actionHandlers = new HashMap<String, IHandler>(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

View File

@@ -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<String, Serializable> 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<String, Serializable> props,
Map<String, Serializable> 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<String, Serializable> props,
Map<String, Serializable> 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<String, Serializable> props);
}

View File

@@ -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<String, Serializable> repoActionParams = buildActionParams();
// get the action handler to prepare for the save
Map<String, Serializable> repoActionParams = new HashMap<String, Serializable>();
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);

View File

@@ -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<String, Serializable> actionProps,
Map<String, Serializable> repoParams)
{
QName aspect = Repository.resolveToQName((String)actionProps.get(PROP_ASPECT));
repoParams.put(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, aspect);
}
public void prepareForEdit(Map<String, Serializable> actionProps,
Map<String, Serializable> repoParams)
{
QName aspect = (QName)repoParams.get(AddFeaturesActionExecuter.PARAM_ASPECT_NAME);
actionProps.put(PROP_ASPECT, aspect.toString());
}
public String generateSummary(FacesContext context, IWizardBean wizard,
Map<String, Serializable> 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});
}
}

View File

@@ -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<String, Serializable> 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";
}
}

View File

@@ -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<String, Serializable> actionProps)
{
actionProps.put(PROP_CHECKIN_MINOR, new Boolean(true));
}
public String getJSPPath()
{
return getJSPPath(CheckInActionExecuter.NAME);
}
public void prepareForSave(Map<String, Serializable> actionProps,
Map<String, Serializable> 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<String, Serializable> actionProps,
Map<String, Serializable> 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<String, Serializable> 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});
}
}

View File

@@ -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<String, Serializable> actionProps,
Map<String, Serializable> 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<String, Serializable> actionProps,
Map<String, Serializable> repoProps)
{
NodeRef destNodeRef = (NodeRef)repoProps.get(CheckOutActionExecuter.PARAM_DESTINATION_FOLDER);
actionProps.put(PROP_DESTINATION, destNodeRef);
}
public String generateSummary(FacesContext context, IWizardBean wizard,
Map<String, Serializable> 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});
}
}

View File

@@ -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<String, Serializable> actionProps,
Map<String, Serializable> 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<String, Serializable> actionProps,
Map<String, Serializable> repoProps)
{
NodeRef destNodeRef = (NodeRef)repoProps.get(CopyActionExecuter.PARAM_DESTINATION_FOLDER);
actionProps.put(PROP_DESTINATION, destNodeRef);
}
public String generateSummary(FacesContext context, IWizardBean wizard,
Map<String, Serializable> 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});
}
}

View File

@@ -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<String, Serializable> actionProps,
Map<String, Serializable> 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<String, Serializable> actionProps,
Map<String, Serializable> repoProps)
{
NodeRef destNodeRef = (NodeRef)repoProps.get(
ImporterActionExecuter.PARAM_DESTINATION_FOLDER);
actionProps.put(PROP_DESTINATION, destNodeRef);
}
public String generateSummary(FacesContext context, IWizardBean wizard,
Map<String, Serializable> 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});
}
}

View File

@@ -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<String, Serializable> actionProps,
Map<String, Serializable> 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<String, Serializable> actionProps,
Map<String, Serializable> repoProps)
{
NodeRef catNodeRef = (NodeRef)repoProps.get(LinkCategoryActionExecuter.PARAM_CATEGORY_VALUE);
actionProps.put(PROP_CATEGORY, catNodeRef);
}
public String generateSummary(FacesContext context, IWizardBean wizard,
Map<String, Serializable> 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});
}
}

View File

@@ -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<String, Serializable> actionProps,
Map<String, Serializable> 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<String> recipients = new ArrayList<String>(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<String, Serializable> actionProps,
Map<String, Serializable> 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<String> recipients = (List<String>)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<String, Serializable> 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});
}
}

View File

@@ -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<String, Serializable> actionProps,
Map<String, Serializable> 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<String, Serializable> actionProps,
Map<String, Serializable> repoProps)
{
NodeRef destNodeRef = (NodeRef)repoProps.get(MoveActionExecuter.PARAM_DESTINATION_FOLDER);
actionProps.put(PROP_DESTINATION, destNodeRef);
}
public String generateSummary(FacesContext context, IWizardBean wizard,
Map<String, Serializable> 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});
}
}

View File

@@ -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<String, Serializable> actionProps,
Map<String, Serializable> repoProps)
{
QName aspect = Repository.resolveToQName((String)actionProps.get(PROP_ASPECT));
repoProps.put(RemoveFeaturesActionExecuter.PARAM_ASPECT_NAME, aspect);
}
public void prepareForEdit(Map<String, Serializable> actionProps,
Map<String, Serializable> repoProps)
{
QName aspect = (QName)repoProps.get(RemoveFeaturesActionExecuter.PARAM_ASPECT_NAME);
actionProps.put(PROP_ASPECT, aspect.toString());
}
public String generateSummary(FacesContext context, IWizardBean wizard,
Map<String, Serializable> 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});
}
}

View File

@@ -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<String, Serializable> actionProps,
Map<String, Serializable> 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<String, Serializable> actionProps,
Map<String, Serializable> repoProps)
{
NodeRef scriptRef = (NodeRef)repoProps.get(ScriptActionExecutor.PARAM_SCRIPTREF);
actionProps.put(PROP_SCRIPT, scriptRef.getId());
}
public String generateSummary(FacesContext context, IWizardBean wizard,
Map<String, Serializable> 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});
}
}

View File

@@ -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<String, Serializable> 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<String, Serializable> actionProps,
Map<String, Serializable> 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<String, Serializable> actionProps,
Map<String, Serializable> 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<String, Serializable> 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();
}
}

View File

@@ -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<String, Serializable> actionProps,
Map<String, Serializable> repoProps)
{
String objectType = (String)actionProps.get(PROP_OBJECT_TYPE);
repoProps.put(SpecialiseTypeActionExecuter.PARAM_TYPE_NAME,
QName.createQName(objectType));
}
public void prepareForEdit(Map<String, Serializable> actionProps,
Map<String, Serializable> 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<String, Serializable> 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});
}
}

View File

@@ -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<String, Serializable> actionProps,
Map<String, Serializable> 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<String, Serializable> actionProps,
Map<String, Serializable> 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<String, Serializable> 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});
}
}

View File

@@ -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<String, Serializable> actionProps,
Map<String, Serializable> 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<String, Serializable> actionProps,
Map<String, Serializable> 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<String, Serializable> 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});
}
}

View File

@@ -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<SelectItem> types;
private List<SelectItem> conditions;
protected Map<String, IHandler> conditionHandlers;
protected Map<String, Serializable> currentConditionProperties;
protected List<Map<String, Serializable>> 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<Map<String, Serializable>>();
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<String, Serializable> condProps = new HashMap<String, Serializable>(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<String, Serializable> repoCondParams = buildConditionParams();
// get the condition handler to prepare for the save
Map<String, Serializable> repoCondParams = new HashMap<String, Serializable>();
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<String, Serializable> repoActionParams = buildActionParams();
// get the action handler to prepare for the save
Map<String, Serializable> repoActionParams = new HashMap<String, Serializable>();
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<String, Serializable> 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<String, Serializable> buildConditionParams()
{
Map<String, Serializable> repoParams = new HashMap<String, Serializable>();
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<String, IHandler>(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";
}
}

View File

@@ -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<ActionCondition> conditions = rule.getActionConditions();
for (ActionCondition condition : conditions)
{
this.currentConditionProperties = new HashMap<String, Serializable>(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<String, Serializable>(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<String, Serializable> 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<String, Serializable> 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<String> recipients = (List<String>)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());
}
}
}

View File

@@ -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<String, Serializable> 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";
}
}

View File

@@ -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<String, Serializable> conditionProps,
Map<String, Serializable> repoProps)
{
String mimeType = (String)conditionProps.get(PROP_MIMETYPE);
repoProps.put(CompareMimeTypeEvaluator.PARAM_VALUE, mimeType);
}
public void prepareForEdit(Map<String, Serializable> conditionProps,
Map<String, Serializable> repoProps)
{
String mimeType = (String)repoProps.get(CompareMimeTypeEvaluator.PARAM_VALUE);
conditionProps.put(PROP_MIMETYPE, mimeType);
}
public String generateSummary(FacesContext context, IWizardBean wizard,
Map<String, Serializable> 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});
}
}

View File

@@ -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<String, Serializable> conditionProps,
Map<String, Serializable> repoProps)
{
QName aspect = QName.createQName((String)conditionProps.get(PROP_ASPECT));
repoProps.put(HasAspectEvaluator.PARAM_ASPECT, aspect);
}
public void prepareForEdit(Map<String, Serializable> conditionProps,
Map<String, Serializable> repoProps)
{
QName aspect = (QName)repoProps.get(HasAspectEvaluator.PARAM_ASPECT);
conditionProps.put(PROP_ASPECT, aspect.toString());
}
public String generateSummary(FacesContext context, IWizardBean wizard,
Map<String, Serializable> 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});
}
}

View File

@@ -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<String, Serializable> conditionProps,
Map<String, Serializable> 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<String, Serializable> conditionProps,
Map<String, Serializable> repoProps)
{
NodeRef catNodeRef = (NodeRef)repoProps.get(InCategoryEvaluator.PARAM_CATEGORY_VALUE);
conditionProps.put(PROP_CATEGORY, catNodeRef);
}
public String generateSummary(FacesContext context, IWizardBean wizard,
Map<String, Serializable> 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});
}
}

View File

@@ -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<String, Serializable> conditionProps,
Map<String, Serializable> repoProps)
{
QName type = QName.createQName((String)conditionProps.get(PROP_MODEL_TYPE));
repoProps.put(IsSubTypeEvaluator.PARAM_TYPE, type);
}
public void prepareForEdit(Map<String, Serializable> conditionProps,
Map<String, Serializable> repoProps)
{
QName type = (QName)repoProps.get(IsSubTypeEvaluator.PARAM_TYPE);
conditionProps.put(PROP_MODEL_TYPE, type.toString());
}
public String generateSummary(FacesContext context, IWizardBean wizard,
Map<String, Serializable> 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});
}
}

View File

@@ -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<String, Serializable> conditionProps,
Map<String, Serializable> repoProps)
{
String text = (String)conditionProps.get(PROP_CONTAINS_TEXT);
repoProps.put(ComparePropertyValueEvaluator.PARAM_VALUE, text);
}
public void prepareForEdit(Map<String, Serializable> conditionProps,
Map<String, Serializable> repoProps)
{
String propValue = (String)repoProps.get(ComparePropertyValueEvaluator.PARAM_VALUE);
conditionProps.put(PROP_CONTAINS_TEXT, propValue);
}
public String generateSummary(FacesContext context, IWizardBean wizard,
Map<String, Serializable> 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});
}
}

View File

@@ -34,6 +34,7 @@ import javax.faces.model.ListDataModel;
import javax.transaction.UserTransaction;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
@@ -589,6 +590,7 @@ public abstract class UserMembersBean implements IContextListener
// and add each of the new permissions in turn
NodeRef nodeRef = getNode().getNodeRef();
this.permissionService.clearPermission(nodeRef, getPersonAuthority());
AlfrescoTransactionSupport.flush();
for (PermissionWrapper wrapper : personRoles)
{
this.permissionService.setPermission(

View File

@@ -30,6 +30,8 @@ import javax.faces.event.ActionEvent;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.faces.model.SelectItem;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import javax.transaction.UserTransaction;
import org.alfresco.model.ContentModel;
@@ -57,6 +59,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.mail.javamail.MimeMessagePreparator;
/**
* @author Kevin Roast
@@ -105,6 +109,7 @@ public abstract class InviteUsersWizard extends AbstractWizardBean
private String automaticText = null;
private String template = null;
private String usingTemplate = null;
private String finalBody;
/**
* @return a cached list of available permissions for the type being dealt with
@@ -277,9 +282,9 @@ public abstract class InviteUsersWizard extends AbstractWizardBean
* @param from From text message
* @param roleText The role display label for the user invite notification
*/
private void notifyUser(NodeRef person, NodeRef node, String from, String roleText)
private void notifyUser(NodeRef person, NodeRef node, final String from, String roleText)
{
String to = (String)this.nodeService.getProperty(person, ContentModel.PROP_EMAIL);
final String to = (String)this.nodeService.getProperty(person, ContentModel.PROP_EMAIL);
if (to != null && to.length() != 0)
{
@@ -289,21 +294,28 @@ public abstract class InviteUsersWizard extends AbstractWizardBean
FacesContext fc = FacesContext.getCurrentInstance();
// use template service to format the email
NodeRef templateRef = new NodeRef(Repository.getStoreRef(), this.usingTemplate);
ServiceRegistry services = Repository.getServiceRegistry(fc);
Map<String, Object> model = DefaultModelHelper.buildDefaultModel(
services, Application.getCurrentUser(fc));
model.put("role", roleText);
model.put("space", new TemplateNode(node, Repository.getServiceRegistry(fc), null));
NodeRef templateRef = new NodeRef(Repository.getStoreRef(), this.usingTemplate);
body = services.getTemplateService().processTemplate("freemarker", templateRef.toString(), model);
}
this.finalBody = body;
SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
simpleMailMessage.setTo(to);
simpleMailMessage.setSubject(this.subject);
simpleMailMessage.setText(body);
simpleMailMessage.setFrom(from);
MimeMessagePreparator mailPreparer = new MimeMessagePreparator()
{
public void prepare(MimeMessage mimeMessage) throws MessagingException
{
MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
message.setTo(to);
message.setSubject(subject);
message.setText(finalBody);
message.setFrom(from);
}
};
if (logger.isDebugEnabled())
logger.debug("Sending notification email to: " + to + "\n...with subject:\n" + subject + "\n...with body:\n" + body);
@@ -311,7 +323,7 @@ public abstract class InviteUsersWizard extends AbstractWizardBean
try
{
// Send the message
this.mailSender.send(simpleMailMessage);
this.mailSender.send(mailPreparer);
}
catch (Throwable e)
{