Skip to content

Commit

Permalink
#30882 First commit for the ImportUtil refactor to improve responses.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgambarios committed Jan 21, 2025
1 parent 42eac4e commit 8fd1178
Show file tree
Hide file tree
Showing 11 changed files with 1,523 additions and 230 deletions.
1,233 changes: 1,003 additions & 230 deletions dotCMS/src/main/java/com/dotmarketing/util/ImportUtil.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.dotmarketing.util.importer;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import java.io.Serializable;
import org.immutables.value.Value;

/**
* Immutable data structure that holds summary information about content processing results.
* This includes counts of created and updated content, as well as the content type identifier.
*/
@Value.Style(typeImmutable = "*", typeAbstract = "Abstract*")
@Value.Immutable
@JsonDeserialize(as = ContentSummary.class)
@JsonIgnoreProperties(ignoreUnknown = true)
public interface AbstractContentSummary extends Serializable {

/**
* @return The number of new content items created during the import process
*/
int created();

/**
* @return The number of existing content items updated during the import process
*/
int updated();

/**
* @return The identifier of the content type being processed
*/
String contentType();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.dotmarketing.util.importer;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import java.io.Serializable;
import org.immutables.value.Value;

/**
* Immutable data structure containing file processing information during import.
* Tracks the total number of rows in the file and how many were successfully parsed,
* along with header validation information.
*/
@Value.Style(typeImmutable = "*", typeAbstract = "Abstract*")
@Value.Immutable
@JsonDeserialize(as = ImportFileInfo.class)
@JsonIgnoreProperties(ignoreUnknown = true)
public interface AbstractImportFileInfo extends Serializable {

/**
* @return The total number of rows found in the import file
*/
int totalRows();

/**
* @return The number of rows successfully parsed from the import file
*/
int parsedRows();

/**
* @return Detailed information about the validated headers in the import file
*/
ImportHeaderInfo headerInfo();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.dotmarketing.util.importer;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import java.io.Serializable;
import java.util.Map;
import org.immutables.value.Value;

/**
* Immutable data structure containing header validation information from the import file.
* Tracks valid, invalid, and missing headers, along with any additional validation details.
*/
@Value.Style(typeImmutable = "*", typeAbstract = "Abstract*")
@Value.Immutable
@JsonDeserialize(as = ImportHeaderInfo.class)
@JsonIgnoreProperties(ignoreUnknown = true)
public interface AbstractImportHeaderInfo extends Serializable {

/**
* @return The total number of headers found in the import file
*/
int totalHeaders();

/**
* @return Array of headers that were successfully validated against the content type
*/
String[] validHeaders();

/**
* @return Array of headers that did not match any content type fields
*/
String[] invalidHeaders();

/**
* @return Array of required content type fields not found in the headers
*/
String[] missingHeaders();

/**
* @return Additional validation details and metadata about the headers
*/
Map<String, String> validationDetails();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.dotmarketing.util.importer;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import java.util.List;
import java.util.Map;
import org.immutables.value.Value;

/**
* Immutable data structure representing the complete results of header validation.
* Includes header information, validation messages, and contextual data needed for
* the import process.
*/
@Value.Style(typeImmutable = "*", typeAbstract = "Abstract*")
@Value.Immutable
@JsonDeserialize(as = ImportHeaderValidationResult.class)
@JsonIgnoreProperties(ignoreUnknown = true)
public interface AbstractImportHeaderValidationResult {

/**
* @return Detailed information about the validated headers
*/
ImportHeaderInfo headerInfo();

/**
* @return List of validation messages generated during header processing
*/
List<ImportValidationMessage> messages();

/**
* @return Contextual information needed for the import process, such as processed headers,
* relationships, and field mappings
*/
Map<String, Object> context();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.dotmarketing.util.importer;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import java.io.Serializable;
import java.util.List;
import org.immutables.value.Value;

/**
* Immutable data structure representing the complete results of an import operation.
* Contains file information, data processing results, and validation messages.
*/
@Value.Style(typeImmutable = "*", typeAbstract = "Abstract*")
@Value.Immutable
@JsonDeserialize(as = ImportResult.class)
@JsonIgnoreProperties(ignoreUnknown = true)
public interface AbstractImportResult extends Serializable {

/**
* @return Information about the processed import file
*/
ImportFileInfo fileInfo();

/**
* @return Results of the data processing operation
*/
ImportResultData data();

/**
* @return List of validation and processing messages generated during import
*/
List<ImportValidationMessage> messages();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.dotmarketing.util.importer;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import java.io.Serializable;
import org.immutables.value.Value;

/**
* Immutable data structure that combines processing statistics and content summary information.
* This interface represents the complete data results of an import operation.
*/
@Value.Style(typeImmutable = "*", typeAbstract = "Abstract*")
@Value.Immutable
@JsonDeserialize(as = ImportResultData.class)
@JsonIgnoreProperties(ignoreUnknown = true)
public interface AbstractImportResultData extends Serializable {

/**
* @return Statistics about processed records including valid and invalid counts
*/
ProcessedData processed();

/**
* @return Summary information about created and updated content
*/
ContentSummary summary();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.dotmarketing.util.importer;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import java.io.Serializable;
import java.util.Map;
import java.util.Optional;
import org.immutables.value.Value;

/**
* Immutable data structure representing a validation message generated during the import process.
* Messages can be errors, warnings, or informational, and may include contextual information
* such as line numbers, field names, and invalid values.
*/
@Value.Style(typeImmutable = "*", typeAbstract = "Abstract*")
@Value.Immutable
@JsonDeserialize(as = ImportValidationMessage.class)
@JsonIgnoreProperties(ignoreUnknown = true)
public interface AbstractImportValidationMessage extends Serializable {

/**
* Enumeration of possible message types for validation results.
*/
enum ValidationMessageType {
/**
* Indicates a critical error that prevents successful processing
*/
ERROR,
/**
* Indicates a potential issue that doesn't prevent processing
*/
WARNING,
/**
* Provides additional information about the process
*/
INFO
}

/**
* @return The type of validation message
*/
ValidationMessageType type();

/**
* @return Optional validation code identifying the specific type of message
*/
Optional<String> code();

/**
* @return The human-readable validation message
*/
String message();

/**
* @return Optional line number in the import file where the issue was found
*/
Optional<Integer> lineNumber();

/**
* @return Optional field name related to the validation message
*/
Optional<String> field();

/**
* @return Additional contextual information about the validation
*/
Map<String, Object> context();

/**
* @return Optional value that failed validation
*/
Optional<String> invalidValue();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.dotmarketing.util.importer;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import java.io.Serializable;
import org.immutables.value.Value;

/**
* Immutable data structure containing counts of valid and invalid records processed
* during the import operation.
*/
@Value.Style(typeImmutable = "*", typeAbstract = "Abstract*")
@Value.Immutable
@JsonDeserialize(as = ProcessedData.class)
@JsonIgnoreProperties(ignoreUnknown = true)
public interface AbstractProcessedData extends Serializable {

/**
* @return The number of records that passed validation and were processed successfully
*/
int valid();

/**
* @return The number of records that failed validation or could not be processed
*/
int invalid();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.dotmarketing.util.importer;

/**
* Enumeration of validation codes used to identify specific types of header validation issues
* during the import process. These codes provide a standardized way to categorize and handle
* different validation scenarios.
*/
public enum HeaderValidationCodes {

/** Indicates a header that doesn't match any content type field */
INVALID_HEADER,
/** Indicates a system-level header (e.g., Identifier, Workflow Action) */
SYSTEM_HEADER,
/** Indicates malformed or unreadable header format */
INVALID_HEADER_FORMAT,
/** Indicates a header name that appears more than once */
DUPLICATE_HEADER,
/** Indicates not all required content type fields are present in headers */
INCOMPLETE_HEADERS,
/** Indicates a required field is missing from the headers */
REQUIRED_FIELD_MISSING,
/** Indicates no key fields were specified for content matching */
NO_KEY_FIELDS,
/** Indicates a field marked as unique in the content type */
UNIQUE_FIELD,
/** Indicates an invalid key field specification */
INVALID_KEY_FIELD,
/** Indicates duplicate values found for unique fields */
DUPLICATE_VALUES,
/** Indicates issues with language-specific headers */
INVALID_LANGUAGE,
/** Indicates security-related validation failures */
SECURITY_ERROR,
/** Indicates general processing errors during validation */
PROCESSING_ERROR

}
Loading

0 comments on commit 8fd1178

Please sign in to comment.