Exercise 4 Building Updates Notification System
Data Building footprints (Esri Shapefile)
Overall Goal Provide email-driven notifications for updates
Demonstrates Email publications and Notification service
Start Workspace RealTime-Ex4-Begin.fmw
End Workspace RealTime-Ex4-Complete.fmw

As a technical analyst in the GIS department you were involved in a recent project to set up a Directory Watch solution for users to automatically update the corporate database.

Having learned that not all users are able to access the internal network where FME Server is hosted, you think that it should be possible to also set up a system that uses email-based automation to handle the same updates.



1) Create Topic
The first step is to create a Topic that will be triggered by the email. Log in to the FME Server web interface and navigate to the Notifications page.

Click the Publications tab and then select New.

Enter "Email Receiver" as the Name. Then click in the text box under Topics to Publish To. Type in ShapeIncomingEmail and click on it to add. This will create a new Topic and assign it to this Publication.

The new Publication can be created to use either the Email (SMTP) protocol or the Email (IMAP) protocol.

SMTP is easier to set up but FME Server must reside on a server with a proper DNS record (all FME Cloud and Training machines will have this). IMAP is necessary when FME Server resides on an internal network.


Email Protocol

To use the SMTP protocol select Email (SMTP) as the Publication Protocol. This will open the Email User Name parameter. Enter a name for receiving email, for example fmeshapeprocessing

Clicking OK will create an email address fmeshapeprocessing@<hostname> - for example:

HostExample Email Address
FME Cloud[email protected]
Amazon AWS[email protected]

Now all emails sent to that address will trigger the ShapeIncomingEmail topic.


IMAP Protocol

To use the IMAP protocol select Email (IMAP) as the Publication Protocol. This will open a number of other parameters. Enter them according to your email account.

In case it is of use, the server information for Gmail, Outlook, and Yahoo! are as follows:

IMAP Server Host imap.gmail.com imap-mail.outlook.com imap.mail.yahoo.com
Server Port 993 993 993
Connection Security SSL/TLS SSL/TLS SSL/TLS
Verify SSL Certificates Yes Yes Yes

You will also need to check the settings in your email account to make sure IMAP is turned on. Regardless of the email provider, you should set these parameters as follows:

Parameter Value
Poll Interval 1 Minute
Emails to Fetch New Emails Only
Download Attachments To A Resource folder of your choice

You may select any Resource folder for attachments to be saved to; but (if you have already completed exercise 1-3) don't choose the BuildingUpdates folder, else you'll cause the previous topics to be triggered by each email attachment!


2) Test Publication
Now let's test the publication. In the Notifications page on FME Server, click the tab marked Topics. Set up Topic Monitoring to watch the topic ShapeIncomingEmail:

Now send an email with an attachment to the address selected for the new publication. When the email is received by FME Server (SMTP), or FME Server fetches it (IMAP), the topic will be triggered with a message. (Remember that an IMAP publication only checks for an email every 60 seconds, so the result might not be immediate!)

Recall that in the previous exercise you used the Logger Protocol and Logger transformers to record the JSON formatted notification message. The same information is displayed in the Topic Monitoring window. So copy the text from the Topic Monitoring window and paste it into a text editor for use later in this exercise.


3) Update Workspace
You already have a created a workspace in FME Workbench to handle incoming notifications from Directory Watch. Let's modify the workflow so that it can work with both Publication protocols. Open the existing workspace C:\FMEData2017\Workspaces\ServerAuthoring\RealTime-Ex4-Begin.fmw in FME Workbench.

Open the JSONFlattener parameters, and add imap_publisher_attachment{0} and email_publisher_attachment{0} under Attributes to Expose:

You can see these are two of the available attributes that are returned by the Topic Message.

Ms Analyst says...
Adding both imap_publisher_attachment and email_publisher_attachment modifies this workspace so that it can work with both Email (SMTP) and Email (IMAP) Publications!


4) Add AttributeManager
The next step is to insert a transformer that will determine where the data is coming from (Directory Watch or an Email Publication) - this is a task where conditional statements are invaluable.

Add an AttributeManager transformer in between the JSONFlattener and FeatureReader. Open the parameters and add _dataset as a new Output Attribute.

Select, from the drop-down menu, the option to set the attribute as a Conditional Value:

Configure the Conditional Value as follows:

Attribute Test Set _dataset To
dirwatch_publisher_path Attribute has a value dirwatch_publisher_path
email_publisher_attachment{0} Attribute has a value email_publisher_attachment{0}
imap_publisher_attachment{0} Attribute has a value imap_publisher_attachment{0}

In other words:

  • If dirwatch_publisher_path has a value, then copy that value into the _dataset attribute.
  • Else, if email_publisher_attachment{0} has a value, then copy that value into the _dataset attribute.
  • Else, if imap_publisher_attachment{0} has a value, then copy that value into the _dataset attribute.

So _dataset gets the location of the data to be processed, whether it comes from the directory watch notification, or an email notification of either type.


5) Edit FeatureReader
The final step is to change the Dataset parameter in the FeatureReader transformer. Instead of pointing to dirwatch_publisher_path, it should be changed to point at the new _dataset attribute:

The workflow should now look like this:


6) Edit User Parameter
As with Exercise 3, specify the output dataset to be written into the FME Server Resources Folder.

Locate the user parameter DestDataset_SPATIALITE (under User Parameters > Published Parameters in the Navigator window) and double-click it to open an editor dialog.

In that dialog enter $(FME_SHAREDRESOURCE_DATA)/Output/building_footprints.sl3


7) Publish Workspace
Publish this workspace to FME Server, registering it under the Notification service. When the Notification service is selected, it is highlighted in red indicating its parameters need to be configured.

Click the "Edit" button and set ShapeIncomingEmail for the "Subscribe to Topics" parameter. Set the "Parameter to Get Topic Message" as Source Text File(s):


8) Update Directory Watch Subscription (Optional)
If you have completed Exercise 3, using the FME Server web interface you can set the "Process Building Updates" Subscription to point at this new workspace.


9) Test Workspace
Test the workspace by sending an email to the Publication email address. Be sure to attach a zip file of the Shapefile datasets (.dbf, .prj, .shp, .shx) from C:\FMEData2017\Data\Engineering\BuildingFootprints to the email.

You can verify if the workflow was successful by checking the Completed Jobs page and the timestamp of the SpatiaLite database in Resources > Data > Output in the FME Server web interface.


CONGRATULATIONS
By completing this exercise you have learned how to:
  • Create an Email Publication
  • Create a new FME Workspace Subscription as part of the Publishing process
  • Use incoming email to trigger Topics/Notifications
  • Configure a workspace to handle triggers by multiple Publication types

results matching ""

    No results matching ""