Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed all mistakes in the Search page #549

Merged
merged 11 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ public void additionalIndex(Context context, IndexableObject indexableObject, So
Community owningCommunity = clarinItemService.getOwningCommunity(context, item);
String communityName = Objects.isNull(owningCommunity) ? " " : owningCommunity.getName();

// _keyword and _filter because
// they are needed in order to work as a facet and filter.
document.addField("items_owning_community", communityName);
document.addField("items_owning_community_keyword", communityName);
document.addField("items_owning_community_filter", communityName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.dspace.app.rest.model.MetadataBitstreamWrapperRest;
import org.dspace.app.rest.model.wrapper.MetadataBitstreamWrapper;
import org.dspace.app.rest.projection.Projection;
import org.dspace.util.FileTreeViewGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -41,8 +40,7 @@ public MetadataBitstreamWrapperRest convert(MetadataBitstreamWrapper modelObject
bitstreamWrapperRest.setId(modelObject.getBitstream().getID().toString());
bitstreamWrapperRest.setDescription(modelObject.getDescription());
bitstreamWrapperRest.setChecksum(modelObject.getBitstream().getChecksum());
bitstreamWrapperRest.setFileSize(FileTreeViewGenerator.humanReadableFileSize(
modelObject.getBitstream().getSizeBytes()));
bitstreamWrapperRest.setFileSize(modelObject.getBitstream().getSizeBytes());
bitstreamWrapperRest.setFileInfo(modelObject.getFileInfo());
bitstreamWrapperRest.setHref(modelObject.getHref());
bitstreamWrapperRest.setFormat(modelObject.getFormat());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public class MetadataBitstreamWrapperRest extends BaseObjectRest<String> {

private String name;
private String description;
private String fileSize;
private long fileSize;
private String checksum;
private List<FileInfo> fileInfo;
private String format;
private String href;
private boolean canPreview;

public MetadataBitstreamWrapperRest(String name, String description, String fileSize, String checksum,
public MetadataBitstreamWrapperRest(String name, String description, long fileSize, String checksum,
List<FileInfo> fileInfo, String format, String href, boolean canPreview) {
this.name = name;
this.description = description;
Expand Down Expand Up @@ -93,11 +93,11 @@ public void setDescription(String description) {
this.description = description;
}

public String getFileSize() {
public long getFileSize() {
return fileSize;
}

public void setFileSize(String fileSize) {
public void setFileSize(long fileSize) {
this.fileSize = fileSize;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.dspace.app.rest.utils.DSpaceObjectUtils;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Site;
import org.dspace.core.Context;
import org.dspace.services.ConfigurationService;
import org.dspace.services.RequestService;
Expand Down Expand Up @@ -93,6 +94,15 @@ public boolean hasDSpacePermission(Authentication authentication, Serializable t
if (Objects.isNull(dso)) {
return true;
}

// Show Site usage reports to anonymous users if the configuration is set to do so
// This Site usage reports are used in the home page and are not sensitive
if (dso instanceof Site) {
if (!configurationService.getBooleanProperty("site.usage-reports.enable.auth.anonymous",
false)) {
return true;
}
}
return authorizeService.authorizeActionBoolean(context, dso, restPermission.getDspaceApiActionId());
} catch (SQLException e) {
log.error(e.getMessage(), e);
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,8 @@ public void ScopeBasedIndexingAndSearchTestParentCommunity2() throws Exception {
FacetEntryMatcher.entityTypeFacet(false),
FacetEntryMatcher.clarinLicenseRightsFacet(false),
FacetEntryMatcher.clarinItemsCommunityFacet(false),
FacetEntryMatcher.clarinItemsLanguageFacet(false)
FacetEntryMatcher.clarinItemsLanguageFacet(false),
FacetEntryMatcher.typeFacet(false)
))
);
}
Expand Down Expand Up @@ -624,7 +625,8 @@ public void ScopeBasedIndexingAndSearchTestSubcommunity22() throws Exception {
FacetEntryMatcher.entityTypeFacet(false),
FacetEntryMatcher.clarinLicenseRightsFacet(false),
FacetEntryMatcher.clarinItemsCommunityFacet(false),
FacetEntryMatcher.clarinItemsLanguageFacet(false)
FacetEntryMatcher.clarinItemsLanguageFacet(false),
FacetEntryMatcher.typeFacet(false)
))
);
}
Expand Down Expand Up @@ -677,7 +679,8 @@ public void ScopeBasedIndexingAndSearchTestCollection222() throws Exception {
FacetEntryMatcher.entityTypeFacet(false),
FacetEntryMatcher.clarinLicenseRightsFacet(false),
FacetEntryMatcher.clarinItemsCommunityFacet(false),
FacetEntryMatcher.clarinItemsLanguageFacet(false)
FacetEntryMatcher.clarinItemsLanguageFacet(false),
FacetEntryMatcher.typeFacet(false)
))
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package org.dspace.app.rest;

import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
Expand Down Expand Up @@ -34,7 +35,6 @@
import org.dspace.content.service.clarin.ClarinLicenseResourceMappingService;
import org.dspace.core.Constants;
import org.dspace.services.ConfigurationService;
import org.dspace.util.FileTreeViewGenerator;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -115,9 +115,9 @@ public void findByHandle() throws Exception {
.andExpect(jsonPath("$._embedded.metadatabitstreams[*].format")
.value(Matchers.containsInAnyOrder(Matchers.containsString(
bts.getFormat(context).getMIMEType()))))
// Convert the long into int because Marchers has a problem to compare long format
.andExpect(jsonPath("$._embedded.metadatabitstreams[*].fileSize")
.value(Matchers.containsInAnyOrder(Matchers.containsString(
FileTreeViewGenerator.humanReadableFileSize(bts.getSizeBytes())))))
.value(hasItem(is((int) bts.getSizeBytes()))))
.andExpect(jsonPath("$._embedded.metadatabitstreams[*].canPreview")
.value(Matchers.containsInAnyOrder(Matchers.is(canPreview))))
.andExpect(jsonPath("$._embedded.metadatabitstreams[*].fileInfo").exists())
Expand Down Expand Up @@ -150,8 +150,7 @@ public void previewingIsDisabledByCfg() throws Exception {
.value(Matchers.containsInAnyOrder(Matchers.containsString(
bts.getFormat(context).getMIMEType()))))
.andExpect(jsonPath("$._embedded.metadatabitstreams[*].fileSize")
.value(Matchers.containsInAnyOrder(Matchers.containsString(
FileTreeViewGenerator.humanReadableFileSize(bts.getSizeBytes())))))
.value(hasItem(is((int) bts.getSizeBytes()))))
.andExpect(jsonPath("$._embedded.metadatabitstreams[*].canPreview")
.value(Matchers.containsInAnyOrder(Matchers.is(false))))
.andExpect(jsonPath("$._embedded.metadatabitstreams[*].fileInfo").exists())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.dspace.content.Site;
import org.dspace.content.service.SiteService;
import org.dspace.core.Constants;
import org.dspace.eperson.EPerson;
import org.dspace.services.ConfigurationService;
Expand All @@ -76,6 +77,8 @@ public class StatisticsRestRepositoryIT extends AbstractControllerIntegrationTes
ConfigurationService configurationService;
@Autowired
protected AuthorizeService authorizeService;
@Autowired
protected SiteService siteService;

private Community communityNotVisited;
private Community communityVisited;
Expand Down Expand Up @@ -1532,6 +1535,22 @@ public void usageReportsSearch_Bitstream_Visited() throws Exception {
)));
}

// Show usage reports for the Anonymous user - it could be configured by cfg property
// `site.usage-reports.enable.auth.anonymous`
@Test
public void usageReportsSearch_Site_For_Anonymous() throws Exception {
// This property is set to `true` before each test
configurationService.setProperty("usage-statistics.authorization.admin.usage", false);

// Get the site object UUID
Site site = siteService.findSite(context);
// Allow accessing Site usage reports for anonymous
getClient()
.perform(get("/api/statistics/usagereports/search/object?uri=http://localhost:8080/server/api/core" +
"/sites/" + site.getID()))
.andExpect(status().isOk());
}

// Create expected points from -6 months to now, with given number of views in current month
private List<UsageReportPointRest> getListOfVisitsPerMonthsPoints(int viewsLastMonth) {
List<UsageReportPointRest> expectedPoints = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public static Matcher<? super Object> matchFacet(boolean hasNext, String name, S
public static Matcher<? super Object> clarinLicenseRightsFacet(boolean hasNext) {
return allOf(
hasJsonPath("$.name", is("rights")),
hasJsonPath("$.facetType", is("standard")),
hasJsonPath("$.facetType", is("text")),
hasJsonPath("$.facetLimit", any(Integer.class)),
hasJsonPath("$._links.self.href", containsString("api/discover/facets/rights")),
hasJsonPath("$._links", matchNextLink(hasNext, "api/discover/facets/rights"))
Expand All @@ -144,7 +144,7 @@ public static Matcher<? super Object> clarinItemsLanguageFacet(boolean hasNext)
public static Matcher<? super Object> clarinItemsCommunityFacet(boolean hasNext) {
return allOf(
hasJsonPath("$.name", is("items_owning_community")),
hasJsonPath("$.facetType", is("standard")),
hasJsonPath("$.facetType", is("text")),
hasJsonPath("$.facetLimit", any(Integer.class)),
hasJsonPath("$._links.self.href",
containsString("api/discover/facets/items_owning_community")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public static Matcher<? super Object> clarinLicenseRightsFilter() {
return allOf(
hasJsonPath("$.filter", is("rights")),
hasJsonPath("$.hasFacets", is(true)),
hasJsonPath("$.type", is("standard")),
hasJsonPath("$.type", is("text")),
hasJsonPath("$.openByDefault", is(false)),
checkOperators()
);
Expand All @@ -180,7 +180,7 @@ public static Matcher<? super Object> clarinItemsCommunityFilter() {
return allOf(
hasJsonPath("$.filter", is("items_owning_community")),
hasJsonPath("$.hasFacets", is(true)),
hasJsonPath("$.type", is("standard")),
hasJsonPath("$.type", is("text")),
hasJsonPath("$.openByDefault", is(false)),
checkOperators()
);
Expand All @@ -189,7 +189,7 @@ public static Matcher<? super Object> clarinItemsCommunityFilter() {
public static Matcher<? super Object> clarinItemsTypeFilter() {
return allOf(
hasJsonPath("$.filter", is("itemtype")),
hasJsonPath("$.hasFacets", is(false)),
hasJsonPath("$.hasFacets", is(true)),
hasJsonPath("$.type", is("text")),
hasJsonPath("$.openByDefault", is(false)),
checkOperators()
Expand Down
3 changes: 3 additions & 0 deletions dspace/config/clarin-dspace.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ matomo.tracker.bitstream.site_id = 1
matomo.tracker.oai.site_id = 1
statistics.cache-server.uri = http://cache-server.none

#### Statistic usage reports ####
# site.usage-reports.enable.auth.anonymous = true


##### Citacepro config #####
# citace.pro.url = https://www.citacepro.com/api/dspace/citace/oai
Expand Down
Loading
Loading