Skip to content

Commit

Permalink
Merged dspace-cris-7 into DSC-1124-inline-group-fields-should-be-indexed
Browse files Browse the repository at this point in the history
  • Loading branch information
vins01-4science committed Oct 12, 2023
2 parents 3db6753 + e20c3ef commit a35679c
Show file tree
Hide file tree
Showing 218 changed files with 9,241 additions and 804 deletions.
2 changes: 1 addition & 1 deletion dspace-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<parent>
<groupId>org.dspace</groupId>
<artifactId>dspace-parent</artifactId>
<version>cris-2023.01.01-SNAPSHOT</version>
<version>cris-2023.02.00-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

Expand Down
23 changes: 12 additions & 11 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 @@ -1158,16 +1159,14 @@ private Item updateItem(EntityRow entityRow, Item item)
handler.logInfo("Row " + entityRow.getRow() + " - Item updated successfully - ID: " + item.getID());

switch (entityRow.getAction()) {
case UPDATE:
itemService.update(context, item);
break;
case UPDATE_WORKFLOW:
startWorkflow(entityRow, item);
break;
case UPDATE_ARCHIVE:
installItem(entityRow, item);
break;
default:
itemService.update(context, item);
break;
}

Expand Down Expand Up @@ -1308,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 @@ -1366,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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
Expand Down Expand Up @@ -107,7 +108,12 @@ public void appendValueOnLastRow(String header, String value, String separator)
throw new IllegalArgumentException("Unknown header '" + header + "'");
}
String cellContent = WorkbookUtils.getCellValue(lastRow, column);
createCell(lastRow, column, isEmpty(cellContent) ? value : cellContent + separator + value);
createCell(lastRow, column,
getValueLimitedByLength(isEmpty(cellContent) ? value : cellContent + separator + value));
}

private String getValueLimitedByLength(String value) {
return StringUtils.length(value) > 32726 ? value.substring(0, 32725) + "…" : value;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @author Jason Sherman [email protected]
*/
public class BrandedPreviewJPEGFilter extends MediaFilter {
public class BrandedPreviewJPEGFilter extends JPEGFilter {
@Override
public String getFilteredName(String oldFilename) {
return oldFilename + ".preview.jpg";
Expand All @@ -36,14 +36,6 @@ public String getBundleName() {
return "BRANDED_PREVIEW";
}

/**
* @return String bitstreamformat
*/
@Override
public String getFormatString() {
return "JPEG";
}

/**
* @return String description
*/
Expand Down Expand Up @@ -81,9 +73,7 @@ public InputStream getDestinationStream(Item currentItem, InputStream source, bo
String brandFont = configurationService.getProperty("webui.preview.brand.font");
int brandFontPoint = configurationService.getIntProperty("webui.preview.brand.fontpoint");

JPEGFilter jpegFilter = new JPEGFilter();
return jpegFilter
.getThumbDim(currentItem, buf, verbose, xmax, ymax, blurring, hqscaling, brandHeight, brandFontPoint,
return getThumbDim(currentItem, buf, verbose, xmax, ymax, blurring, hqscaling, brandHeight, brandFontPoint,
brandFont);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.metadata.export;

/**
* @author Vincenzo Mecca (vins01-4science - vincenzo.mecca at 4science.com)
**/
public class DspaceExportMetadataSchemaException extends Exception {

public DspaceExportMetadataSchemaException(Exception e) {
super(e);
}

public DspaceExportMetadataSchemaException(String message, Exception e) {
super(message, e);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.metadata.export;

import java.io.File;

import org.apache.commons.cli.ParseException;
import org.dspace.core.Context;

/**
* This script can be use to export a given {@code MetadataSchema} into its
* registry file, that respects the standard DTD / XSD DSpace xml registry.
* <p/>
* This script is supposed to work with the CLI (command-line-interface),
* it accepts only two parameters {@code -i <schema-id> -f <file-path>}
* respectively representing:
* <ul>
* <li><b>{@code schema-id}</b>: id of the schema to export</li>
* <li><b>{@code file-path}</b>:full file path of the file that will contain the export</li>
* <ul>
*
* @author Vincenzo Mecca (vins01-4science - vincenzo.mecca at 4science.com)
*
*/
public class MetadataSchemaExportCliScript extends MetadataSchemaExportScript {

protected String filename;

@Override
public void setup() throws ParseException {
super.setup();
filename = commandLine.getOptionValue('f');
}

@Override
protected File getExportedFile(Context context) throws DspaceExportMetadataSchemaException {
try {
File file = new File(filename);
return metadataSchemaExportService.exportMetadataSchemaToFile(context, metadataSchema, file);
} catch (DspaceExportMetadataSchemaException e) {
handler.logError("Problem occured while exporting the schema to file: " + filename, e);
throw e;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.metadata.export;

import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;

/**
* @author Vincenzo Mecca (vins01-4science - vincenzo.mecca at 4science.com)
*
*/
public class MetadataSchemaExportCliScriptConfiguration
extends MetadataSchemaExportScriptConfiguration<MetadataSchemaExportCliScript> {

@Override
public Options getOptions() {
Options options = super.getOptions();

options.addOption(
Option.builder("f").longOpt("file")
.desc("The temporary file-name to use")
.hasArg()
.build()
);

return options;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.metadata.export;

import java.io.File;
import java.io.FileInputStream;
import java.sql.SQLException;
import java.text.MessageFormat;

import org.apache.commons.cli.ParseException;
import org.dspace.app.metadata.export.service.MetadataExportServiceFactory;
import org.dspace.app.metadata.export.service.MetadataSchemaExportService;
import org.dspace.content.MetadataSchema;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.MetadataSchemaService;
import org.dspace.core.Context;
import org.dspace.scripts.DSpaceRunnable;
import org.dspace.services.factory.DSpaceServicesFactory;

/**
* This script can be use to export a given {@code MetadataSchema} into its
* registry file, that respects the standard DTD / XSD DSpace xml registry.
* <p/>
* This script is supposed to work with the webapp, it accepts only one
* parameter {@code -i <schema-id>} representing the id of the schema that
* will be exported.
*
* @author Vincenzo Mecca (vins01-4science - vincenzo.mecca at 4science.com)
**/
public class MetadataSchemaExportScript
extends DSpaceRunnable<MetadataSchemaExportScriptConfiguration<MetadataSchemaExportScript>> {

protected static String REGISTRY_FILENAME_TEMPLATE = "{0}-types.xml";

protected MetadataSchemaService metadataSchemaService =
ContentServiceFactory.getInstance().getMetadataSchemaService();

protected MetadataSchemaExportService metadataSchemaExportService =
MetadataExportServiceFactory.getInstance().getMetadataSchemaExportService();

protected boolean help;
protected int id;

protected MetadataSchema metadataSchema;

@Override
public MetadataSchemaExportScriptConfiguration getScriptConfiguration() {
return DSpaceServicesFactory
.getInstance().getServiceManager()
.getServiceByName("export-schema", MetadataSchemaExportScriptConfiguration.class);
}

@Override
public void setup() throws ParseException {
help = commandLine.hasOption('h');
try {
id = Integer.parseInt(commandLine.getOptionValue('i'));
} catch (Exception e) {
handler.logError("Cannot parse the id argument ( " + id + " )! You should provide an integer!");
throw new ParseException("Cannot parse the id argument ( " + id + " )! You should provide an integer!");
}
}

@Override
public void internalRun() throws Exception {
if (help) {
printHelp();
return;
}

Context context = new Context();
try {
validate(context);
exportMetadataSchema(context);
} catch (Exception e) {
context.abort();
throw e;
}
}

private void validate(Context context) throws SQLException, ParseException {
metadataSchema = this.metadataSchemaService.find(context, id);
if (metadataSchema == null) {
handler.logError("Cannot find the metadata-schema with id: " + id);
throw new ParseException("Cannot find the metadata-schema with id: " + id);
}
}

private void exportMetadataSchema(Context context) throws Exception {
handler.logInfo(
"Exporting the metadata-schema file for the schema " + metadataSchema.getName()
);
try {
File tempFile = getExportedFile(context);

handler.logInfo(
"Exported to file: " + tempFile.getAbsolutePath()
);

try (FileInputStream fis = new FileInputStream(tempFile)) {
handler.logInfo("Summarizing export ...");
context.turnOffAuthorisationSystem();
handler.writeFilestream(
context, getFilename(metadataSchema), fis, "application/xml", false
);
context.restoreAuthSystemState();
}
} catch (Exception e) {
handler.logError("Problem occured while exporting the schema!", e);
throw e;
}
}

protected String getFilename(MetadataSchema ms) {
return MessageFormat.format(REGISTRY_FILENAME_TEMPLATE, ms.getName());
}

protected File getExportedFile(Context context) throws DspaceExportMetadataSchemaException {
return this.metadataSchemaExportService.exportMetadataSchemaToFile(context, metadataSchema);
}
}
Loading

0 comments on commit a35679c

Please sign in to comment.