Search in sources :

Example 11 with RepositoryService

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());
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) ProcessDiagramGenerator(org.activiti.image.ProcessDiagramGenerator) Model(org.activiti.engine.repository.Model) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ProcessEngineImpl(org.activiti.engine.impl.ProcessEngineImpl) RepositoryService(org.activiti.engine.RepositoryService)

Example 12 with RepositoryService

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);
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PopupWindow(org.activiti.explorer.ui.custom.PopupWindow) SelectEditorComponent(org.activiti.editor.ui.SelectEditorComponent) EditorSelectedListener(org.activiti.editor.ui.SelectEditorComponent.EditorSelectedListener) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) BpmnJsonConverter(org.activiti.editor.language.json.converter.BpmnJsonConverter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) RepositoryService(org.activiti.engine.RepositoryService)

Example 13 with RepositoryService

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());
}
Also used : DataSourceProcessEngineAutoConfiguration(org.activiti.spring.boot.DataSourceProcessEngineAutoConfiguration) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) RepositoryService(org.activiti.engine.RepositoryService) Test(org.junit.Test)

Example 14 with RepositoryService

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));
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) RepositoryService(org.activiti.engine.RepositoryService) Test(org.junit.Test)

Example 15 with RepositoryService

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());
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Deployment(org.activiti.engine.repository.Deployment) FileInputStream(java.io.FileInputStream) RepositoryService(org.activiti.engine.RepositoryService) Test(org.junit.Test)

Aggregations

RepositoryService (org.activiti.engine.RepositoryService)16 Test (org.junit.Test)8 ProcessEngine (org.activiti.engine.ProcessEngine)7 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)5 RuntimeService (org.activiti.engine.RuntimeService)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 WorkflowDefinitionConversion (org.activiti.workflow.simple.converter.WorkflowDefinitionConversion)3 WorkflowDefinition (org.activiti.workflow.simple.definition.WorkflowDefinition)3 FileInputStream (java.io.FileInputStream)2 URL (java.net.URL)2 ProcessEngineConfiguration (org.activiti.engine.ProcessEngineConfiguration)2 TaskService (org.activiti.engine.TaskService)2 StandaloneProcessEngineConfiguration (org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration)2 Deployment (org.activiti.engine.repository.Deployment)2 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)2 Task (org.activiti.engine.task.Task)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1