Exercise 4.2 Building Updates Automation
Data Building footprints (Esri Shapefile)
Overall Goal Triggering real-time updates to databases
Demonstrates Processing Directory Watch messages
Start Workspace None
End Workspace C:\FMEData2019\Workspaces\ServerAuthoring\RealTime-Ex2-Complete.fmw

As a technical analyst in the GIS department, you have realized the overhead associated with pushing manual updates to your corporate database. Having read up about automations in FME Server, you think that it should be possible to set up a system that automates this process.

So far you have set up a system for added file notifications to be registered by FME Server. Now you must create a workspace to process these and publish it to FME Server. The workspace must then be triggered by the Directory Watch in Automations.

You may have noticed that the Log Action in Automations actually submits a workspace to process this request. Therefore we have already - perhaps unknowingly - covered how to set up this response. Now it's time to create a new workspace to fit in with your overall goal: to provide real-time updates to your corporate database.


FME Lizard says...
This exercise continues where Exercise 1 left off. You must have completed Exercise 1 to carry out this exercise.


1) Create Workspace
Start FME Workbench and begin with an empty workspace.

Select Readers > Add Reader from the menu bar. When prompted set the parameters as follows:

Reader Format Esri Shapefile
Reader Dataset C:\FMEData2019\Data\Engineering\BuildingFootprints\Updates001.shp
Workflow Options Single Merged Feature Type

It doesn't matter what Shapefile we use as the source right now; setting the source dataset in this step is only to satisfy the shapefile reader requirements. At runtime, the source dataset will be replaced by the file path recorded in the Directory Watch message.

By setting the Workflow options to Single Merged Feature Type this means it will be possible to process any source dataset (of the right format) and have it translated.


2) Add Writer
Having read the data from a Shapefile, we can now add it to the corporate database.

Select Writers > Add Writer from the menubar. When prompted set the parameters as follows:

Writer Format SpatiaLite
Writer Dataset C:\FMEData2019\Data\Engineering\BuildingFootprints\building_footprints.sl3
Writer Parameters Overwrite Existing Database: No
Add Feature Types Table Definition: Manual

In the new feature type that is created, change the Table Name parameter to building_footprints:

Ensure that the Table Handling is set to "Create if Needed". Click OK to close the dialog and then connect the new feature type to the output port of the Shapefile Reader.


3) Inspect Data After adding the writer, click on the building_footprints feature type to bring up the popup menu. Then click the Inspect button to open the dataset in Visual Preview. There is already data in the building_footprints.sl3 dataset, but we should take note of what the data looks like so we will know where it has changed once we update the dataset with the new data. The area within the red box will be where the new data will be added:


4) Publish Workspace
Save the workspace as RealTime-Ex2-Complete.fmw and publish it to the Training Repository in FME Server. We only need it to be run (not do anything special) so register it with the Job Submitter service only.


5) Add Dataset to FME Server
Since the purpose of this Automation is to update our database – let's make sure that it is accessible in FME Server. To do this, we will upload the building_footprints.sl3 SpatiaLite database to FME Server's shared resources.

Use the FME Server web interface to create a new folder Output in Resources > Data and upload the file located at C:\FMEData2019\Data\Engineering\BuildingFootprints\building_footprints.sl3


6) Edit Automation
Navigate to the Automations: Manage page and select Incoming Building Footprints to open the Automation for editing. Before you can make any changes stop the Automation using the button in the top right corner. Instead of adding a new action node, simply select the Log node and change the trigger parameter value to Run Workspace.

Select the Training Repository and workspace uploaded in the previous step. The parameters should now include one for the Source Esri Shapefile and the output database.

The source dataset needs to pick up the file path from the Directory Watch trigger. From the drop-down menu select file path found under the Directory folder. This drop down list is essentially the JSON flattened into its separate components.

For the output database browse the Resource/Data/Output folder to locate the SpatiaLite database uploaded in the previous step:


7) Add Filter
The Esri Shapefile Reader will only accept .shp file extension types, however the Directory Watch will pass a message to the workspace for every file uploaded. To prevent the Automation triggering database update workspaces that will fail add a Filter action so that only the file path containing .shp is parsed to the Run Workspace action.

Select the plus icon at the bottom of the canvas, drag an internal action (orange) onto the canvas.

Move the connection lines so that the Directory Watch enters this new Action node and the Run Workspace is connected to the Success Output port of this action.

Click on the action to configure the filter. There are two parameter values required. Similar to how the Source dataset of the workspace was set, specify the File Path as the Value to Filter. In the Contains String set the string to search for to .shp.

Click Apply to save the changes and restart the automation.


FME Lizard says...
Instead of using a filter action we could have zipped up the update002.shp/.dbf/.shx/.prj files so that the Directory Watch was only triggered once. Much like the Log Action notice the Filter submits a FilterMessage.fmw workspace for each incoming message, therefore if you are handling a high volume of incoming data zipping files may be the preferred option.


7) Test Solution
Now test the solution by putting update001, update002 or update003.shp (and other extensions) into the BuildingUpdates folder. If these files already exist from an earlier exercise, delete them first, then re-add them. You will find that each dataset put into the folder is added to the SpatiaLite database.

Check the Completed Jobs page to confirm that the workspace was run.


7) Inspect the Output
In the FME Data Inspector, add a new dataset, and browse to the C:\ProgramData\Safe Software\FMEServer\resources\data\Output\ folder and add the building_footprints.sl3 dataset. Depending on which update file you added, you should see one of the three buildings added to the dataset:


CONGRATULATIONS
By completing this exercise you have learned how to:
  • Identify JSON elements from an incoming Trigger message
  • Configure the Automation to run a workspace in response to a Trigger using part of this message
  • Chain actions by passing an element of the incoming JSON through a filter

results matching ""

    No results matching ""