Humongous merge. It is incomplete, however; faces-config-navigation.xml and ClientConfigElement

were both beyond me, and are just the raw conflict merge data.  If Kev can't figure out how they should
go together by tomorrow AM (for me) I'll dig back in.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@4306 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-11-08 05:17:40 +00:00
parent c5c18185cf
commit 99486032e1
46 changed files with 5805 additions and 3529 deletions

View File

@@ -39,6 +39,7 @@ import org.alfresco.web.app.context.UIContextService;
import org.alfresco.web.bean.actions.handlers.SimpleWorkflowHandler;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.workflow.WorkflowUtil;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.Utils.URLMode;
import org.alfresco.web.ui.common.component.UIActionLink;

File diff suppressed because it is too large Load Diff

View File

@@ -86,6 +86,7 @@ public final class SearchContext implements Serializable
private static final char OP_WILDCARD = '*';
private static final char OP_AND = '+';
private static final char OP_NOT = '-';
private static final String STR_OP_WILDCARD = "" + OP_WILDCARD;
/** Search mode constants */
public final static int SEARCH_ALL = 0;
@@ -174,21 +175,7 @@ public final class SearchContext implements Serializable
nameAttrBuf.append(OP_NOT);
}
// simple single word text search
if (text.charAt(0) != OP_WILDCARD)
{
// escape characters and append the wildcard character
String safeText = QueryParser.escape(text);
fullTextBuf.append("TEXT:").append(safeText).append(OP_WILDCARD);
nameAttrBuf.append("@").append(nameAttr).append(":").append(safeText).append(OP_WILDCARD);
}
else
{
// found a leading wildcard - prepend it again after escaping the other characters
String safeText = QueryParser.escape(text.substring(1));
fullTextBuf.append("TEXT:*").append(safeText).append(OP_WILDCARD);
nameAttrBuf.append("@").append(nameAttr).append(":*").append(safeText).append(OP_WILDCARD);
}
processSearchTextAttribute(nameAttr, text, nameAttrBuf, fullTextBuf);
}
}
else
@@ -253,18 +240,8 @@ public final class SearchContext implements Serializable
nameAttrBuf.append(OP_AND);
}
if (term.charAt(0) != OP_WILDCARD)
{
String safeTerm = QueryParser.escape(term);
fullTextBuf.append("TEXT:").append(safeTerm).append(OP_WILDCARD);
nameAttrBuf.append("@").append(nameAttr).append(":").append(safeTerm).append(OP_WILDCARD);
}
else
{
String safeTerm = QueryParser.escape(term.substring(1));
fullTextBuf.append("TEXT:*").append(safeTerm).append(OP_WILDCARD);
nameAttrBuf.append("@").append(nameAttr).append(":*").append(safeTerm).append(OP_WILDCARD);
}
processSearchTextAttribute(nameAttr, term, nameAttrBuf, fullTextBuf);
fullTextBuf.append(' ');
nameAttrBuf.append(' ');
@@ -317,11 +294,9 @@ public final class SearchContext implements Serializable
for (QName qname : queryAttributes.keySet())
{
String value = queryAttributes.get(qname).trim();
if (value.length() != 0 && value.length() >= minimum)
if (value.length() >= minimum)
{
String escapedName = Repository.escapeQName(qname);
attributeQuery.append(" +@").append(escapedName)
.append(":").append(QueryParser.escape(value)).append(OP_WILDCARD);
processSearchAttribute(qname, value, attributeQuery);
}
}
@@ -480,6 +455,114 @@ public final class SearchContext implements Serializable
return query;
}
/**
* Build the lucene search terms required for the specified attribute and append to a buffer.
* Supports text values with a wildcard '*' character as the prefix and/or the suffix.
*
* @param qname QName of the attribute
* @param value Non-null value of the attribute
* @param buf Buffer to append lucene terms to
*/
private static void processSearchAttribute(QName qname, String value, StringBuilder buf)
{
if (value.indexOf(' ') == -1)
{
String safeValue;
String prefix = "";
String suffix = "";
// look for a wildcard suffix
if (value.charAt(value.length() - 1) != OP_WILDCARD)
{
// look for wildcard prefix
if (value.charAt(0) != OP_WILDCARD)
{
safeValue = QueryParser.escape(value);
}
else
{
safeValue = QueryParser.escape(value.substring(1));
prefix = STR_OP_WILDCARD;
}
}
else
{
// found a wildcard suffix - append it again after escaping the other characters
suffix = STR_OP_WILDCARD;
// look for wildcard prefix
if (value.charAt(0) != OP_WILDCARD)
{
safeValue = QueryParser.escape(value.substring(0, value.length() - 1));
}
else
{
safeValue = QueryParser.escape(value.substring(1, value.length() - 1));
prefix = STR_OP_WILDCARD;
}
}
buf.append(" +@").append(Repository.escapeQName(qname)).append(":")
.append(prefix).append(safeValue).append(suffix);
}
else
{
// phrase multi-word search
String safeValue = QueryParser.escape(value);
buf.append(" +@").append(Repository.escapeQName(qname)).append(":\"").append(safeValue).append('"');
}
}
/**
* Build the lucene search terms required for the specified attribute and append to multiple buffers.
* Supports text values with a wildcard '*' character as the prefix and/or the suffix.
*
* @param qname QName.toString() of the attribute
* @param value Non-null value of the attribute
* @param attrBuf Attribute search buffer to append lucene terms to
* @param textBuf Text search buffer to append lucene terms to
*/
private static void processSearchTextAttribute(String qname, String value, StringBuilder attrBuf, StringBuilder textBuf)
{
String safeValue;
String suffix = "";
String prefix = "";
if (value.charAt(value.length() - 1) != OP_WILDCARD)
{
// look for wildcard prefix
if (value.charAt(0) != OP_WILDCARD)
{
safeValue = QueryParser.escape(value);
}
else
{
// found a leading wildcard - prepend it again after escaping the other characters
prefix = STR_OP_WILDCARD;
safeValue = QueryParser.escape(value.substring(1));
}
}
else
{
suffix = STR_OP_WILDCARD;
// look for wildcard prefix
if (value.charAt(0) != OP_WILDCARD)
{
safeValue = QueryParser.escape(value.substring(0, value.length() - 1));
}
else
{
prefix = STR_OP_WILDCARD;
safeValue = QueryParser.escape(value.substring(1, value.length() - 1));
}
}
textBuf.append("TEXT:").append(prefix).append(safeValue).append(suffix);
attrBuf.append("@").append(qname).append(":")
.append(prefix).append(safeValue).append(suffix);
}
/**
* Generate a search XPATH pointing to the specified node, optionally return an XPATH
* that includes the child nodes.

View File

@@ -34,6 +34,7 @@ import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.AlfrescoNavigationHandler;
import org.alfresco.web.app.Application;
import org.alfresco.web.app.servlet.GuestTemplateContentServlet;
import org.alfresco.web.app.servlet.TemplateContentServlet;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
@@ -506,9 +507,9 @@ public class SpaceDetailsBean extends BaseDetailsBean
// build RSS feed template URL from selected template and the space NodeRef and
// add the guest=true URL parameter - this is required for no login access and
// add the mimetype=text/xml URL parameter - required to return correct stream type
return TemplateContentServlet.generateURL(space.getNodeRef(),
return GuestTemplateContentServlet.generateURL(space.getNodeRef(),
(NodeRef)space.getProperties().get(ContentModel.PROP_FEEDTEMPLATE))
+ "/rss.xml?guest=true" + "&mimetype=text%2Fxml";
+ "/rss.xml?mimetype=text%2Fxml";
}
/**

View File

@@ -71,14 +71,14 @@ public final class DialogManager
"' does not implement the required IDialogBean interface");
}
// create the DialogState object
this.currentDialogState = new DialogState(config, dialog);
// initialise the managed bean
dialog.init(this.paramsToApply);
// reset the current parameters so subsequent dialogs don't get them
this.paramsToApply = null;
// create the DialogState object
this.currentDialogState = new DialogState(config, dialog);
}
/**

View File

@@ -89,7 +89,7 @@ public class Node implements Serializable
/**
* @return All the properties known about this node.
*/
public Map<String, Object> getProperties()
public final Map<String, Object> getProperties()
{
if (this.propsRetrieved == false)
{

View File

@@ -70,6 +70,9 @@ public class TransientNode extends Node
// setup the transient node so that the super class methods work
// and do not need to go back to the repository
if (logger.isDebugEnabled())
logger.debug("Initialising transient node with data: " + data);
DictionaryService ddService = this.getServiceRegistry().getDictionaryService();
// marshall the given properties and associations into the internal maps
@@ -94,25 +97,11 @@ public class TransientNode extends Node
{
if (assocDef.isChild())
{
// TODO: handle lists of NodeRef's
NodeRef child = null;
Object obj = data.get(item);
if (obj instanceof String)
{
child = new NodeRef((String)obj);
}
else if (obj instanceof NodeRef)
{
child = (NodeRef)obj;
}
else if (obj instanceof List)
{
if (logger.isWarnEnabled())
logger.warn("0..* child associations are not supported yet");
}
if (child != null)
if (obj instanceof NodeRef)
{
NodeRef child = (NodeRef)obj;
// create a child association reference, add it to a list and add the list
// to the list of child associations for this node
List<ChildAssociationRef> assocs = new ArrayList<ChildAssociationRef>(1);
@@ -122,28 +111,36 @@ public class TransientNode extends Node
this.childAssociations.put(item, assocs);
}
else if (obj instanceof List)
{
List targets = (List)obj;
List<ChildAssociationRef> assocs = new ArrayList<ChildAssociationRef>(targets.size());
for (Object target : targets)
{
if (target instanceof NodeRef)
{
NodeRef currentChild = (NodeRef)target;
ChildAssociationRef childRef = new ChildAssociationRef(assocDef.getName(),
this.nodeRef, null, currentChild);
assocs.add(childRef);
}
}
if (assocs.size() > 0)
{
this.childAssociations.put(item, assocs);
}
}
}
else
{
// TODO: handle lists of NodeRef's
NodeRef target = null;
Object obj = data.get(item);
if (obj instanceof String)
{
target = new NodeRef((String)obj);
}
else if (obj instanceof NodeRef)
{
target = (NodeRef)obj;
}
else if (obj instanceof List)
{
if (logger.isWarnEnabled())
logger.warn("0..* associations are not supported yet");
}
if (target != null)
if (obj instanceof NodeRef)
{
NodeRef target = (NodeRef)obj;
// create a association reference, add it to a list and add the list
// to the list of associations for this node
List<AssociationRef> assocs = new ArrayList<AssociationRef>(1);
@@ -152,6 +149,27 @@ public class TransientNode extends Node
this.associations.put(item, assocs);
}
else if (obj instanceof List)
{
List targets = (List)obj;
List<AssociationRef> assocs = new ArrayList<AssociationRef>(targets.size());
for (Object target : targets)
{
if (target instanceof NodeRef)
{
NodeRef currentTarget = (NodeRef)target;
AssociationRef assocRef = new AssociationRef(this.nodeRef, assocDef.getName(), currentTarget);
assocs.add(assocRef);
}
}
if (assocs.size() > 0)
{
this.associations.put(item, assocs);
}
}
}
}
}

View File

@@ -136,7 +136,7 @@ public class ManageTaskDialog extends BaseDialogBean
logger.debug("Saving task: " + this.task.id);
// prepare the edited parameters for saving
Map<QName, Serializable> params = WorkflowBean.prepareTaskParams(this.taskNode);
Map<QName, Serializable> params = WorkflowUtil.prepareTaskParams(this.taskNode);
if (logger.isDebugEnabled())
logger.debug("Saving task with parameters: " + params);
@@ -262,7 +262,7 @@ public class ManageTaskDialog extends BaseDialogBean
tx.begin();
// prepare the edited parameters for saving
Map<QName, Serializable> params = WorkflowBean.prepareTaskParams(this.taskNode);
Map<QName, Serializable> params = WorkflowUtil.prepareTaskParams(this.taskNode);
if (logger.isDebugEnabled())
logger.debug("Transitioning task with parameters: " + params);
@@ -399,7 +399,7 @@ public class ManageTaskDialog extends BaseDialogBean
*/
public void togglePackageItemComplete(ActionEvent event)
{
// TODO: implement this!
// TODO: not supported yet
}
// ------------------------------------------------------------------------------

View File

@@ -119,7 +119,7 @@ public class StartWorkflowWizard extends BaseWizardBean
logger.debug("Starting workflow: " + this.selectedWorkflow);
// prepare the parameters from the current state of the property sheet
Map<QName, Serializable> params = WorkflowBean.prepareTaskParams(this.startTaskNode);
Map<QName, Serializable> params = WorkflowUtil.prepareTaskParams(this.startTaskNode);
if (logger.isDebugEnabled())
logger.debug("Starting workflow with parameters: " + params);

View File

@@ -1,25 +1,19 @@
package org.alfresco.web.bean.workflow;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.transaction.UserTransaction;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.workflow.WorkflowModel;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.workflow.WorkflowService;
import org.alfresco.service.cmr.workflow.WorkflowTask;
import org.alfresco.service.cmr.workflow.WorkflowTaskDefinition;
import org.alfresco.service.cmr.workflow.WorkflowTaskState;
import org.alfresco.service.cmr.workflow.WorkflowTransition;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.ISO9075;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.repository.Node;
@@ -31,7 +25,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Managed bean used for handling workflow related features
* Managed bean used for providing support for the workflow task dashlets
*
* @author gavinc
*/
@@ -55,40 +49,43 @@ public class WorkflowBean
*/
public List<Node> getTasksToDo()
{
// get the current username
FacesContext context = FacesContext.getCurrentInstance();
User user = Application.getCurrentUser(context);
String userName = ISO9075.encode(user.getUserName());
UserTransaction tx = null;
try
if (this.tasks == null)
{
tx = Repository.getUserTransaction(context, true);
tx.begin();
// get the current username
FacesContext context = FacesContext.getCurrentInstance();
User user = Application.getCurrentUser(context);
String userName = ISO9075.encode(user.getUserName());
// get the current in progress tasks for the current user
List<WorkflowTask> tasks = this.workflowService.getAssignedTasks(
userName, WorkflowTaskState.IN_PROGRESS);
// create a list of transient nodes to represent
this.tasks = new ArrayList<Node>(tasks.size());
for (WorkflowTask task : tasks)
UserTransaction tx = null;
try
{
Node node = createTask(task);
this.tasks.add(node);
tx = Repository.getUserTransaction(context, true);
tx.begin();
if (logger.isDebugEnabled())
logger.debug("Added to do task: " + node);
// get the current in progress tasks for the current user
List<WorkflowTask> tasks = this.workflowService.getAssignedTasks(
userName, WorkflowTaskState.IN_PROGRESS);
// create a list of transient nodes to represent
this.tasks = new ArrayList<Node>(tasks.size());
for (WorkflowTask task : tasks)
{
Node node = createTask(task);
this.tasks.add(node);
if (logger.isDebugEnabled())
logger.debug("Added to do task: " + node);
}
// commit the changes
tx.commit();
}
catch (Throwable e)
{
// rollback the transaction
try { if (tx != null) {tx.rollback();} } catch (Exception ex) {}
Utils.addErrorMessage("Failed to get to do tasks: " + e.toString(), e);
}
// commit the changes
tx.commit();
}
catch (Throwable e)
{
// rollback the transaction
try { if (tx != null) {tx.rollback();} } catch (Exception ex) {}
Utils.addErrorMessage("Failed to get to do tasks: " + e.toString(), e);
}
return this.tasks;
@@ -102,40 +99,43 @@ public class WorkflowBean
*/
public List<Node> getTasksCompleted()
{
// get the current username
FacesContext context = FacesContext.getCurrentInstance();
User user = Application.getCurrentUser(context);
String userName = ISO9075.encode(user.getUserName());
UserTransaction tx = null;
try
if (this.completedTasks == null)
{
tx = Repository.getUserTransaction(context, true);
tx.begin();
// get the current username
FacesContext context = FacesContext.getCurrentInstance();
User user = Application.getCurrentUser(context);
String userName = ISO9075.encode(user.getUserName());
// get the current in progress tasks for the current user
List<WorkflowTask> tasks = this.workflowService.getAssignedTasks(
userName, WorkflowTaskState.COMPLETED);
// create a list of transient nodes to represent
this.completedTasks = new ArrayList<Node>(tasks.size());
for (WorkflowTask task : tasks)
UserTransaction tx = null;
try
{
Node node = createTask(task);
this.completedTasks.add(node);
tx = Repository.getUserTransaction(context, true);
tx.begin();
if (logger.isDebugEnabled())
logger.debug("Added completed task: " + node);
// get the current in progress tasks for the current user
List<WorkflowTask> tasks = this.workflowService.getAssignedTasks(
userName, WorkflowTaskState.COMPLETED);
// create a list of transient nodes to represent
this.completedTasks = new ArrayList<Node>(tasks.size());
for (WorkflowTask task : tasks)
{
Node node = createTask(task);
this.completedTasks.add(node);
if (logger.isDebugEnabled())
logger.debug("Added completed task: " + node);
}
// commit the changes
tx.commit();
}
// commit the changes
tx.commit();
}
catch (Throwable e)
{
// rollback the transaction
try { if (tx != null) {tx.rollback();} } catch (Exception ex) {}
Utils.addErrorMessage("Failed to get completed tasks: " + e.toString(), e);
catch (Throwable e)
{
// rollback the transaction
try { if (tx != null) {tx.rollback();} } catch (Exception ex) {}
Utils.addErrorMessage("Failed to get completed tasks: " + e.toString(), e);
}
}
return this.completedTasks;
@@ -163,47 +163,6 @@ public class WorkflowBean
// ------------------------------------------------------------------------------
// Helper methods
public static Map<QName, Serializable> prepareTaskParams(Node node)
{
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
// marshal the properties and associations captured by the property sheet
// back into a Map to pass to the workflow service
// go through all the properties in the transient node and add them to
// params map
Map<String, Object> props = node.getProperties();
for (String propName : props.keySet())
{
QName propQName = Repository.resolveToQName(propName);
params.put(propQName, (Serializable)props.get(propName));
}
// go through any associations that have been added to the start task
// and build a list of NodeRefs representing the targets
Map<String, Map<String, AssociationRef>> assocs = node.getAddedAssociations();
for (String assocName : assocs.keySet())
{
QName assocQName = Repository.resolveToQName(assocName);
// get the associations added and create list of targets
Map<String, AssociationRef> addedAssocs = assocs.get(assocName);
List<NodeRef> targets = new ArrayList<NodeRef>(addedAssocs.size());
for (AssociationRef assoc : addedAssocs.values())
{
targets.add(assoc.getTargetRef());
}
// add the targets for this particular association
if (targets.size() > 0)
{
params.put(assocQName, (Serializable)targets);
}
}
return params;
}
/**
* Creates and populates a TransientNode to represent the given
@@ -225,15 +184,6 @@ public class WorkflowBean
node.getProperties().put("type", taskDef.metadata.getTitle());
node.getProperties().put("id", task.id);
// add the name of the source space (if there is one)
NodeRef context = (NodeRef)task.properties.get(WorkflowModel.PROP_CONTEXT);
if (context != null && this.nodeService.exists(context))
{
String name = Repository.getNameForNode(this.nodeService, context);
node.getProperties().put("sourceSpaceName", name);
node.getProperties().put("sourceSpaceId", context.getId());
}
// add extra properties for completed tasks
if (task.state.equals(WorkflowTaskState.COMPLETED))
{
@@ -260,6 +210,9 @@ public class WorkflowBean
// add the workflow instance id and name this taks belongs to
node.getProperties().put("workflowInstanceId", task.path.instance.id);
// add the task itself as a property
node.getProperties().put("workflowTask", task);
}
return node;

View File

@@ -0,0 +1,184 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.web.bean.workflow;
import org.alfresco.repo.workflow.WorkflowInterpreter;
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
/**
* Backing bean to support the Workflow Console
*/
public class WorkflowConsoleBean
{
// command
private String command = "";
private String submittedCommand = "none";
private long duration = 0L;
private String result = null;
// supporting repository services
private WorkflowInterpreter workflowInterpreter;
/**
* @param nodeService node service
*/
public void setWorkflowInterpreter(WorkflowInterpreter workflowInterpreter)
{
this.workflowInterpreter = workflowInterpreter;
}
/**
* Gets the command result
*
* @return result
*/
public String getResult()
{
if (result == null)
{
interpretCommand("help");
}
return result;
}
/**
* Sets the command result
*
* @param result
*/
public void setResult(String result)
{
this.result = result;
}
/**
* Gets the current query
*
* @return query statement
*/
public String getCommand()
{
return command;
}
/**
* Set the current query
*
* @param query query statement
*/
public void setCommand(String command)
{
this.command = command;
}
/**
* Gets the submitted command
*
* @return submitted command
*/
public String getSubmittedCommand()
{
return submittedCommand;
}
/**
* Set the current query
*
* @param query query statement
*/
public void setSubmittedCommand(String submittedCommand)
{
this.submittedCommand = submittedCommand;
}
/**
* Gets the last command duration
*
* @return command duration
*/
public long getDuration()
{
return duration;
}
/**
* Set the current query
*
* @param query query statement
*/
public void setDuration(long duration)
{
this.duration = duration;
}
/**
* Action to submit command
*
* @return next action
*/
public String submitCommand()
{
interpretCommand(command);
return "success";
}
/**
* Gets the current user name
*
* @return user name
*/
public String getCurrentUserName()
{
return workflowInterpreter.getCurrentUserName();
}
/**
* Gets the current workflow definition
*
* @return workflow definition
*/
public String getCurrentWorkflowDef()
{
WorkflowDefinition def = workflowInterpreter.getCurrentWorkflowDef();
return (def == null) ? "None" : def.title + " v" + def.version;
}
/**
* Interpret workflow console command
*
* @param command command
*/
private void interpretCommand(String command)
{
try
{
long startms = System.currentTimeMillis();
String result = workflowInterpreter.interpretCommand(command);
setDuration(System.currentTimeMillis() - startms);
setResult(result);
setCommand("");
setSubmittedCommand(command);
}
catch (Exception e)
{
setResult(e.toString());
}
}
}

View File

@@ -14,22 +14,29 @@
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.web.bean;
package org.alfresco.web.bean.workflow;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.CopyService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.bean.repository.Node;
import org.apache.log4j.Logger;
import org.alfresco.web.bean.repository.Repository;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Helper class for common Simple Workflow functionality.
* Helper class for common Workflow functionality.
* <p>
* This class should be replaced with calls to a WorkflowService once it is available.
*
@@ -37,7 +44,7 @@ import org.apache.log4j.Logger;
*/
public class WorkflowUtil
{
private static Logger logger = Logger.getLogger(WorkflowUtil.class);
private static Log logger = LogFactory.getLog(WorkflowUtil.class);
/**
* Execute the Approve step for the Simple Workflow on a node.
@@ -139,9 +146,14 @@ public class WorkflowUtil
else
{
// copy the document to the specified folder
String qname = QName.createValidLocalName(docNode.getName());
copyService.copy(ref, rejectFolder, ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, qname));
String name = docNode.getName();
String qname = QName.createValidLocalName(name);
NodeRef newNode = copyService.copy(ref, rejectFolder, ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, qname), true);
// the copy service does not copy the name of the node so we
// need to update the property on the copied item
nodeService.setProperty(newNode, ContentModel.PROP_NAME, name);
}
if (logger.isDebugEnabled())
@@ -151,4 +163,60 @@ public class WorkflowUtil
rejectFolder.getId());
}
}
/**
* Prepares the given node for persistence in the workflow engine.
*
* @param node The node to package up for persistence
* @return The map of data representing the node
*/
public static Map<QName, Serializable> prepareTaskParams(Node node)
{
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
// marshal the properties and associations captured by the property sheet
// back into a Map to pass to the workflow service
// go through all the properties in the transient node and add them to
// params map
Map<String, Object> props = node.getProperties();
for (String propName : props.keySet())
{
QName propQName = Repository.resolveToQName(propName);
params.put(propQName, (Serializable)props.get(propName));
}
// go through any associations that have been added to the start task
// and build a list of NodeRefs representing the targets
Map<String, Map<String, AssociationRef>> assocs = node.getAddedAssociations();
for (String assocName : assocs.keySet())
{
QName assocQName = Repository.resolveToQName(assocName);
// get the associations added and create list of targets
Map<String, AssociationRef> addedAssocs = assocs.get(assocName);
List<NodeRef> targets = new ArrayList<NodeRef>(addedAssocs.size());
for (AssociationRef assoc : addedAssocs.values())
{
targets.add(assoc.getTargetRef());
}
// add the targets for this particular association
if (targets.size() > 0)
{
params.put(assocQName, (Serializable)targets);
}
}
// TODO: Deal with child associations if and when we need to support
// them for workflow tasks, for now warn that they are being used
Map childAssocs = node.getAddedChildAssociations();
if (childAssocs.size() > 0)
{
if (logger.isWarnEnabled())
logger.warn("Child associations are present but are not supported for workflow tasks, ignoring...");
}
return params;
}
}