use of org.opennms.netmgt.alarmd.northbounder.snmptrap.SnmpTrapSink 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();
}
}
use of org.opennms.netmgt.alarmd.northbounder.snmptrap.SnmpTrapSink in project opennms by OpenNMS.
the class SnmpTrapNorthbounderConfigurationResource method updateSnmpTrapSink.
/**
* Update a specific SNMP trap sink.
*
* @param trapSinkName the trap sink name
* @param params the parameters map
* @return the response
*/
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("trapsinks/{trapsinkName}")
public Response updateSnmpTrapSink(@PathParam("trapsinkName") final String trapSinkName, final MultivaluedMapImpl params) {
writeLock();
try {
boolean modified = false;
SnmpTrapSink trapSink = getSnmpTrapSink(trapSinkName);
final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(trapSink);
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) {
saveConfiguration();
return Response.noContent().build();
}
return Response.notModified().build();
} finally {
writeUnlock();
}
}
use of org.opennms.netmgt.alarmd.northbounder.snmptrap.SnmpTrapSink in project opennms by OpenNMS.
the class SnmpTrapNorthbounderConfigurationResource method setImportMapping.
/**
* Sets an import mapping.
*
* @param trapSinkName the trap sink name
* @param mappingGroup the mapping group
* @return the response
*/
@POST
@Path("trapsinks/{trapsinkName}/import-mappings")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
public Response setImportMapping(@PathParam("trapsinkName") final String trapSinkName, final SnmpTrapMappingGroup mappingGroup) {
writeLock();
try {
SnmpTrapSink trapSink = getSnmpTrapSink(trapSinkName);
try {
trapSink.addImportMapping(mappingGroup);
} catch (Throwable t) {
throw getException(Status.INTERNAL_SERVER_ERROR, t);
}
saveConfiguration();
return Response.noContent().build();
} finally {
writeUnlock();
}
}
Aggregations