Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdm/src/main/java/com/sap/cds/sdm/constants/SDMConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ private SDMConstants() {
public static final String FAILED_TO_FETCH_UP_ID = "Failed to fetch up_id";
public static final String FAILED_TO_FETCH_FACET =
"Invalid facet format, unable to extract required information.";
public static final String FILENAME_WHITESPACE_WARNING_MESSAGE =
"The following file(s) could not be updated because the filename(s) cannot be empty.";

public static String nameConstraintMessage(
List<String> fileNameWithRestrictedCharacters, String operation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public void updateName(CdsCreateEventContext context, List<CdsData> data, String
List<String> filesNotFound = new ArrayList<>();
List<String> filesWithUnsupportedProperties = new ArrayList<>();
Map<String, String> badRequest = new HashMap<>();
List<String> fileWithWhiteSpace = new ArrayList<>();
List<String> noSDMRoles = new ArrayList<>();
for (Map<String, Object> entity : data) {
List<Map<String, Object>> attachments = (List<Map<String, Object>>) entity.get(composition);
Expand All @@ -95,7 +96,8 @@ public void updateName(CdsCreateEventContext context, List<CdsData> data, String
composition,
attachmentEntity,
secondaryPropertiesWithInvalidDefinitions,
noSDMRoles);
noSDMRoles,
fileWithWhiteSpace);
handleWarnings(
context,
fileNameWithRestrictedCharacters,
Expand All @@ -104,7 +106,8 @@ public void updateName(CdsCreateEventContext context, List<CdsData> data, String
filesWithUnsupportedProperties,
badRequest,
propertyTitles,
noSDMRoles);
noSDMRoles,
fileWithWhiteSpace);
}
}
}
Expand All @@ -130,7 +133,8 @@ private void processEntity(
String composition,
Optional<CdsEntity> attachmentEntity,
Map<String, String> secondaryPropertiesWithInvalidDefinitions,
List<String> noSDMRoles)
List<String> noSDMRoles,
List<String> fileWithWhiteSpace)
throws IOException {
List<Map<String, Object>> attachments = (List<Map<String, Object>>) entity.get(composition);
if (attachments != null) {
Expand All @@ -146,7 +150,8 @@ private void processEntity(
composition,
attachmentEntity,
secondaryPropertiesWithInvalidDefinitions,
noSDMRoles);
noSDMRoles,
fileWithWhiteSpace);
}
SecondaryPropertiesKey secondaryPropertiesKey =
new SecondaryPropertiesKey(); // Emptying cache after attachments are updated in loop
Expand All @@ -166,7 +171,8 @@ private void processAttachment(
String composition,
Optional<CdsEntity> attachmentEntity,
Map<String, String> secondaryPropertiesWithInvalidDefinitions,
List<String> noSDMRoles)
List<String> noSDMRoles,
List<String> fileWithWhiteSpace)
throws IOException {
String id = (String) attachment.get("ID");
String fileNameInDB;
Expand Down Expand Up @@ -230,8 +236,11 @@ private void processAttachment(
throw new ServiceException("Filename cannot be empty");
}
} else {
if (filenameInRequest == null) {
throw new ServiceException("Filename cannot be empty");
if (filenameInRequest == null || filenameInRequest.trim().length() == 0) {
fileWithWhiteSpace.add(fileNameInDB);
replacePropertiesInAttachment(
attachment, fileNameInDB, propertiesInDB, secondaryTypeProperties);

} else if (!fileNameInDB.equals(
filenameInRequest)) { // If the file name in DB is not equal to the file name in
// request, it means that the file name has been modified
Expand Down Expand Up @@ -322,7 +331,8 @@ private void handleWarnings(
List<String> filesWithUnsupportedProperties,
Map<String, String> badRequest,
Map<String, String> propertyTitles,
List<String> noSDMRoles) {
List<String> noSDMRoles,
List<String> fileWithWhiteSpace) {
if (!fileNameWithRestrictedCharacters.isEmpty()) {
context
.getMessages()
Expand Down Expand Up @@ -363,6 +373,14 @@ private void handleWarnings(
if (!noSDMRoles.isEmpty()) {
context.getMessages().warn(SDMConstants.noSDMRolesMessage(noSDMRoles, "create"));
}
if (!fileWithWhiteSpace.isEmpty()) {
context
.getMessages()
.warn(
String.format(
SDMConstants.FILENAME_WHITESPACE_WARNING_MESSAGE,
String.join(", ", fileWithWhiteSpace)));
}
}

private List<String> getEntityCompositions(CdsCreateEventContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ private void renameDocument(
Map<String, String> badRequest = new HashMap<>();
Map<String, String> propertyTitles = new HashMap<>();
List<String> noSDMRoles = new ArrayList<>();
List<String> fileWithWhiteSpace = new ArrayList<>();
for (Map<String, Object> entity : data) {
List<Map<String, Object>> attachments = (List<Map<String, Object>>) entity.get(composition);
if (attachments != null && !attachments.isEmpty()) {
Expand All @@ -109,7 +110,8 @@ private void renameDocument(
filesWithUnsupportedProperties,
badRequest,
secondaryPropertiesWithInvalidDefinitions,
noSDMRoles);
noSDMRoles,
fileWithWhiteSpace);
}
}
handleWarnings(
Expand All @@ -120,7 +122,8 @@ private void renameDocument(
filesWithUnsupportedProperties,
badRequest,
propertyTitles,
noSDMRoles);
noSDMRoles,
fileWithWhiteSpace);
}

private void processAttachments(
Expand All @@ -133,7 +136,8 @@ private void processAttachments(
List<String> filesWithUnsupportedProperties,
Map<String, String> badRequest,
Map<String, String> secondaryPropertiesWithInvalidDefinitions,
List<String> noSDMRoles)
List<String> noSDMRoles,
List<String> fileWithWhiteSpace)
throws IOException {
Iterator<Map<String, Object>> iterator = attachments.iterator();
while (iterator.hasNext()) {
Expand All @@ -148,7 +152,8 @@ private void processAttachments(
filesWithUnsupportedProperties,
badRequest,
secondaryPropertiesWithInvalidDefinitions,
noSDMRoles);
noSDMRoles,
fileWithWhiteSpace);
}
SecondaryPropertiesKey secondaryPropertiesKey = new SecondaryPropertiesKey();
secondaryPropertiesKey.setRepositoryId(SDMConstants.REPOSITORY_ID);
Expand All @@ -168,7 +173,8 @@ public void processAttachment(
List<String> filesWithUnsupportedProperties,
Map<String, String> badRequest,
Map<String, String> secondaryPropertiesWithInvalidDefinitions,
List<String> noSDMRoles)
List<String> noSDMRoles,
List<String> fileWithWhiteSpace)
throws IOException {
String id = (String) attachment.get("ID");
Map<String, String> secondaryTypeProperties =
Expand Down Expand Up @@ -222,8 +228,10 @@ public void processAttachment(
throw new ServiceException("Filename cannot be empty");
}
} else {
if (filenameInRequest == null) {
throw new ServiceException("Filename cannot be empty");
if (filenameInRequest == null || filenameInRequest.trim().length() == 0) {
fileWithWhiteSpace.add(fileNameInDB);
replacePropertiesInAttachment(
attachment, fileNameInDB, propertiesInDB, secondaryTypeProperties);
} else if (!fileNameInDB.equals(filenameInRequest)) {
updatedSecondaryProperties.put("filename", filenameInRequest);
}
Expand Down Expand Up @@ -313,7 +321,8 @@ private void handleWarnings(
List<String> filesWithUnsupportedProperties,
Map<String, String> badRequest,
Map<String, String> propertyTitles,
List<String> noSDMRoles) {
List<String> noSDMRoles,
List<String> fileWithWhiteSpace) {
if (!fileNameWithRestrictedCharacters.isEmpty()) {
context
.getMessages()
Expand Down Expand Up @@ -353,6 +362,14 @@ private void handleWarnings(
if (!noSDMRoles.isEmpty()) {
context.getMessages().warn(SDMConstants.noSDMRolesMessage(noSDMRoles, "update"));
}
if (!fileWithWhiteSpace.isEmpty()) {
context
.getMessages()
.warn(
String.format(
SDMConstants.FILENAME_WHITESPACE_WARNING_MESSAGE,
String.join(", ", fileWithWhiteSpace)));
}
}

private List<String> getEntityCompositions(CdsUpdateEventContext context) {
Expand Down
Loading
Loading