ADR-017: AD_Element Description Management

<!-- MADR 3.0 Template - Markdown Any Decision Records -->

Status

Proposed

Date

2025-12-06

Deciders

Context and Problem Statement

The iDempiere Application Dictionary contains thousands of AD_Element records that define terminology (Name, PrintName, Description, Help) for columns across the system. Many elements have missing or poor-quality Description and Help text. Current state analysis shows:

Manual documentation is time-consuming and inconsistent. A systematic approach is needed that combines:

  1. Pattern-based automatic generation for predictable columns (_UU, _ID, Is*, Qty*, Amt*, Date*, _Acct)
  2. Java code analysis to extract business logic context
  3. AI-assisted generation for complex descriptions
  4. Migration script generation for PostgreSQL and Oracle

Decision Drivers

Considered Options

  1. Keep Python scripts standalone - Maintain separate Python tooling
  2. Full Java port - Rewrite all functionality in Java within idempiere-cli
  3. Hybrid approach - CLI orchestration with Python utilities and AI agent integration

Decision Outcome

Chosen option: "Hybrid approach", because it maximizes reuse of proven Python logic while providing CLI integration, AI enhancement, and future path to Java-native implementation.

Confirmation

Pros and Cons of the Options

Option 1: Keep Python scripts standalone

Keep Python scripts in .claude/tools/element-docs/ directory.

Option 2: Full Java port

Rewrite all Python scripts as Java services.

Option 3: Hybrid approach (Chosen)

CLI orchestration calling Python scripts + AI agent for complex cases.

Architecture

Component Overview

┌────────────────────────────────────────────────────────────────────────┐
│                        idempiere-cli                                   │
├────────────────────────────────────────────────────────────────────────┤
│  Commands                                                              │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────────┐    │
│  │ element describe│  │ element analyze │  │ element migrate     │    │
│  └────────┬────────┘  └────────┬────────┘  └──────────┬──────────┘    │
│           │                    │                       │               │
├───────────┼────────────────────┼───────────────────────┼───────────────┤
│  Services │                    │                       │               │
│  ┌────────▼────────────────────▼───────────────────────▼──────────┐   │
│  │               ElementDescriptionService                         │   │
│  │  ┌─────────────────┐  ┌──────────────────┐  ┌───────────────┐  │   │
│  │  │ PatternGenerator│  │ JavaCodeAnalyzer │  │ MigrationGen  │  │   │
│  │  └─────────────────┘  └──────────────────┘  └───────────────┘  │   │
│  └────────────────────────────────────────────────────────────────┘   │
│                                    │                                   │
│  ┌─────────────────────────────────▼──────────────────────────────┐   │
│  │                   AI Agent Integration                          │   │
│  │  ┌──────────────────────────────────────────────────────────┐  │   │
│  │  │  idempiere-description-writer (Claude Code Agent)        │  │   │
│  │  │  - Pattern-based generation rules                        │  │   │
│  │  │  - ADR-001 documentation standards                       │  │   │
│  │  │  - Business context analysis                             │  │   │
│  │  └──────────────────────────────────────────────────────────┘  │   │
│  └────────────────────────────────────────────────────────────────┘   │
└────────────────────────────────────────────────────────────────────────┘
                                    │
                                    ▼
┌────────────────────────────────────────────────────────────────────────┐
│                      External Resources                                │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────────┐    │
│  │  Seed Database  │  │  Java Source    │  │  REST API           │    │
│  │  (Adempiere_pg) │  │  (M*.java)      │  │  (AD_Element)       │    │
│  └─────────────────┘  └─────────────────┘  └─────────────────────┘    │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────────┐    │
│  │  Translation    │  │  GitHub Repos   │  │  2Pack XML          │    │
│  │  XML Export     │  │  (raw files)    │  │  Import/Export      │    │
│  └─────────────────┘  └─────────────────┘  └─────────────────────┘    │
└────────────────────────────────────────────────────────────────────────┘

CLI Commands

element describe

Generate descriptions for AD_Element records.

# Generate descriptions for all missing elements
idempiere-cli element describe --missing

# Generate for specific pattern
idempiere-cli element describe --pattern &quot;_UU&quot;
idempiere-cli element describe --pattern &quot;Is*&quot;

# Generate for specific element
idempiere-cli element describe --column &quot;M_Product_ID&quot;

# Use AI for complex descriptions
idempiere-cli element describe --ai --column &quot;QtyReserved&quot;

# Output formats
idempiere-cli element describe --missing --format json
idempiere-cli element describe --missing --format sql
idempiere-cli element describe --missing --format 2pack

element analyze

Analyze elements and extract context.

# Parse seed database for element context
idempiere-cli element analyze --seed /path/to/Adempiere_pg.dmp

# Extract Java business logic
idempiere-cli element analyze --java /path/to/idempiere/org.adempiere.base

# Find missing descriptions
idempiere-cli element analyze --missing --output element_gaps.json

# Categorize by domain
idempiere-cli element analyze --categorize

element migrate

Generate migration scripts.

# Generate migration for all missing descriptions
idempiere-cli element migrate --missing --output /path/to/migration

# Generate for specific category
idempiere-cli element migrate --category &quot;Accounting&quot;

# Preview without generating files
idempiere-cli element migrate --missing --dry-run

Data Sources

The CLI can extract AD_Element data from multiple sources:

1. REST API (Primary)

Uses iDempiere REST Web Services to query AD_Element and AD_Element_Trl:

# Query elements via REST API
idempiere-cli element analyze --rest --filter &quot;Description IS NULL&quot;

# Export translations via REST
idempiere-cli element describe --rest --lang es_ES

REST endpoints used:

2. Translation XML Export/Import

Leverages iDempiere's core Translation.java class for XML format:

# Export element translations to XML
idempiere-cli translation export --table AD_Element --lang en_US

# Import updated descriptions from XML
idempiere-cli translation import --file AD_Element_Trl_en_US.xml

Translation XML format (from Translation.java):

&lt;idempiereTrl table=&quot;AD_Element_Trl&quot; language=&quot;en_US&quot;&gt;
  &lt;row id=&quot;100&quot; trl=&quot;Y&quot;&gt;
    &lt;value column=&quot;Name&quot;&gt;Active&lt;/value&gt;
    &lt;value column=&quot;PrintName&quot;&gt;Active&lt;/value&gt;
    &lt;value column=&quot;Description&quot;&gt;The record is active in the system&lt;/value&gt;
    &lt;value column=&quot;Help&quot;&gt;There are two methods of making records unavailable...&lt;/value&gt;
  &lt;/row&gt;
&lt;/idempiereTrl&gt;

3. Seed Database (Offline)

Parse PostgreSQL seed dump for offline analysis:

# Download and parse seed database
curl -L -o Adempiere_pg.jar https://raw.githubusercontent.com/idempiere/binary.file/master/database/12/Adempiere_pg.jar
unzip Adempiere_pg.jar Adempiere_pg.dmp
idempiere-cli element analyze --seed Adempiere_pg.dmp

4. GitHub Raw Files

Fetch translation files directly from GitHub repositories:

# Fetch from iDempiere core translations
idempiere-cli element fetch --github idempiere/idempiere --path migration/i12.0/oracle/

# Fetch from community translations
idempiere-cli element fetch --github globalqss/idempiere-es --path translation/es_ES/

5. 2Pack XML

Export/import as 2Pack XML for deployment:

# Export elements as 2Pack
idempiere-cli element migrate --format 2pack --output element_descriptions.zip

# Import via existing 2pack command
idempiere-cli 2pack import --file element_descriptions.zip

Pattern-Based Generation Rules

Based on proven Python implementation patterns:

Pattern Description Template Help Template
*_UU Immutable Universally Unique Identifier The {Name} is an immutable UUID that uniquely identifies this record across systems.
*_ID {Entity} reference The {Name} field links to the {Entity} record.
Is* Indicates if {condition} The {Name} checkbox indicates {condition}.
Qty* Quantity of {subject} The {Name} field stores the quantity of {subject}.
Amt* Amount for {purpose} The {Name} field stores the monetary amount for {purpose}.
Date* Date of {event} The {Name} field records the date when {event} occurred.
*_Acct Account for {purpose} The {Name} field defines the accounting configuration for {purpose}.

Standard Columns

Column Description
Created Date this record was created
Updated Date this record was last updated
CreatedBy User who created this record
UpdatedBy User who last updated this record
IsActive The record is active in the system
Processing Process is currently executing
Processed The document has been processed
Posted Accounting entries have been generated
Value Search key for the record
Name Alphanumeric identifier of the entity
Description Optional short description of the record
DocumentNo Document sequence number
SeqNo Method of ordering records; lowest number comes first

Business Logic Enhancement

Java code analysis extracts:

  1. Validation rules: FillMandatory → "Required field"
  2. Read-only conditions: Cannot modify when parent is processed → "Read-only after processing"
  3. Calculations: Calculated by multiplication → "Calculated value"
  4. Triggers: Triggers recalculation when changed → "Changes trigger related calculations"

AI Agent Definition

The idempiere-description-writer agent is a Claude Code agent for generating AD_Element documentation.

Location: .claude/agents/idempiere-description-writer.md (symlink to cloudempiere-workspace)

Source: cloudempiere-workspace/.claude/agents/idempiere/description-writer.md

The agent provides:

Key rules enforced:

Implementation Plan

Phase 1: CLI Foundation

  1. Create ElementDescriptionCommand with subcommands
  2. Implement PatternGenerator service for rule-based generation
  3. Add JSON/SQL/2Pack output formatters

Phase 2: Python Integration

  1. Bundle Python scripts as resources
  2. Create PythonBridge utility for script execution
  3. Implement seed database parsing via Python

Phase 3: AI Agent Integration

  1. Configure idempiere-description-writer agent
  2. Add --ai flag to leverage agent for complex cases
  3. Implement review workflow for AI-generated content

Phase 4: Java Native (Future)

  1. Port parse_seed_dump.py to Java
  2. Port generate_descriptions.py patterns to Java
  3. Deprecate Python dependencies

More Information

Original Python Scripts

The following Python scripts from the iDempiere repository (.claude/tools/element-docs/) define the original implementation logic:

Data Extraction Scripts

Script Purpose
parse_seed_dump.py Parse PostgreSQL seed dump to extract AD_Element relationships
extract_business_logic.py Analyze M*.java beforeSave/afterSave methods
analyze_java_code.py Extract JavaDoc and business logic context

Description Generation Scripts

Script Purpose
generate_descriptions.py Pattern-based description generator
integrate_java_context.py Combine patterns with Java business logic
filter_clean_items.py Filter to keep only high-quality items

Migration Scripts

Script Purpose
merge_migrations.py Merge multiple migration scripts
create_final_migration.py Generate final PostgreSQL/Oracle migrations

Process/Tab Scripts

Script Purpose
parse_process_tab.py Parse AD_Process and AD_Tab records
generate_process_tab.py Generate process/tab descriptions
generate_process_tab_v2.py Enhanced process/tab generation
analyze_process_java.py Analyze process Java implementations

References


Appendix A: Python Script Reference

parse_seed_dump.py

Extracts AD_Element context from PostgreSQL seed database dump:

#!/usr/bin/env python3
&quot;&quot;&quot;
Parse iDempiere seed database dump to extract AD_Element context and relationships.
Outputs JSON with element -&gt; windows, processes, tables mappings.
&quot;&quot;&quot;

import json
import sys
from collections import defaultdict

def parse_copy_block(lines, start_line, columns):
    &quot;&quot;&quot;Parse a COPY block from PostgreSQL dump, extracting specified columns.&quot;&quot;&quot;
    data = []
    col_names = columns.split(&#39;, &#39;)

    for i in range(start_line, len(lines)):
        line = lines[i]
        if line.strip() == &#39;\\.&#39;:
            break
        if line.startswith(&#39;COPY &#39;) or not line.strip():
            continue

        # Tab-separated values
        values = line.rstrip(&#39;\n&#39;).split(&#39;\t&#39;)
        if len(values) &gt;= len(col_names):
            row = {}
            for j, col in enumerate(col_names):
                val = values[j] if j &lt; len(values) else &#39;&#39;
                row[col] = val if val != &#39;\\N&#39; else None
            data.append(row)

    return data

# Tables parsed:
# - ad_element: Core element definitions
# - ad_column: Column -&gt; element mapping
# - ad_field: Field -&gt; column -&gt; window mapping
# - ad_tab: Tab -&gt; window mapping
# - ad_window: Window names
# - ad_process_para: Process parameter -&gt; element mapping
# - ad_process: Process names
# - ad_table: Table names

# Output: element_context.json with structure:
# {
#   &quot;element_id&quot;: {
#     &quot;id&quot;: &quot;...&quot;,
#     &quot;uu&quot;: &quot;...&quot;,
#     &quot;columnname&quot;: &quot;...&quot;,
#     &quot;name&quot;: &quot;...&quot;,
#     &quot;description&quot;: &quot;...&quot;,
#     &quot;help&quot;: &quot;...&quot;,
#     &quot;entitytype&quot;: &quot;D&quot;,
#     &quot;windows&quot;: [&quot;Window1&quot;, &quot;Window2&quot;],
#     &quot;processes&quot;: [&quot;Process1&quot;],
#     &quot;tables&quot;: [&quot;Table1&quot;]
#   }
# }

generate_descriptions.py

Pattern-based description generation:

#!/usr/bin/env python3
&quot;&quot;&quot;
Generate descriptions and help text for AD_Element records with missing documentation.
Uses pattern matching and context analysis.
&quot;&quot;&quot;

# Key patterns:
# - *_UU: &quot;Immutable Universally Unique Identifier&quot;
# - *_ID: &quot;{Entity} reference&quot;
# - Is*: &quot;Indicates if {condition}&quot;
# - Qty*: &quot;Quantity of {subject}&quot;
# - Amt*: &quot;Amount for {purpose}&quot;
# - Date*: &quot;Date of {event}&quot;
# - *_Acct: &quot;Account for {purpose}&quot;

# Standard columns dictionary with fixed descriptions
STANDARD_COLUMNS = {
    &#39;Created&#39;: &#39;Date this record was created&#39;,
    &#39;Updated&#39;: &#39;Date this record was last updated&#39;,
    &#39;CreatedBy&#39;: &#39;User who created this record&#39;,
    &#39;UpdatedBy&#39;: &#39;User who last updated this record&#39;,
    &#39;IsActive&#39;: &#39;The record is active in the system&#39;,
    &#39;Processing&#39;: &#39;Process is currently executing&#39;,
    &#39;Processed&#39;: &#39;The document has been processed&#39;,
    &#39;Posted&#39;: &#39;Accounting entries have been generated&#39;,
    &#39;Value&#39;: &#39;Search key for the record&#39;,
    &#39;Name&#39;: &#39;Alphanumeric identifier of the entity&#39;,
    &#39;Description&#39;: &#39;Optional short description of the record&#39;,
    &#39;DocumentNo&#39;: &#39;Document sequence number of the document&#39;,
    &#39;SeqNo&#39;: &#39;Method of ordering records; lowest number comes first&#39;,
}

# Categorization by business domain:
# - System - Application Dictionary (AD_*)
# - Business Partner (C_BP*, C_BPartner*)
# - Material Management (M_*)
# - Sales and Purchasing (C_Order*, C_Invoice*)
# - Accounting (GL_*, *_Acct)
# - Manufacturing (PP_*)
# - Human Resources (HR_*)
# - Assets (A_*)
# - Performance Analysis (PA_*)
# - UU Identifiers (*_UU)

integrate_java_context.py

Enhances descriptions with Java business logic:

#!/usr/bin/env python3
&quot;&quot;&quot;
Integrate Java business logic into AD_Element descriptions.
Combines pattern-based generation with actual code behavior.
&quot;&quot;&quot;

# Business logic patterns detected:
# - &quot;Cannot modify when parent is processed&quot; -&gt; &quot;Read-only after processing&quot;
# - &quot;Triggers recalculation when changed&quot; -&gt; &quot;Triggers recalculation&quot;
# - &quot;Calculated by multiplication/addition&quot; -&gt; &quot;Calculated value&quot;
# - &quot;Currency converted value&quot; -&gt; &quot;Currency-converted amount&quot;
# - &quot;Validation: FillMandatory&quot; -&gt; &quot;Required field&quot;

# Help text enhancement includes:
# - Business logic context from M*.java
# - Model class references for complex logic
# - Window usage context
# - Process usage context

create_final_migration.py

Generates iDempiere-compatible migration scripts:

#!/usr/bin/env python3
&quot;&quot;&quot;
Create final consolidated migration script for AD_Element descriptions.
Generates PostgreSQL and Oracle compatible scripts.
&quot;&quot;&quot;

# Output paths:
# - migration/iD12/postgresql/{timestamp}_IDEMPIERE-Element-Descriptions.sql
# - migration/iD12/oracle/{timestamp}_IDEMPIERE-Element-Descriptions.sql

# Script format:
# SELECT register_migration_script(&#39;{timestamp}_IDEMPIERE-Element-Descriptions.sql&#39;) FROM dual;
#
# UPDATE AD_Element SET Description=&#39;...&#39;, Help=&#39;...&#39;, Updated=NOW(), UpdatedBy=100
# WHERE AD_Element_UU=&#39;...&#39; AND Description IS NULL AND EntityType=&#39;D&#39;;

# Oracle variant uses SYSDATE instead of NOW()

Appendix B: Documentation Standards (ADR-001 Summary)

Language Rules

  1. Product naming: Always "iDempiere", never "Compiere" or "ADempiere"
  2. Abbreviations: Uppercase (MFA, RFQ, FA, BOM, UOM, PO, SO, GL, AP, AR, API, PDF, XML, URL)
  3. No technical details: Never expose class names, method names, or implementation specifics
  4. Human-readable names: Convert column names to readable form (C_BPartner_ID → Business Partner)

Grammar Rules

  1. Complete sentences: All Help text must use complete sentences
  2. Article usage: "the" for specific, "a/an" for general
  3. Singular/plural: Consistent throughout sentences
  4. Possessive forms: record's (singular), records' (plural ending in s)

Field-Specific Templates

Field Type Description Pattern Help Pattern
*_ID {Entity} link The {Display Name} field identifies the linked {entity} record.
*_UU Immutable Universally Unique Identifier The {Display Name} uniquely identifies this record across all systems.
Is* Indicates whether {condition} is enabled The {Display Name} checkbox {description in lowercase}.
*_Acct Account used for {purpose} The {Display Name} defines which account to use for posting transactions.

Path: /docs/developers/architecture/idempiere-hub/017-ad-element-description-management