use of org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl in project Activiti by Activiti.
the class BpmnDeployer method deploy.
public void deploy(DeploymentEntity deployment, Map<String, Object> deploymentSettings) {
log.debug("Processing deployment {}", deployment.getName());
List<ProcessDefinitionEntity> processDefinitions = new ArrayList<ProcessDefinitionEntity>();
Map<String, ResourceEntity> resources = deployment.getResources();
Map<String, BpmnModel> bpmnModelMap = new HashMap<String, BpmnModel>();
final ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
for (String resourceName : resources.keySet()) {
log.info("Processing resource {}", resourceName);
if (isBpmnResource(resourceName)) {
ResourceEntity resource = resources.get(resourceName);
byte[] bytes = resource.getBytes();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
BpmnParse bpmnParse = bpmnParser.createParse().sourceInputStream(inputStream).setSourceSystemId(resourceName).deployment(deployment).name(resourceName);
if (deploymentSettings != null) {
// Schema validation if needed
if (deploymentSettings.containsKey(DeploymentSettings.IS_BPMN20_XSD_VALIDATION_ENABLED)) {
bpmnParse.setValidateSchema((Boolean) deploymentSettings.get(DeploymentSettings.IS_BPMN20_XSD_VALIDATION_ENABLED));
}
// Process validation if needed
if (deploymentSettings.containsKey(DeploymentSettings.IS_PROCESS_VALIDATION_ENABLED)) {
bpmnParse.setValidateProcess((Boolean) deploymentSettings.get(DeploymentSettings.IS_PROCESS_VALIDATION_ENABLED));
}
} else {
// On redeploy, we assume it is validated at the first deploy
bpmnParse.setValidateSchema(false);
bpmnParse.setValidateProcess(false);
}
bpmnParse.execute();
for (ProcessDefinitionEntity processDefinition : bpmnParse.getProcessDefinitions()) {
processDefinition.setResourceName(resourceName);
if (deployment.getTenantId() != null) {
// process definition inherits the tenant id
processDefinition.setTenantId(deployment.getTenantId());
}
String diagramResourceName = getDiagramResourceForProcess(resourceName, processDefinition.getKey(), resources);
// time the process definition is added to the deployment-cache when diagram-generation has failed the first time.
if (deployment.isNew()) {
if (processEngineConfiguration.isCreateDiagramOnDeploy() && diagramResourceName == null && processDefinition.isGraphicalNotationDefined()) {
try {
byte[] diagramBytes = IoUtil.readInputStream(processEngineConfiguration.getProcessDiagramGenerator().generateDiagram(bpmnParse.getBpmnModel(), "png", processEngineConfiguration.getActivityFontName(), processEngineConfiguration.getLabelFontName(), processEngineConfiguration.getAnnotationFontName(), processEngineConfiguration.getClassLoader()), null);
diagramResourceName = getProcessImageResourceName(resourceName, processDefinition.getKey(), "png");
createResource(diagramResourceName, diagramBytes, deployment);
} catch (Throwable t) {
// if anything goes wrong, we don't store the image (the process will still be executable).
log.warn("Error while generating process diagram, image will not be stored in repository", t);
}
}
}
processDefinition.setDiagramResourceName(diagramResourceName);
processDefinitions.add(processDefinition);
bpmnModelMap.put(processDefinition.getKey(), bpmnParse.getBpmnModel());
}
}
}
// check if there are process definitions with the same process key to prevent database unique index violation
List<String> keyList = new ArrayList<String>();
for (ProcessDefinitionEntity processDefinition : processDefinitions) {
if (keyList.contains(processDefinition.getKey())) {
throw new ActivitiException("The deployment contains process definitions with the same key '" + processDefinition.getKey() + "' (process id atrribute), this is not allowed");
}
keyList.add(processDefinition.getKey());
}
CommandContext commandContext = Context.getCommandContext();
ProcessDefinitionEntityManager processDefinitionManager = commandContext.getProcessDefinitionEntityManager();
DbSqlSession dbSqlSession = commandContext.getSession(DbSqlSession.class);
for (ProcessDefinitionEntity processDefinition : processDefinitions) {
List<TimerEntity> timers = new ArrayList<TimerEntity>();
if (deployment.isNew()) {
int processDefinitionVersion;
ProcessDefinitionEntity latestProcessDefinition = null;
if (processDefinition.getTenantId() != null && !ProcessEngineConfiguration.NO_TENANT_ID.equals(processDefinition.getTenantId())) {
latestProcessDefinition = processDefinitionManager.findLatestProcessDefinitionByKeyAndTenantId(processDefinition.getKey(), processDefinition.getTenantId());
} else {
latestProcessDefinition = processDefinitionManager.findLatestProcessDefinitionByKey(processDefinition.getKey());
}
if (latestProcessDefinition != null) {
processDefinitionVersion = latestProcessDefinition.getVersion() + 1;
} else {
processDefinitionVersion = 1;
}
processDefinition.setVersion(processDefinitionVersion);
processDefinition.setDeploymentId(deployment.getId());
String nextId = idGenerator.getNextId();
String processDefinitionId = processDefinition.getKey() + ":" + processDefinition.getVersion() + ":" + // ACT-505
nextId;
// ACT-115: maximum id length is 64 charcaters
if (processDefinitionId.length() > 64) {
processDefinitionId = nextId;
}
processDefinition.setId(processDefinitionId);
if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, processDefinition));
}
removeObsoleteTimers(processDefinition);
addTimerDeclarations(processDefinition, timers);
removeExistingMessageEventSubscriptions(processDefinition, latestProcessDefinition);
addMessageEventSubscriptions(processDefinition);
removeExistingSignalEventSubScription(processDefinition, latestProcessDefinition);
addSignalEventSubscriptions(processDefinition);
dbSqlSession.insert(processDefinition);
addAuthorizations(processDefinition);
if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, processDefinition));
}
scheduleTimers(timers);
} else {
String deploymentId = deployment.getId();
processDefinition.setDeploymentId(deploymentId);
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());
}
if (persistedProcessDefinition != null) {
processDefinition.setId(persistedProcessDefinition.getId());
processDefinition.setVersion(persistedProcessDefinition.getVersion());
processDefinition.setSuspensionState(persistedProcessDefinition.getSuspensionState());
}
}
// Add to cache
DeploymentManager deploymentManager = processEngineConfiguration.getDeploymentManager();
deploymentManager.getProcessDefinitionCache().add(processDefinition.getId(), processDefinition);
addDefinitionInfoToCache(processDefinition, processEngineConfiguration, commandContext);
// Add to deployment for further usage
deployment.addDeployedArtifact(processDefinition);
createLocalizationValues(processDefinition.getId(), bpmnModelMap.get(processDefinition.getKey()).getProcessById(processDefinition.getKey()));
}
}
use of org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl in project Activiti by Activiti.
the class MailActivityBehavior method setMailServerProperties.
protected void setMailServerProperties(Email email, String tenantId) {
ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
boolean isMailServerSet = false;
if (tenantId != null && tenantId.length() > 0) {
if (processEngineConfiguration.getMailSessionJndi(tenantId) != null) {
setEmailSession(email, processEngineConfiguration.getMailSessionJndi(tenantId));
isMailServerSet = true;
} else if (processEngineConfiguration.getMailServer(tenantId) != null) {
MailServerInfo mailServerInfo = processEngineConfiguration.getMailServer(tenantId);
String host = mailServerInfo.getMailServerHost();
if (host == null) {
throw new ActivitiException("Could not send email: no SMTP host is configured for tenantId " + tenantId);
}
email.setHostName(host);
email.setSmtpPort(mailServerInfo.getMailServerPort());
email.setSSLOnConnect(mailServerInfo.isMailServerUseSSL());
email.setStartTLSEnabled(mailServerInfo.isMailServerUseTLS());
String user = mailServerInfo.getMailServerUsername();
String password = mailServerInfo.getMailServerPassword();
if (user != null && password != null) {
email.setAuthentication(user, password);
}
isMailServerSet = true;
}
}
if (!isMailServerSet) {
String mailSessionJndi = processEngineConfiguration.getMailSessionJndi();
if (mailSessionJndi != null) {
setEmailSession(email, mailSessionJndi);
} else {
String host = processEngineConfiguration.getMailServerHost();
if (host == null) {
throw new ActivitiException("Could not send email: no SMTP host is configured");
}
email.setHostName(host);
int port = processEngineConfiguration.getMailServerPort();
email.setSmtpPort(port);
email.setSSLOnConnect(processEngineConfiguration.getMailServerUseSSL());
email.setStartTLSEnabled(processEngineConfiguration.getMailServerUseTLS());
String user = processEngineConfiguration.getMailServerUsername();
String password = processEngineConfiguration.getMailServerPassword();
if (user != null && password != null) {
email.setAuthentication(user, password);
}
}
}
}
use of org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl in project Activiti by Activiti.
the class JobEntityManager method send.
public void send(MessageEntity message) {
ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
if (processEngineConfiguration.isAsyncExecutorEnabled()) {
// If the async executor is enabled, we need to set the duedate of the job to the current date + the default lock time.
// This is cope with the case where the async job executor or the process engine goes down
// before executing the job. This way, other async job executors can pick the job up after the max lock time.
Date dueDate = new Date(processEngineConfiguration.getClock().getCurrentTime().getTime() + processEngineConfiguration.getAsyncExecutor().getAsyncJobLockTimeInMillis());
message.setDuedate(dueDate);
// was set before, but to be quickly picked up needs to be set to null
message.setLockExpirationTime(null);
} else if (!processEngineConfiguration.isJobExecutorActivate()) {
// If the async executor is disabled AND there is no old school job executor,
// The job needs to be picked up as soon as possible. So the due date is now set to the current time
message.setDuedate(processEngineConfiguration.getClock().getCurrentTime());
// was set before, but to be quickly picked up needs to be set to null
message.setLockExpirationTime(null);
}
message.insert();
if (processEngineConfiguration.isAsyncExecutorEnabled()) {
hintAsyncExecutor(message);
} else {
hintJobExecutor(message);
}
}
use of org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl in project Activiti by Activiti.
the class AsyncExecutorTest method createProcessEngine.
private ProcessEngine createProcessEngine(boolean enableAsyncExecutor, Date time) {
ProcessEngineConfigurationImpl processEngineConfiguration = new StandaloneInMemProcessEngineConfiguration();
processEngineConfiguration.setJdbcUrl("jdbc:h2:mem:activiti-AsyncExecutorTest;DB_CLOSE_DELAY=1000");
processEngineConfiguration.setDatabaseSchemaUpdate("true");
// No need for that old job executor
processEngineConfiguration.setJobExecutorActivate(false);
if (enableAsyncExecutor) {
processEngineConfiguration.setAsyncExecutorEnabled(true);
processEngineConfiguration.setAsyncExecutorActivate(true);
CountingAsyncExecutor countingAsyncExecutor = new CountingAsyncExecutor();
// To avoid waiting too long when a retry happens
countingAsyncExecutor.setDefaultAsyncJobAcquireWaitTimeInMillis(50);
countingAsyncExecutor.setDefaultTimerJobAcquireWaitTimeInMillis(50);
processEngineConfiguration.setAsyncExecutor(countingAsyncExecutor);
}
ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
if (time != null) {
processEngine.getProcessEngineConfiguration().getClock().setCurrentTime(time);
}
return processEngine;
}
use of org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl in project Activiti by Activiti.
the class DatabaseTablePrefixTest method testPerformDatabaseSchemaOperationCreate.
public void testPerformDatabaseSchemaOperationCreate() throws Exception {
// both process engines will be using this datasource.
PooledDataSource pooledDataSource = new PooledDataSource(ReflectUtil.getClassLoader(), "org.h2.Driver", "jdbc:h2:mem:activiti-test;DB_CLOSE_DELAY=1000", "sa", "");
// create two schemas is the database
Connection connection = pooledDataSource.getConnection();
connection.createStatement().execute("drop schema if exists SCHEMA1");
connection.createStatement().execute("drop schema if exists SCHEMA2");
connection.createStatement().execute("create schema SCHEMA1");
connection.createStatement().execute("create schema SCHEMA2");
connection.close();
// configure & build two different process engines, each having a separate table prefix
ProcessEngineConfigurationImpl config1 = (ProcessEngineConfigurationImpl) ProcessEngineConfigurationImpl.createStandaloneInMemProcessEngineConfiguration().setDataSource(pooledDataSource).setDatabaseSchemaUpdate(// disable auto create/drop schema
"NO_CHECK");
config1.setDatabaseTablePrefix("SCHEMA1.");
ProcessEngine engine1 = config1.buildProcessEngine();
ProcessEngineConfigurationImpl config2 = (ProcessEngineConfigurationImpl) ProcessEngineConfigurationImpl.createStandaloneInMemProcessEngineConfiguration().setDataSource(pooledDataSource).setDatabaseSchemaUpdate(// disable auto create/drop schema
"NO_CHECK");
config2.setDatabaseTablePrefix("SCHEMA2.");
ProcessEngine engine2 = config2.buildProcessEngine();
// create the tables in SCHEMA1
connection = pooledDataSource.getConnection();
connection.createStatement().execute("set schema SCHEMA1");
engine1.getManagementService().databaseSchemaUpgrade(connection, "", "SCHEMA1");
connection.close();
// create the tables in SCHEMA2
connection = pooledDataSource.getConnection();
connection.createStatement().execute("set schema SCHEMA2");
engine2.getManagementService().databaseSchemaUpgrade(connection, "", "SCHEMA2");
connection.close();
// engine:
try {
engine1.getRepositoryService().createDeployment().addClasspathResource("org/activiti/engine/test/db/oneJobProcess.bpmn20.xml").deploy();
assertEquals(1, engine1.getRepositoryService().createDeploymentQuery().count());
assertEquals(0, engine2.getRepositoryService().createDeploymentQuery().count());
} finally {
engine1.close();
engine2.close();
}
}
Aggregations