Skip to content

Commit eb44cd5

Browse files
Merge branch 'develop' into deleteissue
2 parents 5214b1a + 36d4ded commit eb44cd5

7 files changed

Lines changed: 816 additions & 12 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3131

3232
<excluded.generation.package>sdm/generated/</excluded.generation.package>
33-
<cds.services.version>3.5.0</cds.services.version>
33+
<cds.services.version>3.10.3</cds.services.version>
3434

3535
<generation-folder>src/gen</generation-folder>
3636

sdm/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,6 @@
319319
<groupId>com.sap.cloud.sdk.cloudplatform</groupId>
320320
<artifactId>resilience4j</artifactId>
321321
</exclusion>
322-
<exclusion>
323-
<groupId>com.sap.cloud.security</groupId>
324-
<artifactId>env</artifactId>
325-
</exclusion>
326322
<exclusion>
327323
<groupId>org.bouncycastle</groupId>
328324
<artifactId>bcprov-jdk18on</artifactId>

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

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,11 @@ public String readAttachment(
413413
Response response = httpClient.newCall(request).execute();
414414
if (!response.isSuccessful()) {
415415
System.out.println(
416-
"Read Attachment failed in the"
416+
"Read Attachment failed in the "
417417
+ facetName
418418
+ " section. Error :"
419419
+ response.body().string());
420-
throw new IOException("Read Attachment failed in the" + facetName + " section");
420+
throw new IOException("Read Attachment failed in the " + facetName + " section");
421421
}
422422
return "OK";
423423
} catch (IOException e) {
@@ -489,7 +489,7 @@ public String deleteAttachment(
489489
try (Response deleteResponse = httpClient.newCall(request).execute()) {
490490
if (deleteResponse.code() != 204) {
491491
System.out.println(
492-
"Delete Attachment failed in the"
492+
"Delete Attachment failed in the "
493493
+ facetName
494494
+ " section. Error :"
495495
+ deleteResponse.body().string());
@@ -532,7 +532,7 @@ public String renameAttachment(
532532
try (Response renameResponse = httpClient.newCall(request).execute()) {
533533
if (renameResponse.code() != 200) {
534534
System.out.println(
535-
"Rename Attachment failed in the"
535+
"Rename Attachment failed in the "
536536
+ facetName
537537
+ " section. Error : "
538538
+ renameResponse.body().string());
@@ -631,6 +631,51 @@ public String updateInvalidSecondaryProperty(
631631
}
632632
}
633633

634+
public String copyAttachment(
635+
String appUrl,
636+
String entityName,
637+
String facetName,
638+
String entityID,
639+
List<String> sourceObjectIds)
640+
throws IOException {
641+
String objectIds = String.join(",", sourceObjectIds);
642+
String url =
643+
"https://"
644+
+ appUrl
645+
+ "/odata/v4/"
646+
+ serviceName
647+
+ "/"
648+
+ entityName
649+
+ "(ID="
650+
+ entityID
651+
+ ",IsActiveEntity=false)/"
652+
+ facetName
653+
+ "/"
654+
+ serviceName
655+
+ ".copyAttachments";
656+
657+
MediaType mediaType = MediaType.parse("application/json");
658+
659+
String jsonPayload =
660+
"{" + "\"up__ID\": \"" + entityID + "\"," + "\"objectIds\": \"" + objectIds + "\"" + "}";
661+
662+
RequestBody body = RequestBody.create(mediaType, jsonPayload);
663+
664+
Request request =
665+
new Request.Builder().url(url).post(body).addHeader("Authorization", token).build();
666+
667+
try (Response response = httpClient.newCall(request).execute()) {
668+
if (!response.isSuccessful()) {
669+
throw new IOException(
670+
"Could not copy attachments: " + response.code() + " - " + response.body().string());
671+
}
672+
return "Attachments copied successfully";
673+
} catch (IOException e) {
674+
System.out.println("Error while copying attachments: " + e.getMessage());
675+
throw new IOException(e);
676+
}
677+
}
678+
634679
public Map<String, Object> fetchMetadata(
635680
String appUrl, String entityName, String facetName, String entityID, String ID)
636681
throws IOException {
@@ -671,4 +716,48 @@ public Map<String, Object> fetchMetadata(
671716
}
672717
}
673718
}
719+
720+
public List<Map<String, Object>> fetchEntityMetadata(
721+
String appUrl, String entityName, String facetName, String entityID) throws IOException {
722+
723+
// Construct the URL for fetching attachment metadata
724+
String url =
725+
"https://"
726+
+ appUrl
727+
+ "/odata/v4/"
728+
+ serviceName
729+
+ "/"
730+
+ entityName
731+
+ "(ID="
732+
+ entityID
733+
+ ",IsActiveEntity=true)/"
734+
+ facetName;
735+
736+
// Make a GET request to fetch the attachment metadata
737+
Request request =
738+
new Request.Builder().url(url).get().addHeader("Authorization", token).build();
739+
740+
try (Response response = httpClient.newCall(request).execute()) {
741+
if (response.code() != 200) {
742+
System.out.println("Response code: " + response.code());
743+
System.out.println(
744+
"Fetch metadata failed for "
745+
+ facetName
746+
+ " Section. Error: "
747+
+ response.body().string());
748+
throw new IOException("Could not fetch " + facetName + " metadata");
749+
} else {
750+
ObjectMapper objectMapper = new ObjectMapper();
751+
Map<String, Object> entityData =
752+
objectMapper.readValue(
753+
response.body().string(), new com.fasterxml.jackson.core.type.TypeReference<>() {});
754+
Object value = entityData.get("value");
755+
List<Map<String, Object>> result =
756+
objectMapper.convertValue(
757+
value,
758+
new com.fasterxml.jackson.core.type.TypeReference<List<Map<String, Object>>>() {});
759+
return result;
760+
}
761+
}
762+
}
674763
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,20 @@ public String updateInvalidSecondaryProperty(
5858
String ID,
5959
String invalidSecondaryProperty);
6060

61+
public String copyAttachment(
62+
String appUrl,
63+
String entityName,
64+
String facetName,
65+
String entityID,
66+
List<String> sourceObjectIds)
67+
throws IOException;
68+
6169
public Map<String, Object> fetchMetadata(
6270
String appUrl, String entityName, String facetName, String entityID, String ID)
6371
throws IOException;
6472

73+
public List<Map<String, Object>> fetchEntityMetadata(
74+
String appUrl, String entityName, String facetName, String entityID) throws IOException;
75+
6576
String deleteEntityDraft(String appUrl, String entityName, String entityID);
6677
}

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

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ public String readAttachment(
397397
+ facetName
398398
+ " section. Error :"
399399
+ response.body().string());
400-
throw new IOException("Read Attachment failed in the" + facetName + " section");
400+
throw new IOException("Read Attachment failed in the " + facetName + " section");
401401
}
402402
return "OK";
403403
} catch (IOException e) {
@@ -465,7 +465,7 @@ public String deleteAttachment(
465465
try (Response deleteResponse = httpClient.newCall(request).execute()) {
466466
if (deleteResponse.code() != 204) {
467467
System.out.println(
468-
"Delete Attachment failed in the"
468+
"Delete Attachment failed in the "
469469
+ facetName
470470
+ " section. Error :"
471471
+ deleteResponse.body().string());
@@ -601,6 +601,45 @@ public String updateInvalidSecondaryProperty(
601601
}
602602
}
603603

604+
public String copyAttachment(
605+
String appUrl,
606+
String entityName,
607+
String facetName,
608+
String entityID,
609+
List<String> sourceObjectIds)
610+
throws IOException {
611+
String objectIds = String.join(",", sourceObjectIds);
612+
String url =
613+
"https://"
614+
+ appUrl
615+
+ "/api/admin/"
616+
+ entityName
617+
+ "(ID="
618+
+ entityID
619+
+ ",IsActiveEntity=false)/"
620+
+ facetName
621+
+ "/"
622+
+ "AdminService.copyAttachments";
623+
624+
MediaType mediaType = MediaType.parse("application/json");
625+
626+
String jsonPayload =
627+
"{" + "\"up__ID\": \"" + entityID + "\"," + "\"objectIds\": \"" + objectIds + "\"" + "}";
628+
629+
RequestBody body = RequestBody.create(mediaType, jsonPayload);
630+
631+
Request request =
632+
new Request.Builder().url(url).post(body).addHeader("Authorization", token).build();
633+
634+
try (Response response = httpClient.newCall(request).execute()) {
635+
if (!response.isSuccessful()) {
636+
throw new IOException(
637+
"Could not copy attachments: " + response.code() + " - " + response.body().string());
638+
}
639+
return "Attachments copied successfully";
640+
}
641+
}
642+
604643
public Map<String, Object> fetchMetadata(
605644
String appUrl, String entityName, String facetName, String entityID, String ID)
606645
throws IOException {
@@ -639,4 +678,46 @@ public Map<String, Object> fetchMetadata(
639678
}
640679
}
641680
}
681+
682+
public List<Map<String, Object>> fetchEntityMetadata(
683+
String appUrl, String entityName, String facetName, String entityID) throws IOException {
684+
685+
// Construct the URL for fetching attachment metadata
686+
String url =
687+
"https://"
688+
+ appUrl
689+
+ "/api/admin/"
690+
+ entityName
691+
+ "(ID="
692+
+ entityID
693+
+ ",IsActiveEntity=true)/"
694+
+ facetName;
695+
696+
// Make a GET request to fetch the attachment metadata
697+
Request request =
698+
new Request.Builder().url(url).get().addHeader("Authorization", token).build();
699+
700+
try (Response response = httpClient.newCall(request).execute()) {
701+
if (response.code() != 200) {
702+
System.out.println("Response code: " + response.code());
703+
System.out.println(
704+
"Fetch metadata failed for "
705+
+ facetName
706+
+ " Section. Error: "
707+
+ response.body().string());
708+
throw new IOException("Could not fetch " + facetName + " metadata");
709+
} else {
710+
ObjectMapper objectMapper = new ObjectMapper();
711+
Map<String, Object> entityData =
712+
objectMapper.readValue(
713+
response.body().string(), new com.fasterxml.jackson.core.type.TypeReference<>() {});
714+
Object value = entityData.get("value");
715+
List<Map<String, Object>> result =
716+
objectMapper.convertValue(
717+
value,
718+
new com.fasterxml.jackson.core.type.TypeReference<List<Map<String, Object>>>() {});
719+
return result;
720+
}
721+
}
722+
}
642723
}

0 commit comments

Comments
 (0)