Skip to content
Merged
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
61 changes: 61 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 @@ -728,6 +728,67 @@ public String copyAttachment(
}
}

public Map<String, Object> moveAttachment(
String appUrl,
String entityName,
String facetName,
String targetEntityID,
String sourceFolderId,
List<String> objectIds,
String sourceFacet)
throws IOException {
String objectIdsString = String.join(",", objectIds);
String url =
"https://"
+ appUrl
+ "/odata/v4/"
+ serviceName
+ "/"
+ entityName
+ "(ID="
+ targetEntityID
+ ",IsActiveEntity=false)/"
+ facetName
+ "/"
+ serviceName
+ ".moveAttachments";

MediaType mediaType = MediaType.parse("application/json");

StringBuilder jsonPayload = new StringBuilder();
jsonPayload.append("{");
jsonPayload.append("\"sourceFolderId\": \"").append(sourceFolderId).append("\",");
jsonPayload.append("\"up__ID\": \"").append(targetEntityID).append("\",");
jsonPayload.append("\"objectIds\": \"").append(objectIdsString).append("\"");

if (sourceFacet != null && !sourceFacet.isEmpty()) {
jsonPayload.append(",\"sourceFacet\": \"").append(sourceFacet).append("\"");
}

jsonPayload.append("}");

RequestBody body = RequestBody.create(jsonPayload.toString(), mediaType);

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

try (Response response = executeWithRetry(request)) {
String responseBody = response.body().string();

if (!response.isSuccessful()) {
throw new IOException(
"Could not move attachments: " + response.code() + " - " + responseBody);
}

@SuppressWarnings("unchecked")
Map<String, Object> result = objectMapper.readValue(responseBody, Map.class);
return result;
} catch (IOException e) {
System.out.println("Error while moving attachments: " + e.getMessage());
throw new IOException(e);
}
}

public String createLink(
String appUrl,
String entityName,
Expand Down
10 changes: 10 additions & 0 deletions sdm/src/test/java/integration/com/sap/cds/sdm/ApiInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ public String copyAttachment(
List<String> sourceObjectIds)
throws IOException;

public Map<String, Object> moveAttachment(
String appUrl,
String entityName,
String facetName,
String targetEntityID,
String sourceFolderId,
List<String> objectIds,
String sourceFacet)
throws IOException;

public Map<String, Object> fetchMetadata(
String appUrl, String entityName, String facetName, String entityID, String ID)
throws IOException;
Expand Down
58 changes: 58 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 @@ -687,6 +687,64 @@ public String copyAttachment(
}
}

public Map<String, Object> moveAttachment(
String appUrl,
String entityName,
String facetName,
String targetEntityID,
String sourceFolderId,
List<String> objectIds,
String sourceFacet)
throws IOException {
String objectIdsString = String.join(",", objectIds);
String url =
"https://"
+ appUrl
+ "/api/admin/"
+ entityName
+ "(ID="
+ targetEntityID
+ ",IsActiveEntity=false)/"
+ facetName
+ "/"
+ "AdminService.moveAttachments";

MediaType mediaType = MediaType.parse("application/json");

StringBuilder jsonPayload = new StringBuilder();
jsonPayload.append("{");
jsonPayload.append("\"sourceFolderId\": \"").append(sourceFolderId).append("\",");
jsonPayload.append("\"up__ID\": \"").append(targetEntityID).append("\",");
jsonPayload.append("\"objectIds\": \"").append(objectIdsString).append("\"");

if (sourceFacet != null && !sourceFacet.isEmpty()) {
jsonPayload.append(",\"sourceFacet\": \"").append(sourceFacet).append("\"");
}

jsonPayload.append("}");

RequestBody body = RequestBody.create(jsonPayload.toString(), mediaType);

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

try (Response response = executeWithRetry(request)) {
String responseBody = response.body().string();

if (!response.isSuccessful()) {
throw new IOException(
"Could not move attachments: " + response.code() + " - " + responseBody);
}

@SuppressWarnings("unchecked")
Map<String, Object> result = objectMapper.readValue(responseBody, Map.class);
return result;
} catch (IOException e) {
System.out.println("Error while moving attachments: " + e.getMessage());
throw new IOException(e);
}
}

public String createLink(
String appUrl,
String entityName,
Expand Down
Loading
Loading