Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ Notes:

**Metrics-specific options:**

**--keep-original-ids** - Keep original metric identifiers from Legacy. Otherwise the Cloud ID is derived from metric title and Legacy identfier.
**--keep-original-ids** - Keep original metric identifiers from Legacy. Otherwise the Cloud ID is derived from metric title and Legacy identifier.

**--ignore-folders** - Legacy folders of Metrics are not migrated to Cloud tags. Use if you used only tags for organizing the catalog in Legacy.

Expand Down
7 changes: 6 additions & 1 deletion src/gooddata_legacy2cloud/dashboards/cloud_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
DrillConverter,
)
from gooddata_legacy2cloud.dashboards.filter_context import FilterContext
from gooddata_legacy2cloud.helpers import dashboard_specific_insight_id, get_cloud_id
from gooddata_legacy2cloud.helpers import (
dashboard_specific_insight_id,
get_cloud_id,
parse_legacy_tags,
)
from gooddata_legacy2cloud.insights.period_comparison_insight import (
PeriodComparisonInsight,
)
Expand Down Expand Up @@ -491,6 +495,7 @@ def get(self):
"attributes": {
"title": self.title,
"description": self.meta["summary"],
"tags": parse_legacy_tags(self.meta),
"content": {
"attributeFilterConfigs": self.attribute_filter_configs,
"filterContextRef": self.filter_context_id,
Expand Down
11 changes: 11 additions & 0 deletions src/gooddata_legacy2cloud/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ def get_object_list(input):
return list(set(matches)) # get rid of duplicities


def parse_legacy_tags(meta: dict) -> list[str]:
"""Parses the space/comma-separated tags string from Legacy metadata into a list."""
tags_str = meta.get("tags", "")
return [
tag.strip()
for part in tags_str.split(",")
for tag in part.split()
if tag.strip()
]


def get_cloud_id(title: str, legacy_identifier: str) -> str:
"""
Returns the Cloud metric identifier.
Expand Down
3 changes: 2 additions & 1 deletion src/gooddata_legacy2cloud/insights/cloud_insight.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import logging
import uuid

from gooddata_legacy2cloud.helpers import get_cloud_id
from gooddata_legacy2cloud.helpers import get_cloud_id, parse_legacy_tags
from gooddata_legacy2cloud.id_mappings import IdMappings
from gooddata_legacy2cloud.insights.data_classes import InsightContext
from gooddata_legacy2cloud.insights.period_comparison_insight import (
Expand Down Expand Up @@ -518,6 +518,7 @@ def get(self):
"attributes": {
"title": self.title,
"description": self.description,
"tags": parse_legacy_tags(self.meta),
"createdAt": "",
"content": {
"filters": self.filters,
Expand Down
14 changes: 2 additions & 12 deletions src/gooddata_legacy2cloud/metrics/cloud_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import logging
from typing import Any

from gooddata_legacy2cloud.helpers import get_cloud_id
from gooddata_legacy2cloud.helpers import get_cloud_id, parse_legacy_tags
from gooddata_legacy2cloud.metrics.data_classes import MetricContext
from gooddata_legacy2cloud.metrics.cloud_maql import CloudMaql
from gooddata_legacy2cloud.metrics.utils import get_folders_names
Expand Down Expand Up @@ -47,17 +47,7 @@ def __init__(
)

def _get_tags(self):
"""
Prepares the tags for the metric.
@param tags_str: The metadata tags string.
"""
tags_str = self.meta.get("tags", "")
tags = [
tag.strip()
for part in tags_str.split(",")
for tag in part.split()
if tag.strip()
]
tags = parse_legacy_tags(self.meta)

# add Legacy folders to Cloud tags
if "folders" in self.metric_content and not self.ctx.ignore_folders:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from pydantic import BaseModel, Field

from gooddata_legacy2cloud.helpers import PP_DASHBOARD_PREFIX
from gooddata_legacy2cloud.helpers import PP_DASHBOARD_PREFIX, parse_legacy_tags
from gooddata_legacy2cloud.pp_dashboards.legacy_objects.pixel_perfect_dashboard import (
PixelPerfectDashboard,
Tab,
Expand Down Expand Up @@ -121,6 +121,7 @@ class Attributes(BaseModel):
title: str
content: Content
description: str | None = ""
tags: list[str] = Field(default_factory=list)


class CloudDashboard(BaseModel):
Expand Down Expand Up @@ -162,6 +163,7 @@ def create_from_legacy_definition(
attributes=Attributes(
title=f"[PP] {pixel_perfect_dashboard.meta.title} - {tab_idx:02} - {tab.title}",
content=Content(layout=Layout(sections=[])),
tags=parse_legacy_tags(pixel_perfect_dashboard.meta.model_dump()),
),
)

Expand All @@ -179,5 +181,6 @@ def create_tabbed_from_legacy_definition(
attributes=Attributes(
title=f"[PP] {pixel_perfect_dashboard.meta.title}",
content=Content(layout=Layout(sections=[])),
tags=parse_legacy_tags(pixel_perfect_dashboard.meta.model_dump()),
),
)
1 change: 1 addition & 0 deletions src/gooddata_legacy2cloud/pp_dashboards/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Meta(BaseModel):
identifier: str
title: str
uri: str
tags: str = ""
unlisted: Optional[int] = 0


Expand Down
14 changes: 10 additions & 4 deletions src/gooddata_legacy2cloud/reports/transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
"""

import logging
from typing import Any

from gooddata_legacy2cloud.helpers import REPORT_INSIGHT_PREFIX, get_cloud_id
from gooddata_legacy2cloud.helpers import (
REPORT_INSIGHT_PREFIX,
get_cloud_id,
parse_legacy_tags,
)
from gooddata_legacy2cloud.reports.charts import process_chart_report
from gooddata_legacy2cloud.reports.data_classes import (
ContextWithWarnings,
Expand Down Expand Up @@ -87,13 +92,14 @@ def transform_legacy_report(
meta.get("identifier", "unknown"), top_level_id
)

cloud_json = {
cloud_json: dict[str, Any] = {
"data": {
"id": top_level_id,
"type": "visualizationObject",
"attributes": {
"title": legacy_title,
"description": legacy_summary,
"tags": parse_legacy_tags(meta),
"content": cloud_content,
},
}
Expand All @@ -103,7 +109,7 @@ def transform_legacy_report(
warnings_list = warning_collector.get_warnings()
errors_list = warning_collector.get_errors()
if errors_list or warnings_list:
old_title = cloud_json["data"]["attributes"].get("title", "")
old_title = legacy_title
if errors_list:
new_prefix = "[ERROR] "
elif (
Expand All @@ -116,7 +122,7 @@ def transform_legacy_report(
if new_prefix and not old_title.startswith(new_prefix):
cloud_json["data"]["attributes"]["title"] = new_prefix + old_title

old_description = cloud_json["data"]["attributes"].get("description", "")
old_description = legacy_summary
messages_str = ""

if errors_list:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"attributes": {
"title": "Migration sample",
"description": "",
"tags": [],
"content": {
"attributeFilterConfigs": [],
"filterContextRef": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"attributes": {
"title": "dashboard with attribute filter with multiple labels 1",
"description": "",
"tags": [],
"content": {
"attributeFilterConfigs": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"attributes": {
"title": "Dashboard with dependent filters",
"description": "",
"tags": [],
"content": {
"attributeFilterConfigs": [],
"filterContextRef": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"attributes": {
"title": "Dashboard with Drills",
"description": "",
"tags": ["important", "is", "this", "very"],
"content": {
"attributeFilterConfigs": [],
"filterContextRef": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"attributes": {
"title": "Dashboard WITH KPIs and filters",
"description": "",
"tags": [],
"content": {
"attributeFilterConfigs": [],
"filterContextRef": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"attributes": {
"title": "[WARN] Dashboard with missing element lookup",
"description": "",
"tags": [],
"content": {
"attributeFilterConfigs": [],
"filterContextRef": {
Expand Down
1 change: 1 addition & 0 deletions tests/data/dashboards/test_cases/headlines_only_cloud.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"attributes": {
"title": "headlines only",
"description": "",
"tags": [],
"content": {
"attributeFilterConfigs": [],
"filterContextRef": {
Expand Down
1 change: 1 addition & 0 deletions tests/data/dashboards/test_cases/self_drill_cloud.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"attributes": {
"title": "self drill",
"description": "",
"tags": [],
"content": {
"attributeFilterConfigs": [],
"filterContextRef": {
Expand Down
1 change: 1 addition & 0 deletions tests/data/insights/test_cases/basic_insight_cloud.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"attributes": {
"title": "Avg item price per category",
"description": "",
"tags": ["finance", "revenue"],
"createdAt": "",
"content": {
"filters": [],
Expand Down
2 changes: 1 addition & 1 deletion tests/data/insights/test_cases/basic_insight_legacy.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"summary": "",
"author": "/gdc/account/profile/5cc081c981561ae1d3f81481b50f002c",
"identifier": "abb6SWS81yFv",
"tags": ""
"tags": "finance revenue"
},
"content": {
"buckets": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"attributes": {
"title": "has all additional date labels (GD date)",
"description": "",
"tags": [],
"createdAt": "",
"content": {
"filters": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"attributes": {
"title": "Headline as a KPI",
"description": "",
"tags": [],
"createdAt": "",
"content": {
"filters": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"attributes": {
"title": "using deprecated metric",
"description": "",
"tags": [],
"createdAt": "",
"content": {
"filters": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"attributes": {
"title": "with metric value filter",
"description": "",
"tags": [],
"createdAt": "",
"content": {
"filters": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"attributes": {
"title": "[WARN] with missing value in color definition",
"description": "\nMigration errors - missing values in filters: {'generic filters - positiveAttributeFilter: customer.country': ['/gdc/md/fkxyvp08rrrkfqss1ai656hvs0m77vl0/obj/633/elements?id=2527', '/gdc/md/fkxyvp08rrrkfqss1ai656hvs0m77vl0/obj/633/elements?id=2525']}\nMissing values in color mapping: {'colorMapping - 93e3f96a07ae4856b05b0294e743efde': '/gdc/md/fkxyvp08rrrkfqss1ai656hvs0m77vl0/obj/631/elements?id=2526', 'colorMapping - 5bd71afd702641e1bc2d795fcecae37d': '/gdc/md/fkxyvp08rrrkfqss1ai656hvs0m77vl0/obj/631/elements?id=2524'}",
"tags": [],
"createdAt": "",
"content": {
"filters": [
Expand Down
1 change: 1 addition & 0 deletions tests/data/insights/test_cases/with_top_filter_cloud.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"attributes": {
"title": "with TOP filter",
"description": "",
"tags": [],
"createdAt": "",
"content": {
"filters": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"title": "Test Pixel Perfect Dashboard",
"uri": "/gdc/md/test_workspace/obj/9001",
"summary": "Test dashboard for migration",
"tags": "finance revenue",
"unlisted": 0
},
"content": {
Expand Down
1 change: 1 addition & 0 deletions tests/data/reports/test_cases/basic_reports_cloud.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"attributes": {
"title": "[PP] sample report",
"description": "",
"tags": [],
"content": {
"buckets": [
{
Expand Down
2 changes: 2 additions & 0 deletions tests/data/reports/test_cases/date_null_filters_cloud.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"attributes": {
"title": "[WARN] [PP] manual date is null",
"description": "**migration warnings:**\n* Failed to create date NULL filter: Search Cloud Id - Unknown Cloud identifier signupdate.year\n\n---\n",
"tags": [],
"content": {
"buckets": [
{
Expand Down Expand Up @@ -63,6 +64,7 @@
"attributes": {
"title": "[WARN] [PP] manual date is not null",
"description": "**migration warnings:**\n* Failed to create date NULL filter: Search Cloud Id - Unknown Cloud identifier signupdate.year\n\n---\n",
"tags": [],
"content": {
"buckets": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"attributes": {
"title": "[PP] measure filter granularity subset",
"description": "",
"tags": [],
"content": {
"buckets": [
{
Expand Down
3 changes: 3 additions & 0 deletions tests/test_pp_dashboards_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def test_pp_dashboard_migration(
dumped = cloud_dashboards[0].model_dump(exclude_none=True)
assert "filterContextRef" not in dumped["attributes"]["content"]

# Tags migrated from legacy meta
assert cloud_dashboards[0].attributes.tags == ["finance", "revenue"]

# Smoke-check IDs and titles
for dashboard in cloud_dashboards:
assert dashboard.id.startswith("ppdash")
Expand Down
Loading