ferrero-opentext/Python-Version/test_multiple_master_ids.py
nickviljoen 444ac7ac6d Fix: PPR multiple master asset IDs now correctly populate MASTERASSETIDS field
Fixed issue where only 1 of 3 master asset IDs was being added to the
FERRERO.MASTERASSETIDS tabular field. The bug was caused by calling
_add_master_asset_id_field() before _add_master_asset_ids_field(),
which created the field with a single value and blocked the multi-value
method from adding all IDs.

Changes:
- metadata_extractor_mvp.py: Prioritize master_opentext_ids parameter
  using if/elif logic to prevent single-ID method from blocking multi-ID
- a2_to_a3_upload_polling.py: Load multiple master assets in PPR mode
- filename_parser.py: Parse multiple tracking IDs (e.g., ID1+ID2+ID3)
- query_db.py: Fix .env loading path
- Added documentation and test files for multiple master asset IDs

Tested in PPR with 3 tracking IDs (BqB8vo+SfUQ7m+laRJo0) - all 3 master
asset IDs now correctly appear in the metadata structure.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-03 21:02:09 +02:00

94 lines
3.2 KiB
Python

#!/usr/bin/env python3
"""
Test script to demonstrate MASTERASSETIDS field with multiple master asset IDs
This creates a test JSON structure showing how multiple master assets would be linked
"""
import json
# Example: A localized asset (derivative) that references TWO master assets
# Master 1: fc5c389776516bb58044c7d4bf479da458599baf (tracking: BqB8vo)
# Master 2: ad3948d72ea8550a338a600ae87a1bdd1968b066 (tracking: SfUQ7m)
test_field_structure = {
'id': 'FERRERO.MASTERASSETIDS',
'parent_table_id': 'FERRERO.TABULAR.FIELD.MASTERASSETIDS',
'type': 'com.artesia.metadata.MetadataTableField',
'values': [
# First master asset ID
{
'cascading_domain_value': False,
'domain_value': True,
'is_locked': False,
'value': {
'field_value': {
'type': 'string',
'value': 'fc5c389776516bb58044c7d4bf479da458599baf'
},
'type': 'com.artesia.metadata.DomainValue'
}
},
# Second master asset ID
{
'cascading_domain_value': False,
'domain_value': True,
'is_locked': False,
'value': {
'field_value': {
'type': 'string',
'value': 'ad3948d72ea8550a338a600ae87a1bdd1968b066'
},
'type': 'com.artesia.metadata.DomainValue'
}
},
# Third master asset ID (optional)
{
'cascading_domain_value': False,
'domain_value': True,
'is_locked': False,
'value': {
'field_value': {
'type': 'string',
'value': '020d76f957ec9f4ec0b18035a2d012cd3fd376c2'
},
'type': 'com.artesia.metadata.DomainValue'
}
}
]
}
print("=" * 80)
print("MULTIPLE MASTER ASSET IDS - TEST STRUCTURE")
print("=" * 80)
print()
print("Field ID:", test_field_structure['id'])
print("Parent Table:", test_field_structure['parent_table_id'])
print("Number of Master Asset IDs:", len(test_field_structure['values']))
print()
print("Master Asset IDs:")
for i, value_obj in enumerate(test_field_structure['values'], 1):
master_id = value_obj['value']['field_value']['value']
print(f" {i}. {master_id}")
print()
print("Full JSON Structure:")
print("-" * 80)
print(json.dumps(test_field_structure, indent=2))
print()
print("=" * 80)
print("TESTING NOTES")
print("=" * 80)
print()
print("To test if DAM accepts multiple IDs:")
print("1. Check if FERRERO.TABULAR.FIELD.MASTERASSETIDS schema allows multiple rows")
print("2. Verify with DAM admin if field has 'Allow Multiple Values' enabled")
print("3. Test upload with this structure to PPR environment")
print()
print("Current Implementation:")
print(" - Code adds ONE master ID (from tracking ID lookup)")
print(" - Supports Many-to-Many relationship conceptually")
print(" - Array structure ready for multiple values")
print()
print("To enable multiple IDs in production:")
print(" - Agency tool needs to send list of master tracking IDs")
print(" - Database schema needs multiple master references")
print(" - Code modification needed to look up multiple masters")
print()