lib/gooddata/models/project.rb
def replace_from_mapping(mapping, opts = {})
      default = {
        :purge => false,
        :dry_run => false
      }
      opts = default.merge(opts)
      dry_run = opts[:dry_run]

      if opts[:purge]
        GoodData.logger.info 'Purging old project definitions'
        reports.peach(&:purge_report_of_unused_definitions!)
      end

      fail ArgumentError, 'No mapping specified' if mapping.blank?
      rds = report_definitions

      {
        # data_permissions: data_permissions,
        variables: variables,
        dashboards: dashboards,
        metrics: metrics,
        report_definitions: rds
      }.each do |key, collection|
        puts "Replacing #{key}"
        collection.peach do |item|
          new_item = item.replace(mapping)
          if new_item.json != item.json
            if dry_run
              GoodData.logger.info "Would save #{new_item.uri}. Running in dry run mode"
            else
              GoodData.logger.info "Saving #{new_item.uri}"
              new_item.save
            end
          else
            GoodData.logger.info "Ignore #{item.uri}"
          end
        end
      end

      GoodData.logger.info 'Replacing hidden metrics'
      local_metrics = mapping.map { |a, _| a }.pmapcat { |a| a.usedby('metric') }.select { |m| m['deprecated'] == '1' }.map { |m| m['link'] }.uniq
      puts "Found #{local_metrics.count} metrics"
      local_metrics.pmap { |m| metrics(m) }.peach do |item|
        new_item = item.replace(mapping)
        if new_item.json != item.json
          if dry_run
            GoodData.logger.info "Would save #{new_item.uri}. Running in dry run mode"
          else
            GoodData.logger.info "Saving #{new_item.uri}"
            new_item.save
          end
        else
          GoodData.logger.info "Ignore #{item.uri}"
        end
      end

      GoodData.logger.info 'Replacing dashboard saved views'
      contexts = mapping.map { |a, _| a }.pmapcat { |a| a.usedby('executionContext') }.map { |a| GoodData::MdObject[a['link'], client: client, project: self] }
      puts "Found #{contexts.count} dashboard saved views"
      contexts.peach do |item|
        new_item = GoodData::MdObject.replace_quoted(item, mapping)
        if new_item.json != item.json
          if dry_run
            GoodData.logger.info "Would save #{new_item.uri}. Running in dry run mode"
          else
            GoodData.logger.info "Saving #{new_item.uri}"
            new_item.save
          end
        else
          GoodData.logger.info "Ignore #{item.uri}"
        end
      end

      GoodData.logger.info 'Replacing variable values'
      variables.each do |var|
        var.values.peach do |val|
          val.replace(mapping).save unless dry_run
        end
      end
      nil
    end
# Method used for walking through objects in project and trying to replace all occurences of some object for another object. This is typically used as a means for exchanging Date dimensions.
#
# @param mapping [Array<Array>] Mapping specifying what should be exchanged for what. As mapping should be used output of GoodData::Helpers.prepare_mapping.
Method used for walking through objects in project and trying to replace all occurences of some object for another object. This is typically used as a means for exchanging Date dimensions.
Method used for walking through objects in project and trying to replace all occurences of some object for another object . This is typically used as a means for exchanging Date dimensions .
def replace_from_mapping(mapping, opts = {})
      default = {
        :purge => false,
        :dry_run => false
      }
      opts = default.merge(opts)
      dry_run = opts[:dry_run]
      if opts[:purge]
        GoodData.logger.info 'Purging old project definitions'
        reports.peach(&:purge_report_of_unused_definitions!)
      end
      fail ArgumentError, 'No mapping specified' if mapping.blank?
      rds = report_definitions
      {
        variables: variables,
        dashboards: dashboards,
        metrics: metrics,
        report_definitions: rds
      }.each do |key, collection|
        puts "Replacing #{key}"
        collection.peach do |item|
          new_item = item.replace(mapping)
          if new_item.json != item.json
            if dry_run
              GoodData.logger.info "Would save #{new_item.uri}. Running in dry run mode"
            else
              GoodData.logger.info "Saving #{new_item.uri}"
              new_item.save
            end
          else
            GoodData.logger.info "Ignore #{item.uri}"
          end
        end
      end
      GoodData.logger.info 'Replacing hidden metrics'
      local_metrics = mapping.map { |a, _| a }.pmapcat { |a| a.usedby('metric') }.select { |m| m['deprecated'] == '1' }.map { |m| m['link'] }.uniq
      puts "Found #{local_metrics.count} metrics"
      local_metrics.pmap { |m| metrics(m) }.peach do |item|
        new_item = item.replace(mapping)
        if new_item.json != item.json
          if dry_run
            GoodData.logger.info "Would save #{new_item.uri}. Running in dry run mode"
          else
            GoodData.logger.info "Saving #{new_item.uri}"
            new_item.save
          end
        else
          GoodData.logger.info "Ignore #{item.uri}"
        end
      end
      GoodData.logger.info 'Replacing dashboard saved views'
      contexts = mapping.map { |a, _| a }.pmapcat { |a| a.usedby('executionContext') }.map { |a| GoodData::MdObject[a['link'], client: client, project: self] }
      puts "Found #{contexts.count} dashboard saved views"
      contexts.peach do |item|
        new_item = GoodData::MdObject.replace_quoted(item, mapping)
        if new_item.json != item.json
          if dry_run
            GoodData.logger.info "Would save #{new_item.uri}. Running in dry run mode"
          else
            GoodData.logger.info "Saving #{new_item.uri}"
            new_item.save
          end
        else
          GoodData.logger.info "Ignore #{item.uri}"
        end
      end
      GoodData.logger.info 'Replacing variable values'
      variables.each do |var|
        var.values.peach do |val|
          val.replace(mapping).save unless dry_run
        end
      end
      nil
    end
def replace_from_mapping ( mapping , opts = { } ) default = { :purge => false , :dry_run => false } opts = default . merge ( opts ) dry_run = opts [ :dry_run ] if opts [ :purge ] GoodData . logger . info 'Purging old project definitions' reports . peach ( & :purge_report_of_unused_definitions! ) end fail ArgumentError , 'No mapping specified' if mapping . blank? rds = report_definitions { variables : variables , dashboards : dashboards , metrics : metrics , report_definitions : rds } . each do | key , collection | puts "Replacing #{key}" collection . peach do | item | new_item = item . replace ( mapping ) if new_item . json != item . json if dry_run GoodData . logger . info "Would save #{new_item.uri}. Running in dry run mode" else GoodData . logger . info "Saving #{new_item.uri}" new_item . save end else GoodData . logger . info "Ignore #{item.uri}" end end end GoodData . logger . info 'Replacing hidden metrics' local_metrics = mapping . map { | a , _ | a } . pmapcat { | a | a . usedby ( 'metric' ) } . select { | m | m [ 'deprecated' ] == '1' } . map { | m | m [ 'link' ] } . uniq puts "Found #{local_metrics.count} metrics" local_metrics . pmap { | m | metrics ( m ) } . peach do | item | new_item = item . replace ( mapping ) if new_item . json != item . json if dry_run GoodData . logger . info "Would save #{new_item.uri}. Running in dry run mode" else GoodData . logger . info "Saving #{new_item.uri}" new_item . save end else GoodData . logger . info "Ignore #{item.uri}" end end GoodData . logger . info 'Replacing dashboard saved views' contexts = mapping . map { | a , _ | a } . pmapcat { | a | a . usedby ( 'executionContext' ) } . map { | a | GoodData :: MdObject [ a [ 'link' ] , client : client , project : self ] } puts "Found #{contexts.count} dashboard saved views" contexts . peach do | item | new_item = GoodData :: MdObject . replace_quoted ( item , mapping ) if new_item . json != item . json if dry_run GoodData . logger . info "Would save #{new_item.uri}. Running in dry run mode" else GoodData . logger . info "Saving #{new_item.uri}" new_item . save end else GoodData . logger . info "Ignore #{item.uri}" end end GoodData . logger . info 'Replacing variable values' variables . each do | var | var . values . peach do | val | val . replace ( mapping ) . save unless dry_run end end nil end
Method used for walking through objects in project and trying to replace all occurences of some object for another object.
Method used for walking through objects in project and trying to replace all occurences of some object for another object .
# data_permissions: data_permissions,
mapping
Mapping specifying what should be exchanged for what. As mapping should be used output of GoodData::Helpers.prepare_mapping.
Mapping specifying what should be exchanged for what . As mapping should be used output of GoodData :: Helpers . prepare_mapping .
opts