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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations