Skip to content

Conversation

@Schmarvinius
Copy link
Collaborator

@Schmarvinius Schmarvinius commented Jan 28, 2026

Add Validation Constraints for Book Attachments

✨ New Features

Added min/max item validation constraints (@Validation.MinItems and @Validation.MaxItems) to attachment compositions, enabling control over the number of attachments per entity. This feature validates attachment counts during create, update, and draft save operations to ensure data consistency.

📝 Changes

Core Validation Logic

  • AttachmentCountValidator.java: New validator class implementing comprehensive attachment count validation:
    • validateForCreate(): Validates both min and max constraints for non-draft create operations
    • validateForUpdate(): Validates constraints based on the new attachment count in the request
    • validateForDraftSave(): Validates constraints during draft activation by querying the draft service
    • Supports compositions with @Validation.MinItems, @Validation.MaxItems, or both annotations
    • Provides detailed error messages (MinimumAmountNotFulfilled, MaximumAmountExceeded)

Handler Integration

  • Registration.java: Wired the new AttachmentCountValidator into create, update, and draft activation handlers
  • CreateAttachmentsHandler.java: Integrated count validation before processing create operations
  • UpdateAttachmentsHandler.java: Added validation for update operations when compositions are modified
  • DraftActiveAttachmentsHandler.java: Added validation during draft activation with late handler ordering

Error Messages

  • messages.properties: Added localized error messages for min/max validation failures

Test Coverage

  • AttachmentCountValidatorTest.java: Comprehensive unit tests covering all validation scenarios (150+ test cases)
  • AttachmentCountValidationDraftTest.java: Integration tests for draft-enabled entities
  • AttachmentCountValidationNonDraftTest.java: Integration tests for non-draft entities
  • CountValidatedRootEntityBuilder.java: Test helper for creating test entities with count-validated attachments

Sample Application

  • attachments.cds: Demonstrated usage in bookshop sample with:
    • Default attachments composition with @Validation.MinItems: 2 and @Validation.MaxItems: 3
    • Hidden minMaxAttachments composition for testing
  • admin-service.cds: Added NonDraftAdminService for testing non-draft scenarios
  • application.yaml: Enabled debug logging for the validator

CI/CD & Versioning

  • .github/workflows/pipeline.yml: Removed obsolete dry-run parameter for pull request builds
  • pom.xml: Updated version to 1.4.0-SNAPSHOT

Code Quality Improvements

  • CountingInputStreamTest.java: Fixed resource management with try-with-resources pattern
  • Various formatting improvements and comment clarifications across multiple files

This enhancement extends the existing attachments functionality by demonstrating validation capabilities for collections, ensuring users provide an appropriate number of attachments when required. The implementation supports both draft and non-draft entities, with validation triggered at appropriate lifecycle events to maintain data consistency.

  • 🔄 Regenerate and Update Summary

@Schmarvinius Schmarvinius self-assigned this Jan 28, 2026
Copy link
Contributor

@hyperspace-insights hyperspace-insights bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good. The new minMaxAttachments field is properly configured with validation annotations for minimum and maximum item counts, following the existing pattern in the file for other attachment fields.

PR Bot Information

Version: 1.17.37 | 📖 Documentation | 🚨 Create Incident | 💬 Feedback

  • Correlation ID: 4b033b70-fc58-11f0-87bd-be00e489c088
  • Event Trigger: pull_request.opened
  • LLM: anthropic--claude-4.5-sonnet

@Schmarvinius Schmarvinius changed the title Add MaxItems and MinItems Annotation Adding MaxItems and MinItems Annotation Jan 29, 2026
Copy link
Contributor

@hyperspace-insights hyperspace-insights bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request adds comprehensive attachment count validation functionality. The code quality is generally good with thorough testing. I identified a few minor issues around missing newlines and a potential logic improvement to help detect configuration errors.

PR Bot Information

Version: 1.17.37 | 📖 Documentation | 🚨 Create Incident | 💬 Feedback

  • Correlation ID: 0988cdf0-fd10-11f0-8de8-e0a44d83f4a8
  • LLM: anthropic--claude-4.5-sonnet
  • Event Trigger: issue_comment.created

@hyperspace-insights hyperspace-insights bot deleted a comment from Schmarvinius Jan 29, 2026
@Schmarvinius Schmarvinius marked this pull request as ready for review January 29, 2026 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant