Skip to content

Commit

Permalink
[CST-11876] Fixed bulk import values split
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaGiamminonni committed Sep 27, 2023
1 parent bcff6b6 commit d7ca5e1
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions dspace-api/src/main/java/org/dspace/app/bulkedit/BulkImport.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import static org.apache.commons.lang3.StringUtils.isAllBlank;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.apache.commons.lang3.StringUtils.split;
import static org.apache.commons.lang3.StringUtils.splitByWholeSeparator;
import static org.apache.commons.lang3.StringUtils.startsWith;
import static org.apache.commons.lang3.exception.ExceptionUtils.getRootCauseMessage;
import static org.apache.commons.lang3.math.NumberUtils.isCreatable;
Expand Down Expand Up @@ -609,7 +609,8 @@ private boolean areMetadataValuesValid(Row row, boolean manyMetadataValuesAllowe
for (int index = firstMetadataIndex; index < row.getLastCellNum(); index++) {

String cellValue = WorkbookUtils.getCellValue(row, index);
String[] values = isNotBlank(cellValue) ? split(cellValue, METADATA_SEPARATOR) : new String[] { "" };
String[] values = isNotBlank(cellValue) ? splitByWholeSeparator(cellValue, METADATA_SEPARATOR)
: new String[] { "" };
if (values.length > 1 && !manyMetadataValuesAllowed) {
handleValidationErrorOnRow(row, "Multiple metadata value on the same cell not allowed "
+ "in the metadata group sheets: " + cellValue);
Expand Down Expand Up @@ -743,7 +744,7 @@ private List<String> validateAccessConditions(Row row) {
Map<String, AccessConditionOption> accessConditionOptions = getUploadAccessConditions();

return Arrays.stream(getAccessConditionValues(row))
.map(accessCondition -> split(accessCondition, ACCESS_CONDITION_ATTRIBUTES_SEPARATOR)[0])
.map(accessCondition -> splitByWholeSeparator(accessCondition, ACCESS_CONDITION_ATTRIBUTES_SEPARATOR)[0])
.filter(accessConditionName -> !accessConditionOptions.containsKey(accessConditionName))
.collect(Collectors.toList());
}
Expand Down Expand Up @@ -788,14 +789,14 @@ private List<AccessCondition> buildAccessConditions(Row row, String[] accessCond
}

return Arrays.stream(accessConditions)
.map(accessCondition -> split(accessCondition, ACCESS_CONDITION_ATTRIBUTES_SEPARATOR))
.map(accessCondition -> splitByWholeSeparator(accessCondition, ACCESS_CONDITION_ATTRIBUTES_SEPARATOR))
.map(accessConditionAttributes -> buildAccessCondition(accessConditionAttributes))
.collect(Collectors.toList());
}

private String[] getAccessConditionValues(Row row) {
String accessConditionCellValue = getCellValue(row, ACCESS_CONDITION_HEADER);
return split(accessConditionCellValue, METADATA_SEPARATOR);
return splitByWholeSeparator(accessConditionCellValue, METADATA_SEPARATOR);
}

private AccessCondition buildAccessCondition(String[] accessCondition) {
Expand Down Expand Up @@ -1306,12 +1307,13 @@ private void removeSingleMetadata(DSpaceObject dso, MetadataField field, String
}

private String getMetadataField(String field) {
return field.contains(LANGUAGE_SEPARATOR_PREFIX) ? split(field, LANGUAGE_SEPARATOR_PREFIX)[0] : field;
return field.contains(LANGUAGE_SEPARATOR_PREFIX) ? splitByWholeSeparator(field, LANGUAGE_SEPARATOR_PREFIX)[0]
: field;
}

private String getMetadataLanguage(String field) {
if (field.contains(LANGUAGE_SEPARATOR_PREFIX)) {
return split(field, LANGUAGE_SEPARATOR_PREFIX)[1].replace(LANGUAGE_SEPARATOR_SUFFIX, "");
return splitByWholeSeparator(field, LANGUAGE_SEPARATOR_PREFIX)[1].replace(LANGUAGE_SEPARATOR_SUFFIX, "");
}
return null;
}
Expand Down Expand Up @@ -1364,7 +1366,8 @@ private MultiValuedMap<String, MetadataValueVO> getMetadataFromRow(Row row, Map<
if (index >= firstMetadataIndex) {

String cellValue = WorkbookUtils.getCellValue(row, index);
String[] values = isNotBlank(cellValue) ? split(cellValue, METADATA_SEPARATOR) : new String[] { "" };
String[] values = isNotBlank(cellValue) ? splitByWholeSeparator(cellValue, METADATA_SEPARATOR)
: new String[] { "" };

List<MetadataValueVO> metadataValues = Arrays.stream(values)
.map(value -> buildMetadataValueVO(row, value, isMetadataGroupsSheet))
Expand Down

0 comments on commit d7ca5e1

Please sign in to comment.