Skip to content

Commit f18a000

Browse files
committed
Merged dspace-cris-2023_02_x into 2023_02_x-DQ-26
2 parents f3e2668 + e666ff8 commit f18a000

File tree

5 files changed

+95
-27
lines changed

5 files changed

+95
-27
lines changed

dspace-api/src/main/java/org/dspace/administer/MetadataImporter.java

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
*/
88
package org.dspace.administer;
99

10+
import java.io.File;
1011
import java.io.IOException;
1112
import java.sql.SQLException;
13+
import java.util.Arrays;
14+
import java.util.List;
15+
import java.util.stream.Collectors;
1216
import javax.xml.parsers.ParserConfigurationException;
1317
import javax.xml.transform.TransformerException;
1418
import javax.xml.xpath.XPath;
@@ -30,6 +34,8 @@
3034
import org.dspace.content.service.MetadataFieldService;
3135
import org.dspace.content.service.MetadataSchemaService;
3236
import org.dspace.core.Context;
37+
import org.dspace.services.ConfigurationService;
38+
import org.dspace.services.factory.DSpaceServicesFactory;
3339
import org.slf4j.Logger;
3440
import org.slf4j.LoggerFactory;
3541
import org.w3c.dom.Document;
@@ -61,10 +67,18 @@
6167
* }
6268
*/
6369
public class MetadataImporter {
70+
public static final String BASE = DSpaceServicesFactory.getInstance()
71+
.getConfigurationService().getProperty("dspace.dir") + File.separator + "config" + File.separator
72+
+ "registries" + File.separator;
73+
public static final String REGISTRY_METADATA_PROPERTY = "registry.metadata.load";
74+
public static final String REGISTRY_BITSTREAM_FORMAT_PROPERTY = "registry.bitstream-formats.load";
75+
6476
protected static MetadataSchemaService metadataSchemaService = ContentServiceFactory.getInstance()
6577
.getMetadataSchemaService();
6678
protected static MetadataFieldService metadataFieldService = ContentServiceFactory.getInstance()
6779
.getMetadataFieldService();
80+
protected static ConfigurationService configurationService = DSpaceServicesFactory.getInstance()
81+
.getConfigurationService();
6882

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

105-
if (line.hasOption('f')) {
120+
if (line.hasOption('h')) {
121+
usage();
122+
System.exit(1);
123+
} else if (line.hasOption('f')) {
106124
String file = line.getOptionValue('f');
107125
boolean forceUpdate = line.hasOption('u');
108126
loadRegistry(file, forceUpdate);
109127
} else {
110-
usage();
111-
System.exit(1);
128+
boolean forceUpdate = line.hasOption('u');
129+
for (String file : getAllRegistryFiles(REGISTRY_METADATA_PROPERTY)) {
130+
loadRegistry(file, forceUpdate);
131+
}
112132
}
113133
}
114134

135+
/**
136+
* Load all registry file names from config
137+
*
138+
* @param propertyName name of the property that used in config
139+
* @return list of all registry files
140+
*/
141+
public static List<String> getAllRegistryFiles(String propertyName) {
142+
List<String> files = Arrays.asList(configurationService.getArrayProperty(propertyName));
143+
return files.stream().map(file -> BASE + file).collect(Collectors.toList());
144+
}
145+
115146
/**
116147
* Load the data from the specified file path into the database
117148
*
@@ -285,7 +316,10 @@ private static void loadType(Context context, Node node)
285316
public static void usage() {
286317
String usage = "Use this class with the following option:\n" +
287318
" -f <xml source file> : specify which xml source file " +
288-
"contains the DC fields to import.\n";
319+
"contains the DC fields to import.\n" +
320+
"If you use the script without the -f parameter, then all" +
321+
" registries will be loaded from the config/registries folder\n";
322+
289323
System.out.println(usage);
290324
}
291325
}

dspace-api/src/main/java/org/dspace/administer/RegistryLoader.java

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import org.w3c.dom.NodeList;
3434
import org.xml.sax.SAXException;
3535

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

7375
Context context = null;
7476

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

8284
// Work out what we're loading
8385
if (argv[0].equalsIgnoreCase("-bitstream")) {
84-
RegistryLoader.loadBitstreamFormats(context, argv[1]);
86+
if (argv.length == 1) {
87+
loadAllBitstreamFormats(context);
88+
} else {
89+
RegistryLoader.loadBitstreamFormats(context, argv[1]);
90+
}
8591
} else if (argv[0].equalsIgnoreCase("-metadata")) {
8692
// Call MetadataImporter, as it handles Metadata schema updates
87-
MetadataImporter.loadRegistry(argv[1], true);
93+
if (argv.length == 1) {
94+
loadAllRegistry();
95+
} else {
96+
MetadataImporter.loadRegistry(argv[1], true);
97+
}
98+
} else if (argv[0].equalsIgnoreCase("-all")) {
99+
loadAllBitstreamFormats(context);
100+
loadAllRegistry();
88101
} else {
89102
System.err.println(usage);
90103
}
@@ -111,6 +124,30 @@ public static void main(String[] argv) throws Exception {
111124
}
112125
}
113126

127+
128+
/**
129+
* Load all bitstream formats from configuration properties
130+
*
131+
* @param context DSpace context object
132+
* @throws Exception
133+
*/
134+
private static void loadAllBitstreamFormats(Context context) throws Exception {
135+
for (String file : MetadataImporter.getAllRegistryFiles(MetadataImporter.REGISTRY_BITSTREAM_FORMAT_PROPERTY)) {
136+
RegistryLoader.loadBitstreamFormats(context, file);
137+
}
138+
}
139+
140+
/**
141+
* Load all metadata registry from configuration properties
142+
*
143+
* @throws Exception
144+
*/
145+
private static void loadAllRegistry() throws Exception {
146+
for (String file : MetadataImporter.getAllRegistryFiles(MetadataImporter.REGISTRY_METADATA_PROPERTY)) {
147+
MetadataImporter.loadRegistry(file, true);
148+
}
149+
}
150+
114151
/**
115152
* Load Bitstream Format metadata
116153
*

dspace-api/src/main/java/org/dspace/storage/rdbms/RegistryUpdater.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
*/
88
package org.dspace.storage.rdbms;
99

10-
import java.io.File;
1110
import java.io.IOException;
1211
import java.sql.SQLException;
12+
import java.util.List;
1313
import javax.xml.parsers.ParserConfigurationException;
1414
import javax.xml.transform.TransformerException;
1515
import javax.xml.xpath.XPathExpressionException;
@@ -20,8 +20,6 @@
2020
import org.dspace.authorize.AuthorizeException;
2121
import org.dspace.content.NonUniqueMetadataException;
2222
import org.dspace.core.Context;
23-
import org.dspace.services.ConfigurationService;
24-
import org.dspace.services.factory.DSpaceServicesFactory;
2523
import org.flywaydb.core.api.callback.Callback;
2624
import org.flywaydb.core.api.callback.Event;
2725
import org.slf4j.Logger;
@@ -58,30 +56,31 @@ public class RegistryUpdater implements Callback {
5856
* Method to actually update our registries from latest configuration files.
5957
*/
6058
private void updateRegistries() {
61-
ConfigurationService config = DSpaceServicesFactory.getInstance().getConfigurationService();
6259
Context context = null;
6360
try {
6461
context = new Context();
6562
context.turnOffAuthorisationSystem();
6663

67-
String base = config.getProperty("dspace.dir")
68-
+ File.separator + "config" + File.separator
69-
+ "registries" + File.separator;
70-
71-
// Load updates to Bitstream format registry (if any)
72-
log.info("Updating Bitstream Format Registry based on {}bitstream-formats.xml", base);
73-
RegistryLoader.loadBitstreamFormats(context, base + "bitstream-formats.xml");
64+
// Load updates to Bitstream formats registries (if any)
65+
List<String> registryBitstreamFormatFiles =
66+
MetadataImporter.getAllRegistryFiles(MetadataImporter.REGISTRY_BITSTREAM_FORMAT_PROPERTY);
67+
for (String bitstreamFormat : registryBitstreamFormatFiles) {
68+
log.info("Updating Bitstream Format Registry based on {}", bitstreamFormat);
69+
RegistryLoader.loadBitstreamFormats(context, bitstreamFormat);
70+
}
7471

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

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

8685
context.restoreAuthSystemState();
8786
// Commit changes and close context

dspace/config/dspace.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,8 @@ registry.metadata.load = iiif-types.xml
10131013
registry.metadata.load = bitstream-types.xml
10141014
registry.metadata.load = dataquality-types.xml
10151015

1016+
registry.bitstream-formats.load = bitstream-formats.xml
1017+
10161018
#---------------------------------------------------------------#
10171019
#-----------------UI-Related CONFIGURATIONS---------------------#
10181020
#---------------------------------------------------------------#

dspace/config/modules/authority.cfg

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,6 @@ choices.plugin.dc.identifier.issn = ZDBAuthority
271271
choices.presentation.dc.identifier.issn = suggest
272272
authority.controlled.dc.identifier.issn = true
273273

274-
choices.plugin.dc.relation.ispartof = SherpaAuthority
275-
choices.presentation.dc.relation.ispartof = suggest
276-
authority.controlled.dc.relation.ispartof = true
277-
278274
authority.controlled.dc.type = true
279275
choices.plugin.dc.type = ControlledVocabularyAuthority
280276

0 commit comments

Comments
 (0)