Fix indexing bug
This commit is contained in:
parent
d9ce0ebf7c
commit
1d3bcd9e8f
|
@ -876,6 +876,11 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
|||
|
||||
@Override
|
||||
public T read(IIdType theId, RequestDetails theRequestDetails) {
|
||||
return read(theId, theRequestDetails, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T read(IIdType theId, RequestDetails theRequestDetails, boolean theDeletedOk) {
|
||||
validateResourceTypeAndThrowIllegalArgumentException(theId);
|
||||
|
||||
// Notify interceptors
|
||||
|
@ -891,10 +896,13 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
|||
|
||||
T retVal = toResource(myResourceType, entity, null, false);
|
||||
|
||||
if (entity.getDeleted() != null) {
|
||||
throw new ResourceGoneException("Resource was deleted at " + new InstantType(entity.getDeleted()).getValueAsString());
|
||||
if (theForHistory == false) {
|
||||
if (entity.getDeleted() != null) {
|
||||
throw new ResourceGoneException("Resource was deleted at " + new InstantType(entity.getDeleted()).getValueAsString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ourLog.debug("Processed read on {} in {}ms", theId.getValue(), w.getMillisAndRestart());
|
||||
return retVal;
|
||||
}
|
||||
|
|
|
@ -171,6 +171,12 @@ public interface IFhirResourceDao<T extends IBaseResource> extends IDao {
|
|||
*/
|
||||
T read(IIdType theId, RequestDetails theRequestDetails);
|
||||
|
||||
/**
|
||||
* Should deleted resources be returned successfully. This should be false for
|
||||
* a normal FHIR read.
|
||||
*/
|
||||
T read(IIdType theId, RequestDetails theRequestDetails, boolean theDeletedOk);
|
||||
|
||||
BaseHasResource readEntity(IIdType theId);
|
||||
|
||||
/**
|
||||
|
|
|
@ -34,6 +34,7 @@ import ca.uhn.fhir.jpa.model.entity.ForcedId;
|
|||
import ca.uhn.fhir.jpa.entity.ResourceReindexJobEntity;
|
||||
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException;
|
||||
import ca.uhn.fhir.util.StopWatch;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
@ -460,7 +461,7 @@ public class ResourceReindexingSvcImpl implements IResourceReindexingSvc {
|
|||
|
||||
IFhirResourceDao<?> dao = myDaoRegistry.getResourceDao(resourceTable.getResourceType());
|
||||
long expectedVersion = resourceTable.getVersion();
|
||||
IBaseResource resource = dao.read(resourceTable.getIdDt().toVersionless());
|
||||
IBaseResource resource = dao.read(resourceTable.getIdDt().toVersionless(), null,true);
|
||||
if (resource == null) {
|
||||
throw new InternalErrorException("Could not find resource version " + resourceTable.getIdDt().toUnqualified().getValue() + " in database");
|
||||
}
|
||||
|
|
|
@ -237,7 +237,7 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test {
|
|||
runInTransaction(() -> {
|
||||
Optional<ResourceTable> tableOpt = myResourceTableDao.findById(id1.getIdPartAsLong());
|
||||
assertTrue(tableOpt.isPresent());
|
||||
assertEquals(BaseHapiFhirDao.INDEX_STATUS_INDEXING_FAILED, tableOpt.get().getIndexStatus().longValue());
|
||||
assertEquals(BaseHapiFhirDao.INDEX_STATUS_INDEXED, tableOpt.get().getIndexStatus().longValue());
|
||||
assertThat(myResourceIndexedSearchParamTokenDao.countForResourceId(id1.getIdPartAsLong()), not(greaterThan(0)));
|
||||
});
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import ca.uhn.fhir.jpa.entity.ResourceReindexJobEntity;
|
|||
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.hl7.fhir.r4.model.Observation;
|
||||
import org.hl7.fhir.r4.model.Patient;
|
||||
import org.junit.Before;
|
||||
|
@ -197,22 +198,22 @@ public class ResourceReindexingSvcImplTest extends BaseJpaTest {
|
|||
"Patient"
|
||||
};
|
||||
List<IBaseResource> resources = Arrays.asList(
|
||||
new Patient().setId("Patient/0"),
|
||||
new Patient().setId("Patient/1"),
|
||||
new Patient().setId("Patient/2"),
|
||||
new Patient().setId("Patient/3")
|
||||
new Patient().setId("Patient/0/_history/1"),
|
||||
new Patient().setId("Patient/1/_history/1"),
|
||||
new Patient().setId("Patient/2/_history/1"),
|
||||
new Patient().setId("Patient/3/_history/1")
|
||||
);
|
||||
mockWhenResourceTableFindById(updatedTimes, resourceTypes);
|
||||
when(myDaoRegistry.getResourceDao(eq("Patient"))).thenReturn(myResourceDao);
|
||||
when(myDaoRegistry.getResourceDao(eq(Patient.class))).thenReturn(myResourceDao);
|
||||
when(myDaoRegistry.getResourceDao(eq("Observation"))).thenReturn(myResourceDao);
|
||||
when(myDaoRegistry.getResourceDao(eq(Observation.class))).thenReturn(myResourceDao);
|
||||
when(myResourceDao.toResource(any(), anyBoolean())).thenAnswer(t -> {
|
||||
ResourceTable table = (ResourceTable) t.getArguments()[0];
|
||||
Long id = table.getId();
|
||||
return resources.get(id.intValue());
|
||||
when(myResourceDao.read(any())).thenAnswer(t->{
|
||||
IIdType id = (IIdType) t.getArguments()[0];
|
||||
return resources.get(id.getIdPartAsLong().intValue());
|
||||
});
|
||||
|
||||
|
||||
int count = mySvc.forceReindexingPass();
|
||||
assertEquals(4, count);
|
||||
|
||||
|
@ -258,20 +259,19 @@ public class ResourceReindexingSvcImplTest extends BaseJpaTest {
|
|||
"Observation"
|
||||
};
|
||||
List<IBaseResource> resources = Arrays.asList(
|
||||
new Patient().setId("Patient/0"),
|
||||
new Patient().setId("Patient/1"),
|
||||
new Observation().setId("Observation/2"),
|
||||
new Observation().setId("Observation/3")
|
||||
new Patient().setId("Patient/0/_history/1"),
|
||||
new Patient().setId("Patient/1/_history/1"),
|
||||
new Observation().setId("Observation/2/_history/1"),
|
||||
new Observation().setId("Observation/3/_history/1")
|
||||
);
|
||||
mockWhenResourceTableFindById(updatedTimes, resourceTypes);
|
||||
when(myDaoRegistry.getResourceDao(eq("Patient"))).thenReturn(myResourceDao);
|
||||
when(myDaoRegistry.getResourceDao(eq(Patient.class))).thenReturn(myResourceDao);
|
||||
when(myDaoRegistry.getResourceDao(eq("Observation"))).thenReturn(myResourceDao);
|
||||
when(myDaoRegistry.getResourceDao(eq(Observation.class))).thenReturn(myResourceDao);
|
||||
when(myResourceDao.toResource(any(), anyBoolean())).thenAnswer(t -> {
|
||||
ResourceTable table = (ResourceTable) t.getArguments()[0];
|
||||
Long id = table.getId();
|
||||
return resources.get(id.intValue());
|
||||
when(myResourceDao.read(any())).thenAnswer(t->{
|
||||
IIdType id = (IIdType) t.getArguments()[0];
|
||||
return resources.get(id.getIdPartAsLong().intValue());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue