OMElement dataElement = (OMElement) dataElements.next();
QName keyQName = new QName(OPERATION_USER_DEFINED_DATA_NS_URI, ELEMENT_NAME_KEY);
OMElement keyElement = dataElement.getFirstChildWithName(keyQName);
if (keyElement == null) {
messageFaultReason = "Key element not found in the message";
throw new BAMException(messageFaultReason);
}
QName valueQName = new QName(OPERATION_USER_DEFINED_DATA_NS_URI, ELEMENT_NAME_VALUE);
OMElement valueElement = dataElement.getFirstChildWithName(valueQName);
if (valueElement == null) {
messageFaultReason = "Value element not found in the message";
throw new BAMException(messageFaultReason);
}
OperationUserDefinedDO operationUserDefinedDO = new OperationUserDefinedDO(operationName, calendar,
keyElement.getText(), valueElement.getText());
try {
int serverID = 0;
int serviceID = 0;
// check whether server is already in DB else add it
ServerDO server = dsAdmin.getServer(serverName, tenantId,
BAMConstants.SERVER_TYPE_EVENTING,BAMConstants.MEDIATION_STAT_TYPE);
if (server == null) {
if (serverName != null && serverName.length() > 0) {
server = new ServerDO();
server.setServerURL(serverName);
server.setTenantID(tenantId);
BAMPersistenceManager.getPersistenceManager(BAMUtil.getRegistry()).syncServer(server);
}
} else {
serverID = server.getId();
}
ServiceDO monitoringService= dsAdmin.getService(serverID, serviceName);
// check whether service is already in DB else add it
if ( monitoringService== null) {
if (serviceName != null && serviceName.length() > 0) {
ServiceDO service = new ServiceDO();
service.setServerID(serverID);
service.setName(serviceName);
BAMPersistenceManager.getPersistenceManager(BAMUtil.getRegistry()).syncService(service);
serviceID = monitoringService.getId();
}
} else {
serviceID = monitoringService.getId();
}
OperationDO monitoringOperation= dsAdmin.getOperation(serviceID, operationName);
// check whether operation is already in DB else add it
if (monitoringOperation == null) {
OperationDO operation = new OperationDO();
operation.setServiceID(serviceID);
operation.setName(operationName);
BAMPersistenceManager.getPersistenceManager(BAMUtil.getRegistry()).syncOperation(operation);
}
operationUserDefinedDO.setOperationID(monitoringOperation.getOperationID());
dsAdmin.addUserDefinedOperationData(operationUserDefinedDO);
} catch (Exception e) {
log.error("Error updating user defined data for operation " + operationName
+ " from eventing message messagereceiver " + e.getLocalizedMessage(), e);
}
}
} else {
// Invalid message, missing ServerName element
messageFaultReason = "OperationName/ServiceName/WSASServerName element not found in the message";
throw new BAMException(messageFaultReason);
}
} else {
// Invalid message, missing ServiceStatisticsData element
messageFaultReason = "OperationUserDefinedData element not found in the message";
throw new BAMException(messageFaultReason);
}
}
}