<commit_before>/*
 * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. licenses this file to you 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.wso2.carbon.siddhi.editor.core.util.designview.designgenerator.generators;

import org.wso2.carbon.siddhi.editor.core.util.designview.beans.configs.Edge;
import org.wso2.carbon.siddhi.editor.core.util.designview.beans.configs.SiddhiAppConfig;
import org.wso2.carbon.siddhi.editor.core.util.designview.beans.configs.siddhielements.*;
import org.wso2.carbon.siddhi.editor.core.util.designview.beans.configs.siddhielements.aggregation.AggregationConfig;
import org.wso2.carbon.siddhi.editor.core.util.designview.beans.configs.siddhielements.query.QueryConfig;
import org.wso2.carbon.siddhi.editor.core.util.designview.beans.configs.siddhielements.query.input.QueryInputConfig;
import org.wso2.carbon.siddhi.editor.core.util.designview.beans.configs.siddhielements.query.input.join.JoinConfig;
import org.wso2.carbon.siddhi.editor.core.util.designview.beans.configs.siddhielements.query.input.windowfilterprojection.WindowFilterProjectionConfig;
import org.wso2.carbon.siddhi.editor.core.util.designview.constants.NodeType;
import org.wso2.carbon.siddhi.editor.core.util.designview.utilities.DesignGeneratorHelper;

import java.util.ArrayList;
import java.util.List;

/**
 * Generator to create Edges, that connect Siddhi Elements - considered as Nodes
 */
public class EdgesGenerator {
    private SiddhiAppConfig siddhiAppConfig;

    public EdgesGenerator(SiddhiAppConfig siddhiAppConfig) {
        this.siddhiAppConfig = siddhiAppConfig;
    }

    /**
     * Generates Edges for the elements in the SiddhiAppConfig
     * @return      List of Edges
     */
    public List<Edge> generateEdges() {
        List<Edge> edges = new ArrayList<>();
        for (QueryConfig query : siddhiAppConfig.getWindowFilterProjectionQueryList()) {
            // Edge towards Query element
            edges.add(
                    generateEdge(
                            getElementWithStreamName(
                                    ((WindowFilterProjectionConfig) (query.getQueryInput())).getFrom()).getId(),
                            query.getId()));
            // Edge from Query element
            edges.add(
                    generateEdge(
                            query.getId(),
                            getElementWithStreamName(query.getQueryOutput().getTarget()).getId()));
        }
        for (QueryConfig query : siddhiAppConfig.getJoinQueryList()) {
            // Edge towards Query element (From Left element)
            edges.add(
                    generateEdge(
                            getElementWithStreamName(
                                    ((JoinConfig) (query.getQueryInput())).getLeft().getFrom()).getId(),
                            query.getId()));
            // Edge towards Query element (From Right element)
            edges.add(
                    generateEdge(
                            getElementWithStreamName(
                                    ((JoinConfig) (query.getQueryInput())).getRight().getFrom()).getId(),
                            query.getId()));
            // Edge from Query element
            edges.add(generateEdge(query.getId(), query.getQueryOutput().getTarget()));
        }
        // TODO: 3/29/18 implement other edges
        return edges;
    }

    /**
     * Returns an Edge, that represents the connection between given parent and child, denoted by their Ids<commit_msg>Fix edge from query element generation in EdgesGenerator<commit_after>/*
 * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. licenses this file to you 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.wso2.carbon.siddhi.editor.core.util.designview.designgenerator.generators;

import org.wso2.carbon.siddhi.editor.core.util.designview.beans.configs.Edge;
import org.wso2.carbon.siddhi.editor.core.util.designview.beans.configs.SiddhiAppConfig;
import org.wso2.carbon.siddhi.editor.core.util.designview.beans.configs.siddhielements.*;
import org.wso2.carbon.siddhi.editor.core.util.designview.beans.configs.siddhielements.aggregation.AggregationConfig;
import org.wso2.carbon.siddhi.editor.core.util.designview.beans.configs.siddhielements.query.QueryConfig;
import org.wso2.carbon.siddhi.editor.core.util.designview.beans.configs.siddhielements.query.input.QueryInputConfig;
import org.wso2.carbon.siddhi.editor.core.util.designview.beans.configs.siddhielements.query.input.join.JoinConfig;
import org.wso2.carbon.siddhi.editor.core.util.designview.beans.configs.siddhielements.query.input.windowfilterprojection.WindowFilterProjectionConfig;
import org.wso2.carbon.siddhi.editor.core.util.designview.constants.NodeType;
import org.wso2.carbon.siddhi.editor.core.util.designview.utilities.DesignGeneratorHelper;

import java.util.ArrayList;
import java.util.List;

/**
 * Generator to create Edges, that connect Siddhi Elements - considered as Nodes
 */
public class EdgesGenerator {
    private SiddhiAppConfig siddhiAppConfig;

    public EdgesGenerator(SiddhiAppConfig siddhiAppConfig) {
        this.siddhiAppConfig = siddhiAppConfig;
    }

    /**
     * Generates Edges for the elements in the SiddhiAppConfig
     * @return      List of Edges
     */
    public List<Edge> generateEdges() {
        List<Edge> edges = new ArrayList<>();
        for (QueryConfig query : siddhiAppConfig.getWindowFilterProjectionQueryList()) {
            // Edge towards Query element
            edges.add(
                    generateEdge(
                            getElementWithStreamName(
                                    ((WindowFilterProjectionConfig) (query.getQueryInput())).getFrom()).getId(),
                            query.getId()));
            // Edge from Query element
            edges.add(
                    generateEdge(
                            query.getId(),
                            getElementWithStreamName(query.getQueryOutput().getTarget()).getId()));
        }
        for (QueryConfig query : siddhiAppConfig.getJoinQueryList()) {
            // Edge towards Query element (From Left element)
            edges.add(
                    generateEdge(
                            getElementWithStreamName(
                                    ((JoinConfig) (query.getQueryInput())).getLeft().getFrom()).getId(),
                            query.getId()));
            // Edge towards Query element (From Right element)
            edges.add(
                    generateEdge(
                            getElementWithStreamName(
                                    ((JoinConfig) (query.getQueryInput())).getRight().getFrom()).getId(),
                            query.getId()));
            // Edge from Query element
            edges.add(
                    generateEdge(
                            query.getId(),
                            getElementWithStreamName(query.getQueryOutput().getTarget()).getId()));
        }
        // TODO: 3/29/18 implement other edges
        return edges;
    }

    /**
     * Returns an Edge, that represents the connection between given parent and child, denoted by their Ids
{'fraction_non_alphanumeric': 0.09863245794505628, 'fraction_numerical': 0.006535156722739925, 'mean_word_length': 2.430469074304691, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2776739', 'n_tokens_mistral': 2281, 'n_tokens_neox': 2219, 'n_words': 492}