gooddata 1.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.editorconfig +12 -0
- data/.flayignore +6 -0
- data/.gitignore +38 -0
- data/.pronto.yml +3 -0
- data/.rspec +5 -0
- data/.rubocop.yml +101 -0
- data/.travis.yml +9 -0
- data/.yardopts +22 -0
- data/CHANGELOG.md +272 -0
- data/CLI.md +435 -0
- data/CONTRIBUTING.md +38 -0
- data/DEPENDENCIES.md +880 -0
- data/Dockerfile.jruby +17 -0
- data/Dockerfile.ruby +19 -0
- data/Gemfile +4 -0
- data/Guardfile +5 -0
- data/LICENSE +22 -0
- data/LICENSE.rb +5 -0
- data/README.md +78 -0
- data/Rakefile +204 -0
- data/TODO.md +32 -0
- data/authors.sh +4 -0
- data/bin/gooddata +7 -0
- data/ci.rake +47 -0
- data/dependency_decisions.yml +104 -0
- data/docker-compose.yml +34 -0
- data/gooddata +9 -0
- data/gooddata.gemspec +72 -0
- data/lib/gooddata.rb +34 -0
- data/lib/gooddata/app/app.rb +16 -0
- data/lib/gooddata/bricks/base_downloader.rb +86 -0
- data/lib/gooddata/bricks/brick.rb +37 -0
- data/lib/gooddata/bricks/bricks.rb +17 -0
- data/lib/gooddata/bricks/middleware/aws_middleware.rb +41 -0
- data/lib/gooddata/bricks/middleware/base_middleware.rb +57 -0
- data/lib/gooddata/bricks/middleware/bench_middleware.rb +25 -0
- data/lib/gooddata/bricks/middleware/bulk_salesforce_middleware.rb +37 -0
- data/lib/gooddata/bricks/middleware/decode_params_middleware.rb +21 -0
- data/lib/gooddata/bricks/middleware/dwh_middleware.rb +41 -0
- data/lib/gooddata/bricks/middleware/fs_download_middleware.rb +48 -0
- data/lib/gooddata/bricks/middleware/fs_upload_middleware.rb +36 -0
- data/lib/gooddata/bricks/middleware/gooddata_middleware.rb +112 -0
- data/lib/gooddata/bricks/middleware/logger_middleware.rb +33 -0
- data/lib/gooddata/bricks/middleware/middleware.rb +12 -0
- data/lib/gooddata/bricks/middleware/restforce_middleware.rb +58 -0
- data/lib/gooddata/bricks/middleware/stdout_middleware.rb +23 -0
- data/lib/gooddata/bricks/middleware/twitter_middleware.rb +29 -0
- data/lib/gooddata/bricks/middleware/undot_params_middleware.rb +37 -0
- data/lib/gooddata/bricks/pipeline.rb +25 -0
- data/lib/gooddata/bricks/utils.rb +18 -0
- data/lib/gooddata/cli/cli.rb +27 -0
- data/lib/gooddata/cli/commands/auth_cmd.rb +29 -0
- data/lib/gooddata/cli/commands/domain_cmd.rb +28 -0
- data/lib/gooddata/cli/commands/project_cmd.rb +28 -0
- data/lib/gooddata/cli/hooks.rb +56 -0
- data/lib/gooddata/cli/shared.rb +66 -0
- data/lib/gooddata/cli/terminal.rb +20 -0
- data/lib/gooddata/client.rb +67 -0
- data/lib/gooddata/commands/api.rb +64 -0
- data/lib/gooddata/commands/auth.rb +107 -0
- data/lib/gooddata/commands/base.rb +12 -0
- data/lib/gooddata/commands/commands.rb +12 -0
- data/lib/gooddata/commands/datasets.rb +148 -0
- data/lib/gooddata/commands/datawarehouse.rb +20 -0
- data/lib/gooddata/commands/domain.rb +40 -0
- data/lib/gooddata/commands/process.rb +67 -0
- data/lib/gooddata/commands/project.rb +144 -0
- data/lib/gooddata/commands/projects.rb +20 -0
- data/lib/gooddata/commands/role.rb +36 -0
- data/lib/gooddata/commands/runners.rb +47 -0
- data/lib/gooddata/commands/scaffold.rb +69 -0
- data/lib/gooddata/commands/user.rb +39 -0
- data/lib/gooddata/connection.rb +127 -0
- data/lib/gooddata/core/core.rb +12 -0
- data/lib/gooddata/core/logging.rb +105 -0
- data/lib/gooddata/core/nil_logger.rb +32 -0
- data/lib/gooddata/core/project.rb +74 -0
- data/lib/gooddata/core/rest.rb +149 -0
- data/lib/gooddata/core/user.rb +20 -0
- data/lib/gooddata/data/data.rb +12 -0
- data/lib/gooddata/data/guesser.rb +122 -0
- data/lib/gooddata/exceptions/attr_element_not_found.rb +16 -0
- data/lib/gooddata/exceptions/command_failed.rb +11 -0
- data/lib/gooddata/exceptions/exceptions.rb +12 -0
- data/lib/gooddata/exceptions/execution_limit_exceeded.rb +13 -0
- data/lib/gooddata/exceptions/export_clone.rb +4 -0
- data/lib/gooddata/exceptions/filter_maqlization.rb +16 -0
- data/lib/gooddata/exceptions/import_clone.rb +4 -0
- data/lib/gooddata/exceptions/malformed_user.rb +15 -0
- data/lib/gooddata/exceptions/maql_execution.rb +16 -0
- data/lib/gooddata/exceptions/no_project_error.rb +19 -0
- data/lib/gooddata/exceptions/object_migration.rb +32 -0
- data/lib/gooddata/exceptions/project_not_found.rb +13 -0
- data/lib/gooddata/exceptions/segment_not_empty.rb +18 -0
- data/lib/gooddata/exceptions/uncomputable_report.rb +13 -0
- data/lib/gooddata/exceptions/user_in_different_domain.rb +15 -0
- data/lib/gooddata/exceptions/validation_error.rb +16 -0
- data/lib/gooddata/extensions/big_decimal.rb +17 -0
- data/lib/gooddata/extensions/class.rb +11 -0
- data/lib/gooddata/extensions/enumerable.rb +39 -0
- data/lib/gooddata/extensions/extensions.rb +10 -0
- data/lib/gooddata/extensions/false.rb +23 -0
- data/lib/gooddata/extensions/hash.rb +49 -0
- data/lib/gooddata/extensions/integer.rb +5 -0
- data/lib/gooddata/extensions/nil.rb +19 -0
- data/lib/gooddata/extensions/numeric.rb +15 -0
- data/lib/gooddata/extensions/object.rb +31 -0
- data/lib/gooddata/extensions/string.rb +7 -0
- data/lib/gooddata/extensions/symbol.rb +15 -0
- data/lib/gooddata/extensions/true.rb +23 -0
- data/lib/gooddata/extract.rb +21 -0
- data/lib/gooddata/goodzilla/goodzilla.rb +160 -0
- data/lib/gooddata/helpers/auth_helpers.rb +75 -0
- data/lib/gooddata/helpers/csv_helper.rb +61 -0
- data/lib/gooddata/helpers/data_helper.rb +129 -0
- data/lib/gooddata/helpers/erb_helper.rb +23 -0
- data/lib/gooddata/helpers/global_helpers.rb +266 -0
- data/lib/gooddata/helpers/global_helpers_params.rb +292 -0
- data/lib/gooddata/helpers/helpers.rb +10 -0
- data/lib/gooddata/lcm/actions/actions.rb +12 -0
- data/lib/gooddata/lcm/actions/apply_custom_maql.rb +80 -0
- data/lib/gooddata/lcm/actions/associate_clients.rb +87 -0
- data/lib/gooddata/lcm/actions/base_action.rb +23 -0
- data/lib/gooddata/lcm/actions/collect_ca_metrics.rb +53 -0
- data/lib/gooddata/lcm/actions/collect_client_projects.rb +78 -0
- data/lib/gooddata/lcm/actions/collect_clients.rb +128 -0
- data/lib/gooddata/lcm/actions/collect_data_product.rb +57 -0
- data/lib/gooddata/lcm/actions/collect_dynamic_schedule_params.rb +62 -0
- data/lib/gooddata/lcm/actions/collect_ldm_objects.rb +56 -0
- data/lib/gooddata/lcm/actions/collect_meta.rb +88 -0
- data/lib/gooddata/lcm/actions/collect_segment_clients.rb +113 -0
- data/lib/gooddata/lcm/actions/collect_segments.rb +72 -0
- data/lib/gooddata/lcm/actions/collect_tagged_objects.rb +80 -0
- data/lib/gooddata/lcm/actions/collect_users_brick_users.rb +46 -0
- data/lib/gooddata/lcm/actions/create_segment_masters.rb +160 -0
- data/lib/gooddata/lcm/actions/ensure_data_product.rb +53 -0
- data/lib/gooddata/lcm/actions/ensure_release_table.rb +53 -0
- data/lib/gooddata/lcm/actions/ensure_segments.rb +32 -0
- data/lib/gooddata/lcm/actions/ensure_technical_users_domain.rb +70 -0
- data/lib/gooddata/lcm/actions/ensure_technical_users_project.rb +83 -0
- data/lib/gooddata/lcm/actions/execute_schedules.rb +128 -0
- data/lib/gooddata/lcm/actions/hello_world.rb +41 -0
- data/lib/gooddata/lcm/actions/import_object_collections.rb +60 -0
- data/lib/gooddata/lcm/actions/print_actions.rb +58 -0
- data/lib/gooddata/lcm/actions/print_modes.rb +69 -0
- data/lib/gooddata/lcm/actions/print_types.rb +52 -0
- data/lib/gooddata/lcm/actions/provision_clients.rb +89 -0
- data/lib/gooddata/lcm/actions/purge_clients.rb +58 -0
- data/lib/gooddata/lcm/actions/rename_existing_client_projects.rb +70 -0
- data/lib/gooddata/lcm/actions/segments_filter.rb +50 -0
- data/lib/gooddata/lcm/actions/synchronize_attribute_drillpaths.rb +64 -0
- data/lib/gooddata/lcm/actions/synchronize_cas.rb +72 -0
- data/lib/gooddata/lcm/actions/synchronize_clients.rb +94 -0
- data/lib/gooddata/lcm/actions/synchronize_color_palette.rb +67 -0
- data/lib/gooddata/lcm/actions/synchronize_etls_in_segment.rb +155 -0
- data/lib/gooddata/lcm/actions/synchronize_label_types.rb +64 -0
- data/lib/gooddata/lcm/actions/synchronize_ldm.rb +82 -0
- data/lib/gooddata/lcm/actions/synchronize_meta.rb +52 -0
- data/lib/gooddata/lcm/actions/synchronize_new_segments.rb +61 -0
- data/lib/gooddata/lcm/actions/synchronize_processes.rb +66 -0
- data/lib/gooddata/lcm/actions/synchronize_schedules.rb +91 -0
- data/lib/gooddata/lcm/actions/synchronize_tag_objects.rb +64 -0
- data/lib/gooddata/lcm/actions/synchronize_user_filters.rb +210 -0
- data/lib/gooddata/lcm/actions/synchronize_user_groups.rb +53 -0
- data/lib/gooddata/lcm/actions/synchronize_users.rb +336 -0
- data/lib/gooddata/lcm/actions/update_release_table.rb +77 -0
- data/lib/gooddata/lcm/data/create_lcm_release.sql.erb +6 -0
- data/lib/gooddata/lcm/data/insert_into_lcm_release.sql.erb +11 -0
- data/lib/gooddata/lcm/data/select_from_lcm_release.sql.erb +8 -0
- data/lib/gooddata/lcm/data/update_lcm_release.sql.erb +7 -0
- data/lib/gooddata/lcm/dsl/dsl.rb +50 -0
- data/lib/gooddata/lcm/dsl/params_dsl.rb +61 -0
- data/lib/gooddata/lcm/dsl/type_dsl.rb +62 -0
- data/lib/gooddata/lcm/helpers/check_helper.rb +41 -0
- data/lib/gooddata/lcm/helpers/helpers.rb +12 -0
- data/lib/gooddata/lcm/helpers/tags_helper.rb +36 -0
- data/lib/gooddata/lcm/lcm.rb +325 -0
- data/lib/gooddata/lcm/lcm2.rb +400 -0
- data/lib/gooddata/lcm/types/base_type.rb +29 -0
- data/lib/gooddata/lcm/types/class/ads_client.rb +35 -0
- data/lib/gooddata/lcm/types/class/class.rb +21 -0
- data/lib/gooddata/lcm/types/class/gd_client.rb +35 -0
- data/lib/gooddata/lcm/types/class/types.rb +12 -0
- data/lib/gooddata/lcm/types/complex/complex.rb +33 -0
- data/lib/gooddata/lcm/types/complex/release_query.rb +35 -0
- data/lib/gooddata/lcm/types/complex/segment.rb +40 -0
- data/lib/gooddata/lcm/types/complex/synchronization_info.rb +35 -0
- data/lib/gooddata/lcm/types/complex/tokens.rb +31 -0
- data/lib/gooddata/lcm/types/complex/types.rb +12 -0
- data/lib/gooddata/lcm/types/complex/update_preference.rb +38 -0
- data/lib/gooddata/lcm/types/complex/users_brick_config.rb +32 -0
- data/lib/gooddata/lcm/types/param.rb +16 -0
- data/lib/gooddata/lcm/types/scalar/bool.rb +22 -0
- data/lib/gooddata/lcm/types/scalar/hash.rb +22 -0
- data/lib/gooddata/lcm/types/scalar/integer.rb +22 -0
- data/lib/gooddata/lcm/types/scalar/object.rb +22 -0
- data/lib/gooddata/lcm/types/scalar/string.rb +22 -0
- data/lib/gooddata/lcm/types/scalar/types.rb +12 -0
- data/lib/gooddata/lcm/types/special/array.rb +33 -0
- data/lib/gooddata/lcm/types/special/enum.rb +15 -0
- data/lib/gooddata/lcm/types/special/types.rb +12 -0
- data/lib/gooddata/lcm/types/types.rb +12 -0
- data/lib/gooddata/lcm/user_bricks_helper.rb +32 -0
- data/lib/gooddata/mixins/author.rb +26 -0
- data/lib/gooddata/mixins/content_getter.rb +15 -0
- data/lib/gooddata/mixins/content_property_reader.rb +17 -0
- data/lib/gooddata/mixins/content_property_writer.rb +17 -0
- data/lib/gooddata/mixins/contributor.rb +20 -0
- data/lib/gooddata/mixins/data_getter.rb +15 -0
- data/lib/gooddata/mixins/data_property_reader.rb +19 -0
- data/lib/gooddata/mixins/data_property_writer.rb +19 -0
- data/lib/gooddata/mixins/inspector.rb +53 -0
- data/lib/gooddata/mixins/is_attribute.rb +17 -0
- data/lib/gooddata/mixins/is_dimension.rb +17 -0
- data/lib/gooddata/mixins/is_fact.rb +17 -0
- data/lib/gooddata/mixins/is_folder.rb +11 -0
- data/lib/gooddata/mixins/is_label.rb +19 -0
- data/lib/gooddata/mixins/links.rb +15 -0
- data/lib/gooddata/mixins/md_finders.rb +79 -0
- data/lib/gooddata/mixins/md_grantees.rb +42 -0
- data/lib/gooddata/mixins/md_id_to_uri.rb +39 -0
- data/lib/gooddata/mixins/md_json.rb +15 -0
- data/lib/gooddata/mixins/md_lock.rb +87 -0
- data/lib/gooddata/mixins/md_object_id.rb +15 -0
- data/lib/gooddata/mixins/md_object_indexer.rb +74 -0
- data/lib/gooddata/mixins/md_object_query.rb +134 -0
- data/lib/gooddata/mixins/md_relations.rb +43 -0
- data/lib/gooddata/mixins/meta_getter.rb +17 -0
- data/lib/gooddata/mixins/meta_property_reader.rb +19 -0
- data/lib/gooddata/mixins/meta_property_writer.rb +19 -0
- data/lib/gooddata/mixins/mixins.rb +19 -0
- data/lib/gooddata/mixins/not_attribute.rb +17 -0
- data/lib/gooddata/mixins/not_exportable.rb +15 -0
- data/lib/gooddata/mixins/not_fact.rb +17 -0
- data/lib/gooddata/mixins/not_group.rb +17 -0
- data/lib/gooddata/mixins/not_label.rb +19 -0
- data/lib/gooddata/mixins/not_metric.rb +19 -0
- data/lib/gooddata/mixins/obj_id.rb +15 -0
- data/lib/gooddata/mixins/rest_getters.rb +17 -0
- data/lib/gooddata/mixins/rest_resource.rb +47 -0
- data/lib/gooddata/mixins/root_key_getter.rb +15 -0
- data/lib/gooddata/mixins/root_key_setter.rb +15 -0
- data/lib/gooddata/mixins/timestamps.rb +19 -0
- data/lib/gooddata/mixins/to_json.rb +11 -0
- data/lib/gooddata/mixins/uri_getter.rb +9 -0
- data/lib/gooddata/models/ads_output_stage.rb +85 -0
- data/lib/gooddata/models/automated_data_distribution.rb +36 -0
- data/lib/gooddata/models/blueprint/anchor_field.rb +65 -0
- data/lib/gooddata/models/blueprint/attribute_field.rb +45 -0
- data/lib/gooddata/models/blueprint/blueprint.rb +11 -0
- data/lib/gooddata/models/blueprint/blueprint_field.rb +70 -0
- data/lib/gooddata/models/blueprint/dashboard_builder.rb +30 -0
- data/lib/gooddata/models/blueprint/dataset_blueprint.rb +455 -0
- data/lib/gooddata/models/blueprint/date_dimension.rb +20 -0
- data/lib/gooddata/models/blueprint/fact_field.rb +20 -0
- data/lib/gooddata/models/blueprint/label_field.rb +47 -0
- data/lib/gooddata/models/blueprint/project_blueprint.rb +791 -0
- data/lib/gooddata/models/blueprint/project_builder.rb +103 -0
- data/lib/gooddata/models/blueprint/reference_field.rb +43 -0
- data/lib/gooddata/models/blueprint/schema_blueprint.rb +160 -0
- data/lib/gooddata/models/blueprint/schema_builder.rb +89 -0
- data/lib/gooddata/models/blueprint/to_manifest.rb +185 -0
- data/lib/gooddata/models/blueprint/to_wire.rb +173 -0
- data/lib/gooddata/models/channel_configuration.rb +112 -0
- data/lib/gooddata/models/client.rb +236 -0
- data/lib/gooddata/models/client_synchronization_result.rb +31 -0
- data/lib/gooddata/models/client_synchronization_result_details.rb +41 -0
- data/lib/gooddata/models/data_product.rb +149 -0
- data/lib/gooddata/models/datawarehouse.rb +114 -0
- data/lib/gooddata/models/domain.rb +505 -0
- data/lib/gooddata/models/execution.rb +115 -0
- data/lib/gooddata/models/execution_detail.rb +81 -0
- data/lib/gooddata/models/from_wire.rb +173 -0
- data/lib/gooddata/models/invitation.rb +75 -0
- data/lib/gooddata/models/links.rb +50 -0
- data/lib/gooddata/models/membership.rb +441 -0
- data/lib/gooddata/models/metadata.rb +324 -0
- data/lib/gooddata/models/metadata/attribute.rb +155 -0
- data/lib/gooddata/models/metadata/dashboard.rb +120 -0
- data/lib/gooddata/models/metadata/dashboard/dashboard_item.rb +76 -0
- data/lib/gooddata/models/metadata/dashboard/filter_apply_item.rb +37 -0
- data/lib/gooddata/models/metadata/dashboard/filter_item.rb +64 -0
- data/lib/gooddata/models/metadata/dashboard/geo_chart_item.rb +56 -0
- data/lib/gooddata/models/metadata/dashboard/headline_item.rb +56 -0
- data/lib/gooddata/models/metadata/dashboard/iframe_item.rb +46 -0
- data/lib/gooddata/models/metadata/dashboard/report_item.rb +92 -0
- data/lib/gooddata/models/metadata/dashboard/text_item.rb +55 -0
- data/lib/gooddata/models/metadata/dashboard_tab.rb +141 -0
- data/lib/gooddata/models/metadata/dataset.rb +67 -0
- data/lib/gooddata/models/metadata/dimension.rb +57 -0
- data/lib/gooddata/models/metadata/fact.rb +51 -0
- data/lib/gooddata/models/metadata/folder.rb +49 -0
- data/lib/gooddata/models/metadata/label.rb +128 -0
- data/lib/gooddata/models/metadata/metadata.rb +12 -0
- data/lib/gooddata/models/metadata/metric.rb +206 -0
- data/lib/gooddata/models/metadata/report.rb +268 -0
- data/lib/gooddata/models/metadata/report_definition.rb +272 -0
- data/lib/gooddata/models/metadata/scheduled_mail.rb +277 -0
- data/lib/gooddata/models/metadata/scheduled_mail/dashboard_attachment.rb +62 -0
- data/lib/gooddata/models/metadata/scheduled_mail/report_attachment.rb +64 -0
- data/lib/gooddata/models/metadata/variable.rb +96 -0
- data/lib/gooddata/models/model.rb +293 -0
- data/lib/gooddata/models/models.rb +12 -0
- data/lib/gooddata/models/module_constants.rb +31 -0
- data/lib/gooddata/models/notification_rule.rb +113 -0
- data/lib/gooddata/models/process.rb +371 -0
- data/lib/gooddata/models/profile.rb +451 -0
- data/lib/gooddata/models/project.rb +2030 -0
- data/lib/gooddata/models/project_creator.rb +209 -0
- data/lib/gooddata/models/project_log_formatter.rb +204 -0
- data/lib/gooddata/models/project_metadata.rb +67 -0
- data/lib/gooddata/models/project_role.rb +79 -0
- data/lib/gooddata/models/report_data_result.rb +270 -0
- data/lib/gooddata/models/schedule.rb +538 -0
- data/lib/gooddata/models/segment.rb +274 -0
- data/lib/gooddata/models/style_setting.rb +62 -0
- data/lib/gooddata/models/subscription.rb +188 -0
- data/lib/gooddata/models/tab_builder.rb +27 -0
- data/lib/gooddata/models/user_filters/mandatory_user_filter.rb +76 -0
- data/lib/gooddata/models/user_filters/user_filter.rb +101 -0
- data/lib/gooddata/models/user_filters/user_filter_builder.rb +553 -0
- data/lib/gooddata/models/user_filters/user_filters.rb +13 -0
- data/lib/gooddata/models/user_filters/variable_user_filter.rb +33 -0
- data/lib/gooddata/models/user_group.rb +250 -0
- data/lib/gooddata/rest/README.md +37 -0
- data/lib/gooddata/rest/client.rb +396 -0
- data/lib/gooddata/rest/connection.rb +776 -0
- data/lib/gooddata/rest/object.rb +69 -0
- data/lib/gooddata/rest/object_factory.rb +51 -0
- data/lib/gooddata/rest/resource.rb +27 -0
- data/lib/gooddata/rest/rest.rb +24 -0
- data/lib/gooddata/version.rb +23 -0
- data/lib/templates/bricks/brick.rb.erb +7 -0
- data/lib/templates/bricks/main.rb.erb +5 -0
- data/lib/templates/project/Goodfile.erb +4 -0
- data/lib/templates/project/data/commits.csv +4 -0
- data/lib/templates/project/data/devs.csv +4 -0
- data/lib/templates/project/data/repos.csv +3 -0
- data/lib/templates/project/model/model.rb.erb +20 -0
- data/spec/.rubocop.yml +16 -0
- data/spec/bricks/bricks_spec.rb +110 -0
- data/spec/bricks/default-config.json +8 -0
- data/spec/data/.gooddata +4 -0
- data/spec/data/blueprints/additional_dataset_module.json +32 -0
- data/spec/data/blueprints/attribute_sort_order_blueprint.json +72 -0
- data/spec/data/blueprints/big_blueprint_not_pruned.json +2079 -0
- data/spec/data/blueprints/invalid_blueprint.json +103 -0
- data/spec/data/blueprints/m_n_model.json +104 -0
- data/spec/data/blueprints/model_module.json +25 -0
- data/spec/data/blueprints/test_blueprint.json +39 -0
- data/spec/data/blueprints/test_project_model_spec.json +106 -0
- data/spec/data/cc/data/source/commits.csv +4 -0
- data/spec/data/cc/data/source/devs.csv +4 -0
- data/spec/data/cc/data/source/repos.csv +3 -0
- data/spec/data/cc/devel.prm +0 -0
- data/spec/data/cc/graph/graph.grf +11 -0
- data/spec/data/cc/workspace.prm +19 -0
- data/spec/data/column_based_permissions.csv +7 -0
- data/spec/data/column_based_permissions2.csv +6 -0
- data/spec/data/dynamic_schedule_params_table.csv +7 -0
- data/spec/data/gd_gse_data_blueprint.json +1371 -0
- data/spec/data/gd_gse_data_manifest.json +1424 -0
- data/spec/data/gd_gse_data_model.json +1772 -0
- data/spec/data/gooddata_version_process/gooddata_version.rb +9 -0
- data/spec/data/gooddata_version_process/gooddata_version.zip +0 -0
- data/spec/data/hello_world_process/hello_world.rb +9 -0
- data/spec/data/hello_world_process/hello_world.zip +0 -0
- data/spec/data/line_based_permissions.csv +3 -0
- data/spec/data/manifests/test_blueprint.json +32 -0
- data/spec/data/manifests/test_project.json +107 -0
- data/spec/data/reports/left_attr_report.json +108 -0
- data/spec/data/reports/metric_only_one_line.json +83 -0
- data/spec/data/reports/report_1.json +197 -0
- data/spec/data/reports/top_attr_report.json +108 -0
- data/spec/data/ruby_params_process/ruby_params.rb +9 -0
- data/spec/data/ruby_process/deep_files/deep_stuff.txt +1 -0
- data/spec/data/ruby_process/process.rb +8 -0
- data/spec/data/ruby_process/stuff.txt +1 -0
- data/spec/data/superfluous_titles_view.json +81 -0
- data/spec/data/test-ci-data.csv +2 -0
- data/spec/data/users.csv +12 -0
- data/spec/data/wire_models/attribute_sort_by_model.json +73 -0
- data/spec/data/wire_models/model_view.json +1775 -0
- data/spec/data/wire_models/nu_model.json +3046 -0
- data/spec/data/wire_models/test_blueprint.json +66 -0
- data/spec/data/wire_test_project.json +150 -0
- data/spec/data/workspace_table.csv +3 -0
- data/spec/environment/default.rb +43 -0
- data/spec/environment/development.rb +32 -0
- data/spec/environment/environment.rb +38 -0
- data/spec/environment/production.rb +27 -0
- data/spec/environment/staging.rb +33 -0
- data/spec/environment/testing.rb +32 -0
- data/spec/helpers/blueprint_helper.rb +27 -0
- data/spec/helpers/cli_helper.rb +38 -0
- data/spec/helpers/connection_helper.rb +43 -0
- data/spec/helpers/crypto_helper.rb +19 -0
- data/spec/helpers/csv_helper.rb +20 -0
- data/spec/helpers/process_helper.rb +35 -0
- data/spec/helpers/project_helper.rb +74 -0
- data/spec/helpers/schedule_helper.rb +33 -0
- data/spec/helpers/spec_helper.rb +17 -0
- data/spec/integration/ads_output_stage_spec.rb +45 -0
- data/spec/integration/blueprint_updates_spec.rb +107 -0
- data/spec/integration/blueprint_with_ca_spec.rb +56 -0
- data/spec/integration/blueprint_with_grain_spec.rb +74 -0
- data/spec/integration/channel_configuration_spec.rb +67 -0
- data/spec/integration/clients_spec.rb +164 -0
- data/spec/integration/command_datawarehouse_spec.rb +45 -0
- data/spec/integration/command_projects_spec.rb +32 -0
- data/spec/integration/commands/command_projects_spec.rb +22 -0
- data/spec/integration/core/connection_spec.rb +56 -0
- data/spec/integration/core/logging_spec.rb +130 -0
- data/spec/integration/core/project_spec.rb +54 -0
- data/spec/integration/create_from_template_spec.rb +29 -0
- data/spec/integration/create_project_spec.rb +27 -0
- data/spec/integration/date_dim_switch_spec.rb +150 -0
- data/spec/integration/deprecated_load_spec.rb +60 -0
- data/spec/integration/full_process_schedule_spec.rb +367 -0
- data/spec/integration/full_project_spec.rb +592 -0
- data/spec/integration/helpers_spec.rb +16 -0
- data/spec/integration/lcm_spec.rb +54 -0
- data/spec/integration/mixins/id_to_uri_spec.rb +44 -0
- data/spec/integration/models/data_product_spec.rb +71 -0
- data/spec/integration/models/domain_spec.rb +162 -0
- data/spec/integration/models/invitation_spec.rb +17 -0
- data/spec/integration/models/membership_spec.rb +127 -0
- data/spec/integration/models/metadata/report_spec.rb +54 -0
- data/spec/integration/models/params_spec.rb +118 -0
- data/spec/integration/models/profile_spec.rb +210 -0
- data/spec/integration/models/project_role_spec.rb +94 -0
- data/spec/integration/models/project_spec.rb +225 -0
- data/spec/integration/models/schedule_spec.rb +485 -0
- data/spec/integration/models/unit_project_spec.rb +130 -0
- data/spec/integration/over_to_user_filters_spec.rb +98 -0
- data/spec/integration/partial_md_export_import_spec.rb +41 -0
- data/spec/integration/project_spec.rb +381 -0
- data/spec/integration/rest_spec.rb +214 -0
- data/spec/integration/schedule_spec.rb +613 -0
- data/spec/integration/segments_spec.rb +100 -0
- data/spec/integration/subscription_spec.rb +88 -0
- data/spec/integration/urn_date_dim_spec.rb +53 -0
- data/spec/integration/user_filters_spec.rb +306 -0
- data/spec/integration/user_group_spec.rb +147 -0
- data/spec/integration/variables_spec.rb +189 -0
- data/spec/logging_in_logging_out_spec.rb +91 -0
- data/spec/spec_helper.rb +66 -0
- data/spec/unit/actions/associate_clients_spec.rb +47 -0
- data/spec/unit/actions/collect_client_projects_spec.rb +47 -0
- data/spec/unit/actions/collect_clients_spec.rb +65 -0
- data/spec/unit/actions/collect_data_product_spec.rb +56 -0
- data/spec/unit/actions/collect_dynamic_schedule_params_spec.rb +56 -0
- data/spec/unit/actions/collect_meta_spec.rb +88 -0
- data/spec/unit/actions/collect_segment_clients_spec.rb +81 -0
- data/spec/unit/actions/collect_tagged_objects_spec.rb +126 -0
- data/spec/unit/actions/collect_users_brick_users_spec.rb +36 -0
- data/spec/unit/actions/create_segment_masters_spec.rb +64 -0
- data/spec/unit/actions/ensure_data_product_spec.rb +38 -0
- data/spec/unit/actions/ensure_technical_users_domain_spec.rb +51 -0
- data/spec/unit/actions/ensure_technical_users_project_spec.rb +72 -0
- data/spec/unit/actions/execute_schedules_spec.rb +94 -0
- data/spec/unit/actions/provision_clients_spec.rb +45 -0
- data/spec/unit/actions/purge_clients_spec.rb +47 -0
- data/spec/unit/actions/rename_existing_client_projects_spec.rb +54 -0
- data/spec/unit/actions/segments_filter_spec.rb +46 -0
- data/spec/unit/actions/shared_examples_for_user_actions.rb +26 -0
- data/spec/unit/actions/synchronize_cas_spec.rb +58 -0
- data/spec/unit/actions/synchronize_etls_in_segment_spec.rb +212 -0
- data/spec/unit/actions/synchronize_ldm_spec.rb +57 -0
- data/spec/unit/actions/synchronize_user_filters_spec.rb +146 -0
- data/spec/unit/actions/synchronize_user_groups_spec.rb +49 -0
- data/spec/unit/actions/synchronize_users_spec.rb +134 -0
- data/spec/unit/bricks/bricks_spec.rb +34 -0
- data/spec/unit/bricks/middleware/aws_middelware_spec.rb +98 -0
- data/spec/unit/bricks/middleware/bench_middleware_spec.rb +15 -0
- data/spec/unit/bricks/middleware/bulk_salesforce_middleware_spec.rb +15 -0
- data/spec/unit/bricks/middleware/gooddata_middleware_spec.rb +15 -0
- data/spec/unit/bricks/middleware/logger_middleware_spec.rb +30 -0
- data/spec/unit/bricks/middleware/restforce_middleware_spec.rb +15 -0
- data/spec/unit/bricks/middleware/stdout_middleware_spec.rb +15 -0
- data/spec/unit/bricks/middleware/twitter_middleware_spec.rb +15 -0
- data/spec/unit/cli/cli_spec.rb +17 -0
- data/spec/unit/cli/commands/cmd_auth_spec.rb +17 -0
- data/spec/unit/core/nil_logger_spec.rb +13 -0
- data/spec/unit/extensions/hash_spec.rb +22 -0
- data/spec/unit/godzilla/goodzilla_spec.rb +74 -0
- data/spec/unit/helpers/csv_helper_spec.rb +22 -0
- data/spec/unit/helpers/data_helper_spec.rb +67 -0
- data/spec/unit/helpers/global_helpers_spec.rb +264 -0
- data/spec/unit/helpers_spec.rb +254 -0
- data/spec/unit/lcm/user_bricks_helper_spec.rb +58 -0
- data/spec/unit/models/blueprint/attribute_sort_by_spec.rb +20 -0
- data/spec/unit/models/blueprint/attributes_spec.rb +28 -0
- data/spec/unit/models/blueprint/dataset_spec.rb +120 -0
- data/spec/unit/models/blueprint/labels_spec.rb +43 -0
- data/spec/unit/models/blueprint/project_blueprint_spec.rb +642 -0
- data/spec/unit/models/blueprint/reference_spec.rb +28 -0
- data/spec/unit/models/blueprint/schema_builder_spec.rb +36 -0
- data/spec/unit/models/blueprint/to_wire_spec.rb +195 -0
- data/spec/unit/models/execution_spec.rb +109 -0
- data/spec/unit/models/from_wire_spec.rb +301 -0
- data/spec/unit/models/metadata_spec.rb +140 -0
- data/spec/unit/models/metric_spec.rb +129 -0
- data/spec/unit/models/model_spec.rb +77 -0
- data/spec/unit/models/project_creator_spec.rb +90 -0
- data/spec/unit/models/project_spec.rb +94 -0
- data/spec/unit/models/report_result_data_spec.rb +194 -0
- data/spec/unit/models/to_manifest_spec.rb +136 -0
- data/spec/unit/models/user_filters/user_filter_builder_spec.rb +110 -0
- data/spec/unit/models/user_filters_spec.rb +95 -0
- data/spec/unit/models/variable_spec.rb +280 -0
- data/spec/unit/rest/polling_spec.rb +101 -0
- data/spec/unit/rest/resource_spec.rb +10 -0
- data/yard-server.sh +3 -0
- metadata +1207 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright (c) 2010-2017 GoodData Corporation. All rights reserved.
|
4
|
+
# This source code is licensed under the BSD-style license found in the
|
5
|
+
# LICENSE file in the root directory of this source tree.
|
6
|
+
|
7
|
+
require_relative 'schema_blueprint'
|
8
|
+
|
9
|
+
module GoodData
|
10
|
+
module Model
|
11
|
+
class DateDimension < GoodData::Model::SchemaBlueprint
|
12
|
+
# Returns urn of the date dataset
|
13
|
+
#
|
14
|
+
# @return [String]
|
15
|
+
def urn
|
16
|
+
data[:urn]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright (c) 2010-2017 GoodData Corporation. All rights reserved.
|
4
|
+
# This source code is licensed under the BSD-style license found in the
|
5
|
+
# LICENSE file in the root directory of this source tree.
|
6
|
+
|
7
|
+
require_relative 'blueprint_field'
|
8
|
+
|
9
|
+
module GoodData
|
10
|
+
module Model
|
11
|
+
class FactBlueprintField < BlueprintField
|
12
|
+
# Returns gd_data_type
|
13
|
+
#
|
14
|
+
# @return [String] returns gd_data_type of the fact
|
15
|
+
def gd_data_type
|
16
|
+
data[:gd_data_type] || Model::DEFAULT_FACT_DATATYPE
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright (c) 2010-2017 GoodData Corporation. All rights reserved.
|
4
|
+
# This source code is licensed under the BSD-style license found in the
|
5
|
+
# LICENSE file in the root directory of this source tree.
|
6
|
+
|
7
|
+
require_relative 'blueprint_field'
|
8
|
+
|
9
|
+
module GoodData
|
10
|
+
module Model
|
11
|
+
class LabelBlueprintField < BlueprintField
|
12
|
+
# Returns the attribute this label is referencing to
|
13
|
+
#
|
14
|
+
# @return [AttributeBlueprintField] the object representing attribute in the blueprint
|
15
|
+
def attribute
|
16
|
+
dataset_blueprint.attribute_for_label(self)
|
17
|
+
end
|
18
|
+
|
19
|
+
def reference_label?
|
20
|
+
data[:reference_label] == true || self == attribute.reference_label
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns gd_data_type
|
24
|
+
#
|
25
|
+
# @return [String] returns gd_data_type of the label
|
26
|
+
def gd_data_type
|
27
|
+
data[:gd_data_type] || Model::DEFAULT_ATTRIBUTE_DATATYPE
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns gd_data_type
|
31
|
+
#
|
32
|
+
# @return [String] returns gd_type of the label
|
33
|
+
def gd_type
|
34
|
+
data[:gd_type] || Model::DEFAULT_TYPE
|
35
|
+
end
|
36
|
+
|
37
|
+
# Validates the fields in the label
|
38
|
+
#
|
39
|
+
# @return [Array] returns list of the errors represented by hash structures
|
40
|
+
def validate
|
41
|
+
validate_presence_of(:id, :reference).map do |e|
|
42
|
+
{ type: :error, message: "Field \"#{e}\" is not defined or empty for label \"#{id}\"" }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,791 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright (c) 2010-2017 GoodData Corporation. All rights reserved.
|
4
|
+
# This source code is licensed under the BSD-style license found in the
|
5
|
+
# LICENSE file in the root directory of this source tree.
|
6
|
+
|
7
|
+
module GoodData
|
8
|
+
module Model
|
9
|
+
class ProjectBlueprint
|
10
|
+
attr_accessor :data
|
11
|
+
|
12
|
+
# Instantiates a project blueprint either from a file or from a string containing
|
13
|
+
# json. Also eats Hash for convenience.
|
14
|
+
#
|
15
|
+
# @param spec [String | Hash] value of an label you are looking for
|
16
|
+
# @return [GoodData::Model::ProjectBlueprint]
|
17
|
+
class << self
|
18
|
+
def from_json(spec)
|
19
|
+
if spec.is_a?(String)
|
20
|
+
if File.file?(spec)
|
21
|
+
ProjectBlueprint.new(MultiJson.load(File.read(spec), :symbolize_keys => true))
|
22
|
+
else
|
23
|
+
ProjectBlueprint.new(MultiJson.load(spec, :symbolize_keys => true))
|
24
|
+
end
|
25
|
+
else
|
26
|
+
ProjectBlueprint.new(spec)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def build(title, &block)
|
31
|
+
pb = ProjectBuilder.create(title, &block)
|
32
|
+
pb.to_blueprint
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Removes column from from the blueprint
|
37
|
+
#
|
38
|
+
# @param project [Hash | GoodData::Model::ProjectBlueprint] Project blueprint
|
39
|
+
# @param dataset [Hash | GoodData::Model::DatasetBlueprint] Dataset blueprint
|
40
|
+
# @param column_id [String] Column id
|
41
|
+
# @return [Hash | GoodData::Model::ProjectBlueprint] Returns changed blueprint
|
42
|
+
def self.remove_column!(project, dataset, column_id)
|
43
|
+
dataset = find_dataset(project, dataset)
|
44
|
+
col = dataset[:columns].find { |c| c[:id] == column_id }
|
45
|
+
dataset[:columns].delete(col)
|
46
|
+
project
|
47
|
+
end
|
48
|
+
|
49
|
+
# Removes dataset from blueprint. Dataset can be given as either a name
|
50
|
+
# or a DatasetBlueprint or a Hash representation.
|
51
|
+
#
|
52
|
+
# @param project [Hash | GoodData::Model::ProjectBlueprint] Project blueprint
|
53
|
+
# @param dataset_name [GoodData::Model::DatasetBlueprint | String | Hash] Dataset to be removed
|
54
|
+
# @param options [Hash] options
|
55
|
+
# @option options [Boolean] :include_date_dimensions Specifies whether to include date dimensions
|
56
|
+
# @option options [Boolean] :dd Specifies whether to include date dimensions
|
57
|
+
# @return [Hash] new project with removed dataset
|
58
|
+
def self.remove_dataset(project, dataset_id, options = {})
|
59
|
+
dataset = dataset_id.is_a?(String) ? find_dataset(project, dataset_id, options) : dataset_name
|
60
|
+
index = project[:datasets].index(dataset)
|
61
|
+
dupped_project = GoodData::Helpers.deep_dup(project)
|
62
|
+
dupped_project[:datasets].delete_at(index)
|
63
|
+
dupped_project
|
64
|
+
end
|
65
|
+
|
66
|
+
# Removes dataset from blueprint. Dataset can be given as either a name
|
67
|
+
# or a DatasetBlueprint or a Hash representation. This version mutates
|
68
|
+
# the dataset in place
|
69
|
+
#
|
70
|
+
# @param project [Hash | GoodData::Model::ProjectBlueprint] Project blueprint
|
71
|
+
# @param dataset_name [GoodData::Model::DatasetBlueprint | String | Hash] Dataset to be removed
|
72
|
+
# @param options [Hash] options
|
73
|
+
# @option options [Boolean] :include_date_dimensions Specifies whether to include date dimensions
|
74
|
+
# @option options [Boolean] :dd Specifies whether to include date dimensions
|
75
|
+
# @return [Hash] project with removed dataset
|
76
|
+
def self.remove_dataset!(project, dataset_id, options = {})
|
77
|
+
project = project.to_hash
|
78
|
+
dataset = dataset_id.is_a?(String) ? find_dataset(project, dataset_id, options) : dataset_id
|
79
|
+
index = project[:datasets].index(dataset)
|
80
|
+
project[:datasets].delete_at(index)
|
81
|
+
project
|
82
|
+
end
|
83
|
+
|
84
|
+
# Returns datasets of blueprint. Those can be optionally including
|
85
|
+
# date dimensions
|
86
|
+
#
|
87
|
+
# @param project [GoodData::Model::ProjectBlueprint | Hash] Project blueprint
|
88
|
+
# @param options [Hash] options
|
89
|
+
# @option options [Boolean] :include_date_dimensions Specifies whether to include date dimensions
|
90
|
+
# @option options [Boolean] :dd Specifies whether to include date dimensions
|
91
|
+
# @return [Array<Hash>]
|
92
|
+
def self.datasets(project_blueprint, options = {})
|
93
|
+
project_blueprint = project_blueprint.to_hash
|
94
|
+
include_date_dimensions = options[:include_date_dimensions] || options[:dd]
|
95
|
+
ds = (project_blueprint.to_hash[:datasets] || [])
|
96
|
+
if include_date_dimensions
|
97
|
+
ds + date_dimensions(project_blueprint)
|
98
|
+
else
|
99
|
+
ds
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# Returns blueprint with all references to one date dimensions changed to reference to the other. Changes the Blueprint in place.
|
104
|
+
#
|
105
|
+
# @param what [GoodData::Model::ReferenceBlueprintField | String] Date dimension reference field to be replaced.
|
106
|
+
# @param for_what [GoodData::Model::ReferenceBlueprintField | String] Date dimension reference field to be used as a replacement.
|
107
|
+
# @return [GoodData::Model::ProjectBlueprint]
|
108
|
+
def swap_date_dimension!(what, for_what)
|
109
|
+
what_id = what.respond_to?(:id) ? what.id : what
|
110
|
+
for_what_id = what.respond_to?(:id) ? for_what.id : for_what
|
111
|
+
|
112
|
+
fields = to_hash[:datasets].flat_map { |x| x[:columns] }.select { |x| x[:type] == :date }.select { |i| i[:dataset] == what_id }
|
113
|
+
fields.each { |f| f[:dataset] = for_what_id }
|
114
|
+
self
|
115
|
+
end
|
116
|
+
|
117
|
+
# Returns true if a dataset contains a particular dataset false otherwise
|
118
|
+
#
|
119
|
+
# @param project [GoodData::Model::ProjectBlueprint | Hash] Project blueprint
|
120
|
+
# @param name [GoodData::Model::DatasetBlueprint | String | Hash] Dataset
|
121
|
+
# @param options [Hash] options
|
122
|
+
# @option options [Boolean] :include_date_dimensions Specifies whether to include date dimensions
|
123
|
+
# @option options [Boolean] :dd Specifies whether to include date dimensions
|
124
|
+
# @return [Boolean]
|
125
|
+
def self.dataset?(project, name, options = {})
|
126
|
+
find_dataset(project, name, options)
|
127
|
+
true
|
128
|
+
rescue
|
129
|
+
false
|
130
|
+
end
|
131
|
+
|
132
|
+
# Returns dataset specified. It can check even for a date dimension
|
133
|
+
#
|
134
|
+
# @param project [GoodData::Model::ProjectBlueprint | Hash] Project blueprint
|
135
|
+
# @param obj [GoodData::Model::DatasetBlueprint | String | Hash] Dataset
|
136
|
+
# @param options [Hash] options
|
137
|
+
# @option options [Boolean] :include_date_dimensions Specifies whether to include date dimensions
|
138
|
+
# @option options [Boolean] :dd Specifies whether to include date dimensions
|
139
|
+
# @return [GoodData::Model::DatasetBlueprint]
|
140
|
+
def self.find_dataset(project_blueprint, obj, options = {})
|
141
|
+
return obj.to_hash if DatasetBlueprint.dataset_blueprint?(obj)
|
142
|
+
all_datasets = datasets(project_blueprint, options)
|
143
|
+
name = obj.respond_to?(:to_hash) ? obj.to_hash[:id] : obj
|
144
|
+
ds = all_datasets.find { |d| d[:id] == name }
|
145
|
+
fail "Dataset #{name} could not be found" if ds.nil?
|
146
|
+
ds
|
147
|
+
end
|
148
|
+
|
149
|
+
# Returns list of date dimensions
|
150
|
+
#
|
151
|
+
# @param project [GoodData::Model::ProjectBlueprint | Hash] Project blueprint
|
152
|
+
# @return [Array<Hash>]
|
153
|
+
def self.date_dimensions(project_blueprint)
|
154
|
+
project_blueprint.to_hash[:date_dimensions] || []
|
155
|
+
# dims.map {|dim| DateDimension.new(dim, project_blueprint)}
|
156
|
+
end
|
157
|
+
|
158
|
+
# Returns true if a date dimension of a given name exists in a bleuprint
|
159
|
+
#
|
160
|
+
# @param project [GoodData::Model::ProjectBlueprint | Hash] Project blueprint
|
161
|
+
# @param name [string] Date dimension
|
162
|
+
# @return [Boolean]
|
163
|
+
def self.date_dimension?(project, name)
|
164
|
+
find_date_dimension(project, name)
|
165
|
+
true
|
166
|
+
rescue
|
167
|
+
false
|
168
|
+
end
|
169
|
+
|
170
|
+
# Finds a date dimension of a given name in a bleuprint. If a dataset is
|
171
|
+
# not found it throws an exeception
|
172
|
+
#
|
173
|
+
# @param project [GoodData::Model::ProjectBlueprint | Hash] Project blueprint
|
174
|
+
# @param name [string] Date dimension
|
175
|
+
# @return [Hash]
|
176
|
+
def self.find_date_dimension(project, name)
|
177
|
+
ds = date_dimensions(project).find { |d| d[:id] == name }
|
178
|
+
fail "Date dimension #{name} could not be found" unless ds
|
179
|
+
ds
|
180
|
+
end
|
181
|
+
|
182
|
+
# Returns fields from all datasets
|
183
|
+
#
|
184
|
+
# @param project [GoodData::Model::ProjectBlueprint | Hash] Project blueprint
|
185
|
+
# @return [Array<Hash>]
|
186
|
+
def self.fields(project)
|
187
|
+
datasets(project).mapcat { |d| DatasetBlueprint.fields(d) }
|
188
|
+
end
|
189
|
+
|
190
|
+
# Changes the dataset through a builder. You provide a block and an istance of
|
191
|
+
# GoodData::Model::ProjectBuilder is passed in as the only parameter
|
192
|
+
#
|
193
|
+
# @return [GoodData::Model::ProjectBlueprint] returns changed project blueprint
|
194
|
+
def change(&block)
|
195
|
+
builder = ProjectBuilder.create_from_data(self)
|
196
|
+
block.call(builder)
|
197
|
+
@data = builder.to_hash
|
198
|
+
self
|
199
|
+
end
|
200
|
+
|
201
|
+
# Returns datasets of blueprint. Those can be optionally including
|
202
|
+
# date dimensions
|
203
|
+
#
|
204
|
+
# @param options [Hash] options
|
205
|
+
# @option options [Boolean] :include_date_dimensions Specifies whether to include date dimensions
|
206
|
+
# @option options [Boolean] :dd Specifies whether to include date dimensions
|
207
|
+
# @return [Array<GoodData::Model::DatasetBlueprint>]
|
208
|
+
def datasets(id = :all, options = {})
|
209
|
+
id = id.respond_to?(:id) ? id.id : id
|
210
|
+
dss = ProjectBlueprint.datasets(self, options).map do |d|
|
211
|
+
case d[:type]
|
212
|
+
when :date_dimension
|
213
|
+
DateDimension.new(d, self)
|
214
|
+
when :dataset
|
215
|
+
DatasetBlueprint.new(d, self)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
id == :all ? dss : dss.find { |d| d.id == id }
|
219
|
+
end
|
220
|
+
|
221
|
+
# Adds dataset to the blueprint
|
222
|
+
#
|
223
|
+
# @param a_dataset [Hash | GoodData::Model::SchemaBlueprint] dataset to be added
|
224
|
+
# @param index [Integer] number specifying at which position the new dataset should be added. If not specified it is added at the end
|
225
|
+
# @return [GoodData::Model::ProjectBlueprint] returns project blueprint
|
226
|
+
def add_dataset!(a_dataset, index = nil)
|
227
|
+
if index.nil? || index > datasets.length
|
228
|
+
data[:datasets] << a_dataset.to_hash
|
229
|
+
else
|
230
|
+
data[:datasets].insert(index, a_dataset.to_hash)
|
231
|
+
end
|
232
|
+
self
|
233
|
+
end
|
234
|
+
|
235
|
+
def add_date_dimension!(a_dimension, index = nil)
|
236
|
+
dim = a_dimension.to_hash
|
237
|
+
if index.nil? || index > date_dimensions.length
|
238
|
+
data[:date_dimensions] << dim
|
239
|
+
else
|
240
|
+
data[:date_dimensions].insert(index, dim)
|
241
|
+
end
|
242
|
+
self
|
243
|
+
end
|
244
|
+
|
245
|
+
# Adds column to particular dataset in the blueprint
|
246
|
+
#
|
247
|
+
# @param dataset [Hash | GoodData::Model::SchemaBlueprint] dataset to be added
|
248
|
+
# @param column_definition [Hash] Column definition to be added
|
249
|
+
# @return [GoodData::Model::ProjectBlueprint] returns project blueprint
|
250
|
+
def add_column!(dataset, column_definition)
|
251
|
+
ds = ProjectBlueprint.find_dataset(to_hash, dataset)
|
252
|
+
ds[:columns] << column_definition
|
253
|
+
self
|
254
|
+
end
|
255
|
+
|
256
|
+
# Removes column to particular dataset in the blueprint
|
257
|
+
#
|
258
|
+
# @param dataset [Hash | GoodData::Model::SchemaBlueprint] dataset to be added
|
259
|
+
# @param id [String] id of the column to be removed
|
260
|
+
# @return [GoodData::Model::ProjectBlueprint] returns project blueprint
|
261
|
+
def remove_column!(dataset, id)
|
262
|
+
ProjectBlueprint.remove_column!(to_hash, dataset, id)
|
263
|
+
self
|
264
|
+
end
|
265
|
+
|
266
|
+
# Moves column to particular dataset in the blueprint. It currently supports moving
|
267
|
+
# of attributes and facts only. The rest of the fields probably does not make sense
|
268
|
+
# In case of attribute it moves its labels as well.
|
269
|
+
#
|
270
|
+
# @param id [GoodData::Model::BlueprintField] column to be moved
|
271
|
+
# @param from_dataset [Hash | GoodData::Model::SchemaBlueprint] dataset from which the field should be moved
|
272
|
+
# @param to_dataset [Hash | GoodData::Model::SchemaBlueprint] dataset to which the field should be moved
|
273
|
+
# @return [GoodData::Model::ProjectBlueprint] returns project blueprint
|
274
|
+
def move!(col, from_dataset, to_dataset)
|
275
|
+
from_dataset = find_dataset(from_dataset)
|
276
|
+
to_dataset = find_dataset(to_dataset)
|
277
|
+
column = if col.is_a?(String)
|
278
|
+
from_dataset.find_column_by_id(col)
|
279
|
+
else
|
280
|
+
from_dataset.find_column(col)
|
281
|
+
end
|
282
|
+
fail "Column #{col} cannot be found in dataset #{from_dataset.id}" unless column
|
283
|
+
stuff = case column.type
|
284
|
+
when :attribute
|
285
|
+
[column] + column.labels
|
286
|
+
when :fact
|
287
|
+
[column]
|
288
|
+
when :reference
|
289
|
+
[column]
|
290
|
+
else
|
291
|
+
fail 'Duplicate does not support moving #{col.type} type of field'
|
292
|
+
end
|
293
|
+
stuff = stuff.map(&:data)
|
294
|
+
stuff.each { |c| remove_column!(from_dataset, c[:id]) }
|
295
|
+
stuff.each { |c| add_column!(to_dataset, c) }
|
296
|
+
self
|
297
|
+
end
|
298
|
+
|
299
|
+
def duplicate!(col, from_dataset, to_dataset)
|
300
|
+
from_dataset = find_dataset(from_dataset)
|
301
|
+
to_dataset = find_dataset(to_dataset)
|
302
|
+
column = if col.is_a?(String)
|
303
|
+
from_dataset.find_column_by_id(col)
|
304
|
+
else
|
305
|
+
from_dataset.find_column(col)
|
306
|
+
end
|
307
|
+
fail "Column #{col} cannot be found in dataset #{from_dataset.id}" unless column
|
308
|
+
stuff = case column.type
|
309
|
+
when :attribute
|
310
|
+
[column] + column.labels
|
311
|
+
when :fact
|
312
|
+
[column]
|
313
|
+
when :reference
|
314
|
+
[column]
|
315
|
+
else
|
316
|
+
fail 'Duplicate does not support moving #{col.type} type of field'
|
317
|
+
end
|
318
|
+
stuff.map(&:data).each { |c| add_column!(to_dataset, c) }
|
319
|
+
self
|
320
|
+
end
|
321
|
+
|
322
|
+
# Returns list of attributes from all the datasets in a blueprint
|
323
|
+
#
|
324
|
+
# @return [Array<Hash>]
|
325
|
+
def attributes
|
326
|
+
datasets.reduce([]) { |acc, elem| acc.concat(elem.attributes) }
|
327
|
+
end
|
328
|
+
|
329
|
+
# Returns list of attributes and anchors from all the datasets in a blueprint
|
330
|
+
#
|
331
|
+
# @return [Array<Hash>]
|
332
|
+
def attributes_and_anchors
|
333
|
+
datasets.mapcat(&:attributes_and_anchors)
|
334
|
+
end
|
335
|
+
|
336
|
+
# Is this a project blueprint?
|
337
|
+
#
|
338
|
+
# @return [Boolean] if it is
|
339
|
+
def project_blueprint?
|
340
|
+
true
|
341
|
+
end
|
342
|
+
|
343
|
+
# Returns list of date dimensions
|
344
|
+
#
|
345
|
+
# @return [Array<Hash>]
|
346
|
+
def date_dimensions
|
347
|
+
ProjectBlueprint.date_dimensions(self).map { |dd| GoodData::Model::DateDimension.new(dd, self) }
|
348
|
+
end
|
349
|
+
|
350
|
+
# Returns true if a dataset contains a particular dataset false otherwise
|
351
|
+
#
|
352
|
+
# @param name [GoodData::Model::DatasetBlueprint | String | Hash] Dataset
|
353
|
+
# @param options [Hash] options
|
354
|
+
# @option options [Boolean] :include_date_dimensions Specifies whether to include date dimensions
|
355
|
+
# @option options [Boolean] :dd Specifies whether to include date dimensions
|
356
|
+
# @return [Boolean]
|
357
|
+
def dataset?(name, options = {})
|
358
|
+
ProjectBlueprint.dataset?(to_hash, name, options)
|
359
|
+
end
|
360
|
+
|
361
|
+
# Returns SLI manifest for one dataset. This is used by our API to allow
|
362
|
+
# loading data. The method is on project blueprint because you need
|
363
|
+
# acces to whole project to be able to generate references
|
364
|
+
#
|
365
|
+
# @param dataset [GoodData::Model::DatasetBlueprint | Hash | String] Dataset
|
366
|
+
# @param mode [String] Method of loading. FULL or INCREMENTAL
|
367
|
+
# @return [Array<Hash>] a title
|
368
|
+
def dataset_to_manifest(dataset, mode = 'FULL')
|
369
|
+
ToManifest.dataset_to_manifest(self, dataset, mode)
|
370
|
+
end
|
371
|
+
|
372
|
+
# Duplicated blueprint
|
373
|
+
#
|
374
|
+
# @param a_blueprint [GoodData::Model::DatasetBlueprint] Dataset blueprint to be merged
|
375
|
+
# @return [GoodData::Model::DatasetBlueprint]
|
376
|
+
def dup
|
377
|
+
ProjectBlueprint.new(GoodData::Helpers.deep_dup(data))
|
378
|
+
end
|
379
|
+
|
380
|
+
# Returns list of facts from all the datasets in a blueprint
|
381
|
+
#
|
382
|
+
# @return [Array<Hash>]
|
383
|
+
def facts
|
384
|
+
datasets.mapcat(&:facts)
|
385
|
+
end
|
386
|
+
|
387
|
+
# Returns list of fields from all the datasets in a blueprint
|
388
|
+
#
|
389
|
+
# @return [Array<Hash>]
|
390
|
+
def fields
|
391
|
+
datasets.flat_map(&:fields)
|
392
|
+
end
|
393
|
+
|
394
|
+
# Returns dataset specified. It can check even for a date dimension
|
395
|
+
#
|
396
|
+
# @param name [GoodData::Model::DatasetBlueprint | String | Hash] Dataset
|
397
|
+
# @param options [Hash] options
|
398
|
+
# @option options [Boolean] :include_date_dimensions Specifies whether to include date dimensions
|
399
|
+
# @option options [Boolean] :dd Specifies whether to include date dimensions
|
400
|
+
# @return [GoodData::Model::DatasetBlueprint]
|
401
|
+
def find_dataset(name, options = {})
|
402
|
+
ds = datasets(name, options)
|
403
|
+
fail "Dataset \"#{name}\" could not be found" unless ds
|
404
|
+
ds
|
405
|
+
end
|
406
|
+
|
407
|
+
# Returns a dataset of a given name. If a dataset is not found it throws an exeception
|
408
|
+
#
|
409
|
+
# @param project [String] Dataset title
|
410
|
+
# @return [Array<Hash>]
|
411
|
+
def find_dataset_by_title(title)
|
412
|
+
ds = ProjectBlueprint.find_dataset_by_title(to_hash, title)
|
413
|
+
DatasetBlueprint.new(ds)
|
414
|
+
end
|
415
|
+
|
416
|
+
# Return list of datasets that are centers of the stars in datamart.
|
417
|
+
# This means these datasets are not referenced by anybody else
|
418
|
+
# In a good blueprint design these should be fact tables
|
419
|
+
#
|
420
|
+
# @return [Array<Hash>]
|
421
|
+
def find_star_centers
|
422
|
+
datasets.select { |d| d.referenced_by.empty? }
|
423
|
+
end
|
424
|
+
|
425
|
+
# Constructor
|
426
|
+
#
|
427
|
+
# @param init_data [ProjectBlueprint | Hash] Blueprint or a blueprint
|
428
|
+
# definition. If passed a hash it is used as data for new instance.
|
429
|
+
# If there is a ProjectBlueprint passed it is duplicated and a new
|
430
|
+
# instance is created.
|
431
|
+
# @return [ProjectBlueprint] A new project blueprint instance
|
432
|
+
def initialize(init_data)
|
433
|
+
some_data = if init_data.respond_to?(:project_blueprint?) && init_data.project_blueprint?
|
434
|
+
init_data.to_hash
|
435
|
+
elsif init_data.respond_to?(:to_blueprint)
|
436
|
+
init_data.to_blueprint.to_hash
|
437
|
+
else
|
438
|
+
init_data
|
439
|
+
end
|
440
|
+
@data = GoodData::Helpers.symbolize_keys(GoodData::Helpers.deep_dup(some_data))
|
441
|
+
(@data[:datasets] || []).each do |d|
|
442
|
+
d[:type] = d[:type].to_sym
|
443
|
+
d[:columns].each do |c|
|
444
|
+
c[:type] = c[:type].to_sym
|
445
|
+
end
|
446
|
+
end
|
447
|
+
(@data[:date_dimensions] || []).each do |d|
|
448
|
+
d[:type] = d[:type].to_sym
|
449
|
+
end
|
450
|
+
@data[:include_ca] = true if @data[:include_ca].nil?
|
451
|
+
end
|
452
|
+
|
453
|
+
def id
|
454
|
+
data[:id]
|
455
|
+
end
|
456
|
+
|
457
|
+
# Returns list of labels from all the datasets in a blueprint
|
458
|
+
#
|
459
|
+
# @return [Array<Hash>]
|
460
|
+
def labels
|
461
|
+
datasets.mapcat(&:labels)
|
462
|
+
end
|
463
|
+
|
464
|
+
# Experimental but a basis for automatic check of health of a project
|
465
|
+
#
|
466
|
+
# @param project [GoodData::Model::DatasetBlueprint | Hash | String] Dataset blueprint
|
467
|
+
# @return [Array<Hash>]
|
468
|
+
def lint(full = false)
|
469
|
+
errors = []
|
470
|
+
find_star_centers.each do |dataset|
|
471
|
+
next unless dataset.anchor?
|
472
|
+
errors << {
|
473
|
+
type: :anchor_on_fact_dataset,
|
474
|
+
dataset_name: dataset.name,
|
475
|
+
anchor_name: dataset.anchor[:name]
|
476
|
+
}
|
477
|
+
end
|
478
|
+
date_facts = datasets.mapcat(&:date_facts)
|
479
|
+
date_facts.each do |date_fact|
|
480
|
+
errors << {
|
481
|
+
type: :date_fact,
|
482
|
+
date_fact: date_fact[:name]
|
483
|
+
}
|
484
|
+
end
|
485
|
+
|
486
|
+
unique_titles = fields.map { |f| Model.title(f) }.uniq
|
487
|
+
(fields.map { |f| Model.title(f) } - unique_titles).each do |duplicate_title|
|
488
|
+
errors << {
|
489
|
+
type: :duplicate_title,
|
490
|
+
title: duplicate_title
|
491
|
+
}
|
492
|
+
end
|
493
|
+
|
494
|
+
datasets.select(&:wide?).each do |wide_dataset|
|
495
|
+
errors << {
|
496
|
+
type: :wide_dataset,
|
497
|
+
dataset: wide_dataset.name
|
498
|
+
}
|
499
|
+
end
|
500
|
+
|
501
|
+
if full
|
502
|
+
# GoodData::Attributes.all(:full => true).select { |attr| attr.used_by}
|
503
|
+
end
|
504
|
+
errors
|
505
|
+
end
|
506
|
+
|
507
|
+
# Merging two blueprints. The self blueprint is changed in place
|
508
|
+
#
|
509
|
+
# @param a_blueprint [GoodData::Model::DatasetBlueprint] Dataset blueprint to be merged
|
510
|
+
# @return [GoodData::Model::ProjectBlueprint]
|
511
|
+
def merge!(a_blueprint)
|
512
|
+
temp_blueprint = merge(a_blueprint)
|
513
|
+
@data = temp_blueprint.data
|
514
|
+
self
|
515
|
+
end
|
516
|
+
|
517
|
+
# Returns list of datasets which are referenced by given dataset. This can be
|
518
|
+
# optionally switched to return even date dimensions
|
519
|
+
#
|
520
|
+
# @param project [GoodData::Model::DatasetBlueprint | Hash | String] Dataset blueprint
|
521
|
+
# @return [Array<Hash>]
|
522
|
+
def referenced_by(dataset)
|
523
|
+
find_dataset(dataset, include_date_dimensions: true).referencing
|
524
|
+
end
|
525
|
+
|
526
|
+
def referencing(dataset)
|
527
|
+
datasets(:all, include_date_dimensions: true)
|
528
|
+
.flat_map(&:references)
|
529
|
+
.select { |r| r.dataset == dataset }
|
530
|
+
.map(&:dataset_blueprint)
|
531
|
+
end
|
532
|
+
|
533
|
+
# Removes dataset from blueprint. Dataset can be given as either a name
|
534
|
+
# or a DatasetBlueprint or a Hash representation.
|
535
|
+
#
|
536
|
+
# @param dataset_name [GoodData::Model::DatasetBlueprint | String | Hash] Dataset to be removed
|
537
|
+
# @param options [Hash] options
|
538
|
+
# @option options [Boolean] :include_date_dimensions Specifies whether to include date dimensions
|
539
|
+
# @option options [Boolean] :dd Specifies whether to include date dimensions
|
540
|
+
# @return [Hash] project with removed dataset
|
541
|
+
def remove_dataset(dataset_name, options = {})
|
542
|
+
ProjectBlueprint.remove_dataset(to_hash, dataset_name, options)
|
543
|
+
self
|
544
|
+
end
|
545
|
+
|
546
|
+
# Removes dataset from blueprint. Dataset can be given as either a name
|
547
|
+
# or a DatasetBlueprint or a Hash representation.
|
548
|
+
#
|
549
|
+
# @param dataset_name [GoodData::Model::DatasetBlueprint | String | Hash] Dataset to be removed
|
550
|
+
# @param options [Hash] options
|
551
|
+
# @option options [Boolean] :include_date_dimensions Specifies whether to include date dimensions
|
552
|
+
# @option options [Boolean] :dd Specifies whether to include date dimensions
|
553
|
+
# @return [Hash] project with removed dataset
|
554
|
+
def remove_dataset!(dataset_id, options = {})
|
555
|
+
ProjectBlueprint.remove_dataset!(to_hash, dataset_id, options)
|
556
|
+
self
|
557
|
+
end
|
558
|
+
|
559
|
+
# Removes all the labels from the anchor. This is a typical operation that people want to
|
560
|
+
# perform on fact tables
|
561
|
+
#
|
562
|
+
# @return [GoodData::Model::ProjectBlueprint] Returns changed blueprint
|
563
|
+
def strip_anchor!(dataset)
|
564
|
+
from_dataset = find_dataset(dataset)
|
565
|
+
stuff = dataset.anchor.labels.map(&:data)
|
566
|
+
stuff.each { |column| remove_column!(from_dataset, column[:id]) }
|
567
|
+
self
|
568
|
+
end
|
569
|
+
|
570
|
+
# Returns some reports that might get you started. They are just simple
|
571
|
+
# reports. Currently it is implemented by getting facts from star centers
|
572
|
+
# and randomly picking attributes form referenced datasets.
|
573
|
+
#
|
574
|
+
# @return [Array<Hash>]
|
575
|
+
def suggest_reports(options = {})
|
576
|
+
strategy = options[:strategy] || :stupid
|
577
|
+
case strategy
|
578
|
+
when :stupid
|
579
|
+
reports = suggest_metrics.reduce([]) do |a, e|
|
580
|
+
star, metrics = e
|
581
|
+
metrics.each(&:save)
|
582
|
+
reports_stubs = metrics.map do |m|
|
583
|
+
breaks = broken_by(star).map { |ds, a_m| ds.identifier_for(a_m) }
|
584
|
+
[breaks, m]
|
585
|
+
end
|
586
|
+
a.concat(reports_stubs)
|
587
|
+
end
|
588
|
+
reports.reduce([]) do |a, e|
|
589
|
+
attrs, metric = e
|
590
|
+
|
591
|
+
attrs.each do |attr|
|
592
|
+
a << GoodData::Report.create(:title => 'Fantastic report',
|
593
|
+
:top => [attr],
|
594
|
+
:left => metric)
|
595
|
+
end
|
596
|
+
a
|
597
|
+
end
|
598
|
+
end
|
599
|
+
end
|
600
|
+
|
601
|
+
# Returns some metrics that might get you started. They are just simple
|
602
|
+
# reports. Currently it is implemented by getting facts from star centers
|
603
|
+
# and randomly picking attributes form referenced datasets.
|
604
|
+
#
|
605
|
+
# @return [Array<Hash>]
|
606
|
+
def suggest_metrics
|
607
|
+
stars = find_star_centers
|
608
|
+
metrics = stars.map(&:suggest_metrics)
|
609
|
+
stars.zip(metrics)
|
610
|
+
end
|
611
|
+
|
612
|
+
alias_method :suggest_measures, :suggest_metrics
|
613
|
+
|
614
|
+
def to_blueprint
|
615
|
+
self
|
616
|
+
end
|
617
|
+
|
618
|
+
def refactor_split_df(dataset)
|
619
|
+
fail ValidationError unless valid?
|
620
|
+
o = find_dataset(dataset)
|
621
|
+
new_dataset = GoodData::Model::DatasetBlueprint.new({ type: :dataset, id: "#{o.id}_dim", columns: [] }, self)
|
622
|
+
new_dataset.change do |d|
|
623
|
+
d.add_anchor('vymysli_id')
|
624
|
+
d.add_label('label.vymysli_id', reference: 'vymysli_id')
|
625
|
+
end
|
626
|
+
nb = merge(new_dataset.to_blueprint)
|
627
|
+
o.attributes.each { |a| nb.move!(a, o, new_dataset.id) }
|
628
|
+
old = nb.find_dataset(dataset)
|
629
|
+
old.attributes.each do |a|
|
630
|
+
remove_column!(old, a)
|
631
|
+
end
|
632
|
+
old.change do |d|
|
633
|
+
d.add_reference(new_dataset.id)
|
634
|
+
end
|
635
|
+
nb
|
636
|
+
end
|
637
|
+
|
638
|
+
def refactor_split_facts(dataset, column_names, new_dataset_title)
|
639
|
+
fail ValidationError unless valid?
|
640
|
+
change do |p|
|
641
|
+
p.add_dataset(new_dataset_title) do |d|
|
642
|
+
d.add_anchor("#{new_dataset_title}.id")
|
643
|
+
end
|
644
|
+
end
|
645
|
+
dataset_to_refactor = find_dataset(dataset)
|
646
|
+
new_dataset = find_dataset(new_dataset_title)
|
647
|
+
column_names.each { |c| move!(c, dataset_to_refactor, new_dataset) }
|
648
|
+
dataset_to_refactor.references.each { |ref| duplicate!(ref, dataset_to_refactor, new_dataset) }
|
649
|
+
self
|
650
|
+
end
|
651
|
+
|
652
|
+
# Merging two blueprints. A new blueprint is created. The self one
|
653
|
+
# is nto mutated
|
654
|
+
#
|
655
|
+
# @param a_blueprint [GoodData::Model::DatasetBlueprint] Dataset blueprint to be merged
|
656
|
+
# @return [GoodData::Model::ProjectBlueprint]
|
657
|
+
def merge(a_blueprint)
|
658
|
+
temp_blueprint = dup
|
659
|
+
return temp_blueprint unless a_blueprint
|
660
|
+
a_blueprint.datasets.each do |dataset|
|
661
|
+
if temp_blueprint.dataset?(dataset.id)
|
662
|
+
local_dataset = temp_blueprint.find_dataset(dataset.id)
|
663
|
+
index = temp_blueprint.datasets.index(local_dataset)
|
664
|
+
local_dataset.merge!(dataset)
|
665
|
+
temp_blueprint.remove_dataset!(local_dataset.id)
|
666
|
+
temp_blueprint.add_dataset!(local_dataset, index)
|
667
|
+
else
|
668
|
+
temp_blueprint.add_dataset!(dataset.dup)
|
669
|
+
end
|
670
|
+
end
|
671
|
+
a_blueprint.date_dimensions.each do |dd|
|
672
|
+
if temp_blueprint.dataset?(dd.id, dd: true)
|
673
|
+
local_dim = temp_blueprint.data[:date_dimensions].find { |d| d[:id] == dd.id }
|
674
|
+
local_dim[:urn] = dd.urn
|
675
|
+
else
|
676
|
+
temp_blueprint.add_date_dimension!(dd.dup)
|
677
|
+
end
|
678
|
+
end
|
679
|
+
temp_blueprint
|
680
|
+
end
|
681
|
+
|
682
|
+
# Helper for storing the project blueprint into a file as JSON.
|
683
|
+
#
|
684
|
+
# @param filename [String] Name of the file where the blueprint should be stored
|
685
|
+
def store_to_file(filename)
|
686
|
+
File.open(filename, 'w') do |f|
|
687
|
+
f << JSON.pretty_generate(to_hash)
|
688
|
+
end
|
689
|
+
end
|
690
|
+
|
691
|
+
# Returns title of a dataset. If not present it is generated from the name
|
692
|
+
#
|
693
|
+
# @return [String] a title
|
694
|
+
def title
|
695
|
+
Model.title(to_hash) if to_hash[:title]
|
696
|
+
end
|
697
|
+
|
698
|
+
# Returns title of a dataset. If not present it is generated from the name
|
699
|
+
#
|
700
|
+
# @return [String] a title
|
701
|
+
def title=(a_title)
|
702
|
+
@data[:title] = a_title
|
703
|
+
end
|
704
|
+
|
705
|
+
# Returns Wire representation. This is used by our API to generate and
|
706
|
+
# change projects
|
707
|
+
#
|
708
|
+
# @return [Hash] a title
|
709
|
+
def to_wire
|
710
|
+
validate
|
711
|
+
ToWire.to_wire(data)
|
712
|
+
end
|
713
|
+
|
714
|
+
# Returns SLI manifest representation. This is used by our API to allow
|
715
|
+
# loading data
|
716
|
+
#
|
717
|
+
# @return [Array<Hash>] a title
|
718
|
+
def to_manifest
|
719
|
+
validate
|
720
|
+
ToManifest.to_manifest(to_hash)
|
721
|
+
end
|
722
|
+
|
723
|
+
# Returns hash representation of blueprint
|
724
|
+
#
|
725
|
+
# @return [Hash] a title
|
726
|
+
def to_hash
|
727
|
+
@data
|
728
|
+
end
|
729
|
+
|
730
|
+
# Validate the blueprint in particular if all references reference existing datasets and valid fields inside them.
|
731
|
+
#
|
732
|
+
# @return [Array] array of errors
|
733
|
+
def validate_references
|
734
|
+
stuff = datasets(:all, include_date_dimensions: true).flat_map(&:references).select do |ref|
|
735
|
+
begin
|
736
|
+
ref.dataset
|
737
|
+
false
|
738
|
+
rescue RuntimeError
|
739
|
+
true
|
740
|
+
end
|
741
|
+
end
|
742
|
+
stuff.map { |r| { type: :bad_reference, reference: r.data, referencing_dataset: r.data[:dataset] } }
|
743
|
+
end
|
744
|
+
|
745
|
+
# Validate the blueprint in particular if all ids must be unique and valid.
|
746
|
+
#
|
747
|
+
# @return [Array] array of errors
|
748
|
+
def validate_identifiers
|
749
|
+
ids = datasets.flat_map { |dataset| dataset.columns.map(&:id) }.compact
|
750
|
+
|
751
|
+
duplicated_ids = ids.select { |id| ids.count(id) > 1 }.uniq
|
752
|
+
errors = duplicated_ids.map { |id| { type: :duplicated_identifier, id: id } } || []
|
753
|
+
|
754
|
+
ids.uniq.each { |id| errors << { type: :invalid_identifier, id: id } if id !~ /^[\w.]+$/ }
|
755
|
+
|
756
|
+
errors
|
757
|
+
end
|
758
|
+
|
759
|
+
# Validate the blueprint and all its datasets return array of errors that are found.
|
760
|
+
#
|
761
|
+
# @return [Array] array of errors
|
762
|
+
def validate
|
763
|
+
errors = []
|
764
|
+
errors.concat validate_identifiers
|
765
|
+
errors.concat validate_references
|
766
|
+
errors.concat datasets.reduce([]) { |acc, elem| acc.concat(elem.validate) }
|
767
|
+
errors.concat datasets.reduce([]) { |acc, elem| acc.concat(elem.validate_gd_data_type_errors) }
|
768
|
+
errors
|
769
|
+
rescue
|
770
|
+
raise GoodData::ValidationError
|
771
|
+
end
|
772
|
+
|
773
|
+
# Validate the blueprint and all its datasets and return true if model is valid. False otherwise.
|
774
|
+
#
|
775
|
+
# @return [Boolean] is model valid?
|
776
|
+
def valid?
|
777
|
+
validate.empty?
|
778
|
+
end
|
779
|
+
|
780
|
+
def ==(other)
|
781
|
+
# to_hash == other.to_hash
|
782
|
+
return false unless id == other.id
|
783
|
+
return false unless title == other.title
|
784
|
+
left = to_hash[:datasets].map { |d| d[:columns].to_set }.to_set
|
785
|
+
right = other.to_hash[:datasets].map { |d| d[:columns].to_set }.to_set
|
786
|
+
return false unless left == right
|
787
|
+
true
|
788
|
+
end
|
789
|
+
end
|
790
|
+
end
|
791
|
+
end
|