Skip to content

Commit

Permalink
Merge remote-tracking branch 'DSpace/main' into main_CST-12826
Browse files Browse the repository at this point in the history
# Conflicts:
#	dspace-server-webapp/src/test/java/org/dspace/app/rest/RorImportMetadataSourceServiceIT.java
#	dspace/config/spring/api/ror-integration.xml
  • Loading branch information
vins01-4science committed Feb 15, 2024
2 parents f75eed9 + 20c8b03 commit d6741fd
Show file tree
Hide file tree
Showing 31 changed files with 709 additions and 96 deletions.
31 changes: 27 additions & 4 deletions dspace-api/src/main/java/org/dspace/app/util/AuthorizeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -628,12 +628,23 @@ public static boolean authorizeNewAccountRegistration(Context context, HttpServl
// actually expected to be returning true.
// For example the LDAP canSelfRegister will return true due to auto-register, while that
// does not imply a new user can register explicitly
return AuthenticateServiceFactory.getInstance().getAuthenticationService()
.allowSetPassword(context, request, null);
return authorizePasswordChange(context, request);
}
return false;
}

/**
* This method will return a boolean indicating whether the current user is allowed to reset the password
* or not
*
* @return A boolean indicating whether the current user can reset its password or not
* @throws SQLException If something goes wrong
*/
public static boolean authorizeForgotPassword() {
return DSpaceServicesFactory.getInstance().getConfigurationService()
.getBooleanProperty("user.forgot-password", true);
}

/**
* This method will return a boolean indicating whether it's allowed to update the password for the EPerson
* with the given email and canLogin property
Expand All @@ -647,15 +658,27 @@ public static boolean authorizeUpdatePassword(Context context, String email) {
if (eperson != null && eperson.canLogIn()) {
HttpServletRequest request = new DSpace().getRequestService().getCurrentRequest()
.getHttpServletRequest();
return AuthenticateServiceFactory.getInstance().getAuthenticationService()
.allowSetPassword(context, request, null);
return authorizePasswordChange(context, request);
}
} catch (SQLException e) {
log.error("Something went wrong trying to retrieve EPerson for email: " + email, e);
}
return false;
}

/**
* Checks if the current configuration has at least one password based authentication method
*
* @param context Dspace Context
* @param request Current Request
* @return True if the password change is enabled
* @throws SQLException
*/
protected static boolean authorizePasswordChange(Context context, HttpServletRequest request) throws SQLException {
return AuthenticateServiceFactory.getInstance().getAuthenticationService()
.allowSetPassword(context, request, null);
}

/**
* This method checks if the community Admin can manage accounts
*
Expand Down
10 changes: 4 additions & 6 deletions dspace-api/src/main/java/org/dspace/app/util/DCInputsReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
Expand Down Expand Up @@ -150,17 +149,16 @@ public List<String> getPairs(String name) {
* Returns the set of DC inputs used for a particular collection, or the
* default set if no inputs defined for the collection
*
* @param collectionHandle collection's unique Handle
* @param collection collection for which search the set of DC inputs
* @return DC input set
* @throws DCInputsReaderException if no default set defined
* @throws ServletException
*/
public List<DCInputSet> getInputsByCollectionHandle(String collectionHandle)
public List<DCInputSet> getInputsByCollection(Collection collection)
throws DCInputsReaderException {
SubmissionConfig config;
try {
config = SubmissionServiceFactory.getInstance().getSubmissionConfigService()
.getSubmissionConfigByCollection(collectionHandle);
.getSubmissionConfigByCollection(collection);
String formName = config.getSubmissionName();
if (formName == null) {
throw new DCInputsReaderException("No form designated as default");
Expand Down Expand Up @@ -691,7 +689,7 @@ private String getValue(Node nd) {

public String getInputFormNameByCollectionAndField(Collection collection, String field)
throws DCInputsReaderException {
List<DCInputSet> inputSets = getInputsByCollectionHandle(collection.getHandle());
List<DCInputSet> inputSets = getInputsByCollection(collection);
for (DCInputSet inputSet : inputSets) {
String[] tokenized = Utils.tokenize(field);
String schema = tokenized[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand All @@ -21,6 +22,7 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Logger;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.DSpaceObject;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.CollectionService;
Expand Down Expand Up @@ -90,6 +92,13 @@ public class SubmissionConfigReader {
*/
private Map<String, String> collectionToSubmissionConfig = null;

/**
* Hashmap which stores which submission process configuration is used by
* which community, computed from the item submission config file
* (specifically, the 'submission-map' tag)
*/
private Map<String, String> communityToSubmissionConfig = null;

/**
* Reference to the global submission step definitions defined in the
* "step-definitions" section
Expand Down Expand Up @@ -127,6 +136,7 @@ public SubmissionConfigReader() throws SubmissionConfigReaderException {

public void reload() throws SubmissionConfigReaderException {
collectionToSubmissionConfig = null;
communityToSubmissionConfig = null;
stepDefns = null;
submitDefns = null;
buildInputs(configDir + SUBMIT_DEF_FILE_PREFIX + SUBMIT_DEF_FILE_SUFFIX);
Expand All @@ -145,7 +155,8 @@ public void reload() throws SubmissionConfigReaderException {
*/
private void buildInputs(String fileName) throws SubmissionConfigReaderException {
collectionToSubmissionConfig = new HashMap<String, String>();
submitDefns = new HashMap<String, List<Map<String, String>>>();
communityToSubmissionConfig = new HashMap<String, String>();
submitDefns = new LinkedHashMap<String, List<Map<String, String>>>();

String uri = "file:" + new File(fileName).getAbsolutePath();

Expand Down Expand Up @@ -210,18 +221,41 @@ public int countSubmissionConfigs() {
* Returns the Item Submission process config used for a particular
* collection, or the default if none is defined for the collection
*
* @param collectionHandle collection's unique Handle
* @param col collection for which search Submission process config
* @return the SubmissionConfig representing the item submission config
* @throws SubmissionConfigReaderException if no default submission process configuration defined
* @throws IllegalStateException if no default submission process configuration defined
*/
public SubmissionConfig getSubmissionConfigByCollection(String collectionHandle) {
// get the name of the submission process config for this collection
String submitName = collectionToSubmissionConfig
.get(collectionHandle);
if (submitName == null) {
public SubmissionConfig getSubmissionConfigByCollection(Collection col) {

String submitName;

if (col != null) {

// get the name of the submission process config for this collection
submitName = collectionToSubmissionConfig
.get(DEFAULT_COLLECTION);
.get(col.getHandle());
if (submitName != null) {
return getSubmissionConfigByName(submitName);
}

if (!communityToSubmissionConfig.isEmpty()) {
try {
List<Community> communities = col.getCommunities();
for (Community com : communities) {
submitName = getSubmissionConfigByCommunity(com);
if (submitName != null) {
return getSubmissionConfigByName(submitName);
}
}
} catch (SQLException sqle) {
throw new IllegalStateException("Error occurred while getting item submission configured " +
"by community", sqle);
}
}
}

submitName = collectionToSubmissionConfig.get(DEFAULT_COLLECTION);

if (submitName == null) {
throw new IllegalStateException(
"No item submission process configuration designated as 'default' in 'submission-map' section of " +
Expand All @@ -230,6 +264,30 @@ public SubmissionConfig getSubmissionConfigByCollection(String collectionHandle)
return getSubmissionConfigByName(submitName);
}

/**
* Recursive function to return the Item Submission process config
* used for a community or the closest community parent, or null
* if none is defined
*
* @param com community for which search Submission process config
* @return the SubmissionConfig representing the item submission config
*/
private String getSubmissionConfigByCommunity(Community com) {
String submitName = communityToSubmissionConfig
.get(com.getHandle());
if (submitName != null) {
return submitName;
}
List<Community> communities = com.getParentCommunities();
for (Community parentCom : communities) {
submitName = getSubmissionConfigByCommunity(parentCom);
if (submitName != null) {
return submitName;
}
}
return null;
}

/**
* Returns the Item Submission process config
*
Expand Down Expand Up @@ -357,13 +415,14 @@ private void processMap(Node e) throws SAXException, SearchServiceException {
Node nd = nl.item(i);
if (nd.getNodeName().equals("name-map")) {
String id = getAttribute(nd, "collection-handle");
String communityId = getAttribute(nd, "community-handle");
String entityType = getAttribute(nd, "collection-entity-type");
String value = getAttribute(nd, "submission-name");
String content = getValue(nd);
if (id == null && entityType == null) {
if (id == null && communityId == null && entityType == null) {
throw new SAXException(
"name-map element is missing collection-handle or collection-entity-type attribute " +
"in 'item-submission.xml'");
"name-map element is missing collection-handle or community-handle or collection-entity-type " +
"attribute in 'item-submission.xml'");
}
if (value == null) {
throw new SAXException(
Expand All @@ -375,7 +434,8 @@ private void processMap(Node e) throws SAXException, SearchServiceException {
}
if (id != null) {
collectionToSubmissionConfig.put(id, value);

} else if (communityId != null) {
communityToSubmissionConfig.put(communityId, value);
} else {
// get all collections for this entity-type
List<Collection> collections = collectionService.findAllCollectionsByEntityType( context,
Expand Down
14 changes: 3 additions & 11 deletions dspace-api/src/main/java/org/dspace/app/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -405,21 +405,13 @@ public static List<String> getControlledVocabulariesDisplayValueLocalized(
DCInput myInputs = null;
boolean myInputsFound = false;
String formFileName = I18nUtil.getInputFormsFileName(locale);
String col_handle = "";

Collection collection = item.getOwningCollection();

if (collection == null) {
// set an empty handle so to get the default input set
col_handle = "";
} else {
col_handle = collection.getHandle();
}

// Read the input form file for the specific collection
DCInputsReader inputsReader = new DCInputsReader(formFileName);

List<DCInputSet> inputSets = inputsReader.getInputsByCollectionHandle(col_handle);
List<DCInputSet> inputSets = inputsReader.getInputsByCollection(collection);

// Replace the values of Metadatum[] with the correct ones in case
// of
Expand Down Expand Up @@ -500,8 +492,8 @@ public static <T> List<T>[] splitList(List<T> idsList, int i) {
public static List<String> differenceInSubmissionFields(Collection fromCollection, Collection toCollection)
throws DCInputsReaderException {
DCInputsReader reader = new DCInputsReader();
List<DCInputSet> from = reader.getInputsByCollectionHandle(fromCollection.getHandle());
List<DCInputSet> to = reader.getInputsByCollectionHandle(toCollection.getHandle());
List<DCInputSet> from = reader.getInputsByCollection(fromCollection);
List<DCInputSet> to = reader.getInputsByCollection(toCollection);

Set<String> fromFieldName = new HashSet<>();
Set<String> toFieldName = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public String getChoiceAuthorityName(String schema, String element, String quali
// check if it is the requested collection
Map<String, ChoiceAuthority> controllerFormDef = controllerFormDefinitions.get(fieldKey);
SubmissionConfig submissionConfig = submissionConfigService
.getSubmissionConfigByCollection(collection.getHandle());
.getSubmissionConfigByCollection(collection);
String submissionName = submissionConfig.getSubmissionName();
// check if the requested collection has a submission definition that use an authority for the metadata
if (controllerFormDef.containsKey(submissionName)) {
Expand Down Expand Up @@ -495,7 +495,7 @@ private ChoiceAuthority getAuthorityByFieldKeyCollection(String fieldKey, Collec
try {
configReaderService = SubmissionServiceFactory.getInstance().getSubmissionConfigService();
SubmissionConfig submissionName = configReaderService
.getSubmissionConfigByCollection(collection.getHandle());
.getSubmissionConfigByCollection(collection);
ma = controllerFormDefinitions.get(fieldKey).get(submissionName.getSubmissionName());
} catch (SubmissionConfigReaderException e) {
// the system is in an illegal state as the submission definition is not valid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.dspace.app.util.DCInputSet;
import org.dspace.app.util.DCInputsReader;
import org.dspace.app.util.DCInputsReaderException;
import org.dspace.content.Collection;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.dspace.content.MetadataValue;
Expand Down Expand Up @@ -69,7 +70,7 @@ public int perform(DSpaceObject dso) throws IOException {
handle = "in workflow";
}
sb.append("Item: ").append(handle);
for (String req : getReqList(item.getOwningCollection().getHandle())) {
for (String req : getReqList(item.getOwningCollection())) {
List<MetadataValue> vals = itemService.getMetadataByMetadataString(item, req);
if (vals.size() == 0) {
sb.append(" missing required field: ").append(req);
Expand All @@ -91,14 +92,14 @@ public int perform(DSpaceObject dso) throws IOException {
}
}

protected List<String> getReqList(String handle) throws DCInputsReaderException {
List<String> reqList = reqMap.get(handle);
protected List<String> getReqList(Collection collection) throws DCInputsReaderException {
List<String> reqList = reqMap.get(collection.getHandle());
if (reqList == null) {
reqList = reqMap.get("default");
}
if (reqList == null) {
reqList = new ArrayList<String>();
List<DCInputSet> inputSet = reader.getInputsByCollectionHandle(handle);
List<DCInputSet> inputSet = reader.getInputsByCollection(collection);
for (DCInputSet inputs : inputSet) {
for (DCInput[] row : inputs.getFields()) {
for (DCInput input : row) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,25 @@ public Collection<MetadatumDTO> getValue(String schema, String element, String q
return values;
}

/**
* Returns an {@code Optional<String>} representing the value
* of the metadata {@code field} found inside the {@code valueList}.
* @param field String of the MetadataField to search
* @return {@code Optional<String>} non empty if found.
*/
public Optional<String> getSingleValue(String field) {
MetadataFieldName metadataFieldName = new MetadataFieldName(field);
return getSingleValue(metadataFieldName.schema, metadataFieldName.element, metadataFieldName.qualifier);
}

/**
* Retrieves a single value for the given schema, element, and qualifier.
*
* @param schema the schema for the value
* @param element the element for the value
* @param qualifier the qualifier for the value
* @return an optional containing the single value, if present
*/
public Optional<String> getSingleValue(String schema, String element, String qualifier) {
return getValue(schema, element, qualifier).stream()
.map(MetadatumDTO::getValue)
Expand Down
Loading

0 comments on commit d6741fd

Please sign in to comment.