
com.appian.connectedsystems.simplified.sdk.SimpleIntegrationTemplate Maven / Gradle / Ivy
package com.appian.connectedsystems.simplified.sdk;
import com.appian.connectedsystems.simplified.sdk.configuration.ConfigurableTemplate;
import com.appian.connectedsystems.simplified.sdk.configuration.SimpleConfiguration;
import com.appian.connectedsystems.templateframework.sdk.ExecutionContext;
import com.appian.connectedsystems.templateframework.sdk.IntegrationResponse;
import com.appian.connectedsystems.templateframework.sdk.IntegrationTemplate;
import com.appian.connectedsystems.templateframework.sdk.TemplateId;
import com.appian.connectedsystems.templateframework.sdk.configuration.ConfigurationDescriptor;
import com.appian.connectedsystems.templateframework.sdk.configuration.LocalTypeDescriptor;
import com.appian.connectedsystems.templateframework.sdk.configuration.PropertyDescriptor;
import com.appian.connectedsystems.templateframework.sdk.configuration.PropertyDescriptorBuilder;
import com.appian.connectedsystems.templateframework.sdk.configuration.PropertyPath;
import com.appian.connectedsystems.templateframework.sdk.configuration.RefreshPolicy;
import com.appian.connectedsystems.templateframework.sdk.metadata.IntegrationTemplateType;
/**
* Each implementation of SimpleIntegrationTemplate represents a new type of integration available to designers in Appian.
*
* Each new type of integration should represent a single operation in the external system.
* Create a new IntegrationTemplate for each operation.
*
*
* Every SimpleIntegrationTemplate must be associated with exactly one {@link SimpleConnectedSystemTemplate}
*
* Each implementation of this class must have the {@link TemplateId} annotation to be successfully deployed
* Use the {@link IntegrationTemplateType} annotation to express whether this integration modifies or queries data
*
*
* {@link SimpleIntegrationTemplate#getConfiguration(SimpleConfiguration, SimpleConfiguration, PropertyPath, ExecutionContext)} determines the UI that designers use to configure the integration for execution.
* {@link SimpleIntegrationTemplate#execute(SimpleConfiguration, SimpleConfiguration, ExecutionContext)} uses the integration and connected system's configurations to make a call to an external system.
*
*
* SimpleIntegrationTemplates are re-instantiated per request. Therefore, each call to {@link SimpleIntegrationTemplate#execute(SimpleConfiguration, SimpleConfiguration, ExecutionContext)} or {@link SimpleIntegrationTemplate#getConfiguration(SimpleConfiguration, SimpleConfiguration, PropertyPath, ExecutionContext)} is on a new instance of the class.
*/
public abstract class SimpleIntegrationTemplate extends ConfigurableTemplate implements IntegrationTemplate {
/**
* Returns a configuration that defines the UI and values of an Appian integration object.
*
* This method should update the {@code integrationConfiguration}.
*
* Every call to this method must call {@link SimpleConfiguration#setProperties(PropertyDescriptor[])}
*
* Example: Text field for entering customer ID and toggle for retrieving additional information
*
*
* return configuration.setProperties(
* textProperty("customerID").label("Customer ID").build(),
* booleanProperty("additionalInfo").label("Get Additional Info").build()
* );
*
*
* This method is called in the following scenarios:
*
*
* - A designer creates a new Integration.
* - A designer loads an existing Integration in the Designer.
* - A designer edits a {@link PropertyDescriptor property} that has a {@link RefreshPolicy refresh policy} of {@code ALWAYS}.
* - A designer selects a new connected system
*
*
*
* @param integrationConfiguration The current {@link SimpleConfiguration configuration}
* This will never be {@code null}
* @param connectedSystemConfiguration The configuration of the designer-selected Appian connected system object associated
* with the Appian Integration object.
* This will never be {@code null}
* @param updatedProperty Field that has been modified by the designer.
* For a field to trigger the {@link SimpleIntegrationTemplate#getConfiguration(SimpleConfiguration, SimpleConfiguration, PropertyPath, ExecutionContext)} method,
* its RefreshPolicy must be set to {@link RefreshPolicy#ALWAYS}.
* Use this path to find the new, designer-updated value in the integrationConfiguration.
* This parameter will be {@code null} when a new Appian Integration object is created,
* when a saved Appian Integration object is reloaded in the designer, and when a new Appian connected system is selected.
* @param executionContext Contains all of the contextual information needed to configure the Appian Integration object,
* including Designer information, Designer locale, and proxy configuration. {@link ExecutionContext}
*
* @return The updated {@link SimpleConfiguration} integrationConfiguration
*/
protected abstract SimpleConfiguration getConfiguration(
SimpleConfiguration integrationConfiguration,
SimpleConfiguration connectedSystemConfiguration,
PropertyPath updatedProperty,
ExecutionContext executionContext);
/**
* Completes the operation in the external system and returns the result to the designer
*
* This method is called when a designer hits the test-request button in the Integration Designer, or when an integration
* is executed from a process, a SAIL form, or a Web API.
*
* Use the {@link SimpleConfiguration#getValue(String)} method to retrieve values from the integration and connected system.
* These values can then be sent to the external system.
*
* @param integrationConfiguration The configuration of the integration.
* This will never be {@code null}
* @param connectedSystemConfiguration The configuration of the connected system associated with the integration.
* This will never be {@code null}
* @param executionContext Contains all of the contextual information needed to execute the integration and configure diagnostics,
* including Designer information, Designer locale, and proxy configuration. {@link ExecutionContext}
*
* @return IntegrationResponse A success boolean, a result map, a list of errors, and designer-localized diagnostic information
*/
protected abstract IntegrationResponse execute(SimpleConfiguration integrationConfiguration,
SimpleConfiguration connectedSystemConfiguration,
ExecutionContext executionContext);
@Override
public ConfigurationDescriptor getConfigurationDescriptor(
ConfigurationDescriptor integrationConfigDescriptor,
ConfigurationDescriptor connectedSystemConfigDescriptor,
PropertyPath updatedProperty,
ExecutionContext executionContext) {
updatedProperty = deroot(updatedProperty);
final SimpleConfiguration simpleIntegrationConfiguration = SimpleConfiguration.from(
integrationConfigDescriptor, typePropertyFactory, executionContext);
final SimpleConfiguration simpleConnectedSystemConfiguration = SimpleConfiguration.from(
connectedSystemConfigDescriptor, typePropertyFactory, executionContext);
return getConfiguration(simpleIntegrationConfiguration, simpleConnectedSystemConfiguration,
updatedProperty, executionContext).toConfiguration();
}
@Override
public IntegrationResponse execute(
ConfigurationDescriptor integrationConfigDescriptor,
ConfigurationDescriptor connectedSystemConfigDescriptor,
ExecutionContext executionContext) {
final SimpleConfiguration simpleIntegrationConfiguration = SimpleConfiguration.from(
integrationConfigDescriptor, typePropertyFactory, executionContext);
final SimpleConfiguration simpleConnectedSystemConfiguration = SimpleConfiguration.from(
connectedSystemConfigDescriptor, typePropertyFactory, executionContext);
return execute(simpleIntegrationConfiguration, simpleConnectedSystemConfiguration, executionContext);
}
@Override
public PropertyDescriptorBuilder localTypeProperty(
LocalTypeDescriptor localType) {
return super.localTypeProperty(localType).isExpressionable(true);
}
@Override
public PropertyDescriptorBuilder localTypeProperty(LocalTypeDescriptor localType, String key) {
return super.localTypeProperty(localType, key).isExpressionable(true);
}
}