function updateSourceNameForDataset(this, oldSourceName, newSourceName)
    %% UPDATESOURCENAMEFORDATASET function updates source name of dataset to newSourceName from oldSourceName in fxptds.FPTRepository ModelDatasetMaps
    %
    % oldSourceName is a char
    % newSourceName is a char
    
    %   Copyright 2016-2020 The MathWorks, Inc.
    
    if ~strcmp(oldSourceName, newSourceName)
        if this.ModelDatasetMap.isKey(oldSourceName)
            ds = this.ModelDatasetMap.getDataByKey(oldSourceName);
            % register the user intent to rename the old model to the new name
            % before the old dataset key is deleted
            context = fxptds.WorkflowTopology.WorkflowContextFactory.getContext(fxptds.UserIntent.RenameModel, ...
                'TopModel', oldSourceName, 'TopModelRename', newSourceName);
            
            ds.WorkflowTopologyFacade.register(context);
            if this.ModelDatasetMap.isKey(newSourceName)
                % If the new source is already in the map (can
                % happen when the UI gets refreshed and calls are
                % made to getChildren and there is a Signal or Bus
                % object in the list), retreive the dataset,
                % disassociate the mapping and ultimately delete
                % the previous dataset to avoid recursive deletes
                % (due to cycle detection and subsequent deletion
                % of key from map) that can cause memory leaks &
                % segvs.
                old_ds = this.ModelDatasetMap.getDataByKey(newSourceName);
                this.ModelDatasetMap.insert(newSourceName,handle([]));
                this.ModelDatasetMap.deleteDataByKey(newSourceName);
                delete(old_ds);
            end
            ds.updateSourceName(newSourceName);
            this.ModelDatasetMap.insert(newSourceName, ds);
            % remove association with the old name.
            this.ModelDatasetMap.insert(oldSourceName,handle([]));
            this.ModelDatasetMap.deleteDataByKey(oldSourceName);
            
            % by the time updateSourceNameForDataset is called, the new name
            % already has the old handle
            % delete the relationship between the old handle and old name and
            % replace with the old handle (same as new handle) and new name
            this.updateModelHandleMap(newSourceName);
            
        end
        
    end
end
