Java Code Examples for org.activiti.engine.impl.identity.Authentication#getAuthenticatedUserId()
The following examples show how to use
org.activiti.engine.impl.identity.Authentication#getAuthenticatedUserId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HistoricProcessInstanceEntity.java From flowable-engine with Apache License 2.0 | 6 votes |
public HistoricProcessInstanceEntity(ExecutionEntity processInstance) { id = processInstance.getId(); processInstanceId = processInstance.getId(); businessKey = processInstance.getBusinessKey(); processDefinitionId = processInstance.getProcessDefinitionId(); processDefinitionKey = processInstance.getProcessDefinitionKey(); processDefinitionName = processInstance.getProcessDefinitionName(); processDefinitionVersion = processInstance.getProcessDefinitionVersion(); deploymentId = processInstance.getDeploymentId(); startTime = Context.getProcessEngineConfiguration().getClock().getCurrentTime(); startUserId = Authentication.getAuthenticatedUserId(); startActivityId = processInstance.getActivityId(); superProcessInstanceId = processInstance.getSuperExecution() != null ? processInstance.getSuperExecution().getProcessInstanceId() : null; // Inherit tenant id (if applicable) if (processInstance.getTenantId() != null) { tenantId = processInstance.getTenantId(); } }
Example 2
Source File: DeleteTaskWithCommentCmd.java From lemon with Apache License 2.0 | 6 votes |
public Object execute(CommandContext commandContext) { TaskEntity taskEntity = commandContext.getTaskEntityManager() .findTaskById(taskId); // taskEntity.fireEvent(TaskListener.EVENTNAME_COMPLETE); if ((Authentication.getAuthenticatedUserId() != null) && (taskEntity.getProcessInstanceId() != null)) { taskEntity.getProcessInstance().involveUser( Authentication.getAuthenticatedUserId(), IdentityLinkType.PARTICIPANT); } Context.getCommandContext().getTaskEntityManager() .deleteTask(taskEntity, comment, false); if (taskEntity.getExecutionId() != null) { ExecutionEntity execution = taskEntity.getExecution(); execution.removeTask(taskEntity); // execution.signal(null, null); } return null; }
Example 3
Source File: FunctionEventListener.java From lemon with Apache License 2.0 | 6 votes |
public void onActivityStart(ActivitiActivityEvent event) { logger.debug("activity start {}", event); String processInstanceId = event.getProcessInstanceId(); ExecutionEntity executionEntity = Context.getCommandContext() .getExecutionEntityManager() .findExecutionById(processInstanceId); String businessKey = executionEntity.getBusinessKey(); String processDefinitionId = event.getProcessDefinitionId(); String activityId = event.getActivityId(); String activityName = this.findActivityName(activityId, processDefinitionId); int eventCode = 0; String eventName = "start"; String userId = Authentication.getAuthenticatedUserId(); this.invokeExpression(eventCode, eventName, businessKey, userId, activityId, activityName); }
Example 4
Source File: DefaultHistoryManager.java From flowable-engine with Apache License 2.0 | 6 votes |
@Override public void createAttachmentComment(String taskId, String processInstanceId, String attachmentName, boolean create) { if (isHistoryEnabled()) { String userId = Authentication.getAuthenticatedUserId(); CommentEntity comment = new CommentEntity(); comment.setUserId(userId); comment.setType(CommentEntity.TYPE_EVENT); comment.setTime(Context.getProcessEngineConfiguration().getClock().getCurrentTime()); comment.setTaskId(taskId); comment.setProcessInstanceId(processInstanceId); if (create) { comment.setAction(Event.ACTION_ADD_ATTACHMENT); } else { comment.setAction(Event.ACTION_DELETE_ATTACHMENT); } comment.setMessage(attachmentName); getSession(CommentEntityManager.class).insert(comment); } }
Example 5
Source File: FunctionEventListener.java From lemon with Apache License 2.0 | 6 votes |
public void onProcessCancelled(ActivitiCancelledEvent event) { logger.debug("process cancelled {}", event); String processInstanceId = event.getProcessInstanceId(); ExecutionEntity executionEntity = Context.getCommandContext() .getExecutionEntityManager() .findExecutionById(processInstanceId); String businessKey = executionEntity.getBusinessKey(); String processDefinitionId = event.getProcessDefinitionId(); String activityId = ""; String activityName = this.findActivityName(activityId, processDefinitionId); int eventCode = 23; String eventName = "process-close"; String userId = Authentication.getAuthenticatedUserId(); this.invokeExpression(eventCode, eventName, businessKey, userId, activityId, activityName); }
Example 6
Source File: FunctionEventListener.java From lemon with Apache License 2.0 | 6 votes |
public void onTaskCompleted(ActivitiEntityEvent event) { logger.debug("task completed {}", event); String processInstanceId = event.getProcessInstanceId(); ExecutionEntity executionEntity = Context.getCommandContext() .getExecutionEntityManager() .findExecutionById(processInstanceId); String businessKey = executionEntity.getBusinessKey(); String processDefinitionId = event.getProcessDefinitionId(); Task task = (Task) event.getEntity(); String activityId = task.getTaskDefinitionKey(); String activityName = this.findActivityName(activityId, processDefinitionId); int eventCode = 5; String eventName = "complete"; String userId = Authentication.getAuthenticatedUserId(); this.invokeExpression(eventCode, eventName, businessKey, userId, activityId, activityName); }
Example 7
Source File: DefaultHistoryManager.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
@Override public void createAttachmentComment(String taskId, String processInstanceId, String attachmentName, boolean create) { if (isHistoryEnabled()) { String userId = Authentication.getAuthenticatedUserId(); CommentEntity comment = getCommentEntityManager().create(); comment.setUserId(userId); comment.setType(CommentEntity.TYPE_EVENT); comment.setTime(getClock().getCurrentTime()); comment.setTaskId(taskId); comment.setProcessInstanceId(processInstanceId); if (create) { comment.setAction(Event.ACTION_ADD_ATTACHMENT); } else { comment.setAction(Event.ACTION_DELETE_ATTACHMENT); } comment.setMessage(attachmentName); getCommentEntityManager().insert(comment); } }
Example 8
Source File: FunctionEventListener.java From lemon with Apache License 2.0 | 6 votes |
public void onProcessCompleted(ActivitiEntityEvent event) { logger.debug("process completed {}", event); String processInstanceId = event.getProcessInstanceId(); ExecutionEntity executionEntity = Context.getCommandContext() .getExecutionEntityManager() .findExecutionById(processInstanceId); String businessKey = executionEntity.getBusinessKey(); String processDefinitionId = event.getProcessDefinitionId(); String activityId = ""; String activityName = this.findActivityName(activityId, processDefinitionId); int eventCode = 24; String eventName = "process-end"; String userId = Authentication.getAuthenticatedUserId(); this.invokeExpression(eventCode, eventName, businessKey, userId, activityId, activityName); }
Example 9
Source File: DefaultHistoryManager.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Override public void createProcessInstanceIdentityLinkComment(String processInstanceId, String userId, String groupId, String type, boolean create, boolean forceNullUserId) { if (isHistoryEnabled()) { String authenticatedUserId = Authentication.getAuthenticatedUserId(); CommentEntity comment = getCommentEntityManager().create(); comment.setUserId(authenticatedUserId); comment.setType(CommentEntity.TYPE_EVENT); comment.setTime(getClock().getCurrentTime()); comment.setProcessInstanceId(processInstanceId); if (userId != null || forceNullUserId) { if (create) { comment.setAction(Event.ACTION_ADD_USER_LINK); } else { comment.setAction(Event.ACTION_DELETE_USER_LINK); } comment.setMessage(new String[] { userId, type }); } else { if (create) { comment.setAction(Event.ACTION_ADD_GROUP_LINK); } else { comment.setAction(Event.ACTION_DELETE_GROUP_LINK); } comment.setMessage(new String[] { groupId, type }); } getCommentEntityManager().insert(comment); } }
Example 10
Source File: TaskEntity.java From flowable-engine with Apache License 2.0 | 5 votes |
@SuppressWarnings("rawtypes") public void complete(Map variablesMap, boolean localScope, boolean fireEvents) { if (getDelegationState() != null && getDelegationState() == DelegationState.PENDING) { throw new ActivitiException("A delegated task cannot be completed, but should be resolved instead."); } if (fireEvents) { fireEvent(TaskListener.EVENTNAME_COMPLETE); } if (Authentication.getAuthenticatedUserId() != null && processInstanceId != null) { getProcessInstance().involveUser(Authentication.getAuthenticatedUserId(), IdentityLinkType.PARTICIPANT); } if (Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled() && fireEvents) { Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent( ActivitiEventBuilder.createEntityWithVariablesEvent(FlowableEngineEventType.TASK_COMPLETED, this, variablesMap, localScope)); } Context .getCommandContext() .getTaskEntityManager() .deleteTask(this, TaskEntity.DELETE_REASON_COMPLETED, false); if (executionId != null) { ExecutionEntity execution = getExecution(); execution.removeTask(this); execution.signal(null, null); } }
Example 11
Source File: AbstractCompleteTaskCmd.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
protected void executeTaskComplete(CommandContext commandContext, TaskEntity taskEntity, Map<String, Object> variables, boolean localScope) { // Task complete logic if (taskEntity.getDelegationState() != null && taskEntity.getDelegationState().equals(DelegationState.PENDING)) { throw new ActivitiException("A delegated task cannot be completed, but should be resolved instead."); } commandContext.getProcessEngineConfiguration().getListenerNotificationHelper().executeTaskListeners(taskEntity, TaskListener.EVENTNAME_COMPLETE); if (Authentication.getAuthenticatedUserId() != null && taskEntity.getProcessInstanceId() != null) { ExecutionEntity processInstanceEntity = commandContext.getExecutionEntityManager().findById(taskEntity.getProcessInstanceId()); commandContext.getIdentityLinkEntityManager().involveUser(processInstanceEntity, Authentication.getAuthenticatedUserId(),IdentityLinkType.PARTICIPANT); } ActivitiEventDispatcher eventDispatcher = Context.getProcessEngineConfiguration().getEventDispatcher(); if (eventDispatcher.isEnabled()) { if (variables != null) { eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityWithVariablesEvent(ActivitiEventType.TASK_COMPLETED, taskEntity, variables, localScope)); } else { eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.TASK_COMPLETED, taskEntity)); } } commandContext.getTaskEntityManager().deleteTask(taskEntity, null, false, false); // Continue process (if not a standalone task) if (taskEntity.getExecutionId() != null) { ExecutionEntity executionEntity = commandContext.getExecutionEntityManager().findById(taskEntity.getExecutionId()); Context.getAgenda().planTriggerExecutionOperation(executionEntity); } }
Example 12
Source File: VariableScopeElResolver.java From flowable-engine with Apache License 2.0 | 5 votes |
@Override public Object getValue(ELContext context, Object base, Object property) { if (base == null) { String variable = (String) property; // according to javadoc, can only be a String if ((EXECUTION_KEY.equals(property) && variableScope instanceof ExecutionEntity) || (TASK_KEY.equals(property) && variableScope instanceof TaskEntity)) { context.setPropertyResolved(true); return variableScope; } else if (EXECUTION_KEY.equals(property) && variableScope instanceof TaskEntity) { context.setPropertyResolved(true); return ((TaskEntity) variableScope).getExecution(); } else if (LOGGED_IN_USER_KEY.equals(property)) { context.setPropertyResolved(true); return Authentication.getAuthenticatedUserId(); } else { if (variableScope.hasVariable(variable)) { context.setPropertyResolved(true); // if not set, the next elResolver in the CompositeElResolver will be called return variableScope.getVariable(variable); } } } // property resolution (eg. bean.value) will be done by the BeanElResolver (part of the CompositeElResolver) // It will use the bean resolved in this resolver as base. return null; }
Example 13
Source File: DefaultHistoryManager.java From flowable-engine with Apache License 2.0 | 5 votes |
@Override public void createProcessInstanceIdentityLinkComment(String processInstanceId, String userId, String groupId, String type, boolean create, boolean forceNullUserId) { if (isHistoryEnabled()) { String authenticatedUserId = Authentication.getAuthenticatedUserId(); CommentEntity comment = new CommentEntity(); comment.setUserId(authenticatedUserId); comment.setType(CommentEntity.TYPE_EVENT); comment.setTime(Context.getProcessEngineConfiguration().getClock().getCurrentTime()); comment.setProcessInstanceId(processInstanceId); if (userId != null || forceNullUserId) { if (create) { comment.setAction(Event.ACTION_ADD_USER_LINK); } else { comment.setAction(Event.ACTION_DELETE_USER_LINK); } comment.setMessage(new String[] { userId, type }); } else { if (create) { comment.setAction(Event.ACTION_ADD_GROUP_LINK); } else { comment.setAction(Event.ACTION_DELETE_GROUP_LINK); } comment.setMessage(new String[] { groupId, type }); } getSession(CommentEntityManager.class).insert(comment); } }
Example 14
Source File: VariableScopeElResolver.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public Object getValue(ELContext context, Object base, Object property) { if (base == null) { String variable = (String) property; // according to javadoc, can only be a String if ((EXECUTION_KEY.equals(property) && variableScope instanceof ExecutionEntity) || (TASK_KEY.equals(property) && variableScope instanceof TaskEntity)) { context.setPropertyResolved(true); return variableScope; } else if (EXECUTION_KEY.equals(property) && variableScope instanceof TaskEntity) { context.setPropertyResolved(true); return ((TaskEntity) variableScope).getExecution(); } else if (LOGGED_IN_USER_KEY.equals(property)) { context.setPropertyResolved(true); return Authentication.getAuthenticatedUserId(); } else { if (variableScope.hasVariable(variable)) { context.setPropertyResolved(true); // if not set, the next elResolver in the CompositeElResolver will be called return variableScope.getVariable(variable); } } } // property resolution (eg. bean.value) will be done by the // BeanElResolver (part of the CompositeElResolver) // It will use the bean resolved in this resolver as base. return null; }
Example 15
Source File: AbstractDatabaseEventLoggerEventHandler.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
protected EventLogEntryEntity createEventLogEntry(String type, String processDefinitionId, String processInstanceId, String executionId, String taskId, Map<String, Object> data) { EventLogEntryEntity eventLogEntry = Context.getCommandContext().getEventLogEntryEntityManager().create(); eventLogEntry.setProcessDefinitionId(processDefinitionId); eventLogEntry.setProcessInstanceId(processInstanceId); eventLogEntry.setExecutionId(executionId); eventLogEntry.setTaskId(taskId); eventLogEntry.setType(type); eventLogEntry.setTimeStamp(timeStamp); putInMapIfNotNull(data, Fields.TIMESTAMP, timeStamp); // Current user String userId = Authentication.getAuthenticatedUserId(); if (userId != null) { eventLogEntry.setUserId(userId); putInMapIfNotNull(data, "userId", userId); } // Current tenant if (!data.containsKey(Fields.TENANT_ID) && processDefinitionId != null) { ProcessDefinition processDefinition = ProcessDefinitionUtil.getProcessDefinition(processDefinitionId); if (processDefinition != null && !ProcessEngineConfigurationImpl.NO_TENANT_ID.equals(processDefinition.getTenantId())) { putInMapIfNotNull(data, Fields.TENANT_ID, processDefinition.getTenantId()); } } try { eventLogEntry.setData(objectMapper.writeValueAsBytes(data)); } catch (Exception e) { logger.warn("Could not serialize event data. Data will not be written to the database", e); } return eventLogEntry; }
Example 16
Source File: AbstractDatabaseEventLoggerEventHandler.java From flowable-engine with Apache License 2.0 | 4 votes |
protected EventLogEntryEntity createEventLogEntry(String type, String processDefinitionId, String processInstanceId, String executionId, String taskId, Map<String, Object> data) { EventLogEntryEntity eventLogEntry = new EventLogEntryEntity(); eventLogEntry.setProcessDefinitionId(processDefinitionId); eventLogEntry.setProcessInstanceId(processInstanceId); eventLogEntry.setExecutionId(executionId); eventLogEntry.setTaskId(taskId); eventLogEntry.setType(type); eventLogEntry.setTimeStamp(timeStamp); putInMapIfNotNull(data, Fields.TIMESTAMP, timeStamp); // Current user String userId = Authentication.getAuthenticatedUserId(); if (userId != null) { eventLogEntry.setUserId(userId); putInMapIfNotNull(data, "userId", userId); } // Current tenant if (!data.containsKey(Fields.TENANT_ID) && processDefinitionId != null) { DeploymentCache<ProcessDefinitionCacheEntry> processDefinitionCache = Context.getProcessEngineConfiguration().getProcessDefinitionCache(); if (processDefinitionCache != null) { ProcessDefinition processDefinition = processDefinitionCache.get(processDefinitionId).getProcessDefinition(); if (processDefinition != null && !ProcessEngineConfigurationImpl.NO_TENANT_ID.equals(processDefinition.getTenantId())) { putInMapIfNotNull(data, Fields.TENANT_ID, processDefinition.getTenantId()); } } } try { eventLogEntry.setData(objectMapper.writeValueAsBytes(data)); } catch (Exception e) { LOGGER.warn("Could not serialize event data. Data will not be written to the database", e); } return eventLogEntry; }
Example 17
Source File: AddCommentCmd.java From flowable-engine with Apache License 2.0 | 4 votes |
@Override public Comment execute(CommandContext commandContext) { // Validate task if (taskId != null) { TaskEntity task = commandContext.getTaskEntityManager().findTaskById(taskId); if (task == null) { throw new ActivitiObjectNotFoundException("Cannot find task with id " + taskId, Task.class); } if (task.isSuspended()) { throw new ActivitiException(getSuspendedTaskException()); } } if (processInstanceId != null) { ExecutionEntity execution = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId); if (execution == null) { throw new ActivitiObjectNotFoundException("execution " + processInstanceId + " doesn't exist", Execution.class); } if (execution.isSuspended()) { throw new ActivitiException(getSuspendedExceptionMessage()); } } String userId = Authentication.getAuthenticatedUserId(); CommentEntity comment = new CommentEntity(); comment.setUserId(userId); comment.setType((type == null) ? CommentEntity.TYPE_COMMENT : type); comment.setTime(commandContext.getProcessEngineConfiguration().getClock().getCurrentTime()); comment.setTaskId(taskId); comment.setProcessInstanceId(processInstanceId); comment.setAction(Event.ACTION_ADD_COMMENT); String eventMessage = message.replaceAll("\\s+", " "); if (eventMessage.length() > 163) { eventMessage = eventMessage.substring(0, 160) + "..."; } comment.setMessage(eventMessage); comment.setFullMessage(message); commandContext .getCommentEntityManager() .insert(comment); return comment; }
Example 18
Source File: UpdateProcessInstanceNameEventListener.java From lemon with Apache License 2.0 | 4 votes |
protected void onInitialized(ActivitiEvent event) { if (!(event instanceof ActivitiEntityEventImpl)) { return; } ActivitiEntityEventImpl activitiEntityEventImpl = (ActivitiEntityEventImpl) event; Object entity = activitiEntityEventImpl.getEntity(); if (!(entity instanceof ExecutionEntity)) { return; } ActivitiEventType activitiEventType = activitiEntityEventImpl.getType(); if (activitiEventType != ActivitiEventType.ENTITY_INITIALIZED) { return; } ExecutionEntity executionEntity = (ExecutionEntity) entity; if (!executionEntity.isProcessInstanceType()) { return; } String processInstanceId = executionEntity.getId(); String processDefinitionId = executionEntity.getProcessDefinitionId(); CommandContext commandContext = Context.getCommandContext(); ProcessDefinitionEntity processDefinition = new GetDeploymentProcessDefinitionCmd( processDefinitionId).execute(commandContext); // {流程标题:title}-{发起人:startUser}-{发起时间:startTime} String processDefinitionName = processDefinition.getName(); if (processDefinitionName == null) { processDefinitionName = processDefinition.getKey(); } String userId = Authentication.getAuthenticatedUserId(); String displayName = userConnector.findById(userId).getDisplayName(); String processInstanceName = processDefinitionName + "-" + displayName + "-" + new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date()); // runtime executionEntity.setName(processInstanceName); // history HistoricProcessInstanceEntity historicProcessInstanceEntity = commandContext .getHistoricProcessInstanceEntityManager() .findHistoricProcessInstance(processInstanceId); historicProcessInstanceEntity.setName(processInstanceName); }
Example 19
Source File: AddCommentCmd.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
public Comment execute(CommandContext commandContext) { TaskEntity task = null; // Validate task if (taskId != null) { task = commandContext.getTaskEntityManager().findById(taskId); if (task == null) { throw new ActivitiObjectNotFoundException("Cannot find task with id " + taskId, Task.class); } if (task.isSuspended()) { throw new ActivitiException(getSuspendedTaskException()); } } ExecutionEntity execution = null; if (processInstanceId != null) { execution = commandContext.getExecutionEntityManager().findById(processInstanceId); if (execution == null) { throw new ActivitiObjectNotFoundException("execution " + processInstanceId + " doesn't exist", Execution.class); } if (execution.isSuspended()) { throw new ActivitiException(getSuspendedExceptionMessage()); } } String processDefinitionId = null; if (execution != null) { processDefinitionId = execution.getProcessDefinitionId(); } else if (task != null) { processDefinitionId = task.getProcessDefinitionId(); } if (processDefinitionId != null && Activiti5Util.isActiviti5ProcessDefinitionId(commandContext, processDefinitionId)) { Activiti5CompatibilityHandler activiti5CompatibilityHandler = Activiti5Util.getActiviti5CompatibilityHandler(); return activiti5CompatibilityHandler.addComment(taskId, processInstanceId, type, message); } String userId = Authentication.getAuthenticatedUserId(); CommentEntity comment = commandContext.getCommentEntityManager().create(); comment.setUserId(userId); comment.setType((type == null) ? CommentEntity.TYPE_COMMENT : type); comment.setTime(commandContext.getProcessEngineConfiguration().getClock().getCurrentTime()); comment.setTaskId(taskId); comment.setProcessInstanceId(processInstanceId); comment.setAction(Event.ACTION_ADD_COMMENT); String eventMessage = message.replaceAll("\\s+", " "); if (eventMessage.length() > 163) { eventMessage = eventMessage.substring(0, 160) + "..."; } comment.setMessage(eventMessage); comment.setFullMessage(message); commandContext.getCommentEntityManager().insert(comment); return comment; }
Example 20
Source File: AutoCompleteFirstTaskListener.java From lemon with Apache License 2.0 | 4 votes |
@Override public void onCreate(DelegateTask delegateTask) throws Exception { String initiatorId = Authentication.getAuthenticatedUserId(); if (initiatorId == null) { return; } String assignee = delegateTask.getAssignee(); if (assignee == null) { return; } PvmActivity targetActivity = this.findFirstActivity(delegateTask .getProcessDefinitionId()); if (!targetActivity.getId().equals( delegateTask.getExecution().getCurrentActivityId())) { return; } if (!initiatorId.equals(assignee)) { return; } logger.debug("auto complete first task : {}", delegateTask); for (IdentityLink identityLink : delegateTask.getCandidates()) { String userId = identityLink.getUserId(); String groupId = identityLink.getGroupId(); if (userId != null) { delegateTask.deleteCandidateUser(userId); } if (groupId != null) { delegateTask.deleteCandidateGroup(groupId); } } // 对提交流程的任务进行特殊处理 HumanTaskDTO humanTaskDto = humanTaskConnector .findHumanTaskByTaskId(delegateTask.getId()); humanTaskDto.setCatalog(HumanTaskConstants.CATALOG_START); humanTaskConnector.saveHumanTask(humanTaskDto); // ((TaskEntity) delegateTask).complete(); // Context.getCommandContext().getHistoryManager().recordTaskId((TaskEntity) delegateTask); new CompleteTaskWithCommentCmd(delegateTask.getId(), null, "发起流程") .execute(Context.getCommandContext()); }