mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Make parse protected to make it override in MetadataExportSearch Add Test for Double Quoted Search CSV Export
(cherry picked from commit 39a45f7f34
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
4b678f2b7d
commit
f79d012cbc
@@ -14,6 +14,8 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.cli.DefaultParser;
|
||||
import org.apache.commons.cli.DefaultParser.Builder;
|
||||
import org.apache.commons.cli.ParseException;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.MetadataDSpaceCsvExportServiceImpl;
|
||||
@@ -167,4 +169,14 @@ public class MetadataExportSearch extends DSpaceRunnable<MetadataExportSearchScr
|
||||
}
|
||||
return scopeObj;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected StepResult parse(String[] args) throws ParseException {
|
||||
commandLine = new DefaultParser().parse(getScriptConfiguration().getOptions(), args);
|
||||
Builder builder = new DefaultParser().builder();
|
||||
builder.setStripLeadingAndTrailingQuotes(false);
|
||||
commandLine = builder.build().parse(getScriptConfiguration().getOptions(), args);
|
||||
setup();
|
||||
return StepResult.Continue;
|
||||
}
|
||||
}
|
||||
|
@@ -117,7 +117,7 @@ public abstract class DSpaceRunnable<T extends ScriptConfiguration> implements R
|
||||
* @param args The primitive array of Strings representing the parameters
|
||||
* @throws ParseException If something goes wrong
|
||||
*/
|
||||
private StepResult parse(String[] args) throws ParseException {
|
||||
protected StepResult parse(String[] args) throws ParseException {
|
||||
commandLine = new DefaultParser().parse(getScriptConfiguration().getOptions(), args);
|
||||
setup();
|
||||
return StepResult.Continue;
|
||||
|
@@ -251,4 +251,35 @@ public class MetadataExportSearchIT extends AbstractIntegrationTestWithDatabase
|
||||
assertNotNull(exception);
|
||||
assertEquals("nonExisting is not a valid search filter", exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exportMetadataSearchDoubleQuotedArgumentTest() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
Item quotedItem1 = ItemBuilder.createItem(context, collection)
|
||||
.withTitle("The Special Runnable Item")
|
||||
.withSubject("quoted-subject")
|
||||
.build();
|
||||
Item quotedItem2 = ItemBuilder.createItem(context, collection)
|
||||
.withTitle("The Special Item")
|
||||
.withSubject("quoted-subject")
|
||||
.build();
|
||||
context.restoreAuthSystemState();
|
||||
|
||||
int result = runDSpaceScript(
|
||||
"metadata-export-search",
|
||||
"-q", "title:\"Special Runnable\"",
|
||||
"-n", filename);
|
||||
|
||||
assertEquals(0, result);
|
||||
|
||||
Item[] expectedResult = new Item[] {quotedItem1};
|
||||
checkItemsPresentInFile(filename, expectedResult);
|
||||
|
||||
File file = new File(filename);
|
||||
try (Reader reader = Files.newReader(file, Charset.defaultCharset());
|
||||
CSVReader csvReader = new CSVReader(reader)) {
|
||||
List<String[]> lines = csvReader.readAll();
|
||||
assertEquals("Unexpected extra items in export", 2, lines.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user