44
55import com .fasterxml .jackson .databind .JsonNode ;
66import com .fasterxml .jackson .databind .ObjectMapper ;
7+ import integration .com .sap .cds .sdm .Credentials ;
8+ import java .util .HashMap ;
9+ import java .util .Map ;
10+ import java .util .Properties ;
711
812public class CmisDocumentHelper {
913
@@ -18,6 +22,20 @@ public class CmisDocumentHelper {
1822 private static final String GET_METADATA_SCRIPT =
1923 "src/test/java/integration/com/sap/cds/sdm/utils/get-metadata.sh" ;
2024
25+ private static Map <String , String > getCmisEnv () {
26+ String tenancyModel = System .getProperty ("tenancyModel" );
27+ if ("multi" .equals (tenancyModel )) {
28+ Properties props = Credentials .getCredentials ();
29+ String repoId = props .getProperty ("defaultRepositoryIDMT" );
30+ if (repoId != null && !repoId .isEmpty ()) {
31+ Map <String , String > env = new HashMap <>();
32+ env .put ("SDM_REPOSITORY_ID" , repoId );
33+ return env ;
34+ }
35+ }
36+ return null ;
37+ }
38+
2139 /**
2240 * Resolves the CMIS parent folder ID from {@code entityId + "__attachments"}, then uploads a
2341 * local file to that folder via create.sh.
@@ -28,15 +46,17 @@ public class CmisDocumentHelper {
2846 */
2947 public static void createDocumentInCmis (String cmisName , String filePath , String entityId ) {
3048 try {
31- // Resolve the parent folder object ID from entityId__attachments
49+ Map < String , String > env = getCmisEnv ();
3250 String folderLine =
33- ShellScriptRunner .runAndCaptureOutput (GET_OBJECT_ID_SCRIPT , entityId + "__attachments" );
51+ ShellScriptRunner .runAndCaptureOutput (
52+ env , GET_OBJECT_ID_SCRIPT , entityId + "__attachments" );
3453 String parentFolderObjectId =
3554 folderLine != null && folderLine .contains (": " )
3655 ? folderLine .substring (folderLine .lastIndexOf (": " ) + 2 ).trim ()
3756 : folderLine ;
3857
39- int exitCode = ShellScriptRunner .run (CREATE_SCRIPT , cmisName , filePath , parentFolderObjectId );
58+ int exitCode =
59+ ShellScriptRunner .run (env , CREATE_SCRIPT , cmisName , filePath , parentFolderObjectId );
4060 if (exitCode != 0 ) {
4161 fail ("create.sh exited with non-zero code: " + exitCode );
4262 }
@@ -54,26 +74,25 @@ public static void createDocumentInCmis(String cmisName, String filePath, String
5474 */
5575 public static void deleteDocumentFromCmis (String entityId , String fileName ) {
5676 try {
57- // Step 1: resolve the parent folder object ID from entityId__attachments
77+ Map < String , String > env = getCmisEnv ();
5878 String folderLine =
59- ShellScriptRunner .runAndCaptureOutput (GET_OBJECT_ID_SCRIPT , entityId + "__attachments" );
79+ ShellScriptRunner .runAndCaptureOutput (
80+ env , GET_OBJECT_ID_SCRIPT , entityId + "__attachments" );
6081 String parentFolderObjectId =
6182 folderLine != null && folderLine .contains (": " )
6283 ? folderLine .substring (folderLine .lastIndexOf (": " ) + 2 ).trim ()
6384 : folderLine ;
6485
65- // Step 2: resolve the document object ID by filename inside the parent folder
6686 String docLine =
6787 ShellScriptRunner .runAndCaptureOutput (
68- GET_OBJECT_ID_SCRIPT , fileName , parentFolderObjectId , "cmis:document" );
88+ env , GET_OBJECT_ID_SCRIPT , fileName , parentFolderObjectId , "cmis:document" );
6989 String documentObjectId =
7090 docLine != null && docLine .contains (": " )
7191 ? docLine .substring (docLine .lastIndexOf (": " ) + 2 ).trim ()
7292 : docLine ;
7393
74- // Step 3: delete the document
7594 int deleteExitCode =
76- ShellScriptRunner .run (DELETE_SCRIPT , documentObjectId , parentFolderObjectId );
95+ ShellScriptRunner .run (env , DELETE_SCRIPT , documentObjectId , parentFolderObjectId );
7796 if (deleteExitCode != 0 ) {
7897 fail ("delete.sh failed with exit code: " + deleteExitCode );
7998 }
@@ -92,25 +111,24 @@ public static void deleteDocumentFromCmis(String entityId, String fileName) {
92111 */
93112 public static void readDocumentFromCmis (String entityId , String fileName , String outputPath ) {
94113 try {
95- // Step 1: resolve the parent folder object ID from entityId__attachments
114+ Map < String , String > env = getCmisEnv ();
96115 String folderLine =
97- ShellScriptRunner .runAndCaptureOutput (GET_OBJECT_ID_SCRIPT , entityId + "__attachments" );
116+ ShellScriptRunner .runAndCaptureOutput (
117+ env , GET_OBJECT_ID_SCRIPT , entityId + "__attachments" );
98118 String parentFolderObjectId =
99119 folderLine != null && folderLine .contains (": " )
100120 ? folderLine .substring (folderLine .lastIndexOf (": " ) + 2 ).trim ()
101121 : folderLine ;
102122
103- // Step 2: resolve the document object ID by filename inside the parent folder
104123 String docLine =
105124 ShellScriptRunner .runAndCaptureOutput (
106- GET_OBJECT_ID_SCRIPT , fileName , parentFolderObjectId , "cmis:document" );
125+ env , GET_OBJECT_ID_SCRIPT , fileName , parentFolderObjectId , "cmis:document" );
107126 String documentObjectId =
108127 docLine != null && docLine .contains (": " )
109128 ? docLine .substring (docLine .lastIndexOf (": " ) + 2 ).trim ()
110129 : docLine ;
111130
112- // Step 3: read/download the document
113- int exitCode = ShellScriptRunner .run (READ_SCRIPT , documentObjectId , outputPath );
131+ int exitCode = ShellScriptRunner .run (env , READ_SCRIPT , documentObjectId , outputPath );
114132 if (exitCode != 0 ) {
115133 fail ("read.sh exited with non-zero code: " + exitCode );
116134 }
@@ -129,26 +147,25 @@ public static void readDocumentFromCmis(String entityId, String fileName, String
129147 */
130148 public static String readDocumentMetadataFromCmis (String entityId , String fileName ) {
131149 try {
132- // Step 1: resolve the parent folder object ID from entityId__attachments
150+ Map < String , String > env = getCmisEnv ();
133151 String folderName = entityId + "__attachments" ;
134- String folderLine = ShellScriptRunner .runAndCaptureOutput (GET_OBJECT_ID_SCRIPT , folderName );
152+ String folderLine =
153+ ShellScriptRunner .runAndCaptureOutput (env , GET_OBJECT_ID_SCRIPT , folderName );
135154 String parentFolderObjectId =
136155 folderLine != null && folderLine .contains (": " )
137156 ? folderLine .substring (folderLine .lastIndexOf (": " ) + 2 ).trim ()
138157 : folderLine ;
139158
140- // Step 2: resolve the document object ID by filename inside the parent folder
141159 String docLine =
142160 ShellScriptRunner .runAndCaptureOutput (
143- GET_OBJECT_ID_SCRIPT , fileName , parentFolderObjectId , "cmis:document" );
161+ env , GET_OBJECT_ID_SCRIPT , fileName , parentFolderObjectId , "cmis:document" );
144162 String documentObjectId =
145163 docLine != null && docLine .contains (": " )
146164 ? docLine .substring (docLine .lastIndexOf (": " ) + 2 ).trim ()
147165 : docLine ;
148166
149- // Step 3: fetch metadata
150167 String metadata =
151- ShellScriptRunner .runAndCaptureOutput (GET_METADATA_SCRIPT , documentObjectId );
168+ ShellScriptRunner .runAndCaptureOutput (env , GET_METADATA_SCRIPT , documentObjectId );
152169 return metadata ;
153170 } catch (Exception e ) {
154171 fail ("Failed to read document metadata from CMIS: " + e .getMessage ());
0 commit comments