use of javax.ws.rs.PUT in project opennms by OpenNMS.
the class NotificationRestService method updateNotification.
/**
* <p>updateNotification</p>
*
* @param notifId a {@link java.lang.String} object.
* @param ack a {@link java.lang.Boolean} object.
*/
@PUT
@Path("{notifId}")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Transactional
public Response updateNotification(@Context final SecurityContext securityContext, @PathParam("notifId") final Integer notifId, @FormParam("ack") final Boolean ack) {
writeLock();
try {
if (ack == null) {
throw getException(Status.BAD_REQUEST, "Must supply the 'ack' parameter, set to either 'true' or 'false'");
}
OnmsNotification notif = getNotification(notifId);
processNotifAck(securityContext, notif, ack);
return Response.noContent().build();
} finally {
writeUnlock();
}
}
use of javax.ws.rs.PUT in project opennms by OpenNMS.
the class HardwareInventoryResource method updateHwEntity.
/**
* Update hardware entity.
*
* @param nodeCriteria the node criteria
* @param entPhysicalIndex the entity physical index
* @param params the parameters
* @return the response
*/
@PUT
@Path("{entPhysicalIndex}")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response updateHwEntity(@PathParam("nodeCriteria") String nodeCriteria, @PathParam("entPhysicalIndex") Integer entPhysicalIndex, MultivaluedMapImpl params) {
writeLock();
try {
final OnmsNode node = getOnmsNode(nodeCriteria);
final OnmsHwEntity entity = getHwEntity(node.getId(), entPhysicalIndex);
boolean modified = true;
BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(entity);
for (String key : params.keySet()) {
if (key.startsWith("entPhysical")) {
if (wrapper.isWritableProperty(key)) {
String stringValue = params.getFirst(key);
Object value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
wrapper.setPropertyValue(key, value);
modified = true;
}
} else {
OnmsHwEntityAttribute attr = entity.getAttribute(key);
if (attr != null) {
attr.setValue(params.getFirst(key));
modified = true;
}
}
}
if (modified) {
m_hwEntityDao.save(entity);
return Response.noContent().build();
}
return Response.notModified().build();
} finally {
writeUnlock();
}
}
use of javax.ws.rs.PUT in project opennms by OpenNMS.
the class MonitoringLocationsRestService method updateMonitoringLocation.
@PUT
@Path("{monitoringLocation}")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Transactional
public Response updateMonitoringLocation(@PathParam("monitoringLocation") String monitoringLocation, MultivaluedMapImpl params) {
writeLock();
try {
OnmsMonitoringLocation def = m_monitoringLocationDao.get(monitoringLocation);
LOG.debug("updateMonitoringLocation: updating monitoring location {}", monitoringLocation);
if (params.isEmpty())
return Response.notModified().build();
boolean modified = false;
final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(def);
wrapper.registerCustomEditor(Duration.class, new StringIntervalPropertyEditor());
for (final String key : params.keySet()) {
if (wrapper.isWritableProperty(key)) {
Object value = null;
String stringValue = params.getFirst(key);
value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
wrapper.setPropertyValue(key, value);
modified = true;
}
}
if (modified) {
LOG.debug("updateMonitoringLocation: monitoring location {} updated", monitoringLocation);
m_monitoringLocationDao.save(def);
return Response.noContent().build();
}
return Response.notModified().build();
} finally {
writeUnlock();
}
}
use of javax.ws.rs.PUT in project opennms by OpenNMS.
the class NodeRestService method updateCategoryForNode.
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("/{nodeCriteria}/categories/{categoryName}")
public Response updateCategoryForNode(@PathParam("nodeCriteria") final String nodeCriteria, @PathParam("categoryName") final String categoryName, MultivaluedMapImpl params) {
writeLock();
try {
OnmsNode node = m_nodeDao.get(nodeCriteria);
if (node == null) {
throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
}
OnmsCategory category = getCategory(node, categoryName);
if (category == null) {
throw getException(Status.BAD_REQUEST, "Category {} not found on node {}", categoryName, nodeCriteria);
}
LOG.debug("updateCategory: updating category {}", category);
BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(category);
boolean updated = false;
for (String key : params.keySet()) {
if (wrapper.isWritableProperty(key)) {
String stringValue = params.getFirst(key);
Object value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
wrapper.setPropertyValue(key, value);
updated = true;
}
}
if (updated) {
LOG.debug("updateCategory: category {} updated", category);
m_categoryDao.saveOrUpdate(category);
} else {
LOG.debug("updateCategory: no fields updated in category {}", category);
}
return Response.noContent().build();
} finally {
writeUnlock();
}
}
use of javax.ws.rs.PUT 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