Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "automatic"
}
53 changes: 53 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,59 @@ public List<Map<String, Object>> fetchEntityMetadataDraft(
}
}

@Override
public String downloadSelectedAttachments(
Comment thread
PujaDeshmukh17 marked this conversation as resolved.
Fixed
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 @@ -118,6 +118,10 @@ public String openAttachment(

String deleteEntityDraft(String appUrl, String entityName, String entityID);

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

public Map<String, Object> fetchChangelog(
String appUrl, String entityName, String facetName, String entityID, String ID)
throws IOException;
Expand Down
49 changes: 49 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,55 @@ public List<Map<String, Object>> fetchEntityMetadataDraft(
}
}

@Override
public String downloadSelectedAttachments(
Comment thread
github-code-quality[bot] marked this conversation as resolved.
Fixed
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.stream.Collectors;
import okhttp3.*;
import okio.ByteString;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.jupiter.api.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.stream.Collectors;
import okhttp3.*;
import okio.ByteString;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.jupiter.api.*;

Expand Down Expand Up @@ -7118,4 +7119,5 @@ void testRenameAttachmentWithExtensionChange_BeforeSave() throws IOException {
// // delete the draft entity
// api.deleteEntityDraft(appUrl, entityName, testEntityID);
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.stream.Collectors;
import okhttp3.*;
import okio.ByteString;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.jupiter.api.*;

Expand Down
1 change: 1 addition & 0 deletions target/spotless-index
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
E1vGKgcMGeK1ECjHhzRTYcAK0E6t00+5of5G89Esy1A=
Loading