Skip to main content
Version: 10.2.9

Use File Storage as transaction source

Download sample project

Download the project tutorial-filestorage_10.1.0.4.zip.

Learn how to input to application from S3 file

note

To make it easier to understand the important classes and interfaces, we recommend downloading and importing the example project into Eclipse IDE and referring to it as you read this guide.

The downloaded project must have the file structure shown below.

Once you downloaded the project, perform the following actions:

  1. Run mvn clean install on the parent pom.xml file.

  2. Make sure you set all the required data for Control Tower and Nexus users.

    1. The user specified is settings.xml under server ID bcb-repository must exist in Nexus.
    2. The Nexus user should have deployment privileges in the wf-machine-config-bundle repository.
    3. In the parent pom.xml file, you specified the Nexus repository where your JARs will be installed. Make sure to point it to your Nexus, for example:
    <workfusion.nexus.host.url>http://localhost:8081/</workfusion.nexus.host.url>
    1. Add the following code with the Control Tower user credentials to the settings.xml file:
    <servers>
    <server>
    <id>control-tower</id>
    <username>CT_username</username>
    <password>CT_password</password>
    </server>
    </servers>
    1. In parent pom.xml, you have set the Control Tower host where your bundle will be published.
    <workfusion.controltower.url>https://yourinstance.workfusion.com/</workfusion.controltower.url>

Now, you can deploy your bots to Nexus or publish a bundle with a Business Process (BP) to Control Tower.

Deploy to Nexus

  1. Run mvn deploy on parent pom.xml. This deployment depends on your Nexus repository configuration.
  2. Once the build appears in Nexus, upload the bots into the local Control Tower. Go to Advanced > Bot Configurations > Import from Repository. You can build your BP by selecting a Bot Task from the list.

Publish to Control Tower

  1. Run mvn bundle:import on tutorial-filestorage-package/pom.xml. The command calls the import plugin.
  2. Open your Control Tower and find the BP named tutorial datastore v0.0.7.

You must make some changes for the samples to work properly:

  1. Upload a CSV file to the S3 bucket (the instance must have access to this bucket). The file can be found at tutorial-filestorage-bcb/src/test/resources/s3-file-test.csv.
  2. Set the bucket name in the File Storage module: com.sample.filestorage.automation.app.FSModule.
  3. Change the file link in the TransactionSupplier connector: com.sample.filestorage.automation.supplier.TransactionSupplierImpl.

Learn TransactionSupplier

In this case, TransactionSupplier is TransactionSupplierImpl.java.

Navigate to the following files:

  • src > main > java > com > sample > filestorage > automation > supplier > TransactionSupplierImpl.java
  • src > main > resources > configs> main > Sample FS Transaction Supplier Example.xml

This is the Bot Task that triggers the execution of the TransactionSupplier class mentioned in [1].

The following code in the Bot Task initializes the task of creating transactions:

def app = SampleFSApp.init(binding).get();
def transactions = app.loadTransactions(TransactionSupplierImpl.class);

Transactions are created for each row in the CSV file in the fs-odf-demo S3 bucket. To read the file, the S3Manager class is used. S3Manager is a utility in ODF that performs file-based operations in S3 and interacts with your local file system.

Execution flow inside Collection\<Transaction> get() method

The following steps describe the execution flow inside the Collection<Transaction> get() method. Refer to the code in TransactionSupplierImpl.java.

  • Using the s3Manager.getFile(url) method, the uploaded file in the S3 bucket is read and InputStream of the file is returned.
  • The BufferedReader object is created using InputStream.
  • Each line of the file is read using the readLine() method of BufferedReader in a while loop.
  • An ODF transaction is created for each line in the CSV file, except for the header line ("first_name", "last_name", "email").
  • The line is split by the delimiter ",", and the values for the column names are extracted.
  • The extracted values are inserted into transaction attributes using the transaction.putAttribute() method.

Work with File Storage

S3PluginAdapter

Since S3Manager is deprecated, you should use S3PluginAdapter that provides similar utility functions.

To implement this class in ODF projects, create a module that provides two resources:

  • A method with the return type as String, which provides the name of the S3 bucket (similar to S3Manager)

  • A singleton instance of the S3PluginAdapter class, for example:

    @Provides
    @Singleton
    public S3PluginAdapter s3PluginAdapter(PluginAdapterFactory pluginAdapterFactory) {
    return(S3PluginAdapter) pluginAdapterFactory.getPluginAdapter(PluginAdapterFactory.PluginsEnum.S3);
    }

Sometimes, in client environments, you may need to define s3EndpointUrl while interacting with s3PluginAdapter. You can perform this action in the constructor of your class as follows:

public MyClass {

private SystemUtilities systemUtilities;

@Inject
public MyClass (SystemUtilities systemUtilties) {
this.systemUtilities = systemUtilities;
this.systemUtilities.defineVariable("s3EndpointUrl", "client_env_specific_s3_endpoint_url");
}

}

Methods available with S3PluginAdapter are as follows.

MethodResultParametersDescription
getCommonS3AttributesMap<String, String>Returns basic attributes for S3Adapter. You can set the S3 access and secret key, bucket name, and endpoint URL in this map.
getbyte[]String urlDownloads a file from the S3 bucket specified in CommonS3Attributes.
listEntriesList<String>String prefix, String pattern, ZonedDateTime minDate, ZonedDateTime maxDateReturns a list of entries from S3. Can return all the entries from a folder or filter them. If you want to use only the prefix, set null for the minDate and maxDate parameters.
deletevoidString urlDeletes a file by URL.
putS3ResultItembyte[] data, String s3key, CannedAccessControlList acl, String contentType, String contentDisposition, Long expiresInSecondsUploads a file to the S3 bucket. The s3key parameter is the path where the file is uploaded. The acl, contentType, contentDisposition and expiresInSeconds parameters match those in the s3 plugin in the Bot Configuration.
copyvoidString from, String to, CannedAccessControlList aclCopies files within the S3 bucket.