fixed code for passing tests successfully

This commit is contained in:
Kateryna Mironova 2022-11-21 15:08:00 -05:00
parent 044611a89c
commit 1b1478d7bc
35 changed files with 160 additions and 130 deletions

View File

@ -73,7 +73,7 @@ public class ResourceVersionSvcDaoImpl implements IResourceVersionSvc {
}
List<Long> matchingIds = dao.searchForIds(theSearchParamMap, new SystemRequestDetails().setRequestPartitionId(theRequestPartitionId)).stream()
.map(ResourcePersistentId::getIdAsLong)
.map(id -> ((JpaPid) id).getId())
.collect(Collectors.toList());
List<ResourceTable> allById = new ArrayList<>();
@ -138,7 +138,7 @@ public class ResourceVersionSvcDaoImpl implements IResourceVersionSvc {
}
List<JpaPid> jpaPids = myIdHelperService.resolveResourcePersistentIdsWithCache(thePartitionId,
new ArrayList<>(theIds)).stream().map(id -> (JpaPid) id).toList();
new ArrayList<>(theIds)).stream().map(id -> (JpaPid) id).collect(Collectors.toList());
// we'll use this map to fetch pids that require versions
HashMap<Long, JpaPid> pidsToVersionToResourcePid = new HashMap<>();
@ -146,7 +146,7 @@ public class ResourceVersionSvcDaoImpl implements IResourceVersionSvc {
// fill in our map
for (JpaPid pid : jpaPids) {
if (pid.getVersion() == null) {
pidsToVersionToResourcePid.put(pid.getIdAsLong(), pid);
pidsToVersionToResourcePid.put(pid.getId(), pid);
}
Optional<IIdType> idOp = theIds.stream()
.filter(i -> i.getIdPart().equals(pid.getAssociatedResourceId().getIdPart()))

View File

@ -1729,9 +1729,9 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> extends BaseStora
protected void addPidToResource(IBasePersistedResource theEntity, IBaseResource theResource) {
if (theResource instanceof IAnyResource) {
IDao.RESOURCE_PID.put((IAnyResource) theResource, theEntity.getPersistentId().getIdAsLong());
IDao.RESOURCE_PID.put((IAnyResource) theResource, ((JpaPid) theEntity.getPersistentId()).getId());
} else if (theResource instanceof IResource) {
IDao.RESOURCE_PID.put((IResource) theResource, theEntity.getPersistentId().getIdAsLong());
IDao.RESOURCE_PID.put((IResource) theResource, ((JpaPid) theEntity.getPersistentId()).getId());
}
}

View File

@ -301,12 +301,12 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
return myTxTemplate.execute(tx -> {
IIdType retVal = myIdHelperService.translatePidIdToForcedId(myFhirContext, myResourceName, pid);
if (!retVal.hasVersionIdPart()) {
IIdType idWithVersion = myMemoryCacheService.getIfPresent(MemoryCacheService.CacheEnum.RESOURCE_CONDITIONAL_CREATE_VERSION, pid.getIdAsLong());
IIdType idWithVersion = myMemoryCacheService.getIfPresent(MemoryCacheService.CacheEnum.RESOURCE_CONDITIONAL_CREATE_VERSION, pid.getId());
if (idWithVersion == null) {
Long version = myResourceTableDao.findCurrentVersionByPid(pid.getIdAsLong());
Long version = myResourceTableDao.findCurrentVersionByPid(pid.getId());
if (version != null) {
retVal = myFhirContext.getVersion().newIdType().setParts(retVal.getBaseUrl(), retVal.getResourceType(), retVal.getIdPart(), Long.toString(version));
myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.RESOURCE_CONDITIONAL_CREATE_VERSION, pid.getIdAsLong(), retVal);
myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.RESOURCE_CONDITIONAL_CREATE_VERSION, pid.getId(), retVal);
}
} else {
retVal = idWithVersion;
@ -667,7 +667,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
TransactionDetails transactionDetails = new TransactionDetails();
List<ResourceTable> deletedResources = new ArrayList<>();
for (ResourcePersistentId pid : theResourceIds) {
ResourceTable entity = myEntityManager.find(ResourceTable.class, pid.getIdAsLong());
ResourceTable entity = myEntityManager.find(ResourceTable.class, ((JpaPid) pid).getId());
deletedResources.add(entity);
T resourceToDelete = toResource(myResourceType, entity, null, false);
@ -1198,10 +1198,11 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
@Transactional
public T readByPid(ResourcePersistentId thePid, boolean theDeletedOk) {
StopWatch w = new StopWatch();
JpaPid jpaPid = (JpaPid) thePid;
Optional<ResourceTable> entity = myResourceTableDao.findById(thePid.getIdAsLong());
Optional<ResourceTable> entity = myResourceTableDao.findById(jpaPid.getId());
if (!entity.isPresent()) {
throw new ResourceNotFoundException(Msg.code(975) + "No resource found with PID " + thePid);
throw new ResourceNotFoundException(Msg.code(975) + "No resource found with PID " + jpaPid);
}
if (isDeleted(entity.get()) && !theDeletedOk) {
throw createResourceGoneException(entity.get());
@ -1209,7 +1210,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
T retVal = toResource(myResourceType, entity.get(), null, false);
ourLog.debug("Processed read on {} in {}ms", thePid, w.getMillis());
ourLog.debug("Processed read on {} in {}ms", jpaPid, w.getMillis());
return retVal;
}
@ -1287,9 +1288,9 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
@SuppressWarnings("unchecked")
@Override
public void reindex(ResourcePersistentId theResourcePersistentId, RequestDetails theRequest, TransactionDetails theTransactionDetails) {
Optional<ResourceTable> entityOpt = myResourceTableDao.findById(theResourcePersistentId.getIdAsLong());
Optional<ResourceTable> entityOpt = myResourceTableDao.findById(((JpaPid) theResourcePersistentId).getId());
if (!entityOpt.isPresent()) {
ourLog.warn("Unable to find entity with PID: {}", theResourcePersistentId.getId());
ourLog.warn("Unable to find entity with PID: {}", ((JpaPid) theResourcePersistentId).getId());
return;
}
@ -1314,21 +1315,21 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
JpaPid pid = (JpaPid) myIdHelperService.resolveResourcePersistentIds(requestPartitionId, getResourceName(), theId.getIdPart());
Set<Integer> readPartitions = null;
if (requestPartitionId.isAllPartitions()) {
entity = myEntityManager.find(ResourceTable.class, pid.getIdAsLong());
entity = myEntityManager.find(ResourceTable.class, pid.getId());
} else {
readPartitions = myRequestPartitionHelperService.toReadPartitions(requestPartitionId);
if (readPartitions.size() == 1) {
if (readPartitions.contains(null)) {
entity = myResourceTableDao.readByPartitionIdNull(pid.getIdAsLong()).orElse(null);
entity = myResourceTableDao.readByPartitionIdNull(pid.getId()).orElse(null);
} else {
entity = myResourceTableDao.readByPartitionId(readPartitions.iterator().next(), pid.getIdAsLong()).orElse(null);
entity = myResourceTableDao.readByPartitionId(readPartitions.iterator().next(), pid.getId()).orElse(null);
}
} else {
if (readPartitions.contains(null)) {
List<Integer> readPartitionsWithoutNull = readPartitions.stream().filter(t -> t != null).collect(Collectors.toList());
entity = myResourceTableDao.readByPartitionIdsOrNull(readPartitionsWithoutNull, pid.getIdAsLong()).orElse(null);
entity = myResourceTableDao.readByPartitionIdsOrNull(readPartitionsWithoutNull, pid.getId()).orElse(null);
} else {
entity = myResourceTableDao.readByPartitionIds(readPartitions, pid.getIdAsLong()).orElse(null);
entity = myResourceTableDao.readByPartitionIds(readPartitions, pid.getId()).orElse(null);
}
}
}

View File

@ -112,7 +112,7 @@ public abstract class BaseHapiFhirResourceDaoObservation<T extends IBaseResource
if (nextOr instanceof ReferenceParam) {
ReferenceParam ref = (ReferenceParam) nextOr;
JpaPid pid = (JpaPid) myIdHelperService.resolveResourcePersistentIds(requestPartitionId, ref.getResourceType(), ref.getIdPart());
orderedSubjectReferenceMap.put(pid.getIdAsLong(), nextOr);
orderedSubjectReferenceMap.put(pid.getId(), nextOr);
} else {
throw new IllegalArgumentException(Msg.code(942) + "Invalid token type (expecting ReferenceParam): " + nextOr.getClass());
}

View File

@ -5,6 +5,7 @@ import ca.uhn.fhir.jpa.api.config.DaoConfig;
import ca.uhn.fhir.jpa.api.dao.IFhirSystemDao;
import ca.uhn.fhir.jpa.api.model.ExpungeOptions;
import ca.uhn.fhir.jpa.api.model.ExpungeOutcome;
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.jpa.model.entity.ResourceHistoryTable;
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import ca.uhn.fhir.jpa.search.builder.SearchBuilder;
@ -146,7 +147,7 @@ public abstract class BaseHapiFhirSystemDao<T extends IBaseBundle, MT> extends B
public void preFetchResources(List<ResourcePersistentId> theResolvedIds) {
List<Long> pids = theResolvedIds
.stream()
.map(t -> t.getIdAsLong())
.map(t -> ((JpaPid) t).getId())
.collect(Collectors.toList());
new QueryChunker<Long>().chunk(pids, ids->{

View File

@ -165,12 +165,12 @@ public class TransactionProcessor extends BaseTransactionProcessor {
}
}
List<JpaPid> outcome = myIdHelperService.resolveResourcePersistentIdsWithCache(requestPartitionId, idsToPreResolve)
.stream().map(id -> (JpaPid) id).toList();
.stream().map(id -> (JpaPid) id).collect(Collectors.toList());
for (JpaPid next : outcome) {
foundIds.add(next.getAssociatedResourceId().toUnqualifiedVersionless().getValue());
theTransactionDetails.addResolvedResourceId(next.getAssociatedResourceId(), next);
if (myDaoConfig.getResourceClientIdStrategy() != DaoConfig.ClientIdStrategyEnum.ANY || !next.getAssociatedResourceId().isIdPartValidLong()) {
idsToPreFetch.add(next.getIdAsLong());
idsToPreFetch.add(next.getId());
}
}
for (IIdType next : idsToPreResolve) {
@ -193,7 +193,7 @@ public class TransactionProcessor extends BaseTransactionProcessor {
if ("PUT".equals(verb) && requestUrl != null && requestUrl.contains("?")) {
JpaPid cachedId = (JpaPid) myMatchResourceUrlService.processMatchUrlUsingCacheOnly(resourceType, requestUrl);
if (cachedId != null) {
idsToPreFetch.add(cachedId.getIdAsLong());
idsToPreFetch.add(cachedId.getId());
} else if (SINGLE_PARAMETER_MATCH_URL_PATTERN.matcher(requestUrl).matches()) {
RuntimeResourceDefinition resourceDefinition = myFhirContext.getResourceDefinition(resource);
SearchParameterMap matchUrlSearchMap = myMatchUrlService.translateMatchUrl(requestUrl, resourceDefinition);
@ -202,7 +202,7 @@ public class TransactionProcessor extends BaseTransactionProcessor {
} else if ("POST".equals(verb) && requestIfNoneExist != null && requestIfNoneExist.contains("?")) {
JpaPid cachedId = (JpaPid) myMatchResourceUrlService.processMatchUrlUsingCacheOnly(resourceType, requestIfNoneExist);
if (cachedId != null) {
idsToPreFetch.add(cachedId.getIdAsLong());
idsToPreFetch.add(cachedId.getId());
} else if (SINGLE_PARAMETER_MATCH_URL_PATTERN.matcher(requestIfNoneExist).matches()) {
RuntimeResourceDefinition resourceDefinition = myFhirContext.getResourceDefinition(resource);
SearchParameterMap matchUrlSearchMap = myMatchUrlService.translateMatchUrl(requestIfNoneExist, resourceDefinition);

View File

@ -129,13 +129,14 @@ public class ResourceExpungeService implements IResourceExpungeService {
@Transactional
public List<ResourcePersistentId> findHistoricalVersionsOfNonDeletedResources(String theResourceName, ResourcePersistentId theResourceId, int theRemainingCount) {
Pageable page = PageRequest.of(0, theRemainingCount);
JpaPid jpaPid = (JpaPid) theResourceId;
Slice<Long> ids;
if (theResourceId != null && theResourceId.getId() != null) {
if (theResourceId.getVersion() != null) {
ids = toSlice(myResourceHistoryTableDao.findForIdAndVersionAndFetchProvenance(theResourceId.getIdAsLong(), theResourceId.getVersion()));
if (jpaPid != null && jpaPid.getId() != null) {
if (jpaPid.getVersion() != null) {
ids = toSlice(myResourceHistoryTableDao.findForIdAndVersionAndFetchProvenance(jpaPid.getId(), jpaPid.getVersion()));
} else {
ids = myResourceHistoryTableDao.findIdsOfPreviousVersionsOfResourceId(page, theResourceId.getIdAsLong());
ids = myResourceHistoryTableDao.findIdsOfPreviousVersionsOfResourceId(page, jpaPid.getId());
}
} else {
if (theResourceName != null) {
@ -154,7 +155,7 @@ public class ResourceExpungeService implements IResourceExpungeService {
Pageable page = PageRequest.of(0, theRemainingCount);
Slice<Long> ids;
if (theResourceId != null) {
ids = myResourceTableDao.findIdsOfDeletedResourcesOfType(page, theResourceId.getIdAsLong(), theResourceName);
ids = myResourceTableDao.findIdsOfDeletedResourcesOfType(page, ((JpaPid) theResourceId).getId(), theResourceName);
ourLog.info("Expunging {} deleted resources of type[{}] and ID[{}]", ids.getNumberOfElements(), theResourceName, theResourceId);
} else {
if (theResourceName != null) {
@ -172,7 +173,7 @@ public class ResourceExpungeService implements IResourceExpungeService {
@Transactional
public void expungeCurrentVersionOfResources(RequestDetails theRequestDetails, List<ResourcePersistentId> theResourceIds, AtomicInteger theRemainingCount) {
for (ResourcePersistentId next : theResourceIds) {
expungeCurrentVersionOfResource(theRequestDetails, next.getIdAsLong(), theRemainingCount);
expungeCurrentVersionOfResource(theRequestDetails, ((JpaPid) next).getId(), theRemainingCount);
if (theRemainingCount.get() <= 0) {
return;
}
@ -230,7 +231,7 @@ public class ResourceExpungeService implements IResourceExpungeService {
@Transactional
public void expungeHistoricalVersionsOfIds(RequestDetails theRequestDetails, List<ResourcePersistentId> theResourceIds, AtomicInteger theRemainingCount) {
for (ResourcePersistentId next : theResourceIds) {
expungeHistoricalVersionsOfId(theRequestDetails, next.getIdAsLong(), theRemainingCount);
expungeHistoricalVersionsOfId(theRequestDetails, ((JpaPid) next).getId(), theRemainingCount);
if (theRemainingCount.get() <= 0) {
return;
}
@ -241,7 +242,7 @@ public class ResourceExpungeService implements IResourceExpungeService {
@Transactional
public void expungeHistoricalVersions(RequestDetails theRequestDetails, List<ResourcePersistentId> theHistoricalIds, AtomicInteger theRemainingCount) {
for (ResourcePersistentId next : theHistoricalIds) {
expungeHistoricalVersion(theRequestDetails, next.getIdAsLong(), theRemainingCount);
expungeHistoricalVersion(theRequestDetails, ((JpaPid) next).getId(), theRemainingCount);
if (theRemainingCount.get() <= 0) {
return;
}
@ -275,43 +276,44 @@ public class ResourceExpungeService implements IResourceExpungeService {
@Override
@Transactional
public void deleteAllSearchParams(ResourcePersistentId theResourceId) {
ResourceTable resource = myResourceTableDao.findById(theResourceId.getIdAsLong()).orElse(null);
Long theResourceLongId = ((JpaPid) theResourceId).getId();
ResourceTable resource = myResourceTableDao.findById(theResourceLongId).orElse(null);
if (resource == null || resource.isParamsUriPopulated()) {
myResourceIndexedSearchParamUriDao.deleteByResourceId(theResourceId.getIdAsLong());
myResourceIndexedSearchParamUriDao.deleteByResourceId(theResourceLongId);
}
if (resource == null || resource.isParamsCoordsPopulated()) {
myResourceIndexedSearchParamCoordsDao.deleteByResourceId(theResourceId.getIdAsLong());
myResourceIndexedSearchParamCoordsDao.deleteByResourceId(theResourceLongId);
}
if (resource == null || resource.isParamsDatePopulated()) {
myResourceIndexedSearchParamDateDao.deleteByResourceId(theResourceId.getIdAsLong());
myResourceIndexedSearchParamDateDao.deleteByResourceId(theResourceLongId);
}
if (resource == null || resource.isParamsNumberPopulated()) {
myResourceIndexedSearchParamNumberDao.deleteByResourceId(theResourceId.getIdAsLong());
myResourceIndexedSearchParamNumberDao.deleteByResourceId(theResourceLongId);
}
if (resource == null || resource.isParamsQuantityPopulated()) {
myResourceIndexedSearchParamQuantityDao.deleteByResourceId(theResourceId.getIdAsLong());
myResourceIndexedSearchParamQuantityDao.deleteByResourceId(theResourceLongId);
}
if (resource == null || resource.isParamsQuantityNormalizedPopulated()) {
myResourceIndexedSearchParamQuantityNormalizedDao.deleteByResourceId(theResourceId.getIdAsLong());
myResourceIndexedSearchParamQuantityNormalizedDao.deleteByResourceId(theResourceLongId);
}
if (resource == null || resource.isParamsStringPopulated()) {
myResourceIndexedSearchParamStringDao.deleteByResourceId(theResourceId.getIdAsLong());
myResourceIndexedSearchParamStringDao.deleteByResourceId(theResourceLongId);
}
if (resource == null || resource.isParamsTokenPopulated()) {
myResourceIndexedSearchParamTokenDao.deleteByResourceId(theResourceId.getIdAsLong());
myResourceIndexedSearchParamTokenDao.deleteByResourceId(theResourceLongId);
}
if (resource == null || resource.isParamsComboStringUniquePresent()) {
myResourceIndexedCompositeStringUniqueDao.deleteByResourceId(theResourceId.getIdAsLong());
myResourceIndexedCompositeStringUniqueDao.deleteByResourceId(theResourceLongId);
}
if (resource == null || resource.isParamsComboTokensNonUniquePresent()) {
myResourceIndexedComboTokensNonUniqueDao.deleteByResourceId(theResourceId.getIdAsLong());
myResourceIndexedComboTokensNonUniqueDao.deleteByResourceId(theResourceLongId);
}
if (myDaoConfig.getIndexMissingFields() == DaoConfig.IndexEnabledEnum.ENABLED) {
mySearchParamPresentDao.deleteByResourceId(theResourceId.getIdAsLong());
mySearchParamPresentDao.deleteByResourceId(theResourceLongId);
}
if (resource == null || resource.isHasLinks()) {
myResourceLinkDao.deleteByResourceId(theResourceId.getIdAsLong());
myResourceLinkDao.deleteByResourceId(theResourceLongId);
}
}

View File

@ -432,7 +432,7 @@ public class IdHelperService implements IIdHelperService {
@Override
public Optional<String> translatePidIdToForcedIdWithCache(ResourcePersistentId theId) {
return myMemoryCacheService.get(MemoryCacheService.CacheEnum.PID_TO_FORCED_ID, theId.getIdAsLong(), pid -> myForcedIdDao.findByResourcePid(pid).map(ForcedId::asTypedFhirResourceId));
return myMemoryCacheService.get(MemoryCacheService.CacheEnum.PID_TO_FORCED_ID, ((JpaPid) theId).getId(), pid -> myForcedIdDao.findByResourcePid(pid).map(ForcedId::asTypedFhirResourceId));
}
private ListMultimap<String, String> organizeIdsByResourceType(Collection<IIdType> theIds) {
@ -597,7 +597,7 @@ public class IdHelperService implements IIdHelperService {
@Override
public PersistentIdToForcedIdMap translatePidsToForcedIds(Set<ResourcePersistentId> theResourceIds) {
assert myDontCheckActiveTransactionForUnitTest || TransactionSynchronizationManager.isSynchronizationActive();
Set<Long> thePids = theResourceIds.stream().map(t -> t.getIdAsLong()).collect(Collectors.toSet());
Set<Long> thePids = theResourceIds.stream().map(t -> ((JpaPid) t).getId()).collect(Collectors.toSet());
Map<Long, Optional<String>> retVal = new HashMap<>(myMemoryCacheService.getAllPresent(MemoryCacheService.CacheEnum.PID_TO_FORCED_ID, thePids));
List<Long> remainingPids = thePids
@ -638,20 +638,21 @@ public class IdHelperService implements IIdHelperService {
*/
@Override
public void addResolvedPidToForcedId(ResourcePersistentId theResourcePersistentId, @Nonnull RequestPartitionId theRequestPartitionId, String theResourceType, @Nullable String theForcedId, @Nullable Date theDeletedAt) {
JpaPid jpaPid = (JpaPid) theResourcePersistentId;
if (theForcedId != null) {
if (theResourcePersistentId.getAssociatedResourceId() == null) {
populateAssociatedResourceId(theResourceType, theForcedId, (JpaPid) theResourcePersistentId);
populateAssociatedResourceId(theResourceType, theForcedId, jpaPid);
}
myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.PID_TO_FORCED_ID, theResourcePersistentId.getIdAsLong(), Optional.of(theResourceType + "/" + theForcedId));
myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.PID_TO_FORCED_ID, jpaPid.getId(), Optional.of(theResourceType + "/" + theForcedId));
String key = toForcedIdToPidKey(theRequestPartitionId, theResourceType, theForcedId);
myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.FORCED_ID_TO_PID, key, theResourcePersistentId);
} else {
myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.PID_TO_FORCED_ID, theResourcePersistentId.getIdAsLong(), Optional.empty());
myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.PID_TO_FORCED_ID, jpaPid.getId(), Optional.empty());
}
if (!myDaoConfig.isDeleteEnabled()) {
ResourceLookup lookup = new ResourceLookup(theResourceType, theResourcePersistentId.getIdAsLong(), theDeletedAt);
ResourceLookup lookup = new ResourceLookup(theResourceType, jpaPid.getId(), theDeletedAt);
String nextKey = theResourcePersistentId.toString();
myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.RESOURCE_LOOKUP, nextKey, lookup);
}
@ -686,14 +687,17 @@ public class IdHelperService implements IIdHelperService {
@Override
@Nullable
public ResourcePersistentId getPidOrNull(@Nonnull RequestPartitionId theRequestPartitionId, IBaseResource theResource) {
JpaPid retVal = new JpaPid(Long.parseLong(theResource.getUserData(RESOURCE_PID).toString()));
if (retVal.getId() == null) {
Object resourceId = theResource.getUserData(RESOURCE_PID);
JpaPid retVal;
if (resourceId == null) {
IIdType id = theResource.getIdElement();
try {
retVal = (JpaPid) resolveResourcePersistentIds(theRequestPartitionId, id.getResourceType(), id.getIdPart());
} catch (ResourceNotFoundException e) {
return null;
}
} else {
retVal = new JpaPid(Long.parseLong(resourceId.toString()));
}
return retVal;
}
@ -718,7 +722,7 @@ public class IdHelperService implements IIdHelperService {
@Override
public IIdType resourceIdFromPidOrThrowException(ResourcePersistentId thePid, String theResourceType) {
Optional<ResourceTable> optionalResource = myResourceTableDao.findById(thePid.getIdAsLong());
Optional<ResourceTable> optionalResource = myResourceTableDao.findById(((JpaPid) thePid).getId());
if (!optionalResource.isPresent()) {
throw new ResourceNotFoundException(Msg.code(2124) + "Requested resource not found");
}

View File

@ -59,8 +59,8 @@ public class JpaIdHelperService extends IdHelperService implements IJpaIdHelperS
@Nonnull
public List<Long> getPidsOrThrowException(List<IIdType> theIds) {
List<JpaPid> resourcePersistentIds = super.resolveResourcePersistentIdsWithCache(RequestPartitionId.allPartitions(), theIds)
.stream().map(id -> (JpaPid) id).toList();
return resourcePersistentIds.stream().map(ResourcePersistentId::getIdAsLong).collect(Collectors.toList());
.stream().map(id -> (JpaPid) id).collect(Collectors.toList());
return resourcePersistentIds.stream().map(JpaPid::getId).collect(Collectors.toList());
}
@ -78,7 +78,9 @@ public class JpaIdHelperService extends IdHelperService implements IJpaIdHelperS
if (retVal == null) {
IIdType id = theResource.getIdElement();
try {
retVal = super.resolveResourcePersistentIds(RequestPartitionId.allPartitions(), id.getResourceType(), id.getIdPart()).getIdAsLong();
JpaPid jpaPid = (JpaPid) super.resolveResourcePersistentIds(
RequestPartitionId.allPartitions(), id.getResourceType(), id.getIdPart());
retVal = jpaPid.getId();
} catch (ResourceNotFoundException e) {
return null;
}
@ -98,8 +100,9 @@ public class JpaIdHelperService extends IdHelperService implements IJpaIdHelperS
assert TransactionSynchronizationManager.isSynchronizationActive();
List<IIdType> ids = Collections.singletonList(theId);
List<JpaPid> resourcePersistentIds = super.resolveResourcePersistentIdsWithCache(RequestPartitionId.allPartitions(), ids).stream().map(id -> (JpaPid) id).toList();;
return resourcePersistentIds.get(0).getIdAsLong();
List<JpaPid> resourcePersistentIds = super.resolveResourcePersistentIdsWithCache(
RequestPartitionId.allPartitions(), ids).stream().map(id -> (JpaPid) id).collect(Collectors.toList());
return resourcePersistentIds.get(0).getId();
}
@Override

View File

@ -67,17 +67,17 @@ public class MdmLinkDaoJpaImpl implements IMdmLinkDao<MdmLink> {
@Override
public int deleteWithAnyReferenceToPid(ResourcePersistentId thePid) {
return myMdmLinkDao.deleteWithAnyReferenceToPid(thePid.getIdAsLong());
return myMdmLinkDao.deleteWithAnyReferenceToPid(((JpaPid) thePid).getId());
}
@Override
public int deleteWithAnyReferenceToPidAndMatchResultNot(ResourcePersistentId thePid, MdmMatchResultEnum theMatchResult) {
return myMdmLinkDao.deleteWithAnyReferenceToPidAndMatchResultNot(thePid.getIdAsLong(), theMatchResult);
return myMdmLinkDao.deleteWithAnyReferenceToPidAndMatchResultNot(((JpaPid) thePid).getId(), theMatchResult);
}
@Override
public List<MdmPidTuple> expandPidsFromGroupPidGivenMatchResult(ResourcePersistentId theGroupPid, MdmMatchResultEnum theMdmMatchResultEnum) {
return myMdmLinkDao.expandPidsFromGroupPidGivenMatchResult(theGroupPid.getIdAsLong(), theMdmMatchResultEnum)
return myMdmLinkDao.expandPidsFromGroupPidGivenMatchResult(((JpaPid) theGroupPid).getId(), theMdmMatchResultEnum)
.stream()
.map( theMdmPidTuple -> new MdmPidTuple()
.setSourcePid(new JpaPid(theMdmPidTuple.getSourcePid()))
@ -87,7 +87,7 @@ public class MdmLinkDaoJpaImpl implements IMdmLinkDao<MdmLink> {
@Override
public List<MdmPidTuple> expandPidsBySourcePidAndMatchResult(ResourcePersistentId theSourcePid, MdmMatchResultEnum theMdmMatchResultEnum) {
return myMdmLinkDao.expandPidsBySourcePidAndMatchResult(theSourcePid.getIdAsLong(), theMdmMatchResultEnum)
return myMdmLinkDao.expandPidsBySourcePidAndMatchResult(((JpaPid) theSourcePid).getId(), theMdmMatchResultEnum)
.stream()
.map( theMdmPidTuple -> new MdmPidTuple()
.setSourcePid(new JpaPid(theMdmPidTuple.getSourcePid()))
@ -97,7 +97,7 @@ public class MdmLinkDaoJpaImpl implements IMdmLinkDao<MdmLink> {
@Override
public List<MdmPidTuple> expandPidsByGoldenResourcePidAndMatchResult(ResourcePersistentId theSourcePid, MdmMatchResultEnum theMdmMatchResultEnum) {
return myMdmLinkDao.expandPidsByGoldenResourcePidAndMatchResult(theSourcePid.getIdAsLong(), theMdmMatchResultEnum)
return myMdmLinkDao.expandPidsByGoldenResourcePidAndMatchResult(((JpaPid) theSourcePid).getId(), theMdmMatchResultEnum)
.stream()
.map( theMdmPidTuple -> new MdmPidTuple()
.setSourcePid(new JpaPid(theMdmPidTuple.getSourcePid()))
@ -123,13 +123,13 @@ public class MdmLinkDaoJpaImpl implements IMdmLinkDao<MdmLink> {
@Override
public List<MdmLink> findAllById(List<ResourcePersistentId> thePids) {
List<Long> theLongPids = thePids.stream().map(theResourcePersistentId -> theResourcePersistentId.getIdAsLong()).collect(Collectors.toList());
List<Long> theLongPids = thePids.stream().map(thePid -> ((JpaPid) thePid).getId()).collect(Collectors.toList());
return myMdmLinkDao.findAllById(theLongPids);
}
@Override
public Optional<MdmLink> findById(ResourcePersistentId thePid) {
return myMdmLinkDao.findById(thePid.getIdAsLong());
return myMdmLinkDao.findById(((JpaPid) thePid).getId());
}
public void deleteAll(List<MdmLink> theLinks) {
@ -191,11 +191,11 @@ public class MdmLinkDaoJpaImpl implements IMdmLinkDao<MdmLink> {
List<Predicate> andPredicates = new ArrayList<>();
if (theGoldenResourceId != null) {
Predicate goldenResourcePredicate = criteriaBuilder.equal(from.get("myGoldenResourcePid").as(Long.class), myIdHelperService.getPidOrThrowException(RequestPartitionId.allPartitions(), theGoldenResourceId).getIdAsLong());
Predicate goldenResourcePredicate = criteriaBuilder.equal(from.get("myGoldenResourcePid").as(Long.class), ((JpaPid) myIdHelperService.getPidOrThrowException(RequestPartitionId.allPartitions(), theGoldenResourceId)).getId());
andPredicates.add(goldenResourcePredicate);
}
if (theSourceId != null) {
Predicate sourceIdPredicate = criteriaBuilder.equal(from.get("mySourcePid").as(Long.class), myIdHelperService.getPidOrThrowException(RequestPartitionId.allPartitions(), theSourceId).getIdAsLong());
Predicate sourceIdPredicate = criteriaBuilder.equal(from.get("mySourcePid").as(Long.class), ((JpaPid) myIdHelperService.getPidOrThrowException(RequestPartitionId.allPartitions(), theSourceId)).getId());
andPredicates.add(sourceIdPredicate);
}
if (theMatchResult != null) {
@ -228,12 +228,12 @@ public class MdmLinkDaoJpaImpl implements IMdmLinkDao<MdmLink> {
@Override
public Optional<? extends IMdmLink> findBySourcePidAndMatchResult(ResourcePersistentId theSourcePid, MdmMatchResultEnum theMatch) {
return myMdmLinkDao.findBySourcePidAndMatchResult(theSourcePid.getIdAsLong(), theMatch);
return myMdmLinkDao.findBySourcePidAndMatchResult(((JpaPid) theSourcePid).getId(), theMatch);
}
@Override
public void deleteLinksWithAnyReferenceToPids(List<ResourcePersistentId> theResourcePersistentIds) {
List<Long> goldenResourcePids = theResourcePersistentIds.stream().map(ResourcePersistentId::getIdAsLong).collect(Collectors.toList());
List<Long> goldenResourcePids = theResourcePersistentIds.stream().map(pid -> ((JpaPid) pid).getId()).collect(Collectors.toList());
// Split into chunks of 500 so older versions of Oracle don't run into issues (500 = 1000 / 2 since the dao
// method uses the list twice in the sql predicate)
List<List<Long>> chunks = ListUtils.partition(goldenResourcePids, 500);

View File

@ -22,6 +22,7 @@ package ca.uhn.fhir.jpa.delete.batch2;
import ca.uhn.fhir.jpa.api.svc.IDeleteExpungeSvc;
import ca.uhn.fhir.jpa.dao.IFulltextSearchSvc;
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
import org.slf4j.Logger;
@ -70,7 +71,7 @@ public class DeleteExpungeSvcImpl implements IDeleteExpungeSvc {
*/
private void clearHibernateSearchIndex(List<ResourcePersistentId> thePersistentIds) {
if (myFullTextSearchSvc != null) {
List<Object> objectIds = thePersistentIds.stream().map(ResourcePersistentId::getIdAsLong).collect(Collectors.toList());
List<Object> objectIds = thePersistentIds.stream().map(id -> ((JpaPid) id).getId()).collect(Collectors.toList());
myFullTextSearchSvc.deleteIndexedDocumentsByTypeAndId(ResourceTable.class, objectIds);
ourLog.info("Cleared Hibernate Search indexes.");
}

View File

@ -157,9 +157,10 @@ public class MdmLink extends BasePartitionable implements IMdmLink {
@Override
public IMdmLink setGoldenResourcePersistenceId(ResourcePersistentId theGoldenResourcePid) {
setPersonPid(theGoldenResourcePid.getIdAsLong());
Long longPid = ((JpaPid) theGoldenResourcePid).getId();
setPersonPid(longPid);
myGoldenResourcePid = theGoldenResourcePid.getIdAsLong();
myGoldenResourcePid = longPid;
return this;
}
@ -170,7 +171,7 @@ public class MdmLink extends BasePartitionable implements IMdmLink {
@Override
public IMdmLink setSourcePersistenceId(ResourcePersistentId theSourcePid) {
mySourcePid = theSourcePid.getIdAsLong();
mySourcePid = ((JpaPid) theSourcePid).getId();
return this;
}

View File

@ -528,7 +528,7 @@ public class SearchBuilder implements ISearchBuilder {
// add the pids to targetPids
for (ResourcePersistentId pid : idToPid.values()) {
myAlsoIncludePids.add(pid);
theTargetPids.add(pid.getIdAsLong());
theTargetPids.add(((JpaPid) pid).getId());
}
}
@ -852,7 +852,7 @@ public class SearchBuilder implements ISearchBuilder {
if (resourcePidToVersion == null) {
resourcePidToVersion = new HashMap<>();
}
resourcePidToVersion.put(next.getIdAsLong(), next.getVersion());
resourcePidToVersion.put(((JpaPid) next).getId(), next.getVersion());
}
}
@ -955,11 +955,11 @@ public class SearchBuilder implements ISearchBuilder {
for (ResourceTag tag : tagList) {
resourceId = new JpaPid(tag.getResourceId());
tagCol = tagMap.get(resourceId.getIdAsLong());
tagCol = tagMap.get(resourceId.getId());
if (tagCol == null) {
tagCol = new ArrayList<>();
tagCol.add(tag);
tagMap.put(resourceId.getIdAsLong(), tagCol);
tagMap.put(resourceId.getId(), tagCol);
} else {
tagCol.add(tag);
}
@ -1024,7 +1024,7 @@ public class SearchBuilder implements ISearchBuilder {
// Do we use the fulltextsvc via hibernate-search to load resources or be backwards compatible with older ES only impl
// to handle lastN?
if (myDaoConfig.isAdvancedHSearchIndexing() && myDaoConfig.isStoreResourceInHSearchIndex()) {
List<Long> pidList = thePids.stream().map(ResourcePersistentId::getIdAsLong).collect(Collectors.toList());
List<Long> pidList = thePids.stream().map(pid -> ((JpaPid) pid).getId()).collect(Collectors.toList());
List<IBaseResource> resources = myFulltextSearchSvc.getResources(pidList);
return resources;

View File

@ -20,6 +20,7 @@ package ca.uhn.fhir.jpa.search.builder;
* #L%
*/
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
import org.apache.commons.lang3.Validate;
@ -119,8 +120,8 @@ public class SearchQueryExecutors {
@Override
public Long next() {
ResourcePersistentId next = myIterator.next();
return next==null?null:next.getIdAsLong();
JpaPid next = (JpaPid) myIterator.next();
return next == null ? null : next.getId();
}
}

View File

@ -323,7 +323,7 @@ public class TermCodeSystemStorageSvcImpl implements ITermCodeSystemStorageSvc {
IIdType csId = myTerminologyVersionAdapterSvc.createOrUpdateCodeSystem(theCodeSystemResource, theRequest);
JpaPid codeSystemResourcePid = (JpaPid) myIdHelperService.resolveResourcePersistentIds(RequestPartitionId.allPartitions(), csId.getResourceType(), csId.getIdPart());
ResourceTable resource = myResourceTableDao.getOne(codeSystemResourcePid.getIdAsLong());
ResourceTable resource = myResourceTableDao.getOne(codeSystemResourcePid.getId());
ourLog.info("CodeSystem resource has ID: {}", csId.getValue());

View File

@ -265,7 +265,7 @@ public class JpaBulkExportProcessorTest {
pids.add(new JpaPid(((IdDt) type).getIdPartAsLong()));
}
MdmPidTuple tuple = createTuple(groupId.getIdAsLong(), groupGoldenPid);
MdmPidTuple tuple = createTuple(groupId.getId(), groupGoldenPid);
IFhirResourceDao<Group> groupDao = mock(IFhirResourceDao.class);
parameters.setExpandMdm(theMdm); // set mdm expansion
@ -322,7 +322,7 @@ public class JpaBulkExportProcessorTest {
assertTrue(pidIterator.hasNext());
while (pidIterator.hasNext()) {
JpaPid pid = (JpaPid) pidIterator.next();
long idAsLong = pid.getIdAsLong();
long idAsLong = pid.getId();
boolean existing = pids.contains(new JpaPid(idAsLong));
if (!existing) {
assertTrue(theMdm);
@ -353,7 +353,7 @@ public class JpaBulkExportProcessorTest {
Arrays.asList(pid, pid2)
);
MdmPidTuple tuple = createTuple(groupId.getIdAsLong(), groupGoldenPid);
MdmPidTuple tuple = createTuple(groupId.getId(), groupGoldenPid);
List<IPrimitiveType> patientTypes = createPatientTypes();
IFhirResourceDao<Group> groupDao = mock(IFhirResourceDao.class);

View File

@ -39,6 +39,7 @@ import ca.uhn.fhir.mdm.util.MdmResourceUtil;
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import org.apache.commons.lang3.StringUtils;
@ -363,8 +364,8 @@ abstract public class BaseMdmR4Test extends BaseJpaR4Test {
Optional<? extends IMdmLink> matchedLinkForTargetPid = myMdmLinkDaoSvc.getMatchedLinkForSourcePid(runInTransaction(() -> myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), theBaseResource)));
if (matchedLinkForTargetPid.isPresent()) {
Long goldenResourcePid = matchedLinkForTargetPid.get().getGoldenResourcePersistenceId().getIdAsLong();
return (T) relevantDao.readByPid(new JpaPid(goldenResourcePid));
JpaPid jpaPid = (JpaPid) matchedLinkForTargetPid.get().getGoldenResourcePersistenceId();
return (T) relevantDao.readByPid(jpaPid);
} else {
return null;
}
@ -372,7 +373,7 @@ abstract public class BaseMdmR4Test extends BaseJpaR4Test {
protected <T extends IBaseResource> T getTargetResourceFromMdmLink(IMdmLink theMdmLink, String theResourceType) {
IFhirResourceDao resourceDao = myDaoRegistry.getResourceDao(theResourceType);
return (T) resourceDao.readByPid(new JpaPid(theMdmLink.getGoldenResourcePersistenceId().getIdAsLong()));
return (T) resourceDao.readByPid(theMdmLink.getGoldenResourcePersistenceId());
}
protected Patient addExternalEID(Patient thePatient, String theEID) {

View File

@ -85,8 +85,8 @@ public class MdmLinkDaoSvcTest extends BaseMdmR4Test {
lists.stream()
.forEach(tuple -> {
assertThat(tuple.getGoldenPid().getIdAsLong(), is(equalTo(golden.getIdElement().getIdPartAsLong())));
assertThat(tuple.getSourcePid().getIdAsLong(), is(in(expectedExpandedPids)));
assertThat(((JpaPid) tuple.getGoldenPid()).getId(), is(equalTo(golden.getIdElement().getIdPartAsLong())));
assertThat(((JpaPid)tuple.getSourcePid()).getId(), is(in(expectedExpandedPids)));
});
}

View File

@ -213,7 +213,7 @@ public class MdmStorageInterceptorIT extends BaseMdmR4Test {
// Updating a Golden Resource Patient who was created via MDM should fail.
IMdmLink mdmLink = runInTransaction(() -> myMdmLinkDaoSvc.getMatchedLinkForSourcePid(myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), patient)).orElseThrow(() -> new IllegalStateException()));
Long sourcePatientPid = mdmLink.getGoldenResourcePersistenceId().getIdAsLong();
Long sourcePatientPid = ((JpaPid) mdmLink.getGoldenResourcePersistenceId()).getId();
Patient goldenResourcePatient = myPatientDao.readByPid(new JpaPid(sourcePatientPid));
goldenResourcePatient.setGender(Enumerations.AdministrativeGender.MALE);
try {

View File

@ -70,10 +70,10 @@ public class MdmGoldenResourceMergerSvcTest extends BaseMdmR4Test {
public void before() {
myFromGoldenPatient = createGoldenPatient();
IdType fromSourcePatientId = myFromGoldenPatient.getIdElement().toUnqualifiedVersionless();
myFromGoldenPatientPid = runInTransaction(()->myIdHelperService.getPidOrThrowException(RequestPartitionId.allPartitions(), fromSourcePatientId)).getIdAsLong();
myFromGoldenPatientPid = ((JpaPid) runInTransaction(()->myIdHelperService.getPidOrThrowException(RequestPartitionId.allPartitions(), fromSourcePatientId))).getId();
myToGoldenPatient = createGoldenPatient();
IdType toGoldenPatientId = myToGoldenPatient.getIdElement().toUnqualifiedVersionless();
myToGoldenPatientPid = runInTransaction(()->myIdHelperService.getPidOrThrowException(RequestPartitionId.allPartitions(), toGoldenPatientId)).getIdAsLong();
myToGoldenPatientPid = ((JpaPid) runInTransaction(()->myIdHelperService.getPidOrThrowException(RequestPartitionId.allPartitions(), toGoldenPatientId))).getId();
myTargetPatient1 = createPatient();
myTargetPatient2 = createPatient();

View File

@ -93,8 +93,8 @@ public class MdmLinkSvcTest extends BaseMdmR4Test {
JpaPid goldenPatient1Pid = (JpaPid) runInTransaction(()->myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), goldenPatient1));
JpaPid goldenPatient2Pid = (JpaPid) runInTransaction(()->myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), goldenPatient2));
assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndSourceResourcePid(goldenPatient1Pid.getIdAsLong(), goldenPatient2Pid.getIdAsLong()).isPresent());
assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndSourceResourcePid(goldenPatient2Pid.getIdAsLong(), goldenPatient1Pid.getIdAsLong()).isPresent());
assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndSourceResourcePid(goldenPatient1Pid.getId(), goldenPatient2Pid.getId()).isPresent());
assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndSourceResourcePid(goldenPatient2Pid.getId(), goldenPatient1Pid.getId()).isPresent());
saveNoMatchLink(goldenPatient1Pid, goldenPatient2Pid);
@ -111,8 +111,8 @@ public class MdmLinkSvcTest extends BaseMdmR4Test {
JpaPid goldenPatient1Pid = (JpaPid) runInTransaction(()->myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), goldenPatient1));
JpaPid goldenPatient2Pid = (JpaPid) runInTransaction(()->myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), goldenPatient2));
assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndSourceResourcePid(goldenPatient1Pid.getIdAsLong(), goldenPatient2Pid.getIdAsLong()).isPresent());
assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndSourceResourcePid(goldenPatient2Pid.getIdAsLong(), goldenPatient1Pid.getIdAsLong()).isPresent());
assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndSourceResourcePid(goldenPatient1Pid.getId(), goldenPatient2Pid.getId()).isPresent());
assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndSourceResourcePid(goldenPatient2Pid.getId(), goldenPatient1Pid.getId()).isPresent());
saveNoMatchLink(goldenPatient2Pid, goldenPatient1Pid);
@ -175,7 +175,7 @@ public class MdmLinkSvcTest extends BaseMdmR4Test {
//assertEquals(patient1.getIdElement().toVersionless().getValue(), sourcePatient.getLinkFirstRep().getTarget().getReference());
List<String> actual = targets
.stream()
.map(link -> link.getSourcePersistenceId().getId().toString())
.map(link -> ((JpaPid) link.getSourcePersistenceId()).getId().toString())
.collect(Collectors.toList());
List<String> expected = Arrays.asList(patient1, patient2)

View File

@ -6,6 +6,7 @@ import ca.uhn.fhir.batch2.model.JobInstance;
import ca.uhn.fhir.jpa.entity.MdmLink;
import ca.uhn.fhir.jpa.mdm.BaseMdmR4Test;
import ca.uhn.fhir.jpa.mdm.helper.MdmHelperR4;
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.jpa.partition.SystemRequestDetails;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.mdm.api.MdmLinkSourceEnum;
@ -53,8 +54,8 @@ class MdmClearStepTest extends BaseMdmR4Test {
goldenPatient.setId(myGoldenId);
myPatientDao.update(goldenPatient);
mySourcePid = myIdHelperService.getPidOrThrowException(sourcePatient).getIdAsLong();
myGoldenPid = myIdHelperService.getPidOrThrowException(goldenPatient).getIdAsLong();
mySourcePid = ((JpaPid) myIdHelperService.getPidOrThrowException(sourcePatient)).getId();
myGoldenPid = ((JpaPid) myIdHelperService.getPidOrThrowException(goldenPatient)).getId();
myLink = buildMdmLink(mySourcePid, myGoldenPid);
myMdmLinkDaoSvc.save(myLink);

View File

@ -18,7 +18,7 @@ public class JpaPid extends ResourcePersistentId<Long> {
public static List<Long> toLongList(Collection<ResourcePersistentId> thePids) {
List<Long> retVal = new ArrayList<>(thePids.size());
for (ResourcePersistentId next : thePids) {
retVal.add(next.getIdAsLong());
retVal.add(((JpaPid) next).getId());
}
return retVal;
}

View File

@ -401,7 +401,7 @@ public class SearchParamExtractorService {
* need to resolve it again
*/
myResourceLinkResolver.validateTypeOrThrowException(type);
resourceLink = ResourceLink.forLocalReference(thePathAndRef.getPath(), theEntity, typeString, resolvedTargetId.getIdAsLong(), targetId, transactionDate, targetVersionId);
resourceLink = ResourceLink.forLocalReference(thePathAndRef.getPath(), theEntity, typeString, ((JpaPid) resolvedTargetId).getId(), targetId, transactionDate, targetVersionId);
} else if (theFailOnInvalidReference) {
@ -498,10 +498,10 @@ public class SearchParamExtractorService {
private ResourceLink resolveTargetAndCreateResourceLinkOrReturnNull(@Nonnull RequestPartitionId theRequestPartitionId, String theSourceResourceName, PathAndRef thePathAndRef, ResourceTable theEntity, Date theUpdateTime, IIdType theNextId, RequestDetails theRequest, TransactionDetails theTransactionDetails) {
assert theRequestPartitionId != null;
ResourcePersistentId resolvedResourceId = theTransactionDetails.getResolvedResourceId(theNextId);
JpaPid resolvedResourceId = (JpaPid) theTransactionDetails.getResolvedResourceId(theNextId);
if (resolvedResourceId != null) {
String targetResourceType = theNextId.getResourceType();
Long targetResourcePid = resolvedResourceId.getIdAsLong();
Long targetResourcePid = resolvedResourceId.getId();
String targetResourceIdPart = theNextId.getIdPart();
Long targetVersion = theNextId.getVersionIdPartAsLong();
return ResourceLink.forLocalReference(thePathAndRef.getPath(), theEntity, targetResourceType, targetResourcePid, targetResourceIdPart, theUpdateTime, targetVersion);
@ -526,7 +526,7 @@ public class SearchParamExtractorService {
}
String targetResourceType = targetResource.getResourceType();
Long targetResourcePid = targetResource.getPersistentId().getIdAsLong();
Long targetResourcePid = ((JpaPid) targetResource.getPersistentId()).getId();
String targetResourceIdPart = theNextId.getIdPart();
Long targetVersion = theNextId.getVersionIdPartAsLong();
return ResourceLink.forLocalReference(thePathAndRef.getPath(), theEntity, targetResourceType, targetResourcePid, targetResourceIdPart, theUpdateTime, targetVersion);

View File

@ -211,8 +211,8 @@ public class SearchCoordinatorSvcImplTest extends BaseSearchSvc{
verify(mySearchCacheSvc, atLeastOnce()).save(searchCaptor.capture());
assertEquals(790, allResults.size());
assertEquals(10, allResults.get(0).getIdAsLong().longValue());
assertEquals(799, allResults.get(789).getIdAsLong().longValue());
assertEquals(10, allResults.get(0).getId());
assertEquals(799, allResults.get(789).getId());
myExpectedNumberOfSearchBuildersCreated = 4;
}

View File

@ -26,6 +26,7 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
@ -154,7 +155,7 @@ public class IdHelperServiceTest {
public void testResolveResourceIdentity_defaultFunctionality(){
RequestPartitionId partitionId = RequestPartitionId.fromPartitionIdAndName(1, "partition");
String resourceType = "Patient";
String resourceForcedId = "AAA";
String resourceForcedId = "123L";
Object[] forcedIdView = new Object[4];
forcedIdView[0] = resourceType;
@ -168,7 +169,7 @@ public class IdHelperServiceTest {
IResourceLookup result = myHelperService.resolveResourceIdentity(partitionId, resourceType, resourceForcedId);
assertEquals(forcedIdView[0], result.getResourceType());
assertEquals(forcedIdView[1], result.getPersistentId().getId());
assertEquals(forcedIdView[1], ((JpaPid) result.getPersistentId()).getId());
assertEquals(forcedIdView[3], result.getDeleted());
}
@ -185,7 +186,8 @@ public class IdHelperServiceTest {
.thenReturn(resourcePersistentId1)
.thenReturn(resourcePersistentId2)
.thenReturn(resourcePersistentId3);
Map<String, ResourcePersistentId> result = myHelperService.resolveResourcePersistentIds(partitionId, resourceType, ids);
Map<String, JpaPid> result = myHelperService.resolveResourcePersistentIds(partitionId, resourceType, ids)
.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> (JpaPid) entry.getValue()));
assertThat(result.keySet(), hasSize(3));
assertEquals(1L, result.get("A").getId());
assertEquals(2L, result.get("B").getId());
@ -199,6 +201,7 @@ public class IdHelperServiceTest {
Long id = 1L;
JpaPid jpaPid1 = new JpaPid(id);
when(myDaoConfig.getResourceClientIdStrategy()).thenReturn(DaoConfig.ClientIdStrategyEnum.ANY);
when(myMemoryCacheService.getThenPutAfterCommit(any(), any(), any())).thenReturn(jpaPid1);
JpaPid result = (JpaPid) myHelperService.resolveResourcePersistentIds(partitionId, resourceType, id.toString());
assertEquals(id, result.getId());

View File

@ -68,7 +68,7 @@ public class FhirSearchDaoR4Test extends BaseJpaR4Test {
// verify results
Assertions.assertEquals(1, ids.size());
Assertions.assertEquals(id1, ids.get(0).getIdAsLong());
Assertions.assertEquals(id1, ids.get(0).getId());
}
@Test

View File

@ -4,8 +4,10 @@ import ca.uhn.fhir.interceptor.api.Pointcut;
import ca.uhn.fhir.jpa.api.config.DaoConfig;
import ca.uhn.fhir.jpa.api.dao.IDao;
import ca.uhn.fhir.jpa.api.svc.IIdHelperService;
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.jpa.provider.BaseResourceProviderR4Test;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
import ca.uhn.fhir.rest.server.provider.ProviderConstants;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBaseResource;
@ -21,6 +23,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -113,7 +116,9 @@ public class HookInterceptorR4Test extends BaseResourceProviderR4Test {
IIdType savedPatientId = myClient.create().resource(new Patient()).execute().getId();
runInTransaction(() -> {
Long savedPatientPid = myIdHelperService.resolveResourcePersistentIdsWithCache(null, Collections.singletonList(savedPatientId)).get(0).getIdAsLong();
List<ResourcePersistentId> pids = myIdHelperService.resolveResourcePersistentIdsWithCache(null,
Collections.singletonList(savedPatientId));
Long savedPatientPid = ((JpaPid) pids.get(0)).getId();
assertEquals(savedPatientPid.longValue(), pid.get());
});
}
@ -128,7 +133,7 @@ public class HookInterceptorR4Test extends BaseResourceProviderR4Test {
pid.set(resourcePid);
});
IIdType savedPatientId = myClient.create().resource(new Patient()).execute().getId();
Long savedPatientPid = runInTransaction(() -> myIdHelperService.resolveResourcePersistentIdsWithCache(null, Collections.singletonList(savedPatientId)).get(0).getIdAsLong());
Long savedPatientPid = runInTransaction(() -> ((JpaPid) myIdHelperService.resolveResourcePersistentIdsWithCache(null, Collections.singletonList(savedPatientId)).get(0)).getId());
myClient.delete().resourceById(savedPatientId).execute();
Parameters parameters = new Parameters();
@ -165,7 +170,7 @@ public class HookInterceptorR4Test extends BaseResourceProviderR4Test {
patient.setActive(true);
myClient.update().resource(patient).execute();
runInTransaction(() -> {
Long savedPatientPid = myIdHelperService.resolveResourcePersistentIdsWithCache(null, Collections.singletonList(savedPatientId)).get(0).getIdAsLong();
Long savedPatientPid = ((JpaPid) myIdHelperService.resolveResourcePersistentIdsWithCache(null, Collections.singletonList(savedPatientId)).get(0)).getId();
assertEquals(savedPatientPid.longValue(), pidOld.get());
assertEquals(savedPatientPid.longValue(), pidNew.get());
});

View File

@ -242,7 +242,7 @@ public class ResourceReindexingSvcImplTest extends BaseJpaTest {
when(myDaoRegistry.getResourceDao(eq("Patient"))).thenReturn(myResourceDao);
when(myDaoRegistry.getResourceDao(eq(Patient.class))).thenReturn(myResourceDao);
when(myResourceDao.readByPid(any(), anyBoolean())).thenAnswer(t->{
int idx = t.getArgument(0, JpaPid.class).getIdAsLong().intValue();
int idx = t.getArgument(0, JpaPid.class).getId().intValue();
return resources.get(idx);
});
@ -350,7 +350,7 @@ public class ResourceReindexingSvcImplTest extends BaseJpaTest {
when(myDaoRegistry.getResourceDao(eq("Observation"))).thenReturn(myResourceDao);
when(myDaoRegistry.getResourceDao(eq(Observation.class))).thenReturn(myResourceDao);
when(myResourceDao.readByPid(any(), anyBoolean())).thenAnswer(t->{
int idx = t.getArgument(0, JpaPid.class).getIdAsLong().intValue();
int idx = t.getArgument(0, JpaPid.class).getId().intValue();
return resources.get(idx);
});
}

View File

@ -96,7 +96,7 @@ public class ResourceVersionSvcTest {
matches.add(getResourceTableRecordForResourceTypeAndPid(
pack.MyResourceId.getResourceType(),
pack.MyPid.getIdAsLong(),
((JpaPid) pack.MyPid).getId(),
pack.MyVersion
));
}

View File

@ -20,6 +20,7 @@ package ca.uhn.fhir.mdm.model;
* #L%
*/
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
public class MdmPidTuple {
@ -45,11 +46,11 @@ public class MdmPidTuple {
}
public Long getGoldenPidAsLong() {
return myGoldenPid.getIdAsLong();
return ((JpaPid) myGoldenPid).getId();
}
public Long getSourcePidAsLong() {
return mySourcePid.getIdAsLong();
return ((JpaPid) myGoldenPid).getId();
}
public String getGoldenPidAsString() {

View File

@ -20,6 +20,7 @@ package ca.uhn.fhir.batch2.jobs.models;
* #L%
*/
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.model.api.IModelJson;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
import com.fasterxml.jackson.annotation.JsonProperty;
@ -77,7 +78,7 @@ public class Id implements IModelJson {
public static Id getIdFromPID(ResourcePersistentId thePID, String theResourceType) {
Id id = new Id();
id.setId(thePID.getId().toString());
id.setId(((JpaPid)thePID).getId().toString());
id.setResourceType(theResourceType);
return id;
}

View File

@ -97,7 +97,7 @@ public class ExpandResourcesStepTest {
ArrayList<IBaseResource> resources = new ArrayList<>();
ArrayList<Id> ids = new ArrayList<>();
for (int i = 0; i < 100; i++) {
String stringId = "Patient/" + i;
String stringId = String.valueOf(i);
Id id = new Id();
id.setResourceType("Patient");
id.setId(stringId);

View File

@ -23,6 +23,7 @@ package ca.uhn.fhir.jpa.dao.expunge;
import ca.uhn.fhir.i18n.Msg;
import ca.uhn.fhir.jpa.api.model.ExpungeOptions;
import ca.uhn.fhir.jpa.api.model.ExpungeOutcome;
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
@ -48,14 +49,15 @@ public class ExpungeService {
}
public ExpungeOutcome expunge(String theResourceName, ResourcePersistentId theResourceId, ExpungeOptions theExpungeOptions, RequestDetails theRequest) {
ourLog.info("Expunge: ResourceName[{}] Id[{}] Version[{}] Options[{}]", theResourceName, theResourceId != null ? theResourceId.getId() : null, theResourceId != null ? theResourceId.getVersion() : null, theExpungeOptions);
ExpungeOperation expungeOperation = getExpungeOperation(theResourceName, theResourceId, theExpungeOptions, theRequest);
JpaPid jpaPid = (JpaPid) theResourceId;
ourLog.info("Expunge: ResourceName[{}] Id[{}] Version[{}] Options[{}]", theResourceName, jpaPid != null ? jpaPid.getId() : null, jpaPid != null ? jpaPid.getVersion() : null, theExpungeOptions);
ExpungeOperation expungeOperation = getExpungeOperation(theResourceName, jpaPid, theExpungeOptions, theRequest);
if (theExpungeOptions.getLimit() < 1) {
throw new InvalidRequestException(Msg.code(1087) + "Expunge limit may not be less than 1. Received expunge limit " + theExpungeOptions.getLimit() + ".");
}
if (theResourceName == null && (theResourceId == null || (theResourceId.getId() == null && theResourceId.getVersion() == null))) {
if (theResourceName == null && (jpaPid == null || (jpaPid.getId() == null && jpaPid.getVersion() == null))) {
if (theExpungeOptions.isExpungeEverything()) {
myExpungeEverythingService.expungeEverything(theRequest);
return new ExpungeOutcome().setDeletedCount(myExpungeEverythingService.getExpungeDeletedEntityCount());

View File

@ -95,10 +95,10 @@ public class DaoResourceLinkResolver implements IResourceLinkResolver {
RuntimeSearchParam searchParam = mySearchParamRegistry.getActiveSearchParam(theSourceResourceName, thePathAndRef.getSearchParamName());
ResourcePersistentId persistentId = null;
JpaPid persistentId = null;
if (theTransactionDetails != null) {
ResourcePersistentId resolvedResourceId = theTransactionDetails.getResolvedResourceId(targetResourceId);
if (resolvedResourceId != null && resolvedResourceId.getIdAsLong() != null && resolvedResourceId.getAssociatedResourceId() != null) {
JpaPid resolvedResourceId = (JpaPid) theTransactionDetails.getResolvedResourceId(targetResourceId);
if (resolvedResourceId != null && resolvedResourceId.getId() != null && resolvedResourceId.getAssociatedResourceId() != null) {
persistentId = resolvedResourceId;
}
}
@ -141,7 +141,8 @@ public class DaoResourceLinkResolver implements IResourceLinkResolver {
}
if (persistentId == null) {
persistentId = new JpaPid((Long) resolvedResource.getPersistentId().getId());
persistentId = ((JpaPid) resolvedResource.getPersistentId());
persistentId = new JpaPid(persistentId.getId());
persistentId.setAssociatedResourceId(targetResourceId);
if (theTransactionDetails != null) {
theTransactionDetails.addResolvedResourceId(targetResourceId, persistentId);
@ -184,7 +185,8 @@ public class DaoResourceLinkResolver implements IResourceLinkResolver {
valueOf = placeholderResourceDao.create(newResource, theRequest).getEntity();
}
JpaPid persistentId = new JpaPid((Long) valueOf.getPersistentId().getId(), 1L);
JpaPid persistentId = (JpaPid) valueOf.getPersistentId();
persistentId = new JpaPid(persistentId.getId(), 1L);
persistentId.setAssociatedResourceId(valueOf.getIdDt());
theTransactionDetails.addResolvedResourceId(persistentId.getAssociatedResourceId(), persistentId);
}