Search in sources :

Example 1 with PropertyPath

use of org.opennms.core.spring.PropertyPath 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;
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) PropertyPath(org.opennms.core.spring.PropertyPath) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with PropertyPath

use of org.opennms.core.spring.PropertyPath 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;
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) PropertyPath(org.opennms.core.spring.PropertyPath) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)2 PropertyPath (org.opennms.core.spring.PropertyPath)2 ForeignSource (org.opennms.netmgt.provision.persist.foreignsource.ForeignSource)2