&& !data.getActivityId().equals("")) {
ServiceDO service;
OperationDO operation;
ActivityDO activity;
MessageDataDO messageDataDO;
if (data.getTimeStamp() != null) {
messageDataDO = new MessageDataDO(data.getTimeStamp(), data.getRemoteIPAddress(), data
.getMessageDirection(), data.getMessageBody(), data.getRequestMessageStatus(), data
.getResponseMessageStatus());
} else {
messageDataDO = new MessageDataDO(
BAMCalendar.getInstance(Calendar.getInstance()).getBAMTimestamp(),
data.getRemoteIPAddress(), data.getMessageDirection(), data.getMessageBody(),
data.getRequestMessageStatus(), data.getResponseMessageStatus());
}
// When first time message comes to a system, service, operation
// need to be
// added.
try {
ServerDO serverDO = dsAdmin.getServer(data.getServerName());
if (serverDO != null) {
int serverId = serverDO.getId();
messageDataDO.setServerId(serverId);
} else {
log.error("Server is not in the Database" + data.getServerName());
}
} catch (BAMException e) {
log.error("Could not retrieve server from DB ", e);
}
try {
if (dsAdmin.getService(messageDataDO.getServerId(), data.getServiceName()) == null) {
service = new ServiceDO();
ServerDO serverDO = dsAdmin.getServer(data.getServerName());
if (serverDO != null) {
int serverId = serverDO.getId();
service.setServerID(serverId);
service.setName(data.getServiceName());
dsAdmin.addService(service);
messageDataDO.setServiceId(dsAdmin.getService(messageDataDO.getServerId(),
data.getServiceName()).getId());
}
} else {
messageDataDO.setServiceId(dsAdmin.getService(messageDataDO.getServerId(),
data.getServiceName()).getId());
}
} catch (BAMException e) {
log.error("Could not retrieve service from DB ", e);
}
try {
if (dsAdmin.getOperation(messageDataDO.getServiceId(), data.getOperationName()) == null) {
operation = new OperationDO();
ServiceDO serviceDO = dsAdmin.getService(messageDataDO.getServerId(), data.getServiceName());
if (serviceDO != null) {
operation.setServiceID(serviceDO.getId());
operation.setName(data.getOperationName());
dsAdmin.addOperation(operation);
messageDataDO.setOperationId(dsAdmin.getOperation(messageDataDO.getServiceId(),
data.getOperationName()).getOperationID());
} else {
serviceDO = new ServiceDO();
serviceDO.setServerID(messageDataDO.getServerId());
serviceDO.setName(data.getServiceName());
dsAdmin.addService(serviceDO);
messageDataDO.setServiceId(dsAdmin.getService(messageDataDO.getServerId(),
data.getServiceName()).getId());
operation.setServiceID(messageDataDO.getServiceId());
operation.setName(data.getOperationName());
dsAdmin.addOperation(operation);
messageDataDO.setOperationId(dsAdmin.getOperation(messageDataDO.getServiceId(),
data.getOperationName()).getOperationID());
}
} else {
messageDataDO.setOperationId(dsAdmin.getOperation(messageDataDO.getServiceId(),
data.getOperationName()).getOperationID());
}
} catch (BAMException e) {
log.error("Could not retrieve operation from DB ", e);
}
checkForActivityExistense(data, dsAdmin, messageDataDO);
try {
MessageDO msg = dsAdmin.getMessage(data.getMessageId(), messageDataDO.getOperationId(),
messageDataDO.getActivityKeyId());
if (msg != null) {
messageDataDO.setMessageKeyId(msg.getMessageKeyId());
} else {
MessageDO mesg = new MessageDO();
mesg.setMessageId(data.getMessageId());
mesg.setActivityKeyId(messageDataDO.getActivityKeyId());
mesg.setOperationId(messageDataDO.getOperationId());
mesg.setTimestamp(data.getTimeStamp());
mesg.setIPAddress(data.getRemoteIPAddress());
mesg.setUserAgent(data.getUserAgent());
//TODO: Data Services supports returning the ID
dsAdmin.addMessage(mesg);
messageDataDO.setMessageKeyId(dsAdmin.getMessage(data.getMessageId(),
messageDataDO.getOperationId(),
messageDataDO.getActivityKeyId())
.getMessageKeyId());
}
} catch (BAMException e) {
log.error("Error updating Message statistics data for server " + data.getServerName() + " service "
+ data.getServiceName() + " operation " + data.getOperationName()
+ " from eventing message receiver " + e.getLocalizedMessage());
}
// store to the BAM MessageData table
try {
MessageDataDO msgDat = dsAdmin.getMessageDataForActivityKeyIDandMessageKeyID(
messageDataDO.getMessageKeyId(), messageDataDO.getActivityKeyId());
if (msgDat != null) {
messageDataDO.setMessageDataKeyId(msgDat.getMessageDataKeyId());
// dsAdmin.updateMessageDump(data.getMessageBody(), data.getMessageDirection(),
// data.getRemoteIPAddress(), msgDat.getMessageDataKeyId());
} else {
if (data.getMessageDirection() != null) {
dsAdmin.addMessageDataDump(messageDataDO, data.getMessageDirection());