Skip to content

Align schema with node#744

Draft
Schmarvinius wants to merge 1 commit intomainfrom
feat/align-cds-model-with-capjs
Draft

Align schema with node#744
Schmarvinius wants to merge 1 commit intomainfrom
feat/align-cds-model-with-capjs

Conversation

@Schmarvinius
Copy link
Collaborator

@Schmarvinius Schmarvinius commented Mar 9, 2026

Align CDS Schema with Node: Rename Fields and Restructure Attachment Model

♻️ Refactor: Aligns the Java CDS attachment feature schema with the Node.js CDS implementation by renaming fields, restructuring the data model, and moving StatusCode to a dedicated service model class.

Changes

This PR introduces several breaking schema changes to match the Node.js CDS model:

  • fileNamefilename: Renamed across all layers — CDS model, Java handlers, service model, i18n files (35 languages), annotations, tests, integration tests, and sample code.
  • scannedAtlastScan: Renamed in the CDS model, handlers, malware scanner, annotations, readonly field logic, and all related tests.
  • StatusCode type refactored: The StatusCode type was previously a CDS-generated enum in sap.attachments. It is now a standalone Java class (com.sap.cds.feature.attachments.service.model.StatusCode) with string constants. All imports updated across the codebase.
  • ScanStates entity added: The CDS model now defines a ScanStates entity extending CodeList with a criticality field, replacing the old inline StatusCode enum type.
  • status field changed: From a typed StatusCode field (readonly) to a plain String with a default of 'Unscanned' and a new statusNav association to ScanStates.
  • note field: Changed from String(5000) to unbounded String.
  • url and hash fields added to MediaData aspect.
  • Annotations updated in attachments-annotations.cds: filename annotation corrected, content marked @odata.draft.skip, fields like url, hash, lastScan marked hidden/computed, LineItem entries reformatted with Criticality, and SortRestrictions added.
  • CreateAttachmentInput record: fileName parameter renamed to filename.
  • i18n property key: attachment_fileNameattachment_filename in all 35 language files.

Key Files

  • attachments.cds: Replaced StatusCode enum type with ScanStates entity, renamed fields, added url, hash, statusNav, changed note to unbounded string.
  • attachments-annotations.cds: Updated field references, annotations, and LineItem structure.
  • StatusCode.java (new): Standalone class with scan status string constants.
  • CreateAttachmentInput.java, AttachmentsServiceImpl.java, CreateAttachmentEvent.java: fileNamefilename rename.
  • DefaultAttachmentMalwareScanner.java, MarkAsDeletedAttachmentEvent.java, ReadonlyDataContextEnhancer.java: scannedAtlastScan rename.
  • README.md, doc/Design.md, doc/Processes.md: Documentation updated to reflect field renames.
  • All i18n_*.properties files: attachment_fileName key renamed to attachment_filename.
  • All test and integration test files: Updated to use new field names and StatusCode import path.
  • OSSAttachmentsServiceHandler.java, FSAttachmentsServiceHandler.java, FSDraftServiceHandler.java: Updated to use filename and new StatusCode import.
  • samples/bookshop/srv/.../RestHandler.java: Updated API responses to use filename.
  • 🔄 Regenerate and Update Summary

📬 Subscribe to the Hyperspace PR Bot DL to get the latest announcements and pilot features!

PR Bot Information

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

  • Event Trigger: pull_request.opened
  • Summary Prompt: Default Prompt
  • Output Template: Default Template
  • LLM: anthropic--claude-4.6-sonnet
  • Correlation ID: 2a5abde0-1bb0-11f1-8667-7da2eb9ca755

@Schmarvinius Schmarvinius requested a review from lisajulia March 9, 2026 12:04
@Schmarvinius Schmarvinius self-assigned this Mar 9, 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 PR consistently renames fileNamefilename, scannedAtlastScan, and moves StatusCode to a dedicated service-layer class — a clean, well-coordinated refactoring across all layers and all 35 i18n files. Three issues were found: the README table still references the old attachment_fileName i18n key (stale after the rename), and contentId and lastScan lost their @readonly constraints at the CDS model level, making them writable when the model is consumed without the annotations file.

PR Bot Information

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

  • Correlation ID: 2a5abde0-1bb0-11f1-8667-7da2eb9ca755
  • Event Trigger: pull_request.opened
  • LLM: anthropic--claude-4.6-sonnet

| `content` | `attachment_content` |
| `mimeType` | `attachment_mimeType` |
| `fileName` | `attachment_fileName` |
| `filename` | `attachment_fileName` |
Copy link
Contributor

Choose a reason for hiding this comment

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

Bug: i18n code in README table is stale after the rename

The table claims the i18n code for filename is attachment_fileName, but all i18n property files were updated to use attachment_filename. This mismatch will mislead consumers who look up the key to override the translation.

Suggested change
| `filename` | `attachment_fileName` |
| `filename` | `attachment_filename` |

Double-check suggestion before committing. Edit this comment for amendments.


Please provide feedback on the review comment by checking the appropriate box:

  • 🌟 Awesome comment, a human might have missed that.
  • ✅ Helpful comment
  • 🤷 Neutral
  • ❌ This comment is not helpful

status : String default 'Unscanned';
statusNav : Association to one ScanStates
on statusNav.code = status;
lastScan : Timestamp;
Copy link
Contributor

Choose a reason for hiding this comment

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

Logic Error: contentId, status, and lastScan lost their @readonly annotations

In the previous model, contentId, status, and scannedAt were all annotated @readonly. The new model removes @readonly from contentId and status (and drops it entirely for lastScan). The annotations file only re-adds @readonly to status and contentId via the annotations file, but leaves lastScan without any read-only protection at the entity level. If the annotations file is consumed independently, or a service exposes these fields without the annotations, lastScan and contentId become writable — which contradicts the documented design that these fields must not be updated by clients (see doc/Design.md and doc/Processes.md).

Suggested change
lastScan : Timestamp;
lastScan : Timestamp @readonly;

Double-check suggestion before committing. Edit this comment for amendments.


Please provide feedback on the review comment by checking the appropriate box:

  • 🌟 Awesome comment, a human might have missed that.
  • ✅ Helpful comment
  • 🤷 Neutral
  • ❌ This comment is not helpful

mimeType : String default 'application/octet-stream';
filename : String;
hash : String;
contentId : String; // id of attachment in external storage, if database storage is used, same as id
Copy link
Contributor

Choose a reason for hiding this comment

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

Logic Error: contentId lost its @readonly annotation at the model level

Previously contentId was @readonly in the aspect definition. The new model removes this, leaving it only in the annotations file. This is inconsistent with how status is handled and means contentId is writable if the base model is used without annotations (e.g. in programmatic access or non-UI scenarios).

Suggested change
contentId : String; // id of attachment in external storage, if database storage is used, same as id
contentId : String @readonly; // id of attachment in external storage, if database storage is used, same as id

Double-check suggestion before committing. Edit this comment for amendments.


Please provide feedback on the review comment by checking the appropriate box:

  • 🌟 Awesome comment, a human might have missed that.
  • ✅ Helpful comment
  • 🤷 Neutral
  • ❌ This comment is not helpful

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