Skip to content

Commit

Permalink
feat(inbound): improve error handling, support variable mappings and …
Browse files Browse the repository at this point in the history
…activation conditions on runtime level
  • Loading branch information
chillleader committed Jul 28, 2023
1 parent c59856a commit 4608884
Show file tree
Hide file tree
Showing 23 changed files with 1,023 additions and 273 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
*/
package io.camunda.connector.api.inbound;

import java.util.Objects;
import io.camunda.connector.impl.inbound.result.CorrelationErrorData;
import java.util.Optional;

/**
* Contains general information about the inbound correlation results.
Expand All @@ -25,63 +26,26 @@
* message name in case of an IntermediateEvent target, or process definition key in case of a
* StartEvent target.
*/
public abstract class InboundConnectorResult {

protected String type;
protected String id;
protected Object responseData;

protected InboundConnectorResult(String type, String id, Object responseData) {
this.type = type;
this.id = id;
this.responseData = responseData;
}
public interface InboundConnectorResult<T> {

/** Type of process correlation point, e.g. StartEvent or Message */
public String getType() {
return type;
}
String getType();

/** ID of a process correlation point (unique within its type, see {@link #getType()} */
public String getId() {
return id;
}

/** Additional information related to Inbound Connector correlation result */
public Object getResponseData() {
return this.responseData;
}

@Override
public String toString() {
return "InboundConnectorResult{"
+ "type='"
+ type
+ '\''
+ ", id='"
+ id
+ '\''
+ ", responseData="
+ responseData
+ '}';
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
InboundConnectorResult result = (InboundConnectorResult) o;
return Objects.equals(type, result.type)
&& Objects.equals(id, result.id)
&& Objects.equals(responseData, result.responseData);
}

@Override
public int hashCode() {
return Objects.hash(type, id, responseData);
}
String getCorrelationPointId();

/** Whether connector was activated */
boolean isActivated();

/**
* Additional information related to Inbound Connector correlation result. Only present when
* {@link #isActivated()} returns true.
*/
Optional<T> getResponseData();

/**
* Additional information about correlation failure reasons. Only present when {@link
* #isActivated()} returns false.
*/
Optional<CorrelationErrorData> getErrorData();
}
76 changes: 76 additions & 0 deletions core/src/main/java/io/camunda/connector/impl/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. Camunda licenses this file to you under the Apache License,
* Version 2.0; you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.camunda.connector.impl;

public class Constants {

/**
* The keyword that identifies the source of `result variable` property of a Connector. Result
* variable is a property that contains the name of the process variable where the Connector
* result will be stored.
*
* <p>For outbound Connectors, this value comes from Zeebe job headers.
*
* <p>For inbound Connectors, this value comes from the extension properties of a BPMN element.
*/
public static final String RESULT_VARIABLE_KEYWORD = "resultVariable";

/**
* The keyword that identifies the source of `result expression` property of a Connector. Result
* expression is a FEEL expression that is used to map the Connector output into process variables
*
* <p>For outbound Connectors, this value comes from Zeebe job headers.
*
* <p>For inbound Connectors, this value comes from the extension properties of a BPMN element.
*/
public static final String RESULT_EXPRESSION_KEYWORD = "resultExpression";

/**
* The keyword that identifies the source of `error expression` property of a Connector. Error
* expression is a FEEL context expression that is used to map the Connector output into process
* variables
*
* <p>This value only exists for outbound Connectors and comes from Zeebe job headers.
*/
public static final String ERROR_EXPRESSION_KEYWORD = "errorExpression";

/**
* The keyword that identifies the source of `correlation key expression` property of a Connector.
* Correlation key expression is a FEEL expression that is extracts the correlation key from the
* inbound Connector output.
*
* <p>This value only exists for inbound Connectors that target an intermediate message catch
* event and comes from the extension properties of a BPMN element.
*/
public static final String CORRELATION_KEY_EXPRESSION_KEYWORD = "correlationKeyExpression";

/**
* The keyword that identifies the source of `activation condition` property of a Connector.
* Activation condition is a boolean FEEL expression that determines whether the inbound Connector
* should be activated based on the inbound payload.
*
* <p>This value only exists for inbound Connectors and comes from the extension properties of a
* BPMN element.
*/
public static final String ACTIVATION_CONDITION_KEYWORD = "activationCondition";

/**
* The keyword that identifies the source of `type` property of an inbound Connector. Type
* identifies the specific inbound Connector implementation.
*/
public static final String INBOUND_TYPE_KEYWORD = "inbound.type";
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ public Class<? extends InboundConnectorExecutable> getConnectorClass() {
return this.connectorClass;
}

public InboundConnectorConfiguration setConnector(SubscriptionInboundConnector connector) {
return this;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
*/
package io.camunda.connector.impl.inbound;

import io.camunda.connector.api.inbound.ProcessCorrelationPoint;
import static io.camunda.connector.impl.Constants.INBOUND_TYPE_KEYWORD;

import java.util.Map;
import java.util.Objects;

Expand All @@ -36,7 +37,7 @@ public InboundConnectorProperties(
String bpmnProcessId,
int version,
long processDefinitionKey) {
this.type = properties.get("inbound.type");
this.type = properties.get(INBOUND_TYPE_KEYWORD);
this.properties = properties;
this.correlationPoint = correlationPoint;
this.bpmnProcessId = bpmnProcessId;
Expand Down Expand Up @@ -73,6 +74,19 @@ public long getProcessDefinitionKey() {
return processDefinitionKey;
}

public String getProperty(String propertyName) {
return properties.get(propertyName);
}

public String getRequiredProperty(String propertyName) {
final String property = getProperty(propertyName);
if (property == null) {
throw new IllegalStateException(
"Required inbound connector property '" + propertyName + "' is missing.");
}
return property;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.camunda.connector.api.inbound;
package io.camunda.connector.impl.inbound;

/**
* Base class for a unique set of properties of a single inbound Connector usage in the business
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,33 @@
*/
package io.camunda.connector.impl.inbound.correlation;

import io.camunda.connector.api.inbound.ProcessCorrelationPoint;
import io.camunda.connector.impl.inbound.ProcessCorrelationPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/** Properties of a message published by an Inbound Connector */
public class MessageCorrelationPoint extends ProcessCorrelationPoint {

public static final String TYPE_NAME = "MESSAGE";

private static final Logger LOG = LoggerFactory.getLogger(MessageCorrelationPoint.class);
private final String messageName;

/** FEEL expression */
private final String correlationKeyExpression;

public MessageCorrelationPoint(String messageName, String correlationKeyExpression) {
public MessageCorrelationPoint(String messageName) {
this.messageName = messageName;
this.correlationKeyExpression = correlationKeyExpression;
LOG.debug("Created inbound correlation point: " + this);
}

public String getMessageName() {
return messageName;
}

public String getCorrelationKeyExpression() {
return correlationKeyExpression;
}

@Override
public String getId() {
return messageName + "-" + correlationKeyExpression.strip();
return messageName;
}

@Override
public String toString() {
return "MessageCorrelationPoint{"
+ "messageName='"
+ messageName
+ '\''
+ ", correlationKeyExpression='"
+ correlationKeyExpression
+ '}';
return "MessageCorrelationPoint{" + "messageName='" + messageName + '\'' + '}';
}

@Override
Expand All @@ -67,9 +51,6 @@ public int compareTo(ProcessCorrelationPoint o) {
return 1;
}
MessageCorrelationPoint other = (MessageCorrelationPoint) o;
if (!messageName.equals(other.messageName)) {
return messageName.compareTo(other.messageName);
}
return correlationKeyExpression.compareTo(other.correlationKeyExpression);
return messageName.compareTo(other.messageName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
*/
package io.camunda.connector.impl.inbound.correlation;

import io.camunda.connector.api.inbound.ProcessCorrelationPoint;
import io.camunda.connector.impl.inbound.ProcessCorrelationPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/** Properties of a StartEvent triggered by an Inbound Connector */
public class StartEventCorrelationPoint extends ProcessCorrelationPoint {

public static final String TYPE_NAME = "START_EVENT";

private final String bpmnProcessId;
private final int version;
private final long processDefinitionKey;
Expand Down Expand Up @@ -58,13 +56,14 @@ public String getId() {
@Override
public String toString() {
return "StartEventCorrelationPoint{"
+ "processDefinitionKey="
+ processDefinitionKey
+ ", bpmnProcessId='"
+ "bpmnProcessId='"
+ bpmnProcessId
+ '\''
+ ", version="
+ version
+ ", processDefinitionKey="
+ processDefinitionKey
+ '\''
+ '}';
}

Expand Down
Loading

0 comments on commit 4608884

Please sign in to comment.