/*
* JBoss, Home of Professional Open Source.
* Copyright 2006, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file 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.integration.console;
import org.jboss.bpm.console.client.model.DeploymentRef;
import org.jboss.bpm.console.client.model.JobRef;
import org.jboss.bpm.console.server.plugin.ProcessEnginePlugin;
import org.jbpm.api.*;
import org.jbpm.api.job.Job;
import org.jbpm.pvm.internal.env.EnvironmentFactory;
import org.jbpm.pvm.internal.env.Environment;
import java.util.ArrayList;
import java.util.List;
/**
* @author Heiko.Braun <heiko.braun@jboss.com>
*/
public class ProcessEnginePluginImpl extends JBPMIntegration
implements ProcessEnginePlugin
{
public ProcessEnginePluginImpl()
{
initializeProcessEngine();
}
public List<DeploymentRef> getDeployments()
{
List<DeploymentRef> results = new ArrayList<DeploymentRef>();
Environment env = ((EnvironmentFactory)processEngine).openEnvironment();
try
{
RepositoryService repositoryService = this.processEngine.getRepositoryService();
DeploymentQuery dquery = repositoryService.createDeploymentQuery();
List<Deployment> dpls = dquery.list();
for(Deployment dpl : dpls)
{
DeploymentRef ref = ModelAdaptor.adoptDeployment(dpl);
// active processes
ProcessDefinitionQuery pdQuery = repositoryService.createProcessDefinitionQuery();
pdQuery.deploymentId(dpl.getId());
List<ProcessDefinition> activePds = pdQuery.list();
for(ProcessDefinition p : activePds)
{
ref.getDefinitions().add(p.getId());
}
// suspended processes
ProcessDefinitionQuery pdQuery2 = repositoryService.createProcessDefinitionQuery();
pdQuery2.deploymentId(dpl.getId());
pdQuery2.suspended();
List<ProcessDefinition> suspendedPds = pdQuery2.list();
for(ProcessDefinition p : suspendedPds)
{
ref.getDefinitions().add(p.getId());
}
results.add(ref);
}
return results;
}
finally
{
env.close();
}
}
public void deleteDeployment(String id)
{
Environment env = ((EnvironmentFactory)processEngine).openEnvironment();
try
{
RepositoryService repositoryService = this.processEngine.getRepositoryService();
repositoryService.deleteDeploymentCascade(id);
}
finally
{
env.close();
}
}
public void suspendDeployment(String id, boolean isSuspended)
{
Environment env = ((EnvironmentFactory)processEngine).openEnvironment();
try
{
RepositoryService repositoryService = this.processEngine.getRepositoryService();
if(isSuspended)
repositoryService.suspendDeployment(id);
else
repositoryService.resumeDeployment(id);
}
finally
{
env.close();
}
}
public List<JobRef> getJobs()
{
List<JobRef> results = new ArrayList<JobRef>();
Environment env = ((EnvironmentFactory)processEngine).openEnvironment();
try
{
ManagementService mgmtService = this.processEngine.getManagementService();
// jobs
JobQuery timerQuery = mgmtService.createJobQuery();
timerQuery.timers();
List<Job> timers = timerQuery.list();
for(Job t : timers)
{
JobRef ref = ModelAdaptor.adoptJob(t);
ref.setType("timer");
results.add(ref);
}
// messages
JobQuery msgQuery= mgmtService.createJobQuery();
msgQuery.messages();
List<Job> msgs = msgQuery.list();
for(Job t : msgs)
{
JobRef ref = ModelAdaptor.adoptJob(t);
ref.setType("message");
results.add(ref);
}
}
finally
{
env.close();
}
return results;
}
public void executeJob(String jobId)
{
Environment env = ((EnvironmentFactory)processEngine).openEnvironment();
try
{
ManagementService mgmtService = this.processEngine.getManagementService();
mgmtService.executeJob(jobId);
}
finally
{
env.close();
}
}
}