Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2010 JBoss Inc Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 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.jbpm.integration.console;
 
 import java.net.URL;
 import java.util.List;
 import java.util.Map;
 
 import  org.drools.SystemEventListenerFactory;
 import  org.jboss.bpm.console.client.model.TaskRef;
 
 public class TaskManagement implements org.jboss.bpm.console.server.integration.TaskManagement {
 	
 	// TODO: make this configurable
 	private String ipAddress = "127.0.0.1";
 	private int port = 9123;
 	private TaskClient client;
 	private Map<StringList<String>> groupListMap = new HashMap<StringList<String>>();
 
 	public void setConnection(String ipAddressint port) {
 		this. = ipAddress;
 		this. = port;
 	}
 	
 	public void connect() {
 		if ( == null) {
 			 = new TaskClient(new MinaTaskClientConnector("org.drools.process.workitem.wsht.WSHumanTaskHandler",
 									new MinaTaskClientHandler(SystemEventListenerFactory.getSystemEventListener())));
 			boolean connected = .connect();
 			if (!connected) {
 					"Could not connect task client");
 			}
 		}
 		try {
 			URL url = null;
 			String propertyName = "roles.properties";
 
 			if (loader instanceof URLClassLoader) {
 				URLClassLoader ucl = (URLClassLoaderloader;
 				url = ucl.findResource(propertyName);
 			}
 			if (url == null) {
 				url = loader.getResource(propertyName);
 			}
 			if (url == null) {
 				..println("No properties file: " + propertyName + " found");
 			} else {
 				Properties bundle = new Properties();
 				InputStream is = url.openStream();
 				if (is != null) {
 					bundle.load(is);
 					is.close();
 				} else {
 					throw new IOException("Properties file " + propertyName" not available");
 				}
 				Enumeration<?> propertyNames = bundle.propertyNames();
 				while (propertyNames.hasMoreElements()) {
 					String key = (StringpropertyNames.nextElement();
 					String value = bundle.getProperty(key);
 					.put(key, Arrays.asList(value.split(",")));
 					..print("Loaded user " + key + ":");
 					for (String role.get(key)) {
						..print(" " + role);
					}
				}
			}
catch (Throwable t) {
		}
	}
	public TaskRef getTaskById(long taskId) {
		.getTask(taskIdresponseHandler);
		Task task = responseHandler.getTask();
        return Transform.task(task);
	}
	public void assignTask(long taskIdString idRefString userId) {
		if (idRef == null) {
			.release(taskIduserIdresponseHandler);
else if (idRef.equals(userId)) {
			List<Stringroles = .get(userId);
			if (roles == null) {
				.claim(taskIdidRefresponseHandler);
else {
				.claim(taskIdidRefrolesresponseHandler);
			}
else {
			.delegate(taskIduserIdidRefresponseHandler);
		}
		responseHandler.waitTillDone(5000);
	}
	@SuppressWarnings("unchecked")
	public void completeTask(long taskIdMap dataString userId) {
		.start(taskIduserIdresponseHandler);
		responseHandler.waitTillDone(5000);
		responseHandler = new BlockingTaskOperationResponseHandler();
		ContentData contentData = null;
		if (data != null) {
			try {
				out = new ObjectOutputStream(bos);
				out.writeObject(data);
				out.close();
				contentData = new ContentData();
				contentData.setContent(bos.toByteArray());
catch (IOException e) {
			}
		}
		.complete(taskIduserIdcontentDataresponseHandler);
		responseHandler.waitTillDone(5000);
	}
	@SuppressWarnings("unchecked")
	public void completeTask(long taskIdString outcomeMap dataString userId) {
		data.put("outcome"outcome);
		completeTask(taskIddatauserId);
	}
	public void releaseTask(long taskIdString userId) {
		// TODO: this method is not being invoked, it's using
		// assignTask with null parameter instead
		.release(taskIduserIdresponseHandler);
		responseHandler.waitTillDone(5000);
	}
	public List<TaskRef> getAssignedTasks(String idRef) {
        List<TaskRef> result = new ArrayList<TaskRef>();
		try {
			.getTasksOwned(idRef"en-UK"responseHandler);
	        List<TaskSummarytasks = responseHandler.getResults();
	        for (TaskSummary tasktasks) {
	        	if (task.getStatus() == .) {
	        		result.add(Transform.task(task));
	        	}
	        }
catch (Throwable t) {
		}
		return result;
	}
	public List<TaskRef> getUnassignedTasks(String idRefString participationType) {
		// TODO participationType ?
        List<TaskRef> result = new ArrayList<TaskRef>();
		try {
			List<Stringroles = .get(idRef);
			if (roles == null) {
				.getTasksAssignedAsPotentialOwner(idRef"en-UK"responseHandler);
else {
				.getTasksAssignedAsPotentialOwner(idRefroles"en-UK"responseHandler);
			}
	        List<TaskSummarytasks = responseHandler.getResults();
	        for (TaskSummary tasktasks) {
	        	result.add(Transform.task(task));
	        }
catch (Throwable t) {
		}
		return result;
	}
New to GrepCode? Check out our FAQ X