gooddata 0.6.20 → 0.6.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -1
- data/DEPENDENCIES.md +816 -0
- data/LICENSE +1 -1
- data/LICENSE.rb +5 -0
- data/Rakefile +74 -22
- data/dependency_decisions.yml +102 -0
- data/gooddata.gemspec +39 -38
- data/lib/gooddata.rb +4 -0
- data/lib/gooddata/app/app.rb +4 -0
- data/lib/gooddata/bricks/base_downloader.rb +5 -1
- data/lib/gooddata/bricks/brick.rb +4 -0
- data/lib/gooddata/bricks/bricks.rb +5 -0
- data/lib/gooddata/bricks/middleware/aws_middleware.rb +5 -0
- data/lib/gooddata/bricks/middleware/base_middleware.rb +5 -0
- data/lib/gooddata/bricks/middleware/bench_middleware.rb +5 -0
- data/lib/gooddata/bricks/middleware/bulk_salesforce_middleware.rb +5 -0
- data/lib/gooddata/bricks/middleware/decode_params_middleware.rb +6 -0
- data/lib/gooddata/bricks/middleware/fs_download_middleware.rb +6 -0
- data/lib/gooddata/bricks/middleware/fs_upload_middleware.rb +6 -0
- data/lib/gooddata/bricks/middleware/gooddata_middleware.rb +6 -0
- data/lib/gooddata/bricks/middleware/logger_middleware.rb +5 -0
- data/lib/gooddata/bricks/middleware/middleware.rb +5 -0
- data/lib/gooddata/bricks/middleware/restforce_middleware.rb +4 -0
- data/lib/gooddata/bricks/middleware/stdout_middleware.rb +5 -0
- data/lib/gooddata/bricks/middleware/twitter_middleware.rb +5 -0
- data/lib/gooddata/bricks/middleware/undot_params_middleware.rb +4 -0
- data/lib/gooddata/bricks/pipeline.rb +4 -0
- data/lib/gooddata/bricks/utils.rb +4 -0
- data/lib/gooddata/cli/cli.rb +4 -0
- data/lib/gooddata/cli/commands/api_cmd.rb +4 -0
- data/lib/gooddata/cli/commands/auth_cmd.rb +4 -0
- data/lib/gooddata/cli/commands/console_cmd.rb +4 -0
- data/lib/gooddata/cli/commands/domain_cmd.rb +4 -0
- data/lib/gooddata/cli/commands/process_cmd.rb +4 -0
- data/lib/gooddata/cli/commands/project_cmd.rb +4 -0
- data/lib/gooddata/cli/commands/projects_cmd.rb +4 -0
- data/lib/gooddata/cli/commands/run_ruby_cmd.rb +4 -0
- data/lib/gooddata/cli/commands/scaffold_cmd.rb +4 -0
- data/lib/gooddata/cli/commands/user_cmd.rb +4 -0
- data/lib/gooddata/cli/hooks.rb +4 -0
- data/lib/gooddata/cli/shared.rb +4 -0
- data/lib/gooddata/cli/terminal.rb +4 -0
- data/lib/gooddata/client.rb +4 -0
- data/lib/gooddata/commands/api.rb +4 -0
- data/lib/gooddata/commands/auth.rb +4 -0
- data/lib/gooddata/commands/base.rb +4 -0
- data/lib/gooddata/commands/commands.rb +5 -0
- data/lib/gooddata/commands/datasets.rb +5 -1
- data/lib/gooddata/commands/datawarehouse.rb +4 -0
- data/lib/gooddata/commands/domain.rb +4 -0
- data/lib/gooddata/commands/process.rb +4 -0
- data/lib/gooddata/commands/project.rb +7 -9
- data/lib/gooddata/commands/projects.rb +4 -0
- data/lib/gooddata/commands/role.rb +4 -0
- data/lib/gooddata/commands/runners.rb +4 -0
- data/lib/gooddata/commands/scaffold.rb +4 -0
- data/lib/gooddata/commands/user.rb +4 -0
- data/lib/gooddata/connection.rb +83 -0
- data/lib/gooddata/core/core.rb +4 -0
- data/lib/gooddata/core/logging.rb +4 -0
- data/lib/gooddata/core/nil_logger.rb +4 -0
- data/lib/gooddata/core/project.rb +4 -0
- data/lib/gooddata/core/rest.rb +14 -16
- data/lib/gooddata/core/user.rb +4 -0
- data/lib/gooddata/data/data.rb +4 -0
- data/lib/gooddata/data/guesser.rb +4 -0
- data/lib/gooddata/exceptions/attr_element_not_found.rb +4 -0
- data/lib/gooddata/exceptions/command_failed.rb +4 -0
- data/lib/gooddata/exceptions/exceptions.rb +4 -0
- data/lib/gooddata/exceptions/execution_limit_exceeded.rb +4 -0
- data/lib/gooddata/exceptions/filter_maqlization.rb +16 -0
- data/lib/gooddata/exceptions/malformed_user.rb +15 -0
- data/lib/gooddata/exceptions/no_project_error.rb +4 -0
- data/lib/gooddata/exceptions/object_migration.rb +28 -0
- data/lib/gooddata/exceptions/project_not_found.rb +5 -0
- data/lib/gooddata/exceptions/uncomputable_report.rb +5 -0
- data/lib/gooddata/exceptions/user_in_different_domain.rb +4 -0
- data/lib/gooddata/exceptions/validation_error.rb +4 -0
- data/lib/gooddata/extensions/big_decimal.rb +4 -0
- data/lib/gooddata/extensions/enumerable.rb +4 -0
- data/lib/gooddata/extensions/extensions.rb +4 -0
- data/lib/gooddata/extensions/false.rb +4 -0
- data/lib/gooddata/extensions/hash.rb +4 -0
- data/lib/gooddata/extensions/nil.rb +4 -0
- data/lib/gooddata/extensions/numeric.rb +4 -0
- data/lib/gooddata/extensions/object.rb +4 -0
- data/lib/gooddata/extensions/symbol.rb +4 -0
- data/lib/gooddata/extensions/true.rb +4 -0
- data/lib/gooddata/extract.rb +4 -0
- data/lib/gooddata/goodzilla/goodzilla.rb +87 -77
- data/lib/gooddata/helpers/auth_helpers.rb +6 -2
- data/lib/gooddata/helpers/csv_helper.rb +4 -0
- data/lib/gooddata/helpers/data_helper.rb +4 -0
- data/lib/gooddata/helpers/global_helpers.rb +35 -6
- data/lib/gooddata/helpers/global_helpers_params.rb +34 -7
- data/lib/gooddata/helpers/helpers.rb +4 -0
- data/lib/gooddata/mixins/author.rb +4 -0
- data/lib/gooddata/mixins/content_getter.rb +4 -0
- data/lib/gooddata/mixins/content_property_reader.rb +4 -0
- data/lib/gooddata/mixins/content_property_writer.rb +4 -0
- data/lib/gooddata/mixins/contributor.rb +4 -0
- data/lib/gooddata/mixins/data_getter.rb +4 -0
- data/lib/gooddata/mixins/data_property_reader.rb +4 -0
- data/lib/gooddata/mixins/data_property_writer.rb +4 -0
- data/lib/gooddata/mixins/inspector.rb +4 -0
- data/lib/gooddata/mixins/is_attribute.rb +4 -0
- data/lib/gooddata/mixins/is_dimension.rb +4 -0
- data/lib/gooddata/mixins/is_fact.rb +4 -0
- data/lib/gooddata/mixins/is_label.rb +4 -0
- data/lib/gooddata/mixins/links.rb +4 -0
- data/lib/gooddata/mixins/md_finders.rb +4 -0
- data/lib/gooddata/mixins/md_id_to_uri.rb +4 -0
- data/lib/gooddata/mixins/md_json.rb +4 -0
- data/lib/gooddata/mixins/md_lock.rb +4 -0
- data/lib/gooddata/mixins/md_object_id.rb +5 -1
- data/lib/gooddata/mixins/md_object_indexer.rb +4 -0
- data/lib/gooddata/mixins/md_object_query.rb +4 -0
- data/lib/gooddata/mixins/md_relations.rb +4 -0
- data/lib/gooddata/mixins/meta_getter.rb +4 -0
- data/lib/gooddata/mixins/meta_property_reader.rb +4 -0
- data/lib/gooddata/mixins/meta_property_writer.rb +4 -0
- data/lib/gooddata/mixins/mixins.rb +4 -0
- data/lib/gooddata/mixins/not_attribute.rb +4 -0
- data/lib/gooddata/mixins/not_exportable.rb +4 -0
- data/lib/gooddata/mixins/not_fact.rb +4 -0
- data/lib/gooddata/mixins/not_label.rb +4 -0
- data/lib/gooddata/mixins/not_metric.rb +6 -0
- data/lib/gooddata/mixins/obj_id.rb +4 -0
- data/lib/gooddata/mixins/rest_getters.rb +4 -0
- data/lib/gooddata/mixins/rest_resource.rb +4 -0
- data/lib/gooddata/mixins/root_key_getter.rb +4 -0
- data/lib/gooddata/mixins/root_key_setter.rb +4 -0
- data/lib/gooddata/mixins/timestamps.rb +4 -0
- data/lib/gooddata/models/blueprint/anchor_field.rb +4 -0
- data/lib/gooddata/models/blueprint/attribute_field.rb +4 -0
- data/lib/gooddata/models/blueprint/blueprint.rb +4 -0
- data/lib/gooddata/models/blueprint/blueprint_field.rb +4 -0
- data/lib/gooddata/models/blueprint/dashboard_builder.rb +4 -0
- data/lib/gooddata/models/blueprint/dataset_blueprint.rb +6 -0
- data/lib/gooddata/models/blueprint/date_dimension.rb +4 -0
- data/lib/gooddata/models/blueprint/fact_field.rb +4 -0
- data/lib/gooddata/models/blueprint/label_field.rb +4 -0
- data/lib/gooddata/models/blueprint/project_blueprint.rb +6 -0
- data/lib/gooddata/models/blueprint/project_builder.rb +4 -0
- data/lib/gooddata/models/blueprint/reference_field.rb +4 -0
- data/lib/gooddata/models/blueprint/schema_blueprint.rb +4 -0
- data/lib/gooddata/models/blueprint/schema_builder.rb +4 -0
- data/lib/gooddata/models/blueprint/to_manifest.rb +17 -1
- data/lib/gooddata/models/blueprint/to_wire.rb +4 -0
- data/lib/gooddata/models/datawarehouse.rb +5 -0
- data/lib/gooddata/models/domain.rb +25 -7
- data/lib/gooddata/models/execution.rb +4 -0
- data/lib/gooddata/models/execution_detail.rb +4 -0
- data/lib/gooddata/models/from_wire.rb +4 -0
- data/lib/gooddata/models/invitation.rb +4 -0
- data/lib/gooddata/models/links.rb +4 -0
- data/lib/gooddata/models/membership.rb +4 -0
- data/lib/gooddata/models/metadata.rb +37 -10
- data/lib/gooddata/models/metadata/attribute.rb +6 -0
- data/lib/gooddata/models/metadata/dashboard.rb +54 -16
- data/lib/gooddata/models/metadata/dashboard/dashboard_item.rb +60 -0
- data/lib/gooddata/models/metadata/dashboard/filter_item.rb +15 -0
- data/lib/gooddata/models/metadata/dashboard/report_item.rb +51 -0
- data/lib/gooddata/models/metadata/dashboard_tab.rb +88 -0
- data/lib/gooddata/models/metadata/dataset.rb +4 -0
- data/lib/gooddata/models/metadata/dimension.rb +4 -0
- data/lib/gooddata/models/metadata/fact.rb +6 -0
- data/lib/gooddata/models/metadata/label.rb +15 -0
- data/lib/gooddata/models/metadata/metadata.rb +4 -0
- data/lib/gooddata/models/metadata/metric.rb +5 -4
- data/lib/gooddata/models/metadata/report.rb +62 -16
- data/lib/gooddata/models/metadata/report_definition.rb +44 -47
- data/lib/gooddata/models/metadata/variable.rb +4 -0
- data/lib/gooddata/models/model.rb +85 -36
- data/lib/gooddata/models/models.rb +4 -0
- data/lib/gooddata/models/module_constants.rb +4 -0
- data/lib/gooddata/models/process.rb +4 -0
- data/lib/gooddata/models/profile.rb +13 -0
- data/lib/gooddata/models/project.rb +173 -92
- data/lib/gooddata/models/project_creator.rb +18 -10
- data/lib/gooddata/models/project_metadata.rb +4 -0
- data/lib/gooddata/models/project_role.rb +4 -0
- data/lib/gooddata/models/report_data_result.rb +217 -125
- data/lib/gooddata/models/schedule.rb +140 -65
- data/lib/gooddata/models/tab_builder.rb +4 -0
- data/lib/gooddata/models/user_filters/mandatory_user_filter.rb +4 -0
- data/lib/gooddata/models/user_filters/user_filter.rb +4 -0
- data/lib/gooddata/models/user_filters/user_filter_builder.rb +98 -56
- data/lib/gooddata/models/user_filters/user_filters.rb +4 -0
- data/lib/gooddata/models/user_filters/variable_user_filter.rb +4 -0
- data/lib/gooddata/rest/client.rb +41 -38
- data/lib/gooddata/rest/connection.rb +91 -20
- data/lib/gooddata/rest/connections/rest_client_connection.rb +5 -1
- data/lib/gooddata/rest/object.rb +9 -1
- data/lib/gooddata/rest/object_factory.rb +5 -1
- data/lib/gooddata/rest/resource.rb +5 -1
- data/lib/gooddata/rest/rest.rb +4 -0
- data/lib/gooddata/version.rb +5 -1
- data/spec/bricks/bricks_spec.rb +4 -0
- data/spec/data/blueprints/test_project_model_spec.json +2 -2
- data/spec/data/gooddata_version_process/gooddata_version.rb +6 -0
- data/spec/data/hello_world_process/hello_world.rb +6 -0
- data/spec/data/manifests/test_project.json +5 -5
- 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 +6 -0
- data/spec/data/ruby_process/process.rb +6 -0
- data/spec/environment/default.rb +5 -0
- data/spec/environment/develop.rb +10 -5
- data/spec/environment/environment.rb +4 -0
- data/spec/environment/hotfix.rb +5 -1
- data/spec/environment/production.rb +4 -0
- data/spec/environment/release.rb +4 -0
- data/spec/environment/staging.rb +30 -0
- data/spec/environment/staging_3.rb +37 -0
- data/spec/helpers/blueprint_helper.rb +4 -0
- data/spec/helpers/cli_helper.rb +4 -0
- data/spec/helpers/connection_helper.rb +24 -17
- data/spec/helpers/crypto_helper.rb +6 -0
- data/spec/helpers/csv_helper.rb +4 -0
- data/spec/helpers/process_helper.rb +5 -1
- data/spec/helpers/project_helper.rb +34 -29
- data/spec/helpers/schedule_helper.rb +4 -0
- data/spec/helpers/spec_helper.rb +4 -0
- data/spec/integration/blueprint_updates_spec.rb +28 -20
- data/spec/integration/command_datawarehouse_spec.rb +6 -0
- data/spec/integration/command_projects_spec.rb +6 -4
- data/spec/integration/create_from_template_spec.rb +6 -0
- data/spec/integration/create_project_spec.rb +6 -0
- data/spec/integration/deprecated_load_spec.rb +58 -0
- data/spec/integration/full_process_schedule_spec.rb +9 -0
- data/spec/integration/full_project_spec.rb +63 -9
- data/spec/integration/over_to_user_filters_spec.rb +7 -2
- data/spec/integration/partial_md_export_import_spec.rb +6 -0
- data/spec/integration/project_spec.rb +12 -6
- data/spec/integration/rest_spec.rb +6 -2
- data/spec/integration/schedule_spec.rb +627 -0
- data/spec/integration/user_filters_spec.rb +122 -21
- data/spec/integration/variables_spec.rb +8 -15
- data/spec/logging_in_logging_out_spec.rb +58 -0
- data/spec/spec_helper.rb +10 -5
- data/spec/unit/bricks/bricks_spec.rb +4 -0
- data/spec/unit/bricks/middleware/aws_middelware_spec.rb +4 -0
- data/spec/unit/bricks/middleware/bench_middleware_spec.rb +4 -0
- data/spec/unit/bricks/middleware/bulk_salesforce_middleware_spec.rb +4 -0
- data/spec/unit/bricks/middleware/gooddata_middleware_spec.rb +4 -0
- data/spec/unit/bricks/middleware/logger_middleware_spec.rb +4 -0
- data/spec/unit/bricks/middleware/restforce_middleware_spec.rb +4 -0
- data/spec/unit/bricks/middleware/stdout_middleware_spec.rb +4 -0
- data/spec/unit/bricks/middleware/twitter_middleware_spec.rb +4 -0
- data/spec/unit/cli/cli_spec.rb +4 -0
- data/spec/unit/cli/commands/cmd_api_spec.rb +4 -0
- data/spec/unit/cli/commands/cmd_auth_spec.rb +4 -0
- data/spec/unit/cli/commands/cmd_domain_spec.rb +4 -0
- data/spec/unit/cli/commands/cmd_process_spec.rb +4 -0
- data/spec/unit/cli/commands/cmd_project_spec.rb +4 -0
- data/spec/unit/cli/commands/cmd_role_spec.rb +4 -0
- data/spec/unit/cli/commands/cmd_run_ruby_spec.rb +4 -0
- data/spec/unit/cli/commands/cmd_scaffold_spec.rb +6 -0
- data/spec/unit/cli/commands/cmd_user_spec.rb +6 -0
- data/spec/unit/commands/command_api_spec.rb +6 -0
- data/spec/unit/commands/command_auth_spec.rb +6 -0
- data/spec/unit/commands/command_dataset_spec.rb +10 -4
- data/spec/unit/commands/command_process_spec.rb +6 -0
- data/spec/unit/commands/command_projects_spec.rb +6 -0
- data/spec/unit/commands/command_scaffold_spec.rb +6 -0
- data/spec/unit/commands/command_user_spec.rb +6 -0
- data/spec/unit/core/connection_spec.rb +6 -0
- data/spec/unit/core/logging_spec.rb +4 -0
- data/spec/unit/core/nil_logger_spec.rb +4 -0
- data/spec/unit/core/project_spec.rb +4 -0
- data/spec/unit/data/guesser_spec.rb +6 -2
- data/spec/unit/extensions/hash_spec.rb +4 -0
- data/spec/unit/godzilla/goodzilla_spec.rb +4 -0
- data/spec/unit/helpers/csv_helper_spec.rb +4 -0
- data/spec/unit/helpers/data_helper_spec.rb +4 -0
- data/spec/unit/helpers/global_helpers_spec.rb +54 -0
- data/spec/unit/helpers_spec.rb +6 -1
- data/spec/unit/models/blueprint/attributes_spec.rb +5 -0
- data/spec/unit/models/blueprint/dataset_spec.rb +5 -0
- data/spec/unit/models/blueprint/labels_spec.rb +5 -0
- data/spec/unit/models/blueprint/project_blueprint_spec.rb +5 -0
- data/spec/unit/models/blueprint/reference_spec.rb +5 -0
- data/spec/unit/models/blueprint/schema_builder_spec.rb +4 -0
- data/spec/unit/models/blueprint/to_wire_spec.rb +5 -0
- data/spec/unit/models/domain_spec.rb +9 -7
- data/spec/unit/models/execution_spec.rb +6 -0
- data/spec/unit/models/from_wire_spec.rb +4 -0
- data/spec/unit/models/invitation_spec.rb +4 -0
- data/spec/unit/models/membership_spec.rb +4 -0
- data/spec/unit/models/metadata_spec.rb +46 -0
- data/spec/unit/models/metric_spec.rb +4 -0
- data/spec/unit/models/model_spec.rb +4 -0
- data/spec/unit/models/params_spec.rb +4 -0
- data/spec/unit/models/profile_spec.rb +4 -0
- data/spec/unit/models/project_creator_spec.rb +127 -0
- data/spec/unit/models/project_role_spec.rb +4 -0
- data/spec/unit/models/project_spec.rb +4 -0
- data/spec/unit/models/report_result_data_spec.rb +193 -0
- data/spec/unit/models/schedule_spec.rb +241 -386
- data/spec/unit/models/to_manifest_spec.rb +21 -0
- data/spec/unit/models/{unit_project.rb → unit_project_spec.rb} +21 -18
- data/spec/unit/models/user_filters_spec.rb +7 -1
- data/spec/unit/models/variable_spec.rb +6 -0
- data/spec/unit/rest/polling_spec.rb +8 -5
- data/spec/unit/rest/resource_spec.rb +4 -0
- metadata +190 -129
- data/.autotest +0 -2
- data/.travis.yml +0 -22
- data/examples.rb +0 -69
- data/lib/gooddata/models/data_result.rb +0 -38
- data/lib/gooddata/models/empty_result.rb +0 -57
- data/spec/unit/models/project_creator.rb +0 -73
@@ -1,4 +1,8 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright (c) 2010-2015 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.
|
2
6
|
|
3
7
|
require_relative 'project'
|
4
8
|
require_relative 'blueprint/project_blueprint'
|
@@ -60,7 +64,7 @@ module GoodData
|
|
60
64
|
|
61
65
|
response = client.get(link)
|
62
66
|
|
63
|
-
chunks = pick_correct_chunks(response['projectModelDiff']['updateScripts'])
|
67
|
+
chunks = pick_correct_chunks(response['projectModelDiff']['updateScripts'], opts)
|
64
68
|
if !chunks.nil? && !dry_run
|
65
69
|
chunks['updateScript']['maqlDdlChunks'].each do |chunk|
|
66
70
|
result = project.execute_maql(chunk)
|
@@ -88,6 +92,8 @@ module GoodData
|
|
88
92
|
end
|
89
93
|
end
|
90
94
|
|
95
|
+
alias_method :migrate_measures, :migrate_metrics
|
96
|
+
|
91
97
|
def load(project, spec)
|
92
98
|
if spec.key?(:uploads) # rubocop:disable Style/GuardClause
|
93
99
|
spec[:uploads].each do |load|
|
@@ -104,18 +110,20 @@ module GoodData
|
|
104
110
|
end
|
105
111
|
end
|
106
112
|
|
107
|
-
def pick_correct_chunks(chunks)
|
113
|
+
def pick_correct_chunks(chunks, opts = {})
|
114
|
+
preference = opts[:preference] || {}
|
108
115
|
# first is cascadeDrops, second is preserveData
|
109
116
|
rules = [
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
117
|
+
{ priority: 1, cascade_drops: false, preserve_data: true },
|
118
|
+
{ priority: 2, cascade_drops: false, preserve_data: false },
|
119
|
+
{ priority: 3, cascade_drops: true, preserve_data: true },
|
120
|
+
{ priority: 4, cascade_drops: true, preserve_data: false }
|
114
121
|
]
|
115
|
-
stuff = chunks.select { |chunk| chunk['updateScript']['maqlDdlChunks'] }
|
116
|
-
|
117
|
-
|
118
|
-
|
122
|
+
stuff = chunks.select { |chunk| chunk['updateScript']['maqlDdlChunks'] }.map { |chunk| { cascade_drops: chunk['updateScript']['cascadeDrops'], preserve_data: chunk['updateScript']['preserveData'], maql: chunk['updateScript']['maqlDdlChunks'], orig: chunk } }
|
123
|
+
results = GoodData::Helpers.join(rules, stuff, [:cascade_drops, :preserve_data], [:cascade_drops, :preserve_data], inner: true).sort_by { |l| l[:priority] }
|
124
|
+
|
125
|
+
pick = results.find { |r| r.values_at(:cascade_drops, :preserve_data) == preference.values_at(:cascade_drops, :preserve_data) } || results.first
|
126
|
+
pick[:orig] if pick
|
119
127
|
end
|
120
128
|
end
|
121
129
|
end
|
@@ -1,4 +1,8 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright (c) 2010-2015 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.
|
2
6
|
|
3
7
|
module GoodData
|
4
8
|
class ProjectMetadata
|
@@ -1,176 +1,268 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
|
3
|
-
|
2
|
+
#
|
3
|
+
# Copyright (c) 2010-2015 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.
|
4
6
|
|
5
7
|
module GoodData
|
6
|
-
class ReportDataResult <
|
7
|
-
|
8
|
-
|
8
|
+
class ReportDataResult < Rest::Object
|
9
|
+
class << self
|
10
|
+
# Does all the needed parsing on the apyload coming from the API and returns an instance of ReportDataResult
|
11
|
+
#
|
12
|
+
# @param [Hash] data Data coming from the API
|
13
|
+
# @return [GoodData::ReportDataResult] Returns new report data result
|
14
|
+
def from_xtab(data, options = {})
|
15
|
+
client = options[:client]
|
16
|
+
project = options[:project]
|
17
|
+
top = top_headers(data)
|
18
|
+
left = left_headers(data)
|
19
|
+
jank = GoodData::Helpers.zeroes(rows(top), cols(left), nil)
|
20
|
+
d = data(data)
|
21
|
+
stuff = d.empty? ? GoodData::Helpers.zeroes(rows(left), cols(top), nil) : d
|
22
|
+
|
23
|
+
a = jank.zip(top).map { |x, y| x + y }
|
24
|
+
b = left.zip(stuff).map { |x, y| x + y }
|
25
|
+
result = a + b
|
26
|
+
client ? client.create(ReportDataResult, data: result, top: rows(top), left: cols(left), project: project) : ReportDataResult.new(data: result, top: rows(top), left: cols(left))
|
27
|
+
end
|
9
28
|
|
10
|
-
|
29
|
+
private
|
11
30
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
31
|
+
def line(child)
|
32
|
+
children = child['children'] || []
|
33
|
+
return (child['first']..child['last']).to_a.map { [child['id']] } if children.empty?
|
34
|
+
children.flat_map { |c| line(c) }.map do |x|
|
35
|
+
child['id'].nil? ? x : [child['id']] + x
|
36
|
+
end
|
37
|
+
end
|
17
38
|
|
18
|
-
|
19
|
-
|
39
|
+
def root_line(root)
|
40
|
+
lookups = root['lookups']
|
41
|
+
header = line(root['tree'])
|
42
|
+
header.map { |l| l.each_with_index.map { |item, index| lookups[index][item] } }
|
43
|
+
end
|
44
|
+
|
45
|
+
def top_headers(data)
|
46
|
+
root = data['xtab_data']['columns']
|
47
|
+
root_line(root).transpose
|
48
|
+
end
|
49
|
+
|
50
|
+
def left_headers(data)
|
51
|
+
root = data['xtab_data']['rows']
|
52
|
+
root_line(root)
|
53
|
+
end
|
54
|
+
|
55
|
+
def cols(stuff)
|
56
|
+
stuff.first.count
|
57
|
+
end
|
58
|
+
|
59
|
+
def rows(stuff)
|
60
|
+
stuff.count
|
61
|
+
end
|
20
62
|
|
21
|
-
|
63
|
+
def data(data)
|
64
|
+
data['xtab_data']['data'].map { |row| row.map { |i| i ? BigDecimal(i) : i } }
|
65
|
+
end
|
22
66
|
end
|
23
67
|
|
24
|
-
|
25
|
-
|
26
|
-
|
68
|
+
# Returns
|
69
|
+
#
|
70
|
+
# @param [Hash] opts Data for the report
|
71
|
+
# @option opts [Array<Array>] :data The data as a matrix. First rows then cols
|
72
|
+
# @option opts [Number] :top Number of rows that are representing the top header
|
73
|
+
# @option opts [Number] :left Number of cols that are representing the left header
|
74
|
+
# @return [GoodData::ReportDataResult] Returns new report data result
|
75
|
+
def initialize(opts)
|
76
|
+
@data = opts[:data]
|
77
|
+
@top_headers_rows_nums = opts[:top]
|
78
|
+
@left_headers_cols_nums = opts[:left]
|
27
79
|
end
|
28
80
|
|
29
|
-
|
30
|
-
|
81
|
+
# Gives you new report result with top headers removed
|
82
|
+
#
|
83
|
+
# @return [GoodData::ReportDataResult] Returns new report data result
|
84
|
+
def without_top_headers
|
85
|
+
slice(@top_headers_rows_nums, 0)
|
31
86
|
end
|
32
87
|
|
33
|
-
|
34
|
-
|
88
|
+
# Gives you new report result with left headers removed
|
89
|
+
#
|
90
|
+
# @return [GoodData::ReportDataResult] Returns new report data result
|
91
|
+
def without_left_headers
|
92
|
+
slice(0, @left_headers_cols_nums)
|
35
93
|
end
|
36
94
|
|
37
|
-
|
95
|
+
# Gives you left headers as an Array
|
96
|
+
#
|
97
|
+
# @return [Array] Return left headers as Array of Arrays. The notation is of a matrix. First rows then cols.
|
98
|
+
def left_headers
|
99
|
+
return nil if @left_headers_cols_nums == 0
|
100
|
+
top = @left_headers_cols_nums - 1
|
101
|
+
without_top_headers.slice(0, [0, top]).to_a
|
102
|
+
end
|
38
103
|
|
39
|
-
|
40
|
-
|
104
|
+
# Gives you right headers as an Array
|
105
|
+
#
|
106
|
+
# @return [Array] Return top headers as Array of Arrays. The notation is of a matrix. First rows then cols.
|
107
|
+
def top_headers
|
108
|
+
return nil if @top_headers_rows_nums == 0
|
109
|
+
top = @top_headers_rows_nums - 1
|
110
|
+
without_left_headers.slice([0, top], 0).to_a
|
41
111
|
end
|
42
112
|
|
43
|
-
|
44
|
-
|
113
|
+
# Gives you data as a new ReportDataResult
|
114
|
+
#
|
115
|
+
# @return [Array] Return left headers as Array of Arrays. The notation is of a matrix. First rows then cols.
|
116
|
+
def data
|
117
|
+
slice(@top_headers_rows_nums, @left_headers_cols_nums)
|
118
|
+
end
|
119
|
+
|
120
|
+
def each
|
121
|
+
to_a.each
|
45
122
|
end
|
123
|
+
alias_method :each_line, :each
|
124
|
+
alias_method :each_row, :each
|
46
125
|
|
47
|
-
def
|
48
|
-
|
126
|
+
def each_column
|
127
|
+
size.last.times.map do |i|
|
128
|
+
col = map { |row| row[i] }
|
129
|
+
yield(col)
|
130
|
+
end
|
49
131
|
end
|
50
132
|
|
51
|
-
|
52
|
-
|
133
|
+
# Gives you data as a new ReportDataResult
|
134
|
+
#
|
135
|
+
# @return [Array] Return left headers as Array of Arrays. The notation is of a matrix. First rows then cols.
|
136
|
+
def to_a
|
137
|
+
@data
|
138
|
+
end
|
139
|
+
alias_method :to_table, :to_a
|
140
|
+
|
141
|
+
# Gives report as a table suitable for printing out
|
142
|
+
#
|
143
|
+
# @return [String]
|
144
|
+
def to_s(options = {})
|
145
|
+
with_indices = options[:index]
|
146
|
+
|
147
|
+
a = to_table.to_a
|
148
|
+
data = a.transpose
|
149
|
+
data.unshift((1..a.length).to_a) if with_indices
|
150
|
+
processed_data = data.each_with_index.map do |col, i|
|
151
|
+
col.unshift(i.zero? ? nil : i) if with_indices # inserts row labels #
|
152
|
+
w = col.map { |cell| cell.to_s.length }.max # w = "column width" #
|
153
|
+
col.each_with_index.map do |cell, j|
|
154
|
+
j.zero? ? cell.to_s.center(w) : cell.to_s.ljust(w)
|
155
|
+
end # alligns the column #
|
156
|
+
end
|
157
|
+
processed_data.transpose.map { |row| "[#{row.join(' | ')}]" }.unshift('').join("\n")
|
53
158
|
end
|
54
159
|
|
160
|
+
# Allows to pick particular row inside the report result
|
161
|
+
#
|
162
|
+
# @return [Array] Returns a row of data
|
163
|
+
def [](index)
|
164
|
+
@data[index]
|
165
|
+
end
|
55
166
|
alias_method :row, :[]
|
56
167
|
|
168
|
+
# Allows to pick particular column inside the report result
|
169
|
+
#
|
170
|
+
# @return [Array] Returns a column of data. The column is returned transposed
|
57
171
|
def column(index)
|
58
|
-
|
172
|
+
transpose[index]
|
59
173
|
end
|
60
174
|
|
61
|
-
|
62
|
-
|
175
|
+
# Is the report without any data? This can be caused by the fact that the filters are too restrictive or data are not loaded in
|
176
|
+
#
|
177
|
+
# @return [Array] Returns true if data result is empty
|
178
|
+
def empty?
|
179
|
+
row, cols = size
|
180
|
+
row == 0 && cols == 0
|
63
181
|
end
|
64
182
|
|
65
|
-
|
66
|
-
|
183
|
+
# Allows you to test if a report contains a row.
|
184
|
+
#
|
185
|
+
# @param [Array<String | Number>] row Row that you want to test. It is looking for the whole row. If the headers are getting in the way use #without_left_headers or #without_top_headers
|
186
|
+
# @return [Array] Returns true if data are inside a report
|
187
|
+
def include_row?(row)
|
188
|
+
@data.include?(row)
|
67
189
|
end
|
68
190
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
191
|
+
# Allows you to test if a report contains a column.
|
192
|
+
#
|
193
|
+
# @param [Array<String | Number>] row Row that you want to test. It is looking for the whole row. If the headers are getting in the way use #without_left_headers or #without_top_headers
|
194
|
+
# @return [Array] Returns true if data are inside a report
|
195
|
+
def include_column?(col)
|
196
|
+
transpose.include_row?(col)
|
75
197
|
end
|
76
198
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
csv_table.each do |row|
|
83
|
-
differences << row unless other_table.find { |r| r == row }
|
84
|
-
end
|
85
|
-
differences
|
199
|
+
# Returns the size of the report
|
200
|
+
#
|
201
|
+
# @return [Array<Number>] The size of the report result as an array. First element is rows second is columns
|
202
|
+
def size
|
203
|
+
[@data.size, @data.empty? ? 0 : @data.first.size]
|
86
204
|
end
|
87
205
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
def each_level(table, level, children, lookup)
|
95
|
-
max_level = level + 1
|
96
|
-
children.each do |kid|
|
97
|
-
first = kid['first']
|
98
|
-
last = kid['last']
|
99
|
-
repetition = last - first + 1
|
100
|
-
repetition.times do |i|
|
101
|
-
table[first + i] ||= []
|
102
|
-
if kid['type'] == 'total'
|
103
|
-
table[first + i][level] = kid['id']
|
104
|
-
else
|
105
|
-
table[first + i][level] = lookup[level][kid['id'].to_s]
|
106
|
-
end
|
107
|
-
end
|
108
|
-
unless kid['children'].empty?
|
109
|
-
new_level = each_level(table, level + 1, kid['children'], lookup)
|
110
|
-
max_level = [max_level, new_level].max
|
111
|
-
end
|
112
|
-
end
|
113
|
-
max_level
|
206
|
+
# Transposes data and returns as new data result
|
207
|
+
#
|
208
|
+
# @return [GoodData::ReportDataResult] Returns new report data result with flipped columns and rows
|
209
|
+
def transpose
|
210
|
+
ReportDataResult.new(data: to_a.transpose, top: @left_headers_cols_nums, left: @top_headers_rows_nums)
|
114
211
|
end
|
115
212
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
213
|
+
# Gives you report result with a subset of data starting at position rows, cols
|
214
|
+
#
|
215
|
+
# @param [Number] rows Position where you want to slice your row. Currently accepts only number
|
216
|
+
# @param [Number] cols Position where you want to slice your row. Currently accepts only number
|
217
|
+
# @return [GoodData::ReportDataResult] Returns new report data result sliced data
|
218
|
+
def slice(rows, cols)
|
219
|
+
rows = rows.is_a?(Enumerable) ? rows : [rows, size.first]
|
220
|
+
cols = cols.is_a?(Enumerable) ? cols : [cols, size.last]
|
221
|
+
new_data = @data[rows.first..rows.last].map { |col| col[cols.first..cols.last] }
|
222
|
+
if client
|
223
|
+
client.create(ReportDataResult, data: new_data, top: @top_headers_rows_nums - rows.first, left: @left_headers_cols_nums - cols.first, project: project)
|
123
224
|
else
|
124
|
-
|
125
|
-
size = each_level(headers, 0, rows['tree']['children'], rows['lookups'])
|
225
|
+
ReportDataResult.new(data: new_data, top: @top_headers_rows_nums - rows.first, left: @left_headers_cols_nums - cols.first, project: project)
|
126
226
|
end
|
127
|
-
return headers, size # rubocop:disable RedundantReturn
|
128
227
|
end
|
129
228
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
size = 0
|
137
|
-
else
|
138
|
-
headers = []
|
139
|
-
size = each_level(headers, 0, columns['tree']['children'], columns['lookups'])
|
140
|
-
end
|
229
|
+
# Returns the size of the the data portion of report
|
230
|
+
#
|
231
|
+
# @return [Array<Number>] The size of the report result as an array. First element is rows second is columns
|
232
|
+
def data_size
|
233
|
+
data.size
|
234
|
+
end
|
141
235
|
|
142
|
-
|
236
|
+
def ==(other)
|
237
|
+
return false if size != other.size
|
238
|
+
@data == other.to_a
|
143
239
|
end
|
144
240
|
|
145
|
-
def
|
146
|
-
|
147
|
-
|
148
|
-
(headers_height).times do |j|
|
149
|
-
table[headers_width + i] ||= []
|
150
|
-
# puts "[#{headers_width + i}][#{j}] #{column_headers[i][j]}"
|
151
|
-
table[headers_width + i][j] = column_headers[i][j]
|
152
|
-
end
|
153
|
-
end
|
241
|
+
def eq?(other)
|
242
|
+
self == other
|
243
|
+
end
|
154
244
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
245
|
+
# Implements subtraction. Works only on reports that have same number of columns. Gives you columns that are not in other.
|
246
|
+
#
|
247
|
+
# @param [GoodData::ReportDataResult] other The other report result
|
248
|
+
# @return [Array<Array>] Returns rows that are not contained in other
|
249
|
+
def -(other)
|
250
|
+
fail 'Seems you are not using a data result as a parameter' unless other.respond_to?(:size)
|
251
|
+
message = 'Results do not have compatible sizes. Subtracting the dataresults works row wise so you have to have the same number of columns'
|
252
|
+
fail message if size.last != other.size.last
|
253
|
+
to_a - other.to_a
|
254
|
+
end
|
163
255
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
256
|
+
# Implements diff. Works only on reports that have same number of columns (because it uses #- behind the scene).
|
257
|
+
#
|
258
|
+
# @param [GoodData::ReportDataResult] other The other report result
|
259
|
+
# @return [Hash] Returns a hash that gives you the differences in the report results
|
260
|
+
def diff(other)
|
261
|
+
{
|
262
|
+
added: other - self,
|
263
|
+
removed: self - other,
|
264
|
+
same: @data & other.to_a
|
265
|
+
}
|
174
266
|
end
|
175
267
|
end
|
176
268
|
end
|