Search in sources :

Example 1 with EmailDestination

use of org.opennms.netmgt.alarmd.northbounder.email.EmailDestination in project opennms by OpenNMS.

the class EmailNorthbounderConfigurationResource method updateEmailDestination.

/**
     * Updates a specific email destination.
     *
     * @param destinationName the destination name
     * @param params the parameters map
     * @return the response
     */
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("destinations/{destinationName}")
public Response updateEmailDestination(@PathParam("destinationName") final String destinationName, final MultivaluedMapImpl params) {
    writeLock();
    try {
        boolean modified = false;
        final EmailDestination destination = getEmailDestination(destinationName);
        final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(destination);
        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();
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) EmailDestination(org.opennms.netmgt.alarmd.northbounder.email.EmailDestination) 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 EmailDestination (org.opennms.netmgt.alarmd.northbounder.email.EmailDestination)1 BeanWrapper (org.springframework.beans.BeanWrapper)1