use of org.activiti.engine.RepositoryService 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.RepositoryService in project Activiti by Activiti.
the class EditModelClickListener method showSelectEditorPopupWindow.
protected void showSelectEditorPopupWindow() {
final PopupWindow selectEditorPopupWindow = new PopupWindow();
selectEditorPopupWindow.setModal(true);
selectEditorPopupWindow.setResizable(false);
selectEditorPopupWindow.setWidth("350px");
selectEditorPopupWindow.setHeight("250px");
selectEditorPopupWindow.addStyleName(Reindeer.PANEL_LIGHT);
selectEditorPopupWindow.center();
final SelectEditorComponent selectEditorComponent = new SelectEditorComponent(false);
selectEditorComponent.getModelerDescriptionLabel().setValue(ExplorerApp.get().getI18nManager().getMessage(Messages.PROCESS_EDITOR_CONVERSION_WARNING_MODELER));
selectEditorComponent.getModelerDescriptionLabel().addStyleName(ExplorerLayout.STYLE_LABEL_RED);
selectEditorComponent.preferTableDrivenEditor();
selectEditorPopupWindow.getContent().addComponent(selectEditorComponent);
selectEditorComponent.setEditorSelectedListener(new EditorSelectedListener() {
public void editorSelectionChanged() {
try {
WorkflowDefinition workflowDefinition = loadWorkflowDefinition();
// When using the modeler, the format must first be converted to the modeler json format
if (selectEditorComponent.isModelerPreferred()) {
WorkflowDefinitionConversion conversion = ExplorerApp.get().getWorkflowDefinitionConversionFactory().createWorkflowDefinitionConversion(workflowDefinition);
conversion.convert();
RepositoryService repositoryService = ProcessEngines.getDefaultProcessEngine().getRepositoryService();
model.setCategory(null);
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode metaInfoJson = objectMapper.createObjectNode();
metaInfoJson.put("name", model.getName());
model.setMetaInfo(metaInfoJson.toString());
repositoryService.saveModel(model);
BpmnJsonConverter bpmnJsonConverter = new BpmnJsonConverter();
ObjectNode json = bpmnJsonConverter.convertToJson(conversion.getBpmnModel());
repositoryService.addModelEditorSource(model.getId(), json.toString().getBytes("utf-8"));
// Show modeler
showModeler();
} else {
// Load and show table editor
ExplorerApp.get().getViewManager().showSimpleTableProcessEditor(model.getId(), workflowDefinition);
}
} catch (Exception e) {
LOGGER.error("Error showing editor", e);
ExplorerApp.get().getNotificationManager().showErrorNotification(Messages.PROCESS_EDITOR_LOADING_ERROR, e);
} finally {
ExplorerApp.get().getMainWindow().removeWindow(selectEditorPopupWindow);
}
}
});
ExplorerApp.get().getViewManager().showPopupWindow(selectEditorPopupWindow);
}
use of org.activiti.engine.RepositoryService in project Activiti by Activiti.
the class ProcessEngineAutoConfigurationTest method launchProcessDefinition.
@Test
public void launchProcessDefinition() throws Exception {
AnnotationConfigApplicationContext applicationContext = this.context(DataSourceAutoConfiguration.class, DataSourceProcessEngineAutoConfiguration.DataSourceProcessEngineConfiguration.class);
RepositoryService repositoryService = applicationContext.getBean(RepositoryService.class);
Assert.assertNotNull("we should have a default repositoryService included", repositoryService);
Assert.assertEquals(2, repositoryService.createProcessDefinitionQuery().count());
List<ProcessDefinition> processDefinitionList = repositoryService.createProcessDefinitionQuery().processDefinitionKey("waiter").list();
Assert.assertNotNull(processDefinitionList);
Assert.assertTrue(!processDefinitionList.isEmpty());
ProcessDefinition processDefinition = processDefinitionList.iterator().next();
Assert.assertEquals("waiter", processDefinition.getKey());
}
use of org.activiti.engine.RepositoryService in project bamboobsc by billchen198318.
the class TestBPMN001 method queryFlowImage.
@Test
public void queryFlowImage() throws Exception {
String deploymentId = "10001";
RepositoryService repositoryService = (RepositoryService) AppContext.getBean("repositoryService");
List<String> names = repositoryService.getDeploymentResourceNames(deploymentId);
for (String name : names) {
System.out.println(name);
if (name.endsWith(".png") || name.endsWith(".bmp")) {
InputStream is = repositoryService.getResourceAsStream(deploymentId, name);
FileUtils.copyInputStreamToFile(is, new File("/tmp/" + name));
}
}
}
use of org.activiti.engine.RepositoryService in project bamboobsc by billchen198318.
the class TestBPMN001 method deployment.
@Test
public void deployment() throws Exception {
InputStream inputStreamBpmn = new FileInputStream("/home/git/bamboobsc/core-doc/DFProjectPublishProcess.bpmn");
InputStream inputStreamPng = new FileInputStream("/home/git/bamboobsc/core-doc/DFProjectPublishProcess.png");
RepositoryService repositoryService = (RepositoryService) AppContext.getBean("repositoryService");
Deployment deployment = repositoryService.createDeployment().name("DFProjectPublishProcess-flow").addInputStream("DFProjectPublishProcess.bpmn", inputStreamBpmn).addInputStream("DFProjectPublishProcess.png", inputStreamPng).deploy();
System.out.println("ID: " + deployment.getId() + " , Name: " + deployment.getName());
}
Aggregations