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

org.zodiac.flowable.engine.util.ProcessFlowCacheUtil Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.flowable.engine.util;

import org.flowable.engine.RepositoryService;
import org.flowable.engine.repository.ProcessDefinition;
import org.zodiac.commons.support.SpringContextHolder;
import org.zodiac.commons.util.Func;
import org.zodiac.sdk.toolkit.constants.StringPool;
import org.zodiac.security.SecurityCacheOperations;

import java.util.concurrent.atomic.AtomicReference;

/**
 * 流程缓存。
 *
 */
public abstract class ProcessFlowCacheUtil {

    private static final String FLOW_CACHE = "flow:process";
    private static final String FLOW_DEFINITION_ID = "definition:id";
    private static AtomicReference repositoryServiceRef = new AtomicReference<>();
    private static AtomicReference securityCacheOperationsRef = new AtomicReference<>();

    protected ProcessFlowCacheUtil() {
        super();
    }

    /**
     * 获得流程定义对象。
     *
     * @param processDefinitionId 流程对象id
     * @return 流程定义
     */
    public static ProcessDefinition getProcessDefinition(String processDefinitionId) {
        return getSecuritycacheoperations().get(FLOW_CACHE, FLOW_DEFINITION_ID, processDefinitionId, () -> getRepositoryService()
            .createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult());
    }

    /**
     * 获取流程类型名。
     *
     * @param category 流程类型
     * @param flowCategoryNameSupplier 类型名称提供者
     * @return 名称
     */
    public static String getCategoryName(String category, FlowCategoryNameSupplier flowCategoryNameSupplier) {
        if (Func.isEmpty(category)) {
            return StringPool.EMPTY;
        }
        String[] categoryArr = category.split(StringPool.UNDERSCORE);
        if (categoryArr.length <= 1) {
            return StringPool.EMPTY;
        } else {
            return null != flowCategoryNameSupplier ? flowCategoryNameSupplier.getName(category) : StringPool.EMPTY;
        }
    }

    private static RepositoryService getRepositoryService() {
        repositoryServiceRef.compareAndSet(null, SpringContextHolder.getBean(RepositoryService.class));
        return repositoryServiceRef.get();
    }

    private static SecurityCacheOperations getSecuritycacheoperations() {
        securityCacheOperationsRef.compareAndSet(null, SpringContextHolder.getBean(SecurityCacheOperations.class));
        return securityCacheOperationsRef.get();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy