|Exercise 4||Orthophoto Notification System|
|Data||Orthophoto images (GeoTIFF)|
|Overall Goal||Provide email-driven access to orthophoto files|
|Demonstrates||Processing an incoming email message|
As a technical analyst in the GIS department a recent project involved setting up a Data Download solution for users to serve orthophoto data to themselves. Having read up about notifications in FME Server, you think that it should be possible to set up a system that uses email-based automation.
So far you have set up a system for incoming email notifications to be registered by FME Server and proved that you can use that to trigger a workspace. Now you must actually edit the workspace to process the incoming email.
One part of the Data Download project clipped raster features to the boundary of a neighborhood. It should be possible to set up the workspace to have extract the neighborhood name from the subject line of the incoming email.
|Miss Vector says...|
|This exercise continues where exercise 3 left off. You must have completed exercise 3 to carry out this exercise.|
1) Open Workspace
Start FME Workbench and open the workspace: C:\FMEData2016\Workspaces\ServerAuthoring\Notifications-Ex4-Begin.fmw (you should open this workspace, even if you created one in exercise 3):
This workspace is a cut-down version of the one used for your Data Download project. Notice raster data is read and clipped to the boundary of a chosen neighborhood.
2) Add Reader
We now need to add a new Reader, which is what we'll use to obtain the content of the email message.
Select Readers > Add Reader from the menubar. When prompted set the parameters as follows:
|Reader Format||Text File|
|Reader Parameters||Read Whole File at Once: Yes|
It doesn't really matter what text file we use as the source, it won't be used anyway. It will be replaced by the content of the incoming email. The Read Whole File at Once parameter is important. With it we'll receive the email content as a single chunk of text. Without it we'll receive the content as lots of lines of text, which would be much harder to parse.
3) Add JSONFlattener
Now add a JSONFlattener transformer to the workspace, after the Text File Reader:
Open the parameters dialog. In there select text_line_data as the source of the JSON content. Under Attributes to Expose manually enter imap_publisher_subject and email_publisher_subject - this will provide us with the email subject line whether we are using IMAP or SMTP.
There are other components of the incoming email we could expose, but these are all we need for now.
4) Add FeatureMerger
Now we need to filter the flow of neighborhood features to include only the neighborhood defined in our email attribute. There are various ways of doing this - maybe the ChangeDetector or Matcher would work - but here we'll use the FeatureMerger combined with the existing Tester.
So, add a FeatureMerger transformer. The Neighborhood features are the Requestor, the JSONFlattener output the Supplier. The best way is to tidy the canvas to look like this:
Open the FeatureMerger parameters dialog. Set the requestor and supplier join values to two identical constant values, like so:
This means that the JSON attributes will be copied onto ALL neighborhood features.
5) Edit Tester
Now open the Tester transformer's parameters dialog. You need to set up two test clauses: one to test if NeighborhoodName = email_publisher_subject and one to test if NeighborhoodName = imap_publisher_subject - the test should be an OR:
Now the feature will pass if it exists in the email subject line - regardless of whether we use the IMAP or SMTP email protocol.
6) Publish to FME Server
Publish the workspace to FME Server. You may (or may not) need to also upload the source raster and KML datasets (depending on whether your FME Server can access the files on your authoring system). Simply register the workspace with the Job Submitter service.
7) Update Subscription
The subscription created in the previous exercise was for a different workspace. Therefore navigate to that subscription in the FME Server interface and change it to run the workspace published in the previous step.
On choosing the workspace you should get the option to set a couple of more parameters, including where you want the data to be written to. Choose to write it to Resources > Data > Output (creating the Output folder if it doesn't already exist).
Also - vitally - you get to choose where to send the incoming message. Choose the published parameter for the text file Reader:
This is how the text file Reader knows where to read the incoming JSON email message from.
8) Test Workspace
Test the workspace by sending an email to the Publication email address. Be sure to make the subject line one of the neighborhoods in Vancouver:
- Mount Pleasant
- West End
Check to ensure the workspace is triggered and run (in the Topic Monitoring and/or Jobs pages) and then look for the output dataset in Resources > Data > Output
|Ms Analyst says...|
|If the output dataset is missing, check the FME log to see what might have gone wrong. You can return to the workspace and add Logger transformers at strategic places and try again, giving the log file a bit more information to help debug problems.|
By completing this exercise you have learned how to: