Skip to content

Commit

Permalink
Merged dspace-cris-2023_02_x into 2023_02_x-DQ-26
Browse files Browse the repository at this point in the history
  • Loading branch information
atarix83 committed Feb 9, 2024
2 parents f3e2668 + e666ff8 commit f18a000
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
*/
package org.dspace.administer;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.xpath.XPath;
Expand All @@ -30,6 +34,8 @@
import org.dspace.content.service.MetadataFieldService;
import org.dspace.content.service.MetadataSchemaService;
import org.dspace.core.Context;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
Expand Down Expand Up @@ -61,10 +67,18 @@
* }
*/
public class MetadataImporter {
public static final String BASE = DSpaceServicesFactory.getInstance()
.getConfigurationService().getProperty("dspace.dir") + File.separator + "config" + File.separator
+ "registries" + File.separator;
public static final String REGISTRY_METADATA_PROPERTY = "registry.metadata.load";
public static final String REGISTRY_BITSTREAM_FORMAT_PROPERTY = "registry.bitstream-formats.load";

protected static MetadataSchemaService metadataSchemaService = ContentServiceFactory.getInstance()
.getMetadataSchemaService();
protected static MetadataFieldService metadataFieldService = ContentServiceFactory.getInstance()
.getMetadataFieldService();
protected static ConfigurationService configurationService = DSpaceServicesFactory.getInstance()
.getConfigurationService();

/**
* logging category
Expand Down Expand Up @@ -100,18 +114,35 @@ public static void main(String[] args)
Options options = new Options();
options.addOption("f", "file", true, "source xml file for DC fields");
options.addOption("u", "update", false, "update an existing schema");
options.addOption("h", "help", false, "help message");
CommandLine line = parser.parse(options, args);

if (line.hasOption('f')) {
if (line.hasOption('h')) {
usage();
System.exit(1);
} else if (line.hasOption('f')) {
String file = line.getOptionValue('f');
boolean forceUpdate = line.hasOption('u');
loadRegistry(file, forceUpdate);
} else {
usage();
System.exit(1);
boolean forceUpdate = line.hasOption('u');
for (String file : getAllRegistryFiles(REGISTRY_METADATA_PROPERTY)) {
loadRegistry(file, forceUpdate);
}
}
}

/**
* Load all registry file names from config
*
* @param propertyName name of the property that used in config
* @return list of all registry files
*/
public static List<String> getAllRegistryFiles(String propertyName) {
List<String> files = Arrays.asList(configurationService.getArrayProperty(propertyName));
return files.stream().map(file -> BASE + file).collect(Collectors.toList());
}

/**
* Load the data from the specified file path into the database
*
Expand Down Expand Up @@ -285,7 +316,10 @@ private static void loadType(Context context, Node node)
public static void usage() {
String usage = "Use this class with the following option:\n" +
" -f <xml source file> : specify which xml source file " +
"contains the DC fields to import.\n";
"contains the DC fields to import.\n" +
"If you use the script without the -f parameter, then all" +
" registries will be loaded from the config/registries folder\n";

System.out.println(usage);
}
}
43 changes: 40 additions & 3 deletions dspace-api/src/main/java/org/dspace/administer/RegistryLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;



/**
* Loads the bitstream format and Dublin Core type registries into the database.
* Intended for use as a command-line tool.
Expand Down Expand Up @@ -68,7 +70,7 @@ private RegistryLoader() { }
*/
public static void main(String[] argv) throws Exception {
String usage = "Usage: " + RegistryLoader.class.getName()
+ " (-bitstream | -metadata) registry-file.xml";
+ " (-bitstream | -metadata | -all) registry-file.xml";

Context context = null;

Expand All @@ -81,10 +83,21 @@ public static void main(String[] argv) throws Exception {

// Work out what we're loading
if (argv[0].equalsIgnoreCase("-bitstream")) {
RegistryLoader.loadBitstreamFormats(context, argv[1]);
if (argv.length == 1) {
loadAllBitstreamFormats(context);
} else {
RegistryLoader.loadBitstreamFormats(context, argv[1]);
}
} else if (argv[0].equalsIgnoreCase("-metadata")) {
// Call MetadataImporter, as it handles Metadata schema updates
MetadataImporter.loadRegistry(argv[1], true);
if (argv.length == 1) {
loadAllRegistry();
} else {
MetadataImporter.loadRegistry(argv[1], true);
}
} else if (argv[0].equalsIgnoreCase("-all")) {
loadAllBitstreamFormats(context);
loadAllRegistry();
} else {
System.err.println(usage);
}
Expand All @@ -111,6 +124,30 @@ public static void main(String[] argv) throws Exception {
}
}


/**
* Load all bitstream formats from configuration properties
*
* @param context DSpace context object
* @throws Exception
*/
private static void loadAllBitstreamFormats(Context context) throws Exception {
for (String file : MetadataImporter.getAllRegistryFiles(MetadataImporter.REGISTRY_BITSTREAM_FORMAT_PROPERTY)) {
RegistryLoader.loadBitstreamFormats(context, file);
}
}

/**
* Load all metadata registry from configuration properties
*
* @throws Exception
*/
private static void loadAllRegistry() throws Exception {
for (String file : MetadataImporter.getAllRegistryFiles(MetadataImporter.REGISTRY_METADATA_PROPERTY)) {
MetadataImporter.loadRegistry(file, true);
}
}

/**
* Load Bitstream Format metadata
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/
package org.dspace.storage.rdbms;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.xpath.XPathExpressionException;
Expand All @@ -20,8 +20,6 @@
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.NonUniqueMetadataException;
import org.dspace.core.Context;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.flywaydb.core.api.callback.Callback;
import org.flywaydb.core.api.callback.Event;
import org.slf4j.Logger;
Expand Down Expand Up @@ -58,30 +56,31 @@ public class RegistryUpdater implements Callback {
* Method to actually update our registries from latest configuration files.
*/
private void updateRegistries() {
ConfigurationService config = DSpaceServicesFactory.getInstance().getConfigurationService();
Context context = null;
try {
context = new Context();
context.turnOffAuthorisationSystem();

String base = config.getProperty("dspace.dir")
+ File.separator + "config" + File.separator
+ "registries" + File.separator;

// Load updates to Bitstream format registry (if any)
log.info("Updating Bitstream Format Registry based on {}bitstream-formats.xml", base);
RegistryLoader.loadBitstreamFormats(context, base + "bitstream-formats.xml");
// Load updates to Bitstream formats registries (if any)
List<String> registryBitstreamFormatFiles =
MetadataImporter.getAllRegistryFiles(MetadataImporter.REGISTRY_BITSTREAM_FORMAT_PROPERTY);
for (String bitstreamFormat : registryBitstreamFormatFiles) {
log.info("Updating Bitstream Format Registry based on {}", bitstreamFormat);
RegistryLoader.loadBitstreamFormats(context, bitstreamFormat);
}

// Load updates to Metadata schema registries (if any)
log.info("Updating Metadata Registries based on metadata type configs in {}", base);
for (String namespaceFile: config.getArrayProperty("registry.metadata.load")) {
log.info("Reading {}", namespaceFile);
MetadataImporter.loadRegistry(base + namespaceFile, true);
List<String> registryMetadataFiles =
MetadataImporter.getAllRegistryFiles(MetadataImporter.REGISTRY_METADATA_PROPERTY);
log.info("Updating Metadata Registries based on metadata type configs in {}", MetadataImporter.BASE);
for (String metadataFile : registryMetadataFiles) {
log.info("Reading {}", metadataFile);
MetadataImporter.loadRegistry(metadataFile, true);
}

String workflowTypes = "workflow-types.xml";
log.info("Reading {}", workflowTypes);
MetadataImporter.loadRegistry(base + workflowTypes, true);
MetadataImporter.loadRegistry( MetadataImporter.BASE + workflowTypes, true);

context.restoreAuthSystemState();
// Commit changes and close context
Expand Down
2 changes: 2 additions & 0 deletions dspace/config/dspace.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,8 @@ registry.metadata.load = iiif-types.xml
registry.metadata.load = bitstream-types.xml
registry.metadata.load = dataquality-types.xml

registry.bitstream-formats.load = bitstream-formats.xml

#---------------------------------------------------------------#
#-----------------UI-Related CONFIGURATIONS---------------------#
#---------------------------------------------------------------#
Expand Down
4 changes: 0 additions & 4 deletions dspace/config/modules/authority.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,6 @@ choices.plugin.dc.identifier.issn = ZDBAuthority
choices.presentation.dc.identifier.issn = suggest
authority.controlled.dc.identifier.issn = true

choices.plugin.dc.relation.ispartof = SherpaAuthority
choices.presentation.dc.relation.ispartof = suggest
authority.controlled.dc.relation.ispartof = true

authority.controlled.dc.type = true
choices.plugin.dc.type = ControlledVocabularyAuthority

Expand Down

0 comments on commit f18a000

Please sign in to comment.