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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations