src/main/java: Implement task "profiles"

The DSpace curation system has task properties that can be used to
create "profiles" of sorts. For example, if you set a custom task
name in curate.cfg:

    plugin.named.org.dspace.curate.CurationTask = \
        org.cgiar.cgspace.ctasks.CountryCodeTagger = countrycodetagger \
        org.cgiar.cgspace.ctasks.CountryCodeTagger = countrycodetagger.force

... then DSpace will look for countrycodetagger.cfg by default, and
countrycodetagger.force.cfg for the second task. We can set different
properties in each one, for example "force=true", and then operate
accordingly in the task when we check the value using taskProperty().

I will use this to force all country tags to be cleared and updated,
where by default we only tag if there are no existing country tags.

See: https://wiki.lyrasis.org/display/DSDOC5x/Curation+System
This commit is contained in:
Alan Orth 2020-08-01 23:04:35 +03:00
parent d4cd5bfd61
commit 4b553676dd
Signed by: alanorth
GPG Key ID: 0FB860CC9C45B1B9
1 changed files with 11 additions and 7 deletions

View File

@ -24,7 +24,6 @@ import org.dspace.authorize.AuthorizeException;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.dspace.content.Metadatum;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants;
import org.dspace.curate.AbstractCurationTask;
import org.dspace.curate.Curator;
@ -41,11 +40,11 @@ public class CountryCodeTagger extends AbstractCurationTask
private int status = Curator.CURATE_UNSET;
private String result = null;
private static final String PLUGIN_PREFIX = "ilri";
private static String isocodesJsonPath;
private static String cgspaceCountriesJsonPath;
private static String iso3166Field;
private static String iso3166Alpha2Field;
private static boolean forceupdate;
private List<String> results = new ArrayList<String>();
@ -57,8 +56,9 @@ public class CountryCodeTagger extends AbstractCurationTask
// Load configuration
isocodesJsonPath = "/org/cgiar/cgspace/ctasks/iso_3166-1.json";
cgspaceCountriesJsonPath = "/org/cgiar/cgspace/ctasks/cgspace-countries.json";
iso3166Field = ConfigurationManager.getProperty(PLUGIN_PREFIX, "countrycodes.iso3166.field");
iso3166Alpha2Field = ConfigurationManager.getProperty(PLUGIN_PREFIX, "countrycodes.iso3166-alpha2.field");
iso3166Field = taskProperty("iso3166.field");
iso3166Alpha2Field = taskProperty("iso3166-alpha2.field");
forceupdate = taskBooleanProperty("forceupdate", false);
if (dso.getType() == Constants.ITEM)
{
@ -85,15 +85,19 @@ public class CountryCodeTagger extends AbstractCurationTask
//System.out.println(itemHandle + ": " + itemCountries.length + " countries possibly need tagging");
// split the alpha2 country code field into schema, element, and qualifier so we can use it with item.addMetadata()
String[] iso3166Alpha2FieldParts = iso3166Alpha2Field.split("\\.");
if (forceupdate) {
item.clearMetadata(iso3166Alpha2FieldParts[0], iso3166Alpha2FieldParts[1], iso3166Alpha2FieldParts[2], Item.ANY);
}
// check the item's country codes, if any
Metadatum[] itemAlpha2CountryCodes = item.getMetadataByMetadataString(iso3166Alpha2Field);
if (itemAlpha2CountryCodes.length == 0) {
//System.out.println(itemHandle + ": Should add codes for " + itemCountries.length + " countries.");
// split the alpha2 country code field into schema, element, and qualifier so we can use it with item.addMetadata()
String[] iso3166Alpha2FieldParts = iso3166Alpha2Field.split("\\.");
Integer addedCodeCount = 0;
for (Metadatum itemCountry : itemCountries) {
//check ISO 3166-1 countries