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/{groupId}/dampenings")
 @Consumes(APPLICATION_JSON)
 @Produces(APPLICATION_JSON)
 @ApiOperation(
     value = "Create a new group dampening",
     notes = "Returns Dampening created if operation finishes correctly")
 @ApiResponses(
     value = {
       @ApiResponse(code = 200, message = "Success, Dampening created"),
       @ApiResponse(code = 500, message = "Internal server error"),
       @ApiResponse(code = 400, message = "Bad Request/Invalid Parameters")
     })
 public Response createGroupDampening(
     @ApiParam(value = "Group Trigger definition id attached to dampening", required = true) //
         @PathParam("groupId") //
         final String groupId,
     @ApiParam(value = "Dampening definition to be created", required = true) //
         final Dampening dampening) {
   try {
     dampening.setTriggerId(groupId);
     boolean exists = (definitions.getDampening(tenantId, dampening.getDampeningId()) != null);
     if (!exists) {
       // make sure we have the best chance of clean data..
       Dampening d = getCleanDampening(dampening);
       definitions.addGroupDampening(tenantId, d);
       if (log.isDebugEnabled()) {
         log.debug("Dampening: " + d);
       }
       return ResponseUtil.ok(d);
     } else {
       return ResponseUtil.badRequest(
           "Existing dampening for dampeningId: " + dampening.getDampeningId());
     }
   } catch (Exception e) {
     log.debug(e.getMessage(), e);
     return ResponseUtil.internalError(e.getMessage());
   }
 }
  private Dampening getCleanDampening(Dampening dampening) throws Exception {
    switch (dampening.getType()) {
      case STRICT:
        return Dampening.forStrict(
            dampening.getTriggerId(), dampening.getTriggerMode(), dampening.getEvalTrueSetting());

      case STRICT_TIME:
        return Dampening.forStrictTime(
            dampening.getTriggerId(), dampening.getTriggerMode(), dampening.getEvalTimeSetting());

      case STRICT_TIMEOUT:
        return Dampening.forStrictTimeout(
            dampening.getTriggerId(), dampening.getTriggerMode(), dampening.getEvalTimeSetting());
      case RELAXED_COUNT:
        return Dampening.forRelaxedCount(
            dampening.getTriggerId(),
            dampening.getTriggerMode(),
            dampening.getEvalTrueSetting(),
            dampening.getEvalTotalSetting());
      case RELAXED_TIME:
        return Dampening.forRelaxedTime(
            dampening.getTriggerId(),
            dampening.getTriggerMode(),
            dampening.getEvalTrueSetting(),
            dampening.getEvalTimeSetting());

      default:
        throw new Exception("Unhandled Dampening Type: " + dampening.toString());
    }
  }