use of javax.ws.rs.PUT in project opennms by OpenNMS.
the class OnmsIpInterfaceResource method updateIpInterface.
/**
* <p>updateIpInterface</p>
*
* @param nodeCriteria a {@link java.lang.String} object.
* @param ipAddress a {@link java.lang.String} object.
* @param params a {@link org.opennms.web.rest.support.MultivaluedMapImpl} object.
* @return a {@link javax.ws.rs.core.Response} object.
*/
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("{ipAddress}")
public Response updateIpInterface(@PathParam("nodeCriteria") final String nodeCriteria, @PathParam("ipAddress") final String ipAddress, final MultivaluedMapImpl params) {
writeLock();
try {
final OnmsNode node = m_nodeDao.get(nodeCriteria);
if (node == null) {
throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
}
final OnmsIpInterface ipInterface = node.getIpInterfaceByIpAddress(ipAddress);
if (ipInterface == null) {
throw getException(Status.CONFLICT, "Can't find interface with IP address {} for node {}.", ipAddress, nodeCriteria);
}
LOG.debug("updateIpInterface: updating ip interface {}", ipInterface);
final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(ipInterface);
boolean modified = false;
for (final String key : params.keySet()) {
// skip nodeId since we already know the node this is associated with and don't want to overwrite it
if ("nodeId".equals(key)) {
continue;
}
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) {
LOG.debug("updateIpInterface: ip interface {} updated", ipInterface);
m_ipInterfaceDao.saveOrUpdate(ipInterface);
return Response.noContent().build();
}
return Response.notModified().build();
} finally {
writeUnlock();
}
}
use of javax.ws.rs.PUT 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();
}
}
use of javax.ws.rs.PUT in project opennms by OpenNMS.
the class OnmsMonitoredServiceResource method updateService.
/**
* <p>updateService</p>
*
* @param nodeCriteria a {@link java.lang.String} object.
* @param ipAddress a {@link java.lang.String} object.
* @param serviceName a {@link java.lang.String} object.
* @param params a {@link org.opennms.web.rest.support.MultivaluedMapImpl} object.
* @return a {@link javax.ws.rs.core.Response} object.
*/
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("{service}")
public Response updateService(@PathParam("nodeCriteria") String nodeCriteria, @PathParam("ipAddress") String ipAddress, @PathParam("service") String serviceName, MultivaluedMapImpl params) {
writeLock();
try {
OnmsNode node = m_nodeDao.get(nodeCriteria);
if (node == null)
throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
OnmsIpInterface intf = node.getIpInterfaceByIpAddress(ipAddress);
if (intf == null)
throw getException(Status.BAD_REQUEST, "IP Interface {} was not found on node {}.", ipAddress, nodeCriteria);
OnmsMonitoredService service = intf.getMonitoredServiceByServiceType(serviceName);
if (service == null)
throw getException(Status.BAD_REQUEST, "Monitored Service {} was not found on IP Interface {} and node {}.", serviceName, ipAddress, nodeCriteria);
LOG.debug("updateService: updating service {}", service);
boolean modified = false;
BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(service);
for (String key : params.keySet()) {
if (wrapper.isWritableProperty(key)) {
String stringValue = params.getFirst(key);
Object value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
if (key.equals("status")) {
if ("S".equals(value) || ("A".equals(service.getStatus()) && "F".equals(value))) {
LOG.debug("updateService: suspending polling for service {} on node with IP {}", service.getServiceName(), service.getIpAddress().getHostAddress());
value = "F";
sendEvent(EventConstants.SUSPEND_POLLING_SERVICE_EVENT_UEI, service);
}
if ("R".equals(value) || ("F".equals(service.getStatus()) && "A".equals(value))) {
LOG.debug("updateService: resuming polling for service {} on node with IP {}", service.getServiceName(), service.getIpAddress().getHostAddress());
value = "A";
sendEvent(EventConstants.RESUME_POLLING_SERVICE_EVENT_UEI, service);
}
}
wrapper.setPropertyValue(key, value);
modified = true;
}
}
if (modified) {
LOG.debug("updateSservice: service {} updated", service);
m_serviceDao.saveOrUpdate(service);
return Response.noContent().build();
}
return Response.notModified().build();
} finally {
writeUnlock();
}
}
use of javax.ws.rs.PUT in project opennms by OpenNMS.
the class SnmpConfigRestService method setSnmpInfo.
/**
* <p>setSnmpInfo</p>
*
* @param ipAddress a {@link java.lang.String} object.
* @param snmpInfo a {@link org.opennms.web.snmpinfo.SnmpInfo} object.
* @return a {@link javax.ws.rs.core.Response} object.
*/
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
@Path("{ipAddr}")
public Response setSnmpInfo(@PathParam("ipAddr") final String ipAddress, final SnmpInfo snmpInfo) {
writeLock();
try {
final SnmpEventInfo eventInfo;
if (ipAddress.contains("-")) {
final String[] addrs = SnmpConfigRestService.getAddresses(ipAddress);
eventInfo = snmpInfo.createEventInfo(addrs[0], addrs[1]);
} else {
eventInfo = snmpInfo.createEventInfo(ipAddress);
}
m_accessService.define(eventInfo);
return Response.noContent().build();
} catch (final Throwable e) {
throw getException(Status.INTERNAL_SERVER_ERROR, "Can't update SNMP configuration for {} : {}", ipAddress, e.getMessage());
} finally {
writeUnlock();
}
}
use of javax.ws.rs.PUT in project opennms by OpenNMS.
the class AlarmRestService method updateAlarms.
/**
* <p>
* updateAlarms
* </p>
*
* @param formProperties
* a {@link org.opennms.web.rest.support.MultivaluedMapImpl} object.
*/
@PUT
@Transactional
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response updateAlarms(@Context final SecurityContext securityContext, final MultivaluedMapImpl formProperties) {
writeLock();
try {
final String ackValue = formProperties.getFirst("ack");
formProperties.remove("ack");
final String escalateValue = formProperties.getFirst("escalate");
formProperties.remove("escalate");
final String clearValue = formProperties.getFirst("clear");
formProperties.remove("clear");
final CriteriaBuilder builder = getCriteriaBuilder(formProperties, false);
builder.distinct();
builder.limit(0);
builder.offset(0);
final String ackUser = formProperties.containsKey("ackUser") ? formProperties.getFirst("ackUser") : securityContext.getUserPrincipal().getName();
formProperties.remove("ackUser");
assertUserEditCredentials(securityContext, ackUser);
final List<OnmsAlarm> alarms = m_alarmDao.findMatching(builder.toCriteria());
for (final OnmsAlarm alarm : alarms) {
final OnmsAcknowledgment acknowledgement = new OnmsAcknowledgment(alarm, ackUser);
acknowledgement.setAckAction(AckAction.UNSPECIFIED);
if (ackValue != null) {
if (Boolean.parseBoolean(ackValue)) {
acknowledgement.setAckAction(AckAction.ACKNOWLEDGE);
} else {
acknowledgement.setAckAction(AckAction.UNACKNOWLEDGE);
}
} else if (escalateValue != null) {
if (Boolean.parseBoolean(escalateValue)) {
acknowledgement.setAckAction(AckAction.ESCALATE);
}
} else if (clearValue != null) {
if (Boolean.parseBoolean(clearValue)) {
acknowledgement.setAckAction(AckAction.CLEAR);
}
} else {
throw getException(Status.BAD_REQUEST, "Must supply one of the 'ack', 'escalate', or 'clear' parameters, set to either 'true' or 'false'.");
}
m_ackDao.processAck(acknowledgement);
}
return alarms == null || alarms.isEmpty() ? Response.notModified().build() : Response.noContent().build();
} finally {
writeUnlock();
}
}
Aggregations