@Override public IPatchExecutable withId(IIdType theId) { if (theId == null) { throw new NullPointerException("theId can not be null"); } if (theId.hasIdPart() == false) { throw new NullPointerException("theId must not be blank and must contain an ID, found: " + theId.getValue()); } myId = theId; return this; }
@Override public IUpdateExecutable withId(IIdType theId) { if (theId == null) { throw new NullPointerException("theId can not be null"); } if (theId.hasIdPart() == false) { throw new NullPointerException("theId must not be blank and must contain an ID, found: " + 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; }
@Override public IDeleteTyped resource(IBaseResource theResource) { Validate.notNull(theResource, "theResource can not be null"); IIdType id = theResource.getIdElement(); Validate.notNull(id, "theResource.getIdElement() can not be null"); if (id.hasResourceType() == false || id.hasIdPart() == false) { throw new IllegalArgumentException("theResource.getId() must contain a resource type and logical ID at a minimum (e.g. Patient/1234), found: " + id.getValue()); } myId = id; return this; }
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(); }
public static IIdType fullyQualifyResourceIdOrReturnNull(IRestfulServerDefaults theServer, IBaseResource theResource, String theServerBase, IIdType theResourceId) { IIdType retVal = null; if (theResourceId.hasIdPart() && isNotBlank(theServerBase)) { String resName = theResourceId.getResourceType(); if (theResource != null && isBlank(resName)) { FhirContext context = theServer.getFhirContext(); context = getContextForVersion(context, theResource.getStructureFhirVersionEnum()); resName = context.getResourceDefinition(theResource).getName(); } if (isNotBlank(resName)) { retVal = theResourceId.withServerBase(theServerBase, resName); } } return retVal; }
/** * Returns the <b>conditional URL</b> if this request has one, or <code>null</code> otherwise. For an * update or delete method, this is the part of the URL after the <code>?</code>. For a create, this * is the value of the <code>If-None-Exist</code> header. * * @param theOperationType The operation type to find the conditional URL for * @return Returns the <b>conditional URL</b> if this request has one, or <code>null</code> otherwise */ public String getConditionalUrl(RestOperationTypeEnum theOperationType) { if (theOperationType == RestOperationTypeEnum.CREATE) { String retVal = this.getHeader(Constants.HEADER_IF_NONE_EXIST); if (isBlank(retVal)) { return null; } if (retVal.startsWith(this.getFhirServerBase())) { retVal = retVal.substring(this.getFhirServerBase().length()); } return retVal; } else if (theOperationType != RestOperationTypeEnum.DELETE && theOperationType != RestOperationTypeEnum.UPDATE) { return null; } if (this.getId() != null && this.getId().hasIdPart()) { return null; } int questionMarkIndex = this.getCompleteUrl().indexOf('?'); if (questionMarkIndex == -1) { return null; } return this.getResourceName() + this.getCompleteUrl().substring(questionMarkIndex); }
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 MethodOutcome execute() { if (myPatchType == null) { throw new InvalidRequestException("No patch type supplied, cannot invoke server"); } if (myPatchBody == null) { throw new InvalidRequestException("No patch body supplied, cannot invoke server"); } BaseHttpClientInvocation invocation; if (isNotBlank(mySearchUrl)) { invocation = MethodUtil.createPatchInvocation(myContext, mySearchUrl, myPatchType, myPatchBody); } else if (myConditional) { invocation = MethodUtil.createPatchInvocation(myContext, myPatchType, myPatchBody, myResourceType, getParamMap()); } else { if (myId == null || myId.hasIdPart() == false) { throw new InvalidRequestException("No ID supplied for resource to patch, can not invoke server"); } invocation = MethodUtil.createPatchInvocation(myContext, myId, myPatchType, myPatchBody); } addPreferHeader(myPrefer, invocation); OutcomeResponseHandler binding = new OutcomeResponseHandler(myPrefer); Map<String, List<String>> params = new HashMap<>(); return invoke(params, binding, invocation); }
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()); } } }
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()); } }
@Override public MethodOutcome execute() { if (myResource == null) { myResource = parseResourceBody(myResourceBody); } // If an explicit encoding is chosen, we will re-serialize to ensure the right encoding if (getParamEncoding() != null) { myResourceBody = null; } BaseHttpClientInvocation invocation; if (mySearchUrl != null) { invocation = MethodUtil.createUpdateInvocation(myContext, myResource, myResourceBody, mySearchUrl); } else if (myConditional) { invocation = MethodUtil.createUpdateInvocation(myContext, myResource, myResourceBody, getParamMap()); } else { if (myId == null) { myId = myResource.getIdElement(); } if (myId == null || myId.hasIdPart() == false) { throw new InvalidRequestException("No ID supplied for resource to update, can not invoke server"); } invocation = MethodUtil.createUpdateInvocation(myResource, myResourceBody, myId, myContext); } addPreferHeader(myPrefer, invocation); OutcomeResponseHandler binding = new OutcomeResponseHandler(myPrefer); Map<String, List<String>> params = new HashMap<String, List<String>>(); return invoke(params, binding, invocation); }
private IIdType populateBundleEntryFullUrl(IBaseResource next, BundleEntryComponent entry) { IIdType idElement = null; if (next.getIdElement().hasBaseUrl()) { idElement = next.getIdElement(); entry.setFullUrl(idElement.toVersionless().getValue()); } else { if (isNotBlank(myBase) && next.getIdElement().hasIdPart()) { idElement = next.getIdElement(); idElement = idElement.withServerBase(myBase, myContext.getResourceDefinition(next).getName()); entry.setFullUrl(idElement.toVersionless().getValue()); } } return idElement; }
private IIdType populateBundleEntryFullUrl(IBaseResource next, BundleEntryComponent entry) { IIdType idElement = null; if (next.getIdElement().hasBaseUrl()) { idElement = next.getIdElement(); entry.setFullUrl(idElement.toVersionless().getValue()); } else { if (isNotBlank(myBase) && next.getIdElement().hasIdPart()) { idElement = next.getIdElement(); idElement = idElement.withServerBase(myBase, myContext.getResourceDefinition(next).getName()); entry.setFullUrl(idElement.toVersionless().getValue()); } } return idElement; }
/** * Returns the newly created forced ID. If the entity already had a forced ID, or if * none was created, returns null. */ protected ForcedId createForcedIdIfNeeded(ResourceTable theEntity, IIdType theId, boolean theCreateForPureNumericIds) { if (theId.isEmpty() == false && theId.hasIdPart() && theEntity.getForcedId() == null) { if (!theCreateForPureNumericIds && IdHelperService.isValidPid(theId)) { return null; } ForcedId fid = new ForcedId(); fid.setResourceType(theEntity.getResourceType()); fid.setForcedId(theId.getIdPart()); fid.setResource(theEntity); theEntity.setForcedId(fid); return fid; } return null; }
if (theResource.getIdElement().hasIdPart()) { if (!theResource.getIdElement().isIdPartValid()) { throw new InvalidRequestException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithInvalidId", theResource.getIdElement().getIdPart()));
if (theId == null || theId.hasIdPart() == false) { throw new InvalidRequestException("No ID supplied. ID is required when validating with mode=DELETE"); if (theId != null && theId.hasResourceType() && theId.hasIdPart()) { Class<? extends IBaseResource> type = getContext().getResourceDefinition(theId.getResourceType()).getImplementingClass(); IFhirResourceDao<? extends IBaseResource> dao = getDao(type);
if (theId == null || theId.hasIdPart() == false) { throw new InvalidRequestException("No ID supplied. ID is required when validating with mode=DELETE"); if (theId != null && theId.hasResourceType() && theId.hasIdPart()) { Class<? extends IBaseResource> type = getContext().getResourceDefinition(theId.getResourceType()).getImplementingClass(); IFhirResourceDao<? extends IBaseResource> dao = getDao(type);
IIdType refId = theRef.getResource().getIdElement(); if (refId != null) { if (refId.hasIdPart()) { if (refId.getValue().startsWith("urn:")) { reference = refId.getValue();
if (theId == null || theId.hasIdPart() == false) { throw new InvalidRequestException("No ID supplied. ID is required when validating with mode=DELETE");