Parameterize a Metadata Writer GitBook

Publish date: 2024-05-09
Exercise 1Parameterize a Metadata Writer
DataParks (MapInfo TAB)
Overall GoalAllow user input to metadata fields
DemonstratesUse of FME parameters.
Creation and use of user parameters
Start WorkspaceC:\FMEData2019\Workspaces\DesktopAdvanced\Parameters-Ex1-Begin.fmw
End WorkspaceC:\FMEData2019\Workspaces\DesktopAdvanced\Parameters-Ex1-Complete.fmw

In this example, imagine that you are a GIS technician working for a city planning department.

The team responsible for maintaining parks has a workspace that translates their data from the source MapInfo TAB format to Google KML. It also writes a file of XML metadata to show who translated the data and when.

At the moment there are a number of problems they face:

You have been assigned to help solve these problems. At least one of these requires you to create user parameters to take the place of hard-coded values.


1) Start Workbench
Start Workbench and open the workspace C:\FMEData2019\Workspaces\DesktopAdvanced\Parameters-Ex1-Begin.fmw

The metadata part of the translation consists of the two transformers and an XML writer feature type.

The Sampler transformer ensures that only one record is written to the output metadata, by discarding all but one feature, and the AttributeCreator creates a set of attributes to write to the metadata.

Check the parameters for each transformer in turn. These are FME parameters, set by the workspace author and not available to the end-user. Here, for example, are the parameters for the Sampler transformer:

You can find these parameters in the Parmeter Editor window, the transformers' Parameters Dialog, and under the Transformers section of the Navigator window.


2) Change XML Writer Parameter
An FME parameter called Pretty Print controls the style of the XML file being written:

To ensure the output is always well-formatted, we should set this parameter to Yes - but we won't create a user parameter from it because we don't want the end-user to change it.

In the Navigator window locate the XML writer, expand the parameters list, and locate the parameter labeled Pretty Print. Double-click it.

In the dialog that opens, change the value to Yes and then click OK to close the dialog.

We have now - as a workspace author - changed an FME parameter.


3) Create User Parameter
The output schema has three variable attributes: username, user company (organization), and user email. We should create a user parameter for each of these to allow the end-user to enter that information.

Firstly, locate the User Parameters section of the Navigator window, right-click on it, and choose the option to Create User Parameter:

In the new dialog, select Text as the type of parameter to create (there is more on parameter types in the next section). Each parameter needs a name, so call this one UserNameParam. Now enter a prompt, such as "Enter your name."

Click OK to close the dialog and create the parameter, which now appears in the Navigator window.


4) Create Remaining User Parameters
The quickest way to create the other two required parameters (UserMailParam and UserCompanyParam) is to duplicate the UserNameParam parameter.

So, right-click on the UserNameParam parameter and choose the option to Duplicate:

A settings dialog for the duplicate parameter will open. Call it UserMailParam and set the prompt to “Enter your email address”.

Repeat the duplication process, this time creating a parameter called UserCompanyParam with the prompt "Enter your company name."

When done the Navigator window looks like this:


5) Use User Parameter – Method 1
Each of the user parameters we've just defined provides values that need to go into attributes in the writer schema. There are a number of ways to extract the value for such a purpose, and we’ll use a different way for each parameter, just to illustrate the different methods.

So, firstly locate the parameters for the AttributeCreator (either the Parameter Editor window or AttributeCreator Parameters dialog). This transformer is what currently creates the attributes for the output.

Click the Attribute Value field for the AuthorName attribute. Click on the drop-down arrow, then select User Parameter > UserNameParam.

Once done the value field will change to a special icon and show the parameter that was chosen:

While here, click on the AuthorEmail and AuthorCompany fields, and press the minus button to delete them, so that we can demonstrate dealing with these a different way.


6) Fix Date Attribute
Looking at the AttributeCreator, we can see that the date field is being entered as a fixed value. Although not a user parameter as such, it's evident that the user must be setting this manually at runtime.

Additionally, the date structure does not conform to an ISO standard, which is why the output fails XML validation.

Let's fix these issues. First click on the drop-down arrow next to the UpdateDate Attribute Value field, then choose Open Text Editor:

In the text editor remove any existing content and replace it with:

 @DateTimeFormat(@DateTimeNow(),%Y-%m-%d) 

This uses FME Date/Time functions to return today's date in a structure matching the ISO date standard.

FME Lizard says...
An alternative method is to simply set the date value to @DateTimeNow() and using the DateTimeConverter transformer to convert it to a real date in an ISO date standard:



7) Use User Parameter – Method 2
A second way to extract the value from a user parameter is with a ParameterFetcher transformer.

Place a ParameterFetcher transformer (after the AttributeCreator is fine). Inspect the parameters.

Select UserEmailParam as the parameter to fetch. Enter AuthorEmail as the name of the target attribute, then select UserCompanyParam and enter AuthorCompany as the target attribute:


8) Use User Parameter – Method 3
Did you notice that the list of parameters available includes many FME-related system parameters? These are particularly useful for use with FME Server and for writing metadata, as we are here.

Locate the BuildNumber attribute on the ParksMetadata feature type. Right click on that attribute and select the Edit Value option:

In the dialog that opens, you can enter a fixed (constant) value, but in our case, we’ll click on the drop-down arrow, select User Parameters, then FME Parameters, and then select FME_BUILD_NUM:

Click OK to close the dialog, and the feature type will highlight the attribute with a light red rightward-pointing arrow to show it has an attribute value set before being written.


9) Save and Run Workspace
Save the workspace and then – as if you were the end-user – run it. Be sure to set the Prompt option on the toolbar first:

When prompted enter your details into the fields that have been newly created, notice that the BuildNumber parameter we created isn't in the prompt. This is because it is an FME-specific private parameter that the user doesn't need to change:

NEW
Notice that - new for FME2019 - you can choose to save your parameter values both as the default and also as a set of preset values for later recall and use.

Locate and open the XML file to ensure the contents have been inserted as expected:

CONGRATULATIONS
By completing this exercise you have learned how to:
  • Set an FME parameter (on the XML writer)
  • Create a text type user parameter
  • Duplicate an existing parameter
  • Use a user parameter in a regular transformer
  • Use a user parameter in a ParameterFetcher transformer
  • Use a user parameter in an Edit Value dialog
  • Use the DateTimeNow and DateTimeFormat functions in a text editor to create an XML-valid date

ncG1vNJzZmirY2Ourq3ZqKWar6NjsLC5jqCgrZqfpLhwkMSsoq2noGKOpcLAp5qenF1nfXKFjn2crKOkpL2CsNWapZydlGmdor7AppytnaKofHV6pLGcq5uZqLJyesetpKU%3D