<commit_before>/*
 * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates
 * and other contributors as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.hawkular.alerts.api.model.condition;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

import org.hawkular.alerts.api.model.event.Event;
import org.hawkular.alerts.api.model.trigger.Mode;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * An <code>EventCondition</code> is used for condition evaluations over Event data using expressions.
 *
 * Expression is a comma separated list of the following 3 tokens structure:
 *
 * <event.field> <operator> <constant> [,<event.field> <operator> <constant>]*
 *
 * - <event.field> represent a fixed field of event structure or a key of tags.
 *   Supported fields are the following:
 *      - tenantId
 *      - id
 *      - ctime
 *      - text
 *      - category
 *      - tags.<key>
 *
 * - <operator> is a string representing a string/numeric operator, supported ones are:
 *   "==" equals
 *   "!=" not equals
 *   "starts" starts with String operator
 *   "ends" ends with String operator
 *   "contains" contains String operator
 *   "match" match String operator
 *   "<" less than
 *   "<=" less or equals than
 *   ">" greater than
 *   ">=" greater or equals than
 *   "==" equals
 *
 * - <constant> is a string that might be interpreted as a number if is not closed with single quotes or a string
 * constant if it is closed with single quotes
 * i.e. 23, 'test'
 *
 * A constant string can contain special character comma but escaped with backslash.
 * i.e. '\,test', 'test\,'
 *
 * So, putting everything together, a valid expression might look like:
 * event.id start 'IDXYZ', event.tag.category == 'Server', event.tag.from end '.com'
 *
 * A non valid expression will return false.
 *
 * @author <NAME>
 * @author <NAME>
 */
@ApiModel(description = "An EventCondition is used for condition evaluations over Event data using expressions. + \n" +
        " + \n" +
        "Expression is a comma separated list of the following 3 tokens structure: + \n" +
        " + \n" +
        "<event.field> <operator> <constant> [,<event.field> <operator> <constant>]* + \n" +
        " + \n" +
        "<event.field> represent a fixed field of event structure or a key of tags. + \n" +
        "Supported fields are the following: + \n" +
        "- tenantId + \n" +
        "- id + \n" +
        "- ctime + \n" +
        "- text + \n" +
        "- category + \n" +
        "- tags.<key> + \n" +
        " + \n" +
        "<operator> is a string representing a string/numeric operator, supported ones are: + \n" +
        "\"==\" equals + \n" +
        "\"!=\" not equals + \n" +
        "\"starts\" starts with String operator + \n" +
        "\"ends\" ends with String operator + \n" +
        "\"contains\" contains String operator + \n" +
        "\"match\" match String operator + \n" +
        "\"<\" less than + \n" +
        "\"<=\" less or equals than + \n" +
        "\">\" greater than + \n" +
        "\">=\" greater or equals than + \n" +
        "\"==\" equals + \n" +
        " + \n" +
        "<constant> is a string that might be interpreted as a number if is not closed with single quotes or a " +
        "string constant if it is closed with single quotes + \n" +
        "i.e. 23, 'test' + \n" +
        " + \n" +
        "A constant string can contain special character comma but escaped with backslash. + \n" +
        "i.e '\\,test', 'test\\,' + \n" +
        " + \n" +
        "So, putting everything together, a valid expression might look like: + \n" +
        "event.id starts 'IDXYZ', event.tag.category == 'Server', event.tag.from end '.com' + \n" +
        " + \n" +
        "A non valid expression will return false. + \n")
public class EventCondition extends Condition {

    private static final long serialVersionUID = 1L;

    @JsonInclude
    private String dataId;

    @ApiModelProperty(value = "Event expression used for this condition.",
            position = 0,
            required = true)
    @JsonInclude(Include.NON_NULL)
    private String expression;

    public EventCondition() {
        this("", "", Mode.FIRING, 1, 1, null, null);
    }

    public EventCondition(String tenantId, String triggerId, String dataId, String expression) {<commit_msg>HWKALERTS-258 Fix EventCondition doco<commit_after>/*
 * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates
 * and other contributors as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.hawkular.alerts.api.model.condition;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

import org.hawkular.alerts.api.model.event.Event;
import org.hawkular.alerts.api.model.trigger.Mode;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * An <code>EventCondition</code> is used for condition evaluations over Event data using expressions.
 * <pre>
 * Expression is a comma separated list of the following 3-token structure:
 *
 * {@code <eventField> <operator> <constant> [,<eventField> <operator> <constant>]* }
 *
 * {@code <eventField>} represents a fixed field of the Event structure, or a tag key.
 * Supported eventFields:
 *   - tenantId (String)
 *   - id (String)
 *   - ctime (Numeric time since epoch in milliseconds)
 *   - text (String)
 *   - category (String)
 *   - tags.<key> (String)
 *
 * {@code <operator>} is a string representing a string/numeric operator.
 * Supported operators:
 *   "starts" starts with String
 *   "ends" ends with String
 *   "contains" contains String
 *   "match" regex match String
 *   "==" equals
 *   "!=" not equals
 *   "<" less than
 *   "<=" less than or equals
 *   ">" greater than
 *   ">=" greater than or equals
 *
 * A String {@code <constant>} must be enclosed in single-quotes. Special characters must be
 * escaped with a backslash. Examples: 'test', '\,test\\'
 *
 * A Numeric {@code <constant>} must be a valid number. Examples: 0, 23, 90.5, -10
 *
 * Example of a valid expression:
 * id starts 'IDXYZ', category == 'Server', tags.from ends '.com'
 *
 * An invalid expression will always return false.
 * </pre>
 * @author <NAME>
 * @author <NAME>
 */
@ApiModel(description = "An EventCondition is used for condition evaluations over Event data using expressions. + \n" +
        " + \n" +
        "Expression is a comma separated list of the following 3-token structure: + \n" +
        " + \n" +
        "<eventField> <operator> <constant> [,<eventField> <operator> <constant>]* + \n" +
        " + \n" +
        "<eventField> represents a fixed field of the Event structure, or a tag key. + \n" +
        "Supported eventFields: + \n" +
        "- tenantId (String) + \n" +
        "- id (String) + \n" +
        "- ctime (Numeric time since epoch in milliseconds) + \n" +
        "- text (String) + \n" +
        "- category (String) + \n" +
        "- tags.<key> (String) + \n" +
        " + \n" +
        "<operator> is a string representing a string/numeric operator. \n" +
        "Supported operators: + \n" +
        "\"starts\" starts with String + \n" +
        "\"ends\" ends with String + \n" +
        "\"contains\" contains String + \n" +
        "\"match\" regex match String + \n" +
        "\"==\" equals + \n" +
        "\"!=\" not equals + \n" +
        "\"<\" less than + \n" +
        "\"<=\" less than or equals + \n" +
        "\">\" greater than + \n" +
        "\">=\" greater than or equals + \n" +
        " + \n" +
        "A String <constant> must be enclosed in single-quotes. Special characters must be + \n" +
        "escaped with a backslash. Examples: 'test', '\\,test\\\\' \n" +
        " + \n" +
        "A Numeric <constant> must be a valid number. Examples: 0, 23, 90.5, -10 \n" +
        " + \n" +
        "Example of a valid expression: + \n" +
        "id starts 'IDXYZ', category == 'Server', tags.from ends '.com' + \n" +
        " + \n" +
        "An invalid expression will always return false. + \n")
public class EventCondition extends Condition {

    private static final long serialVersionUID = 1L;

    @JsonInclude
    private String dataId;

    @ApiModelProperty(value = "Event expression used for this condition.",
            position = 0,
            required = true)
    @JsonInclude(Include.NON_NULL)
    private String expression;

    public EventCondition() {
        this("", "", Mode.FIRING, 1, 1, null, null);
    }

    public EventCondition(String tenantId, String triggerId, String dataId, String expression) {
{'fraction_non_alphanumeric': 0.1322804546826275, 'fraction_numerical': 0.005935016597927774, 'mean_word_length': 2.637760702524698, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1895913', 'n_tokens_mistral': 2960, 'n_tokens_neox': 2881, 'n_words': 1069}