Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2820 from atmire/w2p-71513_Curation-tasks-scripts…
…-and-processes Curation tasks using the scripts and processes functionality
- Loading branch information
Showing
13 changed files
with
947 additions
and
256 deletions.
There are no files selected for viewing
477 changes: 282 additions & 195 deletions
477
dspace-api/src/main/java/org/dspace/curate/CurationCli.java
Large diffs are not rendered by default.
Oops, something went wrong.
85 changes: 85 additions & 0 deletions
85
dspace-api/src/main/java/org/dspace/curate/CurationClientOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* 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.curate; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.apache.commons.cli.CommandLine; | ||
import org.apache.commons.cli.Options; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.dspace.services.ConfigurationService; | ||
import org.dspace.services.factory.DSpaceServicesFactory; | ||
|
||
/** | ||
* This Enum holds all the possible options and combinations for the Curation script | ||
* | ||
* @author Maria Verdonck (Atmire) on 23/06/2020 | ||
*/ | ||
public enum CurationClientOptions { | ||
TASK, | ||
QUEUE, | ||
HELP; | ||
|
||
private static List<String> taskOptions; | ||
|
||
/** | ||
* This method resolves the CommandLine parameters to figure out which action the curation script should perform | ||
* | ||
* @param commandLine The relevant CommandLine for the curation script | ||
* @return The curation option to be ran, parsed from the CommandLine | ||
*/ | ||
protected static CurationClientOptions getClientOption(CommandLine commandLine) { | ||
if (commandLine.hasOption("h")) { | ||
return CurationClientOptions.HELP; | ||
} else if (commandLine.hasOption("t") || commandLine.hasOption("T")) { | ||
return CurationClientOptions.TASK; | ||
} else if (commandLine.hasOption("q")) { | ||
return CurationClientOptions.QUEUE; | ||
} | ||
return null; | ||
} | ||
|
||
protected static Options constructOptions() { | ||
Options options = new Options(); | ||
|
||
options.addOption("t", "task", true, "curation task name; options: " + getTaskOptions()); | ||
options.addOption("T", "taskfile", true, "file containing curation task names"); | ||
options.addOption("i", "id", true, | ||
"Id (handle) of object to perform task on, or 'all' to perform on whole repository"); | ||
options.addOption("p", "parameter", true, "a task parameter 'NAME=VALUE'"); | ||
options.addOption("q", "queue", true, "name of task queue to process"); | ||
options.addOption("e", "eperson", true, "email address of curating eperson"); | ||
options.addOption("r", "reporter", true, | ||
"relative or absolute path to the desired report file. Use '-' to report to console. If absent, no " + | ||
"reporting"); | ||
options.addOption("s", "scope", true, | ||
"transaction scope to impose: use 'object', 'curation', or 'open'. If absent, 'open' applies"); | ||
options.addOption("v", "verbose", false, "report activity to stdout"); | ||
options.addOption("h", "help", false, "help"); | ||
|
||
return options; | ||
} | ||
|
||
/** | ||
* Creates list of the taskOptions' keys from the configs of plugin.named.org.dspace.curate.CurationTask | ||
* | ||
* @return List of the taskOptions' keys from the configs of plugin.named.org.dspace.curate.CurationTask | ||
*/ | ||
public static List<String> getTaskOptions() { | ||
if (taskOptions == null) { | ||
ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService(); | ||
String[] taskConfigs = configurationService.getArrayProperty("plugin.named.org.dspace.curate.CurationTask"); | ||
taskOptions = new ArrayList<>(); | ||
for (String taskConfig : taskConfigs) { | ||
taskOptions.add(StringUtils.substringAfterLast(taskConfig, "=").trim()); | ||
} | ||
} | ||
return taskOptions; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
dspace-api/src/main/java/org/dspace/curate/CurationScriptConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* 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.curate; | ||
|
||
import java.sql.SQLException; | ||
|
||
import org.apache.commons.cli.Options; | ||
import org.dspace.authorize.service.AuthorizeService; | ||
import org.dspace.core.Context; | ||
import org.dspace.scripts.configuration.ScriptConfiguration; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
/** | ||
* The {@link ScriptConfiguration} for the {@link CurationCli} script | ||
* | ||
* @author Maria Verdonck (Atmire) on 23/06/2020 | ||
*/ | ||
public class CurationScriptConfiguration<T extends CurationCli> extends ScriptConfiguration<T> { | ||
|
||
@Autowired | ||
private AuthorizeService authorizeService; | ||
|
||
private Class<T> dspaceRunnableClass; | ||
|
||
@Override | ||
public Class<T> getDspaceRunnableClass() { | ||
return this.dspaceRunnableClass; | ||
} | ||
|
||
@Override | ||
public void setDspaceRunnableClass(Class<T> dspaceRunnableClass) { | ||
this.dspaceRunnableClass = dspaceRunnableClass; | ||
} | ||
|
||
/** | ||
* Only admin can run Curation script via the scripts and processes endpoints. | ||
* @param context The relevant DSpace context | ||
* @return True if currentUser is admin, otherwise false | ||
*/ | ||
@Override | ||
public boolean isAllowedToExecute(Context context) { | ||
try { | ||
return authorizeService.isAdmin(context); | ||
} catch (SQLException e) { | ||
throw new RuntimeException("SQLException occurred when checking if the current user is an admin", e); | ||
} | ||
} | ||
|
||
@Override | ||
public Options getOptions() { | ||
if (options == null) { | ||
super.options = CurationClientOptions.constructOptions(); | ||
} | ||
return options; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
checklinks | ||
requiredmetadata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.