- Resources can now be added and removed to and from workflow packages

- Added simple search based content selector component to support this

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3628 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2006-08-29 19:39:28 +00:00
parent 93de1bdfba
commit 7878ecd144
9 changed files with 853 additions and 106 deletions

View File

@@ -21,6 +21,7 @@ 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.WorkflowTransition;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.web.app.Application;
@@ -49,9 +50,14 @@ public class ManageWorkItemDialog extends BaseDialogBean
protected WorkflowTask workItem;
protected WorkflowInstance workflowInstance;
protected WorkflowTransition[] transitions;
protected NodeRef workflowPackage;
protected List<Node> resources;
protected WorkItemCompleteResolver completeResolver = new WorkItemCompleteResolver();
protected UIRichList packageItemsRichList;
protected List<String> packageItemsToAdd;
protected List<String> packageItemsToRemove;
protected String[] itemsToAdd;
protected boolean isItemBeingAdded = false;
protected static final String ID_PREFIX = "transition_";
protected static final String CLIENT_ID_PREFIX = "dialog:" + ID_PREFIX;
@@ -66,6 +72,23 @@ public class ManageWorkItemDialog extends BaseDialogBean
{
super.init(parameters);
// reset variables
this.workItem = null;
this.workItemNode = null;
this.workflowInstance = null;
this.transitions = null;
this.workflowPackage = null;
this.resources = null;
this.itemsToAdd = null;
this.packageItemsToAdd = null;
this.packageItemsToRemove = null;
this.isItemBeingAdded = false;
if (this.packageItemsRichList != null)
{
this.packageItemsRichList.setValue(null);
}
// get the task details
String taskId = this.parameters.get("id");
this.workItem = this.workflowService.getTaskById(taskId);
@@ -78,6 +101,22 @@ public class ManageWorkItemDialog extends BaseDialogBean
// get access to the workflow instance for the work item
this.workflowInstance = this.workItem.path.instance;
// setup the workflow package for the task
Serializable obj = this.workItem.properties.get(WorkflowModel.ASSOC_PACKAGE);
// TODO: remove this workaroud where JBPM may return a String and not the NodeRef
if (obj instanceof NodeRef)
{
this.workflowPackage = (NodeRef)obj;
}
else if (obj instanceof String)
{
this.workflowPackage = new NodeRef((String)obj);
}
if (logger.isDebugEnabled())
logger.debug("Found workflow package for work item '" +
this.workItem.id + "': " + this.workflowPackage );
}
}
@@ -86,11 +125,35 @@ public class ManageWorkItemDialog extends BaseDialogBean
throws Exception
{
if (logger.isDebugEnabled())
logger.debug("Saving work item: " + this.workItemNode.getId());
logger.debug("Saving task: " + this.workItem.id);
// prepare the edited parameters for saving
Map<QName, Serializable> params = WorkflowBean.prepareWorkItemParams(this.workItemNode);
// remove any items the user selected to remove
if (this.workflowPackage != null && this.packageItemsToRemove != null &&
this.packageItemsToRemove.size() > 0)
{
for (String removedItem : this.packageItemsToRemove)
{
this.nodeService.removeChild(this.workflowPackage, new NodeRef(removedItem));
}
}
// add any items the user selected to add
if (this.workflowPackage != null && this.packageItemsToAdd != null &&
this.packageItemsToAdd.size() > 0)
{
for (String addedItem : this.packageItemsToAdd)
{
NodeRef addedNodeRef = new NodeRef(addedItem);
this.nodeService.addChild(this.workflowPackage, addedNodeRef,
ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
QName.createValidLocalName((String)this.nodeService.getProperty(
addedNodeRef, ContentModel.PROP_NAME))));
}
}
// update the task with the updated parameters
this.workflowService.updateTask(this.workItem.id, params, null, null);
@@ -200,6 +263,70 @@ public class ManageWorkItemDialog extends BaseDialogBean
return outcome;
}
/**
* Prepares the dialog to allow the user to add an item to the workflow package
*
* @param event The event
*/
public void prepareForAdd(ActionEvent event)
{
this.isItemBeingAdded = true;
}
/**
* Cancels the adding of an item to the workflow package
*
* @param event The event
*/
public void cancelAddPackageItems(ActionEvent event)
{
this.isItemBeingAdded = false;
}
/**
* Adds an item to the workflow package
*
* @param event The event
*/
public void addPackageItems(ActionEvent event)
{
if (this.itemsToAdd != null)
{
if (this.packageItemsToAdd == null)
{
// create the list of items to add if necessary
this.packageItemsToAdd = new ArrayList<String>(this.itemsToAdd.length);
}
for (String item : this.itemsToAdd)
{
// if this item is in the remove list it means it was there originally
// and has now been re-added, as a result we don't need to do anything
// to the original workflow package, therefore remove from the remove list
if (this.packageItemsToRemove != null && this.packageItemsToRemove.contains(item))
{
this.packageItemsToRemove.remove(item);
if (logger.isDebugEnabled())
logger.debug("Removed item from the removed list: " + item);
}
else
{
this.packageItemsToAdd.add(item);
if (logger.isDebugEnabled())
logger.debug("Added item to the added list: " + item);
}
}
// reset the rich list so it re-renders
this.packageItemsRichList.setValue(null);
}
this.isItemBeingAdded = false;
this.itemsToAdd = null;
}
/**
* Removes an item from the workflow package
*
@@ -207,7 +334,34 @@ public class ManageWorkItemDialog extends BaseDialogBean
*/
public void removePackageItem(ActionEvent event)
{
logger.info("remove package item: " + event);
UIActionLink link = (UIActionLink)event.getComponent();
Map<String, String> params = link.getParameterMap();
String nodeRef = new NodeRef(Repository.getStoreRef(), params.get("id")).toString();
if (this.packageItemsToAdd != null && this.packageItemsToAdd.contains(nodeRef))
{
// remove the item from the added list if it was added in this dialog session
this.packageItemsToAdd.remove(nodeRef);
if (logger.isDebugEnabled())
logger.debug("Removed item from the added list: " + nodeRef);
}
else
{
// add the node to the list of items to remove
if (this.packageItemsToRemove == null)
{
this.packageItemsToRemove = new ArrayList<String>(1);
}
this.packageItemsToRemove.add(nodeRef);
if (logger.isDebugEnabled())
logger.debug("Added item to the removed list: " + nodeRef);
}
// reset the rich list so it re-renders
this.packageItemsRichList.setValue(null);
}
/**
@@ -217,77 +371,42 @@ public class ManageWorkItemDialog extends BaseDialogBean
*/
public void togglePackageItemComplete(ActionEvent event)
{
UserTransaction tx = null;
try
{
FacesContext context = FacesContext.getCurrentInstance();
tx = Repository.getUserTransaction(context);
tx.begin();
UIActionLink link = (UIActionLink)event.getComponent();
Map<String, String> params = link.getParameterMap();
// create the node ref for the item we are toggling
NodeRef nodeRef = new NodeRef(Repository.getStoreRef(),
(String)params.get("id"));
// get the existing list of completed items
List<NodeRef> completedItems = (List<NodeRef>)this.workItem.properties.get(
WorkflowModel.PROP_COMPLETED_ITEMS);
if (completedItems == null)
{
// if it doesn't exist yet create the list and add the noderef
completedItems = new ArrayList<NodeRef>(1);
completedItems.add(nodeRef);
this.workItem.properties.put(WorkflowModel.PROP_COMPLETED_ITEMS,
(Serializable)completedItems);
}
else
{
if (completedItems.contains(nodeRef))
{
// the item is already in the list remove it
completedItems.remove(nodeRef);
// NOTE: There is a bug somwehere which causes the list to be
// returned as a byte array instead of a list if an empty
// list is persisted, therefore if the list is now empty
// set the completed items back to null
if (completedItems.size() == 0)
{
this.workItem.properties.put(WorkflowModel.PROP_COMPLETED_ITEMS, null);
}
}
else
{
// the noderef is not in the list yet so just add it
completedItems.add(nodeRef);
}
}
// update the task with the updated parameters
this.workflowService.updateTask(this.workItem.id, this.workItem.properties,
null, null);
// commit the transaction
tx.commit();
// reset the rich list if the change was successful
this.packageItemsRichList.setValue(null);
}
catch (Throwable err)
{
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
this.resources = Collections.<Node>emptyList();
try { if (tx != null) {tx.rollback();} } catch (Exception tex) {}
}
// TODO: implement this!
}
// ------------------------------------------------------------------------------
// Bean Getters and Setters
/**
* Returns a String array of NodeRef's that are being added to the workflow package
*
* @return String array of NodeRef's
*/
public String[] getItemsToAdd()
{
return this.itemsToAdd;
}
/**
* Sets the NodeRef's to add as items to the workflow package
*
* @param itemsToAdd NodeRef's to add to the workflow package
*/
public void setItemsToAdd(String[] itemsToAdd)
{
this.itemsToAdd = itemsToAdd;
}
/**
* Determines whether an item is currently being added to the workflow package
*
* @return true if an item is being added
*/
public boolean isItemBeingAdded()
{
return this.isItemBeingAdded;
}
/**
* Sets the rich list being used for the workflow package items
*
@@ -358,21 +477,9 @@ public class ManageWorkItemDialog extends BaseDialogBean
*/
public List<Node> getResources()
{
NodeRef workflowPackage = null;
Serializable obj = this.workItem.properties.get(WorkflowModel.ASSOC_PACKAGE);
// TODO: remove this workaroud where JBPM may return a String and not the NodeRef
if (obj instanceof NodeRef)
{
workflowPackage = (NodeRef)obj;
}
else if (obj instanceof String)
{
workflowPackage = new NodeRef((String)obj);
}
this.resources = new ArrayList<Node>(4);
if (workflowPackage != null)
if (this.workflowPackage != null)
{
UserTransaction tx = null;
try
@@ -381,12 +488,10 @@ public class ManageWorkItemDialog extends BaseDialogBean
tx = Repository.getUserTransaction(context, true);
tx.begin();
if (logger.isDebugEnabled())
logger.debug("Found workflow package for work item '" +
this.workItem.id + "': " + workflowPackage );
List<ChildAssociationRef> childRefs = this.nodeService.getChildAssocs(workflowPackage,
ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
// get existing workflow package items
List<ChildAssociationRef> childRefs = this.nodeService.getChildAssocs(
this.workflowPackage, ContentModel.ASSOC_CONTAINS,
RegexQNamePattern.MATCH_ALL);
for (ChildAssociationRef ref: childRefs)
{
@@ -408,18 +513,13 @@ public class ManageWorkItemDialog extends BaseDialogBean
if (this.dictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT) ||
ContentModel.TYPE_FILELINK.equals(type))
{
// create our Node representation
MapNode node = new MapNode(nodeRef, this.nodeService, true);
this.browseBean.setupCommonBindingProperties(node);
// add property resolvers to show path information
node.addPropertyResolver("path", this.browseBean.resolverPath);
node.addPropertyResolver("displayPath", this.browseBean.resolverDisplayPath);
// add a property resolver to indicate whether the item has been completed or not
node.addPropertyResolver("completed", this.completeResolver);
this.resources.add(node);
// if the node is not in the removed list then add create the
// client side representation and add to the list
if (this.packageItemsToRemove == null ||
this.packageItemsToRemove.contains(nodeRef.toString()) == false)
{
createAndAddNode(nodeRef);
}
}
}
else
@@ -428,6 +528,31 @@ public class ManageWorkItemDialog extends BaseDialogBean
logger.warn("Found invalid object in database: id = " + nodeRef + ", type = " + type);
}
}
else
{
if (logger.isDebugEnabled())
logger.debug("Ignoring " + nodeRef + " as it has been removed from the repository");
}
}
// now iterate through the items to add list and add them to the list of resources
if (this.packageItemsToAdd != null)
{
for (String newItem : this.packageItemsToAdd)
{
NodeRef nodeRef = new NodeRef(newItem);
if (this.nodeService.exists(nodeRef))
{
// we know the type is correct as this was added as a result of a query
// for all content items so just add the item to the resources list
createAndAddNode(nodeRef);
}
else
{
if (logger.isDebugEnabled())
logger.debug("Ignoring " + nodeRef + " as it has been removed from the repository");
}
}
}
// commit the transaction
@@ -463,6 +588,21 @@ public class ManageWorkItemDialog extends BaseDialogBean
// ------------------------------------------------------------------------------
// Helper methods
protected void createAndAddNode(NodeRef nodeRef)
{
// create our Node representation
MapNode node = new MapNode(nodeRef, this.nodeService, true);
this.browseBean.setupCommonBindingProperties(node);
// add property resolvers to show path information
node.addPropertyResolver("path", this.browseBean.resolverPath);
node.addPropertyResolver("displayPath", this.browseBean.resolverDisplayPath);
// add a property resolver to indicate whether the item has been completed or not
// node.addPropertyResolver("completed", this.completeResolver);
this.resources.add(node);
}
// ------------------------------------------------------------------------------
// Inner classes