static {
    Map<String, String> context = new HashMap<>();
    context.put("resourceType", "URL");
    context.put("resourceName", "http://www.jboss.org");

    String triggerId = "jboss-url-response-time-trigger";
    String triggerDescription = "Response Time for http://www.jboss.org";
    String dataId = "jboss-url-response-time-data-id";

    trigger = new Trigger(TEST_TENANT, triggerId, triggerDescription, context);

    firingCondition =
        new ThresholdCondition(
            trigger.getId(), Mode.FIRING, dataId, ThresholdCondition.Operator.GT, 1000d);
    firingCondition.setTenantId(TEST_TENANT);
    firingCondition.getContext().put("description", "Response Time");
    firingCondition.getContext().put("unit", "ms");

    autoResolveCondition =
        new ThresholdCondition(
            trigger.getId(), Mode.AUTORESOLVE, dataId, ThresholdCondition.Operator.LTE, 1000d);
    autoResolveCondition.setTenantId(TEST_TENANT);
    autoResolveCondition.getContext().put("description", "Response Time");
    autoResolveCondition.getContext().put("unit", "ms");

    firingDampening = Dampening.forStrictTimeout(trigger.getId(), Mode.FIRING, 10000);
    firingDampening.setTenantId(TEST_TENANT);
  }
  @POST
  @Path("/groups/members")
  @Consumes(APPLICATION_JSON)
  @Produces(APPLICATION_JSON)
  @ApiOperation(
      value = "Create a new member trigger for a parent trigger.",
      response = Trigger.class,
      notes = "Returns Member Trigger created if operation finished correctly")
  @ApiResponses(
      value = {
        @ApiResponse(code = 200, message = "Success, Member Trigger Created"),
        @ApiResponse(code = 500, message = "Internal server error"),
        @ApiResponse(code = 404, message = "Group trigger not found."),
        @ApiResponse(code = 400, message = "Bad Request/Invalid Parameters")
      })
  public Response createGroupMember(
      @ApiParam(
              value = "Group member trigger to be created",
              name = "groupMember",
              required = true) //
          final GroupMemberInfo groupMember) {
    try {
      if (null == groupMember) {
        return ResponseUtil.badRequest("MemberTrigger is null");
      }
      String groupId = groupMember.getGroupId();
      String memberName = groupMember.getMemberName();
      if (isEmpty(groupId)) {
        return ResponseUtil.badRequest("MemberTrigger groupId is null");
      }
      if (isEmpty(memberName)) {
        return ResponseUtil.badRequest("MemberTrigger memberName is null");
      }
      Trigger child =
          definitions.addMemberTrigger(
              tenantId,
              groupId,
              groupMember.getMemberId(),
              memberName,
              groupMember.getMemberContext(),
              groupMember.getDataIdMap());
      if (log.isDebugEnabled()) {
        log.debug("Child Trigger: " + child.toString());
      }
      return ResponseUtil.ok(child);

    } catch (NotFoundException e) {
      log.debug(e.getMessage(), e);
      return ResponseUtil.notFound(e.getMessage());
    } catch (Exception e) {
      log.debug(e.getMessage(), e);
      return ResponseUtil.internalError(e.getMessage());
    }
  }
  public static Alert getOpenAlert() {

    List<Set<ConditionEval>> satisfyingEvals = new ArrayList<>();

    Data rtBadData1 =
        Data.forNumeric(firingCondition.getDataId(), System.currentTimeMillis(), 1900d);
    ThresholdConditionEval eval1 = new ThresholdConditionEval(firingCondition, rtBadData1);

    Set<ConditionEval> evalSet1 = new HashSet<>();
    evalSet1.add(eval1);
    satisfyingEvals.add(evalSet1);

    // 5 seconds later
    Data rtBadData2 =
        Data.forNumeric(firingCondition.getDataId(), System.currentTimeMillis() + 5000, 1800d);
    ThresholdConditionEval eval2 = new ThresholdConditionEval(firingCondition, rtBadData2);

    Set<ConditionEval> evalSet2 = new HashSet<>();
    evalSet2.add(eval2);
    satisfyingEvals.add(evalSet2);

    Alert openAlert = new Alert(trigger.getTenantId(), trigger, firingDampening, satisfyingEvals);

    return openAlert;
  }
  @PUT
  @Path("/groups/{groupId}")
  @Consumes(APPLICATION_JSON)
  @ApiOperation(value = "Update an existing group trigger definition and its member definitions")
  @ApiResponses(
      value = {
        @ApiResponse(code = 200, message = "Success, Group Trigger updated"),
        @ApiResponse(code = 500, message = "Internal server error"),
        @ApiResponse(code = 404, message = "Trigger doesn't exist/Invalid Parameters")
      })
  public Response updateGroupTrigger(
      @ApiParam(value = "Group Trigger id to be updated", required = true) @PathParam("groupId")
          final String groupId,
      @ApiParam(value = "Updated group trigger definition", name = "trigger", required = true)
          final Trigger groupTrigger) {
    try {
      if (groupTrigger != null && !isEmpty(groupId)) {
        groupTrigger.setId(groupId);
      }
      definitions.updateGroupTrigger(tenantId, groupTrigger);
      if (log.isDebugEnabled()) {
        log.debug("Trigger: " + groupTrigger);
      }
      return ResponseUtil.ok();

    } catch (NotFoundException e) {
      return ResponseUtil.notFound("Trigger " + groupId + " doesn't exist for update");

    } 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());
   }
 }