11package com .sap .cds .sdm .service .handler ;
22
3- import static com .sap .cds .sdm .persistence .DBQuery .*;
4-
53import com .sap .cds .Result ;
64import com .sap .cds .feature .attachments .generated .cds4j .sap .attachments .MediaData ;
75import com .sap .cds .feature .attachments .service .AttachmentService ;
@@ -41,16 +39,19 @@ public class SDMAttachmentsServiceHandler implements EventHandler {
4139 private final DocumentUploadService documentService ;
4240 private static final Logger logger = LoggerFactory .getLogger (SDMAttachmentsServiceHandler .class );
4341 private final TokenHandler tokenHandler ;
42+ private final DBQuery dbQuery ;
4443
4544 public SDMAttachmentsServiceHandler (
4645 PersistenceService persistenceService ,
4746 SDMService sdmService ,
4847 DocumentUploadService documentService ,
49- TokenHandler tokenHandler ) {
48+ TokenHandler tokenHandler ,
49+ DBQuery dbQuery ) {
5050 this .persistenceService = persistenceService ;
5151 this .sdmService = sdmService ;
5252 this .documentService = documentService ;
5353 this .tokenHandler = tokenHandler ;
54+ this .dbQuery = dbQuery ;
5455 }
5556
5657 @ On (event = AttachmentService .EVENT_CREATE_ATTACHMENT )
@@ -77,8 +78,7 @@ public void markAttachmentAsDeleted(AttachmentMarkAsDeletedEventContext context)
7778 String subdomain = contextValues [3 ];
7879 // check if only attachment exists against the folderId
7980 List <CmisDocument > cmisDocuments =
80- DBQuery .getDBQueryInstance ()
81- .getAttachmentsForFolder (entity , persistenceService , folderId , context );
81+ dbQuery .getAttachmentsForFolder (entity , persistenceService , folderId , context );
8282 if (cmisDocuments .isEmpty ()) {
8383 // deleteFolder API
8484 sdmService .deleteDocument ("deleteTree" , folderId , userEmail , subdomain );
@@ -165,8 +165,7 @@ private void processEntities(AttachmentCreateEventContext eventContext)
165165 String upID = (String ) attachmentIds .get (upIdKey );
166166
167167 Result result =
168- DBQuery .getDBQueryInstance ()
169- .getAttachmentsForUPID (attachmentDraftEntity , persistenceService , upID , upIdKey );
168+ dbQuery .getAttachmentsForUPID (attachmentDraftEntity , persistenceService , upID , upIdKey );
170169 checkAttachmentConstraints (eventContext , attachmentDraftEntity , upID , upIdKey );
171170
172171 MediaData data = eventContext .getData ();
@@ -204,9 +203,8 @@ private void checkAttachmentConstraints(
204203 throws ServiceException {
205204 // Fetch the row count for current repository
206205 Result result =
207- DBQuery .getDBQueryInstance ()
208- .getAttachmentsForUPIDAndRepository (
209- attachmentDraftEntity , persistenceService , upID , upIdKey );
206+ dbQuery .getAttachmentsForUPIDAndRepository (
207+ attachmentDraftEntity , persistenceService , upID , upIdKey );
210208 long rowCount = result .rowCount ();
211209 String errorMessageCount =
212210 SDMUtils .getAttachmentCountAndMessage (
@@ -305,9 +303,8 @@ private void handleCreateDocumentResult(
305303 throw new ServiceException (SDMConstants .USER_NOT_AUTHORISED_ERROR );
306304 default :
307305 cmisDocument .setObjectId (createResult .get ("objectId" ).toString ());
308- DBQuery .getDBQueryInstance ()
309- .addAttachmentToDraft (
310- getAttachmentDraftEntity (eventContext ), persistenceService , cmisDocument );
306+ dbQuery .addAttachmentToDraft (
307+ getAttachmentDraftEntity (eventContext ), persistenceService , cmisDocument );
311308 finalizeContext (eventContext , cmisDocument );
312309 }
313310 }
0 commit comments