All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.flowable.management.jmx.mbeans.ProcessDefinitionsMBean Maven / Gradle / Ivy

The newest version!
/* 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.flowable.management.jmx.mbeans;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

import org.flowable.engine.ProcessEngineConfiguration;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.DeploymentBuilder;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.management.jmx.annotations.ManagedAttribute;
import org.flowable.management.jmx.annotations.ManagedOperation;
import org.flowable.management.jmx.annotations.ManagedResource;

/**
 * @author Saeid Mirzaei
 */
@ManagedResource(description = "Process definition MBean")
public class ProcessDefinitionsMBean {

    RepositoryService repositoryService;

    public ProcessDefinitionsMBean(ProcessEngineConfiguration processEngineConfig) {
        if (processEngineConfig != null)
            repositoryService = processEngineConfig.getRepositoryService();
    }

    @ManagedAttribute(description = "List of Process definitions")
    public List> getProcessDefinitions() {
        List deployments = repositoryService.createProcessDefinitionQuery().list();
        List> result = new ArrayList<>(deployments.size());
        for (ProcessDefinition deployment : deployments) {
            List item = new ArrayList<>(3);
            item.add(deployment.getId());
            item.add(deployment.getName());
            item.add(Integer.toString(deployment.getVersion()));
            item.add(Boolean.toString(deployment.isSuspended()));
            item.add(deployment.getDescription());
            result.add(item);
        }
        return result;

    }

    @ManagedOperation(description = "get a specific process definition")
    public List getProcessDefinitionById(String id) {
        ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().processDefinitionId(id).singleResult();
        List item = new ArrayList<>(3);
        item.add(pd.getId());
        item.add(pd.getName());
        item.add(Integer.toString(pd.getVersion()));
        item.add(Boolean.toString(pd.isSuspended()));
        item.add(pd.getDescription());

        return item;

    }

    @ManagedAttribute(description = "List of deployed Processes")
    public List> getDeployments() {
        List deployments = repositoryService.createDeploymentQuery().list();
        List> result = new ArrayList<>(deployments.size());
        for (Deployment deployment : deployments) {
            List item = new ArrayList<>(3);
            item.add(deployment.getId());
            item.add(deployment.getName());
            item.add(deployment.getTenantId());
            result.add(item);
        }
        return result;

    }

    @ManagedOperation(description = "delete deployment")
    public void deleteDeployment(String deploymentId) {
        repositoryService.deleteDeployment(deploymentId);
    }

    @ManagedOperation(description = "Suspend given process ID")
    public void suspendProcessDefinitionById(String processId) {
        repositoryService.suspendProcessDefinitionById(processId);
    }

    @ManagedOperation(description = "Activate given process ID")
    public void activatedProcessDefinitionById(String processId) {
        repositoryService.activateProcessDefinitionById(processId);
    }

    @ManagedOperation(description = "Suspend given process ID")
    public void suspendProcessDefinitionByKey(String processDefinitionKey) {
        repositoryService.suspendProcessDefinitionByKey(processDefinitionKey);
    }

    @ManagedOperation(description = "Activate given process ID")
    public void activatedProcessDefinitionByKey(String processDefinitionKey) {
        repositoryService.activateProcessDefinitionByKey(processDefinitionKey);
    }

    @ManagedOperation(description = "Deploy Process Definition")
    public void deployProcessDefinition(String resourceName, String processDefinitionFile) throws FileNotFoundException {
        DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
        Deployment deployment = deploymentBuilder.addInputStream(resourceName, new FileInputStream(processDefinitionFile)).deploy();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy