use of org.alfresco.service.cmr.workflow.WorkflowTimer in project alfresco-repository by Alfresco.
the class ActivitiWorkflowEngine method getTimers.
/**
* {@inheritDoc}
*/
public List<WorkflowTimer> getTimers(String workflowId) {
try {
List<WorkflowTimer> timers = new ArrayList<WorkflowTimer>();
String processInstanceId = createLocalId(workflowId);
List<Job> timerJobs = managementService.createJobQuery().processInstanceId(processInstanceId).timers().list();
// Only fetch process-instance when timers are available, to prevent extra unneeded query
ProcessInstance jobsProcessInstance = null;
if (timerJobs.size() > 0) {
// Reuse the process-instance, is used from WorkflowPath creation
jobsProcessInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
}
// Convert the timerJobs to WorkflowTimers
for (Job job : timerJobs) {
Execution jobExecution = runtimeService.createExecutionQuery().executionId(job.getExecutionId()).singleResult();
WorkflowPath path = typeConverter.convert(jobExecution, jobsProcessInstance);
WorkflowTask workflowTask = getTaskForTimer(job, jobsProcessInstance, jobExecution);
WorkflowTimer workflowTimer = factory.createWorkflowTimer(job.getId(), job.getId(), job.getExceptionMessage(), job.getDuedate(), path, workflowTask);
timers.add(workflowTimer);
}
return timers;
} catch (ActivitiException ae) {
String msg = messageService.getMessage(ERR_GET_TIMERS, workflowId);
if (logger.isDebugEnabled()) {
logger.debug(msg, ae);
}
throw new WorkflowException(msg, ae);
}
}
use of org.alfresco.service.cmr.workflow.WorkflowTimer in project alfresco-repository by Alfresco.
the class AbstractWorkflowServiceIntegrationTest method testGetTimers.
public void testGetTimers() {
// Make admin current user
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
// Start process that will have a timer
WorkflowDefinition workflowDef = deployDefinition(getTestTimerDefinitionPath());
assertNotNull(workflowDef);
// Create params
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
Serializable wfPackage = workflowService.createPackage(null);
params.put(WorkflowModel.ASSOC_PACKAGE, wfPackage);
Date dueDate = new Date();
params.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE, dueDate);
params.put(WorkflowModel.PROP_WORKFLOW_PRIORITY, 1);
// Assign to USER2
NodeRef assignee = personManager.get(USER2);
params.put(WorkflowModel.ASSOC_ASSIGNEE, assignee);
// Start a workflow instance
WorkflowPath path = workflowService.startWorkflow(workflowDef.getId(), params);
assertNotNull(path);
assertTrue(path.isActive());
String workflowInstanceId = path.getInstance().getId();
// End start task to progress workflow
WorkflowTask startTask = workflowService.getStartTask(workflowInstanceId);
String startTaskId = startTask.getId();
workflowService.endTask(startTaskId, null);
// Query the active task, where timer should be on
WorkflowTask task = getNextTaskForWorkflow(workflowInstanceId);
// Query for timers, timer should be active
List<WorkflowTimer> timers = workflowService.getTimers(workflowInstanceId);
assertNotNull(timers);
assertEquals(1, timers.size());
WorkflowTimer timer = timers.get(0);
assertNotNull(timer.getId());
assertNotNull(timer.getDueDate());
assertNotNull(timer.getName());
assertNull(timer.getError());
// Check path, should be waiting in task-node
assertNotNull(timer.getPath());
assertEquals(task.getPath().getId(), timer.getPath().getId());
assertEquals(workflowInstanceId, timer.getPath().getInstance().getId());
assertNotNull(timer.getPath().getNode());
assertTrue(timer.getPath().getNode().isTaskNode());
// Check task
assertNotNull(timer.getTask());
assertEquals(task.getId(), timer.getTask().getId());
// We finish the task, timer should be gone
workflowService.endTask(task.getId(), null);
timers = workflowService.getTimers(workflowInstanceId);
assertNotNull(timers);
assertEquals(0, timers.size());
}
use of org.alfresco.service.cmr.workflow.WorkflowTimer in project alfresco-repository by Alfresco.
the class ActivitiWorkflowComponentTest method testGetTimers.
@Test
public void testGetTimers() throws Exception {
WorkflowDefinition def = deployTestJobDefinition();
ProcessInstance processInstance = runtime.startProcessInstanceById(BPMEngineRegistry.getLocalId(def.getId()));
// One timer should be active on workflow
String workflowInstanceId = BPMEngineRegistry.createGlobalId(ActivitiConstants.ENGINE_ID, processInstance.getProcessInstanceId());
// Query the timer in activity to have reference
Job timerJob = managementService.createJobQuery().timers().processInstanceId(processInstance.getId()).singleResult();
String globalJobId = BPMEngineRegistry.createGlobalId(ActivitiConstants.ENGINE_ID, timerJob.getId());
// Ask workflowEngine for timers
List<WorkflowTimer> timers = workflowEngine.getTimers(workflowInstanceId);
assertNotNull(timers);
assertEquals(1, timers.size());
WorkflowTimer timer = timers.get(0);
assertEquals(globalJobId, timer.getId());
assertEquals(timerJob.getDuedate(), timer.getDueDate());
// Check the path of the timer
String expectedTimerPathId = BPMEngineRegistry.createGlobalId(ActivitiConstants.ENGINE_ID, timerJob.getExecutionId());
assertNotNull(timer.getPath());
assertEquals(expectedTimerPathId, timer.getPath().getId());
// Check the workflow-instance associated with the path
assertEquals(workflowInstanceId, timer.getPath().getInstance().getId());
// Check the task returned by the timer
Task waitingTask = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(timer.getTask());
assertEquals(BPMEngineRegistry.createGlobalId(ActivitiConstants.ENGINE_ID, waitingTask.getId()), timer.getTask().getId());
// When task with boundry-timer on it is finished, no timers should be available
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
taskService.complete(task.getId());
timers = workflowEngine.getTimers(workflowInstanceId);
assertNotNull(timers);
assertEquals(0, timers.size());
}
use of org.alfresco.service.cmr.workflow.WorkflowTimer in project alfresco-repository by Alfresco.
the class WorkflowInterpreter method executeCommand.
/**
* Execute a single command using the BufferedReader passed in for any data needed.
*
* TODO: Use decent parser!
*
* @param line The unparsed command
* @return The textual output of the command.
*/
@Override
protected String executeCommand(String line) throws IOException {
String[] command = line.split(" ");
if (command.length == 0) {
command = new String[1];
command[0] = line;
}
ByteArrayOutputStream bout = new ByteArrayOutputStream();
PrintStream out = new PrintStream(bout);
// repeat last command?
if (command[0].equals("r")) {
if (lastCommand == null) {
return "No command entered yet.";
}
return "repeating command " + lastCommand + "\n\n" + executeCommand(lastCommand);
}
// remember last command
lastCommand = line;
// execute command
if (command[0].equals("help")) {
String helpFile = I18NUtil.getMessage("workflow_console.help");
ClassPathResource helpResource = new ClassPathResource(helpFile);
byte[] helpBytes = new byte[500];
InputStream helpStream = helpResource.getInputStream();
try {
int read = helpStream.read(helpBytes);
while (read != -1) {
bout.write(helpBytes, 0, read);
read = helpStream.read(helpBytes);
}
} finally {
helpStream.close();
}
} else if (command[0].equals("show")) {
if (command.length < 2) {
return "Syntax Error.\n";
} else if (command[1].equals("file")) {
if (command.length != 3) {
return "Syntax Error.\n";
}
ClassPathResource file = new ClassPathResource(command[2]);
InputStream fileStream = file.getInputStream();
byte[] fileBytes = new byte[500];
try {
int read = fileStream.read(fileBytes);
while (read != -1) {
bout.write(fileBytes, 0, read);
read = fileStream.read(fileBytes);
}
} finally {
fileStream.close();
}
out.println();
} else if (command[1].equals("definitions")) {
List<WorkflowDefinition> defs = null;
if (command.length == 3) {
if (command[2].equals("all")) {
defs = workflowService.getAllDefinitions();
} else {
return "Syntax Error.\n";
}
} else {
defs = workflowService.getDefinitions();
}
for (WorkflowDefinition def : defs) {
out.println("id: " + def.getId() + " , name: " + def.getName() + " , title: " + def.getTitle() + " , version: " + def.getVersion());
}
} else if (command[1].equals("workflows")) {
String id = (currentWorkflowDef != null) ? currentWorkflowDef.getId() : null;
if (id == null && command.length == 2) {
return "workflow definition not in use. Enter command 'show workflows all' or 'use <workflowDefId>'.\n";
}
if (command.length == 3) {
if (command[2].equals("all")) {
id = "all";
} else {
return "Syntax Error.\n";
}
}
if ("all".equals(id)) {
for (WorkflowDefinition def : workflowService.getAllDefinitions()) {
List<WorkflowInstance> workflows = workflowService.getActiveWorkflows(def.getId());
for (WorkflowInstance workflow : workflows) {
out.println("id: " + workflow.getId() + " , desc: " + workflow.getDescription() + " , start date: " + workflow.getStartDate() + " , def: " + workflow.getDefinition().getName() + " v" + workflow.getDefinition().getVersion());
}
}
} else {
List<WorkflowInstance> workflows = workflowService.getActiveWorkflows(id);
for (WorkflowInstance workflow : workflows) {
out.println("id: " + workflow.getId() + " , desc: " + workflow.getDescription() + " , start date: " + workflow.getStartDate() + " , def: " + workflow.getDefinition().getName());
}
}
} else if (command[1].equals("paths")) {
String workflowId = (command.length == 3) ? command[2] : (currentPath == null) ? null : currentPath.getInstance().getId();
if (workflowId == null) {
return "Syntax Error. Workflow Id not specified.\n";
}
List<WorkflowPath> paths = workflowService.getWorkflowPaths(workflowId);
for (WorkflowPath path : paths) {
out.println("path id: " + path.getId() + " , node: " + path.getNode().getName());
}
} else if (command[1].equals("tasks")) {
String pathId = (command.length == 3) ? command[2] : (currentPath == null) ? null : currentPath.getId();
if (pathId == null) {
return "Syntax Error. Path Id not specified.\n";
}
List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(pathId);
for (WorkflowTask task : tasks) {
out.println("task id: " + task.getId() + " , name: " + task.getName() + " , properties: " + task.getProperties().size());
}
} else if (command[1].equals("transitions")) {
String workflowId = (command.length == 3) ? command[2] : (currentPath == null) ? null : currentPath.getInstance().getId();
if (workflowId == null) {
return "Syntax Error. Workflow Id not specified.\n";
}
List<WorkflowPath> paths = workflowService.getWorkflowPaths(workflowId);
if (paths.size() == 0) {
out.println("no further transitions");
}
for (WorkflowPath path : paths) {
out.println("path: " + path.getId() + " , node: " + path.getNode().getName() + " , active: " + path.isActive());
List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(path.getId());
for (WorkflowTask task : tasks) {
out.println(" task id: " + task.getId() + " , name: " + task.getName() + ", title: " + task.getTitle() + " , desc: " + task.getDescription() + " , properties: " + task.getProperties().size());
}
for (WorkflowTransition transition : path.getNode().getTransitions()) {
out.println(" transition id: " + ((transition.getId() == null || transition.getId().equals("")) ? "[default]" : transition.getId()) + " , title: " + transition.getTitle());
}
}
} else if (command[1].equals("timers")) {
String id = (currentWorkflowDef != null) ? currentWorkflowDef.getId() : null;
if (id == null && command.length == 2) {
return "workflow definition not in use. Enter command 'show timers all' or 'use <workflowDefId>'.\n";
}
if (command.length == 3) {
if (command[2].equals("all")) {
id = "all";
} else {
return "Syntax Error.\n";
}
}
List<WorkflowTimer> timers = new ArrayList<WorkflowTimer>();
if ("all".equals(id)) {
for (WorkflowDefinition def : workflowService.getAllDefinitions()) {
List<WorkflowInstance> workflows = workflowService.getActiveWorkflows(def.getId());
for (WorkflowInstance workflow : workflows) {
timers.addAll(workflowService.getTimers(workflow.getId()));
}
}
} else {
List<WorkflowInstance> workflows = workflowService.getActiveWorkflows(id);
for (WorkflowInstance workflow : workflows) {
timers.addAll(workflowService.getTimers(workflow.getId()));
}
}
for (WorkflowTimer timer : timers) {
out.print("id: " + timer.getId() + " , name: " + timer.getName() + " , due date: " + timer.getDueDate() + " , path: " + timer.getPath().getId() + " , node: " + timer.getPath().getNode().getName() + " , process: " + timer.getPath().getInstance().getId());
if (timer.getTask() != null) {
out.print(" , task: " + timer.getTask().getName() + "(" + timer.getTask().getId() + ")");
}
out.println();
if (timer.getError() != null) {
out.println("error executing timer id " + timer.getId());
out.println(timer.getError());
}
}
} else if (command[1].equals("my")) {
if (command.length != 3) {
return "Syntax Error.\n";
}
if (command[2].equals("tasks")) {
out.println(AuthenticationUtil.getRunAsUser() + ":");
List<WorkflowTask> tasks = workflowService.getAssignedTasks(AuthenticationUtil.getRunAsUser(), WorkflowTaskState.IN_PROGRESS);
for (WorkflowTask task : tasks) {
out.println("id: " + task.getId() + " , name: " + task.getName() + " , properties: " + task.getProperties().size() + " , workflow: " + task.getPath().getInstance().getId() + " , path: " + task.getPath().getId());
}
} else if (command[2].equals("completed")) {
out.println(AuthenticationUtil.getRunAsUser() + ":");
List<WorkflowTask> tasks = workflowService.getAssignedTasks(AuthenticationUtil.getRunAsUser(), WorkflowTaskState.COMPLETED);
for (WorkflowTask task : tasks) {
out.println("id: " + task.getId() + " , name " + task.getName() + " , properties: " + task.getProperties().size() + " , workflow: " + task.getPath().getInstance().getId() + " , path: " + task.getPath().getId());
}
} else if (command[2].equals("pooled")) {
out.println(AuthenticationUtil.getRunAsUser() + ":");
List<WorkflowTask> tasks = workflowService.getPooledTasks(AuthenticationUtil.getRunAsUser());
for (WorkflowTask task : tasks) {
out.println("id: " + task.getId() + " , name " + task.getName() + " , properties: " + task.getProperties().size() + " , workflow: " + task.getPath().getInstance().getId() + " , path: " + task.getPath().getId());
}
} else {
return "Syntax Error.\n";
}
} else {
return "Syntax Error.\n";
}
} else if (command[0].equals("desc")) {
if (command.length < 2) {
return "Syntax Error.\n";
}
if (command[1].equals("task")) {
if (command.length != 3) {
return "Syntax Error.\n";
}
WorkflowTask task = workflowService.getTaskById(command[2]);
out.println("id: " + task.getId());
out.println("name: " + task.getName());
out.println("title: " + task.getTitle());
out.println("description: " + task.getDescription());
out.println("state: " + task.getState());
out.println("path: " + task.getPath().getId());
out.println("transitions: " + task.getDefinition().getNode().getTransitions().length);
for (WorkflowTransition transition : task.getDefinition().getNode().getTransitions()) {
out.println(" transition: " + ((transition.getId() == null || transition.getId().equals("")) ? "[default]" : transition.getId()) + " , title: " + transition.getTitle() + " , desc: " + transition.getDescription());
}
out.println("properties: " + task.getProperties().size());
for (Map.Entry<QName, Serializable> prop : task.getProperties().entrySet()) {
out.println(" " + prop.getKey() + " = " + prop.getValue());
}
} else if (command[1].equals("workflow")) {
if (command.length != 3) {
return "Syntax Error.\n";
}
WorkflowInstance workflow = workflowService.getWorkflowById(command[2]);
out.println("definition: " + workflow.getDefinition().getName());
out.println("id: " + workflow.getId());
out.println("description: " + workflow.getDescription());
out.println("active: " + workflow.isActive());
out.println("start date: " + workflow.getStartDate());
out.println("end date: " + workflow.getEndDate());
out.println("initiator: " + workflow.getInitiator());
out.println("context: " + workflow.getContext());
out.println("package: " + workflow.getWorkflowPackage());
} else if (command[1].equals("path")) {
if (command.length != 3) {
return "Syntax Error.\n";
}
Map<QName, Serializable> properties = workflowService.getPathProperties(command[2]);
out.println("path: " + command[1]);
out.println("properties: " + properties.size());
for (Map.Entry<QName, Serializable> prop : properties.entrySet()) {
out.println(" " + prop.getKey() + " = " + prop.getValue());
}
} else {
return "Syntax Error.\n";
}
} else if (command[0].equals("query")) {
if (command.length < 2) {
return "Syntax Error.\n";
}
if (command[1].equals("task")) {
// build query
WorkflowTaskQuery query = new WorkflowTaskQuery();
Map<QName, Object> taskProps = new HashMap<QName, Object>();
Map<QName, Object> procProps = new HashMap<QName, Object>();
for (int i = 2; i < command.length; i++) {
String[] predicate = command[i].split("=");
if (predicate.length == 1) {
return "Syntax Error.\n";
}
String[] predicateName = predicate[0].split("\\.");
if (predicateName.length == 1) {
if (predicate[0].equals("taskId")) {
query.setTaskId(predicate[1]);
} else if (predicate[0].equals("taskState")) {
WorkflowTaskState state = WorkflowTaskState.valueOf(predicate[1]);
if (state == null) {
return "Syntax Error. Unknown task state\n";
}
query.setTaskState(state);
} else if (predicate[0].equals("taskName")) {
query.setTaskName(QName.createQName(predicate[1], namespaceService));
} else if (predicate[0].equals("taskActor")) {
query.setActorId(predicate[1]);
} else if (predicate[0].equals("processId")) {
query.setProcessId(predicate[1]);
} else if (predicate[0].equals("processName")) {
query.setProcessName(QName.createQName(predicate[1], namespaceService));
} else if (predicate[0].equals("workflowDefinitionName")) {
query.setWorkflowDefinitionName(predicate[1]);
} else if (predicate[0].equals("processActive")) {
Boolean active = Boolean.valueOf(predicate[1]);
query.setActive(active);
} else if (predicate[0].equals("orderBy")) {
String[] orderBy = predicate[1].split(",");
WorkflowTaskQuery.OrderBy[] queryOrderBy = new WorkflowTaskQuery.OrderBy[orderBy.length];
for (int iOrderBy = 0; iOrderBy < orderBy.length; iOrderBy++) {
queryOrderBy[iOrderBy] = WorkflowTaskQuery.OrderBy.valueOf(orderBy[iOrderBy]);
if (queryOrderBy[iOrderBy] == null) {
return "Syntax Error. Unknown orderBy.\n";
}
}
query.setOrderBy(queryOrderBy);
} else {
return "Syntax Error. Unknown query predicate.\n";
}
} else if (predicateName.length == 2) {
if (predicateName[0].equals("task")) {
taskProps.put(QName.createQName(predicateName[1], namespaceService), predicate[1]);
} else if (predicateName[0].equals("process")) {
procProps.put(QName.createQName(predicateName[1], namespaceService), predicate[1]);
} else {
return "Syntax Error. Unknown query predicate.\n";
}
} else {
return "Syntax Error.\n";
}
}
if (taskProps.size() > 0) {
query.setTaskCustomProps(taskProps);
}
if (procProps.size() > 0) {
query.setProcessCustomProps(procProps);
}
// execute query
List<WorkflowTask> tasks = workflowService.queryTasks(query);
out.println("found " + tasks.size() + " tasks.");
for (WorkflowTask task : tasks) {
out.println("task id: " + task.getId() + " , name: " + task.getName() + " , properties: " + task.getProperties().size() + ", process id: " + task.getPath().getInstance());
}
} else {
return "Syntax Error.\n";
}
} else if (command[0].equals("deploy")) {
if (command.length != 3) {
return "Syntax Error.\n";
}
ClassPathResource workflowDef = new ClassPathResource(command[2]);
WorkflowDeployment deployment = workflowService.deployDefinition(command[1], workflowDef.getInputStream(), MimetypeMap.MIMETYPE_XML);
WorkflowDefinition def = deployment.getDefinition();
for (String problem : deployment.getProblems()) {
out.println(problem);
}
out.println("deployed definition id: " + def.getId() + " , name: " + def.getName() + " , title: " + def.getTitle() + " , version: " + def.getVersion());
currentDeployEngine = command[1];
currentDeployResource = command[2];
out.print(executeCommand("use definition " + def.getId()));
} else if (command[0].equals("redeploy")) {
if (currentDeployResource == null) {
return "nothing to redeploy\n";
}
out.print(executeCommand("deploy " + currentDeployEngine + " " + currentDeployResource));
} else if (command[0].equals("undeploy")) {
if (command.length < 2) {
return "Syntax Error.\n";
}
if (command[1].equals("definition")) {
if (command.length == 3) {
workflowService.undeployDefinition(command[2]);
currentWorkflowDef = null;
currentPath = null;
out.print(executeCommand("show definitions"));
} else if (command.length == 4) {
if (command[2].equals("name")) {
out.print("undeploying...");
List<WorkflowDefinition> defs = workflowService.getAllDefinitionsByName(command[3]);
for (WorkflowDefinition def : defs) {
workflowService.undeployDefinition(def.getId());
out.print(" v" + def.getVersion());
}
out.println("");
currentWorkflowDef = null;
currentPath = null;
out.print(executeCommand("show definitions all"));
} else {
return "Syntax Error.\n";
}
} else {
return "Syntax Error.\n";
}
} else {
return "Syntax Error.\n";
}
} else if (command[0].equals("use")) {
if (command.length == 1) {
out.println("definition: " + ((currentWorkflowDef == null) ? "None" : currentWorkflowDef.getId() + " , name: " + currentWorkflowDef.getTitle() + " , version: " + currentWorkflowDef.getVersion()));
out.println("workflow: " + ((currentPath == null) ? "None" : currentPath.getInstance().getId() + " , active: " + currentPath.getInstance().isActive()));
out.println("path: " + ((currentPath == null) ? "None" : currentPath.getId() + " , node: " + currentPath.getNode().getTitle()));
} else if (command.length > 1) {
if (command[1].equals("definition")) {
if (command.length != 3) {
return "Syntax Error.\n";
}
WorkflowDefinition def = workflowService.getDefinitionById(command[2]);
if (def == null) {
return "Not found.\n";
}
currentWorkflowDef = def;
currentPath = null;
out.print(executeCommand("use"));
} else if (command[1].equals("workflow")) {
if (command.length != 3) {
return "Syntax Error.\n";
}
WorkflowInstance instance = workflowService.getWorkflowById(command[2]);
currentWorkflowDef = instance.getDefinition();
currentPath = workflowService.getWorkflowPaths(instance.getId()).get(0);
out.print(executeCommand("use"));
} else {
return "Syntax Error.\n";
}
}
} else if (command[0].equals("user")) {
if (command.length == 2) {
if (tenantService.isEnabled()) {
tenantService.checkDomainUser(command[1]);
}
NodeRef personRef = personService.getPerson(command[1]);
if (personRef == null) {
throw new WorkflowException("User " + command[1] + " does not exist.");
}
PersonInfo info = personService.getPerson(personRef);
String userName = info.getUserName();
setCurrentUserName(userName);
}
out.println("using user " + getCurrentUserName());
} else if (command[0].equals("start")) {
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
for (int i = 1; i < command.length; i++) {
String[] param = command[i].split("=");
QName qname = QName.createQName(param[0], namespaceService);
if (param.length == 1) {
if (!vars.containsKey(qname)) {
return "var " + qname + " not found.\n";
}
params.put(qname, vars.get(qname));
} else if (param.length == 2) {
params.put(qname, param[1]);
} else {
return "Syntax Error.\n";
}
}
if (currentWorkflowDef == null) {
return "Workflow definition not selected.\n";
}
setupStartTaskParameters(currentWorkflowDef.getStartTaskDefinition().metadata, params);
WorkflowPath path = workflowService.startWorkflow(currentWorkflowDef.getId(), params);
endStartTaskForPath(path);
out.println("started workflow id: " + path.getInstance().getId() + " , def: " + path.getInstance().getDefinition().getTitle());
currentPath = path;
out.print(interpretCommand("show transitions"));
} else if (command[0].equals("update")) {
if (command.length < 3) {
return "Syntax Error.\n";
}
if (command[1].equals("task")) {
if (command.length < 4) {
return "Syntax Error.\n";
}
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
for (int i = 3; i < command.length; i++) {
String[] param = command[i].split("=");
QName qname = QName.createQName(param[0], namespaceService);
if (param.length == 1) {
if (!vars.containsKey(qname)) {
return "var " + qname + " not found.\n";
}
params.put(qname, vars.get(qname));
} else if (param.length == 2) {
params.put(qname, param[1]);
} else {
return "Syntax Error.\n";
}
}
WorkflowTask task = workflowService.updateTask(command[2], params, null, null);
out.println("updated task id: " + command[2] + ", properties: " + task.getProperties().size());
} else {
return "Syntax Error.\n";
}
} else if (command[0].equals("signal")) {
if (command.length < 2) {
return "Syntax Error.\n";
}
WorkflowPath path = workflowService.signal(command[1], getTransition(command));
out.println("signal sent - path id: " + path.getId());
out.print(interpretCommand("show transitions"));
} else if (command[0].equals("event")) {
if (command.length < 3) {
return "Syntax Error.\n";
}
WorkflowPath path = workflowService.fireEvent(command[1], command[2]);
out.println("event " + command[2] + " fired - path id: " + path.getId());
out.print(interpretCommand("show transitions"));
} else if (command[0].equals("end")) {
if (command.length < 3) {
return "Syntax Error.\n";
}
if (command[1].equals("task")) {
WorkflowTask task = workflowService.endTask(command[2], (command.length == 4) ? command[3] : null);
out.println("signal sent - path id: " + task.getPath().getId());
// ACE-3137: "show transitions" will fail if we don't set the workflow path first.
currentPath = task.getPath();
out.print(interpretCommand("show transitions"));
} else if (command[1].equals("workflow")) {
String workflowId = (command.length == 3) ? command[2] : (currentPath == null) ? null : currentPath.getInstance().getId();
if (workflowId == null) {
return "Syntax Error. Workflow Id not specified.\n";
}
workflowService.cancelWorkflow(workflowId);
out.println("workflow " + workflowId + " cancelled.");
} else {
return "Syntax Error.\n";
}
} else if (command[0].equals("delete")) {
if (command.length < 2) {
return "Syntax Error.\n";
}
if (command[1].equals("workflow")) {
String workflowId = (command.length == 3) ? command[2] : (currentPath == null) ? null : currentPath.getInstance().getId();
if (workflowId == null) {
return "Syntax Error. Workflow Id not specified.\n";
}
workflowService.deleteWorkflow(workflowId);
out.println("workflow " + workflowId + " deleted.");
} else if (command[1].equals("all")) {
if (command.length < 3) {
return "Syntax Error.\n";
}
if (command[2].equals("workflows")) {
if (command.length < 4) {
return "Enter the command 'delete all workflows imeanit' to really delete all workflows\n";
}
if (command[3].equals("imeanit")) {
for (WorkflowDefinition def : workflowService.getAllDefinitions()) {
List<WorkflowInstance> workflows = workflowService.getActiveWorkflows(def.getId());
for (WorkflowInstance workflow : workflows) {
workflowService.deleteWorkflow(workflow.getId());
out.println("workflow " + workflow.getId() + " deleted.");
}
}
} else {
return "Syntax Error.\n";
}
} else {
return "Syntax Error.\n";
}
} else {
return "Syntax Error.\n";
}
} else if (command[0].equals("var")) {
if (command.length == 1) {
for (Map.Entry<QName, Serializable> entry : vars.entrySet()) {
out.println(entry.getKey() + " = " + entry.getValue());
}
} else if (command.length == 2) {
String[] param = command[1].split("=");
if (param.length == 0) {
return "Syntax Error.\n";
}
if (param.length == 1) {
QName qname = QName.createQName(param[0], namespaceService);
vars.remove(qname);
out.println("deleted var " + qname);
} else if (param.length == 2) {
boolean multi = false;
if (param[0].endsWith("*")) {
param[0] = param[0].substring(0, param[0].length() - 1);
multi = true;
}
QName qname = QName.createQName(param[0], namespaceService);
String[] strValues = param[1].split(",");
if (!multi && strValues.length > 1) {
return "Syntax Error.\n";
}
if (!multi) {
vars.put(qname, strValues[0]);
} else {
List<String> values = new ArrayList<String>();
for (String strValue : strValues) {
values.add(strValue);
}
vars.put(qname, (Serializable) values);
}
out.println("set var " + qname + " = " + vars.get(qname));
} else {
return "Syntax Error.\n";
}
} else if (command.length == 4) {
if (command[2].equals("person")) {
boolean multi = false;
if (command[1].endsWith("*")) {
command[1] = command[1].substring(0, command[1].length() - 1);
multi = true;
}
QName qname = QName.createQName(command[1], namespaceService);
String[] strValues = command[3].split(",");
if (!multi && strValues.length > 1) {
return "Syntax Error.\n";
}
if (!multi) {
NodeRef auth = personService.getPerson(strValues[0]);
vars.put(qname, auth);
} else {
List<NodeRef> values = new ArrayList<NodeRef>();
for (String strValue : strValues) {
NodeRef auth = personService.getPerson(strValue);
values.add(auth);
}
vars.put(qname, (Serializable) values);
}
out.println("set var " + qname + " = " + vars.get(qname));
} else if (command[2].equals("group")) {
boolean multi = false;
if (command[1].endsWith("*")) {
command[1] = command[1].substring(0, command[1].length() - 1);
multi = true;
}
QName qname = QName.createQName(command[1], namespaceService);
String[] strValues = command[3].split(",");
if (!multi && strValues.length > 1) {
return "Syntax Error.\n";
}
if (!multi) {
NodeRef auth = authorityDAO.getAuthorityNodeRefOrNull(strValues[0]);
if (auth == null) {
throw new WorkflowException("Group " + strValues[0] + " does not exist.");
}
vars.put(qname, auth);
} else {
List<NodeRef> values = new ArrayList<NodeRef>();
for (String strValue : strValues) {
NodeRef auth = authorityDAO.getAuthorityNodeRefOrNull(strValue);
if (auth == null) {
throw new WorkflowException("Group " + strValue + " does not exist.");
}
values.add(auth);
}
vars.put(qname, (Serializable) values);
}
out.println("set var " + qname + " = " + vars.get(qname));
} else if (command[2].equals("package")) {
QName qname = QName.createQName(command[1], namespaceService);
int number = new Integer(command[3]);
NodeRef packageNodeRef = workflowService.createPackage(null);
for (int i = 0; i < number; i++) {
FileInfo fileInfo = fileFolderService.create(packageNodeRef, "Content" + i, ContentModel.TYPE_CONTENT);
ContentWriter writer = fileFolderService.getWriter(fileInfo.getNodeRef());
writer.putContent("Content" + i);
}
vars.put(qname, packageNodeRef);
out.println("set var " + qname + " = " + vars.get(qname));
} else {
return "Syntax Error.\n";
}
} else {
return "Syntax Error.\n";
}
} else {
return "Syntax Error.\n";
}
out.flush();
String retVal = new String(bout.toByteArray());
out.close();
return retVal;
}
Aggregations