Skip to content

Commit

Permalink
Merged in task/dspace-cris-2023_02_x/DSC_2027 (pull request DSpace#3039)
Browse files Browse the repository at this point in the history
DSC-2027 when indexing with uuid or handler, metrics are now update for that resource

Approved-by: Andrea Bollini
  • Loading branch information
danieleninfo authored and abollini committed Nov 15, 2024
1 parent 6a78aba commit 82ab1d7
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public interface CrisMetricsDAO extends GenericDAO<CrisMetrics> {
public CrisMetrics findLastMetricByResourceIdAndMetricsTypes(Context context, String metricType, UUID resourceId)
throws SQLException;

public List<CrisMetrics> findLastMetricsByResourceId(Context context, UUID resourceId,
Integer limit, Integer offset) throws SQLException;

public CrisMetrics uniqueLastMetricByResourceIdAndResourceTypeIdAndMetricsType(Context context, String metricType,
UUID resource, boolean last) throws SQLException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ public CrisMetrics findLastMetricByResourceIdAndMetricsTypes(Context context, St
return singleResult(context, criteriaQuery);
}

@Override
public List<CrisMetrics> findLastMetricsByResourceId(Context context, UUID resourceId,
Integer limit, Integer offset) throws SQLException {
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, CrisMetrics.class);
Root<CrisMetrics> crisMetricsRoot = criteriaQuery.from(CrisMetrics.class);
Join<CrisMetrics, DSpaceObject> join = crisMetricsRoot.join(CrisMetrics_.resource);
criteriaQuery.where(
criteriaBuilder.and(criteriaBuilder.equal(crisMetricsRoot.get(CrisMetrics_.last), true),
criteriaBuilder.equal(join.get(DSpaceObject_.id), resourceId)));
return list(context, criteriaQuery, false, CrisMetrics.class, limit, offset);
}

@Override
public CrisMetrics uniqueLastMetricByResourceIdAndResourceTypeIdAndMetricsType(Context context, String metricType,
UUID resource, boolean last) throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public interface CrisMetricsService {
public CrisMetrics findLastMetricByResourceIdAndMetricsTypes(Context context, String metricType, UUID resourceUuid)
throws SQLException;

public List<CrisMetrics> findLastMetricsByResourceId(Context context, UUID resourceUuid,
Integer limit, Integer offset) throws SQLException;

public CrisMetrics uniqueLastMetricByResourceIdAndResourceTypeIdAndMetricsType(Context context, String metricType,
UUID resourceUuid, boolean last) throws SQLException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ public CrisMetrics findLastMetricByResourceIdAndMetricsTypes(Context context, St
return this.crisMetricsDAO.findLastMetricByResourceIdAndMetricsTypes(context, metricType, resourceId);
}

@Override
public List<CrisMetrics> findLastMetricsByResourceId(Context context, UUID resourceId,
Integer limit, Integer offset) throws SQLException {
return this.crisMetricsDAO.findLastMetricsByResourceId(context, resourceId, limit, offset);
}

@Override
public CrisMetrics uniqueLastMetricByResourceIdAndResourceTypeIdAndMetricsType(
Context context, String metricType, UUID resource, boolean last) throws SQLException {
Expand Down
18 changes: 17 additions & 1 deletion dspace-api/src/main/java/org/dspace/discovery/IndexClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,23 @@ public void internalRun() throws Exception {

handler.logInfo("Done with indexing");
if (metricUpdate) {
updateCrisMetricsInSolrDocService.performUpdate(context, handler, true);
if (indexableObjects.isPresent()) {
final String param = indexClientOptions == IndexClientOptions.REMOVE ?
commandLine.getOptionValue('r') :
commandLine.getOptionValue('i');
UUID uuid = null;
try {
uuid = UUID.fromString(param);
} catch (Exception e) {
uuid = HandleServiceFactory.getInstance()
.getHandleService().resolveToObject(context, param).getID();
}

updateCrisMetricsInSolrDocService.performUpdate(context, handler, true, uuid);

} else {
updateCrisMetricsInSolrDocService.performUpdate(context, handler, true);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package org.dspace.metrics;
import java.sql.SQLException;
import java.util.List;
import java.util.UUID;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -36,8 +37,14 @@ public class UpdateCrisMetricsInSolrDocService {
IndexingService.class.getName(), IndexingService.class);

public void performUpdate(Context context, DSpaceRunnableHandler handler, boolean optimize) {
performUpdate(context, handler, optimize, null);
}

public void performUpdate(Context context, DSpaceRunnableHandler handler, boolean optimize, UUID resourceUuid) {
try {
List<CrisMetrics> metrics = crisMetricsService.findAllLast(context,-1,-1);
List<CrisMetrics> metrics = resourceUuid == null
? crisMetricsService.findAllLast(context,-1,-1)
: crisMetricsService.findLastMetricsByResourceId(context, resourceUuid, -1, -1);
handler.logInfo("Metric update start");
for (CrisMetrics metric : metrics) {
try {
Expand Down

0 comments on commit 82ab1d7

Please sign in to comment.