EBIworld.com › 2.6 Examples › EBI API Example › Customized API Example :: SendEbiItmNotif.java
/* EXTOL International, all rights reserved
* Author: tfrance
* Date: 10/2003
*
* Modifications:
* Developer : shoppe
* Date : [2014/11/01]
* Description: Updated code to accept 3 arguments to pass into EBI event as 3 individual properties
*
* Developer :
* Date : [YYYY/MM/DD]
* Description:
*
*/
import com.extol.eventmanager.NotificationType;
import com.extol.eventmanager.NotificationService;
import com.extol.eventmanager.Notification;
import com.extol.eventmanager.NotificationException;
import com.extol.eventmanager.NotificationProperty;
/**
* Sample code that demonstrates how a client can use the EBI Notification API to send and receive notifications.
*/
public class SendEbiItmNotif {
NotificationService service;
NotificationType type;
Notification notification;
public SendEbiItmNotif(String formattedTypeName) {
System.out.println("...constructing the SendEbiItemNotif object...");
if (service == null) service = new NotificationService();
type = service.createNotificationType(formattedTypeName);
notification = service.createNotification(type);
}
public static void sendItemNotification(String formattedTypeName, String itemKeyValue, String itemKeyValue1, String itemKeyValue2, String notificationMessage,
Long sequenceNumber) {
if (formattedTypeName != null) {
System.out.println("formattedTypeLength (prior to trimming): " + formattedTypeName.length());
formattedTypeName.trim();
formattedTypeName = formattedTypeName.trim();
System.out.println("formattedTypeLength (after to trimming): " + formattedTypeName.length());
}
SendEbiItmNotif sender = new SendEbiItmNotif(formattedTypeName);
System.out.println("...decorating the notification with the item key value, notification message," +
" and sequence number...");
if (notificationMessage != null && notificationMessage.length() > 0) {
sender.notification.setMessage(notificationMessage);
} else {
System.out.println("...notification message was either null or the length was zero...");
}
sender.notification.setSequenceNumber(sequenceNumber.longValue());
if (itemKeyValue != null && itemKeyValue.length() > 0) {
// sender.notification.setUserData(new String[]{itemKeyValue});
NotificationProperty itemNumberProperty = new NotificationProperty("item_number", "XXX", 0);
itemNumberProperty.setValue(itemKeyValue);
sender.notification.addProperty(itemNumberProperty);
} else {
System.out.println("...item key value was either null or the lenght was zero...");
}
if (itemKeyValue1 != null && itemKeyValue1.length() > 0) {
// sender.notification.setUserData(new String[]{itemKeyValue});
NotificationProperty itemNumberProperty1 = new NotificationProperty("item_number1", "XXX", 1);
itemNumberProperty1.setValue(itemKeyValue1);
sender.notification.addProperty(itemNumberProperty1);
} else {
System.out.println("...item key value was either null or the lenght was zero...");
}
if (itemKeyValue2 != null && itemKeyValue2.length() > 0) {
// sender.notification.setUserData(new String[]{itemKeyValue});
NotificationProperty itemNumberProperty2 = new NotificationProperty("item_number2", "XXX", 2);
itemNumberProperty2.setValue(itemKeyValue2);
sender.notification.addProperty(itemNumberProperty2);
} else {
System.out.println("...item key value was either null or the lenght was zero...");
}
System.out.println("...sending the Notification object to EBI...");
try {
// Send the notification to EBI:
sender.service.sendNotification(sender.notification);
System.out.println("...sent successfully...");
}
catch (NotificationException ne) {
ne.printStackTrace();
System.out.println("Exception: " + ne.getMessage());
}
}
public static void main(String[] args) {
// Assume the arguments are in the same order and type as the method sendItemNotification, except the last arg
// which is a String
that needs to be convereted into a Long
// Dump the arguments to System.out
if (args != null) {
System.out.println("Arguments:");
for (int q=0; q < args.length; q++) {
System.out.println(" " + q + ") " + args[q]);
}
}
String localFormattedName = null;
String localItmNumber = null;
String localItmNumber1 = null;
String localItmNumber2 = null;
String localNotificationMessage = "Triggered Notification on ITMPHY01";
String localSequenceNumber = null;
Long localSequenceNumberL = null;
try {
localFormattedName = args[0];
localItmNumber = args[1];
localItmNumber1 = args[2];
localItmNumber2 = args[3];
localSequenceNumber = args[4];
localSequenceNumberL = new Long(localSequenceNumber);
}
catch (Exception e) {
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
System.err.println("Error while attempting to extract arguments: " + SendEbiItmNotif.class.getName());
StringBuffer errorBuffer = new StringBuffer();
errorBuffer.append("Expected:\n1)formattedTypeName (e.g. com.extol.test.itmphy01.insert\n2) itemKeyValue (e.g " +
"12345)\n3) sequenceNumber (e.g. 123)");
}
try {
SendEbiItmNotif.sendItemNotification(localFormattedName, localItmNumber, localItmNumber1, localItmNumber2, localNotificationMessage, localSequenceNumberL);
}
catch (Exception e) {
e.printStackTrace();
}
}
}