Method: GoodData::Project#replace_from_mapping
- Defined in:
- lib/gooddata/models/project.rb
#replace_from_mapping(mapping, opts = {}) ⇒ Object
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.
1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 |
# File 'lib/gooddata/models/project.rb', line 1587 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| GoodData.logger.info("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 GoodData.logger.info("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] } GoodData.logger.info("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 { visualizations: MdObject.query('visualizationObject', MdObject, client: client, project: self), visualization_widgets: MdObject.query('visualizationWidget', MdObject, client: client, project: self), kpis: MdObject.query('kpi', MdObject, client: client, project: self) }.each do |key, collection| GoodData.logger.info "Replacing #{key}" collection.each do |item| new_item = 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 end nil end |