private void addLocationHeader(RequestDetails theRequest, HttpServletResponse theResponse, MethodOutcome response, String headerLocation, String resourceName) { StringBuilder b = new StringBuilder(); b.append(theRequest.getFhirServerBase()); b.append('/'); b.append(resourceName); b.append('/'); b.append(response.getId().getIdPart()); if (response.getId().hasVersionIdPart()) { b.append("/" + Constants.PARAM_HISTORY + "/"); b.append(response.getId().getVersionIdPart()); } theResponse.addHeader(headerLocation, b.toString()); }
void incrementId(T theResource, ResourceTable theSavedEntity, IIdType theResourceId) { String newVersion; long newVersionLong; if (theResourceId == null || theResourceId.getVersionIdPart() == null) { newVersion = "1"; newVersionLong = 1; } else { newVersionLong = theResourceId.getVersionIdPartAsLong() + 1; newVersion = Long.toString(newVersionLong); } IIdType newId = theResourceId.withVersion(newVersion); theResource.getIdElement().setValue(newId.getValue()); theSavedEntity.setVersion(newVersionLong); }
public static HttpPutClientInvocation createUpdateInvocation(IBaseResource theResource, String theResourceBody, IIdType theId, FhirContext theContext) { String resourceName = theContext.getResourceDefinition(theResource).getName(); StringBuilder urlBuilder = new StringBuilder(); urlBuilder.append(resourceName); urlBuilder.append('/'); urlBuilder.append(theId.getIdPart()); String urlExtension = urlBuilder.toString(); HttpPutClientInvocation retVal; if (StringUtils.isBlank(theResourceBody)) { retVal = new HttpPutClientInvocation(theContext, theResource, urlExtension); } else { retVal = new HttpPutClientInvocation(theContext, theResourceBody, false, urlExtension); } retVal.setForceResourceId(theId); if (theId.hasVersionIdPart()) { retVal.addHeader(Constants.HEADER_IF_MATCH, '"' + theId.getVersionIdPart() + '"'); } return retVal; }
throw new ResourceNotFoundException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "invalidVersion", theId.getVersionIdPart(), theId.toUnqualifiedVersionless())); entity = q.getSingleResult(); } catch (NoResultException e) { throw new ResourceNotFoundException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "invalidVersion", theId.getVersionIdPart(), theId.toUnqualifiedVersionless()));
public static HttpGetClientInvocation createVReadInvocation(FhirContext theContext, IIdType theId, String theResourceName) { return new HttpGetClientInvocation(theContext, new IdDt(theResourceName, theId.getIdPart(), theId.getVersionIdPart()).getValue()); }
@Override public DaoMethodOutcome patch(IIdType theId, PatchTypeEnum thePatchType, String thePatchBody, RequestDetails theRequestDetails) { ResourceTable entityToUpdate = readEntityLatestVersion(theId); if (theId.hasVersionIdPart()) { if (theId.getVersionIdPartAsLong() != entityToUpdate.getVersion()) { throw new ResourceVersionConflictException("Version " + theId.getVersionIdPart() + " is not the most recent version of this resource, unable to apply patch"); } } validateResourceType(entityToUpdate); IBaseResource resourceToUpdate = toResource(entityToUpdate, false); IBaseResource destination; if (thePatchType == PatchTypeEnum.JSON_PATCH) { destination = JsonPatchUtils.apply(getContext(), resourceToUpdate, thePatchBody); } else { destination = XmlPatchUtils.apply(getContext(), resourceToUpdate, thePatchBody); } @SuppressWarnings("unchecked") T destinationCasted = (T) destination; return update(destinationCasted, null, true, theRequestDetails); }
@Override public List<IBaseResource> getResources(int theFromIndex, int theToIndex) { List<IBaseResource> retVal = resources.getResources(theFromIndex, theToIndex); int index = theFromIndex; for (IBaseResource nextResource : retVal) { if (nextResource.getIdElement() == null || isBlank(nextResource.getIdElement().getIdPart())) { throw new InternalErrorException("Server provided resource at index " + index + " with no ID set (using IResource#setId(IdDt))"); } if (isBlank(nextResource.getIdElement().getVersionIdPart()) && nextResource instanceof IResource) { //TODO: Use of a deprecated method should be resolved. IdDt versionId = (IdDt) ResourceMetadataKeyEnum.VERSION_ID.get((IResource) nextResource); if (versionId == null || versionId.isEmpty()) { throw new InternalErrorException("Server provided resource at index " + index + " with no Version ID set (using IResource#setId(IdDt))"); } } index++; } return retVal; }
ourLog.warn("Resource {} version {} does not exist, renumbering version {}", resource.getIdElement().toUnqualifiedVersionless().getValue(), resource.getIdElement().getVersionIdPart(), expectedVersion); myResourceHistoryTableDao.updateVersion(resourceTable.getId(), actualVersion, expectedVersion);
@Override public HttpGetClientInvocation invokeClient(Object[] theArgs) { HttpGetClientInvocation retVal; IIdType id = ((IIdType) theArgs[myIdIndex]); String resourceName = getResourceName(); if (id.hasVersionIdPart()) { retVal = createVReadInvocation(getContext(), new IdDt(resourceName, id.getIdPart(), id.getVersionIdPart()), resourceName); } else { retVal = createReadInvocation(getContext(), id, resourceName); } for (int idx = 0; idx < theArgs.length; idx++) { IParameter nextParam = getParameters().get(idx); nextParam.translateClientArgumentIntoQueryArgument(getContext(), theArgs[idx], null, null); } return retVal; }
ifNoneMatch = ParameterUtil.parseETagValue(ifNoneMatch); if (responseResource.getIdElement() != null && responseResource.getIdElement().hasVersionIdPart()) { if (responseResource.getIdElement().getVersionIdPart().equals(ifNoneMatch)) { ourLog.debug("Returning HTTP 304 because request specified {}={}", Constants.HEADER_IF_NONE_MATCH, ifNoneMatch); throw new NotModifiedException("Not Modified");
metaValue.setVersionId(theResource.getIdElement().getVersionIdPart());
if ("1".equals(id.getVersionIdPart())) { entry.getResponse().setStatus("201 Created"); } else if (isNotBlank(id.getVersionIdPart())) { entry.getResponse().setStatus("200 OK"); if (isNotBlank(id.getVersionIdPart())) { entry.getResponse().setEtag(RestfulServerUtils.createEtag(id.getVersionIdPart()));
Validate.notBlank(defaultString(resourceName), "Can not invoke operation \"$%s\" on instance \"%s\" - No resource type specified", myOperationName, myId.getValue()); id = myId.getIdPart(); version = myId.getVersionIdPart(); } else { resourceName = null;
if (entryResources != null && entryResources.size() > 0) { IBaseResource res = (IBaseResource) entryResources.get(0); String versionId = res.getIdElement().getVersionIdPart(); res.setId(value.getValueAsString()); if (isNotBlank(versionId) && res.getIdElement().hasVersionIdPart() == false) {
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()); } }
if (resourceId.hasVersionIdPart() && Long.parseLong(resourceId.getVersionIdPart()) != entity.getVersion()) { throw new ResourceVersionConflictException("Trying to update " + resourceId + " but this is not the current version");
String versionIdPart = fullId.getVersionIdPart(); response.addHeader(Constants.HEADER_ETAG, createEtag(versionIdPart)); } else if (theResource != null && theResource.getMeta() != null && isNotBlank(theResource.getMeta().getVersionId())) {
String resourceType = myContext.getResourceDefinition(next).getName(); nextEntry.getRequest().setUrl(new IdType(theServerBase, resourceType, next.getIdElement().getIdPart(), next.getIdElement().getVersionIdPart()).getValue());
IIdType id = theId; if (!id.hasBaseUrl()) { id = new IdDt(resName, id.getIdPart(), id.getVersionIdPart());
if (theId.hasVersionIdPart() && Long.parseLong(theId.getVersionIdPart()) != entity.getVersion()) { throw new ResourceVersionConflictException("Trying to delete " + theId + " but this is not the current version");