use of org.graylog2.plugin.database.validators.ValidationResult in project graylog2-server by Graylog2.
the class EventNotificationsResource method test.
@POST
@Timed
@Path("/test")
@RequiresPermissions(RestPermissions.EVENT_NOTIFICATIONS_CREATE)
@ApiOperation(value = "Send a test alert for a given event notification")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Event notification is invalid."), @ApiResponse(code = 500, message = "Error while testing event notification") })
@NoAuditEvent("only used to test event notifications")
public Response test(@ApiParam(name = "JSON Body") NotificationDto dto) {
checkPermission(RestPermissions.EVENT_NOTIFICATIONS_CREATE);
final ValidationResult validationResult = dto.validate();
if (validationResult.failed()) {
return Response.status(Response.Status.BAD_REQUEST).entity(validationResult).build();
}
resourceHandler.test(dto, getSubject().getPrincipal().toString());
return Response.ok().build();
}
use of org.graylog2.plugin.database.validators.ValidationResult in project graylog2-server by Graylog2.
the class EventNotificationsResource method update.
@PUT
@Path("/{notificationId}")
@ApiOperation("Update existing notification")
@AuditEvent(type = EventsAuditEventTypes.EVENT_NOTIFICATION_UPDATE)
public Response update(@ApiParam(name = "notificationId") @PathParam("notificationId") @NotBlank String notificationId, @ApiParam(name = "JSON Body") NotificationDto dto) {
checkPermission(RestPermissions.EVENT_NOTIFICATIONS_EDIT, notificationId);
dbNotificationService.get(notificationId).orElseThrow(() -> new NotFoundException("Notification " + notificationId + " doesn't exist"));
if (!notificationId.equals(dto.id())) {
throw new BadRequestException("Notification IDs don't match");
}
final ValidationResult validationResult = dto.validate();
if (validationResult.failed()) {
return Response.status(Response.Status.BAD_REQUEST).entity(validationResult).build();
}
return Response.ok().entity(resourceHandler.update(dto)).build();
}
use of org.graylog2.plugin.database.validators.ValidationResult in project graylog2-server by Graylog2.
the class EventDefinitionsResource method create.
@POST
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Create new event definition")
@AuditEvent(type = EventsAuditEventTypes.EVENT_DEFINITION_CREATE)
@RequiresPermissions(RestPermissions.EVENT_DEFINITIONS_CREATE)
public Response create(@ApiParam("schedule") @QueryParam("schedule") @DefaultValue("true") boolean schedule, @ApiParam(name = "JSON Body") EventDefinitionDto dto, @Context UserContext userContext) {
checkEventDefinitionPermissions(dto, "create");
final ValidationResult result = dto.validate();
if (result.failed()) {
return Response.status(Response.Status.BAD_REQUEST).entity(result).build();
}
final EventDefinitionDto entity = schedule ? eventDefinitionHandler.create(dto, Optional.of(userContext.getUser())) : eventDefinitionHandler.createWithoutSchedule(dto, Optional.of(userContext.getUser()));
return Response.ok().entity(entity).build();
}
Aggregations