use of org.opennms.netmgt.provision.persist.foreignsource.ForeignSource in project opennms by OpenNMS.
the class AbstractForeignSourceRepository method getDefaultForeignSource.
/**
* <p>getDefaultForeignSource</p>
*
* @return a {@link org.opennms.netmgt.provision.persist.foreignsource.ForeignSource} object.
* @throws org.opennms.netmgt.provision.persist.ForeignSourceRepositoryException if any.
*/
@Override
public ForeignSource getDefaultForeignSource() throws ForeignSourceRepositoryException {
Resource defaultForeignSource = new ClassPathResource("/default-foreign-source.xml");
if (!defaultForeignSource.exists()) {
defaultForeignSource = new ClassPathResource("/org/opennms/netmgt/provision/persist/default-foreign-source.xml");
}
final ForeignSource fs = JaxbUtils.unmarshal(ForeignSource.class, defaultForeignSource);
fs.setDefault(true);
return fs;
}
use of org.opennms.netmgt.provision.persist.foreignsource.ForeignSource in project opennms by OpenNMS.
the class DefaultForeignSourceService method addParameter.
/**
* {@inheritDoc}
*/
@Override
public ForeignSource addParameter(String foreignSourceName, String pathToAdd) {
ForeignSource fs = getForeignSource(foreignSourceName);
PropertyPath path = new PropertyPath(pathToAdd);
Object obj = path.getValue(fs);
try {
MethodUtils.invokeMethod(obj, "addParameter", new Object[] { "key", "value" });
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException("Unable to call addParameter on object of type " + obj.getClass(), e);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("unable to access property " + pathToAdd, e);
} catch (InvocationTargetException e) {
throw new IllegalArgumentException("an execption occurred adding a parameter to " + pathToAdd, e);
}
m_pendingForeignSourceRepository.save(fs);
return fs;
}
use of org.opennms.netmgt.provision.persist.foreignsource.ForeignSource in project opennms by OpenNMS.
the class DefaultForeignSourceService method deletePath.
/**
* {@inheritDoc}
*/
@Override
public ForeignSource deletePath(String foreignSourceName, String pathToDelete) {
ForeignSource fs = getForeignSource(foreignSourceName);
PropertyPath path = new PropertyPath(pathToDelete);
Object objToDelete = path.getValue(fs);
Object parentObject = path.getParent() == null ? fs : path.getParent().getValue(fs);
String propName = path.getPropertyName();
String methodSuffix = Character.toUpperCase(propName.charAt(0)) + propName.substring(1);
String methodName = "delete" + methodSuffix;
try {
MethodUtils.invokeMethod(parentObject, methodName, new Object[] { objToDelete });
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException("Unable to find method " + methodName + " on object of type " + parentObject.getClass() + " with argument " + objToDelete, e);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("unable to access property " + pathToDelete, e);
} catch (InvocationTargetException e) {
throw new IllegalArgumentException("an execption occurred deleting " + pathToDelete, e);
}
m_pendingForeignSourceRepository.save(fs);
return fs;
}
use of org.opennms.netmgt.provision.persist.foreignsource.ForeignSource in project opennms by OpenNMS.
the class DefaultForeignSourceService method deleteDetector.
/**
* {@inheritDoc}
*/
@Override
public ForeignSource deleteDetector(String foreignSource, String name) {
ForeignSource fs = getForeignSource(foreignSource);
List<PluginConfig> detectors = fs.getDetectors();
for (Iterator<PluginConfig> i = detectors.iterator(); i.hasNext(); ) {
PluginConfig pc = i.next();
if (pc.getName().equals(name)) {
i.remove();
break;
}
}
m_pendingForeignSourceRepository.save(fs);
return fs;
}
use of org.opennms.netmgt.provision.persist.foreignsource.ForeignSource in project opennms by OpenNMS.
the class DefaultForeignSourceService method addPolicyToForeignSource.
/**
* {@inheritDoc}
*/
@Override
public ForeignSource addPolicyToForeignSource(String foreignSource, String name) {
ForeignSource fs = getForeignSource(foreignSource);
PluginConfig pc = new PluginConfig(name, "unknown");
fs.addPolicy(pc);
m_pendingForeignSourceRepository.save(fs);
return fs;
}
Aggregations