@@ -765,8 +765,18 @@ private static class AttachmentMoveContext {
765765 */
766766 private void processSingleAttachmentMove (AttachmentMoveContext moveContext ) {
767767 try {
768- // Step 1: Move attachment in SDM
769- CmisDocument cmisDocument = new CmisDocument ();
768+ // Step 1: Fetch attachment metadata from database to get type and URL (needed for link
769+ // attachments)
770+ // Create a copy event context to fetch attachment from source location
771+ AttachmentMoveEventContext eventContext = moveContext .request .getContext ();
772+ AttachmentCopyEventContext copyContext = AttachmentCopyEventContext .create ();
773+ copyContext .setParentEntity (eventContext .getSourceParentEntity ());
774+ copyContext .setCompositionName (eventContext .getSourceCompositionName ());
775+
776+ CmisDocument cmisDocument =
777+ dbQuery .getAttachmentForObjectID (persistenceService , moveContext .objectId , copyContext );
778+
779+ // Set move operation specific fields
770780 cmisDocument .setObjectId (moveContext .objectId );
771781 cmisDocument .setRepositoryId (moveContext .request .getRepositoryId ());
772782 cmisDocument .setSourceFolderId (moveContext .request .getSourceFolderId ());
@@ -850,7 +860,8 @@ private void processSingleAttachmentMove(AttachmentMoveContext moveContext) {
850860 succinctProperties ,
851861 moveContext .entityAnnotations ,
852862 moveContext .targetEntity ,
853- moveContext .processingResults );
863+ moveContext .processingResults ,
864+ cmisDocument );
854865 }
855866
856867 } catch (ServiceException | IOException e ) {
@@ -899,6 +910,7 @@ private static class AttachmentProcessingResults {
899910 * @param entityAnnotations mapping of DB fields to SDM properties
900911 * @param targetEntity the target attachment entity (for type checking)
901912 * @param results holder for successful processing results
913+ * @param sourceCmisDocument the original cmisDocument from database with type and URL
902914 */
903915 private void processValidatedAttachment (
904916 String objectId ,
@@ -909,11 +921,13 @@ private void processValidatedAttachment(
909921 org .json .JSONObject succinctProperties ,
910922 Map <String , String > entityAnnotations ,
911923 com .sap .cds .reflect .CdsEntity targetEntity ,
912- AttachmentProcessingResults results ) {
924+ AttachmentProcessingResults results ,
925+ CmisDocument sourceCmisDocument ) {
913926 logger .info ("Attachment {} validation PASSED - Processing for DB insertion" , objectId );
914927 logger .info ("Entity annotations mapping (DB field -> SDM property): {}" , entityAnnotations );
915928
916- CmisDocument populatedDocument = createPopulatedDocument (succinctProperties );
929+ CmisDocument populatedDocument =
930+ createPopulatedDocument (succinctProperties , sourceCmisDocument );
917931 Map <String , Object > filteredSecondaryProps =
918932 filterSecondaryProperties (objectId , succinctProperties , entityAnnotations , targetEntity );
919933
@@ -932,15 +946,19 @@ private void processValidatedAttachment(
932946 }
933947
934948 /**
935- * Creates a CmisDocument with basic metadata from SDM response.
949+ * Creates a CmisDocument with basic metadata from SDM response and source document .
936950 *
937951 * @param succinctProperties SDM response properties
952+ * @param sourceCmisDocument the original cmisDocument from database with type and URL
938953 * @return populated CmisDocument
939954 */
940- private CmisDocument createPopulatedDocument (org .json .JSONObject succinctProperties ) {
955+ private CmisDocument createPopulatedDocument (
956+ org .json .JSONObject succinctProperties , CmisDocument sourceCmisDocument ) {
941957 CmisDocument document = new CmisDocument ();
942- document .setType (succinctProperties .optString ("sap:type" , null ));
943- document .setUrl (succinctProperties .optString ("sap:linkURL" , null ));
958+ // Preserve type and URL from source document (fetched from database)
959+ // This is essential for link attachments where URL is not in SDM response
960+ document .setType (sourceCmisDocument .getType ());
961+ document .setUrl (sourceCmisDocument .getUrl ());
944962 return document ;
945963 }
946964
0 commit comments