use of org.springframework.beans.factory.access.BeanFactoryReference in project opennms by OpenNMS.
the class BSFNotificationStrategy method declareBeans.
private static void declareBeans(BSFNotificationStrategy obj) throws BSFException {
// Retrieve the parameters before accessing them
obj.retrieveParams();
Integer nodeId;
try {
nodeId = Integer.valueOf(obj.m_notifParams.get(NotificationManager.PARAM_NODE));
} catch (NumberFormatException nfe) {
nodeId = null;
}
OnmsNode node = null;
OnmsAssetRecord assets = null;
final List<String> categories = new ArrayList<String>();
String nodeLabel = null;
String foreignSource = null;
String foreignId = null;
if (nodeId != null) {
final BeanFactoryReference bf = BeanUtils.getBeanFactory("notifdContext");
final NodeDao nodeDao = BeanUtils.getBean(bf, "nodeDao", NodeDao.class);
final TransactionTemplate transTemplate = BeanUtils.getBean(bf, "transactionTemplate", TransactionTemplate.class);
try {
// Redeclare the node id as final
final int theNodeId = nodeId;
node = transTemplate.execute(new TransactionCallback<OnmsNode>() {
@Override
public OnmsNode doInTransaction(final TransactionStatus status) {
final OnmsNode node = nodeDao.get(theNodeId);
// Retrieve the categories in the context of the transaction
if (node != null) {
for (OnmsCategory cat : node.getCategories()) {
categories.add(cat.getName());
}
}
return node;
}
});
if (node == null) {
LOG.error("Could not find a node with id: {}", theNodeId);
} else {
nodeLabel = node.getLabel();
assets = node.getAssetRecord();
foreignSource = node.getForeignSource();
foreignId = node.getForeignId();
}
} catch (final RuntimeException e) {
LOG.error("Error while retrieving node with id {}", nodeId, e);
}
}
s_bsfManager.declareBean("bsf_notif_strategy", obj, BSFNotificationStrategy.class);
s_bsfManager.declareBean("logger", LOG, Logger.class);
s_bsfManager.declareBean("notif_params", obj.m_notifParams, Map.class);
s_bsfManager.declareBean("node_label", nodeLabel, String.class);
s_bsfManager.declareBean("foreign_source", foreignSource, String.class);
s_bsfManager.declareBean("foreign_id", foreignId, String.class);
s_bsfManager.declareBean("node_assets", assets, OnmsAssetRecord.class);
s_bsfManager.declareBean("node_categories", categories, List.class);
s_bsfManager.declareBean("node", node, OnmsNode.class);
for (Argument arg : obj.m_arguments) {
if (NotificationManager.PARAM_TEXT_MSG.equals(arg.getSwitch()))
s_bsfManager.declareBean("text_message", arg.getValue(), String.class);
if (NotificationManager.PARAM_NUM_MSG.equals(arg.getSwitch()))
s_bsfManager.declareBean("numeric_message", arg.getValue(), String.class);
if (NotificationManager.PARAM_NODE.equals(arg.getSwitch()))
s_bsfManager.declareBean("node_id", arg.getValue(), String.class);
if (NotificationManager.PARAM_INTERFACE.equals(arg.getSwitch()))
s_bsfManager.declareBean("ip_addr", arg.getValue(), String.class);
if (NotificationManager.PARAM_SERVICE.equals(arg.getSwitch()))
s_bsfManager.declareBean("svc_name", arg.getValue(), String.class);
if (NotificationManager.PARAM_SUBJECT.equals(arg.getSwitch()))
s_bsfManager.declareBean("subject", arg.getValue(), String.class);
if (NotificationManager.PARAM_EMAIL.equals(arg.getSwitch()))
s_bsfManager.declareBean("email", arg.getValue(), String.class);
if (NotificationManager.PARAM_PAGER_EMAIL.equals(arg.getSwitch()))
s_bsfManager.declareBean("pager_email", arg.getValue(), String.class);
if (NotificationManager.PARAM_XMPP_ADDRESS.equals(arg.getSwitch()))
s_bsfManager.declareBean("xmpp_address", arg.getValue(), String.class);
if (NotificationManager.PARAM_TEXT_PAGER_PIN.equals(arg.getSwitch()))
s_bsfManager.declareBean("text_pin", arg.getValue(), String.class);
if (NotificationManager.PARAM_NUM_PAGER_PIN.equals(arg.getSwitch()))
s_bsfManager.declareBean("numeric_pin", arg.getValue(), String.class);
if (NotificationManager.PARAM_WORK_PHONE.equals(arg.getSwitch()))
s_bsfManager.declareBean("work_phone", arg.getValue(), String.class);
if (NotificationManager.PARAM_HOME_PHONE.equals(arg.getSwitch()))
s_bsfManager.declareBean("home_phone", arg.getValue(), String.class);
if (NotificationManager.PARAM_MOBILE_PHONE.equals(arg.getSwitch()))
s_bsfManager.declareBean("mobile_phone", arg.getValue(), String.class);
if (NotificationManager.PARAM_TUI_PIN.equals(arg.getSwitch()))
s_bsfManager.declareBean("phone_pin", arg.getValue(), String.class);
if (NotificationManager.PARAM_MICROBLOG_USERNAME.equals(arg.getSwitch()))
s_bsfManager.declareBean("microblog_username", arg.getValue(), String.class);
}
}
use of org.springframework.beans.factory.access.BeanFactoryReference in project opennms by OpenNMS.
the class Scriptd method onInit.
/**
* Initialize the <em>Scriptd</em> service.
*/
@Override
protected void onInit() {
// Load the configuration information
//
ScriptdConfigFactory aFactory = null;
try {
ScriptdConfigFactory.reload();
aFactory = ScriptdConfigFactory.getInstance();
} catch (IOException ex) {
LOG.error("Failed to load scriptd configuration", ex);
throw new UndeclaredThrowableException(ex);
}
// get the node DAO
BeanFactoryReference bf = BeanUtils.getBeanFactory("daoContext");
NodeDao nodeDao = BeanUtils.getBean(bf, "nodeDao", NodeDao.class);
m_executor = new Executor(aFactory, nodeDao);
}
use of org.springframework.beans.factory.access.BeanFactoryReference in project opennms by OpenNMS.
the class InsSession method getEventsByCriteria.
private void getEventsByCriteria() {
LOG.debug("clearing events");
clearEvents();
final BeanFactoryReference bf = BeanUtils.getBeanFactory("daoContext");
final EventDao eventDao = BeanUtils.getBean(bf, "eventDao", EventDao.class);
final TransactionTemplate transTemplate = BeanUtils.getBean(bf, "transactionTemplate", TransactionTemplate.class);
try {
transTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
LOG.debug("Entering transaction call back: selection with criteria: {}", criteriaRestriction);
final OnmsCriteria criteria = new OnmsCriteria(OnmsEvent.class);
criteria.add(Restrictions.sqlRestriction(criteriaRestriction));
final List<OnmsEvent> events = eventDao.findMatching(criteria);
LOG.info("Found {} event(s) with criteria: {}", events.size(), criteriaRestriction);
for (final OnmsEvent onmsEvent : events) {
final Event xmlEvent = getXMLEvent(onmsEvent);
if (xmlEvent != null)
addEvent(xmlEvent);
}
}
});
} catch (final RuntimeException e) {
LOG.error("Error while getting events.", e);
}
}
use of org.springframework.beans.factory.access.BeanFactoryReference in project simba-os by cegeka.
the class SpringAwareLocator method getApplicationContext.
private ApplicationContext getApplicationContext() {
if (context == null) {
BeanFactoryLocator locator = ContextSingletonBeanFactoryLocator.getInstance(contextConfigLocation);
BeanFactoryReference reference = locator.useBeanFactory("simbaContext");
context = (AbstractApplicationContext) reference.getFactory();
}
return context;
}
use of org.springframework.beans.factory.access.BeanFactoryReference in project opennms by OpenNMS.
the class InsAbstractSession method getIfAlias.
/**
* @param nodeid
* @param ifindex
* @return
*/
protected String getIfAlias(final int nodeid, final int ifindex) {
LOG.debug("getting ifalias for nodeid: {} and ifindex: {}", nodeid, ifindex);
setCriteria("nodeid = " + nodeid + " AND snmpifindex = " + ifindex);
BeanFactoryReference bf = BeanUtils.getBeanFactory("daoContext");
final SnmpInterfaceDao snmpInterfaceDao = BeanUtils.getBean(bf, "snmpInterfaceDao", SnmpInterfaceDao.class);
final TransactionTemplate transTemplate = BeanUtils.getBean(bf, "transactionTemplate", TransactionTemplate.class);
final OnmsSnmpInterface iface = transTemplate.execute(new TransactionCallback<OnmsSnmpInterface>() {
public OnmsSnmpInterface doInTransaction(final TransactionStatus status) {
return snmpInterfaceDao.findByNodeIdAndIfIndex(nodeid, ifindex);
}
});
if (iface == null) {
return "-1";
} else {
final String ifAlias = iface.getIfAlias();
LOG.debug("ifalias found: {}", ifAlias);
return ifAlias;
}
}
Aggregations