@Override public RestOperationTypeEnum getRestOperationType(RequestDetails theRequestDetails) { if (mySupportsVersion && theRequestDetails.getId().hasVersionIdPart()) { return RestOperationTypeEnum.VREAD; } return RestOperationTypeEnum.READ; }
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()); }
public static IIdType applyETagAsVersion(RequestDetails theRequest, IIdType id) { String ifMatchValue = theRequest.getHeader(Constants.HEADER_IF_MATCH); if (isNotBlank(ifMatchValue)) { ifMatchValue = ParameterUtil.parseETagValue(ifMatchValue); if (id != null && id.hasVersionIdPart() == false) { id = id.withVersion(ifMatchValue); } } return id; }
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; }
@Read(version = true) public IBaseResource read(@IdParam IIdType theId) { TreeMap<Long, T> versions = myIdToVersionToResourceMap.get(theId.getIdPart()); if (versions == null || versions.isEmpty()) { throw new ResourceNotFoundException(theId); } T retVal; if (theId.hasVersionIdPart()) { Long versionId = theId.getVersionIdPartAsLong(); if (!versions.containsKey(versionId)) { throw new ResourceNotFoundException(theId); } else { T resource = versions.get(versionId); if (resource == null) { throw new ResourceGoneException(theId); } retVal = resource; } } else { retVal = versions.lastEntry().getValue(); } myReadCount.incrementAndGet(); return retVal; }
if (theRequest.getId().hasVersionIdPart()) { return false; return false; if (theRequest.getId().hasVersionIdPart() == false) { return false;
@Override public Object execute() {// AAA if (myId.hasVersionIdPart()) { return doReadOrVRead(myType.getImplementingClass(), myId, true, myNotModifiedHandler, myIfVersionMatches, myPrettyPrint, mySummaryMode, myParamEncoding, getSubsetElements(), getCustomAcceptHeaderValue()); } return doReadOrVRead(myType.getImplementingClass(), myId, false, myNotModifiedHandler, myIfVersionMatches, myPrettyPrint, mySummaryMode, myParamEncoding, getSubsetElements(), getCustomAcceptHeaderValue()); }
@Override public boolean incomingServerRequestMatchesMethod(RequestDetails theRequest) { if (!Constants.PARAM_HISTORY.equals(theRequest.getOperation())) { return false; } if (theRequest.getResourceName() == null) { return myResourceOperationType == RestOperationTypeEnum.HISTORY_SYSTEM; } if (!StringUtils.equals(theRequest.getResourceName(), myResourceName)) { return false; } boolean haveIdParam = theRequest.getId() != null && !theRequest.getId().isEmpty(); boolean wantIdParam = myIdParamIndex != null; if (haveIdParam != wantIdParam) { return false; } if (theRequest.getId() == null) { return myResourceOperationType == RestOperationTypeEnum.HISTORY_TYPE; } else if (theRequest.getId().hasVersionIdPart()) { return false; } return true; }
if (theResourceType != null) { resourceName = toResourceName(theResourceType); if (theResourceId != null && theResourceId.hasVersionIdPart()) { IFhirResourceDao<? extends IBaseResource> dao = getDao(theResourceType); BaseHasResource entity = dao.readEntity(theResourceId);
@Override @Transactional(propagation = Propagation.NEVER) public ExpungeOutcome expunge(IIdType theId, ExpungeOptions theExpungeOptions) { TransactionTemplate txTemplate = new TransactionTemplate(myPlatformTransactionManager); BaseHasResource entity = txTemplate.execute(t->readEntity(theId)); if (theId.hasVersionIdPart()) { BaseHasResource currentVersion; currentVersion = txTemplate.execute(t->readEntity(theId.toVersionless())); if (entity.getVersion() == currentVersion.getVersion()) { throw new PreconditionFailedException("Can not perform version-specific expunge of resource " + theId.toUnqualified().getValue() + " as this is the current version"); } return doExpunge(getResourceName(), entity.getResourceId(), entity.getVersion(), theExpungeOptions); } return doExpunge(getResourceName(), entity.getResourceId(), null, theExpungeOptions); }
if (theId.hasVersionIdPart()) { if (theId.isVersionIdPartValidLong() == false) { throw new ResourceNotFoundException(getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "invalidVersion", theId.getVersionIdPart(), theId.toUnqualifiedVersionless())); if (theId.hasVersionIdPart()) { TypedQuery<ResourceHistoryTable> q = myEntityManager.createQuery("SELECT t from ResourceHistoryTable t WHERE t.myResourceId = :RID AND t.myResourceType = :RTYP AND t.myResourceVersion = :RVER", ResourceHistoryTable.class); q.setParameter("RID", pid);
if (theResource.getIdElement().hasVersionIdPart()) { metaValue.setVersionId(theResource.getIdElement().getVersionIdPart());
if (StringUtils.isNotBlank(ifNoneMatch)) { 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);
@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; }
if (theRequest.getId() != null && theRequest.getId().hasVersionIdPart() == false) { if (id != null && id.hasVersionIdPart()) { theRequest.getId().setValue(id.getValue());
String versionId = res.getIdElement().getVersionIdPart(); res.setId(value.getValueAsString()); if (isNotBlank(versionId) && res.getIdElement().hasVersionIdPart() == false) { res.setId(res.getIdElement().withVersion(versionId));
@Override public T read(IIdType theId, RequestDetails theRequestDetails, boolean theDeletedOk) { validateResourceTypeAndThrowIllegalArgumentException(theId); // Notify interceptors if (theRequestDetails != null) { ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getResourceName(), theId); RestOperationTypeEnum operationType = theId.hasVersionIdPart() ? RestOperationTypeEnum.VREAD : RestOperationTypeEnum.READ; notifyInterceptors(operationType, requestDetails); } StopWatch w = new StopWatch(); BaseHasResource entity = readEntity(theId); validateResourceType(entity); T retVal = toResource(myResourceType, entity, null, false); if (theDeletedOk == false) { if (entity.getDeleted() != null) { throw new ResourceGoneException("Resource was deleted at " + new InstantType(entity.getDeleted()).getValueAsString()); } } ourLog.debug("Processed read on {} in {}ms", theId.getValue(), w.getMillisAndRestart()); return retVal; }
@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); }
if (theResourceId.hasVersionIdPart() == false) { theResourceId = theResourceId.withVersion(Long.toString(savedEntity.getVersion()));
if (theId.hasVersionIdPart() && Long.parseLong(theId.getVersionIdPart()) != entity.getVersion()) { throw new ResourceVersionConflictException("Trying to delete " + theId + " but this is not the current version");