@GET @Path("/jail/{name}") @Permission({ "jail", "one" }) @ApiOperation(value = "Get a jail", notes = "Get detailed information about a jail.") public CachedNamedLocation getJail(@PathParam("name") String name) throws NotFoundException { Optional<NucleusJailService> optSrv = NucleusAPI.getJailService(); if (!optSrv.isPresent()) { throw new InternalServerErrorException("Nuclues jail service not available"); } NucleusJailService srv = optSrv.get(); return WebAPI.runOnMain(() -> { Optional<NamedLocation> optJail = srv.getJail(name); if (!optJail.isPresent()) { throw new NotFoundException("Jail with name " + name + " not found"); } return new CachedNamedLocation(optJail.get()); }); }
@DELETE @Path("/jail/{name}") @Permission({ "jail", "delete" }) @ApiOperation(value = "Delete a jail", notes = "Delete an existing jail.") public CachedNamedLocation deleteJail(@PathParam("name") String name) throws NotFoundException { Optional<NucleusJailService> optSrv = NucleusAPI.getJailService(); if (!optSrv.isPresent()) { throw new InternalServerErrorException("Nuclues jail service not available"); } NucleusJailService srv = optSrv.get(); return WebAPI.runOnMain(() -> { Optional<NamedLocation> optJail = srv.getJail(name); if (!optJail.isPresent()) { throw new NotFoundException("Jail with name " + name + " not found"); } srv.removeJail(name); return new CachedNamedLocation(optJail.get()); }); }
Optional<NamedLocation> optJail = srv.getJail(req.getName()); if (!optJail.isPresent()) { throw new InternalServerErrorException("Could not get jail after creating it");