Search in sources :

Example 1 with ExecutionException

use of io.takari.bpm.api.ExecutionException in project concord by walmartlabs.

the class YamlParserTest method test061.

@Test
public void test061() {
    deploy("061.yml");
    MyLogger task = spy(new MyLogger());
    register("__withItemsUtils", new StepConverter.WithItemsUtilsTask());
    register("myLogger", task);
    // ---
    String key = UUID.randomUUID().toString();
    Map<String, Object> args = new HashMap<>();
    args.put("notArrayVariable", "invalid variable type");
    try {
        start(key, "main", args);
        fail("exception expected");
    } catch (ExecutionException e) {
        assertTrue(e.getCause().getCause().getMessage().contains("should be a list"));
    }
}
Also used : StepConverter(com.walmartlabs.concord.project.yaml.converter.StepConverter) YamlTaskStepConverter(com.walmartlabs.concord.project.yaml.converter.YamlTaskStepConverter) Mockito.anyString(org.mockito.Mockito.anyString) ExecutionException(io.takari.bpm.api.ExecutionException) Test(org.junit.jupiter.api.Test)

Example 2 with ExecutionException

use of io.takari.bpm.api.ExecutionException in project concord by walmartlabs.

the class YamlParserTest method test021_2.

@Test
public void test021_2() throws Exception {
    deploy("021_2.yml");
    ProcessDefinition pd = getDefinition("main");
    // /--> task ---------> end
    // start -> gw -> task -> task -> end
    assertEquals(13, pd.getChildren().size());
    TestBean testBean = spy(new TestBean());
    register("testBean", testBean);
    // ---
    String key = UUID.randomUUID().toString();
    Map<String, Object> args = Collections.singletonMap("aInt", -100);
    try {
        start(key, "main", args);
        fail("exception expected");
    } catch (ExecutionException e) {
        assertTrue(e.getMessage().contains("error-code-2"));
    }
    // ---
    verify(testBean, times(1)).toString(eq("b"));
    verifyNoMoreInteractions(testBean);
}
Also used : ProcessDefinition(io.takari.bpm.model.ProcessDefinition) Mockito.anyString(org.mockito.Mockito.anyString) ExecutionException(io.takari.bpm.api.ExecutionException) Test(org.junit.jupiter.api.Test)

Example 3 with ExecutionException

use of io.takari.bpm.api.ExecutionException in project concord by walmartlabs.

the class YamlParserTest method test022_2.

@Test
public void test022_2() throws Exception {
    deploy("022_2.yml");
    ProcessDefinition pd = getDefinition("main");
    // /--> task ---------> end
    // start -> gw -> task -> task -> end
    assertEquals(13, pd.getChildren().size());
    TestBean testBean = spy(new TestBean());
    register("testBean", testBean);
    // ---
    String key = UUID.randomUUID().toString();
    Map<String, Object> args = Collections.singletonMap("aInt", 100);
    try {
        start(key, "main", args);
        fail("exception expected");
    } catch (ExecutionException e) {
        assertTrue(e.getMessage().contains("error-code"));
    }
    // ---
    verify(testBean, times(1)).toString(eq("a"));
    verifyNoMoreInteractions(testBean);
}
Also used : ProcessDefinition(io.takari.bpm.model.ProcessDefinition) Mockito.anyString(org.mockito.Mockito.anyString) ExecutionException(io.takari.bpm.api.ExecutionException) Test(org.junit.jupiter.api.Test)

Example 4 with ExecutionException

use of io.takari.bpm.api.ExecutionException in project concord by walmartlabs.

the class DefaultElementEventProcessor method process.

@Override
public void process(ElementEvent event, EventParamsBuilder builder, Predicate<AbstractElement> filter) throws ExecutionException {
    ProcessDefinition pd = processDefinitionProvider.getById(event.getProcessDefinitionId());
    if (pd == null) {
        throw new RuntimeException("Process definition not found: " + event.getProcessDefinitionId());
    }
    if (!(pd instanceof SourceAwareProcessDefinition)) {
        return;
    }
    Map<String, SourceMap> sourceMaps = ((SourceAwareProcessDefinition) pd).getSourceMaps();
    SourceMap source = sourceMaps.get(event.getElementId());
    if (source == null) {
        return;
    }
    AbstractElement element = ProcessDefinitionUtils.findElement(pd, event.getElementId());
    if (filter != null && !filter.test(element)) {
        return;
    }
    try {
        Map<String, Object> e = new HashMap<>();
        e.put("processDefinitionId", event.getProcessDefinitionId());
        e.put("elementId", event.getElementId());
        e.put("line", source.getLine());
        e.put("column", source.getColumn());
        e.put("description", source.getDescription());
        e.putAll(builder.build(element));
        ProcessEventRequest req = new ProcessEventRequest();
        // TODO should it be in the constants?
        req.setEventType("ELEMENT");
        req.setData(e);
        req.setEventDate(Instant.now().atOffset(ZoneOffset.UTC));
        ProcessEventsApi client = new ProcessEventsApi(apiClientFactory.create(ApiClientConfiguration.builder().sessionToken(event.getSessionToken()).txId(UUID.fromString(event.getInstanceId())).build()));
        client.event(UUID.fromString(event.getInstanceId()), req);
    } catch (Exception e) {
        log.warn("process ['{}'] -> transfer error: {}", event.getInstanceId(), e.getMessage());
    }
}
Also used : AbstractElement(io.takari.bpm.model.AbstractElement) HashMap(java.util.HashMap) SourceAwareProcessDefinition(io.takari.bpm.model.SourceAwareProcessDefinition) ProcessDefinition(io.takari.bpm.model.ProcessDefinition) ExecutionException(io.takari.bpm.api.ExecutionException) ProcessEventRequest(com.walmartlabs.concord.client.ProcessEventRequest) SourceMap(io.takari.bpm.model.SourceMap) SourceAwareProcessDefinition(io.takari.bpm.model.SourceAwareProcessDefinition) ProcessEventsApi(com.walmartlabs.concord.client.ProcessEventsApi)

Example 5 with ExecutionException

use of io.takari.bpm.api.ExecutionException in project concord by walmartlabs.

the class FileFormStorage method save.

@Override
public void save(Form form) throws ExecutionException {
    UUID id = form.getFormInstanceId();
    Path p = dir.resolve(form.getFormDefinition().getName());
    try {
        Path tmp = IOUtils.createTempFile(id.toString(), "form");
        try (OutputStream out = Files.newOutputStream(tmp)) {
            SerializationUtils.serialize(out, form);
        }
        Files.move(tmp, p, REPLACE_EXISTING);
    } catch (IOException e) {
        throw new ExecutionException("Error while saving a form", e);
    }
}
Also used : Path(java.nio.file.Path) OutputStream(java.io.OutputStream) IOException(java.io.IOException) UUID(java.util.UUID) ExecutionException(io.takari.bpm.api.ExecutionException)

Aggregations

ExecutionException (io.takari.bpm.api.ExecutionException)12 IOException (java.io.IOException)5 Test (org.junit.jupiter.api.Test)5 Mockito.anyString (org.mockito.Mockito.anyString)5 Path (java.nio.file.Path)4 YamlTaskStepConverter (com.walmartlabs.concord.project.yaml.converter.YamlTaskStepConverter)3 ProcessDefinition (io.takari.bpm.model.ProcessDefinition)3 Payload (com.walmartlabs.concord.server.process.Payload)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 HashMap (java.util.HashMap)2 ProcessEventRequest (com.walmartlabs.concord.client.ProcessEventRequest)1 ProcessEventsApi (com.walmartlabs.concord.client.ProcessEventsApi)1 ConfigurationUtils (com.walmartlabs.concord.common.ConfigurationUtils)1 TemporaryPath (com.walmartlabs.concord.common.TemporaryPath)1 ConcordFormValidator (com.walmartlabs.concord.common.form.ConcordFormValidator)1 ValidationError (com.walmartlabs.concord.forms.ValidationError)1 StepConverter (com.walmartlabs.concord.project.yaml.converter.StepConverter)1 Constants (com.walmartlabs.concord.sdk.Constants)1 MapUtils (com.walmartlabs.concord.sdk.MapUtils)1