Mashup : Building Mashup Applications : Adding Triggers
 
Adding Triggers
 
About Feed and Design Triggers
Add triggers to an application or a page
Add triggers to a widget
Add triggers to a feed
For each application created within your Mashup Builder Premium instance, you can configure Feed and Design Triggers.
About Feed and Design Triggers
Add triggers to an application or a page
Add triggers to a widget
Add triggers to a feed
About Feed and Design Triggers
Feed Triggers
A Feed Trigger is an entry point to alter the behavior of a Feed.
It is called by the Mashup API before and after the feed execution, allowing for query manipulation, context modification and results manipulation.
Therefore, Feed Triggers can do the following:
Decide to override the query to be issued to the actual ‘execute’ method based on query expansion (beforeQuery method)
Decide to replay the feed execution because the result obtained is not satisfying, for example, if there are no results (afterQuery method that returns Result.EVAL_AGAIN)
Example:
You can use a Feed Trigger on any Feed in your configuration to customize query processing or feeds behavior for different purposes such as:
Query rewriting
Query computing from previously retrieved results
Enabling / Disabling feeds
Design Triggers
Design triggers are called by the Mashup Builder
They include:
Pre-request triggers which can be used to decide whether the user should be redirected to another page or not. The back end is not yet called, so no special load is triggered on the system. For example, redirect the user to the page called /imagesearch if the query starts with ‘image(s)’.
Page and widget triggers which have the possibility to alter the behavior of the display by making decisions to draw things or even change the configuration (each user request gets a fresh copy of the original configuration, so any changes at query time are safe). For example: decide whether a widget should be displayed or not.
Application triggers which are executed on all application pages.
Execution Flow
The Mashup trigger sequence is as follows:
Add triggers to an application or a page
This section describes how to add Feed and Design Triggers to a given application or a given page.
Note that:
Application triggers will be applied globally throughout all the pages of the application.
Page triggers will be applied on the selected page only.
Note: The Feed and Design triggers that can be applied at the ‘page level’ are the same as the ones that can be applied at the ‘application level’.
Add Feed triggers to a given application or page
1. In Mashup Builder, select a page and then select its Feeds view.
2. From the Triggers > Feed Triggers pane, drag the Feed (or Mashup API) triggers that you want to apply to the application level or to the page level.
Feed triggers description
Feed Trigger
Description
Category name regexp processing
Uses regular expressions to search and replace category names for a given feed.
It contains the following properties:
Facets– Enter the facet name.
Search for – Enter a Java regular expression string to search for a specific category name.
Replace with – Enter a Java regular expression string to replace the category name found by the Search for string by another category name.
Look up the reference for String.replaceAll() for further information.
Create facet
Creates pseudo-facets on the fly. This can be useful to create virtual facets for feeds returning a lot of unsorted hits.
For example, an XML feed returns several hits, one hit corresponds to a color meta and we want to use this meta as a facet in a pie chart to represent a pie section.
It contains the following properties:
meta name – Enter the meta name.
facet name – Enter the facet name.
facet description – Enter a description
Query Builder
This is the most important trigger.
It computes simple queries out of a feed result to override another feed's query. In other words, it allows you to programmatically build a query using previously fetched results, assembling metas, facets, etc.
Important: The current feed must be synchronized, otherwise unexpected behavior may occur! To synchronize the feed, select the Feeds view, and in the Feed Options section, set the Synchronized property to true. Sorting is important if you select the Synchronized option in the feed properties. It determines the execution order of your feeds. The first feed in the drop zone is executed first, when results are retrieved, the second feed is executed etc.
It contains the following properties:
xml – Displays the XML code that will be used by the trigger. This code contains the following nodes (the values in green are sample values only):
<string value="str" />: Appends the string "str" to the query. It is useful for static query chunks.
<join glue=" OR ">: Joins the values generated by the embedded nodes using the specified glue.
<metaValues metaName="title" max="3" quotes="true"/>: Retrieves up to 3 values of the "title" meta and surrounds them with quotes for an exact match query.
<facetLeaves facetId="coffee" max="10" quotes="true" />: Retrieves up to 10 values of the "coffee" facet and surrounds them with quotes for an exact match query.
<expr expr="${feeds["feedname"].metas["metaname"] + 10}" />: Executes the specified MEL expression.
<replace pattern="fo[uo]" replacement="bar" caseInsensitive="false">: Applies the specified replacements on the values generated by embedded nodes.
<if test="${expr}">: Executes the specified MEL expression test, and if true, calls the embedded generator nodes. You must format the node as follows: <if test="> <then> ... </then> <else> ... </else> </if>
Important:
Using only <if test="> ... </if> does not work.
Feed to override – Enter the name of the feed to override or simply select it from the list of available feeds from the Values tab (on the left).
Parameter to override Enter the feed parameter to override.
Execution mode – Select the trigger mode:
beforeQuery: builds the query for the current feed.
afterQuery: allows to take the feed's results to build a query for another feed.
Query Builder
Enable feed if disabled – Enables the feed if it is disabled, that is to say, if the Feed options > Enable property is set to false. You can indeed choose to disable a feed by default to launch it only if the query builder is executed to build a specific query. Note: This property is used only in afterQuery mode, that is to say after the execution of a first query.
Launch if empty – Launches the QueryBuilder trigger if the feed is empty or has no results. Note: This property is used only in afterQuery mode, that is to say after the execution of a first query.
JSON to Meta Trigger
Transforms JSON meta values into metas. This is useful for the collaborative widgets returning unreadable and unusable JSON strings that bring valuable information.
It contains the following property:
jsonMetaNames – Enter the JSON meta name that must be transformed into a standard Exalead CloudView meta.
Recommendation Trigger
Defines the feed that will be used for result-condition-based analysis in the Content Recommender. It checks whether the triggers have matched on the page.
Important: The current feed must be synchronized and placed on top of the recommendation feeds, otherwise unexpected behavior may occur. To synchronize the feed, select the Feeds view, and in the Feed Options section, set the Synchronized property to true.
Transform Categories
Applies transformations to a single category using a JavaScript expression. It contains the following property:
JavaScript expression – Enter a JavaScript expression to transform a specific category (available object: category) For example: category.count = category.count / 2
Transform Facets
Applies transformations to a single facet using a JavaScript expression.
It contains the following property:
JavaScript expression – Enter a JavaScript expression to transform a specific facet (available object: facet) For example: facet.name = \"New facet name\"
Page Feed Triggers description
Page Feed Trigger
Description
Aggregation Builder
This trigger can be added to the Page or to the Application level. It adds on-the-fly aggregations to a given facet. For example, you can add an aggregation to get the percentage corresponding to each category.
The calculation can also be performed using the values of different feeds. For example, FeedA relates to a group of items, FeedB relates to one of these items, and you want to make a comparison between these two.
Limitation: This trigger does NOT work with MultiDimension facets and Hierarchical2D facets.
It contains the following properties:
Target Feed – Specifies the target feed on which you want to create on-the-fly aggregations.
Target Facet – Specifies the target facet on which you want to create on-the-fly aggregations.
Facet Iteration mode – Specifies the iteration mode used to iterate each facet category. For example, the "Year" facet is set to YYYY/MM/dd:
ALL – recursive iteration,
FLAT – iteration on the first facet level, in our example: 2010, 2011, 2012, etc.
LEAVES – iteration on the last facet level, in our example: Monday, Tuesday, Wednesday, etc.
Aggregation name – Specifies the aggregation name.
MEL expression (Facet level) – Enter the MEL expression that will be evaluated at facet level to create the target aggregation value.
MEL expression (Category level) – Enter the MEL expression that will be evaluated at category level to create the target aggregation value.
Example:
Target feed: cloudview, Target Facet: area, Aggregation name: percent, MEL expression (Facet level): 100, MEL expression (Category level): ${(category.count*100)/feed.facets["myfacet"].count}
Join feed trigger
This trigger allows you to Join several feeds using a meta as key. It should be used with a query builder
It contains the following property:
Feeds to join: A list of feeds that you want to join using a given joinKey. The first feed of the list will contain the result of the join.
3. Click Save and then Apply your configuration changes.
Add triggers to a given application or page
1. In Mashup Builder, select a page and then select its Design view.
2. From the Triggers pane, select the type of trigger that you want to apply. For example, Pre Request Trigger.
3. Drag the Design triggers that you want to apply to the application level or to the page level. In the following screenshot the Pre Request Trigger I18N... is applied at the application level.
Mashup Page Triggers description
Mashup Page Trigger
Description
Business Console Debug Trigger
This trigger is required for the Business Console Test UI.
It communicates a list of matched rules to the Business Console (Content Recommender tool) and will override subfeeds according to matched rules output configurations.
Google Analytics Trigger
Launches a Google Analytics event trigger. Google Analytics allows you to track how often viewers click particular links on your website.
It contains the following property:
Google Analytics profile: Enter the name of your Google Analytics account ID. For example a code like ‘UA-10876-1’.
Override Page Title
Overrides the page title using result feeds. For example, if you want to set a title from the first hit name.
It contains the following property:
title: Enter the page title that will override the title configured in the Page properties. If blank, it will use the title defined in the WEB-INF/i18n/commons.properties file.
Pre Request Triggers description
Pre Request Trigger
Description
Cookie to parameter
Reads a cookie and sends its value to a new parameter that can be used by feeds as a page parameter.
By default, a timezone.js file (specified in Application > General > JavaScript) retrieves the local timezone of the user session and stores it in themashup-timezone cookie. The Cookie to parameter trigger retrieves this cookie value and pushes it to the timezone page parameter. The user timezone information is provided for each feed in the Advanced Parameters > Timezone Parameter
This trigger contains the following properties:
Parameter name: Specifies the name of the parameter that will contain the cookie value.
Cookie name: Specifies the name of the cookie which contains the value.
I18N: Retrieve the locale in the MashupAPI
Adds a new parameter containing the locale used in the Mashup Builder to the MashupAPI.
The MashupAPI has no ‘user session’ information whatsoever, and does not know which locale is used by the Mashup Builder. It can however be required when a trigger is launched so as to use it in your feed.
It contains the following property:
parameterName: Enter the name of the parameter which contains the locale.
Page Redirection
Redirects to another page used on a javascript routine.
It contains the following property:
expr: Enter a Javascript expression to redirect the user to another page. You must return the name of the page to be called, or null to stay on this page.
Important: If you are looking for an optimized way to do this, a Java PreRequestTrigger may be preferred.
Redirect by group
Redirects authorized/unauthorized group of users to specific page.
It contains the following properties:
Regular expression: Enter a regular expression to extract the group value from security tokens.
Rules: Define the group of users impacted by the redirection.
Redirect if mobile device
Redirects the user to a given URL if the User Agent comes from a mobile device.
It contains the following property:
url: Enter the URL where the user must be redirected to if the User Agent comes from a mobile device
4. Select the Preview to check your configuration changes.
5. Click Apply.
Add triggers to a widget
Triggers can be configured for a given widget. These triggers will be applied on the selected widget only.
1. In Mashup Builder, select a page and then select its Design view.
2. From the Triggers pane, select Mashup Widget Trigger.
3. Choose a widget and drag the triggers that you want to apply to its drop zone:
Mashup Widget Triggers description
Mashup Widget Trigger
Description
Asynchronous ajax loading
Loads the widget asynchronously.
Conditional display
Adds a conditional display to the widget, using a MEL expression parameter.
Remove if facet is empty
Hides a widget when the given facet is empty.
Remove if logged in
Hides a widget when the user is logged in.
Remove if no entries
Hides a widget when its sources contain no entries.
Remove if not logged in
Hides a widget when the user is not logged in. It is also hidden, if security is disabled or ill-configured.
Transform to Ajax links
Transforms all widget links to Ajax links. This is useful when you want to reload some widget components only, and NOT reload the whole page.
4. Click Save and then Apply your configuration changes.
Add triggers to a feed
Triggers can be configured for a given feed. These triggers will be applied on the selected feed only.
Note: The Feed triggers that can be applied at the ‘feed level’ are the same as the ones that can be applied at the ‘application level’.
1. In Mashup Builder, select a page and then select its Feeds view.
2. Choose a feed and drag the triggers that you want to apply to its drop zone.
3. Click Save and then Apply your configuration changes.