use of javax.ws.rs.PUT in project opennms by OpenNMS.
the class CategoryRestService method updateCategory.
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("/{categoryName}")
public Response updateCategory(@PathParam("categoryName") final String categoryName, final MultivaluedMapImpl params) {
writeLock();
try {
OnmsCategory category = m_categoryDao.findByName(categoryName);
if (category == null) {
throw getException(Status.BAD_REQUEST, "Category with name '{}' was not found.", categoryName);
}
LOG.debug("updateCategory: updating category {}", category);
BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(category);
boolean modified = 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);
modified = true;
}
}
LOG.debug("updateCategory: category {} updated", category);
if (modified) {
m_categoryDao.saveOrUpdate(category);
return Response.noContent().build();
}
return Response.notModified().build();
} finally {
writeUnlock();
}
}
use of javax.ws.rs.PUT in project opennms by OpenNMS.
the class KscRestService method addGraph.
@PUT
@Path("{kscReportId}")
@Transactional
public Response addGraph(@PathParam("kscReportId") final Integer kscReportId, @QueryParam("title") final String title, @QueryParam("reportName") final String reportName, @QueryParam("resourceId") final String resourceId, @QueryParam("timespan") String timespan) {
writeLock();
try {
if (kscReportId == null || reportName == null || reportName == "" || resourceId == null || resourceId == "") {
throw getException(Status.BAD_REQUEST, "Invalid request: reportName and resourceId cannot be empty!");
}
final Report report = m_kscReportFactory.getReportByIndex(kscReportId);
if (report == null) {
throw getException(Status.NOT_FOUND, "Invalid request: No KSC report found with ID: {}.", Integer.toString(kscReportId));
}
final Graph graph = new Graph();
if (title != null) {
graph.setTitle(title);
}
boolean found = false;
for (final String valid : KSC_PerformanceReportFactory.TIMESPAN_OPTIONS) {
if (valid.equals(timespan)) {
found = true;
break;
}
}
if (!found) {
LOG.debug("invalid timespan ('{}'), setting to '7_day' instead.", timespan);
timespan = "7_day";
}
graph.setGraphtype(reportName);
graph.setResourceId(resourceId);
graph.setTimespan(timespan);
report.addGraph(graph);
m_kscReportFactory.setReport(kscReportId, report);
try {
m_kscReportFactory.saveCurrent();
} catch (final Exception e) {
throw getException(Status.INTERNAL_SERVER_ERROR, "Cannot save report with Id {} : {} ", kscReportId.toString(), e.getMessage());
}
return Response.noContent().build();
} finally {
writeUnlock();
}
}
use of javax.ws.rs.PUT in project opennms by OpenNMS.
the class IfServicesRestService method updateServices.
@PUT
public Response updateServices(@Context final UriInfo uriInfo, final MultivaluedMapImpl params) {
final String status = params.getFirst("status");
if (status == null || !status.matches("(A|R|S|F)")) {
throw getException(Status.BAD_REQUEST, "Parameter status must be specified. Possible values: A (Managed), F (Forced Unmanaged), R (Rescan to Resume), S (Rescan to Suspend)");
}
final String services_csv = params.getFirst("services");
final List<String> serviceList = new ArrayList<String>();
if (services_csv != null) {
for (String s : services_csv.split(",")) {
serviceList.add(s);
}
}
final Criteria c = getCriteria(uriInfo.getQueryParameters());
c.setLimit(null);
c.setOffset(null);
final OnmsMonitoredServiceList services = new OnmsMonitoredServiceList(m_serviceDao.findMatching(c));
if (services.isEmpty()) {
throw getException(Status.BAD_REQUEST, "Can't find any service matching the provided criteria: {}.", uriInfo.getQueryParameters().toString());
}
boolean modified = false;
for (OnmsMonitoredService svc : services) {
boolean proceed = false;
if (serviceList.isEmpty()) {
proceed = true;
} else {
if (serviceList.contains(svc.getServiceName())) {
proceed = true;
}
}
if (proceed) {
modified = true;
final String currentStatus = svc.getStatus();
svc.setStatus(status);
m_serviceDao.update(svc);
if ("S".equals(status) || ("A".equals(currentStatus) && "F".equals(status))) {
LOG.debug("updateServices: suspending polling for service {} on node with IP {}", svc.getServiceName(), svc.getIpAddress().getHostAddress());
// TODO ManageNodeServlet is sending this.
sendEvent(EventConstants.SERVICE_UNMANAGED_EVENT_UEI, svc);
sendEvent(EventConstants.SUSPEND_POLLING_SERVICE_EVENT_UEI, svc);
}
if ("R".equals(status) || ("F".equals(currentStatus) && "A".equals(status))) {
LOG.debug("updateServices: resuming polling for service {} on node with IP {}", svc.getServiceName(), svc.getIpAddress().getHostAddress());
sendEvent(EventConstants.RESUME_POLLING_SERVICE_EVENT_UEI, svc);
}
}
}
return modified ? Response.noContent().build() : Response.notModified().build();
}
use of javax.ws.rs.PUT in project opennms by OpenNMS.
the class NodeRestService method updateNode.
/**
* <p>updateNode</p>
*
* @param nodeCriteria 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("{nodeCriteria}")
public Response updateNode(@PathParam("nodeCriteria") final String nodeCriteria, 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);
if (node.getAssetRecord().getGeolocation() == null) {
node.getAssetRecord().setGeolocation(new OnmsGeolocation());
}
LOG.debug("updateNode: updating node {}", node);
boolean modified = false;
final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(node);
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) {
LOG.debug("updateNode: node {} updated", node);
m_nodeDao.saveOrUpdate(node);
return Response.noContent().build();
}
return Response.notModified().build();
} finally {
writeUnlock();
}
}
use of javax.ws.rs.PUT in project opennms by OpenNMS.
the class NotificationRestService method updateNotifications.
/**
* <p>updateNotifications</p>
*
* @param params a {@link org.opennms.web.rest.support.MultivaluedMapImpl} object.
*/
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Transactional
public Response updateNotifications(@Context final SecurityContext securityContext, final MultivaluedMapImpl params) {
writeLock();
try {
Boolean ack = false;
if (params.containsKey("ack")) {
ack = "true".equals(params.getFirst("ack"));
params.remove("ack");
}
final CriteriaBuilder builder = getCriteriaBuilder(params);
for (final OnmsNotification notif : m_notifDao.findMatching(builder.toCriteria())) {
processNotifAck(securityContext, notif, ack);
}
return Response.noContent().build();
} finally {
writeUnlock();
}
}
Aggregations