use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.
the class StreamOutputResource method get.
@GET
@Timed
@ApiOperation(value = "Get a list of all outputs for a stream")
@RequiresPermissions(RestPermissions.STREAM_OUTPUTS_CREATE)
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such stream on this node.") })
public OutputListResponse get(@ApiParam(name = "streamid", value = "The id of the stream whose outputs we want.", required = true) @PathParam("streamid") String streamid) throws NotFoundException {
checkPermission(RestPermissions.STREAMS_READ, streamid);
checkPermission(RestPermissions.STREAM_OUTPUTS_READ);
final Stream stream = streamService.load(streamid);
final Set<OutputSummary> outputs = new HashSet<>();
for (Output output : stream.getOutputs()) outputs.add(OutputSummary.create(output.getId(), output.getTitle(), output.getType(), output.getCreatorUserId(), new DateTime(output.getCreatedAt()), new HashMap<>(output.getConfiguration()), output.getContentPack()));
return OutputListResponse.create(outputs);
}
use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.
the class StreamRuleResource method create.
@POST
@Timed
@ApiOperation(value = "Create a stream rule")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.STREAM_RULE_CREATE)
public Response create(@ApiParam(name = "streamid", value = "The stream id this new rule belongs to.", required = true) @PathParam("streamid") String streamId, @ApiParam(name = "JSON body", required = true) @Valid @NotNull CreateStreamRuleRequest cr) throws NotFoundException, ValidationException {
checkPermission(RestPermissions.STREAMS_EDIT, streamId);
checkNotDefaultStream(streamId, "Cannot add stream rules to the default stream.");
final Stream stream = streamService.load(streamId);
final StreamRule streamRule = streamRuleService.create(streamId, cr);
final String id = streamService.save(streamRule);
clusterEventBus.post(StreamsChangedEvent.create(stream.getId()));
final SingleStreamRuleSummaryResponse response = SingleStreamRuleSummaryResponse.create(id);
final URI streamRuleUri = getUriBuilderToSelf().path(StreamRuleResource.class).path("{streamRuleId}").build(streamId, id);
return Response.created(streamRuleUri).entity(response).build();
}
use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.
the class StreamRuleServiceImpl method loadForStreamId.
@Override
public List<StreamRule> loadForStreamId(String streamId) throws NotFoundException {
ObjectId id = new ObjectId(streamId);
final List<StreamRule> streamRules = new ArrayList<>();
final List<DBObject> respStreamRules = query(StreamRuleImpl.class, new BasicDBObject(StreamRuleImpl.FIELD_STREAM_ID, id));
for (DBObject streamRule : respStreamRules) {
streamRules.add(toStreamRule(streamRule));
}
return streamRules;
}
use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.
the class StreamServiceImpl method load.
public Stream load(ObjectId id) throws NotFoundException {
final DBObject o = get(StreamImpl.class, id);
if (o == null) {
throw new NotFoundException("Stream <" + id + "> not found!");
}
final List<StreamRule> streamRules = streamRuleService.loadForStreamId(id.toHexString());
final Set<Output> outputs = loadOutputsForRawStream(o);
@SuppressWarnings("unchecked") final Map<String, Object> fields = o.toMap();
return new StreamImpl((ObjectId) o.get("_id"), fields, streamRules, outputs, getIndexSet(o));
}
use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.
the class ClusterStatsService method ldapStats.
public LdapStats ldapStats() {
int numberOfRoles = 0;
LdapSettings ldapSettings = null;
try {
numberOfRoles = roleService.loadAll().size();
ldapSettings = ldapSettingsService.load();
} catch (NotFoundException ignored) {
}
if (ldapSettings == null) {
return LdapStats.create(false, false, 0, numberOfRoles);
}
return LdapStats.create(ldapSettings.isEnabled(), ldapSettings.isActiveDirectory(), ldapSettings.getGroupMapping().size(), numberOfRoles);
}
Aggregations