Skip to content

Commit edc17f5

Browse files
committed
multitenant fix
1 parent 0f958d8 commit edc17f5

8 files changed

Lines changed: 893 additions & 23 deletions

File tree

.github/workflows/multi tenancy_Integration.yml

Lines changed: 832 additions & 2 deletions
Large diffs are not rendered by default.

sdm/src/test/java/integration/com/sap/cds/sdm/utils/CmisDocumentHelper.java

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
import com.fasterxml.jackson.databind.JsonNode;
66
import 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

812
public 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());

sdm/src/test/java/integration/com/sap/cds/sdm/utils/ShellScriptRunner.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.ArrayList;
77
import java.util.Collections;
88
import java.util.List;
9+
import java.util.Map;
910
import java.util.concurrent.CopyOnWriteArrayList;
1011

1112
public class ShellScriptRunner {
@@ -20,12 +21,20 @@ public class ShellScriptRunner {
2021
*/
2122
public static int run(String scriptPath, String... args)
2223
throws IOException, InterruptedException {
24+
return run(null, scriptPath, args);
25+
}
26+
27+
public static int run(Map<String, String> env, String scriptPath, String... args)
28+
throws IOException, InterruptedException {
2329
List<String> command = new ArrayList<>();
2430
command.add("bash");
2531
command.add(scriptPath);
2632
Collections.addAll(command, args);
2733

2834
ProcessBuilder pb = new ProcessBuilder(command);
35+
if (env != null) {
36+
pb.environment().putAll(env);
37+
}
2938
pb.redirectErrorStream(false);
3039
Process process = pb.start();
3140

@@ -75,12 +84,21 @@ public static int run(String scriptPath, String... args)
7584
*/
7685
public static String runAndCaptureOutput(String scriptPath, String... args)
7786
throws IOException, InterruptedException {
87+
return runAndCaptureOutput(null, scriptPath, args);
88+
}
89+
90+
public static String runAndCaptureOutput(
91+
Map<String, String> env, String scriptPath, String... args)
92+
throws IOException, InterruptedException {
7893
List<String> command = new ArrayList<>();
7994
command.add("bash");
8095
command.add(scriptPath);
8196
Collections.addAll(command, args);
8297

8398
ProcessBuilder pb = new ProcessBuilder(command);
99+
if (env != null) {
100+
pb.environment().putAll(env);
101+
}
84102
pb.redirectErrorStream(false);
85103
Process process = pb.start();
86104

sdm/src/test/java/integration/com/sap/cds/sdm/utils/create.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ if [[ ! -f "$CONFIG_FILE" ]]; then
3636
exit 1
3737
fi
3838
load_props "$CONFIG_FILE"
39+
defaultRepositoryID="${SDM_REPOSITORY_ID:-$defaultRepositoryID}"
3940
CMIS_URL="${CMIS_URL%/}/"
4041

4142
# --- Validate positional parameters ---

sdm/src/test/java/integration/com/sap/cds/sdm/utils/delete.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ if [[ ! -f "$CONFIG_FILE" ]]; then
3737
exit 1
3838
fi
3939
load_props "$CONFIG_FILE"
40+
defaultRepositoryID="${SDM_REPOSITORY_ID:-$defaultRepositoryID}"
4041
CMIS_URL="${CMIS_URL%/}/"
4142

4243
# --- Validate positional parameters ---

sdm/src/test/java/integration/com/sap/cds/sdm/utils/get-metadata.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ if [[ ! -f "$CONFIG_FILE" ]]; then
3737
exit 1
3838
fi
3939
load_props "$CONFIG_FILE"
40+
defaultRepositoryID="${SDM_REPOSITORY_ID:-$defaultRepositoryID}"
4041
CMIS_URL="${CMIS_URL%/}/"
4142

4243
# --- Validate positional parameters ---

sdm/src/test/java/integration/com/sap/cds/sdm/utils/get-object-id.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ if [[ ! -f "$CONFIG_FILE" ]]; then
4141
exit 1
4242
fi
4343
load_props "$CONFIG_FILE"
44+
defaultRepositoryID="${SDM_REPOSITORY_ID:-$defaultRepositoryID}"
4445
CMIS_URL="${CMIS_URL%/}/"
4546

4647
# --- Validate positional parameters ---

sdm/src/test/java/integration/com/sap/cds/sdm/utils/read.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ if [[ ! -f "$CONFIG_FILE" ]]; then
3636
exit 1
3737
fi
3838
load_props "$CONFIG_FILE"
39+
defaultRepositoryID="${SDM_REPOSITORY_ID:-$defaultRepositoryID}"
3940
CMIS_URL="${CMIS_URL%/}/"
4041

4142
# --- Validate positional parameters ---

0 commit comments

Comments
 (0)