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:
im-shubham-vish
2025-08-12 16:55:53 +05:30
committed by github-actions[bot]
parent 4b678f2b7d
commit f79d012cbc
3 changed files with 44 additions and 1 deletions

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -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());
}
}
}