Search in sources :

Example 1 with SnmpTrapMappingGroup

use of org.opennms.netmgt.alarmd.northbounder.snmptrap.SnmpTrapMappingGroup in project opennms by OpenNMS.

the class SnmpTrapNorthbounderConfigurationResource method updateImportMapping.

/**
 * Update import mapping.
 *
 * @param trapSinkName the trap sink name
 * @param mappingName the mapping name
 * @param params the parameters map
 * @return the response
 */
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("trapsinks/{trapsinkName}/import-mappings/{mappingName}")
public Response updateImportMapping(@PathParam("trapsinkName") final String trapSinkName, @PathParam("mappingName") final String mappingName, final MultivaluedMapImpl params) {
    writeLock();
    try {
        SnmpTrapSink trapSink = getSnmpTrapSink(trapSinkName);
        SnmpTrapMappingGroup mappingGroup = null;
        try {
            mappingGroup = trapSink.getImportMapping(mappingName);
        } catch (Throwable t) {
            throw getException(Status.INTERNAL_SERVER_ERROR, t);
        }
        if (mappingGroup == null) {
            return Response.status(404).build();
        }
        boolean modified = false;
        final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(mappingGroup);
        for (final String key : params.keySet()) {
            if (wrapper.isWritableProperty(key)) {
                final String stringValue = params.getFirst(key);
                final Object value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
                wrapper.setPropertyValue(key, value);
                modified = true;
            }
        }
        if (modified) {
            try {
                trapSink.addImportMapping(mappingGroup);
            } catch (Throwable t) {
                throw getException(Status.INTERNAL_SERVER_ERROR, t);
            }
            saveConfiguration();
            return Response.noContent().build();
        }
        return Response.notModified().build();
    } finally {
        writeUnlock();
    }
}
Also used : SnmpTrapMappingGroup(org.opennms.netmgt.alarmd.northbounder.snmptrap.SnmpTrapMappingGroup) BeanWrapper(org.springframework.beans.BeanWrapper) SnmpTrapSink(org.opennms.netmgt.alarmd.northbounder.snmptrap.SnmpTrapSink) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Aggregations

Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 SnmpTrapMappingGroup (org.opennms.netmgt.alarmd.northbounder.snmptrap.SnmpTrapMappingGroup)1 SnmpTrapSink (org.opennms.netmgt.alarmd.northbounder.snmptrap.SnmpTrapSink)1 BeanWrapper (org.springframework.beans.BeanWrapper)1