Making calls to service-layer APIs

There are three API methods available to invoke on the Cúram Event Adaptor to create a CAP message and publish it the Intelligent Operations Center's WebSphere Message Broker instance.

SimplePublisher

curam.eventadaptor.publishers.intf.SimplePublisherIntf.publish(SimpleHeader, EventAdaptorNVPairList, EXTERNALEVENTTYPEEntry)

The SimplePublisher interface allows for publication of CAP messages with many of the values populated using defaults. This method assigns the values from the SimpleHeader and default values to a CAPHeader. This CAPHeader is then passed as a parameter to the curam.eventadaptor.publishers.intf.CAPPublisherIntf.publish method.

The SimpleHeader allows for some values in the CAP message to be set. The values that can be set are:

The remainder are default values, set from environment variables (which are defined in the code tables).

Table 1. Default CAP Event Values
Value Name Default Value
Identifier Random value
Category "Event"
Code "Other"
Certainty "Observed"
Message type "Alert"
Scope "Public"
Severity "Moderate"
Status "Actual"
Urgency "Unknown"

The code snippet below illustrates how to use the SimplePublisherIntf.

Figure 1. Using the SimplePublisher
@Inject
private TargetSystemDAO targetSystemDAO;

@Inject
SimplePublisher simplePublisher;

public ClassConstructor(string arg0) {
  super(arg0);
  GuiceWrapper.getInjector().injectMembers(this);
}

public simplePublisherSample() {
  // How to set up the variables that are passed to the publish method
  
  SimpleHeader simpleHeader = new SimpleHeader();
  
  simpleHeader.description = "Sample description";
  simpleHeader.event = "Sample event title";
  simpleHeader.headline = "Sample headline";
  simpleHeader.sender = "Sample sender";
  simpleHeader.onset = header. DateTime.getCurrentDateTime();
  
  EventAdaptorNVPair nvPair1 = new EventAdaptorNVPair();
  nvPair1.name = "parameter1 name";
  nvPair1.value = "parameter1 value";
  
  EventAdaptorNVPair nvPair2 = new EventAdaptorNVPair();
  nvPair2.name = "parameter2 name";
  nvPair2.value = "parameter2 value";
  
  nvPairList.dtls.add(nvPair1);
  nvPairList.dtls.add(nvPair2);
  
  // Call the publish method
  simplePublisher.publish(simpleHeader, nvPairList, EXTERNALEVENTTYPEEntry.EVENTADAPTOR_SAMPLE);
}

CAPPublisher

curam.eventadaptor.publishers.intf.CAPPublisherIntf.publish(CAPHeader, EventAdaptorNVPairList, EXTERNALEVENTTYPEEntry)

The CAPPublisher interface allows for publication of CAP messages with all of the values populated by the values passed in in the CAPHeader parameter.

This method validates the CAPHeader. The content of the header is then used to build a CAP XML document using capXMLBuilder.convertToDocument(). The output from this conversion is then passed as a parameter to the curam.eventadaptor.publishers.intf.XMLPublisherIntf.publish method.

The code snippet below illustrates how to use the CAPPublisherIntf.

Figure 2. Using the CAPPublisher
@Inject
private TargetSystemDAO targetSystemDAO;

@Inject
CAPPublisher capPublisher;

public ClassConstructor(string arg0) {
  super(arg0);
  GuiceWrapper.getInjector().injectMembers(this);
}

public capPublisherSample() {
  // How to set up the variables that are passed to the publish method
  
  CAPHeader capHeader = new CAPHeader();
  
  capHeader.description = "Sample description";
  capHeader.event = "Sample event name";
  capHeader.headline = "Sample headline";
  capHeader.identifier = "sampleIdentifier";
  capHeader.sender = "Sample sender";
  capHeader.category = EAALERTINFOCATEGORY.FIRE;
  capHeader.certainty = EAALERTINFOCERTAINTY.LIKELY;
  capHeader.messageType = EAALERTMESSAGETYPE.UPDATE;
  capHeader.onset = DateTime.getCurrentDateTime();
  capHeader.senderName = "the sendername";
  capHeader.scope = EAALERTSCOPE.PRIVATE;
  capHeader.severity = EAALERTINFOSEVERITY.EXTREME;
  capHeader.status = EAALERTSTATUS.TEST;
  capHeader.urgency = EAALERTINFOURGENCY.EXPECTED;
  capHeader.code = EAALERTCODE.EVENT;
  capHeader.webIdentifier = "http://www.curamsoftware.com"; 

  EventAdaptorNVPairList nvPairList = new EventAdaptorNVPairList();

  EventAdaptorNVPair nvPair1 = new EventAdaptorNVPair();
  nvPair1.name = "parameter1 name";
  nvPair1.value = "parameter1 value";

  EventAdaptorNVPair nvPair2 = new EventAdaptorNVPair();
  nvPair2.name = "parameter2 name";
  nvPair2.value = "parameter2 value";

  nvPairList.dtls.add(nvPair1);
  nvPairList.dtls.add(nvPair2);
  
  // Call the publish method
  capPublisher.publish(capHeader, nvPairList, EXTERNALEVENTTYPEEntry.EVENTADAPTOR_SAMPLE);
}

XMLPublisher

curam.eventadaptor.publishers.intf.XMLPublisherImpl.publish(Document, EXTERNALEVENTTYPEEntry)

The XMLPublisher interface allows for publication of SOAP messages with XML Document passed in in the Document parameter. This gives the most control of any of the publish APIs, as the XML is custom. This is the method that will be used if the Event Adaptor is to interact with an external service which does not work with CAP messages, or if a custom crafted CAP message is preferred.

If the External Event Type is enabled, it will validate the XML and then publish the document to the web service endpoint. If the Event Type is not enabled, then it will not publish the document.

The code snippet below illustrates how to use the XMLPublisherIntf.

Figure 3. Using the XMLPublisher
@Inject
private TargetSystemDAO targetSystemDAO;

@Inject
XMLPublisher xmlPublisher;

public ClassConstructor(string arg0) {
  super(arg0);
  GuiceWrapper.getInjector().injectMembers(this);
}

public xmlPublisherSample(Document document) {
  // Call the publish method
  XmlPublisher.publish(document, EXTERNALEVENTTYPEEntry.EVENTADAPTOR_SAMPLE);
}