Files
You can upload and download files to and from the Catalytic platform. You can then reference those files in Fields in Workflows and Instances.
The Files
client allows you to upload and download files from the Catalytic platform, and to get file metadata like size, content-type and filename. It provides the following methods:
Quickstart Example
/*
* This example demonstrates downloading and uploading files
* from a Workflow Instance.
*/
import org.catalytic.sdk.CatalyticClient;
import org.catalytic.sdk.entities.Workflow;
import org.catalytic.sdk.entities.WorkflowsPage;
public class Program {
public static void main(String[] args) throws Exception {
// Create and initialize the Catalytic SDK Client
CatalyticClient catalytic = new CatalyticClient();
// Find workflows matching "Sdk Example Pushbot"
Where where = new Where().text().matches("SDK Example Workflow");
WorkflowsPage results = catalytic.workflows().find(where);
// `results` is a results page containing `workflows` and
// a `nextPageToken` you can use to page through results.
// We only expect one match for this example so we can simply
// get the first matching Workflow.
Workflow workflow = results.getWorkflows().get(0);
// ######
// TODO: Finish this example
// ######
// Now that we've got our workflow, let's set the inputs it expects
var request = workflow
.SetInput("Age", 42)
.SetInput("Name", "Alice")
.SetName($"SDK Example - {DateTimeOffset.Now.ToString()}");
// Start the workflow
var instance = catalytic.Instances.Start(request);
// get the step we want to complete
var steps = catalytic.Instances.GetSteps(instance.InstanceId).Steps;
var uploadStep = steps.Where(
s => s.Name == "Upload Updated Spreadsheet and Set Email").First();
// download the Data Table from the "Table" field as a CSV
var tableId = instance.Fields["Table"].GetValue<Guid>();
var csvFile = catalytic.DataTables.Download(tableId, DataTableExportFormat.CSV);
// Do our "business logic" to transform the csv data
// As a simple example, we replace "Foo" with "Bar"
var updatedCsvContent = csvFile.OpenText().ReadToEnd().Replace("Foo", "Bar");
// create the output csv file locally
var updatedCsvFile = new FileInfo(Path.GetTempFileName());
File.WriteAllText(updatedCsvFile.FullName, updatedCsvContent);
// To complete the step, we will set both a text and a file field
var stepRequest = step
.SetInput("Updated CSV", updatedCsvFile)
.SetInput("Email Address", YourEmail);
catalytic.Instances.CompleteStep(stepRequest);
Console.WriteLine($"You should have an email waiting for you at {YourEmail} now with the updated CSV converted to an Excel attachment");
WorkflowsPage results = catalytic.workflows().find(where);
List<Workflow> workflows = new ArrayList<>();
workflows.addAll(results.getWorkflows());
while (results.getNextPageToken() != null) {
results = catalytic.workflows().find(results.getNextPageToken());
workflows.addAll(results.getWorkflows());
}
System.out.println("Found " + workflows.size() + " Workflows by name and 1 by Id");
}
}
// update this to your email before running this sample
public const string YourEmail = "[email protected]";
static void Main(string[] args)
{
// create and initialize the Catalytic SDK Client
var catalytic = new CatalyticClient(Credentials.Default);
// find workflows matching "Sdk Example Pushbot"
var matches = catalytic.Workflows.Find(
Where.Text.Matches("Sdk Example Workflow"));
// `matches` is a results page containing `Workflows` and
// a `NextPageToken` you can use to page through results.
// We only expect one match for this example so we can simply
// get the first matching Workflow.
var pushbot = matches.Workflows.FirstOrDefault();
if (workflow == null)
{
pushbot = catalytic.Workflows.Import(
new Uri("https://push.bot/sdk-example"));
}
// Now that we've got our workflow, let's set the inputs it expects
var request = workflow
.SetInput("Age", 42)
.SetInput("Name", "Alice")
.SetName($"SDK Example - {DateTimeOffset.Now.ToString()}");
// Start the workflow
var instance = catalytic.Instances.Start(request);
// get the step we want to complete
var steps = catalytic.Instances.GetSteps(instance.InstanceId).Steps;
var uploadStep = steps.Where(
s => s.Name == "Upload Updated Spreadsheet and Set Email").First();
// download the Data Table from the "Table" field as a CSV
var tableId = instance.Fields["Table"].GetValue<Guid>();
var csvFile = catalytic.DataTables.Download(tableId, DataTableExportFormat.CSV);
// Do our "business logic" to transform the csv data
// As a simple example, we replace "Foo" with "Bar"
var updatedCsvContent = csvFile.OpenText().ReadToEnd().Replace("Foo", "Bar");
// create the output csv file locally
var updatedCsvFile = new FileInfo(Path.GetTempFileName());
File.WriteAllText(updatedCsvFile.FullName, updatedCsvContent);
// To complete the step, we will set both a text and a file field
var stepRequest = step
.SetInput("Updated CSV", updatedCsvFile)
.SetInput("Email Address", YourEmail);
catalytic.Instances.CompleteStep(stepRequest);
Console.WriteLine($"You should have an email waiting for you at {YourEmail} now with the updated CSV converted to an Excel attachment");
}
}
}
Updated almost 3 years ago