Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EPIC] Import/Export: ✨ Improve Error Formats in JSON /validate Responses #30882

Closed
3 of 10 tasks
Tracked by #31217
fmontes opened this issue Dec 6, 2024 · 1 comment · Fixed by #31183 or #31294
Closed
3 of 10 tasks
Tracked by #31217

[EPIC] Import/Export: ✨ Improve Error Formats in JSON /validate Responses #30882

fmontes opened this issue Dec 6, 2024 · 1 comment · Fixed by #31183 or #31294

Comments

@fmontes
Copy link
Member

fmontes commented Dec 6, 2024

Problem Statement

The current validation response structure in our system is unclear and inconsistent. This complexity leads to increased development costs and potential errors as it mixes data types, includes unnecessary information, and lacks a standardized error format. Simplifying and standardizing the structure would improve reliability and ease of integration.

Objectives

  • Redesign the validation response object to ensure consistent data structures.
  • Introduce standardized error and warning messages with unique codes.
  • Eliminate redundant data and logically group related data within the response.

User Story

As a developer, I want the validation responses to be standardized and clearly structured, so that I can easily integrate and manage them in my applications.

Detailed Requirements

Here is an example of the proposal response.

{
  "results": {
    "file": {
      "totalRows": 4,
      "parsedRows": 3,
      "headers": {
        "valid": ["title"],
        "invalid": ["contentHost"],
        "missing": ["image", "blogs"]
      }
    },
    "data": {
      "processed": {
        "valid": 3,
        "invalid": 0
      },
      "summary": {
        "created": 3,
        "updated": 0,
        "contentType": "Fake Content"
      }
    },
    "warnings": [
      {
        "code": "INVALID_HEADER",
        "field": "contentHost",
        "message": "Header doesn't match any Content Type field; column will be ignored"
      },
      {
        "code": "MISSING_KEY_FIELD",
        "message": "No key fields specified, may result in duplicate content"
      },
      {
        "code": "INCOMPLETE_HEADERS",
        "message": "Not all Content Type fields match file headers. Some fields may be empty"
      }
    ],
    "errors": [
      {
        "code": "INVALID_FILE_TYPE",
        "message": "File type is not supported"
      },
      {
        "code": "INVALID_IMAGE_PATH",
        "row": 2,
        "field": "image",
        "value": "/invalid/path.jpg",
        "message": "Image path not found in Site Browser"
      },
      {
        "code": "INVALID_RELATIONSHIP",
        "row": 3,
        "field": "blogs",
        "value": "invalid-blog-id",
        "message": "Blog with ID 'invalid-blog-id' not found"
      },
      {
        "code": "REQUIRED_FIELD_MISSING",
        "row": 4,
        "field": "title",
        "message": "Required field 'title' is missing"
      }
    ]
  }
}

The response is a JSON object with a main results object containing:

  • File processing information
  • Data processing summary
  • Warnings
  • Errors

File Information (results.file)

Must include:

  • totalRows: Total number of rows in the uploaded file
  • parsedRows: Number of successfully parsed rows
  • headers: Object containing:
    • valid: Array of valid headers matching content type fields
    • invalid: Array of headers that don't match any fields
    • missing: Array of required fields not present in headers

Data Processing (results.data)

Must include:

  • processed: Object with counts of valid/invalid records
  • summary: Object containing:
    • Record creation/update counts
    • Content type information

Warning System (results.warnings)

Each warning must include:

  • code: Standardized warning code (e.g., INVALID_HEADER, MISSING_KEY_FIELD)
  • field: Affected field name (when applicable)
  • message: Human-readable description

Common warning codes to implement:

  • INVALID_HEADER: When headers don't match content type fields
  • MISSING_KEY_FIELD: When unique identifiers are missing
  • INCOMPLETE_HEADERS: When required fields are missing from headers
  • There are probably more that I don't know about

Error System (results.errors)

Each error must include:

  • code: Standardized error code
  • message: Detailed error description
  • row: Row number where error occurred (when applicable)
  • field: Field where error occurred (when applicable)
  • value: Invalid value causing the error (when applicable)

Common error codes to implement:

  • INVALID_FILE_TYPE: For unsupported file formats
  • INVALID_IMAGE_PATH: When image references are invalid
  • INVALID_RELATIONSHIP: When referenced entities don't exist
  • REQUIRED_FIELD_MISSING: When mandatory fields are empty
  • There are probably more that I don't know about

Importance

  1. Debugging: Detailed response structure helps identify issues quickly
  2. User Experience: Clear error messages help content editors fix issues independently
  3. Validation: Comprehensive checks ensure data integrity
  4. Maintenance: Standardized error codes make error handling consistent

Development Guidelines

  1. Maintain consistent error/warning code naming conventions
  2. Include row numbers whenever possible for easier debugging
  3. Provide specific field names in error messages
  4. Include invalid values in error messages when applicable
  5. Keep messages human-readable and actionable

Acceptance Criteria

Preview Give feedback

Technical Details

The response structure reform relies on standardized JSON formats.

  • Consideration of how these changes may affect existing systems, particularly those heavily dependent on the specific format of error messages and codes.

Potential Challenges

  • Detailed definition and documentation of new error and warning codes to ensure they cover all conceivable scenarios.
  • Ensuring that the new structure caters to both machine readability and human usability.

Tasks

Preview Give feedback
  1. Merged QA : Passed Internal Release : 25.02.07 Team : Scout Type : Task
  2. OKR : Core Features Priority : 2 High QA : Passed Internal Release : 25.02.12 Team : Scout Type : Task
  3. Merged Note to QA OKR : Core Features Priority : 2 High QA : Passed Internal Release : 25.02.26 Team : Scout Type : Task
@fmontes fmontes changed the title Improve Validation Response Object Structure Import/Export: ✨ Improve Error Formats in JSON /validate Responses Dec 6, 2024
@nollymar nollymar moved this from New to Next 1-3 Sprints in dotCMS - Product Planning Dec 6, 2024
@jgambarios jgambarios moved this from Next 1-3 Sprints to In Progress in dotCMS - Product Planning Jan 16, 2025
@jgambarios jgambarios self-assigned this Jan 16, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in dotCMS - Product Planning Jan 24, 2025
@nollymar nollymar reopened this Jan 27, 2025
@github-project-automation github-project-automation bot moved this from Done to Current Sprint Backlog in dotCMS - Product Planning Jan 27, 2025
@nollymar nollymar moved this from Current Sprint Backlog to In Progress in dotCMS - Product Planning Jan 27, 2025
@jgambarios jgambarios changed the title Import/Export: ✨ Improve Error Formats in JSON /validate Responses [EPIC] Import/Export: ✨ Improve Error Formats in JSON /validate Responses Jan 27, 2025
github-merge-queue bot pushed a commit that referenced this issue Feb 20, 2025
This PR represents the final stage of the Import Content response
improvements, where the `ImportContentletsProcessor` now leverages the
new structured response format while maintaining full backward
compatibility with existing Struts implementations.

### Changes Overview

* Updated `ImportContentletsProcessor` to use new response format 
* Added converter to maintain backward compatibility with Struts actions
* Improved error handling and validation message organization
* Enhanced documentation and code organization

### What's Not Changed

We intentionally kept several aspects unchanged to ensure stability:
* Core import logic remains untouched
* Legacy response format is still fully supported
* Existing workflow processing behavior
* Current transaction handling
* Permission checking mechanisms

While working on this code, we identified several potential improvements
that were intentionally left for future iterations to keep the scope
focused on the immediate needs.

This PR is related to: #30882
This PR fixes: #31339
@github-project-automation github-project-automation bot moved this from In Progress to Done in dotCMS - Product Planning Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment