forked from DSpace/dspace-replicate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractPackagerTask.java
More file actions
112 lines (99 loc) · 5.04 KB
/
Copy pathAbstractPackagerTask.java
File metadata and controls
112 lines (99 loc) · 5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
* 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.ctask.replicate;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dspace.content.packager.PackageParameters;
import org.dspace.curate.AbstractCurationTask;
/**
* AbstractPackagerTask encapsulates a few common convenience methods which may
* be useful to curation tasks that wrap or utilize DSpace Packager classes
* (org.dspace.content.packager.*).
*
* @author Tim Donohue
* @see org.dspace.app.packager.Packager
* @see org.dspace.content.packager.PackageDisseminator
* @see org.dspace.content.packager.PackageIngester
*/
public abstract class AbstractPackagerTask extends AbstractCurationTask {
private static final Logger log = LogManager.getLogger();
// Name of recursive mode option configurable in curation task configuration file
private final String recursiveMode = "recursiveMode";
// Name of useWorkflow option configurable in curation task configuration file
private final String useWorkflow = "useWorkflow";
// Name of useCollectionTemplate option configurable in curation task configuration file
private final String useCollectionTemplate = "useCollectionTemplate";
/**
* Loads pre-configured PackageParameters settings from a given Module
* configuration file (specified by 'moduleName').
* <p>
* These PackageParameters should be configured using the following
* configuration file format:
* <p>
* SETTING FORMAT: [modulename].[taskname].[option] = [value]
* <p>
* Valid 'options' include all packager options supported by the
* Packager class, e.g. AIP packagers minimally support these options:
* https://wiki.lyrasis.org/display/DSDOC9x/AIP+Backup+and+Restore#AIPBackupandRestore-AdditionalPackagerOptions
* <p>
* Please note that different Packager classes will support different options.
* You should determine which options are valid for your Packager class
* and the curation task that utilizes it.
* <p>
* Example usage: if your module is named "mymodule" and your curation task is named
* "myreplacetask" in curate.cfg, then you can configure its PackageParameters like so:
* <p>
* mymodule.myreplacetask.replaceMode = true
* mymodule.myreplacetask.recursiveMode = true
* mymodule.myreplacetask.createMetadataFields = true
* mymodule.myreplacetask.[any-supported-option] = [any-supported-value]
*
* @param moduleName Module name to load configuration file and settings from
* @return configured PackageParameters (or null, if configurations not found)
* @see org.dspace.content.packager.PackageParameters
*/
protected PackageParameters loadPackagerParameters(String moduleName) {
// Load up the replicate-mets.cfg file & all settings inside it
List<String> moduleProps = configurationService.getPropertyKeys(moduleName);
PackageParameters pkgParams = new PackageParameters();
// If our config file doesn't load properly, we'll return null
if (moduleProps != null) {
// loop through all properties in the config file
for (String property : moduleProps) {
// Set propertyName, removing leading module name (if applicable)
String propertyName = property;
if (propertyName.startsWith(moduleName + ".")) {
propertyName = propertyName.replaceFirst(moduleName + ".", "");
}
// Only obey the setting(s) beginning with this task's ID/name,
if (propertyName.startsWith(this.taskId)) {
// Parse out the option name by removing the "[taskID]." from beginning of property
String option = propertyName.replace(taskId + ".", "");
String value = configurationService.getProperty(property);
// Check which option is being set
if (option.equalsIgnoreCase(recursiveMode)) {
pkgParams.setRecursiveModeEnabled(Boolean.parseBoolean(value));
} else if (option.equals(useWorkflow)) {
pkgParams.setWorkflowEnabled(Boolean.parseBoolean(value));
} else if (option.equals(useCollectionTemplate)) {
pkgParams.setUseCollectionTemplate(Boolean.parseBoolean(value));
} else {
// otherwise, assume the Packager will understand what to do with this option
// just set it as a property in PackageParameters
pkgParams.addProperty(option, value);
}
log.debug("Set package parameter property <{}> to value <{}>", option, value);
}
}
return pkgParams;
} else {
return null;
}
}
}