Skip to content

Commit 43dfa3f

Browse files
Merge branch 'develop' into errorHandlingFix
2 parents 973e70c + 9c1a9cf commit 43dfa3f

File tree

5 files changed

+1131
-19
lines changed

5 files changed

+1131
-19
lines changed

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

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public String deleteEntityDraft(String appUrl, String entityName, String entityI
206206
System.out.println("Delete entity failed. Error : " + response.body().string());
207207
throw new IOException("Could not delete entity");
208208
}
209-
return "Entity Deleted";
209+
return "Entity Draft Deleted";
210210
} catch (IOException e) {
211211
System.out.println("Could not delete entity : " + e);
212212
}
@@ -676,6 +676,94 @@ public String copyAttachment(
676676
}
677677
}
678678

679+
public String createLink(
680+
String appUrl,
681+
String entityName,
682+
String facetName,
683+
String entityID,
684+
String linkName,
685+
String linkUrl)
686+
throws IOException {
687+
String url =
688+
"https://"
689+
+ appUrl
690+
+ "/odata/v4/"
691+
+ serviceName
692+
+ "/"
693+
+ entityName
694+
+ "(ID="
695+
+ entityID
696+
+ ",IsActiveEntity=false)/"
697+
+ facetName
698+
+ "/"
699+
+ serviceName
700+
+ ".createLink";
701+
702+
MediaType mediaType = MediaType.parse("application/json");
703+
704+
String jsonPayload =
705+
"{" + "\"name\": \"" + linkName + "\"," + "\"url\": \"" + linkUrl + "\"" + "}";
706+
707+
RequestBody body = RequestBody.create(mediaType, jsonPayload);
708+
709+
Request request =
710+
new Request.Builder().url(url).post(body).addHeader("Authorization", token).build();
711+
712+
try (Response response = httpClient.newCall(request).execute()) {
713+
if (!response.isSuccessful()) {
714+
throw new IOException(
715+
"Could not create link: " + response.code() + " - " + response.body().string());
716+
}
717+
return "Link created successfully";
718+
} catch (IOException e) {
719+
System.out.println("Error while creating link: " + e.getMessage());
720+
throw new IOException(e);
721+
}
722+
}
723+
724+
public String openAttachment(
725+
String appUrl, String entityName, String facetName, String entityID, String ID)
726+
throws IOException {
727+
String url =
728+
"https://"
729+
+ appUrl
730+
+ "/odata/v4/"
731+
+ serviceName
732+
+ "/Books(ID="
733+
+ entityID
734+
+ ",IsActiveEntity=true)"
735+
+ "/"
736+
+ facetName
737+
+ "(up__ID="
738+
+ entityID
739+
+ ",ID="
740+
+ ID
741+
+ ",IsActiveEntity=true)"
742+
+ "/"
743+
+ serviceName
744+
+ ".openAttachment";
745+
746+
MediaType mediaType = MediaType.parse("application/json");
747+
748+
String jsonPayload = "{}";
749+
750+
RequestBody body = RequestBody.create(mediaType, jsonPayload);
751+
752+
Request request =
753+
new Request.Builder().url(url).post(body).addHeader("Authorization", token).build();
754+
755+
try (Response response = httpClient.newCall(request).execute()) {
756+
if (!response.isSuccessful()) {
757+
throw new IOException(
758+
"Could not open attachment: " + response.code() + " - " + response.body().string());
759+
}
760+
return "Attachment opened successfully";
761+
} catch (IOException e) {
762+
System.out.println("Error while opening attachment: " + e.getMessage());
763+
throw new IOException(e);
764+
}
765+
}
766+
679767
public Map<String, Object> fetchMetadata(
680768
String appUrl, String entityName, String facetName, String entityID, String ID)
681769
throws IOException {

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,18 @@ public Map<String, Object> fetchMetadata(
7373
public List<Map<String, Object>> fetchEntityMetadata(
7474
String appUrl, String entityName, String facetName, String entityID) throws IOException;
7575

76+
public String createLink(
77+
String appUrl,
78+
String entityName,
79+
String facetName,
80+
String entityID,
81+
String linkName,
82+
String linkUrl)
83+
throws IOException;
84+
85+
public String openAttachment(
86+
String appUrl, String entityName, String facetName, String entityID, String ID)
87+
throws IOException;
88+
7689
String deleteEntityDraft(String appUrl, String entityName, String entityID);
7790
}

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

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public String deleteEntityDraft(String appUrl, String entityName, String entityI
196196
System.out.println("Delete entity failed. Error : " + response.body().string());
197197
throw new IOException("Could not delete entity");
198198
}
199-
return "Entity Deleted";
199+
return "Entity Draft Deleted";
200200
} catch (IOException e) {
201201
System.out.println("Could not delete entity : " + e);
202202
}
@@ -505,11 +505,6 @@ public String renameAttachment(
505505

506506
try (Response renameResponse = httpClient.newCall(request).execute()) {
507507
if (renameResponse.code() != 200) {
508-
System.out.println(
509-
"Rename Attachment failed in the "
510-
+ facetName
511-
+ " section. Error : "
512-
+ renameResponse.body().string());
513508
throw new IOException("Attachment was not renamed in section: " + facetName);
514509
}
515510
return "Renamed";
@@ -640,6 +635,86 @@ public String copyAttachment(
640635
}
641636
}
642637

638+
public String createLink(
639+
String appUrl,
640+
String entityName,
641+
String facetName,
642+
String entityID,
643+
String linkName,
644+
String linkUrl)
645+
throws IOException {
646+
String url =
647+
"https://"
648+
+ appUrl
649+
+ "/api/admin/"
650+
+ entityName
651+
+ "(ID="
652+
+ entityID
653+
+ ",IsActiveEntity=false)/"
654+
+ facetName
655+
+ "/"
656+
+ "AdminService.createLink";
657+
658+
MediaType mediaType = MediaType.parse("application/json");
659+
660+
String jsonPayload =
661+
"{" + "\"name\": \"" + linkName + "\"," + "\"url\": \"" + linkUrl + "\"" + "}";
662+
663+
RequestBody body = RequestBody.create(mediaType, jsonPayload);
664+
665+
Request request =
666+
new Request.Builder().url(url).post(body).addHeader("Authorization", token).build();
667+
668+
try (Response response = httpClient.newCall(request).execute()) {
669+
if (!response.isSuccessful()) {
670+
throw new IOException(
671+
"Could not create link: " + response.code() + " - " + response.body().string());
672+
}
673+
return "Link created successfully";
674+
}
675+
}
676+
677+
public String openAttachment(
678+
String appUrl, String entityName, String facetName, String entityID, String ID)
679+
throws IOException {
680+
String url =
681+
"https://"
682+
+ appUrl
683+
+ "/api/admin/"
684+
+ entityName
685+
+ "(ID="
686+
+ entityID
687+
+ ",IsActiveEntity=true)/"
688+
+ facetName
689+
+ "(up__ID="
690+
+ entityID
691+
+ ",ID="
692+
+ ID
693+
+ ",IsActiveEntity=true)"
694+
+ "/"
695+
+ "AdminService.openAttachment";
696+
697+
MediaType mediaType = MediaType.parse("application/json");
698+
699+
String jsonPayload = "{}";
700+
701+
RequestBody body = RequestBody.create(mediaType, jsonPayload);
702+
703+
Request request =
704+
new Request.Builder().url(url).post(body).addHeader("Authorization", token).build();
705+
706+
try (Response response = httpClient.newCall(request).execute()) {
707+
if (!response.isSuccessful()) {
708+
throw new IOException(
709+
"Could not open attachment: " + response.code() + " - " + response.body().string());
710+
}
711+
return "Attachment opened successfully";
712+
} catch (IOException e) {
713+
System.out.println("Error while opening attachment: " + e.getMessage());
714+
throw new IOException(e);
715+
}
716+
}
717+
643718
public Map<String, Object> fetchMetadata(
644719
String appUrl, String entityName, String facetName, String entityID, String ID)
645720
throws IOException {

0 commit comments

Comments
 (0)