This section describes how to create custom query alerts.
With Query Alerting, users can save queries and be alerted whenever new or modified documents that match these queries are added to the index. You can configure it using the Business Console (see "Setting up Query Alerting" the Exalead CloudView Business Console User's Guide) or the MAMI (see below.)
AlertingManager Class
The AlertingManager class provides a simple API to manage existing alerts, add new ones, and handles the communication with the Alerting MAMI.
When creating an alert, you have to specify the AlertDesc instance.
According to the alerting mode (scheduled or real-time), the following fields are mandatory:
Field
Mandatory for
Example
NAME
Scheduled
Real-time
-
USERNAME
Scheduled
Real-time
-
GROUP
Scheduled
Real-time
When using several groups, use commas as separators. For example, 'group1, group2'
QUERY_ARGS
Scheduled
Real-time
For the query london flat refined on file extension, language and source: 'cloudview.r=f%2FSource%2F4&cloudview.r=f%2FLanguage%2Fen&cloudview.r=%2Bf%2Ffile_extension%2F6&q=london%20flat&isDebugModeEnable=false& lang=en'
PAGE
Scheduled
-
UI_LEVEL_QUERY_ARGS
Scheduled
For the query london flat refined on file extension, language and source:
AddAlert mAMICmd = new AddAlert(); mAMICmd.withAlertDesc(alertDesc);
alertingManager.addAlert(mAMICmd);
Retrieve Existing Alerts or Alert Groups
Example 2. Sample for Alerts
import com.exalead.cloudview.alerting.v10.*;
. .
AlertDescList alertList = alertingManager.getUserAlerts(new GetUserAlerts().withUser(USERNAME). withGroup(GROUP)); // for a given user & a given group // or
alertList = alertingManager.getUserAlerts(new GetUserAlerts().withUser(USERNAME).withGroup(GROUP)); // for all users & a given group
for (AlertDesc alertDesc : alertList.getAlertDesc()) { // iterates on retrieved alerts // do whatever you want with your alert }
Example 3. Sample for Alert Groups
import com.exalead.cloudview.alerting.v10.*;
. .
AlertingStatus status = alertingManager.getAlertingStatus(new GetAlertingStatus());
for (AlertingGroupStatus groupStatus : status.getAlertingGroupStatus()) { // iterates on retrieved alert group statuses // do whatever you want with your alert group status System.out.println("Name: '" + groupStatus.getName() + "'"); System.out.println("Description: '" + groupStatus.getDescription() + "'"); System.out.println("Default? '" + groupStatus.isUseAsDefault() + "'"); }
Edit an Alert
When creating an alert, a key is automatically defined to identify it. This key is required to edit an alert and is it retrieved from the Alerting Manager.
Example 4. Sample
import com.exalead.cloudview.alerting.v10.*;
. .
AlertDesc anExistingAlert; // retrieve key
anExistingAlert.withName(NEW_ALERT_NAME); // edit alert name
EditAlert editCmd = new EditAlert().withAlertDesc(anExistingAlert); alertingManager.editAlert(editCmd);
Remove an Alert
When creating an alert, a key is automatically defined to identify it. This key is required to remove an alert and is it retrieved from the Alerting Manager.
Example 5. Sample
import com.exalead.cloudview.alerting.v10.*;
. .
AlertDesc anExistingAlert; // retrieve key
anExistingAlert.withName(NEW_ALERT_NAME); // edit alert name
DeleteAlert removeCmd = new DeleteAlert().withKey(anExistingAlert.getKey()); alertingManager.deleteAlert(removeCmd);