This commit is contained in:
Ken Stevens 2022-12-04 16:21:10 -05:00
parent e7ee1abed3
commit e071e00ae0
17 changed files with 59 additions and 46 deletions

View File

@ -53,6 +53,7 @@ import ca.uhn.fhir.jpa.interceptor.CascadingDeleteInterceptor;
import ca.uhn.fhir.jpa.interceptor.JpaConsentContextServices;
import ca.uhn.fhir.jpa.interceptor.OverridePathBasedReferentialIntegrityForDeletesInterceptor;
import ca.uhn.fhir.jpa.interceptor.validation.RepositoryValidatingRuleBuilder;
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.jpa.model.sched.ISchedulerService;
import ca.uhn.fhir.jpa.packages.IHapiPackageCacheManager;
import ca.uhn.fhir.jpa.packages.IPackageInstallerSvc;
@ -299,7 +300,7 @@ public class JpaConfig {
@Bean
@Primary
public IResourceLinkResolver daoResourceLinkResolver() {
return new DaoResourceLinkResolver();
return new DaoResourceLinkResolver<JpaPid>();
}
@Bean
@ -791,5 +792,4 @@ public class JpaConfig {
return new ObservationLastNIndexPersistSvc();
}
}

View File

@ -30,7 +30,7 @@ import ca.uhn.fhir.jpa.dao.data.IForcedIdDao;
import ca.uhn.fhir.jpa.dao.data.IResourceTableDao;
import ca.uhn.fhir.jpa.model.config.PartitionSettings;
import ca.uhn.fhir.jpa.model.cross.IResourceLookup;
import ca.uhn.fhir.jpa.model.cross.ResourceLookup;
import ca.uhn.fhir.jpa.model.cross.JpaResourceLookup;
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.jpa.model.entity.ForcedId;
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
@ -517,7 +517,7 @@ public class IdHelperService implements IIdHelperService<JpaPid> {
String forcedId = (String) next[2];
Date deletedAt = (Date) next[3];
ResourceLookup lookup = new ResourceLookup(resourceType, resourcePid, deletedAt);
JpaResourceLookup lookup = new JpaResourceLookup(resourceType, resourcePid, deletedAt);
if (!retVal.containsKey(forcedId)) {
retVal.put(forcedId, new ArrayList<>());
}
@ -580,7 +580,7 @@ public class IdHelperService implements IIdHelperService<JpaPid> {
}
lookup
.stream()
.map(t -> new ResourceLookup((String) t[0], (Long) t[1], (Date) t[2]))
.map(t -> new JpaResourceLookup((String) t[0], (Long) t[1], (Date) t[2]))
.forEach(t -> {
String id = t.getPersistentId().toString();
if (!theTargets.containsKey(id)) {
@ -654,7 +654,7 @@ public class IdHelperService implements IIdHelperService<JpaPid> {
}
if (!myDaoConfig.isDeleteEnabled()) {
ResourceLookup lookup = new ResourceLookup(theResourceType, jpaPid.getId(), theDeletedAt);
JpaResourceLookup lookup = new JpaResourceLookup(theResourceType, jpaPid.getId(), theDeletedAt);
String nextKey = theResourcePersistentId.toString();
myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.RESOURCE_LOOKUP, nextKey, lookup);
}
@ -750,4 +750,14 @@ public class IdHelperService implements IIdHelperService<JpaPid> {
return pidToForcedIdMap.getResolvedResourceIds();
}
@Override
public JpaPid newPid(Object thePid) {
return new JpaPid((Long) thePid);
}
@Override
public JpaPid newPidFromString(String thePid) {
return new JpaPid(Long.parseLong(thePid));
}
}

View File

@ -100,7 +100,7 @@ public class SearchParamWithInlineReferencesExtractor {
@Autowired
private SearchParamExtractorService mySearchParamExtractorService;
@Autowired
private DaoResourceLinkResolver myDaoResourceLinkResolver;
private DaoResourceLinkResolver<JpaPid> myDaoResourceLinkResolver;
@Autowired
private DaoSearchParamSynchronizer myDaoSearchParamSynchronizer;
@Autowired

View File

@ -21,16 +21,15 @@ package ca.uhn.fhir.jpa.model.cross;
*/
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
import java.util.Date;
public class ResourceLookup implements IResourceLookup {
public class JpaResourceLookup implements IResourceLookup {
private final String myResourceType;
private final Long myResourcePid;
private final Date myDeletedAt;
public ResourceLookup(String theResourceType, Long theResourcePid, Date theDeletedAt) {
public JpaResourceLookup(String theResourceType, Long theResourcePid, Date theDeletedAt) {
myResourceType = theResourceType;
myResourcePid = theResourcePid;
myDeletedAt = theDeletedAt;
@ -46,9 +45,8 @@ public class ResourceLookup implements IResourceLookup {
return myDeletedAt;
}
//TODO KM Should I rename the method and change the returned type here? (ResourceHistoryTable and ResourceTable also have the same method)
@Override
public ResourcePersistentId getPersistentId() {
public JpaPid getPersistentId() {
return new JpaPid(myResourcePid);
}
}

View File

@ -23,7 +23,6 @@ package ca.uhn.fhir.jpa.model.entity;
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.annotations.OptimisticLock;
@ -228,7 +227,7 @@ public class ResourceHistoryTable extends BaseHasResource implements Serializabl
}
@Override
public ResourcePersistentId getPersistentId() {
public JpaPid getPersistentId() {
return new JpaPid(myResourceId);
}

View File

@ -32,6 +32,7 @@ import java.util.Optional;
* @param myId This is the only required field that needs to be populated, other fields can be populated for specific use cases.
*/
public class ResourcePersistentId<T> {
public static final ResourcePersistentId NOT_FOUND = new ResourcePersistentId(-1L);
private T myId;
private Long myVersion;
private String myResourceType;

View File

@ -54,7 +54,7 @@ import java.util.function.Supplier;
*/
public class TransactionDetails {
public static final ResourcePersistentId NOT_FOUND = new ResourcePersistentId(-1L);
public static final ResourcePersistentId NOT_FOUND = ResourcePersistentId.NOT_FOUND;
private final Date myTransactionDate;
private List<Runnable> myRollbackUndoActions = Collections.emptyList();

View File

@ -29,6 +29,7 @@ import ca.uhn.fhir.batch2.model.JobDefinition;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.api.svc.IBatch2DaoSvc;
import ca.uhn.fhir.jpa.api.svc.IDeleteExpungeSvc;
import ca.uhn.fhir.jpa.api.svc.IIdHelperService;
import ca.uhn.fhir.jpa.dao.tx.HapiTransactionService;
import ca.uhn.fhir.rest.api.server.storage.IDeleteExpungeJobSubmitter;
import ca.uhn.fhir.rest.server.provider.ProviderConstants;
@ -45,8 +46,8 @@ public class DeleteExpungeAppCtx {
public JobDefinition<DeleteExpungeJobParameters> expungeJobDefinition(
IBatch2DaoSvc theBatch2DaoSvc,
HapiTransactionService theHapiTransactionService,
IDeleteExpungeSvc theDeleteExpungeSvc
) {
IDeleteExpungeSvc theDeleteExpungeSvc,
IIdHelperService theIdHelperService) {
return JobDefinition
.newBuilder()
.setJobDefinitionId(JOB_DELETE_EXPUNGE)
@ -67,7 +68,7 @@ public class DeleteExpungeAppCtx {
new LoadIdsStep(theBatch2DaoSvc))
.addLastStep("expunge",
"Perform the resource expunge",
expungeStep(theHapiTransactionService, theDeleteExpungeSvc)
expungeStep(theHapiTransactionService, theDeleteExpungeSvc, theIdHelperService)
)
.build();
}
@ -78,8 +79,8 @@ public class DeleteExpungeAppCtx {
}
@Bean
public DeleteExpungeStep expungeStep(HapiTransactionService theHapiTransactionService, IDeleteExpungeSvc theDeleteExpungeSvc) {
return new DeleteExpungeStep(theHapiTransactionService, theDeleteExpungeSvc);
public DeleteExpungeStep expungeStep(HapiTransactionService theHapiTransactionService, IDeleteExpungeSvc theDeleteExpungeSvc, IIdHelperService theIdHelperService) {
return new DeleteExpungeStep(theHapiTransactionService, theDeleteExpungeSvc, theIdHelperService);
}
@Bean

View File

@ -29,6 +29,7 @@ import ca.uhn.fhir.batch2.api.VoidModel;
import ca.uhn.fhir.batch2.jobs.chunk.ResourceIdListWorkChunkJson;
import ca.uhn.fhir.batch2.jobs.reindex.ReindexJobParameters;
import ca.uhn.fhir.jpa.api.svc.IDeleteExpungeSvc;
import ca.uhn.fhir.jpa.api.svc.IIdHelperService;
import ca.uhn.fhir.jpa.dao.tx.HapiTransactionService;
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.jpa.partition.SystemRequestDetails;
@ -47,10 +48,12 @@ public class DeleteExpungeStep implements IJobStepWorker<ReindexJobParameters, R
private static final Logger ourLog = LoggerFactory.getLogger(DeleteExpungeStep.class);
private final HapiTransactionService myHapiTransactionService;
private final IDeleteExpungeSvc myDeleteExpungeSvc;
private final IIdHelperService myIdHelperService;
public DeleteExpungeStep(HapiTransactionService theHapiTransactionService, IDeleteExpungeSvc theDeleteExpungeSvc) {
public DeleteExpungeStep(HapiTransactionService theHapiTransactionService, IDeleteExpungeSvc theDeleteExpungeSvc, IIdHelperService theIdHelperService) {
myHapiTransactionService = theHapiTransactionService;
myDeleteExpungeSvc = theDeleteExpungeSvc;
myIdHelperService = theIdHelperService;
}
@Nonnull
@ -91,7 +94,7 @@ public class DeleteExpungeStep implements IJobStepWorker<ReindexJobParameters, R
@Override
public Void doInTransaction(@Nonnull TransactionStatus theStatus) {
List<JpaPid> persistentIds = myData.getJpaPids();
List<JpaPid> persistentIds = myData.getResourcePersistentIds(myIdHelperService);
if (persistentIds.isEmpty()) {
ourLog.info("Starting delete expunge work chunk. Ther are no resources to delete expunge - Instance[{}] Chunk[{}]", myInstanceId, myChunkId);

View File

@ -32,7 +32,6 @@ import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.api.dao.IFhirSystemDao;
import ca.uhn.fhir.jpa.api.svc.IIdHelperService;
import ca.uhn.fhir.jpa.dao.tx.HapiTransactionService;
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.jpa.partition.SystemRequestDetails;
import ca.uhn.fhir.parser.DataFormatException;
import ca.uhn.fhir.rest.api.server.RequestDetails;
@ -104,7 +103,7 @@ public class ReindexStep implements IJobStepWorker<ReindexJobParameters, Resourc
@Override
public Void doInTransaction(@Nonnull TransactionStatus theStatus) {
List<JpaPid> persistentIds = myData.getJpaPids();
List<ResourcePersistentId> persistentIds = myData.getResourcePersistentIds(myIdHelperService);
ourLog.info("Starting reindex work chunk with {} resources - Instance[{}] Chunk[{}]", persistentIds.size(), myInstanceId, myChunkId);
StopWatch sw = new StopWatch();

View File

@ -20,8 +20,9 @@ package ca.uhn.fhir.batch2.jobs.chunk;
* #L%
*/
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.jpa.api.svc.IIdHelperService;
import ca.uhn.fhir.model.api.IModelJson;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
@ -57,7 +58,7 @@ public class ResourceIdListWorkChunkJson implements IModelJson {
.toString();
}
public List<JpaPid> getJpaPids() {
public <T extends ResourcePersistentId> List<T> getResourcePersistentIds(IIdHelperService<T> theIdHelperService) {
if (myTypedPids.isEmpty()) {
return Collections.emptyList();
}
@ -65,7 +66,7 @@ public class ResourceIdListWorkChunkJson implements IModelJson {
return myTypedPids
.stream()
.map(t -> {
JpaPid retval = t.asJpaPid();
T retval = theIdHelperService.newPidFromString(t.getPid());
retval.setResourceType(t.getResourceType());
return retval;
})

View File

@ -21,7 +21,6 @@ package ca.uhn.fhir.batch2.jobs.chunk;
*/
import ca.uhn.fhir.jpa.api.pid.TypedResourcePid;
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.model.api.IModelJson;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.builder.EqualsBuilder;
@ -87,8 +86,4 @@ public class TypedPidJson implements IModelJson {
public int hashCode() {
return new HashCodeBuilder(17, 37).append(myResourceType).append(myPid).toHashCode();
}
public JpaPid asJpaPid() {
return new JpaPid(Long.parseLong(myPid));
}
}

View File

@ -99,7 +99,7 @@ public class MdmClearStep implements IJobStepWorker<MdmClearJobParameters, Resou
@Override
public Void doInTransaction(@Nonnull TransactionStatus theStatus) {
List<JpaPid> persistentIds = myData.getJpaPids();
List<JpaPid> persistentIds = myData.getResourcePersistentIds(myIdHelperService);
if (persistentIds.isEmpty()) {
return null;
}

View File

@ -29,6 +29,7 @@ import ca.uhn.fhir.batch2.api.VoidModel;
import ca.uhn.fhir.batch2.jobs.chunk.ResourceIdListWorkChunkJson;
import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.api.svc.IIdHelperService;
import ca.uhn.fhir.jpa.batch.log.Logs;
import ca.uhn.fhir.mdm.api.IMdmChannelSubmitterSvc;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
@ -53,6 +54,7 @@ public class MdmInflateAndSubmitResourcesStep implements IJobStepWorker<MdmSubmi
private ResponseTerminologyTranslationSvc myResponseTerminologyTranslationSvc;
@Autowired
private IMdmChannelSubmitterSvc myMdmChannelSubmitterSvc;
private IIdHelperService<? extends ResourcePersistentId> myIdHelperService;
@Nonnull
@Override
@ -61,10 +63,10 @@ public class MdmInflateAndSubmitResourcesStep implements IJobStepWorker<MdmSubmi
ResourceIdListWorkChunkJson idList = theStepExecutionDetails.getData();
ourLog.info("Final Step for $mdm-submit - Expand and submit resources");
ourLog.info("About to expand {} resource IDs into their full resource bodies.", idList.getJpaPids().size());
ourLog.info("About to expand {} resource IDs into their full resource bodies.", idList.getResourcePersistentIds(myIdHelperService).size());
//Inflate the resources by PID
List<IBaseResource> allResources = fetchAllResources(idList.getJpaPids());
List<IBaseResource> allResources = fetchAllResources(idList.getResourcePersistentIds(myIdHelperService));
//Replace the terminology
if (myResponseTerminologyTranslationSvc != null) {

View File

@ -168,5 +168,7 @@ public interface IIdHelperService<T extends ResourcePersistentId> {
*/
Set<String> translatePidsToFhirResourceIds(Set<T> thePids);
T newPid(Object thePid);
T newPidFromString(String thePid);
}

View File

@ -65,14 +65,14 @@ import java.util.Date;
import java.util.List;
import java.util.Optional;
public class DaoResourceLinkResolver implements IResourceLinkResolver {
public class DaoResourceLinkResolver<T extends ResourcePersistentId> implements IResourceLinkResolver {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DaoResourceLinkResolver.class);
@Autowired
private DaoConfig myDaoConfig;
@Autowired
private FhirContext myContext;
@Autowired
private IIdHelperService myIdHelperService;
private IIdHelperService<T> myIdHelperService;
@Autowired
private DaoRegistry myDaoRegistry;
@Autowired
@ -95,9 +95,9 @@ public class DaoResourceLinkResolver implements IResourceLinkResolver {
RuntimeSearchParam searchParam = mySearchParamRegistry.getActiveSearchParam(theSourceResourceName, thePathAndRef.getSearchParamName());
ResourcePersistentId persistentId = null;
T persistentId = null;
if (theTransactionDetails != null) {
JpaPid resolvedResourceId = (JpaPid) theTransactionDetails.getResolvedResourceId(targetResourceId);
T resolvedResourceId = (T) theTransactionDetails.getResolvedResourceId(targetResourceId);
if (resolvedResourceId != null && resolvedResourceId.getId() != null && resolvedResourceId.getAssociatedResourceId() != null) {
persistentId = resolvedResourceId;
}
@ -141,7 +141,7 @@ public class DaoResourceLinkResolver implements IResourceLinkResolver {
}
if (persistentId == null) {
persistentId = new ResourcePersistentId(resolvedResource.getPersistentId().getId());
persistentId = myIdHelperService.newPid(resolvedResource.getPersistentId().getId());
persistentId.setAssociatedResourceId(targetResourceId);
if (theTransactionDetails != null) {
theTransactionDetails.addResolvedResourceId(targetResourceId, persistentId);
@ -307,10 +307,10 @@ public class DaoResourceLinkResolver implements IResourceLinkResolver {
myDaoRegistry.getDaoOrThrowException(theType);
}
private static class ResourceLookupPersistentIdWrapper implements IResourceLookup {
private final ResourcePersistentId myPersistentId;
private static class ResourceLookupPersistentIdWrapper<P extends ResourcePersistentId> implements IResourceLookup {
private final P myPersistentId;
public ResourceLookupPersistentIdWrapper(ResourcePersistentId thePersistentId) {
public ResourceLookupPersistentIdWrapper(P thePersistentId) {
myPersistentId = thePersistentId;
}
@ -325,7 +325,7 @@ public class DaoResourceLinkResolver implements IResourceLinkResolver {
}
@Override
public ResourcePersistentId getPersistentId() {
public P getPersistentId() {
return myPersistentId;
}
}

View File

@ -1,15 +1,17 @@
package ca.uhn.fhir.jpa.dao.index;
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.util.CanonicalIdentifier;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
class DaoResourceLinkResolverTest {
@Test
public void testLinkResolution() {
DaoResourceLinkResolver resolver = new DaoResourceLinkResolver();
DaoResourceLinkResolver resolver = new DaoResourceLinkResolver<JpaPid>();
CanonicalIdentifier canonicalIdentifier = resolver.extractIdentifierFromUrl("Patient?_patient?" +
"identifier=http://hapifhir.io/fhir/namingsystem/my_id|123456");
assertEquals("http://hapifhir.io/fhir/namingsystem/my_id", canonicalIdentifier.getSystemElement().getValueAsString());