Search in sources :

Example 41 with DELETE

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

the class NodeRestService method deleteNode.

/**
     * <p>deleteNode</p>
     *
     * @param nodeCriteria a {@link java.lang.String} object.
     * @return a {@link javax.ws.rs.core.Response} object.
     */
@DELETE
@Path("{nodeCriteria}")
public Response deleteNode(@PathParam("nodeCriteria") final String nodeCriteria) {
    writeLock();
    try {
        final OnmsNode node = m_nodeDao.get(nodeCriteria);
        if (node == null)
            throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
        LOG.debug("deleteNode: deleting node {}", nodeCriteria);
        Event e = EventUtils.createDeleteNodeEvent("OpenNMS.REST", node.getId(), -1L);
        sendEvent(e);
        return Response.noContent().build();
    } finally {
        writeUnlock();
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Event(org.opennms.netmgt.xml.event.Event) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 42 with DELETE

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

the class GroupRestService method deleteGroup.

@DELETE
@Path("{groupName}")
public Response deleteGroup(@PathParam("groupName") final String groupName) {
    writeLock();
    try {
        final OnmsGroup group = getOnmsGroup(groupName);
        LOG.debug("deleteGroup: deleting group {}", group);
        m_groupService.deleteGroup(groupName);
        return Response.noContent().build();
    } finally {
        writeUnlock();
    }
}
Also used : OnmsGroup(org.opennms.netmgt.model.OnmsGroup) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 43 with DELETE

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

the class GroupRestService method removeUser.

@DELETE
@Path("{groupName}/users/{userName}")
public Response removeUser(@PathParam("groupName") final String groupName, @PathParam("userName") final String userName) {
    writeLock();
    try {
        final OnmsGroup group = getOnmsGroup(groupName);
        if (group.getUsers().contains(userName)) {
            group.removeUser(userName);
            m_groupService.saveGroup(group);
            return Response.noContent().build();
        } else {
            throw getException(Status.BAD_REQUEST, "User with name '{}' does not exist in group '{}'", userName, groupName);
        }
    } finally {
        writeUnlock();
    }
}
Also used : OnmsGroup(org.opennms.netmgt.model.OnmsGroup) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 44 with DELETE

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

the class ForeignSourceRestService method deleteDeployedForeignSource.

/**
     * <p>deleteDeployedForeignSource</p>
     *
     * @param foreignSource a {@link java.lang.String} object.
     * @return a {@link javax.ws.rs.core.Response} object.
     */
@DELETE
@Path("deployed/{foreignSource}")
@Transactional
public Response deleteDeployedForeignSource(@PathParam("foreignSource") final String foreignSource) {
    writeLock();
    try {
        ForeignSource fs = getForeignSource(foreignSource);
        LOG.debug("deleteDeployedForeignSource: deleting foreign source {}", foreignSource);
        if ("default".equals(foreignSource)) {
            m_deployedForeignSourceRepository.resetDefaultForeignSource();
        } else {
            m_deployedForeignSourceRepository.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)

Example 45 with DELETE

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

the class NodeRestService method removeCategoryFromNode.

@DELETE
@Path("/{nodeCriteria}/categories/{categoryName}")
public Response removeCategoryFromNode(@PathParam("nodeCriteria") String nodeCriteria, @PathParam("categoryName") String categoryName) {
    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("deleteCaegory: deleting category {} from node {}", categoryName, nodeCriteria);
        node.getCategories().remove(category);
        m_nodeDao.saveOrUpdate(node);
        return Response.noContent().build();
    } finally {
        writeUnlock();
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

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