Skip to content
106 changes: 106 additions & 0 deletions sdm/src/test/java/integration/com/sap/cds/sdm/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,112 @@ public List<Map<String, Object>> fetchEntityMetadataDraft(
}
}

@Override
public String downloadSelectedAttachmentsDraft(
String appUrl, String entityName, String facetName, String entityID, List<String> ids)
throws IOException {
String url =
"https://"
+ appUrl
+ "/odata/v4/"
+ serviceName
+ "/"
+ entityName
+ "(ID="
+ entityID
+ ",IsActiveEntity=false)"
+ "/"
+ facetName
+ "(up__ID="
+ entityID
+ ",ID="
+ ids.get(0)
+ ",IsActiveEntity=false)"
+ "/"
+ serviceName
+ ".downloadSelectedAttachments";

String idsParam = String.join(",", ids);
String jsonPayload = "{\"ids\": \"" + idsParam + "\"}";

RequestBody body = RequestBody.create(MediaType.parse("application/json"), jsonPayload);

Request request =
new Request.Builder().url(url).post(body).addHeader("Authorization", token).build();

try (Response response = executeWithRetry(request)) {
if (!response.isSuccessful()) {
throw new IOException(
"Could not download attachments: "
+ response.code()
+ " - "
+ response.body().string());
}
String responseBody = response.body().string();
Map<String, Object> responseMap = objectMapper.readValue(responseBody, Map.class);
if (responseMap.containsKey("value")) {
return responseMap.get("value").toString();
}
return responseBody;
} catch (IOException e) {
System.out.println("Error while downloading attachments: " + e.getMessage());
throw new IOException(e);
}
}

@Override
public String downloadSelectedAttachments(
String appUrl, String entityName, String facetName, String entityID, List<String> ids)
throws IOException {
String url =
"https://"
+ appUrl
+ "/odata/v4/"
+ serviceName
+ "/"
+ entityName
+ "(ID="
+ entityID
+ ",IsActiveEntity=true)"
+ "/"
+ facetName
+ "(up__ID="
+ entityID
+ ",ID="
+ ids.get(0)
+ ",IsActiveEntity=true)"
+ "/"
+ serviceName
+ ".downloadSelectedAttachments";

String idsParam = String.join(",", ids);
String jsonPayload = "{\"ids\": \"" + idsParam + "\"}";

RequestBody body = RequestBody.create(MediaType.parse("application/json"), jsonPayload);

Request request =
new Request.Builder().url(url).post(body).addHeader("Authorization", token).build();

try (Response response = executeWithRetry(request)) {
if (!response.isSuccessful()) {
throw new IOException(
"Could not download attachments: "
+ response.code()
+ " - "
+ response.body().string());
}
String responseBody = response.body().string();
Map<String, Object> responseMap = objectMapper.readValue(responseBody, Map.class);
if (responseMap.containsKey("value")) {
return responseMap.get("value").toString();
}
return responseBody;
} catch (IOException e) {
System.out.println("Error while downloading attachments: " + e.getMessage());
throw new IOException(e);
}
}

public Map<String, Object> fetchChangelog(
String appUrl, String entityName, String facetName, String entityID, String ID)
throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,12 @@ public String openAttachment(
public Map<String, Object> fetchChangelog(
String appUrl, String entityName, String facetName, String entityID, String ID)
throws IOException;

public String downloadSelectedAttachments(
String appUrl, String entityName, String facetName, String entityID, List<String> ids)
throws IOException;

public String downloadSelectedAttachmentsDraft(
String appUrl, String entityName, String facetName, String entityID, List<String> ids)
throws IOException;
}
98 changes: 98 additions & 0 deletions sdm/src/test/java/integration/com/sap/cds/sdm/ApiMT.java
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,104 @@ public List<Map<String, Object>> fetchEntityMetadataDraft(
}
}

@Override
public String downloadSelectedAttachmentsDraft(
String appUrl, String entityName, String facetName, String entityID, List<String> ids)
throws IOException {
String url =
"https://"
+ appUrl
+ "/api/admin/"
+ entityName
+ "(ID="
+ entityID
+ ",IsActiveEntity=false)"
+ "/"
+ facetName
+ "(up__ID="
+ entityID
+ ",ID="
+ ids.get(0)
+ ",IsActiveEntity=false)"
+ "/AdminService.downloadSelectedAttachments";

String idsParam = String.join(",", ids);
String jsonPayload = "{\"ids\": \"" + idsParam + "\"}";

RequestBody body = RequestBody.create(MediaType.parse("application/json"), jsonPayload);

Request request =
new Request.Builder().url(url).post(body).addHeader("Authorization", token).build();

try (Response response = executeWithRetry(request)) {
if (!response.isSuccessful()) {
throw new IOException(
"Could not download attachments: "
+ response.code()
+ " - "
+ response.body().string());
}
String responseBody = response.body().string();
Map<String, Object> responseMap = objectMapper.readValue(responseBody, Map.class);
if (responseMap.containsKey("value")) {
return responseMap.get("value").toString();
}
return responseBody;
} catch (IOException e) {
System.out.println("Error while downloading attachments: " + e.getMessage());
throw new IOException(e);
}
}

@Override
public String downloadSelectedAttachments(
String appUrl, String entityName, String facetName, String entityID, List<String> ids)
throws IOException {
String url =
"https://"
+ appUrl
+ "/api/admin/"
+ entityName
+ "(ID="
+ entityID
+ ",IsActiveEntity=true)"
+ "/"
+ facetName
+ "(up__ID="
+ entityID
+ ",ID="
+ ids.get(0)
+ ",IsActiveEntity=true)"
+ "/AdminService.downloadSelectedAttachments";

String idsParam = String.join(",", ids);
String jsonPayload = "{\"ids\": \"" + idsParam + "\"}";

RequestBody body = RequestBody.create(MediaType.parse("application/json"), jsonPayload);

Request request =
new Request.Builder().url(url).post(body).addHeader("Authorization", token).build();

try (Response response = executeWithRetry(request)) {
if (!response.isSuccessful()) {
throw new IOException(
"Could not download attachments: "
+ response.code()
+ " - "
+ response.body().string());
}
String responseBody = response.body().string();
Map<String, Object> responseMap = objectMapper.readValue(responseBody, Map.class);
if (responseMap.containsKey("value")) {
return responseMap.get("value").toString();
}
return responseBody;
} catch (IOException e) {
System.out.println("Error while downloading attachments: " + e.getMessage());
throw new IOException(e);
}
}

public Map<String, Object> fetchChangelog(
String appUrl, String entityName, String facetName, String entityID, String ID)
throws IOException {
Expand Down
Loading
Loading