Skip to content

Commit d204513

Browse files
Merge pull request #296 from cap-java/mimetype
fixed mime type validation error
2 parents 832da90 + 27ad5eb commit d204513

File tree

7 files changed

+336
-105
lines changed

7 files changed

+336
-105
lines changed

sdm/src/main/java/com/sap/cds/sdm/constants/SDMConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ private SDMConstants() {
4545
public static final String SDM_CONNECTIONPOOL_PREFIX = "cds.attachments.sdm.http.%s";
4646
public static final String USER_NOT_AUTHORISED_ERROR =
4747
"You do not have the required permissions to upload attachments. Please contact your administrator for access.";
48+
public static final String MIMETYPE_INVALID_ERROR =
49+
"This file type is not allowed in this repository. Contact your administrator for assistance.";
4850
public static final String USER_NOT_AUTHORISED_ERROR_LINK =
4951
"You do not have the required permissions to create links. Please contact your administrator for access.";
5052
public static final String FILE_NOT_FOUND_ERROR = "Object not found in repository";

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,11 @@ private void formResponse(
320320
} else if ((responseCode == 403)
321321
&& (responseString.equals("User does not have required scope"))) {
322322
status = "unauthorized";
323+
} else if (responseCode == 403) {
324+
JSONObject jsonResponse = new JSONObject(responseString);
325+
String message = jsonResponse.getString("message");
326+
if ("MIME type of the uploaded file is blocked according to your repository configuration."
327+
.equals(message)) status = "blocked";
323328
} else {
324329
JSONObject jsonResponse = new JSONObject(responseString);
325330
String message = jsonResponse.getString("message");

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ private void handleCreateDocumentResult(
293293
throw new ServiceException(createResult.get("message").toString());
294294
case "unauthorized":
295295
throw new ServiceException(SDMConstants.USER_NOT_AUTHORISED_ERROR);
296+
case "blocked":
297+
throw new ServiceException(SDMConstants.MIMETYPE_INVALID_ERROR);
296298
default:
297299
cmisDocument.setObjectId(createResult.get("objectId").toString());
298300
dbQuery.addAttachmentToDraft(

0 commit comments

Comments
 (0)