public SingleStreamRuleSummaryResponse update(@ApiParam(name = "streamid", value = "The stream id this rule belongs to.", required = true) @PathParam("streamid") String streamid,
@ApiParam(name = "streamRuleId", value = "The stream rule id we are updating", required = true) @PathParam("streamRuleId") String streamRuleId,
@ApiParam(name = "JSON body", required = true) CreateStreamRuleRequest cr) {
checkPermission(RestPermissions.STREAMS_EDIT, streamid);
final StreamRule streamRule;
try {
streamRule = streamRuleService.load(loadObjectId(streamRuleId));
if (!streamRule.getStreamId().equals(streamid)) {
throw new NotFoundException();
}
} catch (org.graylog2.database.NotFoundException e) {
throw new javax.ws.rs.NotFoundException(e);
}
final StreamRuleType streamRuleType = StreamRuleType.fromInteger(cr.type);
if(null == streamRuleType) {
throw new BadRequestException("Unknown stream rule type " + cr.type);
}
streamRule.setField(cr.field);
streamRule.setType(streamRuleType);
streamRule.setInverted(cr.inverted);
streamRule.setValue(cr.value);
String id;
try {
streamRuleService.save(streamRule);
id = streamRule.getId();
} catch (ValidationException e) {
LOG.error("Validation error.", e);
throw new BadRequestException(e);
}