@Override public String toString() { ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); b.append("resPid", myResource.getIdDt().toUnqualifiedVersionless().getValue()); b.append("paramName", myParamName); b.append("present", myPresent); return b.build(); }
protected void validateOkToDelete(List<DeleteConflict> theDeleteConflicts, ResourceTable theEntity, boolean theForValidate) { TypedQuery<ResourceLink> query = myEntityManager.createQuery("SELECT l FROM ResourceLink l WHERE l.myTargetResourcePid = :target_pid", ResourceLink.class); query.setParameter("target_pid", theEntity.getId()); query.setMaxResults(1); List<ResourceLink> resultList = query.getResultList(); if (resultList.isEmpty()) { return; } if (myDaoConfig.isEnforceReferentialIntegrityOnDelete() == false && !theForValidate) { ourLog.debug("Deleting {} resource dependencies which can no longer be satisfied", resultList.size()); myResourceLinkDao.deleteAll(resultList); return; } ResourceLink link = resultList.get(0); IdDt targetId = theEntity.getIdDt(); IdDt sourceId = link.getSourceResource().getIdDt(); String sourcePath = link.getSourcePath(); theDeleteConflicts.add(new DeleteConflict(sourceId, sourcePath, targetId)); }
@Override protected ResourceTable updateEntity(RequestDetails theRequest, IBaseResource theResource, ResourceTable theEntity, Date theDeletedTimestampOrNull, boolean thePerformIndexing, boolean theUpdateVersion, Date theUpdateTime, boolean theForceUpdate, boolean theCreateNewHistoryEntry) { ResourceTable retVal = super.updateEntity(theRequest, theResource, theEntity, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theUpdateTime, theForceUpdate, theCreateNewHistoryEntry); if (theDeletedTimestampOrNull != null) { Long subscriptionId = getSubscriptionTablePidForSubscriptionResource(theEntity.getIdDt()); if (subscriptionId != null) { mySubscriptionTableDao.deleteAllForSubscription(retVal); } } return retVal; }
protected void expungeHistoricalVersionsOfId(Long theResourceId, AtomicInteger theRemainingCount) { ResourceTable resource = myResourceTableDao.findById(theResourceId).orElseThrow(IllegalArgumentException::new); Pageable page = PageRequest.of(0, theRemainingCount.get()); Slice<Long> versionIds = myResourceHistoryTableDao.findForResourceId(page, resource.getId(), resource.getVersion()); ourLog.debug("Found {} versions of resource {} to expunge", versionIds.getNumberOfElements(), resource.getIdDt().getValue()); for (Long nextVersionId : versionIds) { expungeHistoricalVersion(nextVersionId); if (theRemainingCount.decrementAndGet() <= 0) { return; } } }
@Override public void reindex(T theResource, ResourceTable theEntity) { ourLog.debug("Indexing resource {} - PID {}", theEntity.getIdDt().getValue(), theEntity.getId()); if (theResource != null) { CURRENTLY_REINDEXING.put(theResource, Boolean.TRUE); } updateEntity(null, theResource, theEntity, theEntity.getDeleted(), true, false, theEntity.getUpdatedDate(), true, false); if (theResource != null) { CURRENTLY_REINDEXING.put(theResource, null); } }
private boolean resourceIdMatches(ResourceLink theResourceLink, ReferenceParam theReference) { ResourceTable target = theResourceLink.getTargetResource(); IdDt idDt = target.getIdDt(); if (idDt.isIdPartValidLong()) { return theReference.getIdPartAsLong() == idDt.getIdPartAsLong(); } else { ForcedId forcedId = target.getForcedId(); if (forcedId != null) { return forcedId.getForcedId().equals(theReference.getValue()); } else { return false; } } }
public void storeCompositeStringUniques(ResourceIndexedSearchParams theParams, ResourceTable theEntity, ResourceIndexedSearchParams existingParams) { // Store composite string uniques if (myDaoConfig.isUniqueIndexesEnabled()) { for (ResourceIndexedCompositeStringUnique next : myDaoSearchParamSynchronizer.subtract(existingParams.compositeStringUniques, theParams.compositeStringUniques)) { ourLog.debug("Removing unique index: {}", next); myEntityManager.remove(next); theEntity.getParamsCompositeStringUnique().remove(next); } for (ResourceIndexedCompositeStringUnique next : myDaoSearchParamSynchronizer.subtract(theParams.compositeStringUniques, existingParams.compositeStringUniques)) { if (myDaoConfig.isUniqueIndexesCheckedBeforeSave()) { ResourceIndexedCompositeStringUnique existing = myResourceIndexedCompositeStringUniqueDao.findByQueryString(next.getIndexString()); if (existing != null) { String msg = myContext.getLocalizer().getMessage(BaseHapiFhirDao.class, "uniqueIndexConflictFailure", theEntity.getResourceType(), next.getIndexString(), existing.getResource().getIdDt().toUnqualifiedVersionless().getValue()); throw new PreconditionFailedException(msg); } } ourLog.debug("Persisting unique index: {}", next); myEntityManager.persist(next); } } } }
for (ResourceLink nextLink : linksForCompositePart) { if (linksForCompositePartWantPaths.contains(nextLink.getSourcePath())) { String value = nextLink.getTargetResource().getIdDt().toUnqualifiedVersionless().getValue(); if (isNotBlank(value)) { value = UrlUtil.escapeUrlParam(value);
@Override protected ResourceTable updateEntity(RequestDetails theRequest, IBaseResource theResource, ResourceTable theEntity, Date theDeletedTimestampOrNull, boolean thePerformIndexing, boolean theUpdateVersion, Date theUpdateTime, boolean theForceUpdate, boolean theCreateNewHistoryEntry) { ResourceTable retVal = super.updateEntity(theRequest, theResource, theEntity, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theUpdateTime, theForceUpdate, theCreateNewHistoryEntry); CodeSystem cs = (CodeSystem) theResource; if (cs != null && isNotBlank(cs.getUrl())) { String codeSystemUrl = cs.getUrl(); if (cs.getContent() == CodeSystemContentMode.COMPLETE || cs.getContent() == null) { ourLog.info("CodeSystem {} has a status of {}, going to store concepts in terminology tables", retVal.getIdDt().getValue(), cs.getContentElement().getValueAsString()); Long codeSystemResourcePid = retVal.getId(); TermCodeSystemVersion persCs = myCsvDao.findCurrentVersionForCodeSystemResourcePid(codeSystemResourcePid); if (persCs != null) { ourLog.info("Code system version already exists in database"); } else { persCs = new TermCodeSystemVersion(); persCs.setResource(retVal); persCs.getConcepts().addAll(toPersistedConcepts(cs.getConcept(), persCs)); ourLog.info("Code system has {} concepts", persCs.getConcepts().size()); myTerminologySvc.storeNewCodeSystemVersion(codeSystemResourcePid, codeSystemUrl, cs.getName(), persCs); } } } return retVal; }
@Override protected ResourceTable updateEntity(RequestDetails theRequest, IBaseResource theResource, ResourceTable theEntity, Date theDeletedTimestampOrNull, boolean thePerformIndexing, boolean theUpdateVersion, Date theUpdateTime, boolean theForceUpdate, boolean theCreateNewHistoryEntry) { ResourceTable retVal = super.updateEntity(theRequest, theResource, theEntity, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theUpdateTime, theForceUpdate, theCreateNewHistoryEntry); CodeSystem cs = (CodeSystem) theResource; if (cs != null && isNotBlank(cs.getUrl())) { String codeSystemUrl = cs.getUrl(); Long codeSystemResourcePid = retVal.getId(); if (retVal.getDeleted() != null) { // deleting } else if (cs.getContent() == CodeSystemContentMode.COMPLETE || cs.getContent() == null) { ourLog.info("CodeSystem {} has a status of {}, going to store concepts in terminology tables", retVal.getIdDt().getValue(), cs.getContentElement().getValueAsString()); TermCodeSystemVersion persCs = new TermCodeSystemVersion(); persCs.setResource(retVal); persCs.getConcepts().addAll(toPersistedConcepts(cs.getConcept(), persCs)); ourLog.info("Code system has {} concepts", persCs.getConcepts().size()); myTerminologySvc.storeNewCodeSystemVersion(codeSystemResourcePid, codeSystemUrl, cs.getName(), persCs); } } return retVal; }
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"); ourLog.error("Failed to index resource {}: {}", resourceTable.getIdDt(), e.toString(), e); t.setRollbackOnly(); return e;
if (!ObjectUtil.equals(codeSystem.getResource().getId(), theCodeSystemVersion.getResource().getId())) { String msg = myContext.getLocalizer().getMessage(BaseHapiTerminologySvcImpl.class, "cannotCreateDuplicateCodeSystemUri", theSystemUri, codeSystem.getResource().getIdDt().toUnqualifiedVersionless().getValue()); throw new UnprocessableEntityException(msg);
private DaoMethodOutcome toMethodOutcome(@Nonnull final ResourceTable theEntity, @Nonnull IBaseResource theResource) { DaoMethodOutcome outcome = new DaoMethodOutcome(); IIdType id = null; if (theResource.getIdElement().getValue() != null) { id = theResource.getIdElement(); } if (id == null) { id = theEntity.getIdDt(); if (getContext().getVersion().getVersion().isRi()) { id = getContext().getVersion().newIdType().setValue(id.getValue()); } } outcome.setId(id); outcome.setResource(theResource); outcome.setEntity(theEntity); return outcome; }
Long pid = match.iterator().next(); entity = myEntityManager.find(ResourceTable.class, pid); resourceId = entity.getIdDt(); } else { return create(theResource, null, thePerformIndexing, new Date(), theRequestDetails); "Invalid resource ID[" + entity.getIdDt().toUnqualifiedVersionless() + "] of type[" + entity.getResourceType() + "] - Does not match expected [" + getResourceName() + "]"); theResource.setId(entity.getIdDt().getValue()); DaoMethodOutcome outcome = toMethodOutcome(entity, theResource).setCreated(false); outcome.setPreviousResource(oldResource);
private void expungeCurrentVersionOfResource(Long theResourceId, AtomicInteger theRemainingCount) { ResourceTable resource = myResourceTableDao.findById(theResourceId).orElseThrow(IllegalStateException::new); ResourceHistoryTable currentVersion = myResourceHistoryTableDao.findForIdAndVersion(resource.getId(), resource.getVersion()); if (currentVersion != null) { expungeHistoricalVersion(currentVersion.getId()); } ourLog.info("Expunging current version of resource {}", resource.getIdDt().getValue()); myResourceIndexedSearchParamUriDao.deleteAll(resource.getParamsUri()); myResourceIndexedSearchParamCoordsDao.deleteAll(resource.getParamsCoords()); myResourceIndexedSearchParamDateDao.deleteAll(resource.getParamsDate()); myResourceIndexedSearchParamNumberDao.deleteAll(resource.getParamsNumber()); myResourceIndexedSearchParamQuantityDao.deleteAll(resource.getParamsQuantity()); myResourceIndexedSearchParamStringDao.deleteAll(resource.getParamsString()); myResourceIndexedSearchParamTokenDao.deleteAll(resource.getParamsToken()); myResourceLinkDao.deleteAll(resource.getResourceLinks()); myResourceLinkDao.deleteAll(resource.getResourceLinksAsTarget()); myResourceTagDao.deleteAll(resource.getTags()); resource.getTags().clear(); if (resource.getForcedId() != null) { ForcedId forcedId = resource.getForcedId(); resource.setForcedId(null); myResourceTableDao.saveAndFlush(resource); myIdHelperService.delete(forcedId); } myResourceTableDao.delete(resource); theRemainingCount.decrementAndGet(); }
"cannotCreateDuplicateConceptMapUrl", conceptMapUrl, existingTermConceptMap.getResource().getIdDt().toUnqualifiedVersionless().getValue());
theResource.setId(entity.getIdDt()); if (serverAssignedId) { switch (myDaoConfig.getResourceClientIdStrategy()) {