use of org.activiti.engine.repository.Model in project Activiti by Activiti.
the class ModelResourceTest method testDeleteModel.
public void testDeleteModel() throws Exception {
Model model = null;
try {
Calendar now = Calendar.getInstance();
now.set(Calendar.MILLISECOND, 0);
processEngineConfiguration.getClock().setCurrentTime(now.getTime());
model = repositoryService.newModel();
model.setCategory("Model category");
model.setKey("Model key");
model.setMetaInfo("Model metainfo");
model.setName("Model name");
model.setVersion(2);
repositoryService.saveModel(model);
HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId()));
closeResponse(executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT));
// Check if the model is really gone
assertNull(repositoryService.createModelQuery().modelId(model.getId()).singleResult());
model = null;
} finally {
if (model != null) {
try {
repositoryService.deleteModel(model.getId());
} catch (Throwable ignore) {
// Ignore, model might not be created
}
}
}
}
use of org.activiti.engine.repository.Model in project Activiti by Activiti.
the class DeploymentEntityManager method deleteDeployment.
public void deleteDeployment(String deploymentId, boolean cascade) {
List<ProcessDefinition> processDefinitions = getDbSqlSession().createProcessDefinitionQuery().deploymentId(deploymentId).list();
// Remove the deployment link from any model.
// The model will still exists, as a model is a source for a deployment model and has a different lifecycle
List<Model> models = getDbSqlSession().createModelQueryImpl().deploymentId(deploymentId).list();
for (Model model : models) {
ModelEntity modelEntity = (ModelEntity) model;
modelEntity.setDeploymentId(null);
getModelManager().updateModel(modelEntity);
}
if (cascade) {
// delete process instances
for (ProcessDefinition processDefinition : processDefinitions) {
String processDefinitionId = processDefinition.getId();
getProcessInstanceManager().deleteProcessInstancesByProcessDefinition(processDefinitionId, "deleted deployment", cascade);
}
}
for (ProcessDefinition processDefinition : processDefinitions) {
String processDefinitionId = processDefinition.getId();
// remove related authorization parameters in IdentityLink table
getIdentityLinkManager().deleteIdentityLinksByProcDef(processDefinitionId);
// event subscriptions
List<EventSubscriptionEntity> eventSubscriptionEntities = getEventSubscriptionManager().findEventSubscriptionsByTypeAndProcessDefinitionId(null, processDefinitionId, // null type ==> all types
processDefinition.getTenantId());
for (EventSubscriptionEntity eventSubscriptionEntity : eventSubscriptionEntities) {
eventSubscriptionEntity.delete();
}
getProcessDefinitionInfoManager().deleteProcessDefinitionInfo(processDefinitionId);
}
// delete process definitions from db
getProcessDefinitionManager().deleteProcessDefinitionsByDeploymentId(deploymentId);
for (ProcessDefinition processDefinition : processDefinitions) {
// remove timer start events for current process definition:
List<Job> timerStartJobs = Context.getCommandContext().getJobEntityManager().findJobsByTypeAndProcessDefinitionId(TimerStartEventJobHandler.TYPE, processDefinition.getId());
if (timerStartJobs != null && timerStartJobs.size() > 0) {
for (Job timerStartJob : timerStartJobs) {
if (Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.JOB_CANCELED, timerStartJob, null, null, processDefinition.getId()));
}
((JobEntity) timerStartJob).delete();
}
}
// If previous process definition version has a timer/message/signal start event, it must be added
ProcessDefinitionEntity latestProcessDefinition = findLatestProcessDefinition(processDefinition);
// Only if the currently deleted process definition is the latest version, we fall back to the previous start event type
if (processDefinition.getId().equals(latestProcessDefinition.getId())) {
// Try to find a previous version (it could be some versions are missing due to deletions)
ProcessDefinition previousProcessDefinition = findNewLatestProcessDefinitionAfterRemovalOf(processDefinition);
if (previousProcessDefinition != null) {
// Need to resolve process definition to make sure it's parsed
ProcessDefinitionEntity resolvedProcessDefinition = Context.getProcessEngineConfiguration().getDeploymentManager().resolveProcessDefinition((ProcessDefinitionEntity) previousProcessDefinition);
// Timer start
List<TimerDeclarationImpl> timerDeclarations = (List<TimerDeclarationImpl>) resolvedProcessDefinition.getProperty(BpmnParse.PROPERTYNAME_START_TIMER);
if (timerDeclarations != null) {
for (TimerDeclarationImpl timerDeclaration : timerDeclarations) {
TimerEntity timer = timerDeclaration.prepareTimerEntity(null);
timer.setProcessDefinitionId(previousProcessDefinition.getId());
if (previousProcessDefinition.getTenantId() != null) {
timer.setTenantId(previousProcessDefinition.getTenantId());
}
Context.getCommandContext().getJobEntityManager().schedule(timer);
}
}
// Signal / Message start
List<EventSubscriptionDeclaration> signalEventDefinitions = (List<EventSubscriptionDeclaration>) resolvedProcessDefinition.getProperty(BpmnParse.PROPERTYNAME_EVENT_SUBSCRIPTION_DECLARATION);
if (signalEventDefinitions != null) {
for (EventSubscriptionDeclaration eventDefinition : signalEventDefinitions) {
if (eventDefinition.getEventType().equals("signal") && eventDefinition.isStartEvent()) {
SignalEventSubscriptionEntity subscriptionEntity = new SignalEventSubscriptionEntity();
subscriptionEntity.setEventName(eventDefinition.getEventName());
subscriptionEntity.setActivityId(eventDefinition.getActivityId());
subscriptionEntity.setProcessDefinitionId(previousProcessDefinition.getId());
subscriptionEntity.setTenantId(previousProcessDefinition.getTenantId());
subscriptionEntity.insert();
} else if (eventDefinition.getEventType().equals("message") && eventDefinition.isStartEvent()) {
MessageEventSubscriptionEntity newSubscription = new MessageEventSubscriptionEntity();
newSubscription.setEventName(eventDefinition.getEventName());
newSubscription.setActivityId(eventDefinition.getActivityId());
newSubscription.setConfiguration(previousProcessDefinition.getId());
newSubscription.setProcessDefinitionId(previousProcessDefinition.getId());
newSubscription.setTenantId(previousProcessDefinition.getTenantId());
newSubscription.insert();
}
}
}
}
}
}
getResourceManager().deleteResourcesByDeploymentId(deploymentId);
getDbSqlSession().delete("deleteDeployment", deploymentId);
}
use of org.activiti.engine.repository.Model in project Activiti by Activiti.
the class RepositoryServiceTest method testUpdateModelPersistence.
public void testUpdateModelPersistence() throws Exception {
Model model = repositoryService.newModel();
assertNotNull(model);
model.setName("Test model");
model.setCategory("test");
model.setMetaInfo("meta");
repositoryService.saveModel(model);
assertNotNull(model.getId());
model = repositoryService.getModel(model.getId());
assertNotNull(model);
model.setName("New name");
model.setCategory("New category");
model.setMetaInfo("test");
model.setVersion(2);
repositoryService.saveModel(model);
assertNotNull(model.getId());
repositoryService.addModelEditorSource(model.getId(), "new".getBytes("utf-8"));
repositoryService.addModelEditorSourceExtra(model.getId(), "new".getBytes("utf-8"));
model = repositoryService.getModel(model.getId());
assertEquals("New name", model.getName());
assertEquals("New category", model.getCategory());
assertEquals("test", model.getMetaInfo());
assertNotNull(model.getCreateTime());
assertEquals(Integer.valueOf(2), model.getVersion());
assertEquals("new", new String(repositoryService.getModelEditorSource(model.getId()), "utf-8"));
assertEquals("new", new String(repositoryService.getModelEditorSourceExtra(model.getId()), "utf-8"));
repositoryService.deleteModel(model.getId());
}
use of org.activiti.engine.repository.Model in project Activiti by Activiti.
the class SimpleTableEditor method save.
protected void save() {
WorkflowDefinition workflowDefinition = createWorkflow();
final ProcessEngineImpl defaultProcessEngine = (ProcessEngineImpl) ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = defaultProcessEngine.getRepositoryService();
ProcessEngineConfiguration processEngineConfiguration = defaultProcessEngine.getProcessEngineConfiguration();
ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
Model model = null;
if (modelId == null) {
// new process
model = repositoryService.newModel();
} else {
// update existing process
model = repositoryService.getModel(modelId);
}
model.setName(workflowDefinition.getName());
model.setCategory(SimpleTableEditorConstants.TABLE_EDITOR_CATEGORY);
repositoryService.saveModel(model);
// Store model entity
WorkflowDefinitionConversion conversion = ExplorerApp.get().getWorkflowDefinitionConversionFactory().createWorkflowDefinitionConversion(workflowDefinition);
conversion.convert();
try {
// Write JSON to byte-array and set as editor-source
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ExplorerApp.get().getSimpleWorkflowJsonConverter().writeWorkflowDefinition(workflowDefinition, new OutputStreamWriter(baos));
repositoryService.addModelEditorSource(model.getId(), baos.toByteArray());
// Store process image
// TODO: we should really allow the service to take an inputstream as input. Now we load it into memory ...
repositoryService.addModelEditorSourceExtra(model.getId(), IOUtils.toByteArray(diagramGenerator.generateDiagram(conversion.getBpmnModel(), "png", processEngineConfiguration.getActivityFontName(), processEngineConfiguration.getLabelFontName(), processEngineConfiguration.getAnnotationFontName(), processEngineConfiguration.getClassLoader())));
} catch (IOException e) {
logger.warn("Could not generate process image. Image is not stored and will not be shown.", e);
}
ExplorerApp.get().getViewManager().showEditorProcessDefinitionPage(model.getId());
}
use of org.activiti.engine.repository.Model in project Activiti by Activiti.
the class ModelResourceSourceTest method testSetModelEditorSourceExtra.
public void testSetModelEditorSourceExtra() throws Exception {
Model model = null;
try {
model = repositoryService.newModel();
model.setName("Model name");
repositoryService.saveModel(model);
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_SOURCE_EXTRA, model.getId()));
httpPut.setEntity(HttpMultipartHelper.getMultiPartEntity("sourcefile", "application/octet-stream", new ByteArrayInputStream("This is the new extra editor source".getBytes()), null));
closeResponse(executeBinaryRequest(httpPut, HttpStatus.SC_NO_CONTENT));
assertEquals("This is the new extra editor source", new String(repositoryService.getModelEditorSourceExtra(model.getId())));
} finally {
try {
repositoryService.deleteModel(model.getId());
} catch (Throwable ignore) {
// Ignore, model might not be created
}
}
}
Aggregations