public static Operator fromDbValue(String s) { return Stream.of(values()) .filter(o -> o.getDbValue().equals(s)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Unsupported operator db value: " + s)); }
public static boolean isValid(String s) { return Stream.of(values()) .anyMatch(o -> o.getDbValue().equals(s)); }
private static JsonObject toJson(EvaluatedCondition evaluatedCondition) { Condition condition = evaluatedCondition.getCondition(); JsonObject result = new JsonObject(); result.addProperty("metric", condition.getMetricKey()); result.addProperty("op", condition.getOperator().getDbValue()); if (condition.isOnLeakPeriod()) { result.addProperty("period", 1); } result.addProperty("error", condition.getErrorThreshold()); evaluatedCondition.getValue().ifPresent(v -> result.addProperty("actual", v)); result.addProperty(FIELD_LEVEL, evaluatedCondition.getStatus().name()); return result; } }
private static JsonObject toJson(EvaluatedCondition evaluatedCondition) { Condition condition = evaluatedCondition.getCondition(); JsonObject result = new JsonObject(); result.addProperty("metric", condition.getMetricKey()); result.addProperty("op", condition.getOperator().getDbValue()); if (condition.isOnLeakPeriod()) { result.addProperty("period", 1); } condition.getWarningThreshold().ifPresent(t -> result.addProperty("warning", t)); condition.getErrorThreshold().ifPresent(t -> result.addProperty("error", t)); evaluatedCondition.getValue().ifPresent(v -> result.addProperty("actual", v)); result.addProperty(FIELD_LEVEL, evaluatedCondition.getStatus().name()); return result; } }
public static Operator fromDbValue(String s) { return Stream.of(values()) .filter(o -> o.getDbValue().equals(s)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Unsupported operator db value: " + s)); } }
static void addConditionParams(NewAction action) { action .createParam(PARAM_METRIC) .setDescription("Condition metric.<br/>" + " Only metric of the following types are allowed:" + "<ul>" + "<li>INT</li>" + "<li>MILLISEC</li>" + "<li>RATING</li>" + "<li>WORK_DUR</li>" + "<li>FLOAT</li>" + "<li>PERCENT</li>" + "<li>LEVEL</li>" + "") .setRequired(true) .setExampleValue("blocker_violations"); action.createParam(PARAM_OPERATOR) .setDescription("Condition operator:<br/>" + "<ul>" + "<li>LT = is lower than</li>" + "<li>GT = is greater than</li>" + "</ui>") .setExampleValue(Condition.Operator.GREATER_THAN.getDbValue()) .setPossibleValues(getPossibleOperators()); action.createParam(PARAM_ERROR) .setMaximumLength(CONDITION_MAX_LENGTH) .setDescription("Condition error threshold") .setRequired(true) .setExampleValue("10"); }