<commit_before>/**
 * Copyright (c) 2016, 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.
 */

var Processors = (function (processors) {

    var flowControllers = processors.flowControllers || {};

    //Define manipulator mediators
    var invokeMediator = {
        id: "InvokeMediator",
        title: "Invoke Mediator",
        icon: "images/SwitchMediator.gif",
        colour : "#334455",
        type : "Custom",
        dragCursorOffset : { left: 10, top: -5 },
        createCloneCallback : function(view){
            function cloneCallBack() {
                var svgRoot = view.createSVGForDraggable();
                var rect = svgRoot.draw.basicRect(0, 0, 20, 50, 0, 0).attr("fill-opacity", 1);
                return svgRoot.getDraggableRoot();
            }
            return cloneCallBack;
        },
        init: function (view) {
            if (!_.isUndefined(view.viewRoot)) {
                var center = view.model.get('center');
                var rectangle = view.viewRoot.draw.centeredRect(center, 20, 50, 1, 1, view.viewRoot, "#334455");
                rectangle.on('mouseover', function () {
                    diagram.selectedNode = view.model;
                    rectangle.style("fill", "green").style("fill-opacity", 1)
                        .style("cursor", 'url(images/BlackHandwriting.cur), pointer');
                }).on('mouseout', function () {
                    if(_.isEqual(diagram.selectedNode, view.model)){
                        diagram.destinationLifeLine = null;
                        diagram.destinationProcessor = view.model;
                        diagram.selectedNode = null;
                    }
                    rectangle.style("fill", "#334455").style("fill-opacity", 1);
                }).on('mousedown', function () {
                    d3.event.preventDefault();
                    d3.event.stopPropagation();
                    var startPoint = center.clone().move(0, -20);
                    var newStartPointFn = function (endX, endY) {
                        if (startPoint.x() > endX) {
                            return {x: startPoint.x() - 10, y: startPoint.y()};
                        } else {
                            return {x: startPoint.x() + 10, y: startPoint.y()};
                        }
                    };
                    diagram.trigger("messageDrawStart", view.model, startPoint, newStartPointFn);
                });
                Object.getPrototypeOf(view.viewRoot).rect = rectangle;

                function resyncPointCordinates(messagePoint){
                    if (_.isEqual(messagePoint.direction(), "inbound")) {
                        var sPX = messagePoint.message().source().x();
                        messagePoint.y(center.y() + 20);
                        messagePoint.message().source().forceY = true;
                        messagePoint.message().source().y(messagePoint.y());
                        view.modelAttr("children").add(messagePoint);
                    } else if (_.isEqual(messagePoint.direction(), "outbound")) {
                        var sPX = messagePoint.message().destination().x();
                        messagePoint.y(center.y() - 20);
                        var dest = messagePoint.message().destination();
                        if(dest.parent()){
                            dest.x(dest.parent().get("centerPoint").x());
                        }
                        dest.forceY = true;
                        dest.y(messagePoint.y());
                        view.modelAttr("children").add(messagePoint);
                    }
                    if (center.x() > sPX) {
                        messagePoint.x(center.x() - 10);
                    } else {
                        messagePoint.x(center.x() + 10);
                    }
                }

                //override addChild
                view.model.addChild = function (messageLinkPoint, opts) {
                    // Set the parent of the message link point
                    messageLinkPoint.parent(view.model);
                    resyncPointCordinates(messageLinkPoint);
                };

                for(var index = 0; index < view.modelAttr("children").length; index++){
                    var point = view.modelAttr("children").at(index);
                    resyncPointCordinates(point);
                    if(point && point instanceof SequenceD.Models.MessagePoint && _.isEqual(point.direction(), "outbound")) {
                        var linkView = new SequenceD.Views.MessageLink({
                            model: point.message(),
                            options: {class: "message"}
                        });
                        linkView.render("#diagramWrapper", "messages");
                    }
                }
            }

        },
        parameters: [],

        getMySubTree: function (model) {
            var messageLinks = model.get('children').models;
            var endpoint = undefined;
            messageLinks.forEach(function (child) {
                if (_.isEqual(child.get('direction'), "inbound")) {
                    endpoint = child.get('parent').get('title');
                    // When we define the properties, need to extract the endpoint from the property
                    definedConstants["HTTPEP"] = {name: endpoint, value: "https://www.google.lk"};
                } else {
                    endpoint = "anonymous";
                }
            });
            return new TreeNode("InvokeMediator", "InvokeMediator", ("invoke(" + endpoint + ")"), ";");
        }
    };

    // Add defined mediators to manipulators<commit_msg>Refine source gen, get the parent of inbound connection in invoke mediator<commit_after>/**
 * Copyright (c) 2016, 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.
 */

var Processors = (function (processors) {

    var flowControllers = processors.flowControllers || {};

    //Define manipulator mediators
    var invokeMediator = {
        id: "InvokeMediator",
        title: "Invoke Mediator",
        icon: "images/SwitchMediator.gif",
        colour : "#334455",
        type : "Custom",
        dragCursorOffset : { left: 10, top: -5 },
        createCloneCallback : function(view){
            function cloneCallBack() {
                var svgRoot = view.createSVGForDraggable();
                var rect = svgRoot.draw.basicRect(0, 0, 20, 50, 0, 0).attr("fill-opacity", 1);
                return svgRoot.getDraggableRoot();
            }
            return cloneCallBack;
        },
        init: function (view) {
            if (!_.isUndefined(view.viewRoot)) {
                var center = view.model.get('center');
                var rectangle = view.viewRoot.draw.centeredRect(center, 20, 50, 1, 1, view.viewRoot, "#334455");
                rectangle.on('mouseover', function () {
                    diagram.selectedNode = view.model;
                    rectangle.style("fill", "green").style("fill-opacity", 1)
                        .style("cursor", 'url(images/BlackHandwriting.cur), pointer');
                }).on('mouseout', function () {
                    if(_.isEqual(diagram.selectedNode, view.model)){
                        diagram.destinationLifeLine = null;
                        diagram.destinationProcessor = view.model;
                        diagram.selectedNode = null;
                    }
                    rectangle.style("fill", "#334455").style("fill-opacity", 1);
                }).on('mousedown', function () {
                    d3.event.preventDefault();
                    d3.event.stopPropagation();
                    var startPoint = center.clone().move(0, -20);
                    var newStartPointFn = function (endX, endY) {
                        if (startPoint.x() > endX) {
                            return {x: startPoint.x() - 10, y: startPoint.y()};
                        } else {
                            return {x: startPoint.x() + 10, y: startPoint.y()};
                        }
                    };
                    diagram.trigger("messageDrawStart", view.model, startPoint, newStartPointFn);
                });
                Object.getPrototypeOf(view.viewRoot).rect = rectangle;

                function resyncPointCordinates(messagePoint){
                    if (_.isEqual(messagePoint.direction(), "inbound")) {
                        var sPX = messagePoint.message().source().x();
                        messagePoint.y(center.y() + 20);
                        messagePoint.message().source().forceY = true;
                        messagePoint.message().source().y(messagePoint.y());
                        view.modelAttr("children").add(messagePoint);
                    } else if (_.isEqual(messagePoint.direction(), "outbound")) {
                        var sPX = messagePoint.message().destination().x();
                        messagePoint.y(center.y() - 20);
                        var dest = messagePoint.message().destination();
                        if(dest.parent()){
                            dest.x(dest.parent().get("centerPoint").x());
                        }
                        dest.forceY = true;
                        dest.y(messagePoint.y());
                        view.modelAttr("children").add(messagePoint);
                    }
                    if (center.x() > sPX) {
                        messagePoint.x(center.x() - 10);
                    } else {
                        messagePoint.x(center.x() + 10);
                    }
                }

                //override addChild
                view.model.addChild = function (messageLinkPoint, opts) {
                    // Set the parent of the message link point
                    //messageLinkPoint.parent(view.model);
                    resyncPointCordinates(messageLinkPoint);
                };

                for(var index = 0; index < view.modelAttr("children").length; index++){
                    var point = view.modelAttr("children").at(index);
                    resyncPointCordinates(point);
                    if(point && point instanceof SequenceD.Models.MessagePoint && _.isEqual(point.direction(), "outbound")) {
                        var linkView = new SequenceD.Views.MessageLink({
                            model: point.message(),
                            options: {class: "message"}
                        });
                        linkView.render("#diagramWrapper", "messages");
                    }
                }
            }

        },
        parameters: [],

        getMySubTree: function (model) {
            var messageLinks = model.get('children').models;
            var endpoint = undefined;
            messageLinks.forEach(function (child) {
                if (_.isEqual(child.get('direction'), "inbound")) {
                    endpoint = child.get('message').get('source').get('parent').get('title');
                    // When we define the properties, need to extract the endpoint from the property
                    definedConstants["HTTPEP"] = {name: endpoint, value: "https://www.google.lk"};
                } else {
                    endpoint = "anonymous";
                }
            });
            return new TreeNode("InvokeMediator", "InvokeMediator", ("invoke(" + endpoint + ")"), ";");
        }
    };

    // Add defined mediators to manipulators
{'fraction_non_alphanumeric': 0.11944444444444445, 'fraction_numerical': 0.010634920634920634, 'mean_word_length': 1.4952475247524752, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, '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': '5330324', 'n_tokens_mistral': 3229, 'n_tokens_neox': 2963, 'n_words': 708}