Search in sources :

Example 6 with CommandContext

use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.

the class SignalThrowingEventListener method onEvent.

@Override
public void onEvent(ActivitiEvent event) {
    if (isValidEvent(event)) {
        if (event.getProcessInstanceId() == null && processInstanceScope) {
            throw new ActivitiIllegalArgumentException("Cannot throw process-instance scoped signal, since the dispatched event is not part of an ongoing process instance");
        }
        CommandContext commandContext = Context.getCommandContext();
        List<SignalEventSubscriptionEntity> subscriptionEntities = null;
        if (processInstanceScope) {
            subscriptionEntities = commandContext.getEventSubscriptionEntityManager().findSignalEventSubscriptionsByProcessInstanceAndEventName(event.getProcessInstanceId(), signalName);
        } else {
            String tenantId = null;
            if (event.getProcessDefinitionId() != null) {
                ProcessDefinitionEntity processDefinitionEntity = commandContext.getProcessEngineConfiguration().getDeploymentManager().findDeployedProcessDefinitionById(event.getProcessDefinitionId());
                tenantId = processDefinitionEntity.getTenantId();
            }
            subscriptionEntities = commandContext.getEventSubscriptionEntityManager().findSignalEventSubscriptionsByEventName(signalName, tenantId);
        }
        for (SignalEventSubscriptionEntity signalEventSubscriptionEntity : subscriptionEntities) {
            signalEventSubscriptionEntity.eventReceived(null, false);
        }
    }
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) SignalEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity)

Example 7 with CommandContext

use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.

the class DbSchemaDrop method main.

public static void main(String[] args) {
    ProcessEngineImpl processEngine = (ProcessEngineImpl) ProcessEngines.getDefaultProcessEngine();
    CommandExecutor commandExecutor = processEngine.getProcessEngineConfiguration().getCommandExecutor();
    CommandConfig config = new CommandConfig().transactionNotSupported();
    commandExecutor.execute(config, new Command<Object>() {

        public Object execute(CommandContext commandContext) {
            commandContext.getSession(DbSqlSession.class).dbSchemaDrop();
            return null;
        }
    });
}
Also used : CommandConfig(org.activiti.engine.impl.interceptor.CommandConfig) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) ProcessEngineImpl(org.activiti.engine.impl.ProcessEngineImpl)

Example 8 with CommandContext

use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.

the class EventSubscriptionEntity method scheduleEventAsync.

protected void scheduleEventAsync(Serializable payload) {
    final CommandContext commandContext = Context.getCommandContext();
    MessageEntity message = new MessageEntity();
    message.setJobHandlerType(ProcessEventJobHandler.TYPE);
    message.setJobHandlerConfiguration(id);
    message.setTenantId(getTenantId());
    GregorianCalendar expireCal = new GregorianCalendar();
    ProcessEngineConfiguration processEngineConfig = Context.getCommandContext().getProcessEngineConfiguration();
    expireCal.setTime(processEngineConfig.getClock().getCurrentTime());
    expireCal.add(Calendar.SECOND, processEngineConfig.getLockTimeAsyncJobWaitTime());
    message.setLockExpirationTime(expireCal.getTime());
    // TODO: support payload
    //    if(payload != null) {
    //      message.setEventPayload(payload);
    //    }
    commandContext.getJobEntityManager().send(message);
}
Also used : ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) GregorianCalendar(java.util.GregorianCalendar)

Example 9 with CommandContext

use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.

the class ProcessDefinitionInfoCache method get.

public ProcessDefinitionInfoCacheObject get(final String processDefinitionId) {
    ProcessDefinitionInfoCacheObject infoCacheObject = null;
    if (cache.containsKey(processDefinitionId)) {
        infoCacheObject = commandExecutor.execute(new Command<ProcessDefinitionInfoCacheObject>() {

            @Override
            public ProcessDefinitionInfoCacheObject execute(CommandContext commandContext) {
                ProcessDefinitionInfoEntityManager infoEntityManager = commandContext.getProcessDefinitionInfoEntityManager();
                ObjectMapper objectMapper = commandContext.getProcessEngineConfiguration().getObjectMapper();
                ProcessDefinitionInfoCacheObject cacheObject = cache.get(processDefinitionId);
                ProcessDefinitionInfoEntity infoEntity = infoEntityManager.findProcessDefinitionInfoByProcessDefinitionId(processDefinitionId);
                if (infoEntity != null && infoEntity.getRevision() != cacheObject.getRevision()) {
                    cacheObject.setRevision(infoEntity.getRevision());
                    if (infoEntity.getInfoJsonId() != null) {
                        byte[] infoBytes = infoEntityManager.findInfoJsonById(infoEntity.getInfoJsonId());
                        try {
                            ObjectNode infoNode = (ObjectNode) objectMapper.readTree(infoBytes);
                            cacheObject.setInfoNode(infoNode);
                        } catch (Exception e) {
                            throw new ActivitiException("Error reading json info node for process definition " + processDefinitionId, e);
                        }
                    }
                } else if (infoEntity == null) {
                    cacheObject.setRevision(0);
                    cacheObject.setInfoNode(objectMapper.createObjectNode());
                }
                return cacheObject;
            }
        });
    }
    return infoCacheObject;
}
Also used : ProcessDefinitionInfoEntityManager(org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntityManager) ActivitiException(org.activiti.engine.ActivitiException) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Command(org.activiti.engine.impl.interceptor.Command) ProcessDefinitionInfoEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntity) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ActivitiException(org.activiti.engine.ActivitiException)

Example 10 with CommandContext

use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.

the class BaseJPARestTestCase method assertAndEnsureCleanDb.

/** Each test is assumed to clean up all DB content it entered.
   * After a test method executed, this method scans all tables to see if the DB is completely clean. 
   * It throws AssertionFailed in case the DB is not clean.
   * If the DB is not clean, it is cleaned by performing a create a drop. */
protected void assertAndEnsureCleanDb() throws Throwable {
    log.debug("verifying that db is clean after test");
    Map<String, Long> tableCounts = managementService.getTableCount();
    StringBuilder outputMessage = new StringBuilder();
    for (String tableName : tableCounts.keySet()) {
        String tableNameWithoutPrefix = tableName.replace(processEngineConfiguration.getDatabaseTablePrefix(), "");
        if (!TABLENAMES_EXCLUDED_FROM_DB_CLEAN_CHECK.contains(tableNameWithoutPrefix)) {
            Long count = tableCounts.get(tableName);
            if (count != 0L) {
                outputMessage.append("  " + tableName + ": " + count + " record(s) ");
            }
        }
    }
    if (outputMessage.length() > 0) {
        outputMessage.insert(0, "DB NOT CLEAN: \n");
        log.error(EMPTY_LINE);
        log.error(outputMessage.toString());
        log.info("dropping and recreating db");
        CommandExecutor commandExecutor = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getCommandExecutor();
        commandExecutor.execute(new Command<Object>() {

            public Object execute(CommandContext commandContext) {
                DbSqlSession session = commandContext.getSession(DbSqlSession.class);
                session.dbSchemaDrop();
                session.dbSchemaCreate();
                return null;
            }
        });
        if (exception != null) {
            throw exception;
        } else {
            Assert.fail(outputMessage.toString());
        }
    } else {
        log.info("database was clean");
    }
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) DbSqlSession(org.activiti.engine.impl.db.DbSqlSession)

Aggregations

CommandContext (org.activiti.engine.impl.interceptor.CommandContext)72 CommandExecutor (org.activiti.engine.impl.interceptor.CommandExecutor)18 DbSqlSession (org.activiti.engine.impl.db.DbSqlSession)13 SignalEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity)8 Date (java.util.Date)7 ActivitiException (org.activiti.engine.ActivitiException)7 CommandConfig (org.activiti.engine.impl.interceptor.CommandConfig)7 EventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity)7 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)7 MessageEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity)6 HashMap (java.util.HashMap)4 TimerEntity (org.activiti.engine.impl.persistence.entity.TimerEntity)4 Job (org.activiti.engine.runtime.Job)4 Deployment (org.activiti.engine.test.Deployment)4 ArrayList (java.util.ArrayList)3 GregorianCalendar (java.util.GregorianCalendar)3 List (java.util.List)3 ExtensionElement (org.activiti.bpmn.model.ExtensionElement)3 DynamicBpmnService (org.activiti.engine.DynamicBpmnService)3 JobEntity (org.activiti.engine.impl.persistence.entity.JobEntity)3