<commit_before>/// <reference path="camelPlugin.ts"/>
/// <reference path="endpointChooser.ts"/>

namespace Camel {

  _module.controller("Camel.EndpointController", ["$scope", "$location", "localStorage", "workspace", "jolokia", "jolokiaService", (
      $scope,
      $location: ng.ILocationService,
      localStorage: Storage,
      workspace: Jmx.Workspace,
      jolokia: Jolokia.IJolokia,
      jolokiaService: JVM.JolokiaService) => {

    Camel.initEndpointChooserScope($scope, $location, localStorage, workspace, jolokia);
    $scope.loadEndpointNames();

    $scope.workspace = workspace;
    $scope.message = "";

    $scope.cancel = () => $location.path('/camel/endpoints');

    $scope.createEndpoint = (name) => {
      var jolokia = workspace.jolokia;
      if (jolokia) {
        var mbean = getSelectionCamelContextMBean(workspace);
        if (mbean) {
          $scope.message = name;
          var operation = "createEndpoint(java.lang.String)";
          jolokiaService.execute(mbean, operation, name)
            .then(Core.onSuccess(operationSuccess))
            .catch((error: string) => {
              error = error.replace("org.apache.camel.ResolveEndpointFailedException : ", "")
              Core.notification("danger", error);
            });
        } else {
          Core.notification("danger", "Could not find the CamelContext MBean!");
        }
      }
    };

    $scope.createEndpointFromData = () => {
      if ($scope.selectedComponentName && $scope.endpointPath) {
        var name = $scope.selectedComponentName + "://" + $scope.endpointPath;
        log.debug("Have endpoint data " + JSON.stringify($scope.endpointParameters));

        var params = "";
        angular.forEach($scope.endpointParameters, (value, key) => {
          var prefix = params ? "&" : "";
          params += prefix + key + "=" + value;
        });
        if (params) {
          name += "?" + params;
        }
        // TODO use form data too for URIs parameters...
        $scope.createEndpoint(name);
      }
    };

    $scope.deleteEndpoint = () => {
      var jolokia = workspace.jolokia;
      var selection = workspace.selection;
      var entries = selection.entries;
      if (selection && jolokia && entries) {
        var domain = selection.domain;
        var brokerName = entries["BrokerName"];
        var name = entries["Destination"];
        var isQueue = "Topic" !== entries["Type"];
        if (domain && brokerName) {
          var mbean = "" + domain + ":BrokerName=" + brokerName + ",Type=Broker";
          $scope.message = "Deleting " + (isQueue ? "queue" : "topic") + " " + name;
          var operation = "removeEndpoint(java.lang.String)";
          jolokia.execute(mbean, operation, name, Core.onSuccess(deleteSuccess));
        }
      }
    };

    function operationSuccess(endpointCreated): void {
      $scope.endpointName = "";
      $scope.workspace.operationCounter += 1;
      Core.$apply($scope);

      if (endpointCreated && endpointCreated === true) {
        Core.notification('success', "Creating endpoint " + $scope.message);
      } else {
        Core.notification('danger', "Failed to create endpoint " + $scope.message);
      }
    }

    function deleteSuccess(): void {
      // lets set the selection to the parent
      if (workspace.selection) {
        var parent = Core.pathGet(workspace, ["selection", "parent"]);
        if (parent) {
          $scope.workspace.updateSelectionNode(parent);
        }
      }
      $scope.workspace.operationCounter += 1;
      Core.$apply($scope);
      Core.notification("success", $scope.message);
    }
  }]);<commit_msg>fix: ENTESB-10189 [Hawtio] It is possible to create an endpoint with name made up of most special signs<commit_after>/// <reference path="camelPlugin.ts"/>
/// <reference path="endpointChooser.ts"/>

namespace Camel {

  _module.controller("Camel.EndpointController", ["$scope", "$location", "localStorage", "workspace", "jolokia", "jolokiaService", (
      $scope,
      $location: ng.ILocationService,
      localStorage: Storage,
      workspace: Jmx.Workspace,
      jolokia: Jolokia.IJolokia,
      jolokiaService: JVM.JolokiaService) => {

    Camel.initEndpointChooserScope($scope, $location, localStorage, workspace, jolokia);
    $scope.loadEndpointNames();

    $scope.workspace = workspace;

    $scope.cancel = () => $location.path('/camel/endpoints');

    $scope.createEndpoint = (name) => {
      var jolokia = workspace.jolokia;
      if (jolokia) {
        var mbean = getSelectionCamelContextMBean(workspace);
        if (mbean) {
          var operation = "createEndpoint(java.lang.String)";
          jolokiaService.execute(mbean, operation, name)
            .then(() => operationSuccess())
            .catch((error: string) => {
              error = error.replace("org.apache.camel.ResolveEndpointFailedException : ", "")
              Core.notification("danger", error);
            });
        } else {
          Core.notification("danger", "Could not find the CamelContext MBean!");
        }
      }
    };

    $scope.createEndpointFromData = () => {
      if ($scope.selectedComponentName && $scope.endpointPath) {
        var name = $scope.selectedComponentName + "://" + $scope.endpointPath;
        log.debug("Have endpoint data " + JSON.stringify($scope.endpointParameters));

        var params = "";
        angular.forEach($scope.endpointParameters, (value, key) => {
          var prefix = params ? "&" : "";
          params += prefix + key + "=" + value;
        });
        if (params) {
          name += "?" + params;
        }
        // TODO use form data too for URIs parameters...
        $scope.createEndpoint(name);
      }
    };

    $scope.deleteEndpoint = () => {
      var jolokia = workspace.jolokia;
      var selection = workspace.selection;
      var entries = selection.entries;
      if (selection && jolokia && entries) {
        var domain = selection.domain;
        var brokerName = entries["BrokerName"];
        var name = entries["Destination"];
        if (domain && brokerName) {
          var mbean = "" + domain + ":BrokerName=" + brokerName + ",Type=Broker";
          var operation = "removeEndpoint(java.lang.String)";
          jolokia.execute(mbean, operation, name, Core.onSuccess(deleteSuccess));
        }
      }
    };

    function operationSuccess() {
      $scope.endpointName = "";
      $scope.workspace.operationCounter += 1;
      Core.$apply($scope);
      Core.notification('success', "Creating endpoint", 3000);
    }

    function deleteSuccess(): void {
      // lets set the selection to the parent
      if (workspace.selection) {
        var parent = Core.pathGet(workspace, ["selection", "parent"]);
        if (parent) {
          $scope.workspace.updateSelectionNode(parent);
        }
      }
      $scope.workspace.operationCounter += 1;
      Core.$apply($scope);
      Core.notification("success", "Endpoint deleted");
    }
  }]);
{'fraction_non_alphanumeric': 0.14521215596330275, 'fraction_numerical': 0.0018635321100917432, 'mean_word_length': 2.5273003033367036, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5368237', 'n_tokens_mistral': 2009, 'n_tokens_neox': 1937, 'n_words': 402}