Skip to content

Commit

Permalink
Merged in DSC-897 (pull request DSpace#1077)
Browse files Browse the repository at this point in the history
[DSC-897] changed the implementation of Categories in statistics section depending

Approved-by: Andrea Bollini
  • Loading branch information
eskander17 authored and abollini committed Sep 21, 2023
2 parents 2849bb1 + a11f60b commit 16d4c69
Show file tree
Hide file tree
Showing 5 changed files with 448 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ public String getRelation() {
public void setRelation(String relation) {
this.relation = relation;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Map;
import java.util.Optional;

import org.apache.commons.lang3.StringUtils;
import org.dspace.app.rest.model.UsageReportCategoryRest;
import org.dspace.content.Bitstream;
import org.dspace.content.Collection;
Expand Down Expand Up @@ -40,6 +41,13 @@ public List<UsageReportCategoryRest> getCategories(DSpaceObject dso) {
} else if (dso instanceof Community) {
return mapping.get("community");
} else if (dso instanceof Collection) {
String entityType = getEntityType(dso);
if (StringUtils.isNotEmpty(entityType)) {
List<UsageReportCategoryRest> result = mapping.get("collection-" + entityType);
if (result != null) {
return result;
}
}
return mapping.get("collection");
} else if (dso instanceof Item) {
Item item = (Item) dso;
Expand All @@ -59,6 +67,16 @@ public List<UsageReportCategoryRest> getCategories(DSpaceObject dso) {
return null;
}

private String getEntityType(DSpaceObject dso) {
return dso.getMetadata()
.stream()
.filter(metadataValue ->
"dspace.entity.type".equals(metadataValue.getMetadataField().toString('.')))
.map(MetadataValue::getValue)
.findFirst()
.orElse("");
}

public UsageReportGenerator getReportGenerator(DSpaceObject dso, String reportId) {
List<UsageReportCategoryRest> categories = getCategories(dso);
Optional<UsageReportCategoryRest> cat = categories.stream().filter(x -> x.getReports().containsKey(reportId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static org.dspace.core.Constants.ITEM;

import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -24,6 +25,7 @@
import org.dspace.core.Context;
import org.dspace.discovery.configuration.DiscoveryConfiguration;
import org.dspace.discovery.configuration.DiscoveryConfigurationService;
import org.dspace.services.ConfigurationService;
import org.dspace.statistics.content.StatisticsDatasetDisplay;
import org.dspace.statistics.service.SolrLoggerService;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -40,6 +42,9 @@ public class TopCategoriesGenerator extends AbstractUsageReportGenerator {
@Autowired
private SolrLoggerService solrLoggerService;

@Autowired
private ConfigurationService configurationService;

@Autowired
private DiscoveryConfigurationService discoveryConfigurationService;

Expand Down Expand Up @@ -67,8 +72,8 @@ private Map<String, Integer> getCategoriesCount(DSpaceObject dso, String startDa

Map<String, Integer> categoriesCount = new HashMap<String, Integer>();

for (String category : categoryQueries.keySet()) {
String categoryQuery = categoryQueries.get(category);
for (String category : getCategoryQueries().keySet()) {
String categoryQuery = getCategoryQueries().get(category);
Integer categoryCount = getCategoryCount(dso, discoveryConfiguration, categoryQuery, startDate, endDate);
categoriesCount.put(category, categoryCount);
}
Expand Down Expand Up @@ -105,7 +110,7 @@ private String composeCategoryQuery(DSpaceObject dso, DiscoveryConfiguration con
}

private String getAllCategoryQueriesReverted() {
return categoryQueries.values().stream()
return getCategoryQueries().values().stream()
.filter(categoryQuery -> !OTHER_CATEGORY.equals(categoryQuery))
.map(categoryQuery -> "-" + formatCategoryQuery(categoryQuery))
.collect(Collectors.joining(" AND "));
Expand All @@ -130,10 +135,26 @@ public String getReportType() {
}

public Map<String, String> getCategoryQueries() {
if (categoryQueries == null) {
return getDefaultCategoryQueries();
}
return categoryQueries;
}

public void setCategoryQueries(Map<String, String> categoryQueries) {
this.categoryQueries = categoryQueries;
}

private Map<String, String> getDefaultCategoryQueries() {
return Arrays.stream(getDefaultEntityTypes())
.collect(Collectors.toMap(
type -> type.toLowerCase(),
type -> "entityType_keyword: '" + type + "'"
));
}

private String[] getDefaultEntityTypes() {
return configurationService.getArrayProperty("cris.entity-type");
}

}
Loading

0 comments on commit 16d4c69

Please sign in to comment.