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@3987 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4133 . Removed LicenseComponent reference from projects\repository\source\java\org\alfresco\repo\descriptor\DescriptorServiceImpl.java git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4135 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -21,7 +21,6 @@ import javax.faces.context.FacesContext;
|
||||
import org.alfresco.model.ContentModel;
|
||||
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.util.ISO9075;
|
||||
import org.alfresco.web.action.ActionEvaluator;
|
||||
@@ -45,37 +44,28 @@ public class CancelWorkflowEvaluator implements ActionEvaluator
|
||||
public boolean evaluate(Node node)
|
||||
{
|
||||
boolean result = false;
|
||||
|
||||
// get the id of the task
|
||||
String taskId = (String)node.getProperties().get("id");
|
||||
if (taskId != null)
|
||||
FacesContext context = FacesContext.getCurrentInstance();
|
||||
|
||||
// get the task from the node
|
||||
WorkflowTask task = (WorkflowTask)node.getProperties().get("workflowTask");
|
||||
if (task != null)
|
||||
{
|
||||
FacesContext context = FacesContext.getCurrentInstance();
|
||||
|
||||
// get the initiator of the workflow the task belongs to
|
||||
WorkflowService workflowSvc = Repository.getServiceRegistry(
|
||||
context).getWorkflowService();
|
||||
|
||||
WorkflowTask task = workflowSvc.getTaskById(taskId);
|
||||
if (task != null)
|
||||
NodeRef initiator = task.path.instance.initiator;
|
||||
if (initiator != null)
|
||||
{
|
||||
NodeRef initiator = task.path.instance.initiator;
|
||||
if (initiator != null)
|
||||
// find the current username
|
||||
User user = Application.getCurrentUser(context);
|
||||
String currentUserName = ISO9075.encode(user.getUserName());
|
||||
|
||||
// get the username of the initiator
|
||||
NodeService nodeSvc = Repository.getServiceRegistry(
|
||||
context).getNodeService();
|
||||
String userName = (String)nodeSvc.getProperty(initiator, ContentModel.PROP_USERNAME);
|
||||
|
||||
// if the current user started the workflow allow the cancel action
|
||||
if (currentUserName.equals(userName))
|
||||
{
|
||||
// find the current username
|
||||
User user = Application.getCurrentUser(context);
|
||||
String currentUserName = ISO9075.encode(user.getUserName());
|
||||
|
||||
// get the username of the initiator
|
||||
NodeService nodeSvc = Repository.getServiceRegistry(
|
||||
context).getNodeService();
|
||||
String userName = (String)nodeSvc.getProperty(initiator, ContentModel.PROP_USERNAME);
|
||||
|
||||
// if the current user started the workflow allow the cancel action
|
||||
if (currentUserName.equals(userName))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,305 @@
|
||||
/*
|
||||
* 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.app.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.SocketException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.repository.TemplateException;
|
||||
import org.alfresco.service.cmr.repository.TemplateImageResolver;
|
||||
import org.alfresco.service.cmr.repository.TemplateNode;
|
||||
import org.alfresco.service.cmr.repository.TemplateService;
|
||||
import org.alfresco.service.cmr.security.AccessStatus;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.web.ui.common.Utils;
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
/**
|
||||
* Base class for the template content servlets. Provides common
|
||||
* processing for the request.
|
||||
*
|
||||
* @see org.alfresco.web.app.servlet.TemplateContentServlet
|
||||
* @see org.alfresco.web.app.servlet.GuestTemplateContentServlet
|
||||
*
|
||||
* @author Kevin Roast
|
||||
* @author gavinc
|
||||
*/
|
||||
public abstract class BaseTemplateContentServlet extends BaseServlet
|
||||
{
|
||||
private static final String MIMETYPE_HTML = "text/html";
|
||||
|
||||
private static final long serialVersionUID = -4123407921997235977L;
|
||||
|
||||
private static final String ARG_MIMETYPE = "mimetype";
|
||||
private static final String ARG_TEMPLATE_PATH = "templatePath";
|
||||
private static final String ARG_CONTEXT_PATH = "contextPath";
|
||||
|
||||
/**
|
||||
* Gets the logger to use for this request.
|
||||
* <p>
|
||||
* This will show all debug entries from this class as though they
|
||||
* came from the subclass.
|
||||
*
|
||||
* @return The logger
|
||||
*/
|
||||
protected abstract Log getLogger();
|
||||
|
||||
/**
|
||||
* Builds the FreeMarker model
|
||||
*
|
||||
* @param services Service Registry instance
|
||||
* @param req Http request
|
||||
* @param templateRef The node ref of the template to process
|
||||
* @return The FreeMarker model
|
||||
*/
|
||||
protected abstract Map<String, Object> buildModel(ServiceRegistry services,
|
||||
HttpServletRequest req, NodeRef templateRef);
|
||||
|
||||
/**
|
||||
* Processes the template request using the current context i.e. no
|
||||
* authentication checks are made, it is presumed they have already
|
||||
* been done.
|
||||
*
|
||||
* @param req The HTTP request
|
||||
* @param res The HTTP response
|
||||
* @param redirectToLogin Flag to determine whether to redirect to the login
|
||||
* page if the user does not have the correct permissions
|
||||
*/
|
||||
protected void processTemplateRequest(HttpServletRequest req, HttpServletResponse res,
|
||||
boolean redirectToLogin) throws ServletException, IOException
|
||||
{
|
||||
Log logger = getLogger();
|
||||
String uri = req.getRequestURI();
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
String queryString = req.getQueryString();
|
||||
logger.debug("Processing URL: " + uri +
|
||||
((queryString != null && queryString.length() > 0) ? ("?" + queryString) : ""));
|
||||
}
|
||||
|
||||
uri = uri.substring(req.getContextPath().length());
|
||||
StringTokenizer t = new StringTokenizer(uri, "/");
|
||||
int tokenCount = t.countTokens();
|
||||
|
||||
t.nextToken(); // skip servlet name
|
||||
|
||||
NodeRef nodeRef = null;
|
||||
NodeRef templateRef = null;
|
||||
|
||||
String contentPath = req.getParameter(ARG_CONTEXT_PATH);
|
||||
if (contentPath != null && contentPath.length() != 0)
|
||||
{
|
||||
// process the name based path to resolve the NodeRef
|
||||
PathRefInfo pathInfo = resolveNamePath(getServletContext(), contentPath);
|
||||
|
||||
nodeRef = pathInfo.NodeRef;
|
||||
}
|
||||
else if (tokenCount > 3)
|
||||
{
|
||||
// get NodeRef to the content from the URL elements
|
||||
StoreRef storeRef = new StoreRef(t.nextToken(), t.nextToken());
|
||||
nodeRef = new NodeRef(storeRef, t.nextToken());
|
||||
}
|
||||
|
||||
// get NodeRef to the template if supplied
|
||||
String templatePath = req.getParameter(ARG_TEMPLATE_PATH);
|
||||
if (templatePath != null && templatePath.length() != 0)
|
||||
{
|
||||
// process the name based path to resolve the NodeRef
|
||||
PathRefInfo pathInfo = resolveNamePath(getServletContext(), templatePath);
|
||||
|
||||
templateRef = pathInfo.NodeRef;
|
||||
}
|
||||
else if (tokenCount >= 7)
|
||||
{
|
||||
StoreRef storeRef = new StoreRef(t.nextToken(), t.nextToken());
|
||||
templateRef = new NodeRef(storeRef, t.nextToken());
|
||||
}
|
||||
|
||||
// if no context is specified, use the template itself
|
||||
// TODO: should this default to something else?
|
||||
if (nodeRef == null && templateRef != null)
|
||||
{
|
||||
nodeRef = templateRef;
|
||||
}
|
||||
|
||||
if (nodeRef == null)
|
||||
{
|
||||
throw new TemplateException("Not enough elements supplied in URL or no 'path' argument specified.");
|
||||
}
|
||||
|
||||
// get the services we need to retrieve the content
|
||||
ServiceRegistry serviceRegistry = getServiceRegistry(getServletContext());
|
||||
NodeService nodeService = serviceRegistry.getNodeService();
|
||||
TemplateService templateService = serviceRegistry.getTemplateService();
|
||||
PermissionService permissionService = serviceRegistry.getPermissionService();
|
||||
|
||||
// check that the user has at least READ access on any nodes - else redirect to the login page
|
||||
if (permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED ||
|
||||
(templateRef != null && permissionService.hasPermission(templateRef, PermissionService.READ) == AccessStatus.DENIED))
|
||||
{
|
||||
if (redirectToLogin)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Redirecting to login page...");
|
||||
|
||||
redirectToLoginPage(req, res, getServletContext());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Returning 403 Forbidden error...");
|
||||
|
||||
res.sendError(HttpServletResponse.SC_FORBIDDEN);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
String mimetype = MIMETYPE_HTML;
|
||||
if (req.getParameter(ARG_MIMETYPE) != null)
|
||||
{
|
||||
mimetype = req.getParameter(ARG_MIMETYPE);
|
||||
}
|
||||
res.setContentType(mimetype);
|
||||
|
||||
try
|
||||
{
|
||||
UserTransaction txn = null;
|
||||
try
|
||||
{
|
||||
txn = serviceRegistry.getTransactionService().getUserTransaction(true);
|
||||
txn.begin();
|
||||
|
||||
// if template not supplied, then use the default against the node
|
||||
if (templateRef == null)
|
||||
{
|
||||
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_TEMPLATABLE))
|
||||
{
|
||||
templateRef = (NodeRef)nodeService.getProperty(nodeRef, ContentModel.PROP_TEMPLATE);
|
||||
}
|
||||
if (templateRef == null)
|
||||
{
|
||||
throw new TemplateException("Template reference not set against node or not supplied in URL.");
|
||||
}
|
||||
}
|
||||
|
||||
// create the model - put the supplied noderef in as space/document as appropriate
|
||||
Object model = getModel(serviceRegistry, req, templateRef, nodeRef);
|
||||
|
||||
// process the template against the node content directly to the response output stream
|
||||
// assuming the repo is capable of streaming in chunks, this should allow large files
|
||||
// to be streamed directly to the browser response stream.
|
||||
try
|
||||
{
|
||||
templateService.processTemplate(
|
||||
null,
|
||||
templateRef.toString(),
|
||||
model,
|
||||
res.getWriter());
|
||||
|
||||
// commit the transaction
|
||||
txn.commit();
|
||||
}
|
||||
catch (SocketException e)
|
||||
{
|
||||
if (e.getMessage().contains("ClientAbortException"))
|
||||
{
|
||||
// the client cut the connection - our mission was accomplished apart from a little error message
|
||||
logger.error("Client aborted stream read:\n node: " + nodeRef + "\n template: " + templateRef);
|
||||
try { if (txn != null) {txn.rollback();} } catch (Exception tex) {}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable txnErr)
|
||||
{
|
||||
try { if (txn != null) {txn.rollback();} } catch (Exception tex) {}
|
||||
throw txnErr;
|
||||
}
|
||||
}
|
||||
catch (Throwable err)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Error during template servlet processing: " + err.getMessage(), err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the model that to process the template against.
|
||||
* <p>
|
||||
* The model includes the usual template root objects such as 'companyhome', 'userhome',
|
||||
* 'person' and also includes the node specified on the servlet URL as 'space' and 'document'
|
||||
*
|
||||
* @param services ServiceRegistry required for TemplateNode construction
|
||||
* @param req Http request - for accessing Session and url args
|
||||
* @param templateRef NodeRef of the template itself
|
||||
* @param nodeRef NodeRef of the space/document to process template against
|
||||
*
|
||||
* @return an object model ready for executing template against
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private Object getModel(ServiceRegistry services, HttpServletRequest req, NodeRef templateRef, NodeRef nodeRef)
|
||||
{
|
||||
// build FreeMarker default model and merge
|
||||
Map<String, Object> root = buildModel(services, req, templateRef);
|
||||
|
||||
// put the current NodeRef in as "space" and "document"
|
||||
TemplateNode node = new TemplateNode(nodeRef, services, this.imageResolver);
|
||||
root.put("space", node);
|
||||
root.put("document", node);
|
||||
|
||||
// add URL arguments as a map called 'args' to the root of the model
|
||||
Map<String, String> args = new HashMap<String, String>(8, 1.0f);
|
||||
Enumeration names = req.getParameterNames();
|
||||
while (names.hasMoreElements())
|
||||
{
|
||||
String name = (String)names.nextElement();
|
||||
args.put(name, req.getParameter(name));
|
||||
}
|
||||
root.put("args", args);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
/** Template Image resolver helper */
|
||||
private TemplateImageResolver imageResolver = new TemplateImageResolver()
|
||||
{
|
||||
public String resolveImagePathForName(String filename, boolean small)
|
||||
{
|
||||
return Utils.getFileTypeImage(getServletContext(), filename, small);
|
||||
}
|
||||
};
|
||||
}
|
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* 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.app.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.web.bean.repository.User;
|
||||
import org.alfresco.web.ui.repo.component.template.DefaultModelHelper;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
|
||||
/**
|
||||
* Servlet responsible for streaming content from a template processed against a node directly
|
||||
* to the response stream.
|
||||
* <p>
|
||||
* The URL to the servlet should be generated thus:
|
||||
* <pre>/alfresco/template/workspace/SpacesStore/0000-0000-0000-0000</pre>
|
||||
* or
|
||||
* <pre>/alfresco/template/workspace/SpacesStore/0000-0000-0000-0000/workspace/SpacesStore/0000-0000-0000-0000</pre>
|
||||
* or
|
||||
* <pre>/alfresco/template?templatePath=/Company%20Home/Data%20Dictionary/Presentation%20Templates/doc_info.ftl&contextPath=/Company%20Home/mydoc.txt</pre>
|
||||
* <p>
|
||||
* The store protocol, followed by the store ID, followed by the content Node Id used to
|
||||
* identify the node to execute the default template for. The second set of elements encode
|
||||
* the store and node Id of the template to used if a default is not set or not requested. Instead
|
||||
* of using NodeRef references to the template and context, path arguments can be used. The URL args
|
||||
* of 'templatePath' and 'contextPath' can be used instead to specify name based encoded Paths to the
|
||||
* template and its context.
|
||||
* <p>
|
||||
* The URL may be followed by a 'mimetype' argument specifying the mimetype to return the result as
|
||||
* on the stream. Otherwise it is assumed that HTML is the default response mimetype.
|
||||
* <p>
|
||||
* Like most Alfresco servlets, the URL may be followed by a valid 'ticket' argument for authentication:
|
||||
* ?ticket=1234567890
|
||||
* <p>
|
||||
* And/or also followed by the "?guest=true" argument to force guest access login for the URL. If the
|
||||
* guest=true parameter is used the current session will be logged out and the guest user logged in.
|
||||
* Therefore upon completion of this request the current user will be "guest".
|
||||
* <p>
|
||||
* This servlet only accesses content available to the guest user. If the guest user does not
|
||||
* have access to the requested a 401 Forbidden response is returned to the caller.
|
||||
* <p>
|
||||
* This servlet does not effect the current session, therefore if guest access is required to a
|
||||
* resource this servlet can be used without logging out the current user.
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class GuestTemplateContentServlet extends BaseTemplateContentServlet
|
||||
{
|
||||
private static final long serialVersionUID = -2510767849932627519L;
|
||||
|
||||
private static final Log logger = LogFactory.getLog(GuestTemplateContentServlet.class);
|
||||
|
||||
private static final String DEFAULT_URL = "/guestTemplate/{0}/{1}/{2}";
|
||||
private static final String TEMPLATE_URL = "/guestTemplate/{0}/{1}/{2}/{3}/{4}/{5}";
|
||||
|
||||
@Override
|
||||
protected Log getLogger()
|
||||
{
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> buildModel(ServiceRegistry services, HttpServletRequest req,
|
||||
NodeRef templateRef)
|
||||
{
|
||||
// setup the guest user to pass to the build model helper method
|
||||
AuthenticationService auth = (AuthenticationService)services.getAuthenticationService();
|
||||
PersonService personService = (PersonService)services.getPersonService();
|
||||
NodeService nodeService = (NodeService)services.getNodeService();
|
||||
|
||||
NodeRef guestRef = personService.getPerson(PermissionService.GUEST_AUTHORITY);
|
||||
User guestUser = new User(PermissionService.GUEST_AUTHORITY, auth.getCurrentTicket(), guestRef);
|
||||
NodeRef guestHomeRef = (NodeRef)nodeService.getProperty(guestRef, ContentModel.PROP_HOMEFOLDER);
|
||||
if (nodeService.exists(guestHomeRef) == false)
|
||||
{
|
||||
throw new InvalidNodeRefException(guestHomeRef);
|
||||
}
|
||||
guestUser.setHomeSpaceId(guestHomeRef.getId());
|
||||
|
||||
// build the default model
|
||||
return DefaultModelHelper.buildDefaultModel(services, guestUser, templateRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
protected void service(HttpServletRequest req, HttpServletResponse res)
|
||||
throws ServletException, IOException
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
String queryString = req.getQueryString();
|
||||
logger.debug("Setting up guest access to URL: " + req.getRequestURI() +
|
||||
((queryString != null && queryString.length() > 0) ? ("?" + queryString) : ""));
|
||||
}
|
||||
|
||||
TemplateContentWork tcw = new TemplateContentWork(req, res);
|
||||
AuthenticationUtil.runAs(tcw, PermissionService.GUEST_AUTHORITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to generate a URL to process a template against a node.
|
||||
* <p>
|
||||
* The result of the template is supplied returned as the response.
|
||||
*
|
||||
* @param nodeRef NodeRef of the content node to generate URL for (cannot be null)
|
||||
* @param templateRef NodeRef of the template to process against, or null to use default
|
||||
*
|
||||
* @return URL to process the template
|
||||
*/
|
||||
public final static String generateURL(NodeRef nodeRef, NodeRef templateRef)
|
||||
{
|
||||
if (templateRef == null)
|
||||
{
|
||||
return MessageFormat.format(DEFAULT_URL, new Object[] {
|
||||
nodeRef.getStoreRef().getProtocol(),
|
||||
nodeRef.getStoreRef().getIdentifier(),
|
||||
nodeRef.getId() } );
|
||||
}
|
||||
else
|
||||
{
|
||||
return MessageFormat.format(TEMPLATE_URL, new Object[] {
|
||||
nodeRef.getStoreRef().getProtocol(),
|
||||
nodeRef.getStoreRef().getIdentifier(),
|
||||
nodeRef.getId(),
|
||||
templateRef.getStoreRef().getProtocol(),
|
||||
templateRef.getStoreRef().getIdentifier(),
|
||||
templateRef.getId()} );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class to wrap the call to processTemplateRequest.
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class TemplateContentWork implements RunAsWork<Object>
|
||||
{
|
||||
private HttpServletRequest req = null;
|
||||
private HttpServletResponse res = null;
|
||||
|
||||
public TemplateContentWork(HttpServletRequest req, HttpServletResponse res)
|
||||
{
|
||||
this.req = req;
|
||||
this.res = res;
|
||||
}
|
||||
|
||||
public Object doWork() throws Exception
|
||||
{
|
||||
processTemplateRequest(this.req, this.res, false);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,55 +1,65 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2005, JBoss Inc., and individual contributors as indicated
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jbpm.webapp.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.jbpm.JbpmContext;
|
||||
import org.jbpm.graph.def.ProcessDefinition;
|
||||
|
||||
public class ProcessImageServlet extends HttpServlet {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
long processDefinitionId = Long.parseLong( request.getParameter( "definitionId" ) );
|
||||
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
|
||||
ProcessDefinition processDefinition = jbpmContext.getGraphSession().loadProcessDefinition(processDefinitionId);
|
||||
byte[] bytes = processDefinition.getFileDefinition().getBytes("processimage.jpg");
|
||||
OutputStream out = response.getOutputStream();
|
||||
out.write(bytes);
|
||||
out.flush();
|
||||
|
||||
// leave this in. it is in case we want to set the mime type later.
|
||||
// get the mime type
|
||||
// String contentType = URLConnection.getFileNameMap().getContentTypeFor( fileName );
|
||||
// set the content type (=mime type)
|
||||
// response.setContentType( contentType );
|
||||
}
|
||||
}
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2005, JBoss Inc., and individual contributors as indicated
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.alfresco.web.app.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.jbpm.JbpmContext;
|
||||
import org.jbpm.graph.def.ProcessDefinition;
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
// TODO: DC: Tidy up
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
|
||||
|
||||
public class JBPMProcessImageServlet extends HttpServlet {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
long processDefinitionId = Long.parseLong( request.getParameter( "definitionId" ) );
|
||||
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
|
||||
ProcessDefinition processDefinition = jbpmContext.getGraphSession().loadProcessDefinition(processDefinitionId);
|
||||
byte[] bytes = processDefinition.getFileDefinition().getBytes("processimage.jpg");
|
||||
OutputStream out = response.getOutputStream();
|
||||
out.write(bytes);
|
||||
out.flush();
|
||||
|
||||
// leave this in. it is in case we want to set the mime type later.
|
||||
// get the mime type
|
||||
// String contentType = URLConnection.getFileNameMap().getContentTypeFor( fileName );
|
||||
// set the content type (=mime type)
|
||||
// response.setContentType( contentType );
|
||||
}
|
||||
}
|
@@ -17,32 +17,16 @@
|
||||
package org.alfresco.web.app.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.SocketException;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.repository.TemplateException;
|
||||
import org.alfresco.service.cmr.repository.TemplateImageResolver;
|
||||
import org.alfresco.service.cmr.repository.TemplateNode;
|
||||
import org.alfresco.service.cmr.repository.TemplateService;
|
||||
import org.alfresco.service.cmr.security.AccessStatus;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.web.app.Application;
|
||||
import org.alfresco.web.ui.common.Utils;
|
||||
import org.alfresco.web.ui.repo.component.template.DefaultModelHelper;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -71,24 +55,37 @@ import org.apache.commons.logging.LogFactory;
|
||||
* Like most Alfresco servlets, the URL may be followed by a valid 'ticket' argument for authentication:
|
||||
* ?ticket=1234567890
|
||||
* <p>
|
||||
* And/or also followed by the "?guest=true" argument to force guest access login for the URL.
|
||||
* And/or also followed by the "?guest=true" argument to force guest access login for the URL. If the
|
||||
* guest=true parameter is used the current session will be logged out and the guest user logged in.
|
||||
* Therefore upon completion of this request the current user will be "guest".
|
||||
* <p>
|
||||
* If the user attempting the request is not authorised to access the requested node the login page
|
||||
* will be redirected to.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public class TemplateContentServlet extends BaseServlet
|
||||
{
|
||||
private static final String MIMETYPE_HTML = "text/html";
|
||||
public class TemplateContentServlet extends BaseTemplateContentServlet
|
||||
{
|
||||
private static final long serialVersionUID = -2510767849932627519L;
|
||||
|
||||
private static final long serialVersionUID = -4123407921997235977L;
|
||||
|
||||
private static Log logger = LogFactory.getLog(TemplateContentServlet.class);
|
||||
private static final Log logger = LogFactory.getLog(TemplateContentServlet.class);
|
||||
|
||||
private static final String DEFAULT_URL = "/template/{0}/{1}/{2}";
|
||||
private static final String TEMPLATE_URL = "/template/{0}/{1}/{2}/{3}/{4}/{5}";
|
||||
|
||||
private static final String ARG_MIMETYPE = "mimetype";
|
||||
private static final String ARG_TEMPLATE_PATH = "templatePath";
|
||||
private static final String ARG_CONTEXT_PATH = "contextPath";
|
||||
@Override
|
||||
protected Log getLogger()
|
||||
{
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> buildModel(ServiceRegistry services, HttpServletRequest req,
|
||||
NodeRef templateRef)
|
||||
{
|
||||
return DefaultModelHelper.buildDefaultModel(services,
|
||||
Application.getCurrentUser(req.getSession()), templateRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
@@ -96,12 +93,10 @@ public class TemplateContentServlet extends BaseServlet
|
||||
protected void service(HttpServletRequest req, HttpServletResponse res)
|
||||
throws ServletException, IOException
|
||||
{
|
||||
String uri = req.getRequestURI();
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
String queryString = req.getQueryString();
|
||||
logger.debug("Processing URL: " + uri +
|
||||
logger.debug("Authenticating request to URL: " + req.getRequestURI() +
|
||||
((queryString != null && queryString.length() > 0) ? ("?" + queryString) : ""));
|
||||
}
|
||||
|
||||
@@ -111,189 +106,9 @@ public class TemplateContentServlet extends BaseServlet
|
||||
return;
|
||||
}
|
||||
|
||||
uri = uri.substring(req.getContextPath().length());
|
||||
StringTokenizer t = new StringTokenizer(uri, "/");
|
||||
int tokenCount = t.countTokens();
|
||||
|
||||
t.nextToken(); // skip servlet name
|
||||
|
||||
NodeRef nodeRef = null;
|
||||
NodeRef templateRef = null;
|
||||
|
||||
String contentPath = req.getParameter(ARG_CONTEXT_PATH);
|
||||
if (contentPath != null && contentPath.length() != 0)
|
||||
{
|
||||
// process the name based path to resolve the NodeRef
|
||||
PathRefInfo pathInfo = resolveNamePath(getServletContext(), contentPath);
|
||||
|
||||
nodeRef = pathInfo.NodeRef;
|
||||
}
|
||||
else if (tokenCount > 3)
|
||||
{
|
||||
// get NodeRef to the content from the URL elements
|
||||
StoreRef storeRef = new StoreRef(t.nextToken(), t.nextToken());
|
||||
nodeRef = new NodeRef(storeRef, t.nextToken());
|
||||
}
|
||||
|
||||
// get NodeRef to the template if supplied
|
||||
String templatePath = req.getParameter(ARG_TEMPLATE_PATH);
|
||||
if (templatePath != null && templatePath.length() != 0)
|
||||
{
|
||||
// process the name based path to resolve the NodeRef
|
||||
PathRefInfo pathInfo = resolveNamePath(getServletContext(), templatePath);
|
||||
|
||||
templateRef = pathInfo.NodeRef;
|
||||
}
|
||||
else if (tokenCount >= 7)
|
||||
{
|
||||
StoreRef storeRef = new StoreRef(t.nextToken(), t.nextToken());
|
||||
templateRef = new NodeRef(storeRef, t.nextToken());
|
||||
}
|
||||
|
||||
// if no context is specified, use the template itself
|
||||
// TODO: should this default to something else?
|
||||
if (nodeRef == null && templateRef != null)
|
||||
{
|
||||
nodeRef = templateRef;
|
||||
}
|
||||
|
||||
if (nodeRef == null)
|
||||
{
|
||||
throw new TemplateException("Not enough elements supplied in URL or no 'path' argument specified.");
|
||||
}
|
||||
|
||||
// get the services we need to retrieve the content
|
||||
ServiceRegistry serviceRegistry = getServiceRegistry(getServletContext());
|
||||
NodeService nodeService = serviceRegistry.getNodeService();
|
||||
TemplateService templateService = serviceRegistry.getTemplateService();
|
||||
PermissionService permissionService = serviceRegistry.getPermissionService();
|
||||
|
||||
// check that the user has at least READ access on any nodes - else redirect to the login page
|
||||
if (permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED ||
|
||||
(templateRef != null && permissionService.hasPermission(templateRef, PermissionService.READ) == AccessStatus.DENIED))
|
||||
{
|
||||
redirectToLoginPage(req, res, getServletContext());
|
||||
return;
|
||||
}
|
||||
|
||||
String mimetype = MIMETYPE_HTML;
|
||||
if (req.getParameter(ARG_MIMETYPE) != null)
|
||||
{
|
||||
mimetype = req.getParameter(ARG_MIMETYPE);
|
||||
}
|
||||
res.setContentType(mimetype);
|
||||
|
||||
try
|
||||
{
|
||||
UserTransaction txn = null;
|
||||
try
|
||||
{
|
||||
txn = serviceRegistry.getTransactionService().getUserTransaction(true);
|
||||
txn.begin();
|
||||
|
||||
// if template not supplied, then use the default against the node
|
||||
if (templateRef == null)
|
||||
{
|
||||
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_TEMPLATABLE))
|
||||
{
|
||||
templateRef = (NodeRef)nodeService.getProperty(nodeRef, ContentModel.PROP_TEMPLATE);
|
||||
}
|
||||
if (templateRef == null)
|
||||
{
|
||||
throw new TemplateException("Template reference not set against node or not supplied in URL.");
|
||||
}
|
||||
}
|
||||
|
||||
// create the model - put the supplied noderef in as space/document as appropriate
|
||||
Object model = getModel(serviceRegistry, req, templateRef, nodeRef);
|
||||
|
||||
// process the template against the node content directly to the response output stream
|
||||
// assuming the repo is capable of streaming in chunks, this should allow large files
|
||||
// to be streamed directly to the browser response stream.
|
||||
try
|
||||
{
|
||||
templateService.processTemplate(
|
||||
null,
|
||||
templateRef.toString(),
|
||||
model,
|
||||
res.getWriter());
|
||||
|
||||
// commit the transaction
|
||||
txn.commit();
|
||||
}
|
||||
catch (SocketException e)
|
||||
{
|
||||
if (e.getMessage().contains("ClientAbortException"))
|
||||
{
|
||||
// the client cut the connection - our mission was accomplished apart from a little error message
|
||||
logger.error("Client aborted stream read:\n node: " + nodeRef + "\n template: " + templateRef);
|
||||
try { if (txn != null) {txn.rollback();} } catch (Exception tex) {}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable txnErr)
|
||||
{
|
||||
try { if (txn != null) {txn.rollback();} } catch (Exception tex) {}
|
||||
throw txnErr;
|
||||
}
|
||||
}
|
||||
catch (Throwable err)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Error during template servlet processing: " + err.getMessage(), err);
|
||||
}
|
||||
processTemplateRequest(req, res, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the model that to process the template against.
|
||||
* <p>
|
||||
* The model includes the usual template root objects such as 'companyhome', 'userhome',
|
||||
* 'person' and also includes the node specified on the servlet URL as 'space' and 'document'
|
||||
*
|
||||
* @param services ServiceRegistry required for TemplateNode construction
|
||||
* @param req Http request - for accessing Session and url args
|
||||
* @param templateRef NodeRef of the template itself
|
||||
* @param nodeRef NodeRef of the space/document to process template against
|
||||
*
|
||||
* @return an object model ready for executing template against
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private Object getModel(ServiceRegistry services, HttpServletRequest req, NodeRef templateRef, NodeRef nodeRef)
|
||||
{
|
||||
// build FreeMarker default model and merge
|
||||
Map root = DefaultModelHelper.buildDefaultModel(
|
||||
services, Application.getCurrentUser(req.getSession()), templateRef);
|
||||
|
||||
// put the current NodeRef in as "space" and "document"
|
||||
TemplateNode node = new TemplateNode(nodeRef, services, this.imageResolver);
|
||||
root.put("space", node);
|
||||
root.put("document", node);
|
||||
|
||||
// add URL arguments as a map called 'args' to the root of the model
|
||||
Map<String, String> args = new HashMap<String, String>(8, 1.0f);
|
||||
Enumeration names = req.getParameterNames();
|
||||
while (names.hasMoreElements())
|
||||
{
|
||||
String name = (String)names.nextElement();
|
||||
args.put(name, req.getParameter(name));
|
||||
}
|
||||
root.put("args", args);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
/** Template Image resolver helper */
|
||||
private TemplateImageResolver imageResolver = new TemplateImageResolver()
|
||||
{
|
||||
public String resolveImagePathForName(String filename, boolean small)
|
||||
{
|
||||
return Utils.getFileTypeImage(getServletContext(), filename, small);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper to generate a URL to process a template against a node.
|
||||
* <p>
|
||||
|
@@ -20,7 +20,7 @@ import java.util.Map;
|
||||
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.web.bean.WorkflowUtil;
|
||||
import org.alfresco.web.bean.workflow.WorkflowUtil;
|
||||
|
||||
/**
|
||||
* Approve Workflow command implementation
|
||||
|
@@ -20,7 +20,7 @@ import java.util.Map;
|
||||
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.web.bean.WorkflowUtil;
|
||||
import org.alfresco.web.bean.workflow.WorkflowUtil;
|
||||
|
||||
/**
|
||||
* Reject Workflow command implementation
|
||||
|
@@ -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;
|
||||
|
@@ -783,7 +783,8 @@ public class CheckinCheckoutBean
|
||||
}
|
||||
catch (Throwable err)
|
||||
{
|
||||
Utils.addErrorMessage(MSG_ERROR_CANCELCHECKOUT + err.getMessage(), err);
|
||||
Utils.addErrorMessage(Application.getMessage(
|
||||
FacesContext.getCurrentInstance(), MSG_ERROR_CANCELCHECKOUT) + err.getMessage(), err);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@@ -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";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
@@ -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);
|
||||
|
@@ -1,17 +1,13 @@
|
||||
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;
|
||||
@@ -19,7 +15,6 @@ 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 +26,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 +50,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 +100,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 +164,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
|
||||
@@ -260,6 +220,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;
|
||||
|
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -36,6 +36,7 @@ public class ClientConfigElement extends ConfigElementAdapter
|
||||
private int searchMinimum = 3;
|
||||
private boolean forceAndTerms = false;
|
||||
private int searchMaxResults = -1;
|
||||
private int selectorsSearchMaxResults = 500;
|
||||
private String helpUrl = null;
|
||||
private String editLinkType = "http";
|
||||
private String homeSpacePermission = null;
|
||||
@@ -135,6 +136,11 @@ public class ClientConfigElement extends ConfigElementAdapter
|
||||
combinedElement.setSearchMaxResults(newElement.getSearchMaxResults());
|
||||
}
|
||||
|
||||
if (newElement.getSelectorsSearchMaxResults() != combinedElement.getSelectorsSearchMaxResults())
|
||||
{
|
||||
combinedElement.setSelectorsSearchMaxResults(newElement.getSelectorsSearchMaxResults());
|
||||
}
|
||||
|
||||
if (newElement.isShelfVisible() != combinedElement.isShelfVisible())
|
||||
{
|
||||
combinedElement.setShelfVisible(newElement.isShelfVisible());
|
||||
@@ -310,10 +316,9 @@ public class ClientConfigElement extends ConfigElementAdapter
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
public int getSearchMaxResults()
|
||||
{
|
||||
return searchMaxResults;
|
||||
return this.searchMaxResults;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -326,6 +331,29 @@ public class ClientConfigElement extends ConfigElementAdapter
|
||||
{
|
||||
this.searchMaxResults = searchMaxResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* If positive, this will limit the size of the result set from the search
|
||||
* used in selector components.
|
||||
*
|
||||
* @return The maximum number of results to display
|
||||
*/
|
||||
public int getSelectorsSearchMaxResults()
|
||||
{
|
||||
return this.selectorsSearchMaxResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the the result set from a search for the selector components
|
||||
* will be of limited size. If negative it is unlimited, by default,
|
||||
* this is set to 500.
|
||||
*
|
||||
* @param selectorsSearchMaxResults
|
||||
*/
|
||||
/*package*/ void setSelectorsSearchMaxResults(int selectorsSearchMaxResults)
|
||||
{
|
||||
this.selectorsSearchMaxResults = selectorsSearchMaxResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the default Home Space permissions.
|
||||
|
@@ -36,6 +36,7 @@ public class ClientElementReader implements ConfigElementReader
|
||||
public static final String ELEMENT_SEARCHMINIMUM = "search-minimum";
|
||||
public static final String ELEMENT_SEARCHANDTERMS = "search-and-terms";
|
||||
public static final String ELEMENT_SEARCHMAXRESULTS = "search-max-results";
|
||||
public static final String ELEMENT_SELECTORSSEARCHMAXRESULTS = "selectors-search-max-results";
|
||||
public static final String ELEMENT_HOMESPACEPERMISSION = "home-space-permission";
|
||||
public static final String ELEMENT_FROMEMAILADDRESS = "from-email-address";
|
||||
public static final String ELEMENT_SHELFVISIBLE = "shelf-visible";
|
||||
@@ -111,6 +112,14 @@ public class ClientElementReader implements ConfigElementReader
|
||||
configElement.setSearchMaxResults(Integer.parseInt(searchMaxResults.getTextTrim()));
|
||||
}
|
||||
|
||||
// get the selectors search max results size
|
||||
Element selectorsSearchMaxResults = element.element(ELEMENT_SELECTORSSEARCHMAXRESULTS);
|
||||
if (selectorsSearchMaxResults != null)
|
||||
{
|
||||
configElement.setSelectorsSearchMaxResults(
|
||||
Integer.parseInt(selectorsSearchMaxResults.getTextTrim()));
|
||||
}
|
||||
|
||||
// get the default permission for newly created users Home Spaces
|
||||
Element permission = element.element(ELEMENT_HOMESPACEPERMISSION);
|
||||
if (permission != null)
|
||||
|
@@ -30,7 +30,9 @@ import javax.faces.el.ValueBinding;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.search.LimitBy;
|
||||
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.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
@@ -353,15 +355,30 @@ public class UIContentSelector extends UIInput
|
||||
|
||||
query.append(":*" + safeContains + "*");
|
||||
}
|
||||
|
||||
int maxResults = Application.getClientConfig(context).getSelectorsSearchMaxResults();
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Query: " + query.toString());
|
||||
logger.debug("Max results size: " + maxResults);
|
||||
}
|
||||
|
||||
// setup search parameters, including limiting the results
|
||||
SearchParameters searchParams = new SearchParameters();
|
||||
searchParams.addStore(Repository.getStoreRef());
|
||||
searchParams.setLanguage(SearchService.LANGUAGE_LUCENE);
|
||||
searchParams.setQuery(query.toString());
|
||||
if (maxResults > 0)
|
||||
{
|
||||
searchParams.setLimit(maxResults);
|
||||
searchParams.setLimitBy(LimitBy.FINAL_SIZE);
|
||||
}
|
||||
|
||||
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
|
||||
|
@@ -36,6 +36,7 @@ import org.alfresco.model.ContentModel;
|
||||
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.LimitBy;
|
||||
import org.alfresco.service.cmr.search.ResultSet;
|
||||
import org.alfresco.service.cmr.search.SearchParameters;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
@@ -914,13 +915,23 @@ public abstract class BaseAssociationEditor extends UIInput
|
||||
}
|
||||
}
|
||||
|
||||
int maxResults = Application.getClientConfig(context).getSelectorsSearchMaxResults();
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Query: " + query.toString());
|
||||
logger.debug("Max results size: " + maxResults);
|
||||
}
|
||||
|
||||
SearchParameters searchParams = new SearchParameters();
|
||||
searchParams.addStore(Repository.getStoreRef());
|
||||
searchParams.setLanguage(SearchService.LANGUAGE_LUCENE);
|
||||
searchParams.setQuery(query.toString());
|
||||
if (maxResults > 0)
|
||||
{
|
||||
searchParams.setLimit(maxResults);
|
||||
searchParams.setLimitBy(LimitBy.FINAL_SIZE);
|
||||
}
|
||||
|
||||
if (type.equals(ContentModel.TYPE_PERSON.toString()))
|
||||
{
|
||||
|
@@ -176,10 +176,11 @@ public class UIProperty extends PropertySheetItem
|
||||
// if we're in edit mode ensure that we don't allow editing of system properties or scenarios we don't support
|
||||
if (propSheet.inEditMode())
|
||||
{
|
||||
// if we are trying to edit a NodeRef or Path property type set it to read-only as
|
||||
// these are internal properties that shouldn't be edited.
|
||||
// if we are trying to edit a system property type set it to read-only as these are internal
|
||||
// properties that shouldn't be edited.
|
||||
if (typeName.equals(DataTypeDefinition.NODE_REF) || typeName.equals(DataTypeDefinition.PATH) ||
|
||||
typeName.equals(DataTypeDefinition.CONTENT))
|
||||
typeName.equals(DataTypeDefinition.CONTENT) || typeName.equals(DataTypeDefinition.QNAME) ||
|
||||
typeName.equals(DataTypeDefinition.CHILD_ASSOC_REF) || typeName.equals(DataTypeDefinition.ASSOC_REF))
|
||||
{
|
||||
logger.warn("Setting property " + propDef.getName().toString() + " to read-only as it can not be edited");
|
||||
control.getAttributes().put("disabled", Boolean.TRUE);
|
||||
|
@@ -1,244 +1,254 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2005, JBoss Inc., and individual contributors as indicated
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jbpm.webapp.tag;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.jsp.JspException;
|
||||
import javax.servlet.jsp.JspWriter;
|
||||
import javax.servlet.jsp.tagext.TagSupport;
|
||||
|
||||
import org.dom4j.DocumentException;
|
||||
import org.dom4j.DocumentHelper;
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.XPath;
|
||||
import org.dom4j.xpath.DefaultXPath;
|
||||
import org.jbpm.JbpmContext;
|
||||
import org.jbpm.file.def.FileDefinition;
|
||||
import org.jbpm.graph.def.ProcessDefinition;
|
||||
import org.jbpm.graph.exe.Token;
|
||||
import org.jbpm.taskmgmt.exe.TaskInstance;
|
||||
|
||||
public class ProcessImageTag extends TagSupport {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private long taskInstanceId = -1;
|
||||
private long tokenInstanceId = -1;
|
||||
|
||||
private byte[] gpdBytes = null;
|
||||
private byte[] imageBytes = null;
|
||||
private Token currentToken = null;
|
||||
private ProcessDefinition processDefinition = null;
|
||||
|
||||
static String currentTokenColor = "red";
|
||||
static String childTokenColor = "blue";
|
||||
static String tokenNameColor = "blue";
|
||||
|
||||
|
||||
public void release() {
|
||||
taskInstanceId = -1;
|
||||
gpdBytes = null;
|
||||
imageBytes = null;
|
||||
currentToken = null;
|
||||
}
|
||||
|
||||
public int doEndTag() throws JspException {
|
||||
try {
|
||||
initialize();
|
||||
retrieveByteArrays();
|
||||
if (gpdBytes != null && imageBytes != null) {
|
||||
writeTable();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new JspException("table couldn't be displayed", e);
|
||||
} catch (DocumentException e) {
|
||||
e.printStackTrace();
|
||||
throw new JspException("table couldn't be displayed", e);
|
||||
}
|
||||
release();
|
||||
return EVAL_PAGE;
|
||||
}
|
||||
|
||||
private void retrieveByteArrays() {
|
||||
try {
|
||||
FileDefinition fileDefinition = processDefinition.getFileDefinition();
|
||||
gpdBytes = fileDefinition.getBytes("gpd.xml");
|
||||
imageBytes = fileDefinition.getBytes("processimage.jpg");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void writeTable() throws IOException, DocumentException {
|
||||
|
||||
int borderWidth = 4;
|
||||
Element rootDiagramElement = DocumentHelper.parseText(new String(gpdBytes)).getRootElement();
|
||||
int[] boxConstraint;
|
||||
int[] imageDimension = extractImageDimension(rootDiagramElement);
|
||||
String imageLink = "/alfresco/processimage?definitionId=" + processDefinition.getId();
|
||||
JspWriter jspOut = pageContext.getOut();
|
||||
|
||||
if (tokenInstanceId > 0) {
|
||||
|
||||
List allTokens = new ArrayList();
|
||||
walkTokens(currentToken, allTokens);
|
||||
|
||||
jspOut.println("<div style='position:relative; background-image:url(" + imageLink + "); width: " + imageDimension[0] + "px; height: " + imageDimension[1] + "px;'>");
|
||||
|
||||
for (int i = 0; i < allTokens.size(); i++)
|
||||
{
|
||||
Token token = (Token) allTokens.get(i);
|
||||
|
||||
//check how many tokens are on teh same level (= having the same parent)
|
||||
int offset = i;
|
||||
if(i > 0) {
|
||||
while(offset > 0 && ((Token) allTokens.get(offset - 1)).getParent().equals(token.getParent())) {
|
||||
offset--;
|
||||
}
|
||||
}
|
||||
boxConstraint = extractBoxConstraint(rootDiagramElement, token);
|
||||
|
||||
//Adjust for borders
|
||||
//boxConstraint[2]-=borderWidth*2;
|
||||
//boxConstraint[3]-=borderWidth*2;
|
||||
|
||||
jspOut.println("<div style='position:absolute; left: "+ boxConstraint[0] +"px; top: "+ boxConstraint[1] +"px; ");
|
||||
|
||||
if (i == (allTokens.size() - 1)) {
|
||||
jspOut.println("border: " + currentTokenColor);
|
||||
}
|
||||
else {
|
||||
jspOut.println("border: " + childTokenColor);
|
||||
}
|
||||
|
||||
jspOut.println(" " + borderWidth + "px groove; "+
|
||||
"width: "+ boxConstraint[2] +"px; height: "+ boxConstraint[3] +"px;'>");
|
||||
|
||||
if(token.getName()!=null)
|
||||
{
|
||||
jspOut.println("<span style='color:" + tokenNameColor + ";font-style:italic;position:absolute;left:"+ (boxConstraint[2] + 10) +"px;top:" +((i - offset) * 20) +";'> " + token.getName() +"</span>");
|
||||
}
|
||||
|
||||
jspOut.println("</div>");
|
||||
}
|
||||
jspOut.println("</div>");
|
||||
}
|
||||
else
|
||||
{
|
||||
boxConstraint = extractBoxConstraint(rootDiagramElement);
|
||||
|
||||
jspOut.println("<table border=0 cellspacing=0 cellpadding=0 width=" + imageDimension[0] + " height=" + imageDimension[1] + ">");
|
||||
jspOut.println(" <tr>");
|
||||
jspOut.println(" <td width=" + imageDimension[0] + " height=" + imageDimension[1] + " style=\"background-image:url(" + imageLink + ")\" valign=top>");
|
||||
jspOut.println(" <table border=0 cellspacing=0 cellpadding=0>");
|
||||
jspOut.println(" <tr>");
|
||||
jspOut.println(" <td width=" + (boxConstraint[0] - borderWidth) + " height=" + (boxConstraint[1] - borderWidth)
|
||||
+ " style=\"background-color:transparent;\"></td>");
|
||||
jspOut.println(" </tr>");
|
||||
jspOut.println(" <tr>");
|
||||
jspOut.println(" <td style=\"background-color:transparent;\"></td>");
|
||||
jspOut.println(" <td style=\"border-color:" + currentTokenColor + "; border-width:" + borderWidth + "px; border-style:groove; background-color:transparent;\" width="
|
||||
+ boxConstraint[2] + " height=" + (boxConstraint[3] + (2 * borderWidth)) + "> </td>");
|
||||
jspOut.println(" </tr>");
|
||||
jspOut.println(" </table>");
|
||||
jspOut.println(" </td>");
|
||||
jspOut.println(" </tr>");
|
||||
jspOut.println("</table>");
|
||||
}
|
||||
}
|
||||
|
||||
private int[] extractBoxConstraint(Element root) {
|
||||
int[] result = new int[4];
|
||||
String nodeName = currentToken.getNode().getName();
|
||||
XPath xPath = new DefaultXPath("//node[@name='" + nodeName + "']");
|
||||
Element node = (Element) xPath.selectSingleNode(root);
|
||||
result[0] = Integer.valueOf(node.attribute("x").getValue()).intValue();
|
||||
result[1] = Integer.valueOf(node.attribute("y").getValue()).intValue();
|
||||
result[2] = Integer.valueOf(node.attribute("width").getValue()).intValue();
|
||||
result[3] = Integer.valueOf(node.attribute("height").getValue()).intValue();
|
||||
return result;
|
||||
}
|
||||
|
||||
private int[] extractBoxConstraint(Element root, Token token) {
|
||||
int[] result = new int[4];
|
||||
String nodeName = token.getNode().getName();
|
||||
XPath xPath = new DefaultXPath("//node[@name='" + nodeName + "']");
|
||||
Element node = (Element) xPath.selectSingleNode(root);
|
||||
result[0] = Integer.valueOf(node.attribute("x").getValue()).intValue();
|
||||
result[1] = Integer.valueOf(node.attribute("y").getValue()).intValue();
|
||||
result[2] = Integer.valueOf(node.attribute("width").getValue()).intValue();
|
||||
result[3] = Integer.valueOf(node.attribute("height").getValue()).intValue();
|
||||
return result;
|
||||
}
|
||||
|
||||
private int[] extractImageDimension(Element root) {
|
||||
int[] result = new int[2];
|
||||
result[0] = Integer.valueOf(root.attribute("width").getValue()).intValue();
|
||||
result[1] = Integer.valueOf(root.attribute("height").getValue()).intValue();
|
||||
return result;
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
|
||||
if (this.taskInstanceId > 0) {
|
||||
TaskInstance taskInstance = jbpmContext.getTaskMgmtSession().loadTaskInstance(taskInstanceId);
|
||||
currentToken = taskInstance.getToken();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.tokenInstanceId > 0)
|
||||
currentToken = jbpmContext.getGraphSession().loadToken(this.tokenInstanceId);
|
||||
}
|
||||
processDefinition = currentToken.getProcessInstance().getProcessDefinition();
|
||||
}
|
||||
|
||||
private void walkTokens(Token parent, List allTokens)
|
||||
{
|
||||
Map children = parent.getChildren();
|
||||
if(children != null && children.size() > 0)
|
||||
{
|
||||
Collection childTokens = children.values();
|
||||
for (Iterator iterator = childTokens.iterator(); iterator.hasNext();)
|
||||
{
|
||||
Token child = (Token) iterator.next();
|
||||
walkTokens(child, allTokens);
|
||||
}
|
||||
}
|
||||
|
||||
allTokens.add(parent);
|
||||
}
|
||||
|
||||
public void setTask(long id) {
|
||||
this.taskInstanceId = id;
|
||||
}
|
||||
|
||||
public void setToken(long id) {
|
||||
this.tokenInstanceId = id;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2005, JBoss Inc., and individual contributors as indicated
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.alfresco.web.ui.repo.tag;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.jsp.JspException;
|
||||
import javax.servlet.jsp.JspWriter;
|
||||
import javax.servlet.jsp.tagext.TagSupport;
|
||||
|
||||
import org.dom4j.DocumentException;
|
||||
import org.dom4j.DocumentHelper;
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.XPath;
|
||||
import org.dom4j.xpath.DefaultXPath;
|
||||
import org.jbpm.JbpmContext;
|
||||
import org.jbpm.file.def.FileDefinition;
|
||||
import org.jbpm.graph.def.ProcessDefinition;
|
||||
import org.jbpm.graph.exe.Token;
|
||||
import org.jbpm.taskmgmt.exe.TaskInstance;
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
// TODO: DC - Tidy up
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
|
||||
|
||||
public class JBPMProcessImageTag extends TagSupport {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private long taskInstanceId = -1;
|
||||
private long tokenInstanceId = -1;
|
||||
|
||||
private byte[] gpdBytes = null;
|
||||
private byte[] imageBytes = null;
|
||||
private Token currentToken = null;
|
||||
private ProcessDefinition processDefinition = null;
|
||||
|
||||
static String currentTokenColor = "red";
|
||||
static String childTokenColor = "blue";
|
||||
static String tokenNameColor = "blue";
|
||||
|
||||
|
||||
public void release() {
|
||||
taskInstanceId = -1;
|
||||
gpdBytes = null;
|
||||
imageBytes = null;
|
||||
currentToken = null;
|
||||
}
|
||||
|
||||
public int doEndTag() throws JspException {
|
||||
try {
|
||||
initialize();
|
||||
retrieveByteArrays();
|
||||
if (gpdBytes != null && imageBytes != null) {
|
||||
writeTable();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new JspException("table couldn't be displayed", e);
|
||||
} catch (DocumentException e) {
|
||||
e.printStackTrace();
|
||||
throw new JspException("table couldn't be displayed", e);
|
||||
}
|
||||
release();
|
||||
return EVAL_PAGE;
|
||||
}
|
||||
|
||||
private void retrieveByteArrays() {
|
||||
try {
|
||||
FileDefinition fileDefinition = processDefinition.getFileDefinition();
|
||||
gpdBytes = fileDefinition.getBytes("gpd.xml");
|
||||
imageBytes = fileDefinition.getBytes("processimage.jpg");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void writeTable() throws IOException, DocumentException {
|
||||
|
||||
int borderWidth = 4;
|
||||
Element rootDiagramElement = DocumentHelper.parseText(new String(gpdBytes)).getRootElement();
|
||||
int[] boxConstraint;
|
||||
int[] imageDimension = extractImageDimension(rootDiagramElement);
|
||||
String imageLink = "/alfresco/processimage?definitionId=" + processDefinition.getId();
|
||||
JspWriter jspOut = pageContext.getOut();
|
||||
|
||||
if (tokenInstanceId > 0) {
|
||||
|
||||
List allTokens = new ArrayList();
|
||||
walkTokens(currentToken, allTokens);
|
||||
|
||||
jspOut.println("<div style='position:relative; background-image:url(" + imageLink + "); width: " + imageDimension[0] + "px; height: " + imageDimension[1] + "px;'>");
|
||||
|
||||
for (int i = 0; i < allTokens.size(); i++)
|
||||
{
|
||||
Token token = (Token) allTokens.get(i);
|
||||
|
||||
//check how many tokens are on teh same level (= having the same parent)
|
||||
int offset = i;
|
||||
if(i > 0) {
|
||||
while(offset > 0 && ((Token) allTokens.get(offset - 1)).getParent().equals(token.getParent())) {
|
||||
offset--;
|
||||
}
|
||||
}
|
||||
boxConstraint = extractBoxConstraint(rootDiagramElement, token);
|
||||
|
||||
//Adjust for borders
|
||||
//boxConstraint[2]-=borderWidth*2;
|
||||
//boxConstraint[3]-=borderWidth*2;
|
||||
|
||||
jspOut.println("<div style='position:absolute; left: "+ boxConstraint[0] +"px; top: "+ boxConstraint[1] +"px; ");
|
||||
|
||||
if (i == (allTokens.size() - 1)) {
|
||||
jspOut.println("border: " + currentTokenColor);
|
||||
}
|
||||
else {
|
||||
jspOut.println("border: " + childTokenColor);
|
||||
}
|
||||
|
||||
jspOut.println(" " + borderWidth + "px groove; "+
|
||||
"width: "+ boxConstraint[2] +"px; height: "+ boxConstraint[3] +"px;'>");
|
||||
|
||||
if(token.getName()!=null)
|
||||
{
|
||||
jspOut.println("<span style='color:" + tokenNameColor + ";font-style:italic;position:absolute;left:"+ (boxConstraint[2] + 10) +"px;top:" +((i - offset) * 20) +";'> " + token.getName() +"</span>");
|
||||
}
|
||||
|
||||
jspOut.println("</div>");
|
||||
}
|
||||
jspOut.println("</div>");
|
||||
}
|
||||
else
|
||||
{
|
||||
boxConstraint = extractBoxConstraint(rootDiagramElement);
|
||||
|
||||
jspOut.println("<table border=0 cellspacing=0 cellpadding=0 width=" + imageDimension[0] + " height=" + imageDimension[1] + ">");
|
||||
jspOut.println(" <tr>");
|
||||
jspOut.println(" <td width=" + imageDimension[0] + " height=" + imageDimension[1] + " style=\"background-image:url(" + imageLink + ")\" valign=top>");
|
||||
jspOut.println(" <table border=0 cellspacing=0 cellpadding=0>");
|
||||
jspOut.println(" <tr>");
|
||||
jspOut.println(" <td width=" + (boxConstraint[0] - borderWidth) + " height=" + (boxConstraint[1] - borderWidth)
|
||||
+ " style=\"background-color:transparent;\"></td>");
|
||||
jspOut.println(" </tr>");
|
||||
jspOut.println(" <tr>");
|
||||
jspOut.println(" <td style=\"background-color:transparent;\"></td>");
|
||||
jspOut.println(" <td style=\"border-color:" + currentTokenColor + "; border-width:" + borderWidth + "px; border-style:groove; background-color:transparent;\" width="
|
||||
+ boxConstraint[2] + " height=" + (boxConstraint[3] + (2 * borderWidth)) + "> </td>");
|
||||
jspOut.println(" </tr>");
|
||||
jspOut.println(" </table>");
|
||||
jspOut.println(" </td>");
|
||||
jspOut.println(" </tr>");
|
||||
jspOut.println("</table>");
|
||||
}
|
||||
}
|
||||
|
||||
private int[] extractBoxConstraint(Element root) {
|
||||
int[] result = new int[4];
|
||||
String nodeName = currentToken.getNode().getName();
|
||||
XPath xPath = new DefaultXPath("//node[@name='" + nodeName + "']");
|
||||
Element node = (Element) xPath.selectSingleNode(root);
|
||||
result[0] = Integer.valueOf(node.attribute("x").getValue()).intValue();
|
||||
result[1] = Integer.valueOf(node.attribute("y").getValue()).intValue();
|
||||
result[2] = Integer.valueOf(node.attribute("width").getValue()).intValue();
|
||||
result[3] = Integer.valueOf(node.attribute("height").getValue()).intValue();
|
||||
return result;
|
||||
}
|
||||
|
||||
private int[] extractBoxConstraint(Element root, Token token) {
|
||||
int[] result = new int[4];
|
||||
String nodeName = token.getNode().getName();
|
||||
XPath xPath = new DefaultXPath("//node[@name='" + nodeName + "']");
|
||||
Element node = (Element) xPath.selectSingleNode(root);
|
||||
result[0] = Integer.valueOf(node.attribute("x").getValue()).intValue();
|
||||
result[1] = Integer.valueOf(node.attribute("y").getValue()).intValue();
|
||||
result[2] = Integer.valueOf(node.attribute("width").getValue()).intValue();
|
||||
result[3] = Integer.valueOf(node.attribute("height").getValue()).intValue();
|
||||
return result;
|
||||
}
|
||||
|
||||
private int[] extractImageDimension(Element root) {
|
||||
int[] result = new int[2];
|
||||
result[0] = Integer.valueOf(root.attribute("width").getValue()).intValue();
|
||||
result[1] = Integer.valueOf(root.attribute("height").getValue()).intValue();
|
||||
return result;
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
|
||||
if (this.taskInstanceId > 0) {
|
||||
TaskInstance taskInstance = jbpmContext.getTaskMgmtSession().loadTaskInstance(taskInstanceId);
|
||||
currentToken = taskInstance.getToken();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.tokenInstanceId > 0)
|
||||
currentToken = jbpmContext.getGraphSession().loadToken(this.tokenInstanceId);
|
||||
}
|
||||
processDefinition = currentToken.getProcessInstance().getProcessDefinition();
|
||||
}
|
||||
|
||||
private void walkTokens(Token parent, List allTokens)
|
||||
{
|
||||
Map children = parent.getChildren();
|
||||
if(children != null && children.size() > 0)
|
||||
{
|
||||
Collection childTokens = children.values();
|
||||
for (Iterator iterator = childTokens.iterator(); iterator.hasNext();)
|
||||
{
|
||||
Token child = (Token) iterator.next();
|
||||
walkTokens(child, allTokens);
|
||||
}
|
||||
}
|
||||
|
||||
allTokens.add(parent);
|
||||
}
|
||||
|
||||
public void setTask(long id) {
|
||||
this.taskInstanceId = id;
|
||||
}
|
||||
|
||||
public void setToken(long id) {
|
||||
this.tokenInstanceId = id;
|
||||
}
|
||||
|
||||
}
|
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2005, JBoss Inc., and individual contributors as indicated
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jbpm.webapp.bean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
|
||||
import org.jbpm.scheduler.impl.Scheduler;
|
||||
|
||||
public class AdminBean {
|
||||
|
||||
String deployUrl;
|
||||
|
||||
public void deployProcess() {
|
||||
}
|
||||
|
||||
public void createSchema() {
|
||||
}
|
||||
|
||||
public void dropSchema() {
|
||||
}
|
||||
|
||||
public boolean isSchedulerRunning() {
|
||||
return getScheduler().isRunning();
|
||||
}
|
||||
|
||||
public List getSchedulerHistoryLogs() {
|
||||
return getScheduler().getSchedulerHistoryLogs();
|
||||
}
|
||||
|
||||
private Scheduler getScheduler() {
|
||||
return (Scheduler) FacesContext.getCurrentInstance()
|
||||
.getExternalContext()
|
||||
.getApplicationMap()
|
||||
.get("scheduler");
|
||||
}
|
||||
|
||||
public String getDeployUrl() {
|
||||
return deployUrl;
|
||||
}
|
||||
public void setDeployUrl(String deployUrl) {
|
||||
this.deployUrl = deployUrl;
|
||||
}
|
||||
}
|
@@ -1,22 +0,0 @@
|
||||
package org.jbpm.webapp.bean;
|
||||
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
|
||||
public class AlfrescoUserBean extends UserBean
|
||||
{
|
||||
AuthenticationService authService;
|
||||
|
||||
|
||||
public void setAuthenticationService(AuthenticationService authService)
|
||||
{
|
||||
this.authService = authService;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getUserName()
|
||||
{
|
||||
return authService.getCurrentUserName();
|
||||
}
|
||||
|
||||
}
|
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2005, JBoss Inc., and individual contributors as indicated
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jbpm.webapp.bean;
|
||||
|
||||
import org.jbpm.context.def.VariableAccess;
|
||||
|
||||
public class FormParameter {
|
||||
|
||||
private String value = null;
|
||||
private VariableAccess variableAccess = null;
|
||||
|
||||
public FormParameter(String value, VariableAccess variableAccess) {
|
||||
this.value = value;
|
||||
this.variableAccess = variableAccess;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
public VariableAccess getVariableAccess() {
|
||||
return variableAccess;
|
||||
}
|
||||
}
|
@@ -1,205 +0,0 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2005, JBoss Inc., and individual contributors as indicated
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jbpm.webapp.bean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.faces.event.ActionEvent;
|
||||
import javax.faces.model.DataModel;
|
||||
import javax.faces.model.ListDataModel;
|
||||
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.jbpm.JbpmConfiguration;
|
||||
import org.jbpm.JbpmContext;
|
||||
import org.jbpm.db.GraphSession;
|
||||
import org.jbpm.db.TaskMgmtSession;
|
||||
import org.jbpm.graph.def.ProcessDefinition;
|
||||
import org.jbpm.graph.def.Transition;
|
||||
import org.jbpm.graph.exe.ProcessInstance;
|
||||
import org.jbpm.taskmgmt.def.Task;
|
||||
import org.jbpm.taskmgmt.exe.TaskInstance;
|
||||
|
||||
public class HomeBean {
|
||||
|
||||
UserBean userBean;
|
||||
TaskBean taskBean;
|
||||
JbpmConfiguration config;
|
||||
DataModel taskInstances;
|
||||
DataModel processDefs;
|
||||
|
||||
|
||||
public HomeBean()
|
||||
{
|
||||
}
|
||||
|
||||
public void setJbpmConfiguration(JbpmConfiguration config)
|
||||
{
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public List getTaskInstances()
|
||||
{
|
||||
JbpmContext xjbpmContext = config.getCurrentJbpmContext();
|
||||
JbpmContext jbpmContext = (xjbpmContext == null) ? config.createJbpmContext() : xjbpmContext;
|
||||
|
||||
try
|
||||
{
|
||||
TaskMgmtSession taskMgmtSession = jbpmContext.getTaskMgmtSession();
|
||||
List<TaskInstance> taskInstances = taskMgmtSession.findTaskInstances(userBean.getUserName());
|
||||
for (TaskInstance taskInstance : taskInstances)
|
||||
{
|
||||
taskInstance.getName();
|
||||
taskInstance.getTaskMgmtInstance().getTaskMgmtDefinition().getProcessDefinition().getName();
|
||||
}
|
||||
return taskInstances;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (xjbpmContext == null) jbpmContext.close();
|
||||
}
|
||||
}
|
||||
|
||||
public DataModel getTaskInstancesModel()
|
||||
{
|
||||
if (taskInstances == null)
|
||||
{
|
||||
taskInstances = new ListDataModel(getTaskInstances());
|
||||
}
|
||||
return taskInstances;
|
||||
}
|
||||
|
||||
public List getLatestProcessDefinitions()
|
||||
{
|
||||
JbpmContext xjbpmContext = config.getCurrentJbpmContext();
|
||||
JbpmContext jbpmContext = (xjbpmContext == null) ? config.createJbpmContext() : xjbpmContext;
|
||||
try
|
||||
{
|
||||
GraphSession graphSession = jbpmContext.getGraphSession();
|
||||
List<ProcessDefinition> procDefs = graphSession.findLatestProcessDefinitions();
|
||||
for (ProcessDefinition procDef : procDefs)
|
||||
{
|
||||
procDef.getName();
|
||||
Task startTask = procDef.getTaskMgmtDefinition().getStartTask();
|
||||
if (startTask != null)
|
||||
{
|
||||
startTask.getName();
|
||||
}
|
||||
}
|
||||
return procDefs;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (xjbpmContext == null) jbpmContext.close();
|
||||
}
|
||||
}
|
||||
|
||||
public DataModel getLatestProcessDefinitionsModel()
|
||||
{
|
||||
if (processDefs == null)
|
||||
{
|
||||
processDefs = new ListDataModel(getLatestProcessDefinitions());
|
||||
}
|
||||
return processDefs;
|
||||
}
|
||||
|
||||
/**
|
||||
* selects a task.
|
||||
*/
|
||||
public String selectTaskInstance()
|
||||
{
|
||||
JbpmContext xjbpmContext = config.getCurrentJbpmContext();
|
||||
JbpmContext jbpmContext = (xjbpmContext == null) ? config.createJbpmContext() : xjbpmContext;
|
||||
|
||||
try
|
||||
{
|
||||
// Get the task instance id from request parameter
|
||||
TaskInstance selectedTask = (TaskInstance)taskInstances.getRowData();
|
||||
long taskInstanceId = selectedTask.getId();
|
||||
TaskMgmtSession taskMgmtSession = jbpmContext.getTaskMgmtSession();
|
||||
TaskInstance taskInstance = taskMgmtSession.loadTaskInstance(taskInstanceId);
|
||||
taskBean.initialize(taskInstance);
|
||||
|
||||
return "task";
|
||||
}
|
||||
finally
|
||||
{
|
||||
taskInstances = null;
|
||||
processDefs = null;
|
||||
if (xjbpmContext == null ) jbpmContext.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* prepares a task form for starting a new process instance.
|
||||
*/
|
||||
public String startProcessInstance()
|
||||
{
|
||||
JbpmContext xjbpmContext = config.getCurrentJbpmContext();
|
||||
JbpmContext jbpmContext = (xjbpmContext == null) ? config.createJbpmContext() : xjbpmContext;
|
||||
try
|
||||
{
|
||||
jbpmContext.setActorId(AuthenticationUtil.getCurrentUserName());
|
||||
|
||||
// Get the task instance id from request parameter
|
||||
ProcessDefinition selectedProc = (ProcessDefinition)processDefs.getRowData();
|
||||
long processDefinitionId = selectedProc.getId();
|
||||
GraphSession graphSession = jbpmContext.getGraphSession();
|
||||
ProcessDefinition processDefinition = graphSession.loadProcessDefinition(processDefinitionId);
|
||||
|
||||
// create a new process instance to run
|
||||
ProcessInstance processInstance = new ProcessInstance(processDefinition);
|
||||
|
||||
// create a new taskinstance for the start task
|
||||
Task startTask = processInstance.getTaskMgmtInstance().getTaskMgmtDefinition().getStartTask();
|
||||
if (startTask != null)
|
||||
{
|
||||
TaskInstance taskInstance = processInstance.getTaskMgmtInstance().createStartTaskInstance();
|
||||
taskBean.initialize(taskInstance);
|
||||
}
|
||||
|
||||
// Save the process instance along with the task instance
|
||||
jbpmContext.save(processInstance);
|
||||
|
||||
// Fill the task backing bean with useful information
|
||||
return (startTask == null) ? "home" : "task";
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (xjbpmContext == null) jbpmContext.close();
|
||||
taskInstances = null;
|
||||
processDefs = null;
|
||||
}
|
||||
}
|
||||
|
||||
public UserBean getUserBean() {
|
||||
return userBean;
|
||||
}
|
||||
public void setUserBean(UserBean userBean) {
|
||||
this.userBean = userBean;
|
||||
}
|
||||
public TaskBean getTaskBean() {
|
||||
return taskBean;
|
||||
}
|
||||
public void setTaskBean(TaskBean taskBean) {
|
||||
this.taskBean = taskBean;
|
||||
}
|
||||
}
|
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2005, JBoss Inc., and individual contributors as indicated
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jbpm.webapp.bean;
|
||||
|
||||
import javax.faces.application.FacesMessage;
|
||||
import javax.faces.context.FacesContext;
|
||||
|
||||
public class JsfHelper {
|
||||
|
||||
public static long getId(String parameterName) {
|
||||
long value = -1;
|
||||
String valueText = (String) FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(parameterName);
|
||||
try {
|
||||
Long id = new Long(valueText);
|
||||
value = id.longValue();
|
||||
} catch (NumberFormatException e) {
|
||||
throw new RuntimeException("couldn't parse '"+parameterName+"'='"+valueText+"' as a long");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static void addMessage(String msg) {
|
||||
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(msg));
|
||||
}
|
||||
|
||||
public static void setSessionAttribute(String key, Object value) {
|
||||
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put(key, value);
|
||||
}
|
||||
|
||||
public static Object getSessionAttribute(String key) {
|
||||
return FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get(key);
|
||||
}
|
||||
|
||||
public static void removeSessionAttribute(String key) {
|
||||
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove(key);
|
||||
}
|
||||
|
||||
public static String getParameter(String name) {
|
||||
return (String) FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(name);
|
||||
}
|
||||
// private static final Log log = LogFactory.getLog(JsfHelper.class);
|
||||
}
|
@@ -1,228 +0,0 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2005, JBoss Inc., and individual contributors as indicated
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jbpm.webapp.bean;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.model.SelectItem;
|
||||
|
||||
import org.jbpm.JbpmContext;
|
||||
import org.jbpm.graph.def.ProcessDefinition;
|
||||
|
||||
|
||||
/**
|
||||
* Monitoring Bean Implementation.
|
||||
*
|
||||
* @author David Loiseau
|
||||
*/
|
||||
|
||||
public class MonitoringBean {
|
||||
|
||||
long processInstanceId;
|
||||
String message;
|
||||
String variableName;
|
||||
String variableValue;
|
||||
String variableNameOperator;
|
||||
String variableValueOperator;
|
||||
ArrayList processInstances;
|
||||
|
||||
public String showProcessDefinitions() {
|
||||
return "processDefinitions";
|
||||
}
|
||||
|
||||
public List getProcessDefinitions() {
|
||||
|
||||
ArrayList processDefinitionsList = new ArrayList();
|
||||
|
||||
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
|
||||
List processDefinitions = jbpmContext.getGraphSession().findAllProcessDefinitions();
|
||||
|
||||
if (processDefinitions.isEmpty() == false) {
|
||||
ListIterator listProcessDefinitions = processDefinitions.listIterator();
|
||||
while (listProcessDefinitions.hasNext() ) {
|
||||
ProcessDefinition processDefinition = (ProcessDefinition)listProcessDefinitions.next();
|
||||
|
||||
int instancesCount = 0;
|
||||
try {
|
||||
Connection connection = jbpmContext.getConnection();
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
String request = "SELECT COUNT(*) AS instancesCount "
|
||||
+ "FROM jbpm_processinstance "
|
||||
+ "WHERE processdefinition_='"
|
||||
+ processDefinition.getId() + "'";
|
||||
ResultSet resultSet = statement.executeQuery(request);
|
||||
resultSet.next();
|
||||
instancesCount = resultSet.getInt("instancesCount");
|
||||
}
|
||||
catch (Exception e) {}
|
||||
|
||||
processDefinitionsList.add(
|
||||
new ProcessDefinitionBean(
|
||||
processDefinition.getId(),
|
||||
processDefinition.getName(),
|
||||
processDefinition.getVersion(),
|
||||
instancesCount
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
return(processDefinitionsList);
|
||||
}
|
||||
|
||||
public String inspectInstance() {
|
||||
try {
|
||||
ProcessInstanceBean processInstanceBean = new ProcessInstanceBean(this.processInstanceId);
|
||||
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("processInstanceBean", processInstanceBean);
|
||||
this.message = "";
|
||||
return "inspectInstance";
|
||||
}
|
||||
catch (Exception exception) {
|
||||
this.message = "Error for process instance " + this.processInstanceId;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public String showSearchInstances() {
|
||||
return("showSearchInstances");
|
||||
}
|
||||
|
||||
public String searchInstances() {
|
||||
|
||||
long count = 0;
|
||||
|
||||
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
|
||||
|
||||
try {
|
||||
Connection connection = jbpmContext.getConnection();
|
||||
Statement statement = connection.createStatement();
|
||||
statement.setMaxRows(100);
|
||||
|
||||
String request = "SELECT DISTINCT processinstance_, name_, stringvalue_ FROM jbpm_variableinstance "
|
||||
+ "WHERE name_ "
|
||||
+ this.variableNameOperator + " '"
|
||||
+ variableName + "' AND stringvalue_ "
|
||||
+ this.variableValueOperator + " '" + variableValue + "'";
|
||||
|
||||
ResultSet resultSet = statement.executeQuery(request);
|
||||
|
||||
processInstances = new ArrayList();
|
||||
|
||||
while (resultSet.next()) {
|
||||
processInstances.add(new ProcessInstanceBean(
|
||||
resultSet.getLong("processinstance_"),
|
||||
resultSet.getString("name_"),
|
||||
resultSet.getString("stringvalue_")));
|
||||
count++;
|
||||
}
|
||||
statement.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
this.message = "Search error " + e.getMessage();
|
||||
}
|
||||
|
||||
if (count == 1) {
|
||||
ProcessInstanceBean processInstanceBean = (ProcessInstanceBean)processInstances.iterator().next();
|
||||
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("processInstanceBean", processInstanceBean);
|
||||
return("inspectInstance");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public List getOperatorsList (){
|
||||
|
||||
ArrayList operatorsList = new ArrayList();
|
||||
|
||||
SelectItem item = new SelectItem("=", "is equal to");
|
||||
operatorsList.add(item);
|
||||
item = new SelectItem("like", "is like");
|
||||
operatorsList.add(item);
|
||||
return operatorsList;
|
||||
|
||||
}
|
||||
|
||||
public long getProcessInstanceId() {
|
||||
return processInstanceId;
|
||||
}
|
||||
|
||||
public void setProcessInstanceId(long processInstanceId) {
|
||||
this.processInstanceId = processInstanceId;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public boolean isShowProcessInstances() {
|
||||
if (processInstances == null) return false;
|
||||
if (processInstances.size() == 0) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public ArrayList getProcessInstances() {
|
||||
return processInstances;
|
||||
}
|
||||
|
||||
public String getVariableName() {
|
||||
return variableName;
|
||||
}
|
||||
|
||||
public void setVariableName(String variableName) {
|
||||
this.variableName = variableName;
|
||||
}
|
||||
|
||||
public String getVariableValue() {
|
||||
return variableValue;
|
||||
}
|
||||
|
||||
public void setVariableValue(String variableValue) {
|
||||
this.variableValue = variableValue;
|
||||
}
|
||||
|
||||
public String getVariableNameOperator() {
|
||||
return variableNameOperator;
|
||||
}
|
||||
|
||||
public void setVariableNameOperator(String variableNameOperator) {
|
||||
this.variableNameOperator = variableNameOperator;
|
||||
}
|
||||
|
||||
public String getVariableValueOperator() {
|
||||
return variableValueOperator;
|
||||
}
|
||||
|
||||
public void setVariableValueOperator(String variableValueOperator) {
|
||||
this.variableValueOperator = variableValueOperator;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,141 +0,0 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2005, JBoss Inc., and individual contributors as indicated
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jbpm.webapp.bean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
|
||||
import org.jbpm.JbpmContext;
|
||||
import org.jbpm.db.GraphSession;
|
||||
import org.jbpm.graph.def.ProcessDefinition;
|
||||
import org.jbpm.graph.exe.ProcessInstance;
|
||||
|
||||
/**
|
||||
* Process Definition Bean Implementation.
|
||||
*
|
||||
* @author David Loiseau
|
||||
*/
|
||||
|
||||
public class ProcessDefinitionBean {
|
||||
|
||||
String name;
|
||||
int version;
|
||||
long id;
|
||||
int instancesCount;
|
||||
|
||||
public ProcessDefinitionBean() {
|
||||
}
|
||||
|
||||
public ProcessDefinitionBean(long id) {
|
||||
this.id = id;
|
||||
initialize();
|
||||
}
|
||||
|
||||
public ProcessDefinitionBean(long id, String name, int version, int instancesCount) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
this.instancesCount = instancesCount;
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
|
||||
GraphSession graphSession = jbpmContext.getGraphSession();
|
||||
ProcessDefinition processDefinition = graphSession.loadProcessDefinition(id);
|
||||
this.name = processDefinition.getName();
|
||||
this.version = processDefinition.getVersion();
|
||||
this.instancesCount = graphSession.findProcessInstances(this.id).size();
|
||||
}
|
||||
|
||||
public List getProcessInstances() {
|
||||
|
||||
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
|
||||
GraphSession graphSession = jbpmContext.getGraphSession();
|
||||
|
||||
ArrayList processInstancesList = new ArrayList();
|
||||
|
||||
List listProcessInstance = graphSession.findProcessInstances(this.id);
|
||||
|
||||
if (listProcessInstance.isEmpty() == false) {
|
||||
ListIterator listProcessInstances = listProcessInstance.listIterator();
|
||||
while (listProcessInstances.hasNext()) {
|
||||
ProcessInstance processInstance = (ProcessInstance) listProcessInstances.next();
|
||||
|
||||
processInstancesList.add(new ProcessInstanceBean(processInstance.getId(), processInstance.getStart(), processInstance.getEnd()));
|
||||
}
|
||||
}
|
||||
|
||||
return processInstancesList;
|
||||
}
|
||||
|
||||
public String showProcessInstances() {
|
||||
ProcessDefinitionBean processDefinitionBean = new ProcessDefinitionBean();
|
||||
processDefinitionBean.setId(this.id);
|
||||
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("processDefinitionBean", processDefinitionBean);
|
||||
return ("processInstances");
|
||||
}
|
||||
|
||||
public String startProcessInstance() {
|
||||
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
|
||||
GraphSession graphSession = jbpmContext.getGraphSession();
|
||||
ProcessDefinition processDefinition = graphSession.loadProcessDefinition(getId());
|
||||
processDefinition.createInstance();
|
||||
return showProcessInstances();
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
this.initialize();
|
||||
}
|
||||
|
||||
public int getInstancesCount() {
|
||||
return instancesCount;
|
||||
}
|
||||
|
||||
public void setInstancesCount(int instancesCount) {
|
||||
this.instancesCount = instancesCount;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(int version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
}
|
@@ -1,420 +0,0 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2005, JBoss Inc., and individual contributors as indicated
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jbpm.webapp.bean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
|
||||
import org.jbpm.JbpmContext;
|
||||
import org.jbpm.db.GraphSession;
|
||||
import org.jbpm.db.TaskMgmtSession;
|
||||
import org.jbpm.graph.def.Transition;
|
||||
import org.jbpm.graph.exe.ProcessInstance;
|
||||
import org.jbpm.graph.exe.Token;
|
||||
import org.jbpm.taskmgmt.exe.TaskInstance;
|
||||
|
||||
/**
|
||||
* Process Instance Bean Implementation.
|
||||
*
|
||||
* @author David Loiseau
|
||||
*/
|
||||
|
||||
public class ProcessInstanceBean {
|
||||
|
||||
long id;
|
||||
String processDefinitionLabel;
|
||||
long processDefinitionId;
|
||||
Date start;
|
||||
Date end;
|
||||
|
||||
ArrayList tokens;
|
||||
ArrayList variables;
|
||||
ArrayList tasks;
|
||||
ArrayList transitions;
|
||||
|
||||
String variableName;
|
||||
String variableValue;
|
||||
|
||||
long tokenInstanceId;
|
||||
long taskInstanceId;
|
||||
|
||||
public ProcessInstanceBean(long id, Date start, Date end) {
|
||||
this.id = id;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
public ProcessInstanceBean(long id) {
|
||||
this.id = id;
|
||||
this.initialize();
|
||||
}
|
||||
|
||||
public ProcessInstanceBean(long id, String variableName, String variableValue) {
|
||||
this.id = id;
|
||||
this.variableName = variableName;
|
||||
this.variableValue = variableValue;
|
||||
this.initialize();
|
||||
}
|
||||
|
||||
public String inspectProcessInstance() {
|
||||
ProcessInstanceBean processInstanceBean = new ProcessInstanceBean(this.id);
|
||||
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("processInstanceBean", processInstanceBean);
|
||||
return ("inspectInstance");
|
||||
}
|
||||
|
||||
public String deleteProcessInstance() {
|
||||
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
|
||||
GraphSession graphSession = jbpmContext.getGraphSession();
|
||||
graphSession.deleteProcessInstance(this.id);
|
||||
return ("deleteInstance");
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
|
||||
GraphSession graphSession = jbpmContext.getGraphSession();
|
||||
ProcessInstance processInstance = graphSession.loadProcessInstance(this.id);
|
||||
this.start = processInstance.getStart();
|
||||
this.end = processInstance.getEnd();
|
||||
this.processDefinitionId = processInstance.getProcessDefinition().getId();
|
||||
this.processDefinitionLabel = processInstance.getProcessDefinition().getName() + " (version " + processInstance.getProcessDefinition().getVersion() + ")";
|
||||
|
||||
initializeVariablesList(processInstance);
|
||||
initializeTokensList(processInstance);
|
||||
initializeTasksList(processInstance);
|
||||
}
|
||||
|
||||
private void initializeAvailableTransitions(TaskInstance taskInstance) {
|
||||
|
||||
transitions = new ArrayList();
|
||||
|
||||
if (taskInstance.getAvailableTransitions().isEmpty() == false) {
|
||||
Iterator availableTransitionsIterator = taskInstance.getAvailableTransitions().iterator();
|
||||
while (availableTransitionsIterator.hasNext()) {
|
||||
Transition transition = (Transition) availableTransitionsIterator.next();
|
||||
transitions.add(transition);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeAvailableTransitions(Token token) {
|
||||
|
||||
transitions = new ArrayList();
|
||||
|
||||
if (token.getNode().getLeavingTransitions().isEmpty() == false) {
|
||||
Iterator availableTransitionsIterator = token.getNode().getLeavingTransitions().iterator();
|
||||
while (availableTransitionsIterator.hasNext()) {
|
||||
Transition transition = (Transition) availableTransitionsIterator.next();
|
||||
transitions.add(transition);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeVariablesList(ProcessInstance processInstance) {
|
||||
|
||||
// Variables list
|
||||
variables = new ArrayList();
|
||||
|
||||
if (processInstance.getContextInstance().getVariables() != null && !processInstance.getContextInstance().getVariables().values().isEmpty()) {
|
||||
int mapsize = processInstance.getContextInstance().getVariables().size();
|
||||
Iterator variablesIterator = processInstance.getContextInstance().getVariables().entrySet().iterator();
|
||||
for (int i = 0; i < mapsize; i++) {
|
||||
Entry entry = (Entry) variablesIterator.next();
|
||||
variables.add(new VariableBean((String) entry.getKey(), entry.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void initializeTasksList(ProcessInstance processInstance) {
|
||||
|
||||
// Tasks list
|
||||
tasks = new ArrayList();
|
||||
if (processInstance.getTaskMgmtInstance().getTaskInstances().isEmpty() == false) {
|
||||
Iterator tasksIterator = processInstance.getTaskMgmtInstance().getTaskInstances().iterator();
|
||||
while (tasksIterator.hasNext()) {
|
||||
TaskInstance taskInstance = (TaskInstance) tasksIterator.next();
|
||||
tasks.add(new TaskBean(taskInstance.getId(), taskInstance.getName(), taskInstance.getActorId(), taskInstance.getEnd()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void initializeTokensList(ProcessInstance processInstance) {
|
||||
|
||||
// Tokens list
|
||||
Token rootToken = processInstance.getRootToken();
|
||||
|
||||
tokens = new ArrayList();
|
||||
this.tokenInstanceId = rootToken.getId();
|
||||
this.taskInstanceId = 0;
|
||||
tokens.add(new TokenBean(rootToken.getId(), "Root", rootToken.getNode().getName(), rootToken.getNode().getClass().getName(), rootToken.getStart(),
|
||||
rootToken.getEnd(), 1));
|
||||
try {
|
||||
if (rootToken.getChildren().isEmpty() == false) {
|
||||
AddChildrenTokensToTokensList(this.tokens, rootToken, 2);
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Add token childs to the current token beans list
|
||||
*
|
||||
* @param tokensList
|
||||
* Current token list to update
|
||||
* @param token
|
||||
* Token where are the token childs
|
||||
* @param level
|
||||
* Level where is the token: 1 for the root token, 2 for the childs
|
||||
* of the root token, ...
|
||||
*/
|
||||
private void AddChildrenTokensToTokensList(ArrayList tokensList, Token token, long level) {
|
||||
|
||||
Iterator childrenIterator = token.getChildren().values().iterator();
|
||||
while (childrenIterator.hasNext()) {
|
||||
Token childToken = (Token) childrenIterator.next();
|
||||
tokensList.add(new TokenBean(childToken.getId(), childToken.getName(), childToken.getNode().getName(), childToken.getNode().getClass().getName(),
|
||||
childToken.getStart(), childToken.getEnd(), level));
|
||||
try {
|
||||
if (childToken.getChildren().isEmpty() == false) {
|
||||
AddChildrenTokensToTokensList(tokensList, childToken, level + 1);
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String updateVariable() {
|
||||
|
||||
if (this.variableName != null) {
|
||||
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
|
||||
GraphSession graphSession = jbpmContext.getGraphSession();
|
||||
ProcessInstance processInstance = graphSession.loadProcessInstance(this.id);
|
||||
if (this.variableValue != null) {
|
||||
processInstance.getContextInstance().setVariable(this.variableName, this.variableValue);
|
||||
} else {
|
||||
processInstance.getContextInstance().deleteVariable(this.variableName);
|
||||
}
|
||||
initializeVariablesList(processInstance);
|
||||
}
|
||||
return "inspectInstance";
|
||||
}
|
||||
|
||||
public String selectToken() {
|
||||
this.taskInstanceId = 0;
|
||||
this.tokenInstanceId = JsfHelper.getId("tokenInstanceId");
|
||||
return "";
|
||||
}
|
||||
|
||||
public String selectTask() {
|
||||
this.tokenInstanceId = 0;
|
||||
this.taskInstanceId = JsfHelper.getId("taskInstanceId");
|
||||
return "";
|
||||
}
|
||||
|
||||
public String signal() {
|
||||
|
||||
selectToken();
|
||||
|
||||
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
|
||||
GraphSession graphSession = jbpmContext.getGraphSession();
|
||||
|
||||
Token token = graphSession.loadToken(this.tokenInstanceId);
|
||||
|
||||
if (token.getNode().getLeavingTransitions().size() > 1) {
|
||||
initializeAvailableTransitions(token);
|
||||
return "showTransitions";
|
||||
}
|
||||
|
||||
token.signal();
|
||||
|
||||
this.initializeTokensList(token.getProcessInstance());
|
||||
|
||||
return "inspectInstance";
|
||||
}
|
||||
|
||||
public String selectTransition() {
|
||||
String transitionName;
|
||||
|
||||
transitionName = JsfHelper.getParameter("transitionName");
|
||||
ProcessInstance processInstance = null;
|
||||
|
||||
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
|
||||
if (this.taskInstanceId > 0) {
|
||||
TaskMgmtSession taskMgmtSession = jbpmContext.getTaskMgmtSession();
|
||||
TaskInstance taskInstance = taskMgmtSession.loadTaskInstance(this.taskInstanceId);
|
||||
if (transitionName.equals("")) {
|
||||
taskInstance.end();
|
||||
} else {
|
||||
taskInstance.end(transitionName);
|
||||
}
|
||||
processInstance = taskInstance.getToken().getProcessInstance();
|
||||
} else if (this.tokenInstanceId > 0) {
|
||||
GraphSession graphSession = jbpmContext.getGraphSession();
|
||||
Token token = graphSession.loadToken(this.tokenInstanceId);
|
||||
if (transitionName.equals("")) {
|
||||
token.signal();
|
||||
} else {
|
||||
token.signal(transitionName);
|
||||
}
|
||||
processInstance = token.getProcessInstance();
|
||||
}
|
||||
|
||||
jbpmContext.save(processInstance);
|
||||
|
||||
this.initializeTasksList(processInstance);
|
||||
this.initializeTokensList(processInstance);
|
||||
|
||||
return "inspectInstance";
|
||||
}
|
||||
|
||||
public String endTask() {
|
||||
|
||||
selectTask();
|
||||
|
||||
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
|
||||
TaskMgmtSession taskMgmtSession = jbpmContext.getTaskMgmtSession();
|
||||
|
||||
TaskInstance taskInstance = taskMgmtSession.loadTaskInstance(this.taskInstanceId);
|
||||
|
||||
if (taskInstance.getAvailableTransitions().size() > 1) {
|
||||
initializeAvailableTransitions(taskInstance);
|
||||
return "showTransitions";
|
||||
}
|
||||
|
||||
taskInstance.end();
|
||||
|
||||
ProcessInstance processInstance = taskInstance.getToken().getProcessInstance();
|
||||
jbpmContext.save(processInstance);
|
||||
|
||||
this.initializeTasksList(processInstance);
|
||||
this.initializeTokensList(processInstance);
|
||||
|
||||
return "inspectInstance";
|
||||
}
|
||||
|
||||
// Show all the process instances for a given process definition ID
|
||||
public String showProcessInstances() {
|
||||
ProcessDefinitionBean processDefinitionBean = new ProcessDefinitionBean(this.processDefinitionId);
|
||||
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("processDefinitionBean", processDefinitionBean);
|
||||
return ("processInstances");
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Date getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public void setStart(Date start) {
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
public Date getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
public void setEnd(Date end) {
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
public ArrayList getTokens() {
|
||||
return tokens;
|
||||
}
|
||||
|
||||
public void setTokens(ArrayList tokens) {
|
||||
this.tokens = tokens;
|
||||
}
|
||||
|
||||
public String getProcessDefinitionLabel() {
|
||||
return processDefinitionLabel;
|
||||
}
|
||||
|
||||
public void setProcessDefinitionLabel(String processDefinitionLabel) {
|
||||
this.processDefinitionLabel = processDefinitionLabel;
|
||||
}
|
||||
|
||||
public ArrayList getVariables() {
|
||||
return variables;
|
||||
}
|
||||
|
||||
public ArrayList getTasks() {
|
||||
return tasks;
|
||||
}
|
||||
|
||||
public ArrayList getTransitions() {
|
||||
return transitions;
|
||||
}
|
||||
|
||||
public void setVariables(ArrayList variables) {
|
||||
this.variables = variables;
|
||||
}
|
||||
|
||||
public String getVariableName() {
|
||||
return variableName;
|
||||
}
|
||||
|
||||
public void setVariableName(String variableName) {
|
||||
this.variableName = variableName;
|
||||
}
|
||||
|
||||
public String getVariableValue() {
|
||||
return variableValue;
|
||||
}
|
||||
|
||||
public void setVariableValue(String variableValue) {
|
||||
this.variableValue = variableValue;
|
||||
}
|
||||
|
||||
public long getTokenInstanceId() {
|
||||
return tokenInstanceId;
|
||||
}
|
||||
|
||||
public void setTokenInstanceId(long tokenInstanceId) {
|
||||
this.taskInstanceId = 0;
|
||||
this.tokenInstanceId = tokenInstanceId;
|
||||
}
|
||||
|
||||
public long getTaskInstanceId() {
|
||||
return taskInstanceId;
|
||||
}
|
||||
|
||||
public void setTaskInstanceId(long taskInstanceId) {
|
||||
this.tokenInstanceId = 0;
|
||||
this.taskInstanceId = taskInstanceId;
|
||||
}
|
||||
|
||||
}
|
@@ -1,269 +0,0 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2005, JBoss Inc., and individual contributors as indicated
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jbpm.webapp.bean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.faces.model.DataModel;
|
||||
import javax.faces.model.ListDataModel;
|
||||
import javax.faces.model.SelectItem;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.jbpm.JbpmContext;
|
||||
import org.jbpm.context.def.VariableAccess;
|
||||
import org.jbpm.graph.def.Transition;
|
||||
import org.jbpm.graph.exe.ProcessInstance;
|
||||
import org.jbpm.logging.exe.LoggingInstance;
|
||||
import org.jbpm.taskmgmt.def.TaskController;
|
||||
import org.jbpm.taskmgmt.exe.TaskInstance;
|
||||
import org.jbpm.taskmgmt.log.TaskAssignLog;
|
||||
|
||||
public class TaskBean {
|
||||
|
||||
UserBean userBean = null;
|
||||
List taskFormParameters;
|
||||
List availableTransitions;
|
||||
List availableTransitionItems;
|
||||
TaskInstance taskInstance;
|
||||
long taskInstanceId;
|
||||
DataModel transitions;
|
||||
|
||||
// JbpmContext jbpmContext;
|
||||
// GraphSession graphSession;
|
||||
// TaskMgmtSession taskMgmtSession;
|
||||
|
||||
// For monitoring purposes
|
||||
String name;
|
||||
String actorId;
|
||||
Date end;
|
||||
|
||||
public TaskBean() {
|
||||
// this.jbpmContext = JbpmContext.getCurrentJbpmContext();
|
||||
// this.graphSession = jbpmContext.getGraphSession();
|
||||
// this.taskMgmtSession = jbpmContext.getTaskMgmtSession();
|
||||
|
||||
// get the parameters from the session
|
||||
// this.taskFormParameters = (List) JsfHelper.getSessionAttribute("taskFormParameters");
|
||||
}
|
||||
|
||||
public TaskBean(long taskInstanceId, String name, String actorId, Date end) {
|
||||
this.taskInstanceId = taskInstanceId;
|
||||
this.name = name;
|
||||
this.actorId = actorId;
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
public void initialize(TaskInstance taskInstance) {
|
||||
this.taskInstance = taskInstance;
|
||||
this.taskInstanceId = taskInstance.getId();
|
||||
|
||||
// set the parameters
|
||||
this.taskFormParameters = new ArrayList();
|
||||
TaskController taskController = taskInstance.getTask().getTaskController();
|
||||
if (taskController!=null) {
|
||||
List variableAccesses = taskController.getVariableAccesses();
|
||||
Iterator iter = variableAccesses.iterator();
|
||||
while (iter.hasNext()) {
|
||||
VariableAccess variableAccess = (VariableAccess) iter.next();
|
||||
String mappedName = variableAccess.getMappedName();
|
||||
Object value = taskInstance.getVariable(mappedName);
|
||||
TaskFormParameter tfp = new TaskFormParameter(variableAccess, value);
|
||||
taskFormParameters.add(tfp);
|
||||
}
|
||||
}
|
||||
|
||||
// store the parameters in the session
|
||||
//JsfHelper.setSessionAttribute("taskFormParameters", taskFormParameters);
|
||||
|
||||
// get the available transitions
|
||||
availableTransitions = null;
|
||||
|
||||
availableTransitions = taskInstance.getAvailableTransitions();
|
||||
if ((availableTransitions != null) && (availableTransitions.size() <= 1)) {
|
||||
transitions = null;
|
||||
availableTransitions = null;
|
||||
availableTransitionItems = null;
|
||||
} else {
|
||||
transitions = new ListDataModel(availableTransitions);
|
||||
availableTransitionItems = new ArrayList();
|
||||
Iterator iter = availableTransitions.iterator();
|
||||
while (iter.hasNext()) {
|
||||
Transition transition = (Transition) iter.next();
|
||||
SelectItem transitionItem = new SelectItem();
|
||||
transitionItem.setValue(transition.getName());
|
||||
transitionItem.setLabel(transition.getName());
|
||||
transitionItem.setDisabled(false);
|
||||
availableTransitionItems.add(transitionItem);
|
||||
}
|
||||
}
|
||||
|
||||
log.debug("initialized availableTransitions " + availableTransitions);
|
||||
}
|
||||
|
||||
public String save() {
|
||||
log.debug("saving the task parameters " + taskFormParameters);
|
||||
|
||||
// submit the parameters in the jbpm task controller
|
||||
TaskInstance taskInstance = JbpmContext.getCurrentJbpmContext().getTaskMgmtSession().loadTaskInstance(taskInstanceId);
|
||||
|
||||
// collect the parameter values from the values that were updated in the
|
||||
// parameters by jsf.
|
||||
Iterator iter = taskFormParameters.iterator();
|
||||
while (iter.hasNext()) {
|
||||
TaskFormParameter taskFormParameter = (TaskFormParameter) iter.next();
|
||||
|
||||
if ((taskFormParameter.isWritable()) && (taskFormParameter.getValue() != null)) {
|
||||
log.debug("submitting [" + taskFormParameter.getLabel() + "]=" + taskFormParameter.getValue());
|
||||
taskInstance.setVariable(taskFormParameter.getLabel(), taskFormParameter.getValue());
|
||||
} else {
|
||||
log.debug("ignoring unwritable [" + taskFormParameter.getLabel() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
// save the process instance and hence the updated task instance variables
|
||||
JbpmContext.getCurrentJbpmContext().save(taskInstance);
|
||||
|
||||
// remove the parameters from the session
|
||||
//JsfHelper.removeSessionAttribute("taskFormParameters");
|
||||
|
||||
return "home";
|
||||
}
|
||||
|
||||
public String saveAndClose() {
|
||||
// save
|
||||
save();
|
||||
|
||||
TaskInstance taskInstance = JbpmContext.getCurrentJbpmContext().getTaskMgmtSession().loadTaskInstance(taskInstanceId);
|
||||
|
||||
// close the task instance
|
||||
if (transitions == null)
|
||||
{
|
||||
taskInstance.end();
|
||||
}
|
||||
else
|
||||
{
|
||||
Transition selectedTransition = (Transition)transitions.getRowData();
|
||||
taskInstance.end(selectedTransition.getName());
|
||||
}
|
||||
|
||||
ProcessInstance processInstance = taskInstance.getTaskMgmtInstance().getProcessInstance();
|
||||
if (processInstance.hasEnded()) {
|
||||
JsfHelper.addMessage("The process has finished.");
|
||||
}
|
||||
|
||||
LoggingInstance loggingInstance = processInstance.getLoggingInstance();
|
||||
List assignmentLogs = loggingInstance.getLogs(TaskAssignLog.class);
|
||||
|
||||
log.debug("assignmentlogs: " + assignmentLogs);
|
||||
|
||||
if (assignmentLogs.size() == 1) {
|
||||
TaskAssignLog taskAssignLog = (TaskAssignLog) assignmentLogs.get(0);
|
||||
JsfHelper.addMessage("A new task has been assigned to '" + taskAssignLog.getTaskNewActorId() + "'");
|
||||
|
||||
} else if (assignmentLogs.size() > 1) {
|
||||
String msg = "New tasks have been assigned to: ";
|
||||
Iterator iter = assignmentLogs.iterator();
|
||||
while (iter.hasNext()) {
|
||||
TaskAssignLog taskAssignLog = (TaskAssignLog) iter.next();
|
||||
msg += taskAssignLog.getActorId();
|
||||
if (iter.hasNext())
|
||||
msg += ", ";
|
||||
}
|
||||
msg += ".";
|
||||
JsfHelper.addMessage(msg);
|
||||
}
|
||||
|
||||
JbpmContext.getCurrentJbpmContext().save(taskInstance);
|
||||
|
||||
return "home";
|
||||
}
|
||||
|
||||
public long getTaskInstanceId() {
|
||||
return taskInstanceId;
|
||||
}
|
||||
public void setTaskInstanceId(long taskInstanceId) {
|
||||
this.taskInstanceId = taskInstanceId;
|
||||
}
|
||||
public UserBean getUserBean() {
|
||||
return userBean;
|
||||
}
|
||||
public void setUserBean(UserBean userBean) {
|
||||
this.userBean = userBean;
|
||||
}
|
||||
public List getTaskFormParameters() {
|
||||
return taskFormParameters;
|
||||
}
|
||||
|
||||
public DataModel getTransitions()
|
||||
{
|
||||
return transitions;
|
||||
}
|
||||
|
||||
public List getAvailableTransitions() {
|
||||
return availableTransitions;
|
||||
}
|
||||
public void setAvailableTransitions(List availableTransitions) {
|
||||
this.availableTransitions = availableTransitions;
|
||||
}
|
||||
public List getAvailableTransitionItems() {
|
||||
return availableTransitionItems;
|
||||
}
|
||||
public TaskInstance getTaskInstance() {
|
||||
return taskInstance;
|
||||
}
|
||||
|
||||
private static final Log log = LogFactory.getLog(TaskBean.class);
|
||||
|
||||
public String getActorId() {
|
||||
return actorId;
|
||||
}
|
||||
|
||||
public void setActorId(String actorId) {
|
||||
this.actorId = actorId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Date getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
public void setEnd(Date end) {
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
public boolean isEnded() {
|
||||
if (end == null)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -1,109 +0,0 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2005, JBoss Inc., and individual contributors as indicated
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jbpm.webapp.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.jbpm.context.def.VariableAccess;
|
||||
import org.jbpm.taskmgmt.exe.TaskInstance;
|
||||
|
||||
public class TaskFormParameter implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected String label = null;
|
||||
protected String description = null;
|
||||
protected Object value = null;
|
||||
protected boolean isReadable = true;
|
||||
protected boolean isWritable = true;
|
||||
protected boolean isRequired = true;
|
||||
|
||||
public TaskFormParameter() {
|
||||
}
|
||||
|
||||
public TaskFormParameter(VariableAccess variableAccess, Object value) {
|
||||
this.label = variableAccess.getMappedName();
|
||||
this.value = value;
|
||||
this.isReadable = variableAccess.isReadable();
|
||||
this.isWritable = variableAccess.isWritable();
|
||||
this.isRequired = variableAccess.isRequired();
|
||||
}
|
||||
|
||||
public TaskFormParameter(TaskFormParameter other) {
|
||||
this.label = other.label;
|
||||
this.description = other.description;
|
||||
this.value = other.value;
|
||||
this.isReadable = other.isReadable;
|
||||
this.isWritable = other.isWritable;
|
||||
this.isRequired = other.isRequired;
|
||||
}
|
||||
|
||||
public static TaskFormParameter create(TaskInstance instance, String name, Object value, Session session) {
|
||||
TaskFormParameter taskFormParameter = null;
|
||||
return taskFormParameter;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "("+label+","+value+")";
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
public boolean isReadable() {
|
||||
return isReadable;
|
||||
}
|
||||
public void setReadable(boolean isReadable) {
|
||||
this.isReadable = isReadable;
|
||||
}
|
||||
public boolean isRequired() {
|
||||
return isRequired;
|
||||
}
|
||||
public void setRequired(boolean isRequired) {
|
||||
this.isRequired = isRequired;
|
||||
}
|
||||
public boolean isWritable() {
|
||||
return isWritable;
|
||||
}
|
||||
public boolean isReadOnly() {
|
||||
return !isWritable;
|
||||
}
|
||||
public void setWritable(boolean isWritable) {
|
||||
this.isWritable = isWritable;
|
||||
}
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
public void setValue(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
@@ -1,125 +0,0 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2005, JBoss Inc., and individual contributors as indicated
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jbpm.webapp.bean;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Token Bean Implementation.
|
||||
*
|
||||
* @author David Loiseau
|
||||
*/
|
||||
|
||||
public class TokenBean {
|
||||
|
||||
long id;
|
||||
String name;
|
||||
String nodeName;
|
||||
String nodeClassName;
|
||||
Date start;
|
||||
Date end;
|
||||
long level;
|
||||
|
||||
public TokenBean(long id, String name, String nodeName, String nodeClassName, Date start, Date end, long level) {
|
||||
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.nodeName = nodeName;
|
||||
this.nodeClassName = nodeClassName;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
private String getTypeNameFromClassName(String className) {
|
||||
String typeName = "";
|
||||
if (className.indexOf(".") > 0) {
|
||||
typeName = className.substring(className.lastIndexOf(".") + 1);
|
||||
}
|
||||
return typeName;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
String label = "";
|
||||
int i = 1;
|
||||
while (i < this.level) {
|
||||
label = label + "---";
|
||||
i++;
|
||||
}
|
||||
if (i > 1)
|
||||
label = label + " ";
|
||||
label = label + this.name;
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
public String getNodeName() {
|
||||
return nodeName;
|
||||
}
|
||||
|
||||
public void setNodeName(String nodeName) {
|
||||
this.nodeName = nodeName;
|
||||
}
|
||||
|
||||
public Date getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
public void setEnd(Date end) {
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
public Date getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public void setStart(Date start) {
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
public String getNodeType() {
|
||||
return getTypeNameFromClassName(this.nodeClassName);
|
||||
}
|
||||
|
||||
public boolean isSignal() {
|
||||
if (this.end == null)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2005, JBoss Inc., and individual contributors as indicated
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jbpm.webapp.bean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.faces.model.SelectItem;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.jbpm.JbpmContext;
|
||||
import org.jbpm.identity.User;
|
||||
import org.jbpm.identity.hibernate.IdentitySession;
|
||||
|
||||
public class UserBean {
|
||||
|
||||
String userName;
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String name) {
|
||||
this.userName = name;
|
||||
}
|
||||
|
||||
public String login() {
|
||||
JbpmContext.getCurrentJbpmContext().setActorId(userName);
|
||||
return "home";
|
||||
}
|
||||
|
||||
public List getUsers() {
|
||||
Session session = JbpmContext.getCurrentJbpmContext().getSession();
|
||||
IdentitySession identitySession = new IdentitySession(session);
|
||||
return identitySession.getUsers();
|
||||
}
|
||||
|
||||
public List getUserSelectItems() {
|
||||
List userSelectItems = new ArrayList();
|
||||
|
||||
Iterator iter = getUsers().iterator();
|
||||
while (iter.hasNext()) {
|
||||
User user = (User) iter.next();
|
||||
userSelectItems.add(new UserSelectItem(user));
|
||||
}
|
||||
|
||||
return userSelectItems;
|
||||
}
|
||||
|
||||
public static class UserSelectItem extends SelectItem {
|
||||
private static final long serialVersionUID = 1L;
|
||||
public UserSelectItem(User user) {
|
||||
setValue(user.getName());
|
||||
setLabel(user.getName());
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2005, JBoss Inc., and individual contributors as indicated
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jbpm.webapp.bean;
|
||||
|
||||
/**
|
||||
* Variable Bean Implementation.
|
||||
*
|
||||
* @author David Loiseau
|
||||
*/
|
||||
|
||||
public class VariableBean {
|
||||
|
||||
String name;
|
||||
Object value;
|
||||
|
||||
public VariableBean(String name, Object value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2005, JBoss Inc., and individual contributors as indicated
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jbpm.webapp.context;
|
||||
|
||||
import org.jbpm.graph.def.ProcessDefinition;
|
||||
import org.jbpm.taskmgmt.exe.TaskInstance;
|
||||
|
||||
public class BpmContext {
|
||||
|
||||
ProcessDefinition processDefinition;
|
||||
TaskInstance taskInstance;
|
||||
|
||||
public ProcessDefinition getProcessDefinition() {
|
||||
return processDefinition;
|
||||
}
|
||||
public void setProcessDefinition(ProcessDefinition processDefinition) {
|
||||
this.processDefinition = processDefinition;
|
||||
}
|
||||
public TaskInstance getTaskInstance() {
|
||||
return taskInstance;
|
||||
}
|
||||
public void setTaskInstance(TaskInstance taskInstance) {
|
||||
this.taskInstance = taskInstance;
|
||||
}
|
||||
}
|
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2005, JBoss Inc., and individual contributors as indicated
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jbpm.webapp.context;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Context {
|
||||
|
||||
static ThreadLocal contextsThreadLocal = new ThreadLocal();
|
||||
|
||||
public static void create() {
|
||||
contextsThreadLocal.set(new HashMap());
|
||||
}
|
||||
|
||||
public static void destroy() {
|
||||
contextsThreadLocal.set(null);
|
||||
}
|
||||
|
||||
public static Object getContext(Class clazz) {
|
||||
Map contexts = (Map) contextsThreadLocal.get();
|
||||
Object context = contexts.get(clazz);
|
||||
if (context==null) {
|
||||
try {
|
||||
context = clazz.newInstance();
|
||||
contexts.put(clazz, context);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("couldn't instantiate context '"+clazz.getName()+"'");
|
||||
}
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
public static PersistenceContext getPersistenceContext() {
|
||||
return (PersistenceContext) getContext(PersistenceContext.class);
|
||||
}
|
||||
|
||||
public static BpmContext getBpmContext() {
|
||||
return (BpmContext) getContext(BpmContext.class);
|
||||
}
|
||||
}
|
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2005, JBoss Inc., and individual contributors as indicated
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jbpm.webapp.context;
|
||||
|
||||
import javax.naming.InitialContext;
|
||||
import javax.rmi.PortableRemoteObject;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.jbpm.db.JbpmSession;
|
||||
import org.jbpm.db.JbpmSessionFactory;
|
||||
import org.jbpm.identity.hibernate.IdentitySession;
|
||||
|
||||
public class PersistenceContext {
|
||||
|
||||
static String jndiName = "java:/jbpm/SessionFactory";
|
||||
static JbpmSessionFactory jbpmSessionFactory = null;
|
||||
static {
|
||||
try {
|
||||
InitialContext initialContext = new InitialContext();
|
||||
Object o = initialContext.lookup(jndiName);
|
||||
SessionFactory sessionFactory = (SessionFactory) PortableRemoteObject.narrow(o, SessionFactory.class);
|
||||
jbpmSessionFactory = new JbpmSessionFactory(null, sessionFactory);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("couldn't get the hibernate session factory from jndi entry '"+jndiName+"'", e);
|
||||
}
|
||||
}
|
||||
|
||||
boolean isRollbackOnly;
|
||||
JbpmSession jbpmSession;
|
||||
IdentitySession identitySession;
|
||||
|
||||
public void beginTransaction() {
|
||||
isRollbackOnly = false;
|
||||
log.debug("beginning transaction");
|
||||
jbpmSession = jbpmSessionFactory.openJbpmSessionAndBeginTransaction();
|
||||
identitySession = new IdentitySession(jbpmSession.getSession());
|
||||
}
|
||||
|
||||
public void endTransaction() {
|
||||
if (isRollbackOnly) {
|
||||
log.debug("rolling back transaction");
|
||||
jbpmSession.rollbackTransactionAndClose();
|
||||
} else {
|
||||
log.debug("committing transaction");
|
||||
jbpmSession.commitTransactionAndClose();
|
||||
}
|
||||
}
|
||||
|
||||
public void setRollbackOnly() {
|
||||
isRollbackOnly = true;
|
||||
}
|
||||
|
||||
public IdentitySession getIdentitySession() {
|
||||
return identitySession;
|
||||
}
|
||||
|
||||
public JbpmSession getJbpmSession() {
|
||||
return jbpmSession;
|
||||
}
|
||||
|
||||
private static final Log log = LogFactory.getLog(PersistenceContext.class);
|
||||
}
|
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2005, JBoss Inc., and individual contributors as indicated
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jbpm.webapp.filter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.jbpm.JbpmContext;
|
||||
import org.jbpm.webapp.bean.UserBean;
|
||||
|
||||
public class AuthenticationFilter implements Filter {
|
||||
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
}
|
||||
|
||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
||||
HttpServletRequest request = (HttpServletRequest) servletRequest;
|
||||
HttpSession session = request.getSession();
|
||||
UserBean userBean = null;
|
||||
if (session!=null) {
|
||||
userBean = (UserBean) session.getAttribute("userBean");
|
||||
}
|
||||
if (userBean!=null) {
|
||||
String actorId = userBean.getUserName();
|
||||
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
|
||||
jbpmContext.setActorId(actorId);
|
||||
}
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
}
|
||||
}
|
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2005, JBoss Inc., and individual contributors as indicated
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jbpm.webapp.filter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.transaction.TransactionUtil;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.jbpm.JbpmConfiguration;
|
||||
import org.jbpm.JbpmContext;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
|
||||
public class JbpmContextFilter implements Filter, Serializable
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private ServletContext context;
|
||||
|
||||
public void init(FilterConfig filterConfig) throws ServletException
|
||||
{
|
||||
this.context = filterConfig.getServletContext();
|
||||
}
|
||||
|
||||
public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain)
|
||||
throws IOException, ServletException
|
||||
{
|
||||
WebApplicationContext wc = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
|
||||
final JbpmConfiguration jbpmConfig = (JbpmConfiguration) wc.getBean("jbpm_configuration");
|
||||
TransactionService trx = (TransactionService) wc.getBean("TransactionService");
|
||||
|
||||
TransactionUtil.executeInUserTransaction(trx, new TransactionUtil.TransactionWork<Object>()
|
||||
{
|
||||
public Object doWork() throws Exception
|
||||
{
|
||||
JbpmContext jbpmContext = jbpmConfig.createJbpmContext();
|
||||
try
|
||||
{
|
||||
String actorId = AuthenticationUtil.getCurrentUserName();
|
||||
if (actorId != null)
|
||||
{
|
||||
jbpmContext.setActorId(actorId);
|
||||
}
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
}
|
||||
finally
|
||||
{
|
||||
jbpmContext.close();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void destroy()
|
||||
{
|
||||
}
|
||||
}
|
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2005, JBoss Inc., and individual contributors as indicated
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jbpm.webapp.filter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
public class LogFilter implements Filter {
|
||||
|
||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
||||
HttpServletRequest request = (HttpServletRequest) servletRequest;
|
||||
|
||||
log.debug("request "+request.getRequestURL());
|
||||
|
||||
Enumeration enumeration = request.getParameterNames();
|
||||
while (enumeration.hasMoreElements()) {
|
||||
String paramName = (String) enumeration.nextElement();
|
||||
log.debug("request parameter ["+paramName+"]="+request.getParameter(paramName));
|
||||
}
|
||||
|
||||
HttpSession session = request.getSession();
|
||||
enumeration = session.getAttributeNames();
|
||||
while (enumeration.hasMoreElements()) {
|
||||
String attributeName = (String) enumeration.nextElement();
|
||||
log.debug("session parameter ["+attributeName+"]="+session.getAttribute(attributeName));
|
||||
}
|
||||
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
}
|
||||
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
private static final Log log = LogFactory.getLog(LogFilter.class);
|
||||
}
|
Reference in New Issue
Block a user