Search in sources :

Example 36 with DELETE

use of javax.ws.rs.DELETE in project opennms by OpenNMS.

the class UserRestService method deleteUser.

@DELETE
@Path("{userCriteria}")
public Response deleteUser(@Context final SecurityContext securityContext, @PathParam("userCriteria") final String userCriteria) {
    writeLock();
    try {
        if (!hasEditRights(securityContext)) {
            throw getException(Status.BAD_REQUEST, "User {} does not have write access to users!", securityContext.getUserPrincipal().getName());
        }
        final OnmsUser user = getOnmsUser(userCriteria);
        LOG.debug("deleteUser: deleting user {}", user);
        try {
            m_userManager.deleteUser(user.getUsername());
        } catch (final Throwable t) {
            throw getException(Status.INTERNAL_SERVER_ERROR, t);
        }
        return Response.noContent().build();
    } finally {
        writeUnlock();
    }
}
Also used : OnmsUser(org.opennms.netmgt.model.OnmsUser) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 37 with DELETE

use of javax.ws.rs.DELETE in project opennms by OpenNMS.

the class UserRestService method deleteRole.

@DELETE
@Path("{userCriteria}/roles/{roleName}")
public Response deleteRole(@Context final SecurityContext securityContext, @PathParam("userCriteria") final String userCriteria, @PathParam("roleName") final String roleName) {
    writeLock();
    try {
        if (!hasEditRights(securityContext)) {
            throw getException(Status.BAD_REQUEST, "User {} does not have write access to users!", securityContext.getUserPrincipal().getName());
        }
        if (!Authentication.isValidRole(roleName)) {
            throw getException(Status.BAD_REQUEST, "Invalid role {}!", roleName);
        }
        final OnmsUser user = getOnmsUser(userCriteria);
        boolean modified = false;
        if (user.getRoles().contains(roleName)) {
            user.getRoles().remove(roleName);
            modified = true;
        }
        if (modified) {
            LOG.debug("deleteRole: user {} updated", user);
            try {
                m_userManager.save(user);
            } catch (final Throwable t) {
                throw getException(Status.INTERNAL_SERVER_ERROR, t);
            }
            return Response.noContent().build();
        }
        return Response.notModified().build();
    } finally {
        writeUnlock();
    }
}
Also used : OnmsUser(org.opennms.netmgt.model.OnmsUser) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 38 with DELETE

use of javax.ws.rs.DELETE in project opennms by OpenNMS.

the class OnmsSnmpInterfaceResource method deleteSnmpInterface.

/**
     * <p>deleteSnmpInterface</p>
     *
     * @param nodeCriteria a {@link java.lang.String} object.
     * @param ifIndex a int.
     * @return a {@link javax.ws.rs.core.Response} object.
     */
@DELETE
@Path("{ifIndex}")
public Response deleteSnmpInterface(@PathParam("nodeCriteria") final String nodeCriteria, @PathParam("ifIndex") final int ifIndex) {
    writeLock();
    try {
        final OnmsNode node = m_nodeDao.get(nodeCriteria);
        if (node == null)
            throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
        final OnmsEntity snmpInterface = node.getSnmpInterfaceWithIfIndex(ifIndex);
        if (snmpInterface == null)
            throw getException(Status.BAD_REQUEST, "Can't find SNMP interface with ifIndex {} for node {}", Integer.toString(ifIndex), nodeCriteria);
        LOG.debug("deletSnmpInterface: deleting interface with ifIndex {} from node {}", ifIndex, nodeCriteria);
        node.getSnmpInterfaces().remove(snmpInterface);
        m_nodeDao.saveOrUpdate(node);
        // TODO Add important events here
        return Response.noContent().build();
    } finally {
        writeUnlock();
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsEntity(org.opennms.netmgt.model.OnmsEntity) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 39 with DELETE

use of javax.ws.rs.DELETE in project opennms by OpenNMS.

the class OnmsMonitoredServiceResource method deleteService.

/**
     * <p>deleteService</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.
     * @return a {@link javax.ws.rs.core.Response} object.
     */
@DELETE
@Path("{service}")
public Response deleteService(@PathParam("nodeCriteria") final String nodeCriteria, @PathParam("ipAddress") final String ipAddress, @PathParam("service") final String serviceName) {
    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.CONFLICT, "Monitored Service {} was not found on IP Interface {} and node {}.", serviceName, ipAddress, nodeCriteria);
        LOG.debug("deleteService: deleting service {} from node {}", serviceName, nodeCriteria);
        Event e = EventUtils.createDeleteServiceEvent("OpenNMS.REST", node.getId(), ipAddress, serviceName, -1L);
        sendEvent(e);
        return Response.noContent().build();
    } finally {
        writeUnlock();
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Event(org.opennms.netmgt.xml.event.Event) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 40 with DELETE

use of javax.ws.rs.DELETE in project opennms by OpenNMS.

the class ForeignSourceRestService method deletePendingForeignSource.

/**
     * <p>deletePendingForeignSource</p>
     *
     * @param foreignSource a {@link java.lang.String} object.
     * @return a {@link javax.ws.rs.core.Response} object.
     */
@DELETE
@Path("{foreignSource}")
@Transactional
public Response deletePendingForeignSource(@PathParam("foreignSource") final String foreignSource) {
    writeLock();
    try {
        ForeignSource fs = getForeignSource(foreignSource);
        LOG.debug("deletePendingForeignSource: deleting foreign source {}", foreignSource);
        m_pendingForeignSourceRepository.delete(fs);
        return Response.accepted().build();
    } finally {
        writeUnlock();
    }
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

DELETE (javax.ws.rs.DELETE)202 Path (javax.ws.rs.Path)186 ApiOperation (io.swagger.annotations.ApiOperation)59 ApiResponses (io.swagger.annotations.ApiResponses)48 Produces (javax.ws.rs.Produces)43 Timed (com.codahale.metrics.annotation.Timed)31 AuditEvent (org.graylog2.audit.jersey.AuditEvent)25 IOException (java.io.IOException)20 Response (javax.ws.rs.core.Response)20 WebApplicationException (javax.ws.rs.WebApplicationException)17 HashMap (java.util.HashMap)15 NotFoundException (javax.ws.rs.NotFoundException)15 RestException (com.yahoo.pulsar.broker.web.RestException)12 Consumes (javax.ws.rs.Consumes)12 KeeperException (org.apache.zookeeper.KeeperException)12 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)11 ApiResponse (io.swagger.annotations.ApiResponse)11 NamespaceId (co.cask.cdap.proto.id.NamespaceId)9 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)9 Event (keywhiz.log.Event)9