private void populateBundleEntryFullUrl(IBaseResource next, BundleEntryComponent entry) { if (next.getIdElement().hasBaseUrl()) { entry.setFullUrl(next.getIdElement().toVersionless().getValue()); } else { if (isNotBlank(myBase) && next.getIdElement().hasIdPart()) { IIdType id = next.getIdElement().toVersionless(); id = id.withServerBase(myBase, myContext.getResourceDefinition(next).getName()); entry.setFullUrl(id.getValue()); } } }
public void setTargetResourceUrl(IIdType theTargetResourceUrl) { Validate.isTrue(theTargetResourceUrl.hasBaseUrl()); Validate.isTrue(theTargetResourceUrl.hasResourceType()); if (theTargetResourceUrl.hasIdPart()) { // do nothing } else { // Must have set an url like http://example.org/something // We treat 'something' as the resource type because of fix for #659. Prior to #659 fix, 'something' was // treated as the id and 'example.org' was treated as the resource type // TODO: log a warning? } myTargetResourceType = theTargetResourceUrl.getResourceType(); myTargetResourceUrl = theTargetResourceUrl.getValue(); }
private String determineReferenceText(IBaseReference theRef, CompositeChildElement theCompositeChildElement) { IIdType ref = theRef.getReferenceElement(); if (isBlank(ref.getIdPart())) { String reference = ref.getValue(); if (theRef.getResource() != null) { IIdType containedId = getContainedResources().getResourceId(theRef.getResource()); if (containedId != null && !containedId.isEmpty()) { if (containedId.isLocal()) { reference = containedId.getValue(); } else { reference = "#" + containedId.getValue(); if (refId.hasIdPart()) { if (refId.getValue().startsWith("urn:")) { reference = refId.getValue(); } else { if (!refId.hasResourceType()) { refId = refId.withResourceType(myContext.getResourceDefinition(theRef.getResource()).getName()); reference = refId.toVersionless().getValue(); } else { reference = refId.getValue(); if (!ref.hasResourceType() && !ref.isLocal() && theRef.getResource() != null) { ref = ref.withResourceType(myContext.getResourceDefinition(theRef.getResource()).getName()); if (isNotBlank(myServerBaseUrl) && StringUtils.equals(myServerBaseUrl, ref.getBaseUrl())) { if (isStripVersionsFromReferences(theCompositeChildElement)) { return ref.toUnqualifiedVersionless().getValue();
public HttpPatchClientInvocation(FhirContext theContext, IIdType theId, String theContentType, String theContents) { super(theContext); myUrlPath = theId.toUnqualifiedVersionless().getValue(); myContentType = theContentType; myContents = theContents; }
@Override public IHistoryUntyped onInstance(IIdType theId) { if (theId.hasResourceType() == false) { throw new IllegalArgumentException("Resource ID does not have a resource type: " + theId.getValue()); } myId = theId; return this; }
@Override public IDeleteTyped resourceById(IIdType theId) { Validate.notNull(theId, "theId can not be null"); if (theId.hasResourceType() == false || theId.hasIdPart() == false) { throw new IllegalArgumentException("theId must contain a resource type and logical ID at a minimum (e.g. Patient/1234)found: " + theId.getValue()); } myId = theId; return this; }
if (next.getIdElement().isEmpty() == false) { addedResourceIds.add(next.getIdElement()); Set<String> containedIds = new HashSet<String>(); for (IBaseResource nextContained : next.getContained()) { if (nextContained.getIdElement().isEmpty() == false) { containedIds.add(nextContained.getIdElement().getValue()); IBaseResource nextRes = (IBaseResource) nextRef.getResource(); if (nextRes != null) { if (nextRes.getIdElement().hasIdPart()) { if (containedIds.contains(nextRes.getIdElement().getValue())) { if (id.hasResourceType() == false) { String resName = myContext.getResourceDefinition(nextRes).getName(); id = id.withResourceType(resName);
private void filterBundle(org.hl7.fhir.dstu3.model.Bundle theBundle) { for (Iterator<BundleEntryComponent> iter = theBundle.getEntry().iterator(); iter.hasNext(); ) { IBaseResource next = iter.next().getResource(); for (IIdType nextExclude : myExcludes) { if (nextExclude.hasResourceType() && nextExclude.toUnqualifiedVersionless().getValue().equals(next.getIdElement().toUnqualifiedVersionless().getValue())) { iter.remove(); continue; } else if (nextExclude.getIdPart().equals(next.getIdElement().getIdPart())) { iter.remove(); continue; } } } }
if (theResource.getIdElement().hasIdPart()) { if (!theResource.getIdElement().isIdPartValid()) { throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithInvalidId", theResource.getIdElement().getIdPart())); for (ResourceReferenceInfo nextRef : refs) { IIdType refId = nextRef.getResourceReference().getReferenceElement(); if (refId != null && refId.hasBaseUrl()) { if (getConfig().getTreatBaseUrlsAsLocal().contains(refId.getBaseUrl())) { IIdType newRefId = refId.toUnqualified(); nextRef.getResourceReference().setReference(newRefId.getValue());
if (nextId.isEmpty() && nextValue.getResource() != null) { nextId = nextValue.getResource().getIdElement(); if (nextId.isEmpty() || nextId.getValue().startsWith("#")) { if (nextId == null || nextId.hasIdPart() == false) { return; String baseUrl = nextId.getBaseUrl(); String typeString = nextId.getResourceType(); if (isBlank(typeString)) { String msg = "Invalid resource reference found at path[" + theNextPathsUnsplit + "] - Does not contain resource type - " + nextId.getValue(); if (theFailOnInvalidReference) { throw new InvalidRequestException(msg); resourceDefinition = myContext.getResourceDefinition(typeString); } catch (DataFormatException e) { String msg = "Invalid resource reference found at path[" + theNextPathsUnsplit + "] - Resource type is unknown or not supported on this server - " + nextId.getValue(); if (theFailOnInvalidReference) { throw new InvalidRequestException(msg); String msg = myContext.getLocalizer().getMessage(BaseSearchParamExtractor.class, "externalReferenceNotAllowed", nextId.getValue()); throw new InvalidRequestException(msg); } else { String id = nextId.getIdPart(); if (StringUtils.isBlank(id)) { String msg = "Invalid resource reference found at path[" + theNextPathsUnsplit + "] - Does not contain resource ID - " + nextId.getValue(); if (theFailOnInvalidReference) {
case VREAD: appliesToResourceId = Collections.singleton(theInputResourceId); appliesToResourceType = theInputResourceId.getResourceType(); break; case SEARCH_SYSTEM: QualifiedParamList orParamList = QualifiedParamList.splitQueryStringByCommasIgnoreEscape(null, nextIdValue); for (String next : orParamList) { IIdType nextId = ctx.getVersion().newIdType().setValue(next); if (nextId.hasIdPart()) { if (!nextId.hasResourceType()) { nextId = nextId.withResourceType(appliesToResourceType); if (nextId.getResourceType().equals(appliesToResourceType)) { appliesToResourceId.add(nextId); if (isNotBlank(next.getResourceType())) { if (!next.getResourceType().equals(requestAppliesToResource.getResourceType())) { continue; if (!next.getIdPart().equals(requestAppliesToResource.getIdPart())) { continue; if (nextRequestAppliesToResourceId.hasResourceType()) { Class<? extends IBaseResource> type = theRequestDetails.getServer().getFhirContext().getResourceDefinition(nextRequestAppliesToResourceId.getResourceType()).getImplementingClass(); if (myAppliesToTypes.contains(type) == false) { return null; boolean haveOwnersForAll = appliesToResourceId
protected void updateResourceMetadata(IBaseResourceEntity theEntity, IBaseResource theResource) { IIdType id = theEntity.getIdDt(); if (getContext().getVersion().getVersion().isRi()) { id = getContext().getVersion().newIdType().setValue(id.getValue()); } if (id.hasResourceType() == false) { id = id.withResourceType(theEntity.getResourceType()); } theResource.setId(id); if (theResource instanceof IResource) { ResourceMetadataKeyEnum.VERSION.put((IResource) theResource, id.getVersionIdPart()); ResourceMetadataKeyEnum.UPDATED.put((IResource) theResource, theEntity.getUpdated()); } else { IBaseMetaType meta = theResource.getMeta(); meta.setVersionId(id.getVersionIdPart()); meta.setLastUpdated(theEntity.getUpdatedDate()); } }
private static void copy(FhirContext theCtx, IGenericClient theTarget, String theResType, List<IBaseResource> theQueued, Set<String> theSent, Bundle theReceived) { for (Bundle.BundleEntryComponent nextEntry : theReceived.getEntry()) { Resource nextResource = nextEntry.getResource(); nextResource.setId(theResType + "/" + "CR-" + nextResource.getIdElement().getIdPart()); boolean haveUnsentReference = false; for (ResourceReferenceInfo nextRefInfo : theCtx.newTerser().getAllResourceReferences(nextResource)) { IIdType nextRef = nextRefInfo.getResourceReference().getReferenceElement(); if (nextRef.hasIdPart()) { String newRef = nextRef.getResourceType() + "/" + "CR-" + nextRef.getIdPart(); ourLog.info("Changing reference {} to {}", nextRef.getValue(), newRef); nextRefInfo.getResourceReference().setReference(newRef); if (!theSent.contains(newRef)) { haveUnsentReference = true; } } } if (haveUnsentReference) { ourLog.info("Queueing {} for delivery after", nextResource.getId()); theQueued.add(nextResource); continue; } IIdType newId = theTarget .update() .resource(nextResource) .execute() .getId(); ourLog.info("Copied resource {} and got ID {}", nextResource.getId(), newId); theSent.add(nextResource.getIdElement().toUnqualifiedVersionless().getValue()); } }
IIdType id = theRequest.getId(); if (isNotBlank(locationHeader)) { id.setValue(locationHeader); if (isNotBlank(id.getResourceType())) { if (!getResourceName().equals(id.getResourceType())) { throw new InvalidRequestException( "Attempting to update '" + getResourceName() + "' but content-location header specifies different resource type '" + id.getResourceType() + "' - header value: " + locationHeader); if (theRequest.getId() != null && theRequest.getId().hasVersionIdPart() == false) { if (id != null && id.hasVersionIdPart()) { theRequest.getId().setValue(id.getValue()); MethodOutcome mo = new MethodOutcome(); parseContentLocation(getContext(), mo, locationHeader); if (mo.getId() == null || mo.getId().isEmpty()) { throw new InvalidRequestException("Invalid Content-Location header for resource " + getResourceName() + ": " + locationHeader);
@Override public MethodOutcome invokeClient(String theResponseMimeType, InputStream theResponseInputStream, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws BaseServerResponseException { MethodOutcome response = MethodUtil.process2xxResponse(myContext, theResponseStatusCode, theResponseMimeType, theResponseInputStream, theHeaders); response.setCreatedUsingStatusCode(theResponseStatusCode); if (myPrefer == PreferReturnEnum.REPRESENTATION) { if (response.getResource() == null) { if (response.getId() != null && isNotBlank(response.getId().getValue()) && response.getId().hasBaseUrl()) { ourLog.info("Server did not return resource for Prefer-representation, going to fetch: {}", response.getId().getValue()); IBaseResource resource = read().resource(response.getId().getResourceType()).withUrl(response.getId()).execute(); response.setResource(resource); } } } response.setResponseHeaders(theHeaders); return response; } }
static List<Long> translateForcedIdToPids(DaoConfig theDaoConfig, IIdType theId, IForcedIdDao theForcedIdDao) { Validate.isTrue(theId.hasIdPart()); if (theDaoConfig.getResourceClientIdStrategy() != DaoConfig.ClientIdStrategyEnum.ANY && isValidPid(theId)) { return Collections.singletonList(theId.getIdPartAsLong()); } else { List<ForcedId> forcedId; if (theId.hasResourceType()) { forcedId = theForcedIdDao.findByTypeAndForcedId(theId.getResourceType(), theId.getIdPart()); } else { forcedId = theForcedIdDao.findByForcedId(theId.getIdPart()); } if (!forcedId.isEmpty()) { List<Long> retVal = new ArrayList<>(forcedId.size()); for (ForcedId next : forcedId) { retVal.add(next.getResourcePid()); } return retVal; } else { throw new ResourceNotFoundException(theId); } } }
@Override public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException { IIdType idDt = (IIdType) theArgs[getIdParameterIndex()]; if (idDt == null) { throw new NullPointerException("ID can not be null"); } if (idDt.hasResourceType() == false) { idDt = idDt.withResourceType(getResourceName()); } else if (getResourceName().equals(idDt.getResourceType()) == false) { throw new InvalidRequestException("ID parameter has the wrong resource type, expected '" + getResourceName() + "', found: " + idDt.getResourceType()); } HttpDeleteClientInvocation retVal = createDeleteInvocation(getContext(), idDt); for (int idx = 0; idx < theArgs.length; idx++) { IParameter nextParam = getParameters().get(idx); nextParam.translateClientArgumentIntoQueryArgument(getContext(), theArgs[idx], null, null); } return retVal; }
IFhirResourceDao<?> subscriptionDao = myDaoRegistry.getSubscriptionDao(); IIdType subscriptionId = theSubscriptionId; if (!subscriptionId.hasResourceType()) { subscriptionId = subscriptionId.withResourceType(ResourceTypeEnum.SUBSCRIPTION.getCode()); jobDetails.setRemainingSearchUrls(searchUrls.stream().map(StringParam::getValue).collect(Collectors.toList())); if (theSubscriptionId != null) { jobDetails.setSubscriptionId(theSubscriptionId.toUnqualifiedVersionless().getValue());
/** * Constructor which creates an error message based on a given resource ID * * @param theResourceId The ID of the resource that could not be found */ public ResourceGoneException(IIdType theResourceId) { super(STATUS_CODE, "Resource " + (theResourceId != null ? theResourceId.getValue() : "") + " is gone/deleted"); }
if (next.getIdElement().isEmpty()) { nextEntry.getRequest().setMethod(HTTPVerb.POST); } else { nextEntry.getRequest().setMethod(HTTPVerb.PUT); if (next.getIdElement().isAbsolute()) { nextEntry.getRequest().setUrl(next.getIdElement().getValue()); } else { String resourceType = myContext.getResourceDefinition(next).getName(); nextEntry.getRequest().setUrl(new IdType(theServerBase, resourceType, next.getIdElement().getIdPart(), next.getIdElement().getVersionIdPart()).getValue());