Skip to content

Commit c8a0dcc

Browse files
Merged in task/dspace-cris-2024_02_x/DSC-2792 (pull request DSpace#5588)
[DSC-2792] handle user for CLI bulk item export script Approved-by: Vincenzo Mecca
2 parents 3fd7679 + f26715e commit c8a0dcc

4 files changed

Lines changed: 100 additions & 47 deletions

File tree

dspace-api/src/main/java/org/dspace/content/integration/crosswalks/script/BulkItemExport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public void setup() throws ParseException {
152152
@Override
153153
public void internalRun() throws Exception {
154154
context = new Context(Context.Mode.READ_ONLY);
155-
assignCurrentUserInContext();
155+
assignCurrentUserInContext(context);
156156
assignSpecialGroupsInContext();
157157
assignHandlerLocaleInContext();
158158

@@ -343,7 +343,7 @@ private List<QueryBuilderSearchFilter> parseSearchFilters() {
343343

344344
}
345345

346-
private void assignCurrentUserInContext() throws SQLException {
346+
protected void assignCurrentUserInContext(Context context) throws SQLException, ParseException {
347347
UUID uuid = getEpersonIdentifier();
348348
if (uuid != null) {
349349
EPerson ePerson = EPersonServiceFactory.getInstance().getEPersonService().find(context, uuid);

dspace-api/src/main/java/org/dspace/content/integration/crosswalks/script/BulkItemExportCli.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
*/
88
package org.dspace.content.integration.crosswalks.script;
99

10+
import java.sql.SQLException;
11+
12+
import org.apache.commons.cli.ParseException;
13+
import org.dspace.core.Context;
14+
import org.dspace.eperson.EPerson;
15+
import org.dspace.eperson.factory.EPersonServiceFactory;
16+
1017
/**
1118
* Extension of {@link BulkItemExport} for CLI.
1219
*
@@ -15,4 +22,22 @@
1522
*/
1623
public class BulkItemExportCli extends BulkItemExport {
1724

25+
@Override
26+
protected void assignCurrentUserInContext(Context context) throws SQLException, ParseException {
27+
if (commandLine.hasOption('e')) {
28+
String ePersonEmail = commandLine.getOptionValue('e');
29+
try {
30+
EPerson ePerson =
31+
EPersonServiceFactory.getInstance().getEPersonService().findByEmail(context, ePersonEmail);
32+
if (ePerson == null) {
33+
super.handler.logError("EPerson not found: " + ePersonEmail);
34+
throw new IllegalArgumentException("Unable to find a user with email: " + ePersonEmail);
35+
}
36+
context.setCurrentUser(ePerson);
37+
} catch (SQLException e) {
38+
throw new IllegalArgumentException("SQLException trying to find user with email: " + ePersonEmail);
39+
}
40+
}
41+
}
42+
1843
}

dspace-api/src/main/java/org/dspace/content/integration/crosswalks/script/BulkItemExportCliScriptConfiguration.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*/
88
package org.dspace.content.integration.crosswalks.script;
99

10+
import org.apache.commons.cli.Options;
11+
1012
/**
1113
* Extension of {@link BulkItemExportScriptConfiguration} for CLI.
1214
*
@@ -16,4 +18,13 @@
1618
public class BulkItemExportCliScriptConfiguration<T extends BulkItemExportCli>
1719
extends BulkItemExportScriptConfiguration<T> {
1820

21+
@Override
22+
public Options getOptions() {
23+
Options options = super.getOptions();
24+
options.addOption("e", "email", true, "email address of user");
25+
options.getOption("e").setRequired(false);
26+
super.options = options;
27+
return options;
28+
}
29+
1930
}

0 commit comments

Comments
 (0)