@GET @Path("/{triggerId}/conditions/{conditionId}") @Produces(APPLICATION_JSON) @ApiOperation(value = "@Deprecated : Use GET /alerts/triggers/{triggerId}/conditions") @ApiResponses( value = { @ApiResponse(code = 200, message = "Success, Condition found"), @ApiResponse(code = 404, message = "No Condition found"), @ApiResponse(code = 500, message = "Internal server error") }) @Deprecated public Response getTriggerCondition( @ApiParam(value = "Trigger definition id to be retrieved", required = true) @PathParam("triggerId") final String triggerId, @PathParam("conditionId") final String conditionId) { try { Trigger trigger = definitions.getTrigger(tenantId, triggerId); if (trigger == null) { return ResponseUtil.notFound("No trigger found for triggerId: " + triggerId); } Condition found = definitions.getCondition(tenantId, conditionId); if (found == null) { return ResponseUtil.notFound("No condition found for conditionId: " + conditionId); } if (!found.getTriggerId().equals(triggerId)) { return ResponseUtil.notFound( "ConditionId: " + conditionId + " does not belong to triggerId: " + triggerId); } return ResponseUtil.ok(found); } catch (Exception e) { log.debug(e.getMessage(), e); return ResponseUtil.internalError(e.getMessage()); } }
@GET @Path("/{triggerId}") @Produces(APPLICATION_JSON) @ApiOperation(value = "Get an existing trigger definition", response = Trigger.class) @ApiResponses( value = { @ApiResponse(code = 200, message = "Success, Trigger found"), @ApiResponse(code = 404, message = "Trigger not found"), @ApiResponse(code = 500, message = "Internal server error") }) public Response getTrigger( @ApiParam(value = "Trigger definition id to be retrieved", required = true) @PathParam("triggerId") final String triggerId) { try { Trigger found = definitions.getTrigger(tenantId, triggerId); if (found != null) { log.debug("Trigger: " + found); return ResponseUtil.ok(found); } else { return ResponseUtil.notFound("triggerId: " + triggerId + " not found"); } } catch (Exception e) { log.debug(e.getMessage(), e); return ResponseUtil.internalError(e.getMessage()); } }
@POST @Path("/groups") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation( value = "Create a new group trigger", response = Trigger.class, notes = "Returns created GroupTrigger") @ApiResponses( value = { @ApiResponse(code = 200, message = "Success, Group Trigger Created"), @ApiResponse(code = 500, message = "Internal server error"), @ApiResponse(code = 400, message = "Bad Request/Invalid Parameters") }) public Response createGroupTrigger( @ApiParam(value = "Trigger definition to be created", name = "groupTrigger", required = true) final Trigger groupTrigger) { try { if (null != groupTrigger) { if (isEmpty(groupTrigger.getId())) { groupTrigger.setId(Trigger.generateId()); } else if (definitions.getTrigger(tenantId, groupTrigger.getId()) != null) { return ResponseUtil.badRequest("Trigger with ID [" + groupTrigger.getId() + "] exists."); } definitions.addGroupTrigger(tenantId, groupTrigger); log.debug("Group Trigger: " + groupTrigger.toString()); return ResponseUtil.ok(groupTrigger); } else { return ResponseUtil.badRequest("Trigger is null"); } } catch (Exception e) { log.debug(e.getMessage(), e); return ResponseUtil.internalError(e.getMessage()); } }
@PUT @Path("/{triggerId}/conditions/{conditionId}") @Produces(APPLICATION_JSON) @ApiOperation( value = "Deprecated : Use PUT /alerts/triggers/{triggerId}/conditions to set the entire " + "condition set in one service.") @ApiResponses( value = { @ApiResponse(code = 200, message = "Success, Condition updated"), @ApiResponse(code = 404, message = "No Condition found"), @ApiResponse(code = 500, message = "Internal server error"), @ApiResponse(code = 400, message = "Bad Request/Invalid Parameters") }) @Deprecated public Response updateCondition( @ApiParam(value = "Trigger definition id to be retrieved", required = true) @PathParam("triggerId") final String triggerId, @PathParam("conditionId") final String conditionId, @ApiParam(value = "Json representation of a condition") String jsonCondition) { try { Trigger trigger = definitions.getTrigger(tenantId, triggerId); if (trigger == null) { return ResponseUtil.notFound("No trigger found for triggerId: " + triggerId); } if (isEmpty(jsonCondition) || !jsonCondition.contains("type")) { return ResponseUtil.badRequest("json condition empty or without type"); } ObjectMapper om = new ObjectMapper(); JsonNode rootNode = om.readTree(jsonCondition); Condition condition = JacksonDeserializer.deserializeCondition(rootNode); if (condition == null) { return ResponseUtil.badRequest("Bad json condition"); } condition.setTriggerId(triggerId); boolean exists = false; if (conditionId.equals(condition.getConditionId())) { exists = (definitions.getCondition(tenantId, condition.getConditionId()) != null); } if (!exists) { return ResponseUtil.notFound("Condition not found for conditionId: " + conditionId); } else { Collection<Condition> conditions = definitions.updateCondition(tenantId, condition); if (log.isDebugEnabled()) { log.debug("Conditions: " + conditions); } return ResponseUtil.ok(conditions); } } catch (Exception e) { log.debug(e.getMessage(), e); return ResponseUtil.internalError(e.getMessage()); } }
@DELETE @Path("/{triggerId}/conditions/{conditionId}") @Produces(APPLICATION_JSON) @ApiOperation( value = "Deprecated : Use PUT /alerts/triggers/{triggerId}/conditions to set the entire " + "condition set in one service.") @ApiResponses( value = { @ApiResponse(code = 200, message = "Success, Condition deleted"), @ApiResponse(code = 404, message = "No Condition found"), @ApiResponse(code = 500, message = "Internal server error"), @ApiResponse(code = 400, message = "Bad Request/Invalid Parameters") }) @Deprecated public Response deleteCondition( @ApiParam(value = "Trigger definition id to be retrieved", required = true) @PathParam("triggerId") final String triggerId, @PathParam("conditionId") final String conditionId) { try { Trigger trigger = definitions.getTrigger(tenantId, triggerId); if (trigger == null) { return ResponseUtil.notFound("No trigger found for triggerId: " + triggerId); } Condition condition = definitions.getCondition(tenantId, conditionId); if (condition == null) { return ResponseUtil.notFound("No condition found for conditionId: " + conditionId); } if (!condition.getTriggerId().equals(triggerId)) { return ResponseUtil.badRequest( "ConditionId: " + conditionId + " does not belong to triggerId: " + triggerId); } Collection<Condition> conditions = definitions.removeCondition(tenantId, conditionId); if (log.isDebugEnabled()) { log.debug("Conditions: " + conditions); } return ResponseUtil.ok(conditions); } catch (Exception e) { log.debug(e.getMessage(), e); return ResponseUtil.internalError(e.getMessage()); } }