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