Exporting and Importing Workflows using XML

Using the Flux APIs, you can easily export your workflows to XML, then import them into a different environment.

This is especially useful when moving data between environments – for example, moving a workflow from development to production.

This is also useful for moving to a newer version of Flux that has a different database schema than your previous version. In most cases, a major or minor upgrade will require a new database schema. In those cases you can follow these steps to perform the upgrade (NOTE: if you are running a secured engine, use only the code marked "Secured Engine" in the steps below. If you are using an unsecured engine, use the "Unsecured Engine" code instead):

  1. Create a new database schema for the new Flux version.
  2. Start the old version of Flux and run the export running workflows code below on that version. This will save all of the workflow data to an XML file.
  3. Run the export repository workflows code on the same Flux version, to export all repository workflows to a separate XML file.
  4. Shut down the old version of Flux.
  5. Start the new version of Flux, making sure that it is using the new schema.
  6. Run the import running workflows code below to import all of the workflow data into the new version.
  7. Run the import repository code as well to import all workflows from the repository.

Export Running Workflows

The following code exports all running workflows to an XML file:

import flux.*;
 
 
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
 
public class ExportFlows {
 
 
  public static void main(String[] args) throws NotBoundException, EngineException, RemoteException, FileNotFoundException {
 
 
//    Look up the engine on the specified host and port, with the SSL setting given.
    Engine engine = Factory.makeInstance().lookupEngine("localhost"7520true);
    try {
 
 
//      Edit this to use a valid login for your engine.
//      If security is not enabled, comment out the line below, as well as the
//      try / finally block and the logout line.
      engine.login("admin""admin");
       
      List workflows = new ArrayList();
 
 
      FlowChartIterator fcit = engine.get();
 
 
      try {
        while (fcit.hasNext()) {
          workflows.add(fcit.next());
        }
      finally {
        fcit.close();
      }
 
 
//      Export the workflows to XML - make sure to update
//      the path to a location on your own server.
      EngineHelper.makeXmlFromFlowCharts(workflows, new FileOutputStream("/path/to/workflows.xml"), true);
    finally {
      engine.logout();
    }
  }
}

Import Running Workflows

The following code loads an XML file and imports all running workflows onto the target engine:

import flux.*;
 
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.List;
 
 
public class ImportFlows {
 
 
  public static void main(String[] args) throws NotBoundException, EngineException, RemoteException, FileNotFoundException {
 
 
//    Look up the engine on the specified host and port, with the SSL setting given.
    Engine engine = Factory.makeInstance().lookupEngine("localhost"7520true);
 
 
    try {
 
 
//      Edit this to use a valid login for your engine.
//      If security is not enabled, comment out the line below, as well as the
//      try / finally block and the logout line.
      engine.login("admin""admin");
 
 
//     Make sure to use the same file path that you previously exported to.
      List<FlowChart> workflows = EngineHelper.makeFlowChartsFromXml(new FileInputStream("/path/to/workflows.xml"), true);
 
 
//      Add the flows to the engine.
      for (FlowChart workflow : workflows) {
        engine.put(workflow);
      }
    finally {
      engine.logout();
    }
  }
}

Export Repository Workflows

The following code exports all repository workflows to an XML file:

import flux.*;
import flux.repository.RepositoryAdministrator;
import flux.repository.RepositoryElement;
import flux.repository.RepositoryIterator;
 
 
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
 
 
public class ExportFlows {
 
 
  public static void main(String[] args) throws NotBoundException, EngineException, RemoteException, FileNotFoundException {
 
 
//    Look up the engine on the specified host and port, with the SSL setting given.
    Engine engine = Factory.makeInstance().lookupEngine("localhost"7520true);
 
 
    try {
 
 
//      Edit this to use a valid login for your engine.
//      If security is not enabled, comment out the line below, as well as the
//      try / finally block and the logout line.
      engine.login("admin""admin");
 
 
      List<FlowChart> workflows = new ArrayList<FlowChart>();
 
 
      RepositoryAdministrator repoAdmin = engine.getRepositoryAdministrator();
      RepositoryIterator repoIt = repoAdmin.get("/");
      try {
        while (repoIt.hasNext()) {
          RepositoryElement repoEl = repoIt.next();
          if (repoEl.isFlowChart()) {
            workflows.add(repoEl.getFlowChart());
          }
        }
      finally {
        repoIt.close();
      }
 
 
      //    Exoport the workflows to XML - make sure to update the path below to a
      //    location on your own server.
      EngineHelper.makeXmlFromFlowCharts(workflows, new FileOutputStream("/path/to/repository-workflows.xml"), true);
    finally {
      engine.logout();
    }
  }
}

Import Repository Workflows

The following code loads an XML file and imports all repository workflows from that file onto an engine:

import flux.*;
import flux.repository.RepositoryAdministrator;
 
 
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.List;
 
 
public class ImportFlows {
 
 
  public static void main(String[] args) throws NotBoundException, EngineException, RemoteException, FileNotFoundException {
 
 
//    Look up the engine on the specified host and port, with the SSL setting given.
    Engine engine = Factory.makeInstance().lookupEngine("localhost"7520true);
 
 
    try {
 
 
//      Edit this to use a valid login for your engine.
//      If security is not enabled, comment out the line below, as well as the
//      try / finally block and the logout line.
 engine.login("admin""admin");
  
//     Make sure to use the same file path that you previously exported to.
      List<FlowChart> workflows = EngineHelper.makeFlowChartsFromXml(new FileInputStream("/path/to/repository-workflows.xml"), true);
      RepositoryAdministrator repoAdmin = engine.getRepositoryAdministrator();
 
 
//      Add the flows to the engine.
      for (FlowChart workflow : workflows) {
 
 
//        Overwrites any existing workflows with the same name – set the second argument
//        to false if you do not want to overwrite.
        repoAdmin.put(workflow, true);
      }
    finally {
      engine.logout();
    }
  }
}
 
 
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.