Esempio n. 1
0
 private void send(Action action, boolean detail) {
   Event e = action.getEvent();
   if (e != null) {
     StringBuilder msg = new StringBuilder();
     msg.append(e.getEventType());
     msg.append(" ");
     msg.append(e.getId());
     msg.append(" at ");
     msg.append(new Date(e.getCtime()).toString());
     conn.doPrivmsg(channel, msg.toString());
     if (detail) {
       conn.doPrivmsg(channel, JsonUtil.toJson(e));
     }
   }
 }
 @POST
 @Path("/")
 @Consumes(APPLICATION_JSON)
 @Produces(APPLICATION_JSON)
 @ApiOperation(
     value = "Create a new Event.",
     notes = "Returns created Event.",
     response = Event.class)
 @ApiResponses(
     value = {
       @ApiResponse(code = 200, message = "Success, Event Created."),
       @ApiResponse(code = 500, message = "Internal server error.", response = ApiError.class),
       @ApiResponse(
           code = 400,
           message = "Bad Request/Invalid Parameters.",
           response = ApiError.class)
     })
 public Response createEvent(
     @ApiParam(
             value = "Event to be created. Category and Text fields required,",
             name = "event",
             required = true)
         final Event event) {
   try {
     if (null != event) {
       if (isEmpty(event.getId())) {
         return ResponseUtil.badRequest("Event with id null.");
       }
       if (isEmpty(event.getCategory())) {
         return ResponseUtil.badRequest("Event with category null.");
       }
       event.setTenantId(tenantId);
       if (null != alertsService.getEvent(tenantId, event.getId(), true)) {
         return ResponseUtil.badRequest("Event with ID [" + event.getId() + "] exists.");
       }
       /*
          New events are sent directly to the engine for inference process.
          Input events and new ones generated by the alerts engine are persisted at the end of the process.
       */
       alertsService.addEvents(Collections.singletonList(event));
       if (log.isDebugEnabled()) {
         log.debug("Event: " + event.toString());
       }
       return ResponseUtil.ok(event);
     } else {
       return ResponseUtil.badRequest("Event is null");
     }
   } catch (Exception e) {
     log.debug(e.getMessage(), e);
     if (e.getCause() != null && e.getCause() instanceof IllegalArgumentException) {
       return ResponseUtil.badRequest("Bad arguments: " + e.getMessage());
     }
     return ResponseUtil.internalError(e);
   }
 }