Skip to content

Commit 41a5ef3

Browse files
Merge branch 'deleteissue' of https://github.com/cap-java/sdm into deleteissue
2 parents 0052e47 + 4da2d8c commit 41a5ef3

5 files changed

Lines changed: 103 additions & 74 deletions

File tree

sdm/src/main/java/com/sap/cds/sdm/service/SDMServiceImpl.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,18 @@ public int updateAttachments(
167167
return 500;
168168
}
169169
}
170-
List<String> validSecondaryProperties =
171-
getValidSecondaryProperties(secondaryTypes, sdmCredentials, repositoryId, isSystemUser);
170+
List<String> validSecondaryProperties;
171+
try {
172+
validSecondaryProperties =
173+
getValidSecondaryProperties(secondaryTypes, sdmCredentials, repositoryId, isSystemUser);
174+
} catch (Exception e) {
175+
String errorMessage = e.getMessage();
176+
if (errorMessage != null && errorMessage.length() >= 3) {
177+
return (Integer.parseInt(errorMessage.substring(0, 3)));
178+
} else {
179+
return 500;
180+
}
181+
}
172182
SecondaryTypesKey secondaryTypesKey = new SecondaryTypesKey();
173183
secondaryTypesKey.setRepositoryId(repositoryId);
174184
CacheConfig.getSecondaryTypesCache()
@@ -573,6 +583,11 @@ public List<String> getValidSecondaryProperties(
573583
sdmCredentials.getUrl(), repositoryId, value);
574584
HttpGet getTypesRequest = new HttpGet(sdmUrl);
575585
try (var response = (CloseableHttpResponse) httpClient.execute(getTypesRequest)) {
586+
int statusCode = response.getStatusLine().getStatusCode();
587+
if (statusCode != 200) {
588+
String reasonPhrase = response.getStatusLine().getReasonPhrase();
589+
throw new ServiceException(statusCode + " : " + reasonPhrase);
590+
}
576591
HttpEntity responseEntity = response.getEntity();
577592
if (responseEntity != null
578593
&& Boolean.FALSE.equals(

sdm/src/main/java/com/sap/cds/sdm/service/handler/SDMCustomServiceHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void copyAttachments(AttachmentCopyEventContext context) throws IOExcepti
4747
String folderName = upID + "__" + facet;
4848
String repositoryId = SDMConstants.REPOSITORY_ID;
4949
Boolean isSystemUser = context.getSystemUser();
50-
Boolean folderExists = true;
50+
boolean folderExists = true;
5151

5252
SDMCredentials sdmCredentials = tokenHandler.getSDMCredentials();
5353
String folderId =

sdm/src/main/java/com/sap/cds/sdm/service/handler/SDMServiceGenericHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ public SDMServiceGenericHandler(RegisterService attachmentService) {
2020

2121
@On(event = "copyAttachments")
2222
public void copyAttachments(EventContext context) throws IOException {
23-
String up__ID = context.get("up__ID").toString();
23+
String upID = context.get("up__ID").toString();
2424
String objectIdsString = context.get("objectIds").toString();
2525
List<String> objectIds = Arrays.stream(objectIdsString.split(",")).map(String::trim).toList();
2626
var copyEventInput =
27-
new CopyAttachmentInput(up__ID, context.getTarget().getQualifiedName(), objectIds);
27+
new CopyAttachmentInput(upID, context.getTarget().getQualifiedName(), objectIds);
2828
attachmentService.copyAttachments(copyEventInput, context.getUserInfo().isSystemUser());
2929
context.setCompleted();
3030
}

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

Lines changed: 54 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -726,49 +726,60 @@ void testRenameMultipleEntitiesWithOneUnsupportedCharacter() {
726726
@Test
727727
@Order(14)
728728
void testRenameEntitiesWithoutSDMRole() throws IOException {
729-
// System.out.println("Test (14) : Rename attachments where user don't have SDM-Roles");
730-
// boolean testStatus = true;
731-
// try {
732-
// String apiResponse = apiNoRoles.editEntityDraft(appUrl, entityName, srvpath, entityID);
733-
// if ("Entity in draft mode".equals(apiResponse)) {
734-
// String[] name = {"sample456", "reference456", "footnote456"};
735-
// for (int i = 0; i < facet.length; i++) {
736-
// apiResponse =
737-
// apiNoRoles.renameAttachment(appUrl, entityName, facet[i], entityID, ID[i],
738-
// name[i]);
739-
// if (!"Renamed".equals(apiResponse)) {
740-
// testStatus = false;
741-
// System.out.println(facet[i] + " was not renamed: " + apiResponse);
742-
// }
743-
// }
744-
// if (testStatus) {
745-
// apiResponse = apiNoRoles.saveEntityDraft(appUrl, entityName, srvpath, entityID);
746-
// System.out.println("response is " + apiResponse);
747-
// String expected =
748-
// "[{\"code\":\"<none>\",\"message\":\"Could not update the following
749-
// files.\\n\\n\\t\\u2022 sample123\\n\\nYou do not have the required permissions to update
750-
// attachments. Kindly contact the admin\",\"numericSeverity\":3},"
751-
// + "{\"code\":\"<none>\",\"message\":\"Could not update the following
752-
// files.\\n\\n\\t\\u2022 reference123\\n\\nYou do not have the required permissions to update
753-
// attachments. Kindly contact the admin\",\"numericSeverity\":3},"
754-
// + "{\"code\":\"<none>\",\"message\":\"Could not update the following
755-
// files.\\n\\n\\t\\u2022 footnote123\\n\\nYou do not have the required permissions to update
756-
// attachments. Kindly contact the admin\",\"numericSeverity\":3}]";
757-
// if (!apiResponse.equals(expected)) {
758-
// testStatus = false;
759-
// System.out.println("Entity draft not saved: " + apiResponse);
760-
// }
761-
// } else {
762-
// apiNoRoles.saveEntityDraft(appUrl, entityName, srvpath, entityID);
763-
// }
764-
// }
765-
// } catch (Exception e) {
766-
// testStatus = false;
767-
// System.out.println("Exception during renaming entities: " + e.getMessage());
768-
// }
769-
// if (!testStatus) {
770-
// fail("Attachment got renamed without SDM roles.");
771-
// }
729+
System.out.println("Test (14) : Rename attachments where user don't have SDM-Roles");
730+
boolean testStatus = true;
731+
try {
732+
String apiResponse = apiNoRoles.editEntityDraft(appUrl, entityName, srvpath, entityID);
733+
if ("Entity in draft mode".equals(apiResponse)) {
734+
String[] name = {"sample456", "reference456", "footnote456"};
735+
for (int i = 0; i < facet.length; i++) {
736+
apiResponse =
737+
apiNoRoles.renameAttachment(appUrl, entityName, facet[i], entityID, ID[i], name[i]);
738+
if (!"Renamed".equals(apiResponse)) {
739+
testStatus = false;
740+
}
741+
}
742+
if (testStatus) {
743+
apiResponse = apiNoRoles.saveEntityDraft(appUrl, entityName, srvpath, entityID);
744+
String expected =
745+
"[{\"code\":\"<none>\",\"message\":\"Could not update the following files. \\n"
746+
+ //
747+
"\\n"
748+
+ //
749+
"\\t\\u2022 sample123\\n"
750+
+ //
751+
"\\n"
752+
+ //
753+
"You do not have the required permissions to update attachments. Kindly contact the admin\",\"numericSeverity\":3},{\"code\":\"<none>\",\"message\":\"Could not update the following files. \\n"
754+
+ //
755+
"\\n"
756+
+ //
757+
"\\t\\u2022 reference123\\n"
758+
+ //
759+
"\\n"
760+
+ //
761+
"You do not have the required permissions to update attachments. Kindly contact the admin\",\"numericSeverity\":3},{\"code\":\"<none>\",\"message\":\"Could not update the following files. \\n"
762+
+ //
763+
"\\n"
764+
+ //
765+
"\\t\\u2022 footnote123\\n"
766+
+ //
767+
"\\n"
768+
+ //
769+
"You do not have the required permissions to update attachments. Kindly contact the admin\",\"numericSeverity\":3}]";
770+
if (!apiResponse.equals(expected)) {
771+
testStatus = false;
772+
}
773+
} else {
774+
apiNoRoles.saveEntityDraft(appUrl, entityName, srvpath, entityID);
775+
}
776+
}
777+
} catch (Exception e) {
778+
testStatus = false;
779+
}
780+
if (!testStatus) {
781+
fail("Attachment got renamed without SDM roles.");
782+
}
772783
}
773784

774785
@Test

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

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -752,32 +752,35 @@ void testRenameMultipleAttachmentsWithOneUnsupportedCharacter() {
752752
@Test
753753
@Order(17)
754754
void testRenameSingleAttachmentWithoutSDMRole() throws IOException {
755-
// System.out.println("Test (17) : Rename attachments where user don't have SDM-Roles");
756-
// boolean testStatus = false;
757-
// String apiResponse = apiNoRoles.editEntityDraft(appUrl, entityName, srvpath, entityID);
758-
// String name = "sample123";
759-
// if (apiResponse == "Entity in draft mode") {
760-
// apiResponse =
761-
// apiNoRoles.renameAttachment(appUrl, entityName, facetName, entityID, attachmentID1,
762-
// name);
763-
// if (apiResponse.equals("Renamed")) {
764-
// apiResponse = apiNoRoles.saveEntityDraft(appUrl, entityName, srvpath, entityID);
765-
// System.out.println("response from apiNoRoles.saveEntityDraft() is " + apiResponse);
766-
// String expected =
767-
// "[{\"code\":\"<none>\",\"message\":\"Could not update the following
768-
// files.\\n\\n\\t\\u2022 valid_attachment1.pdf"
769-
// + "\\n\\nYou do not have the required permissions to update attachments.
770-
// Kindly contact the admin\",\"numericSeverity\":3}]";
771-
// if (apiResponse.equals(expected)) {
772-
// testStatus = true;
773-
// }
774-
// } else {
775-
// apiNoRoles.saveEntityDraft(appUrl, entityName, srvpath, entityID);
776-
// }
777-
// }
778-
// if (!testStatus) {
779-
// fail("Attachment was renamed");
780-
// }
755+
System.out.println("Test (17) : Rename attachments where user don't have SDM-Roles");
756+
boolean testStatus = false;
757+
String apiResponse = apiNoRoles.editEntityDraft(appUrl, entityName, srvpath, entityID);
758+
String name = "sample123";
759+
if (apiResponse == "Entity in draft mode") {
760+
apiResponse =
761+
apiNoRoles.renameAttachment(appUrl, entityName, facetName, entityID, attachmentID1, name);
762+
if (apiResponse.equals("Renamed")) {
763+
apiResponse = apiNoRoles.saveEntityDraft(appUrl, entityName, srvpath, entityID);
764+
String expected =
765+
"[{\"code\":\"<none>\",\"message\":\"Could not update the following files. \\n"
766+
+ //
767+
"\\n"
768+
+ //
769+
"\\t\\u2022 valid_attachment1.pdf\\n"
770+
+ //
771+
"\\n"
772+
+ //
773+
"You do not have the required permissions to update attachments. Kindly contact the admin\",\"numericSeverity\":3}]";
774+
if (apiResponse.equals(expected)) {
775+
testStatus = true;
776+
}
777+
} else {
778+
apiNoRoles.saveEntityDraft(appUrl, entityName, srvpath, entityID);
779+
}
780+
}
781+
if (!testStatus) {
782+
fail("Attachment got renamed without SDM roles.");
783+
}
781784
}
782785

783786
@Test

0 commit comments

Comments
 (0)