use of javax.ws.rs.NotFoundException in project keywhiz by square.
the class ClientsResource method clientDetailResponseFromId.
private ClientDetailResponse clientDetailResponseFromId(long clientId) {
Optional<Client> optionalClient = clientDAO.getClientById(clientId);
if (!optionalClient.isPresent()) {
throw new NotFoundException("Client not found.");
}
Client client = optionalClient.get();
ImmutableList<Group> groups = ImmutableList.copyOf(aclDAO.getGroupsFor(client));
ImmutableList<SanitizedSecret> sanitizedSecrets = ImmutableList.copyOf(aclDAO.getSanitizedSecretsFor(client));
return ClientDetailResponse.fromClient(client, groups, sanitizedSecrets);
}
use of javax.ws.rs.NotFoundException in project keywhiz by square.
the class SecretsResourceTest method rollbackThrowsException.
@Test(expected = NotFoundException.class)
public void rollbackThrowsException() {
doThrow(new NotFoundException()).when(secretDAO).setCurrentSecretVersionByName(eq("name2"), anyLong());
resource.resetSecretVersion(user, "name2", new LongParam("125"));
}
use of javax.ws.rs.NotFoundException in project graylog2-server by Graylog2.
the class MetricsResource method singleMetric.
@GET
@Timed
@Path("/{metricName}")
@ApiOperation(value = "Get a single metric")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such metric") })
@Produces(MediaType.APPLICATION_JSON)
public Metric singleMetric(@ApiParam(name = "metricName", required = true) @PathParam("metricName") String metricName) {
checkPermission(RestPermissions.METRICS_READ, metricName);
final Metric metric = metricRegistry.getMetrics().get(metricName);
if (metric == null) {
final String msg = "I do not have a metric called [" + metricName + "].";
LOG.debug(msg);
throw new NotFoundException(msg);
}
return metric;
}
use of javax.ws.rs.NotFoundException in project graylog2-server by Graylog2.
the class MetricsResource method byNamespace.
@GET
@Timed
@Path("/namespace/{namespace}")
@ApiOperation(value = "Get all metrics of a namespace")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such metric namespace") })
@Produces(MediaType.APPLICATION_JSON)
public MetricsSummaryResponse byNamespace(@ApiParam(name = "namespace", required = true) @PathParam("namespace") String namespace) {
final List<Map<String, Object>> metrics = Lists.newArrayList();
for (Map.Entry<String, Metric> e : metricRegistry.getMetrics().entrySet()) {
final String metricName = e.getKey();
if (metricName.startsWith(namespace) && isPermitted(RestPermissions.METRICS_READ, metricName)) {
try {
final Metric metric = e.getValue();
metrics.add(MetricUtils.map(metricName, metric));
} catch (Exception ex) {
LOG.warn("Could not read metric in namespace list.", ex);
}
}
}
if (metrics.isEmpty()) {
final String msg = "No metrics with namespace [" + namespace + "] found.";
LOG.debug(msg);
throw new NotFoundException(msg);
}
return MetricsSummaryResponse.create(metrics);
}
use of javax.ws.rs.NotFoundException in project graylog2-server by Graylog2.
the class IndexSetsResource method delete.
@DELETE
@Path("{id}")
@Timed
@ApiOperation(value = "Delete index set")
@AuditEvent(type = AuditEventTypes.INDEX_SET_DELETE)
@ApiResponses(value = { @ApiResponse(code = 403, message = "Unauthorized"), @ApiResponse(code = 404, message = "Index set not found") })
public void delete(@ApiParam(name = "id", required = true) @PathParam("id") String id, @ApiParam(name = "delete_indices") @QueryParam("delete_indices") @DefaultValue("true") boolean deleteIndices) {
checkPermission(RestPermissions.INDEXSETS_DELETE, id);
final IndexSet indexSet = getIndexSet(indexSetRegistry, id);
final IndexSet defaultIndexSet = indexSetRegistry.getDefault();
if (indexSet.equals(defaultIndexSet)) {
throw new BadRequestException("Default index set <" + indexSet.getConfig().id() + "> cannot be deleted!");
}
if (indexSetService.delete(id) == 0) {
throw new NotFoundException("Couldn't delete index set with ID <" + id + ">");
} else {
if (deleteIndices) {
try {
systemJobManager.submit(indexSetCleanupJobFactory.create(indexSet));
} catch (SystemJobConcurrencyException e) {
LOG.error("Error running system job", e);
}
}
}
}
Aggregations