Description
Currently, the API allows Media entities to be persisted without an associated ExternalReference. This lack of referential integrity prevents the system from precisely linking media records with external services, leading to orphaned data and synchronization issues.
To ensure data consistency, the system must be updated to require at least one ExternalReference for every Media record saved.
Technical Requirements
1. Service Layer Validation
The MediaService (or equivalent service layer) must validate the existence of a reference before persistence. If no reference is found, a ValidationException should be thrown.
Proposed Logic:
public Media save(Media media) {
if (!externalsRepo.existsByMediasIdMedia(media.getIdMedia())) {
throw new ValidationException("Referência externa obrigatória");
}
return mediaRepo.save(media);
}
2. Spring Batch Integration & Error Handling
To prevent data corruption from stopping bulk processes, the Spring Batch jobs must handle this validation failure gracefully:
- Catch Exception: If a
ValidationException is thrown during the item writing/processing phase, the job should not terminate.
- Retry Logic: Attempt to re-extract or recover the ID from the source JSON if possible.
- Skip Policy: If the ID cannot be recovered or the reference is truly missing, the specific media record should be ignored/skipped.
- Logging: Log the skipped record for later auditing without stopping the overall job execution.
Acceptance Criteria
Description
Currently, the API allows
Mediaentities to be persisted without an associatedExternalReference. This lack of referential integrity prevents the system from precisely linking media records with external services, leading to orphaned data and synchronization issues.To ensure data consistency, the system must be updated to require at least one
ExternalReferencefor everyMediarecord saved.Technical Requirements
1. Service Layer Validation
The
MediaService(or equivalent service layer) must validate the existence of a reference before persistence. If no reference is found, aValidationExceptionshould be thrown.Proposed Logic:
2. Spring Batch Integration & Error Handling
To prevent data corruption from stopping bulk processes, the Spring Batch jobs must handle this validation failure gracefully:
ValidationExceptionis thrown during the item writing/processing phase, the job should not terminate.Acceptance Criteria
Mediaentities can no longer be saved via the API without an associatedExternalReference.ValidationExceptionwith the message "Referência externa obrigatória" when validation fails.