support for entity type for collection at input submissions

This commit is contained in:
Paulo Graça
2023-05-19 22:44:07 +01:00
parent 95ad0ba927
commit d7d7f7c370
5 changed files with 82 additions and 4 deletions

View File

@@ -22,6 +22,8 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Logger;
import org.dspace.content.Collection;
import org.dspace.content.DSpaceObject;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.CollectionService;
import org.dspace.core.Context;
import org.dspace.handle.factory.HandleServiceFactory;
import org.dspace.services.factory.DSpaceServicesFactory;
@@ -105,6 +107,9 @@ public class SubmissionConfigReader {
*/
private SubmissionConfig lastSubmissionConfig = null;
protected static final CollectionService collectionService
= ContentServiceFactory.getInstance().getCollectionService();
/**
* Load Submission Configuration from the
* item-submission.xml configuration file
@@ -335,17 +340,22 @@ public class SubmissionConfigReader {
* by the collection handle.
*/
private void processMap(Node e) throws SAXException {
// create a context
Context context = new Context();
NodeList nl = e.getChildNodes();
int len = nl.getLength();
for (int i = 0; i < len; i++) {
Node nd = nl.item(i);
if (nd.getNodeName().equals("name-map")) {
String id = getAttribute(nd, "collection-handle");
String entityType = getAttribute(nd, "collection-entity-type");
String value = getAttribute(nd, "submission-name");
String content = getValue(nd);
if (id == null) {
if (id == null && entityType == null) {
throw new SAXException(
"name-map element is missing collection-handle attribute in 'item-submission.xml'");
"name-map element is missing collection-handle or collection-entity-type attribute " +
"in 'item-submission.xml'");
}
if (value == null) {
throw new SAXException(
@@ -355,7 +365,17 @@ public class SubmissionConfigReader {
throw new SAXException(
"name-map element has content in 'item-submission.xml', it should be empty.");
}
collectionToSubmissionConfig.put(id, value);
if (id != null) {
collectionToSubmissionConfig.put(id, value);
} else {
// get all collections for this entity-type
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"
}
}

View File

@@ -18,6 +18,7 @@ import java.util.List;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
@@ -1047,4 +1048,25 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl<Collection> i
return (int) resp.getTotalSearchResults();
}
@Override
@SuppressWarnings("rawtypes")
public List<Collection> findAllCollectionsByEntityType(Context context, String entityType)
throws SearchServiceException {
List<Collection> collectionList = new ArrayList<>();
DiscoverQuery discoverQuery = new DiscoverQuery();
discoverQuery.setMaxResults(0);
discoverQuery.setDSpaceObjectFilter(IndexableCollection.TYPE);
discoverQuery.addFilterQueries("dspace.entity.type:" + entityType);
DiscoverResult discoverResult = searchService.search(context, discoverQuery);
List<IndexableObject> solrIndexableObjects = discoverResult.getIndexableObjects();
for (IndexableObject solrCollection : solrIndexableObjects) {
Collection c = ((IndexableCollection) solrCollection).getIndexedObject();
collectionList.add(c);
}
return collectionList;
}
}

View File

@@ -455,4 +455,19 @@ public interface CollectionService
public int countCollectionsWithSubmit(String q, Context context, Community community, String entityType)
throws SQLException, SearchServiceException;
/**
* Returns a list of all collections for a specific entity type.
* NOTE: for better performance, this method retrieves its results from an index (cache)
* and does not query the database directly.
* This means that results may be stale or outdated until
* https://github.com/DSpace/DSpace/issues/2853 is resolved."
*
* @param context DSpace Context
* @param entityType limit the returned collection to those related to given entity type
* @return list of collections found
* @throws SearchServiceException if search error
*/
public List<Collection> findAllCollectionsByEntityType(Context context, String entityType)
throws SearchServiceException;
}

View File

@@ -11,7 +11,8 @@
<!ELEMENT name-map EMPTY >
<!ATTLIST name-map
collection-handle CDATA #REQUIRED
collection-handle CDATA #IMPLIED
collection-entity-type CDATA #IMPLIED
submission-name NMTOKEN #REQUIRED>
<!-- 'step-definitions' must contain at least one 'step-definition' node -->

View File

@@ -47,6 +47,26 @@
<name-map collection-handle="123456789/29" submission-name="JournalVolume"/>
<name-map collection-handle="123456789/30" submission-name="JournalIssue"/>
-->
<!-- These configurations enable default submission forms per Entity type
The collection-entity-type will be the entity-type attribute associated with a collection,
typically the entity name that is associated with a collection if any created or loaded
(that is usually specified in relationship-types.xml).
- - - - - -
PLEASE NOTICE THAT YOU WILL HAVE TO RESTART DSPACE
- - - - - -
Uncomment if you intend to use them
-->
<!--
<name-map collection-entity-type="Publication" submission-name="Publication"/>
<name-map collection-entity-type="Person" submission-name="Person"/>
<name-map collection-entity-type="Project" submission-name="Project"/>
<name-map collection-entity-type="OrgUnit" submission-name="OrgUnit"/>
<name-map collection-entity-type="Journal" submission-name="Journal"/>
<name-map collection-entity-type="JournalVolume" submission-name="JournalVolume"/>
<name-map collection-entity-type="JournalIssue" submission-name="JournalIssue"/>
-->
<name-map collection-entity-type="Person" submission-name="Person"/>
</submission-map>