Skip to content

Commit

Permalink
fix: identify persistent classes with an INT id field in the cache in…
Browse files Browse the repository at this point in the history
…validation system (#15554)

Co-authored-by: Morten Hansen <[email protected]>
(cherry picked from commit d72d3d4)
  • Loading branch information
netroms committed Nov 2, 2023
1 parent cbf7cff commit e58cb1e
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@

import io.lettuce.core.pubsub.RedisPubSubListener;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.hisp.dhis.cacheinvalidation.BaseCacheEvictionService;
import org.hisp.dhis.category.CategoryOptionCombo;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataset.CompleteDataSetRegistration;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.datastatistics.DataStatisticsEvent;
import org.hisp.dhis.datavalue.DataValue;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.period.Period;
Expand Down Expand Up @@ -134,9 +134,18 @@ private Serializable getEntityId(String message) throws ClassNotFoundException {
return getTrackedEntityAttributeValueId(idPart);
} else if (CompleteDataSetRegistration.class.isAssignableFrom(entityClass)) {
return getCompleteDataSetRegistrationId(idPart);
} else if (DataStatisticsEvent.class.isAssignableFrom(entityClass)) {
return Integer.parseInt(idPart);
} else {
try {
// Best effort to try to identify classes with int IDs.
Field idField = entityClass.getDeclaredField("id");
Class<?> idType = idField.getType();
if (idType == int.class) {
return Integer.parseInt(idPart);
}
} catch (NoSuchFieldException e) {
// Ignore this exception, as it's expected unless it's a class with an int ID.
}
// In most cases the ID will be a long.
return Long.parseLong(idPart);
}
}
Expand Down

0 comments on commit e58cb1e

Please sign in to comment.