<commit_before>'use strict';
angular.module('angular-jointjs-graph')
  .factory('GraphSelection', ['JointGraph', 'JointPaper', 'GraphHelpers', 'GraphEntities', 'GraphLinks', 'FactoryMap',
    function(JointGraph, JointPaper, GraphHelpers, GraphEntities, GraphLinks, FactoryMap) {
      var selection,
          selectionChangeCallback;

      function updateSelectedEntity() {
        var cell = JointGraph.getCell(selection.selectedCellId);

        if (cell) {
          var entityIdentifier = cell.get('backendModelParams').entityIdentifier,
            modelValues = {};

          _.each(GraphHelpers.entityProperties(entityIdentifier), function(propertyKey) {
            modelValues[propertyKey] = selection.selectedResource[propertyKey];
          });

          cell.attr(FactoryMap.get('JointNodeParams').get(modelValues).attrs);
        }
      }

      function notifySelectionChange() {
        if (_.isFunction(selectionChangeCallback)) {
          selectionChangeCallback(selection);
        }
      }

      return {
        onSelectionChange: function(callback) {
          selectionChangeCallback = callback;
        },
        select: function(selectedIds) {
          this.revertSelection();

          if (selectedIds) {
            var cell = JointGraph.getCell(selectedIds.selectedCellId),
                entity = selectedIds.isChartNode ?
                  GraphEntities.getSingle(cell) :
                  GraphLinks.getSingle(cell);

            selection = {
              isChartNode: selectedIds.isChartNode,
              selectedResource: entity,
              selectedCellId: selectedIds.selectedCellId,
              masterResource: angular.copy(entity)
            };
          } else {
            selection = null;
          }

          notifySelectionChange();
        },
        selectEntity: function(entity, identifier) {
          this.select({
            backendModelId: entity[GraphHelpers.getModelIdKey()],
            selectedCellId: GraphEntities.jointModelId(identifier, entity),
            isChartNode: true,
            entityIdentifier: identifier
          });
        },
        getSelectedEntity: function() {
          return selection ? selection.selectedResource : null;
        },
        revertSelection: function() {
          if (selection) {
            angular.copy(selection.masterResource, selection.selectedResource);
            updateSelectedEntity();
            notifySelectionChange();
          }
        },
        syncSelection: function() {
          if (selection) {
            angular.copy(selection.selectedResource, selection.masterResource);
            updateSelectedEntity();
            notifySelectionChange();
          }
        },
        clear: function() {
          JointPaper.clearSelection();
          selection = null;
          notifySelectionChange();
        },
        clearAndRevert: function() {
          JointPaper.clearSelection();
          angular.copy(selection.masterResource, selection.selectedResource);
          updateSelectedEntity();
          selection = null;
          notifySelectionChange();
        }
      };
    }
  ]);
<commit_msg>Fixed omitted null check<commit_after>'use strict';
angular.module('angular-jointjs-graph')
  .factory('GraphSelection', ['JointGraph', 'JointPaper', 'GraphHelpers', 'GraphEntities', 'GraphLinks', 'FactoryMap',
    function(JointGraph, JointPaper, GraphHelpers, GraphEntities, GraphLinks, FactoryMap) {
      var selection,
          selectionChangeCallback;

      function updateSelectedEntity() {
        var cell = JointGraph.getCell(selection.selectedCellId);

        if (cell) {
          var entityIdentifier = cell.get('backendModelParams').entityIdentifier,
            modelValues = {};

          _.each(GraphHelpers.entityProperties(entityIdentifier), function(propertyKey) {
            modelValues[propertyKey] = selection.selectedResource[propertyKey];
          });

          cell.attr(FactoryMap.get('JointNodeParams').get(modelValues).attrs);
        }
      }

      function notifySelectionChange() {
        if (_.isFunction(selectionChangeCallback)) {
          selectionChangeCallback(selection);
        }
      }

      return {
        onSelectionChange: function(callback) {
          selectionChangeCallback = callback;
        },
        select: function(selectedIds) {
          this.revertSelection();

          if (selectedIds) {
            var cell = JointGraph.getCell(selectedIds.selectedCellId),
                entity = selectedIds.isChartNode ?
                  GraphEntities.getSingle(cell) :
                  GraphLinks.getSingle(cell);

            selection = {
              isChartNode: selectedIds.isChartNode,
              selectedResource: entity,
              selectedCellId: selectedIds.selectedCellId,
              masterResource: angular.copy(entity)
            };
          } else {
            selection = null;
          }

          notifySelectionChange();
        },
        selectEntity: function(entity, identifier) {
          this.select({
            backendModelId: entity[GraphHelpers.getModelIdKey()],
            selectedCellId: GraphEntities.jointModelId(identifier, entity),
            isChartNode: true,
            entityIdentifier: identifier
          });
        },
        getSelectedEntity: function() {
          return selection ? selection.selectedResource : null;
        },
        revertSelection: function() {
          if (selection) {
            angular.copy(selection.masterResource, selection.selectedResource);
            updateSelectedEntity();
            notifySelectionChange();
          }
        },
        syncSelection: function() {
          if (selection) {
            angular.copy(selection.selectedResource, selection.masterResource);
            updateSelectedEntity();
            notifySelectionChange();
          }
        },
        clear: function() {
          JointPaper.clearSelection();
          selection = null;
          notifySelectionChange();
        },
        clearAndRevert: function() {
          JointPaper.clearSelection();
          if (selection) {
            angular.copy(selection.masterResource, selection.selectedResource);
            updateSelectedEntity();
          }
          selection = null;
          notifySelectionChange();
        }
      };
    }
  ]);

{'fraction_non_alphanumeric': 0.0986180904522613, 'fraction_numerical': 0.0, 'mean_word_length': 2.0768115942028986, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6255656', 'n_tokens_mistral': 1495, 'n_tokens_neox': 1459, 'n_words': 245}