Search in sources :

Example 41 with ForeignSource

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;
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 42 with ForeignSource

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

Example 43 with ForeignSource

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

Example 44 with ForeignSource

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;
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource)

Example 45 with ForeignSource

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;
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource)

Aggregations

ForeignSource (org.opennms.netmgt.provision.persist.foreignsource.ForeignSource)72 PluginConfig (org.opennms.netmgt.provision.persist.foreignsource.PluginConfig)31 Test (org.junit.Test)23 Requisition (org.opennms.netmgt.provision.persist.requisition.Requisition)11 Before (org.junit.Before)10 MockForeignSourceRepository (org.opennms.netmgt.provision.persist.MockForeignSourceRepository)9 ArrayList (java.util.ArrayList)8 Path (javax.ws.rs.Path)8 Transactional (org.springframework.transaction.annotation.Transactional)8 TreeSet (java.util.TreeSet)6 File (java.io.File)4 DELETE (javax.ws.rs.DELETE)4 Date (java.util.Date)3 Consumes (javax.ws.rs.Consumes)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 Produces (javax.ws.rs.Produces)2 DateTime (org.joda.time.DateTime)2 Duration (org.joda.time.Duration)2