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();
}
}
Aggregations