Java Code Examples for org.activiti.engine.impl.interceptor.CommandContext#getDbSqlSession()

The following examples show how to use org.activiti.engine.impl.interceptor.CommandContext#getDbSqlSession() . 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: TaskEntity.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public void insert(ExecutionEntity execution, boolean fireEvents) {
    CommandContext commandContext = Context.getCommandContext();
    DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
    dbSqlSession.insert(this);

    // Inherit tenant id (if applicable)
    if (execution != null && execution.getTenantId() != null) {
        setTenantId(execution.getTenantId());
    }

    if (execution != null) {
        execution.addTask(this);
    }

    commandContext.getHistoryManager().recordTaskCreated(this, execution);

    if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled() && fireEvents) {
        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
                ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_CREATED, this));
        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
                ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_INITIALIZED, this));
    }
}
 
Example 2
Source File: TaskEntity.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public void update() {
    // Needed to make history work: the setter will also update the historic task
    setOwner(this.getOwner());
    setAssignee(this.getAssignee(), true, false);
    setDelegationState(this.getDelegationState());
    setName(this.getName());
    setDescription(this.getDescription());
    setPriority(this.getPriority());
    setCategory(this.getCategory());
    setCreateTime(this.getCreateTime());
    setDueDate(this.getDueDate());
    setParentTaskId(this.getParentTaskId());
    setFormKey(formKey);

    CommandContext commandContext = Context.getCommandContext();
    DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
    dbSqlSession.update(this);

    if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
                ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_UPDATED, this));
    }
}
 
Example 3
Source File: SchemaOperationsProcessEngineBuild.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public Object execute(CommandContext commandContext) {
  DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
  if (dbSqlSession != null) {
    dbSqlSession.performSchemaOperationsProcessEngineBuild();
  }
  return null;
}
 
Example 4
Source File: ModelEntityManager.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void updateModel(ModelEntity updatedModel) {
    CommandContext commandContext = Context.getCommandContext();
    updatedModel.setLastUpdateTime(Context.getProcessEngineConfiguration().getClock().getCurrentTime());
    DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
    dbSqlSession.update(updatedModel);

    if (Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
                ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_UPDATED, updatedModel));
    }
}
 
Example 5
Source File: ProcessDefinitionInfoEntityManager.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void updateProcessDefinitionInfo(ProcessDefinitionInfoEntity updatedProcessDefinitionInfo) {
    CommandContext commandContext = Context.getCommandContext();
    DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
    dbSqlSession.update(updatedProcessDefinitionInfo);

    if (Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
                ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_UPDATED, updatedProcessDefinitionInfo));
    }
}
 
Example 6
Source File: GetAttachmentContentCmd.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public InputStream execute(CommandContext commandContext) {
    DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
    AttachmentEntity attachment = dbSqlSession.selectById(AttachmentEntity.class, attachmentId);

    String contentId = attachment.getContentId();
    if (contentId == null) {
        return null;
    }

    ByteArrayEntity byteArray = dbSqlSession.selectById(ByteArrayEntity.class, contentId);
    byte[] bytes = byteArray.getBytes();

    return new ByteArrayInputStream(bytes);
}
 
Example 7
Source File: CreateAttachmentCmd.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public Attachment execute(CommandContext commandContext) {

    verifyParameters(commandContext);

    AttachmentEntity attachment = new AttachmentEntity();
    attachment.setName(attachmentName);
    attachment.setDescription(attachmentDescription);
    attachment.setType(attachmentType);
    attachment.setTaskId(taskId);
    attachment.setProcessInstanceId(processInstanceId);
    attachment.setUrl(url);
    attachment.setUserId(Authentication.getAuthenticatedUserId());
    attachment.setTime(commandContext.getProcessEngineConfiguration().getClock().getCurrentTime());

    DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
    dbSqlSession.insert(attachment);

    if (content != null) {
        byte[] bytes = IoUtil.readInputStream(content, attachmentName);
        ByteArrayEntity byteArray = ByteArrayEntity.createAndInsert(bytes);
        attachment.setContentId(byteArray.getId());
        attachment.setContent(byteArray);
    }

    commandContext.getHistoryManager()
            .createAttachmentComment(taskId, processInstanceId, attachmentName, true);

    if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        // Forced to fetch the process-instance to associate the right process definition
        String processDefinitionId = null;
        if (attachment.getProcessInstanceId() != null) {
            ExecutionEntity process = commandContext.getExecutionEntityManager().findExecutionById(processInstanceId);
            if (process != null) {
                processDefinitionId = process.getProcessDefinitionId();
            }
        }

        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
                ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_CREATED, attachment, processInstanceId, processInstanceId, processDefinitionId));
        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
                ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_INITIALIZED, attachment, processInstanceId, processInstanceId, processDefinitionId));
    }

    return attachment;
}