use of javax.ws.rs.PUT in project graylog2-server by Graylog2.
the class StreamRuleResource method update.
@PUT
@Path("/{streamRuleId}")
@Timed
@ApiOperation(value = "Update a stream rule")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Stream or stream rule not found."), @ApiResponse(code = 400, message = "Invalid JSON Body.") })
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.STREAM_RULE_UPDATE)
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) @Valid @NotNull CreateStreamRuleRequest cr) throws NotFoundException, ValidationException {
checkPermission(RestPermissions.STREAMS_EDIT, streamid);
checkNotDefaultStream(streamid, "Cannot update stream rules on default stream.");
final StreamRule streamRule;
streamRule = streamRuleService.load(streamRuleId);
if (!streamRule.getStreamId().equals(streamid)) {
throw new NotFoundException("Couldn't update stream rule " + streamRuleId + "in stream " + streamid);
}
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());
streamRule.setDescription(cr.description());
streamRuleService.save(streamRule);
clusterEventBus.post(StreamsChangedEvent.create(streamid));
return SingleStreamRuleSummaryResponse.create(streamRule.getId());
}
use of javax.ws.rs.PUT in project graylog2-server by Graylog2.
the class GrokResource method bulkUpdatePatterns.
@PUT
@Timed
@ApiOperation("Add a list of new patterns")
@AuditEvent(type = AuditEventTypes.GROK_PATTERN_IMPORT_CREATE)
public Response bulkUpdatePatterns(@ApiParam(name = "patterns", required = true) @NotNull GrokPatternList patternList, @ApiParam(name = "replace", value = "Replace all patterns with the new ones.") @QueryParam("replace") @DefaultValue("false") boolean replace) throws ValidationException {
checkPermission(RestPermissions.INPUTS_CREATE);
final Set<String> updatedPatternNames = Sets.newHashSet();
for (final GrokPattern pattern : patternList.patterns()) {
updatedPatternNames.add(pattern.name());
if (!grokPatternService.validate(pattern)) {
throw new ValidationException("Invalid pattern " + pattern + ". Did not save any patterns.");
}
}
grokPatternService.saveAll(patternList.patterns(), replace);
clusterBus.post(GrokPatternsChangedEvent.create(Collections.emptySet(), updatedPatternNames));
return Response.accepted().build();
}
use of javax.ws.rs.PUT in project graylog2-server by Graylog2.
the class AuditCoverageTest method testAuditCoverage.
@Test
public void testAuditCoverage() throws Exception {
final ConfigurationBuilder configurationBuilder = new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage("org.graylog2")).setScanners(new MethodAnnotationsScanner());
final Set<String> auditEventTypes = new AuditEventTypes().auditEventTypes();
final Reflections reflections = new Reflections(configurationBuilder);
final ImmutableSet.Builder<Method> methods = ImmutableSet.builder();
final ImmutableSet.Builder<Method> missing = ImmutableSet.builder();
final ImmutableSet.Builder<Method> unregisteredAction = ImmutableSet.builder();
methods.addAll(reflections.getMethodsAnnotatedWith(POST.class));
methods.addAll(reflections.getMethodsAnnotatedWith(PUT.class));
methods.addAll(reflections.getMethodsAnnotatedWith(DELETE.class));
for (Method method : methods.build()) {
if (!method.isAnnotationPresent(AuditEvent.class) && !method.isAnnotationPresent(NoAuditEvent.class)) {
missing.add(method);
} else {
if (method.isAnnotationPresent(AuditEvent.class)) {
final AuditEvent annotation = method.getAnnotation(AuditEvent.class);
if (!auditEventTypes.contains(annotation.type())) {
unregisteredAction.add(method);
}
}
}
}
assertThat(missing.build()).describedAs("Check that there are no POST, PUT and DELETE resources which do not have the @AuditEvent annotation").isEmpty();
assertThat(unregisteredAction.build()).describedAs("Check that there are no @AuditEvent annotations with unregistered event types").isEmpty();
}
use of javax.ws.rs.PUT in project incubator-atlas by apache.
the class TaxonomyService method updateTerm.
@PUT
@Path("{taxonomyName}/terms/{termName}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response updateTerm(String body, @Context HttpHeaders headers, @Context UriInfo ui, @PathParam("taxonomyName") String taxonomyName, @PathParam("termName") String termName) throws CatalogException {
AtlasPerfTracer perf = null;
try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.updateTerm(" + taxonomyName + ", " + termName + ")");
}
Map<String, Object> queryProperties = new HashMap<>();
queryProperties.put("termPath", new TermPath(taxonomyName, termName));
Map<String, Object> updateProperties = parsePayload(body);
updateResource(termResourceProvider, new InstanceRequest(queryProperties, updateProperties));
return Response.status(Response.Status.OK).entity(new Results(ui.getRequestUri().toString(), 200)).build();
} finally {
AtlasPerfTracer.log(perf);
}
}
use of javax.ws.rs.PUT in project incubator-atlas by apache.
the class TaxonomyService method updateTaxonomy.
@PUT
@Path("{taxonomyName}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response updateTaxonomy(String body, @Context HttpHeaders headers, @Context UriInfo ui, @PathParam("taxonomyName") String taxonomyName) throws CatalogException {
AtlasPerfTracer perf = null;
try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.updateTaxonomy(" + taxonomyName + ")");
}
Map<String, Object> queryProperties = new HashMap<>();
queryProperties.put("name", taxonomyName);
Map<String, Object> updateProperties = parsePayload(body);
updateResource(taxonomyResourceProvider, new InstanceRequest(queryProperties, updateProperties));
return Response.status(Response.Status.OK).entity(new Results(ui.getRequestUri().toString(), 200)).build();
} finally {
AtlasPerfTracer.log(perf);
}
}
Aggregations