mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged V1.4 to HEAD
svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@3876 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@3925 . git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3927 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,349 @@
|
||||
package org.alfresco.web.ui.repo.component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.MessageFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.context.ResponseWriter;
|
||||
import javax.faces.el.ValueBinding;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowInstance;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.web.app.Application;
|
||||
import org.alfresco.web.bean.repository.Node;
|
||||
import org.alfresco.web.bean.repository.Repository;
|
||||
import org.alfresco.web.ui.common.component.SelfRenderingComponent;
|
||||
|
||||
/**
|
||||
* JSF component that displays information about the workflows a node is involved in.
|
||||
* <p>
|
||||
* The node to show workflow information on.
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class UINodeWorkflowInfo extends SelfRenderingComponent
|
||||
{
|
||||
protected Node value = null;
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Component Impl
|
||||
|
||||
@Override
|
||||
public String getFamily()
|
||||
{
|
||||
return "org.alfresco.faces.NodeWorkflowInfo";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restoreState(FacesContext context, Object state)
|
||||
{
|
||||
Object values[] = (Object[])state;
|
||||
// standard component attributes are restored by the super class
|
||||
super.restoreState(context, values[0]);
|
||||
this.value = (Node)values[1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object saveState(FacesContext context)
|
||||
{
|
||||
Object values[] = new Object[8];
|
||||
// standard component attributes are saved by the super class
|
||||
values[0] = super.saveState(context);
|
||||
values[1] = this.value;
|
||||
return values;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void encodeBegin(FacesContext context) throws IOException
|
||||
{
|
||||
if (!isRendered()) return;
|
||||
|
||||
// get the node to display the information for
|
||||
Node node = getValue();
|
||||
|
||||
if (node != null)
|
||||
{
|
||||
// get the services we need
|
||||
NodeService nodeService = Repository.getServiceRegistry(context).getNodeService();
|
||||
DictionaryService ddService = Repository.getServiceRegistry(context).getDictionaryService();
|
||||
WorkflowService workflowService = Repository.getServiceRegistry(context).getWorkflowService();
|
||||
ResponseWriter out = context.getResponseWriter();
|
||||
ResourceBundle bundle = Application.getBundle(context);
|
||||
|
||||
// render simple workflow info
|
||||
renderSimpleWorkflowInfo(context, node, nodeService, ddService, out, bundle);
|
||||
|
||||
// render advanced workflow info
|
||||
renderAdvancedWorkflowInfo(context, node, nodeService, ddService, workflowService, out, bundle);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encodeEnd(FacesContext context) throws IOException
|
||||
{
|
||||
if (!isRendered()) return;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Strongly typed component property accessors
|
||||
|
||||
/**
|
||||
* Get the value, this will be a node representing a piece of content or a space
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public Node getValue()
|
||||
{
|
||||
ValueBinding vb = getValueBinding("value");
|
||||
if (vb != null)
|
||||
{
|
||||
this.value = (Node)vb.getValue(getFacesContext());
|
||||
}
|
||||
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value, either a space or content node.
|
||||
*
|
||||
* @param value the value
|
||||
*/
|
||||
public void setValue(Node value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Helper methods
|
||||
|
||||
/**
|
||||
* Renders the simple workflow details for the given node.
|
||||
*
|
||||
* @param context Faces context
|
||||
* @param node The node
|
||||
* @param nodeService The NodeService instance
|
||||
* @param ddService The Data Dictionary instance
|
||||
* @param out The response writer
|
||||
* @param bundle Message bundle to get strings from
|
||||
*/
|
||||
protected void renderSimpleWorkflowInfo(FacesContext context, Node node,
|
||||
NodeService nodeService, DictionaryService ddService,
|
||||
ResponseWriter out, ResourceBundle bundle)
|
||||
throws IOException
|
||||
{
|
||||
boolean isContent = true;
|
||||
|
||||
QName type = nodeService.getType(node.getNodeRef());
|
||||
if (ddService.isSubClass(type, ContentModel.TYPE_FOLDER))
|
||||
{
|
||||
isContent = false;
|
||||
}
|
||||
|
||||
// Render HTML for simple workflow
|
||||
if (isContent)
|
||||
{
|
||||
// TODO: for now we only support advanced workflow on content so only
|
||||
// render the simple workflow title if the node is a content node
|
||||
out.write("<div class=\"nodeWorkflowInfoTitle\">");
|
||||
out.write(bundle.getString("simple_workflow"));
|
||||
out.write("</div>");
|
||||
}
|
||||
out.write("<div class=\"nodeWorkflowInfoText\">");
|
||||
|
||||
if (node.hasAspect(ContentModel.ASPECT_SIMPLE_WORKFLOW))
|
||||
{
|
||||
// get the simple workflow aspect properties
|
||||
Map<String, Object> props = node.getProperties();
|
||||
|
||||
String approveStepName = (String)props.get(
|
||||
ContentModel.PROP_APPROVE_STEP.toString());
|
||||
String rejectStepName = (String)props.get(
|
||||
ContentModel.PROP_REJECT_STEP.toString());
|
||||
|
||||
Boolean approveMove = (Boolean)props.get(
|
||||
ContentModel.PROP_APPROVE_MOVE.toString());
|
||||
Boolean rejectMove = (Boolean)props.get(
|
||||
ContentModel.PROP_REJECT_MOVE.toString());
|
||||
|
||||
NodeRef approveFolder = (NodeRef)props.get(
|
||||
ContentModel.PROP_APPROVE_FOLDER.toString());
|
||||
NodeRef rejectFolder = (NodeRef)props.get(
|
||||
ContentModel.PROP_REJECT_FOLDER.toString());
|
||||
|
||||
String approveFolderName = null;
|
||||
String rejectFolderName = null;
|
||||
|
||||
// get the approve folder name
|
||||
if (approveFolder != null)
|
||||
{
|
||||
Node approveNode = new Node(approveFolder);
|
||||
approveFolderName = approveNode.getName();
|
||||
}
|
||||
|
||||
// get the reject folder name
|
||||
if (rejectFolder != null)
|
||||
{
|
||||
Node rejectNode = new Node(rejectFolder);
|
||||
rejectFolderName = rejectNode.getName();
|
||||
}
|
||||
|
||||
// calculate the approve action string
|
||||
String action = null;
|
||||
if (approveMove.booleanValue())
|
||||
{
|
||||
action = Application.getMessage(FacesContext.getCurrentInstance(), "moved");
|
||||
}
|
||||
else
|
||||
{
|
||||
action = Application.getMessage(FacesContext.getCurrentInstance(), "copied");
|
||||
}
|
||||
|
||||
String actionPattern = null;
|
||||
if (isContent)
|
||||
{
|
||||
actionPattern = Application.getMessage(FacesContext.getCurrentInstance(), "document_action");
|
||||
}
|
||||
else
|
||||
{
|
||||
actionPattern = Application.getMessage(FacesContext.getCurrentInstance(), "space_action");
|
||||
}
|
||||
Object[] params = new Object[] {action, approveFolderName, approveStepName};
|
||||
out.write(MessageFormat.format(actionPattern, params));
|
||||
|
||||
// add details of the reject step if there is one
|
||||
if (rejectStepName != null && rejectMove != null && rejectFolderName != null)
|
||||
{
|
||||
if (rejectMove.booleanValue())
|
||||
{
|
||||
action = Application.getMessage(FacesContext.getCurrentInstance(), "moved");
|
||||
}
|
||||
else
|
||||
{
|
||||
action = Application.getMessage(FacesContext.getCurrentInstance(), "copied");
|
||||
}
|
||||
|
||||
out.write(" ");
|
||||
params = new Object[] {action, rejectFolderName, rejectStepName};
|
||||
out.write(MessageFormat.format(actionPattern, params));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// work out which no workflow message to show depending on the node type
|
||||
if (isContent)
|
||||
{
|
||||
out.write(bundle.getString("doc_not_in_simple_workflow"));
|
||||
}
|
||||
else
|
||||
{
|
||||
out.write(bundle.getString("space_not_in_simple_workflow"));
|
||||
}
|
||||
}
|
||||
out.write("</div>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the advanced workflow details for the given node.
|
||||
*
|
||||
* @param context Faces context
|
||||
* @param node The node
|
||||
* @param nodeService The NodeService instance
|
||||
* @param ddService The Data Dictionary instance
|
||||
* @param workflowService The WorkflowService instance
|
||||
* @param out The response writer
|
||||
* @param bundle Message bundle to get strings from
|
||||
*/
|
||||
protected void renderAdvancedWorkflowInfo(FacesContext context, Node node,
|
||||
NodeService nodeService, DictionaryService ddService, WorkflowService workflowService,
|
||||
ResponseWriter out, ResourceBundle bundle)
|
||||
throws IOException
|
||||
{
|
||||
boolean isContent = true;
|
||||
|
||||
QName type = nodeService.getType(node.getNodeRef());
|
||||
if (ddService.isSubClass(type, ContentModel.TYPE_FOLDER))
|
||||
{
|
||||
isContent = false;
|
||||
}
|
||||
|
||||
// TODO: for now we only support advanced workflow on content so don't render
|
||||
// anything for other types
|
||||
if (isContent)
|
||||
{
|
||||
// Render HTML for advanved workflow
|
||||
out.write("<div class=\"nodeWorkflowInfoTitle\">");
|
||||
out.write(bundle.getString("advanced_workflows"));
|
||||
out.write("</div><div class=\"nodeWorkflowInfoText\">");
|
||||
|
||||
List<WorkflowInstance> workflows = workflowService.getWorkflowsForContent(
|
||||
node.getNodeRef(), true);
|
||||
if (workflows != null && workflows.size() > 0)
|
||||
{
|
||||
SimpleDateFormat format = new SimpleDateFormat(bundle.getString("date_pattern"));
|
||||
|
||||
// list out all the workflows the document is part of
|
||||
if (isContent)
|
||||
{
|
||||
out.write(bundle.getString("doc_part_of_advanced_workflows"));
|
||||
}
|
||||
else
|
||||
{
|
||||
out.write(bundle.getString("space_part_of_advanced_workflows"));
|
||||
}
|
||||
out.write(":<br/><ul>");
|
||||
for (WorkflowInstance wi : workflows)
|
||||
{
|
||||
out.write("<li>");
|
||||
out.write(wi.definition.title);
|
||||
if (wi.definition.description != null && wi.definition.description.length() > 0)
|
||||
{
|
||||
out.write(" (");
|
||||
out.write(wi.definition.description);
|
||||
out.write(")");
|
||||
}
|
||||
out.write(" ");
|
||||
if (wi.startDate != null)
|
||||
{
|
||||
out.write(bundle.getString("started_on").toLowerCase());
|
||||
out.write(" ");
|
||||
out.write(format.format(wi.startDate));
|
||||
out.write(" ");
|
||||
}
|
||||
if (wi.initiator != null)
|
||||
{
|
||||
out.write(bundle.getString("by"));
|
||||
out.write(" ");
|
||||
String userName = (String)nodeService.getProperty(wi.initiator,
|
||||
ContentModel.PROP_USERNAME);
|
||||
out.write(userName);
|
||||
out.write(".");
|
||||
}
|
||||
out.write("</li>");
|
||||
}
|
||||
out.write("</ul>");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isContent)
|
||||
{
|
||||
out.write(bundle.getString("doc_not_in_advanced_workflow"));
|
||||
}
|
||||
else
|
||||
{
|
||||
out.write(bundle.getString("space_not_in_advanced_workflow"));
|
||||
}
|
||||
}
|
||||
out.write("</div>");
|
||||
}
|
||||
}
|
||||
}
|
@@ -18,6 +18,7 @@
|
||||
package org.alfresco.web.ui.repo.component.property;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -37,7 +38,9 @@ import org.alfresco.service.cmr.dictionary.AssociationDefinition;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.search.ResultSet;
|
||||
import org.alfresco.service.cmr.search.SearchParameters;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.web.app.Application;
|
||||
@@ -701,7 +704,12 @@ public abstract class BaseAssociationEditor extends UIInput
|
||||
|
||||
if (ContentModel.TYPE_PERSON.equals(nodeService.getType(targetRef)))
|
||||
{
|
||||
out.write((String)nodeService.getProperty(targetRef, ContentModel.PROP_USERNAME));
|
||||
//out.write((String)nodeService.getProperty(targetRef, ContentModel.PROP_USERNAME));
|
||||
Map<QName, Serializable> props = nodeService.getProperties(targetRef);
|
||||
String firstName = (String)props.get(ContentModel.PROP_FIRSTNAME);
|
||||
String lastName = (String)props.get(ContentModel.PROP_LASTNAME);
|
||||
String fullName = firstName + " " + (lastName != null ? lastName : "");
|
||||
out.write(fullName);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -821,21 +829,33 @@ public abstract class BaseAssociationEditor extends UIInput
|
||||
item.getId().equals(currentNode.getId()) == false) ||
|
||||
this.removed.containsKey(item.getId()))
|
||||
{
|
||||
out.write("<option value='");
|
||||
out.write(item.getId());
|
||||
out.write("'>");
|
||||
// if the node represents a person, show the username instead of the name
|
||||
if (ContentModel.TYPE_PERSON.equals(nodeService.getType(item)))
|
||||
{
|
||||
out.write((String)nodeService.getProperty(item, ContentModel.PROP_USERNAME));
|
||||
Map<QName, Serializable> props = nodeService.getProperties(item);
|
||||
String userName = (String)props.get(ContentModel.PROP_USERNAME);
|
||||
if (userName != null && (userName.equals(PermissionService.GUEST_AUTHORITY) == false))
|
||||
{
|
||||
out.write("<option value='");
|
||||
out.write(item.getId());
|
||||
out.write("'>");
|
||||
String firstName = (String)props.get(ContentModel.PROP_FIRSTNAME);
|
||||
String lastName = (String)props.get(ContentModel.PROP_LASTNAME);
|
||||
String fullName = firstName + " " + (lastName != null ? lastName : "");
|
||||
out.write(fullName);
|
||||
out.write("</option>");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
out.write("<option value='");
|
||||
out.write(item.getId());
|
||||
out.write("'>");
|
||||
out.write(Repository.getDisplayPath(nodeService.getPath(item)));
|
||||
out.write("/");
|
||||
out.write(Repository.getNameForNode(nodeService, item));
|
||||
out.write("</option>");
|
||||
}
|
||||
out.write("</option>");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -877,34 +897,52 @@ public abstract class BaseAssociationEditor extends UIInput
|
||||
if (contains != null && contains.length() > 0)
|
||||
{
|
||||
String safeContains = Utils.remove(contains.trim(), "\"");
|
||||
query.append(" AND +@");
|
||||
|
||||
// if the association's target is the person type search on the
|
||||
// username instead of the name property
|
||||
// firstName and lastName properties instead of the name property
|
||||
if (type.equals(ContentModel.TYPE_PERSON.toString()))
|
||||
{
|
||||
String userName = Repository.escapeQName(QName.createQName(
|
||||
NamespaceService.CONTENT_MODEL_1_0_URI, "userName"));
|
||||
query.append(userName);
|
||||
query.append(" AND (@");
|
||||
String firstName = Repository.escapeQName(QName.createQName(
|
||||
NamespaceService.CONTENT_MODEL_1_0_URI, "firstName"));
|
||||
query.append(firstName);
|
||||
query.append(":*" + safeContains + "*");
|
||||
query.append(" OR @");
|
||||
String lastName = Repository.escapeQName(QName.createQName(
|
||||
NamespaceService.CONTENT_MODEL_1_0_URI, "lastName"));
|
||||
query.append(lastName);
|
||||
query.append(":*" + safeContains + "*)");
|
||||
}
|
||||
else
|
||||
{
|
||||
query.append(" AND +@");
|
||||
String nameAttr = Repository.escapeQName(QName.createQName(
|
||||
NamespaceService.CONTENT_MODEL_1_0_URI, "name"));
|
||||
query.append(nameAttr);
|
||||
query.append(":*" + safeContains + "*");
|
||||
}
|
||||
|
||||
query.append(":*" + safeContains + "*");
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Query: " + query.toString());
|
||||
|
||||
SearchParameters searchParams = new SearchParameters();
|
||||
searchParams.addStore(Repository.getStoreRef());
|
||||
searchParams.setLanguage(SearchService.LANGUAGE_LUCENE);
|
||||
searchParams.setQuery(query.toString());
|
||||
|
||||
if (type.equals(ContentModel.TYPE_PERSON.toString()))
|
||||
{
|
||||
searchParams.addSort("@" + ContentModel.PROP_LASTNAME, true);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Added lastname as sort column to query for people");
|
||||
}
|
||||
|
||||
ResultSet results = null;
|
||||
try
|
||||
{
|
||||
results = Repository.getServiceRegistry(context).getSearchService().query(
|
||||
Repository.getStoreRef(), SearchService.LANGUAGE_LUCENE, query.toString());
|
||||
results = Repository.getServiceRegistry(context).getSearchService().query(searchParams);
|
||||
this.availableOptions = results.getNodeRefs();
|
||||
}
|
||||
finally
|
||||
|
Reference in New Issue
Block a user