Search in sources :

Example 1 with ProcessDefinitionEntityManager

use of org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntityManager in project Activiti by Activiti.

the class BpmnDeploymentHelper method getPersistedInstanceOfProcessDefinition.

/**
 * Gets the persisted version of the already-deployed process definition.  Note that this is
 * different from {@link #getMostRecentVersionOfProcessDefinition} as it looks specifically for
 * a process definition that is already persisted and attached to a particular deployment,
 * rather than the latest version across all deployments.
 */
public ProcessDefinitionEntity getPersistedInstanceOfProcessDefinition(ProcessDefinitionEntity processDefinition) {
    String deploymentId = processDefinition.getDeploymentId();
    if (StringUtils.isEmpty(processDefinition.getDeploymentId())) {
        throw new IllegalStateException("Provided process definition must have a deployment id.");
    }
    ProcessDefinitionEntityManager processDefinitionManager = Context.getCommandContext().getProcessEngineConfiguration().getProcessDefinitionEntityManager();
    ProcessDefinitionEntity persistedProcessDefinition = null;
    if (processDefinition.getTenantId() == null || ProcessEngineConfiguration.NO_TENANT_ID.equals(processDefinition.getTenantId())) {
        persistedProcessDefinition = processDefinitionManager.findProcessDefinitionByDeploymentAndKey(deploymentId, processDefinition.getKey());
    } else {
        persistedProcessDefinition = processDefinitionManager.findProcessDefinitionByDeploymentAndKeyAndTenantId(deploymentId, processDefinition.getKey(), processDefinition.getTenantId());
    }
    return persistedProcessDefinition;
}
Also used : ProcessDefinitionEntityManager(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntityManager) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)

Example 2 with ProcessDefinitionEntityManager

use of org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntityManager in project Activiti by Activiti.

the class AbstractSetProcessDefinitionStateCmd method findProcessDefinition.

protected List<ProcessDefinitionEntity> findProcessDefinition(CommandContext commandContext) {
    // we don't need to do an extra database fetch and we can simply return it, wrapped in a list
    if (processDefinitionEntity != null) {
        return singletonList(processDefinitionEntity);
    }
    // Validation of input parameters
    if (processDefinitionId == null && processDefinitionKey == null) {
        throw new ActivitiIllegalArgumentException("Process definition id or key cannot be null");
    }
    List<ProcessDefinitionEntity> processDefinitionEntities = new ArrayList<ProcessDefinitionEntity>();
    ProcessDefinitionEntityManager processDefinitionManager = commandContext.getProcessDefinitionEntityManager();
    if (processDefinitionId != null) {
        ProcessDefinitionEntity processDefinitionEntity = processDefinitionManager.findById(processDefinitionId);
        if (processDefinitionEntity == null) {
            throw new ActivitiObjectNotFoundException("Cannot find process definition for id '" + processDefinitionId + "'", ProcessDefinition.class);
        }
        processDefinitionEntities.add(processDefinitionEntity);
    } else {
        ProcessDefinitionQueryImpl query = new ProcessDefinitionQueryImpl(commandContext).processDefinitionKey(processDefinitionKey);
        if (tenantId == null || ProcessEngineConfiguration.NO_TENANT_ID.equals(tenantId)) {
            query.processDefinitionWithoutTenantId();
        } else {
            query.processDefinitionTenantId(tenantId);
        }
        List<ProcessDefinition> processDefinitions = query.list();
        if (processDefinitions.isEmpty()) {
            throw new ActivitiException("Cannot find process definition for key '" + processDefinitionKey + "'");
        }
        for (ProcessDefinition processDefinition : processDefinitions) {
            processDefinitionEntities.add((ProcessDefinitionEntity) processDefinition);
        }
    }
    return processDefinitionEntities;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ProcessDefinitionEntityManager(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntityManager) ProcessDefinitionQueryImpl(org.activiti.engine.impl.ProcessDefinitionQueryImpl) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ArrayList(java.util.ArrayList) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 3 with ProcessDefinitionEntityManager

use of org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntityManager in project Activiti by Activiti.

the class ProcessDefinitionUtil method getProcessDefinitionFromDatabase.

public static ProcessDefinitionEntity getProcessDefinitionFromDatabase(String processDefinitionId) {
    ProcessDefinitionEntityManager processDefinitionEntityManager = Context.getProcessEngineConfiguration().getProcessDefinitionEntityManager();
    ProcessDefinitionEntity processDefinition = processDefinitionEntityManager.findById(processDefinitionId);
    if (processDefinition == null) {
        throw new ActivitiException("No process definition found with id " + processDefinitionId);
    }
    return processDefinition;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ProcessDefinitionEntityManager(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntityManager) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)

Example 4 with ProcessDefinitionEntityManager

use of org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntityManager in project carbon-business-process by wso2.

the class ProcessInstanceService method isValidUserToStartProcess.

private boolean isValidUserToStartProcess(ProcessInstanceCreateRequest processInstanceCreateRequest) {
    // check whether the users/groups exist
    String processDefinitionId = processInstanceCreateRequest.getProcessDefinitionId();
    RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
    if (processDefinitionId == null) {
        final String processDefinitionKey = processInstanceCreateRequest.getProcessDefinitionKey();
        final String tenantId = processInstanceCreateRequest.getTenantId();
        ProcessEngine processEngine = BPMNOSGIService.getBPMNEngineService().getProcessEngine();
        if (processEngine != null) {
            if (processDefinitionKey != null) {
                if (((ProcessEngineImpl) processEngine).getProcessEngineConfiguration() != null) {
                    CommandExecutor commandExecutor = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getCommandExecutor();
                    if (commandExecutor != null) {
                        processDefinitionId = (String) commandExecutor.execute(new Command<Object>() {

                            public Object execute(CommandContext commandContext) {
                                ProcessDefinitionEntityManager processDefinitionEntityManager = commandContext.getSession(ProcessDefinitionEntityManager.class);
                                ProcessDefinitionEntity processDefinitionEntity = processDefinitionEntityManager.findLatestProcessDefinitionByKeyAndTenantId(processDefinitionKey, tenantId);
                                if (processDefinitionEntity != null && processDefinitionEntity.getProcessDefinition() != null) {
                                    return processDefinitionEntity.getProcessDefinition().getId();
                                }
                                return null;
                            }
                        });
                    }
                }
                if (processDefinitionId == null) {
                    return false;
                }
            }
            String messageName = processInstanceCreateRequest.getMessage();
            if (messageName != null && !messageName.isEmpty()) {
                ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery().messageEventSubscriptionName(messageName);
                if (processDefinitionQuery != null) {
                    processDefinitionQuery = processDefinitionQuery.processDefinitionTenantId(processInstanceCreateRequest.getTenantId());
                    if (processDefinitionQuery != null && processDefinitionQuery.count() > 1) {
                        processDefinitionQuery = processDefinitionQuery.latestVersion();
                    }
                }
                if (processDefinitionQuery != null) {
                    ProcessDefinition processDefinition = processDefinitionQuery.singleResult();
                    if (processDefinition != null) {
                        processDefinitionId = processDefinition.getId();
                    }
                }
                if (processDefinitionId == null) {
                    return false;
                }
            }
        }
    }
    PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    String userName = carbonContext.getUsername();
    String tenantDomain = carbonContext.getTenantDomain();
    String userNameWithTenantDomain = userName + "@" + tenantDomain;
    BPSGroupIdentityManager bpsGroupIdentityManager = BPMNOSGIService.getGroupIdentityManager();
    List<Group> groupList = bpsGroupIdentityManager.findGroupsByUser(userName);
    List<IdentityLink> identityLinkList = repositoryService.getIdentityLinksForProcessDefinition(processDefinitionId);
    boolean valueExistsForUserId = false;
    boolean valueExistsForGroupId = false;
    for (IdentityLink identityLink : identityLinkList) {
        String userId = identityLink.getUserId();
        if (userId != null) {
            valueExistsForUserId = true;
            if (userId.contains("$")) {
                userId = resolveVariable(processInstanceCreateRequest, userId);
            }
            if (!userId.isEmpty() && (userId.equals(userName) || userId.equals(userNameWithTenantDomain))) {
                return true;
            }
            continue;
        }
        String groupId = identityLink.getGroupId();
        if (groupId != null) {
            valueExistsForGroupId = true;
            if (groupId.contains("$")) {
                groupId = resolveVariable(processInstanceCreateRequest, groupId);
            }
            for (Group identityGroup : groupList) {
                if (!groupId.isEmpty() && identityGroup.getId() != null && identityGroup.getId().equals(groupId)) {
                    return true;
                }
            }
        }
    }
    if (!valueExistsForGroupId && !valueExistsForUserId) {
        return true;
    }
    return false;
}
Also used : Group(org.activiti.engine.identity.Group) ProcessDefinitionEntityManager(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntityManager) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) ProcessDefinitionQuery(org.activiti.engine.repository.ProcessDefinitionQuery) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) RestIdentityLink(org.wso2.carbon.bpmn.rest.model.common.RestIdentityLink) IdentityLink(org.activiti.engine.task.IdentityLink) BPSGroupIdentityManager(org.wso2.carbon.bpmn.core.integration.BPSGroupIdentityManager) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) RepositoryService(org.activiti.engine.RepositoryService) ProcessEngine(org.activiti.engine.ProcessEngine)

Example 5 with ProcessDefinitionEntityManager

use of org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntityManager in project Activiti by Activiti.

the class BpmnDeploymentHelper method getMostRecentVersionOfProcessDefinition.

/**
 * Gets the most recent persisted process definition that matches this one for tenant and key.
 * If none is found, returns null.  This method assumes that the tenant and key are properly
 * set on the process definition entity.
 */
public ProcessDefinitionEntity getMostRecentVersionOfProcessDefinition(ProcessDefinitionEntity processDefinition) {
    String key = processDefinition.getKey();
    String tenantId = processDefinition.getTenantId();
    ProcessDefinitionEntityManager processDefinitionManager = Context.getCommandContext().getProcessEngineConfiguration().getProcessDefinitionEntityManager();
    ProcessDefinitionEntity existingDefinition = null;
    if (tenantId != null && !tenantId.equals(ProcessEngineConfiguration.NO_TENANT_ID)) {
        existingDefinition = processDefinitionManager.findLatestProcessDefinitionByKeyAndTenantId(key, tenantId);
    } else {
        existingDefinition = processDefinitionManager.findLatestProcessDefinitionByKey(key);
    }
    return existingDefinition;
}
Also used : ProcessDefinitionEntityManager(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntityManager) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)

Aggregations

ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)6 ProcessDefinitionEntityManager (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntityManager)6 ActivitiException (org.activiti.engine.ActivitiException)2 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)2 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)2 ArrayList (java.util.ArrayList)1 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)1 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)1 ProcessEngine (org.activiti.engine.ProcessEngine)1 RepositoryService (org.activiti.engine.RepositoryService)1 Group (org.activiti.engine.identity.Group)1 ProcessDefinitionQueryImpl (org.activiti.engine.impl.ProcessDefinitionQueryImpl)1 CommandExecutor (org.activiti.engine.impl.interceptor.CommandExecutor)1 ProcessDefinitionQuery (org.activiti.engine.repository.ProcessDefinitionQuery)1 IdentityLink (org.activiti.engine.task.IdentityLink)1 BPSGroupIdentityManager (org.wso2.carbon.bpmn.core.integration.BPSGroupIdentityManager)1 RestIdentityLink (org.wso2.carbon.bpmn.rest.model.common.RestIdentityLink)1 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)1