Search in sources :

Example 11 with ProcessEngineConfiguration

use of org.activiti.engine.ProcessEngineConfiguration in project tutorials by eugenp.

the class ProcessEngineCreationIntegrationTest method givenNoXMLConfig_whenCreateInMemProcessEngineConfig_thenCreated.

@Test
public void givenNoXMLConfig_whenCreateInMemProcessEngineConfig_thenCreated() {
    ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration();
    ProcessEngine processEngine = processEngineConfiguration.setJdbcUrl("jdbc:h2:mem:my-own-in-mem-db;DB_CLOSE_DELAY=1000").buildProcessEngine();
    assertNotNull(processEngine);
    assertEquals("sa", processEngine.getProcessEngineConfiguration().getJdbcUsername());
}
Also used : ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) ProcessEngine(org.activiti.engine.ProcessEngine) Test(org.junit.Test)

Example 12 with ProcessEngineConfiguration

use of org.activiti.engine.ProcessEngineConfiguration in project tutorials by eugenp.

the class ProcessEngineCreationIntegrationTest method givenNoXMLConfig_whenCreateProcessEngineConfig_thenCreated.

@Test
public void givenNoXMLConfig_whenCreateProcessEngineConfig_thenCreated() {
    ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
    ProcessEngine processEngine = processEngineConfiguration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE).setJdbcUrl("jdbc:h2:mem:my-own-db;DB_CLOSE_DELAY=1000").buildProcessEngine();
    assertNotNull(processEngine);
    assertEquals("sa", processEngine.getProcessEngineConfiguration().getJdbcUsername());
}
Also used : ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) ProcessEngine(org.activiti.engine.ProcessEngine) Test(org.junit.Test)

Example 13 with ProcessEngineConfiguration

use of org.activiti.engine.ProcessEngineConfiguration in project tutorials by eugenp.

the class ProcessEngineCreationIntegrationTest method givenDifferentNameXMLConfig_whenGetProcessEngineConfig_thenGotResult.

@Test
public void givenDifferentNameXMLConfig_whenGetProcessEngineConfig_thenGotResult() {
    ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("my.activiti.cfg.xml");
    ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
    assertNotNull(processEngine);
    assertEquals("baeldung", processEngine.getProcessEngineConfiguration().getJdbcUsername());
}
Also used : ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) ProcessEngine(org.activiti.engine.ProcessEngine) Test(org.junit.Test)

Example 14 with ProcessEngineConfiguration

use of org.activiti.engine.ProcessEngineConfiguration in project Activiti by Activiti.

the class ProcessInstanceDetailPanel method addProcessImage.

protected void addProcessImage() {
    ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(processDefinition.getId());
    // Only show when graphical notation is defined
    if (processDefinitionEntity != null) {
        boolean didDrawImage = false;
        if (ExplorerApp.get().isUseJavascriptDiagram()) {
            try {
                final InputStream definitionStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName());
                XMLInputFactory xif = XmlUtil.createSafeXmlInputFactory();
                XMLStreamReader xtr = xif.createXMLStreamReader(definitionStream);
                BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);
                if (!bpmnModel.getFlowLocationMap().isEmpty()) {
                    int maxX = 0;
                    int maxY = 0;
                    for (String key : bpmnModel.getLocationMap().keySet()) {
                        GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(key);
                        double elementX = graphicInfo.getX() + graphicInfo.getWidth();
                        if (maxX < elementX) {
                            maxX = (int) elementX;
                        }
                        double elementY = graphicInfo.getY() + graphicInfo.getHeight();
                        if (maxY < elementY) {
                            maxY = (int) elementY;
                        }
                    }
                    // using panel for scrollbars
                    Panel imagePanel = new Panel();
                    imagePanel.addStyleName(Reindeer.PANEL_LIGHT);
                    imagePanel.setWidth(100, UNITS_PERCENTAGE);
                    imagePanel.setHeight(100, UNITS_PERCENTAGE);
                    URL explorerURL = ExplorerApp.get().getURL();
                    URL url = new URL(explorerURL.getProtocol(), explorerURL.getHost(), explorerURL.getPort(), explorerURL.getPath().replace("/ui", "") + "diagram-viewer/index.html?processDefinitionId=" + processDefinition.getId() + "&processInstanceId=" + processInstance.getId());
                    Embedded browserPanel = new Embedded("", new ExternalResource(url));
                    browserPanel.setType(Embedded.TYPE_BROWSER);
                    browserPanel.setWidth(maxX + 350 + "px");
                    browserPanel.setHeight(maxY + 220 + "px");
                    HorizontalLayout panelLayoutT = new HorizontalLayout();
                    panelLayoutT.setSizeUndefined();
                    imagePanel.setContent(panelLayoutT);
                    imagePanel.addComponent(browserPanel);
                    panelLayout.addComponent(imagePanel);
                    didDrawImage = true;
                }
            } catch (Exception e) {
                LOGGER.error("Error loading process diagram component", e);
            }
        }
        if (!didDrawImage && processDefinitionEntity.isGraphicalNotationDefined()) {
            ProcessEngineConfiguration processEngineConfiguration = ProcessEngines.getDefaultProcessEngine().getProcessEngineConfiguration();
            ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
            StreamResource diagram = new ProcessDefinitionImageStreamResourceBuilder().buildStreamResource(processInstance, repositoryService, runtimeService, diagramGenerator, processEngineConfiguration);
            if (diagram != null) {
                Label header = new Label(i18nManager.getMessage(Messages.PROCESS_HEADER_DIAGRAM));
                header.addStyleName(ExplorerLayout.STYLE_H3);
                header.addStyleName(ExplorerLayout.STYLE_DETAIL_BLOCK);
                header.addStyleName(ExplorerLayout.STYLE_NO_LINE);
                panelLayout.addComponent(header);
                Embedded embedded = new Embedded(null, diagram);
                embedded.setType(Embedded.TYPE_IMAGE);
                embedded.setSizeUndefined();
                // using panel for scrollbars
                Panel imagePanel = new Panel();
                imagePanel.setScrollable(true);
                imagePanel.addStyleName(Reindeer.PANEL_LIGHT);
                imagePanel.setWidth(100, UNITS_PERCENTAGE);
                imagePanel.setHeight(100, UNITS_PERCENTAGE);
                HorizontalLayout panelLayoutT = new HorizontalLayout();
                panelLayoutT.setSizeUndefined();
                imagePanel.setContent(panelLayoutT);
                imagePanel.addComponent(embedded);
                panelLayout.addComponent(imagePanel);
            }
        }
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStream(java.io.InputStream) GraphicInfo(org.activiti.bpmn.model.GraphicInfo) Label(com.vaadin.ui.Label) PrettyTimeLabel(org.activiti.explorer.ui.custom.PrettyTimeLabel) ExternalResource(com.vaadin.terminal.ExternalResource) URL(java.net.URL) BpmnModel(org.activiti.bpmn.model.BpmnModel) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter) HorizontalLayout(com.vaadin.ui.HorizontalLayout) Panel(com.vaadin.ui.Panel) DetailPanel(org.activiti.explorer.ui.custom.DetailPanel) ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) StreamResource(com.vaadin.terminal.StreamResource) ProcessDiagramGenerator(org.activiti.image.ProcessDiagramGenerator) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) Embedded(com.vaadin.ui.Embedded) ProcessDefinitionImageStreamResourceBuilder(org.activiti.explorer.ui.process.ProcessDefinitionImageStreamResourceBuilder) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 15 with ProcessEngineConfiguration

use of org.activiti.engine.ProcessEngineConfiguration 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)

Aggregations

ProcessEngineConfiguration (org.activiti.engine.ProcessEngineConfiguration)24 ProcessEngine (org.activiti.engine.ProcessEngine)7 Test (org.junit.Test)7 Date (java.util.Date)4 ProcessEngineImpl (org.activiti.engine.impl.ProcessEngineImpl)4 ProcessDiagramGenerator (org.activiti.image.ProcessDiagramGenerator)4 StreamResource (com.vaadin.terminal.StreamResource)3 Embedded (com.vaadin.ui.Embedded)3 HorizontalLayout (com.vaadin.ui.HorizontalLayout)2 Label (com.vaadin.ui.Label)2 Panel (com.vaadin.ui.Panel)2 URL (java.net.URL)2 GregorianCalendar (java.util.GregorianCalendar)2 MBeanServerConnection (javax.management.MBeanServerConnection)2 ObjectName (javax.management.ObjectName)2 JMXConnector (javax.management.remote.JMXConnector)2 JMXServiceURL (javax.management.remote.JMXServiceURL)2 ActivitiException (org.activiti.engine.ActivitiException)2 RepositoryService (org.activiti.engine.RepositoryService)2 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)2