Search in sources :

Example 1 with BpmEvent

use of org.jboss.pnc.bpm.model.BpmEvent in project pnc by project-ncl.

the class BpmEndpointImpl method notifyTask.

@Override
public void notifyTask(int taskId) {
    String content;
    JsonNode node;
    try {
        content = readContent(request.getInputStream());
        node = JsonOutputConverterMapper.getMapper().readTree(content);
    } catch (IOException e) {
        throw new RuntimeException("Could not get JSON from request data. " + "Verify it is not empty and in the correct format.", e);
    }
    if (!node.has("eventType")) {
        throw new RuntimeException("Request JSON does not contain required \"eventType\" field.");
    }
    String eventTypeName = node.get("eventType").asText();
    BpmEventType eventType = nullableValueOf(eventTypeName);
    if (eventType != null) {
        BpmEvent notification;
        try {
            notification = JsonOutputConverterMapper.getMapper().readValue(node.traverse(), eventType.getType());
        } catch (IOException e) {
            throw new RuntimeException("Could not deserialize JSON request for event type '" + eventTypeName + "' " + " into '" + eventType.getType() + "'. JSON value: " + content, e);
        }
        logger.debug("Received notification {} for BPM task with id {}.", notification, taskId);
        try {
            bpmManager.notify(taskId, notification);
        } catch (NoEntityException e) {
            throw new EmptyEntityException(e.getMessage());
        }
    } else {
        logger.info("Received notification with unknown eventType {}, ignoring it.", eventTypeName);
    }
}
Also used : BpmEvent(org.jboss.pnc.bpm.model.BpmEvent) EmptyEntityException(org.jboss.pnc.facade.validation.EmptyEntityException) BpmEventType(org.jboss.pnc.bpm.BpmEventType) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) NoEntityException(org.jboss.pnc.bpm.NoEntityException)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 IOException (java.io.IOException)1 BpmEventType (org.jboss.pnc.bpm.BpmEventType)1 NoEntityException (org.jboss.pnc.bpm.NoEntityException)1 BpmEvent (org.jboss.pnc.bpm.model.BpmEvent)1 EmptyEntityException (org.jboss.pnc.facade.validation.EmptyEntityException)1