<commit_before>/**
 * @module Osgi
 */
module Osgi {

  export function BundleController($scope, $location, workspace:Workspace, $routeParams, jolokia) {
    $scope.bundleId = $routeParams.bundleId;

    updateTableContents();

    $scope.showValue = (key) => {
      switch (key) {
        case "Bundle-Name":
        case "Bundle-SymbolicName":
        case "Bundle-Version":
        case "Export-Package":
        case "Import-Package":
          return false;
        default:
          return true;
      }
    };

    $scope.executeLoadClass = (clazz) => {
      var mbean = getHawtioOSGiToolsMBean(workspace);
      if (mbean) {
        jolokia.request(
                {type: 'exec', mbean: mbean, operation: 'getLoadClassOrigin', arguments: [$scope.bundleId, clazz]},
                {
                  success: function (response) {
                    var divEl = document.getElementById("loadClassResult");
                    var resultBundle = response.value;
                    var style;
                    var resultTxt;
                    if (resultBundle === -1) {
                      style = "";
                      resultTxt = "Class can not be loaded from this bundle.";
                    } else {
                      style = "alert-success";
                      resultTxt = "Class is served from Bundle " + bundleLinks(workspace, resultBundle);
                    }
                    divEl.innerHTML +=
                            "<div class='alert " + style + "'>" +
                                    "<button type='button' class='close' data-dismiss='alert'>&times;</button>" +
                                    "Loading class <strong>" + clazz + "</strong> in Bundle " + $scope.bundleId + ". " + resultTxt + "</div>";
                  },
                  error: function (response) {
                    inspectReportError(response);
                  }
                });
      } else {
        inspectReportNoMBeanFound();
      }
    };

    $scope.executeFindResource = (resource) => {
      var mbean = getHawtioOSGiToolsMBean(workspace);
      if (mbean) {
        jolokia.request(
                {type: 'exec', mbean: mbean, operation: 'getResourceURL', arguments: [$scope.bundleId, resource]},
                {
                  success: function (response) {
                    var divEl = document.getElementById("loadClassResult");
                    var resultURL = response.value;
                    var style;
                    var resultTxt;
                    if (resultURL === null) {
                      style = "";
                      resultTxt = "Resource can not be found from this bundle.";
                    } else {
                      style = "alert-success";
                      resultTxt = "Resource is available from: " + resultURL;
                    }
                    divEl.innerHTML +=
                            "<div class='alert " + style + "'>" +
                                    "<button type='button' class='close' data-dismiss='alert'>&times;</button>" +
                                    "Finding resource <strong>" + resource + "</strong> in Bundle " + $scope.bundleId + ". " + resultTxt + "</div>";
                  },
                  error: function (response) {
                    inspectReportError(response);
                  }
                }
        )
      } else {
        inspectReportNoMBeanFound();
      }
    };


    $scope.mavenLink = (row) => {
      if (angular.isObject(row)) {
        return Maven.mavenLink(row.Location);
      }
      // TODO try using the LogQuery mbean to find the mvn coords for a bundle id?
      return "";
    };

    $scope.startBundle = (bundleId) => {
      jolokia.request([
        {type: 'exec', mbean: getSelectionFrameworkMBean(workspace), operation: 'startBundle', arguments: [bundleId]}
      ],
              onSuccess(updateTableContents));
    };

    $scope.stopBundle = (bundleId) => {
      jolokia.request([
        {type: 'exec', mbean: getSelectionFrameworkMBean(workspace), operation: 'stopBundle', arguments: [bundleId]}
      ],
              onSuccess(updateTableContents));
    };

    $scope.updatehBundle = (bundleId) => {
      jolokia.request([
        {type: 'exec', mbean: getSelectionFrameworkMBean(workspace), operation: 'updateBundle', arguments: [bundleId]}
      ],
              onSuccess(updateTableContents));
    };

    $scope.refreshBundle = (bundleId) => {
      jolokia.request([
        {type: 'exec', mbean: getSelectionFrameworkMBean(workspace), operation: 'refreshBundle', arguments: [bundleId]}
      ],
              onSuccess(updateTableContents));
    };

    $scope.uninstallBundle = (bundleId) => {
      jolokia.request([
        {type: 'exec', mbean: getSelectionFrameworkMBean(workspace), operation: 'uninstallBundle', arguments: [bundleId]}
      ],
              onSuccess($location.path("/osgi/bundle-list")));
    };

    function inspectReportNoMBeanFound() {
      var divEl = document.getElementById("loadClassResult");
      divEl.innerHTML +=
              "<div class='alert alert-error'>" +
                      "<button type='button' class='close' data-dismiss='alert'>&times;</button>" +
                      "The hawtio.OSGiTools MBean is not available. Please contact technical support." +
                      "</div>";
    }

    function inspectReportError(response) {
      var divEl = document.getElementById("loadClassResult");
      divEl.innerHTML +=
              "<div class='alert alert-error'>" +
                      "<button type='button' class='close' data-dismiss='alert'>&times;</button>" +
                      "Problem invoking hawtio.OSGiTools MBean. " + response +
                      "</div>";
    }

    function populateTable(response) {
      var values = response.value;
      $scope.bundles = values;
      // now find the row based on the selection ui<commit_msg>ENTESB-1086 Exception in hawtio when uninstalling a bundle on OSGI tab<commit_after>/**
 * @module Osgi
 */
module Osgi {

  export function BundleController($scope, $location, workspace:Workspace, $routeParams, jolokia) {
    $scope.bundleId = $routeParams.bundleId;

    updateTableContents();

    $scope.showValue = (key) => {
      switch (key) {
        case "Bundle-Name":
        case "Bundle-SymbolicName":
        case "Bundle-Version":
        case "Export-Package":
        case "Import-Package":
          return false;
        default:
          return true;
      }
    };

    $scope.executeLoadClass = (clazz) => {
      var mbean = getHawtioOSGiToolsMBean(workspace);
      if (mbean) {
        jolokia.request(
                {type: 'exec', mbean: mbean, operation: 'getLoadClassOrigin', arguments: [$scope.bundleId, clazz]},
                {
                  success: function (response) {
                    var divEl = document.getElementById("loadClassResult");
                    var resultBundle = response.value;
                    var style;
                    var resultTxt;
                    if (resultBundle === -1) {
                      style = "";
                      resultTxt = "Class can not be loaded from this bundle.";
                    } else {
                      style = "alert-success";
                      resultTxt = "Class is served from Bundle " + bundleLinks(workspace, resultBundle);
                    }
                    divEl.innerHTML +=
                            "<div class='alert " + style + "'>" +
                                    "<button type='button' class='close' data-dismiss='alert'>&times;</button>" +
                                    "Loading class <strong>" + clazz + "</strong> in Bundle " + $scope.bundleId + ". " + resultTxt + "</div>";
                  },
                  error: function (response) {
                    inspectReportError(response);
                  }
                });
      } else {
        inspectReportNoMBeanFound();
      }
    };

    $scope.executeFindResource = (resource) => {
      var mbean = getHawtioOSGiToolsMBean(workspace);
      if (mbean) {
        jolokia.request(
                {type: 'exec', mbean: mbean, operation: 'getResourceURL', arguments: [$scope.bundleId, resource]},
                {
                  success: function (response) {
                    var divEl = document.getElementById("loadClassResult");
                    var resultURL = response.value;
                    var style;
                    var resultTxt;
                    if (resultURL === null) {
                      style = "";
                      resultTxt = "Resource can not be found from this bundle.";
                    } else {
                      style = "alert-success";
                      resultTxt = "Resource is available from: " + resultURL;
                    }
                    divEl.innerHTML +=
                            "<div class='alert " + style + "'>" +
                                    "<button type='button' class='close' data-dismiss='alert'>&times;</button>" +
                                    "Finding resource <strong>" + resource + "</strong> in Bundle " + $scope.bundleId + ". " + resultTxt + "</div>";
                  },
                  error: function (response) {
                    inspectReportError(response);
                  }
                }
        )
      } else {
        inspectReportNoMBeanFound();
      }
    };


    $scope.mavenLink = (row) => {
      if (angular.isObject(row)) {
        return Maven.mavenLink(row.Location);
      }
      // TODO try using the LogQuery mbean to find the mvn coords for a bundle id?
      return "";
    };

    $scope.startBundle = (bundleId) => {
      jolokia.request([
        {type: 'exec', mbean: getSelectionFrameworkMBean(workspace), operation: 'startBundle', arguments: [bundleId]}
      ],
              onSuccess(updateTableContents));
    };

    $scope.stopBundle = (bundleId) => {
      jolokia.request([
        {type: 'exec', mbean: getSelectionFrameworkMBean(workspace), operation: 'stopBundle', arguments: [bundleId]}
      ],
              onSuccess(updateTableContents));
    };

    $scope.updatehBundle = (bundleId) => {
      jolokia.request([
        {type: 'exec', mbean: getSelectionFrameworkMBean(workspace), operation: 'updateBundle', arguments: [bundleId]}
      ],
              onSuccess(updateTableContents));
    };

    $scope.refreshBundle = (bundleId) => {
      jolokia.request([
        {type: 'exec', mbean: getSelectionFrameworkMBean(workspace), operation: 'refreshBundle', arguments: [bundleId]}
      ],
              onSuccess(updateTableContents));
    };

    $scope.uninstallBundle = (bundleId) => {
      jolokia.request([{
        type: 'exec', 
        mbean: getSelectionFrameworkMBean(workspace), 
        operation: 'uninstallBundle', 
        arguments: [bundleId]
        }], onSuccess(function() { 
          $location.path("/osgi/bundle-list");
          Core.$apply($scope); 
        }));
    };

    function inspectReportNoMBeanFound() {
      var divEl = document.getElementById("loadClassResult");
      divEl.innerHTML +=
              "<div class='alert alert-error'>" +
                      "<button type='button' class='close' data-dismiss='alert'>&times;</button>" +
                      "The hawtio.OSGiTools MBean is not available. Please contact technical support." +
                      "</div>";
    }

    function inspectReportError(response) {
      var divEl = document.getElementById("loadClassResult");
      divEl.innerHTML +=
              "<div class='alert alert-error'>" +
                      "<button type='button' class='close' data-dismiss='alert'>&times;</button>" +
                      "Problem invoking hawtio.OSGiTools MBean. " + response +
                      "</div>";
    }

    function populateTable(response) {
      var values = response.value;
      $scope.bundles = values;
      // now find the row based on the selection ui
{'fraction_non_alphanumeric': 0.12361700357707346, 'fraction_numerical': 0.0004991265285749938, 'mean_word_length': 1.6585581601061476, 'pattern_counts': {'":': 10, '<': 43, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2487543', 'n_tokens_mistral': 3180, 'n_tokens_neox': 3014, 'n_words': 669}