Search in sources :

Example 1 with SourceAwareProcessDefinition

use of io.takari.bpm.model.SourceAwareProcessDefinition 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)

Aggregations

ProcessEventRequest (com.walmartlabs.concord.client.ProcessEventRequest)1 ProcessEventsApi (com.walmartlabs.concord.client.ProcessEventsApi)1 ExecutionException (io.takari.bpm.api.ExecutionException)1 AbstractElement (io.takari.bpm.model.AbstractElement)1 ProcessDefinition (io.takari.bpm.model.ProcessDefinition)1 SourceAwareProcessDefinition (io.takari.bpm.model.SourceAwareProcessDefinition)1 SourceMap (io.takari.bpm.model.SourceMap)1 HashMap (java.util.HashMap)1