Skip to content

Commit f129b61

Browse files
Merge branch 'develop' into tmvirusscan
2 parents f8add6a + 72e219b commit f129b61

5 files changed

Lines changed: 3583 additions & 2 deletions

File tree

sdm/src/test/java/integration/com/sap/cds/sdm/Api.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,67 @@ public String copyAttachment(
728728
}
729729
}
730730

731+
public Map<String, Object> moveAttachment(
732+
String appUrl,
733+
String entityName,
734+
String facetName,
735+
String targetEntityID,
736+
String sourceFolderId,
737+
List<String> objectIds,
738+
String sourceFacet)
739+
throws IOException {
740+
String objectIdsString = String.join(",", objectIds);
741+
String url =
742+
"https://"
743+
+ appUrl
744+
+ "/odata/v4/"
745+
+ serviceName
746+
+ "/"
747+
+ entityName
748+
+ "(ID="
749+
+ targetEntityID
750+
+ ",IsActiveEntity=false)/"
751+
+ facetName
752+
+ "/"
753+
+ serviceName
754+
+ ".moveAttachments";
755+
756+
MediaType mediaType = MediaType.parse("application/json");
757+
758+
StringBuilder jsonPayload = new StringBuilder();
759+
jsonPayload.append("{");
760+
jsonPayload.append("\"sourceFolderId\": \"").append(sourceFolderId).append("\",");
761+
jsonPayload.append("\"up__ID\": \"").append(targetEntityID).append("\",");
762+
jsonPayload.append("\"objectIds\": \"").append(objectIdsString).append("\"");
763+
764+
if (sourceFacet != null && !sourceFacet.isEmpty()) {
765+
jsonPayload.append(",\"sourceFacet\": \"").append(sourceFacet).append("\"");
766+
}
767+
768+
jsonPayload.append("}");
769+
770+
RequestBody body = RequestBody.create(jsonPayload.toString(), mediaType);
771+
772+
Request request =
773+
new Request.Builder().url(url).post(body).addHeader("Authorization", token).build();
774+
775+
try (Response response = executeWithRetry(request)) {
776+
String responseBody = response.body().string();
777+
778+
if (!response.isSuccessful()) {
779+
throw new IOException(
780+
"Could not move attachments: " + response.code() + " - " + responseBody);
781+
}
782+
783+
@SuppressWarnings("unchecked")
784+
Map<String, Object> result = objectMapper.readValue(responseBody, Map.class);
785+
return result;
786+
} catch (IOException e) {
787+
System.out.println("Error while moving attachments: " + e.getMessage());
788+
throw new IOException(e);
789+
}
790+
}
791+
731792
public String createLink(
732793
String appUrl,
733794
String entityName,

sdm/src/test/java/integration/com/sap/cds/sdm/ApiInterface.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ public String copyAttachment(
6666
List<String> sourceObjectIds)
6767
throws IOException;
6868

69+
public Map<String, Object> moveAttachment(
70+
String appUrl,
71+
String entityName,
72+
String facetName,
73+
String targetEntityID,
74+
String sourceFolderId,
75+
List<String> objectIds,
76+
String sourceFacet)
77+
throws IOException;
78+
6979
public Map<String, Object> fetchMetadata(
7080
String appUrl, String entityName, String facetName, String entityID, String ID)
7181
throws IOException;

sdm/src/test/java/integration/com/sap/cds/sdm/ApiMT.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,64 @@ public String copyAttachment(
687687
}
688688
}
689689

690+
public Map<String, Object> moveAttachment(
691+
String appUrl,
692+
String entityName,
693+
String facetName,
694+
String targetEntityID,
695+
String sourceFolderId,
696+
List<String> objectIds,
697+
String sourceFacet)
698+
throws IOException {
699+
String objectIdsString = String.join(",", objectIds);
700+
String url =
701+
"https://"
702+
+ appUrl
703+
+ "/api/admin/"
704+
+ entityName
705+
+ "(ID="
706+
+ targetEntityID
707+
+ ",IsActiveEntity=false)/"
708+
+ facetName
709+
+ "/"
710+
+ "AdminService.moveAttachments";
711+
712+
MediaType mediaType = MediaType.parse("application/json");
713+
714+
StringBuilder jsonPayload = new StringBuilder();
715+
jsonPayload.append("{");
716+
jsonPayload.append("\"sourceFolderId\": \"").append(sourceFolderId).append("\",");
717+
jsonPayload.append("\"up__ID\": \"").append(targetEntityID).append("\",");
718+
jsonPayload.append("\"objectIds\": \"").append(objectIdsString).append("\"");
719+
720+
if (sourceFacet != null && !sourceFacet.isEmpty()) {
721+
jsonPayload.append(",\"sourceFacet\": \"").append(sourceFacet).append("\"");
722+
}
723+
724+
jsonPayload.append("}");
725+
726+
RequestBody body = RequestBody.create(jsonPayload.toString(), mediaType);
727+
728+
Request request =
729+
new Request.Builder().url(url).post(body).addHeader("Authorization", token).build();
730+
731+
try (Response response = executeWithRetry(request)) {
732+
String responseBody = response.body().string();
733+
734+
if (!response.isSuccessful()) {
735+
throw new IOException(
736+
"Could not move attachments: " + response.code() + " - " + responseBody);
737+
}
738+
739+
@SuppressWarnings("unchecked")
740+
Map<String, Object> result = objectMapper.readValue(responseBody, Map.class);
741+
return result;
742+
} catch (IOException e) {
743+
System.out.println("Error while moving attachments: " + e.getMessage());
744+
throw new IOException(e);
745+
}
746+
}
747+
690748
public String createLink(
691749
String appUrl,
692750
String entityName,

0 commit comments

Comments
 (0)