Skip to content

Commit

Permalink
Merged in task/dspace-cris_2023_02_x/DSC-1968_DSC-1969_DSC-1970 (pull…
Browse files Browse the repository at this point in the history
… request DSpace#2883)

Task/dspace cris 2023 02 x/DSC-1968 DSC 1969 DSC 1970

Approved-by: Vincenzo Mecca
  • Loading branch information
abollini authored and vins01-4science committed Oct 16, 2024
2 parents 4425985 + 6d50425 commit 27cbcd4
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.stream.Stream;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.dspace.app.customurl.CustomUrlService;
import org.dspace.content.Item;
import org.dspace.content.MetadataValue;
Expand Down Expand Up @@ -129,7 +130,9 @@ public void deleteOldCustomUrlByIndex(Context context, Item item, int index) {
@Override
@SuppressWarnings("rawtypes")
public Optional<Item> findItemByCustomUrl(Context context, String customUrl) {

if (StringUtils.isBlank(customUrl)) {
return Optional.empty();
}
DiscoverQuery discoverQuery = new DiscoverQuery();
discoverQuery.addDSpaceObjectFilter(IndexableItem.TYPE);
discoverQuery.addFilterQueries("customurl:" + searchService.escapeQueryChars(customUrl));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
Expand Down Expand Up @@ -134,9 +135,11 @@ private boolean equivalent(Map<String, List<MetadataValue>> currMetadataValues,
}

private boolean equivalent(List<MetadataValue> metadataValue, List<MetadataValueDTO> metadataValueDTO) {
if (metadataValue.size() != metadataValueDTO.size()) {
if ((Objects.isNull(metadataValue) && !Objects.isNull(metadataValueDTO)) ||
(!Objects.isNull(metadataValue) && Objects.isNull(metadataValueDTO)) ||
metadataValue.size() != metadataValueDTO.size()) {
return false;
} else {
} else if (!Objects.isNull(metadataValue) && !Objects.isNull(metadataValueDTO)) {
for (int i = 0; i < metadataValue.size(); i++) {
if (!equivalent(metadataValue.get(i), metadataValueDTO.get(i))) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ private void enhanceItems(Context context) {
try {
int total = itemService.countArchivedItems(context);
for (int offset = 0; offset < total; offset += PAGE_SIZE) {
// commit and session clear within the enhance method
// do one by one to reduce the risk of conflict with the enhance thread
findItemsToEnhance(offset).forEachRemaining(this::enhanceItem);
context.commit();
context.clear();
}
} catch (SQLException e) {
throw new SQLRuntimeException(e);
Expand All @@ -91,13 +91,10 @@ private Iterator<Item> findItemsToEnhance(int offset) {
}

private void enhanceItem(Item item) {
itemEnhancerService.enhance(context, item, force);
uncacheItem(item);
}

private void uncacheItem(Item item) {
try {
context.uncacheEntity(item);
itemEnhancerService.enhance(context, item, force);
context.commit();
context.clear();
} catch (SQLException e) {
throw new SQLRuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.dspace.app.util.DCInputSet;
import org.dspace.app.util.DCInputsReader;
import org.dspace.app.util.DCInputsReaderException;
Expand Down Expand Up @@ -123,11 +123,10 @@ public boolean checkMetadataFieldVisibility(Context context, Item item, Metadata
return isMetadataFieldVisible(context, boxes, item, metadataField, false);
}


private List<MetadataValue> getPermissionFilteredMetadata(Context context, Item item,
List<MetadataValue> metadataValues, boolean preventBoxSecurityCheck) {

if (item.isWithdrawn() && isNotAdmin(context)) {
if (item.isWithdrawn() && isNotAdmin(context, item)) {
return new ArrayList<MetadataValue>();
}

Expand Down Expand Up @@ -177,42 +176,17 @@ private boolean isMetadataValueVisible(Context context, List<CrisLayoutBox> boxe

private boolean isMetadataFieldVisible(Context context, List<CrisLayoutBox> boxes, Item item,
MetadataField metadataField, boolean preventBoxSecurityCheck) {
if (CollectionUtils.isNotEmpty(boxes)) {
return isMetadataFieldVisibleByBoxes(context, boxes, item, metadataField, preventBoxSecurityCheck);
}
return isNotAdmin(context) ? isMetadataFieldVisibleFor(context, item, metadataField) : true;
}

private boolean isMetadataFieldVisibleFor(Context context, Item item, MetadataField metadataField) {
return canEditItem(context, item) || isNotHidden(context, metadataField);
}

private boolean isMetadataValueReturnAllowed(Context context, Item item, MetadataValue metadataValue) {
Integer securityLevel = metadataValue.getSecurityLevel();
if (securityLevel == null) {
return true;
}

MetadataSecurityEvaluation metadataSecurityEvaluation = getMetadataSecurityEvaluator(securityLevel);
try {
return metadataSecurityEvaluation.allowMetadataFieldReturn(context, item, metadataValue.getMetadataField());
} catch (SQLException e) {
throw new SQLRuntimeException(e);
}
}

private boolean isMetadataFieldVisibleByBoxes(Context context, List<CrisLayoutBox> boxes, Item item,
MetadataField metadataField, boolean preventBoxSecurityCheck) {

if (isPublicMetadataField(metadataField, boxes, preventBoxSecurityCheck)) {
return true;
}

// stop any further costly check if the converter request the fastest strategy
if (preventBoxSecurityCheck) {
return false;
}

EPerson currentUser = context.getCurrentUser();
EPerson currentUser = context != null ? context.getCurrentUser() : null;
List<CrisLayoutBox> notPublicBoxes = getNotPublicBoxes(metadataField, boxes);

if (Objects.nonNull(currentUser)) {
Expand All @@ -232,13 +206,46 @@ private boolean isMetadataFieldVisibleByBoxes(Context context, List<CrisLayoutBo
return false;
}

private boolean isMetadataFieldVisibleFor(Context context, Item item, MetadataField metadataField) {
return isNotHidden(context, metadataField) || canEditItem(context, item);
}

private boolean isMetadataValueReturnAllowed(Context context, Item item, MetadataValue metadataValue) {
Integer securityLevel = metadataValue.getSecurityLevel();
if (securityLevel == null) {
return true;
}

MetadataSecurityEvaluation metadataSecurityEvaluation = getMetadataSecurityEvaluator(securityLevel);
try {
return metadataSecurityEvaluation.allowMetadataFieldReturn(context, item, metadataValue.getMetadataField());
} catch (SQLException e) {
throw new SQLRuntimeException(e);
}
}

private boolean isPublicMetadataField(MetadataField metadataField, List<CrisLayoutBox> boxes,
boolean preventBoxSecurityCheck) {

List<String> publicFields = preventBoxSecurityCheck ? getPublicMetadataFromConfig() : getPublicMetadata(boxes);
List<String> publicFields = preventBoxSecurityCheck || boxes.isEmpty() ?
getPublicMetadataFromConfig() : getPublicMetadata(boxes);

return publicFields.stream()
.anyMatch(publicField -> publicField.equals(metadataField.toString('.')));
.anyMatch(publicField -> metadataMatch(metadataField, publicField));
}

private boolean metadataMatch(MetadataField metadataField, String publicField) {
if (metadataField == null || publicField == null) {
return false;
}
if (publicField.contains(".*")) {
final String exactMatch = publicField.replace(".*", "");
StringBuffer qualifiedMatch = new StringBuffer(exactMatch).append(".");
return exactMatch.equals(metadataField.toString('.')) ||
StringUtils.startsWith(metadataField.toString('.'), qualifiedMatch.toString());
} else {
return publicField.equals(metadataField.toString('.'));
}
}

private List<String> getPublicMetadataFromConfig() {
Expand Down Expand Up @@ -291,13 +298,9 @@ private List<DCInputSet> dcInputsSet(final String sd) {
}
}

private boolean isAdmin(Context context) {
return !isNotAdmin(context);
}

private boolean isNotAdmin(Context context) {
private boolean isNotAdmin(Context context, Item item) {
try {
return context == null || !authorizeService.isAdmin(context);
return context == null || !authorizeService.isAdmin(context, item);
} catch (SQLException e) {
throw new SQLRuntimeException(e);
}
Expand All @@ -311,7 +314,7 @@ private List<MetadataValue> getFromSubmission(Context context, List<CrisLayoutBo
for (MetadataValue metadataValue : metadataValues) {
MetadataField field = metadataValue.getMetadataField();
if (dcInputsContainsField(dcInputSets, field)
|| isMetadataFieldVisibleByBoxes(context, boxes, item, field, preventBoxSecurityCheck)) {
|| isMetadataFieldVisible(context, boxes, item, field, preventBoxSecurityCheck)) {
filteredMetadataValues.add(metadataValue);
}
}
Expand All @@ -325,8 +328,9 @@ private boolean dcInputsContainsField(List<DCInputSet> dcInputSets, MetadataFiel

private boolean isNotHidden(Context context, MetadataField metadataField) {
try {
return !metadataExposureService.isHidden(context, metadataField.getMetadataSchema().getName(),
metadataField.getElement(), metadataField.getQualifier());
return metadataField != null &&
!metadataExposureService.isHidden(context, metadataField.getMetadataSchema().getName(),
metadataField.getElement(), metadataField.getQualifier());
} catch (SQLException e) {
throw new SQLRuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ public class RelatedItemEnhancerUpdatePoller {

@Scheduled(fixedDelayString = "${related-item-enhancer-poller.delay}")
public void pollItemToUpdateAndProcess() {
try {
try (Context context = new Context();) {
log.debug("item enhancer poller executed");
Context context = new Context();
context.setDispatcher(RelatedItemEnhancerUpdatePoller.class.getSimpleName());
context.turnOffAuthorisationSystem();
UUID extractedUuid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.catalina.connector.ClientAbortException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dspace.app.exception.ResourceAlreadyExistsException;
Expand Down Expand Up @@ -268,6 +269,14 @@ protected ResponseEntity<Object> handleTypeMismatch(TypeMismatchException ex, Ht
return super.handleTypeMismatch(ex, headers, HttpStatus.BAD_REQUEST, request);
}

@ExceptionHandler(ClientAbortException.class)
public void clientAbortExceptionHandler(HttpServletRequest request, ClientAbortException e) {
// This usually means the browser closed or disconnected or
// something. We can't do anything. To avoid excessive stack traces
// in log, just print a simple message
log.warn("ClientAbortException");
}

@ExceptionHandler(Exception.class)
protected void handleGenericException(HttpServletRequest request, HttpServletResponse response, Exception ex)
throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5287,6 +5287,10 @@ public void testSearchItemByCustomUrlWithoutResult() throws Exception {
.param("q", "http://example.com/sample"))
.andExpect(status().isNoContent());

getClient(token).perform(get("/api/core/items/search/findByCustomURL")
.param("q", ""))
.andExpect(status().isNoContent());

}

@Test
Expand Down
2 changes: 2 additions & 0 deletions dspace/config/dspace.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -1801,6 +1801,8 @@ context-menu-entry.requestcorrection.enabled = true
context-menu-entry.statistics.enabled = true
context-menu-entry.subscriptions.enabled = true
context-menu-entry.itemversion.enabled = true
context-menu-entry.orcidview.enabled = true
context-menu-entry.fullitem.enabled = true
################################################

################ CrossWalk configurations ###########
Expand Down
12 changes: 12 additions & 0 deletions dspace/config/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,18 @@
<AppenderRef ref='A5'/>
</Logger>

<!--
Block beanutil logging except on exceptions
https://issues.apache.org/jira/browse/BEANUTILS-477
-->
<Logger name='org.apache.commons.beanutils'
level='ERROR'/>
<!--
Block Hibernate DefaultLoadEventListeer logging except on exceptions
https://github.com/DSpace/DSpace/issues/8883
-->
<Logger name='org.hibernate.event.internal.DefaultLoadEventListener'
level='ERROR'/>
<!-- Block services logging except on exceptions -->
<Logger name='org.dspace.kernel'
level='ERROR'/>
Expand Down
16 changes: 14 additions & 2 deletions dspace/config/modules/public-metadata.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
metadata.publicField = dc.title
metadata.publicField = dc.date.issued
metadata.publicField = dc.creator
metadata.publicField = dc.contributor.*
metadata.publicField = dc.publisher
metadata.publicField = dc.description.abstract

metadata.publicField = dc.date.issued
metadata.publicField = dc.date.accessioned
metadata.publicField = dc.type
metadata.publicField = dspace.entity.type
metadata.publicField = datacite.rights
metadata.publicField = datacite.available
metadata.publicField = person.familyName
metadata.publicField = person.givenName
metadata.publicField = person.affiliation.name
metadata.publicField = person.jobTitle
metadata.publicField = oairecerif.person.affiliation

0 comments on commit 27cbcd4

Please sign in to comment.