All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.camunda.connector.textract.TextractConnectorFunction Maven / Gradle / Ivy

There is a newer version: 8.6.0-alpha5
Show newest version
/*
 * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
 * under one or more contributor license agreements. Licensed under a proprietary license.
 * See the License.txt file for more information. You may not use this file
 * except in compliance with the proprietary license.
 */
package io.camunda.connector.textract;

import io.camunda.connector.api.annotation.OutboundConnector;
import io.camunda.connector.api.outbound.OutboundConnectorContext;
import io.camunda.connector.api.outbound.OutboundConnectorFunction;
import io.camunda.connector.generator.java.annotation.ElementTemplate;
import io.camunda.connector.textract.caller.AsyncTextractCaller;
import io.camunda.connector.textract.caller.PollingTextractCalller;
import io.camunda.connector.textract.caller.SyncTextractCaller;
import io.camunda.connector.textract.model.TextractRequest;
import io.camunda.connector.textract.suppliers.AmazonTextractClientSupplier;

@OutboundConnector(
    name = "AWS Textract",
    inputVariables = {"authentication", "configuration", "input"},
    type = "io.camunda:aws-textract:1")
@ElementTemplate(
    id = "io.camunda.connectors.AWSTEXTRACT.v1",
    name = "AWS Textract Outbound Connector",
    description =
        "Automatically extract printed text, handwriting, layout elements, and data from any document",
    inputDataClass = TextractRequest.class,
    version = 1,
    propertyGroups = {
      @ElementTemplate.PropertyGroup(id = "authentication", label = "Authentication"),
      @ElementTemplate.PropertyGroup(id = "configuration", label = "Configuration"),
      @ElementTemplate.PropertyGroup(id = "input", label = "Configure input")
    },
    documentationRef =
        "https://docs.camunda.io/docs/next/components/connectors/out-of-the-box-connectors/amazon-textract/",
    icon = "icon.svg")
public class TextractConnectorFunction implements OutboundConnectorFunction {

  private final AmazonTextractClientSupplier clientSupplier;

  private final SyncTextractCaller syncTextractCaller;

  private final PollingTextractCalller pollingTextractCaller;

  private final AsyncTextractCaller asyncTextractCaller;

  public TextractConnectorFunction() {
    this.clientSupplier = new AmazonTextractClientSupplier();
    this.syncTextractCaller = new SyncTextractCaller();
    this.pollingTextractCaller = new PollingTextractCalller();
    this.asyncTextractCaller = new AsyncTextractCaller();
  }

  public TextractConnectorFunction(
      AmazonTextractClientSupplier clientSupplier,
      SyncTextractCaller syncTextractCaller,
      PollingTextractCalller pollingTextractCaller,
      AsyncTextractCaller asyncTextractCaller) {
    this.clientSupplier = clientSupplier;
    this.syncTextractCaller = syncTextractCaller;
    this.pollingTextractCaller = pollingTextractCaller;
    this.asyncTextractCaller = asyncTextractCaller;
  }

  @Override
  public Object execute(OutboundConnectorContext context) throws Exception {
    TextractRequest request = context.bindVariables(TextractRequest.class);
    return switch (request.getInput().executionType()) {
      case SYNC ->
          syncTextractCaller.call(
              request.getInput(), clientSupplier.getSyncTextractClient(request));
      case POLLING ->
          pollingTextractCaller.call(
              request.getInput(), clientSupplier.getAsyncTextractClient(request));
      case ASYNC ->
          asyncTextractCaller.call(
              request.getInput(), clientSupplier.getAsyncTextractClient(request));
    };
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy