Search in sources :

Example 56 with PUT

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();
    }
}
Also used : OnmsNotification(org.opennms.netmgt.model.OnmsNotification) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) Transactional(org.springframework.transaction.annotation.Transactional)

Example 57 with PUT

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();
    }
}
Also used : OnmsHwEntity(org.opennms.netmgt.model.OnmsHwEntity) BeanWrapper(org.springframework.beans.BeanWrapper) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsHwEntityAttribute(org.opennms.netmgt.model.OnmsHwEntityAttribute) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 58 with PUT

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();
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) StringIntervalPropertyEditor(org.opennms.netmgt.provision.persist.StringIntervalPropertyEditor) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) Transactional(org.springframework.transaction.annotation.Transactional)

Example 59 with PUT

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();
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 60 with PUT

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();
    }
}
Also used : SnmpTrapMappingGroup(org.opennms.netmgt.alarmd.northbounder.snmptrap.SnmpTrapMappingGroup) BeanWrapper(org.springframework.beans.BeanWrapper) SnmpTrapSink(org.opennms.netmgt.alarmd.northbounder.snmptrap.SnmpTrapSink) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Aggregations

PUT (javax.ws.rs.PUT)203 Path (javax.ws.rs.Path)172 Consumes (javax.ws.rs.Consumes)108 Produces (javax.ws.rs.Produces)72 ApiOperation (io.swagger.annotations.ApiOperation)70 ApiResponses (io.swagger.annotations.ApiResponses)53 Timed (com.codahale.metrics.annotation.Timed)36 AuditEvent (org.graylog2.audit.jersey.AuditEvent)36 URI (java.net.URI)24 Response (javax.ws.rs.core.Response)23 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)19 IOException (java.io.IOException)18 BeanWrapper (org.springframework.beans.BeanWrapper)16 BadRequestException (javax.ws.rs.BadRequestException)14 NotFoundException (javax.ws.rs.NotFoundException)14 WebApplicationException (javax.ws.rs.WebApplicationException)12 UriBuilder (javax.ws.rs.core.UriBuilder)12 UUID (java.util.UUID)11 GET (javax.ws.rs.GET)11 POST (javax.ws.rs.POST)11