Refactor SubmissionConfigReader to use a map for the collections configured through the entityType value

This commit is contained in:
Toni Prieto
2024-04-15 06:03:05 +02:00
parent 502028f84d
commit b7189006bc

View File

@@ -24,10 +24,10 @@ import org.apache.logging.log4j.Logger;
import org.dspace.content.Collection; import org.dspace.content.Collection;
import org.dspace.content.Community; import org.dspace.content.Community;
import org.dspace.content.DSpaceObject; import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.CollectionService; import org.dspace.content.service.CollectionService;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.discovery.SearchServiceException;
import org.dspace.handle.factory.HandleServiceFactory; import org.dspace.handle.factory.HandleServiceFactory;
import org.dspace.services.factory.DSpaceServicesFactory; import org.dspace.services.factory.DSpaceServicesFactory;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@@ -99,6 +99,13 @@ public class SubmissionConfigReader {
*/ */
private Map<String, String> communityToSubmissionConfig = null; private Map<String, String> communityToSubmissionConfig = null;
/**
* Hashmap which stores which submission process configuration is used by
* which entityType, computed from the item submission config file
* (specifically, the 'submission-map' tag)
*/
private Map<String, String> entityTypeToSubmissionConfig = null;
/** /**
* Reference to the global submission step definitions defined in the * Reference to the global submission step definitions defined in the
* "step-definitions" section * "step-definitions" section
@@ -137,6 +144,7 @@ public class SubmissionConfigReader {
public void reload() throws SubmissionConfigReaderException { public void reload() throws SubmissionConfigReaderException {
collectionToSubmissionConfig = null; collectionToSubmissionConfig = null;
communityToSubmissionConfig = null; communityToSubmissionConfig = null;
entityTypeToSubmissionConfig = null;
stepDefns = null; stepDefns = null;
submitDefns = null; submitDefns = null;
buildInputs(configDir + SUBMIT_DEF_FILE_PREFIX + SUBMIT_DEF_FILE_SUFFIX); buildInputs(configDir + SUBMIT_DEF_FILE_PREFIX + SUBMIT_DEF_FILE_SUFFIX);
@@ -156,6 +164,7 @@ public class SubmissionConfigReader {
private void buildInputs(String fileName) throws SubmissionConfigReaderException { private void buildInputs(String fileName) throws SubmissionConfigReaderException {
collectionToSubmissionConfig = new HashMap<String, String>(); collectionToSubmissionConfig = new HashMap<String, String>();
communityToSubmissionConfig = new HashMap<String, String>(); communityToSubmissionConfig = new HashMap<String, String>();
entityTypeToSubmissionConfig = new HashMap<String, String>();
submitDefns = new LinkedHashMap<String, List<Map<String, String>>>(); submitDefns = new LinkedHashMap<String, List<Map<String, String>>>();
String uri = "file:" + new File(fileName).getAbsolutePath(); String uri = "file:" + new File(fileName).getAbsolutePath();
@@ -173,9 +182,6 @@ public class SubmissionConfigReader {
} catch (FactoryConfigurationError fe) { } catch (FactoryConfigurationError fe) {
throw new SubmissionConfigReaderException( throw new SubmissionConfigReaderException(
"Cannot create Item Submission Configuration parser", fe); "Cannot create Item Submission Configuration parser", fe);
} catch (SearchServiceException se) {
throw new SubmissionConfigReaderException(
"Cannot perform a discovery search for Item Submission Configuration", se);
} catch (Exception e) { } catch (Exception e) {
throw new SubmissionConfigReaderException( throw new SubmissionConfigReaderException(
"Error creating Item Submission Configuration: " + e); "Error creating Item Submission Configuration: " + e);
@@ -238,6 +244,16 @@ public class SubmissionConfigReader {
return getSubmissionConfigByName(submitName); return getSubmissionConfigByName(submitName);
} }
// get the name of the submission process based on the entity type of this collections
if (!entityTypeToSubmissionConfig.isEmpty()) {
String entityType = collectionService.getMetadataFirstValue(col, "dspace", "entity", "type", Item.ANY);
submitName = entityTypeToSubmissionConfig
.get(entityType);
if (submitName != null) {
return getSubmissionConfigByName(submitName);
}
}
if (!communityToSubmissionConfig.isEmpty()) { if (!communityToSubmissionConfig.isEmpty()) {
try { try {
List<Community> communities = col.getCommunities(); List<Community> communities = col.getCommunities();
@@ -358,7 +374,7 @@ public class SubmissionConfigReader {
* should correspond to the collection-form maps, the form definitions, and * should correspond to the collection-form maps, the form definitions, and
* the display/storage word pairs. * the display/storage word pairs.
*/ */
private void doNodes(Node n) throws SAXException, SearchServiceException, SubmissionConfigReaderException { private void doNodes(Node n) throws SAXException, SubmissionConfigReaderException {
if (n == null) { if (n == null) {
return; return;
} }
@@ -405,9 +421,7 @@ public class SubmissionConfigReader {
* the collection handle and item submission name, put name in hashmap keyed * the collection handle and item submission name, put name in hashmap keyed
* by the collection handle. * by the collection handle.
*/ */
private void processMap(Node e) throws SAXException, SearchServiceException { private void processMap(Node e) throws SAXException {
// create a context
Context context = new Context();
NodeList nl = e.getChildNodes(); NodeList nl = e.getChildNodes();
int len = nl.getLength(); int len = nl.getLength();
@@ -428,7 +442,7 @@ public class SubmissionConfigReader {
throw new SAXException( throw new SAXException(
"name-map element is missing submission-name attribute in 'item-submission.xml'"); "name-map element is missing submission-name attribute in 'item-submission.xml'");
} }
if (content != null && content.length() > 0) { if (content != null && !content.isEmpty()) {
throw new SAXException( throw new SAXException(
"name-map element has content in 'item-submission.xml', it should be empty."); "name-map element has content in 'item-submission.xml', it should be empty.");
} }
@@ -437,12 +451,7 @@ public class SubmissionConfigReader {
} else if (communityId != null) { } else if (communityId != null) {
communityToSubmissionConfig.put(communityId, value); communityToSubmissionConfig.put(communityId, value);
} else { } else {
// get all collections for this entity-type entityTypeToSubmissionConfig.put(entityType, value);
List<Collection> collections = collectionService.findAllCollectionsByEntityType( context,
entityType);
for (Collection collection : collections) {
collectionToSubmissionConfig.putIfAbsent(collection.getHandle(), value);
}
} }
} // ignore any child node that isn't a "name-map" } // ignore any child node that isn't a "name-map"
} }