public void applyTo(IBaseResource theResouce) { if (theResouce == null) { throw new NullPointerException("theResource can not be null"); } else { theResouce.setId(new IdType(getValue())); } }
public void applyTo(IBaseResource theResouce) { if (theResouce == null) { throw new NullPointerException("theResource can not be null"); } else { theResouce.setId(new IdType(getValue())); } }
public void applyTo(IBaseResource theResouce) { if (theResouce == null) { throw new NullPointerException("theResource can not be null"); } else { theResouce.setId(new IdType(getValue())); } }
/** * Returns the referenced resource, fetching it <b>if it has not already been loaded</b>. This method invokes the * HTTP client to retrieve the resource unless it has already been loaded, or was a contained resource in which case * it is simply returned. */ public IBaseResource loadResource(IRestfulClient theClient) { if (myResource != null) { return myResource; } IdDt resourceId = getReference(); if (resourceId == null || isBlank(resourceId.getValue())) { throw new IllegalStateException("Reference has no resource ID defined"); } if (isBlank(resourceId.getBaseUrl()) || isBlank(resourceId.getResourceType())) { throw new IllegalStateException("Reference is not complete (must be in the form [baseUrl]/[resource type]/[resource ID]) - Reference is: " + resourceId.getValue()); } String resourceUrl = resourceId.getValue(); ourLog.debug("Loading resource at URL: {}", resourceUrl); RuntimeResourceDefinition definition = theClient.getFhirContext().getResourceDefinition(resourceId.getResourceType()); Class<? extends IBaseResource> resourceType = definition.getImplementingClass(); myResource = theClient.fetchResourceFromUrl(resourceType, resourceUrl); myResource.setId(resourceUrl); return myResource; }
id.setParts(null, myResourceName, theIdPart, versionIdPart); if (theResource != null) { theResource.setId(id);
@Override public DaoMethodOutcome create(T theResource, String theIfNoneExist, boolean thePerformIndexing, Date theUpdateTimestamp, RequestDetails theRequestDetails) { if (isNotBlank(theResource.getIdElement().getIdPart())) { if (getContext().getVersion().getVersion().isOlderThan(FhirVersionEnum.DSTU3)) { String message = getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithClientAssignedId", theResource.getIdElement().getIdPart()); throw new InvalidRequestException(message, createErrorOperationOutcome(message, "processing")); } else { // As of DSTU3, ID and version in the body should be ignored for a create/update theResource.setId(""); } } if (myDaoConfig.getResourceServerIdStrategy() == DaoConfig.IdStrategyEnum.UUID) { theResource.setId(UUID.randomUUID().toString()); } return doCreate(theResource, theIfNoneExist, thePerformIndexing, theUpdateTimestamp, theRequestDetails); }
@Override public List<IBaseResource> toListOfResources() { ArrayList<IBaseResource> retVal = new ArrayList<IBaseResource>(); for (BundleEntryComponent next : myBundle.getEntry()) { if (next.getResource() != null) { retVal.add(next.getResource()); } else if (next.getResponse().getLocationElement().isEmpty() == false) { IdType id = new IdType(next.getResponse().getLocation()); String resourceType = id.getResourceType(); if (isNotBlank(resourceType)) { IBaseResource res = (IBaseResource) myContext.getResourceDefinition(resourceType).newInstance(); res.setId(id); retVal.add(res); } } } return retVal; }
@Override protected void validateResourceIdAndUrlIdForNonConditionalOperation(IBaseResource theResource, String theResourceId, String theUrlId, String theMatchUrl) { if (isBlank(theMatchUrl)) { if (isBlank(theUrlId)) { String msg = getContext().getLocalizer().getMessage(BaseOutcomeReturningMethodBindingWithResourceParam.class, "noIdInUrlForUpdate"); throw new InvalidRequestException(msg); } if (isBlank(theResourceId)) { String msg = getContext().getLocalizer().getMessage(BaseOutcomeReturningMethodBindingWithResourceParam.class, "noIdInBodyForUpdate"); throw new InvalidRequestException(msg); } if (!theResourceId.equals(theUrlId)) { String msg = getContext().getLocalizer().getMessage(BaseOutcomeReturningMethodBindingWithResourceParam.class, "incorrectIdForUpdate", theResourceId, theUrlId); throw new InvalidRequestException(msg); } } else { theResource.setId((IIdType) null); } } }
@Override protected void validateResourceIdAndUrlIdForNonConditionalOperation(IBaseResource theResource, String theResourceId, String theUrlId, String theMatchUrl) { if (isBlank(theMatchUrl)) { if (isBlank(theUrlId)) { String msg = getContext().getLocalizer().getMessage(BaseOutcomeReturningMethodBindingWithResourceParam.class, "noIdInUrlForUpdate"); throw new InvalidRequestException(msg); } if (isBlank(theResourceId)) { String msg = getContext().getLocalizer().getMessage(BaseOutcomeReturningMethodBindingWithResourceParam.class, "noIdInBodyForUpdate"); throw new InvalidRequestException(msg); } if (!theResourceId.equals(theUrlId)) { String msg = getContext().getLocalizer().getMessage(BaseOutcomeReturningMethodBindingWithResourceParam.class, "incorrectIdForUpdate", theResourceId, theUrlId); throw new InvalidRequestException(msg); } } else { theResource.setId((IIdType)null); } } }
@Override protected void validateResourceIdAndUrlIdForNonConditionalOperation(IBaseResource theResource, String theResourceId, String theUrlId, String theMatchUrl) { if (isNotBlank(theUrlId)) { String msg = getContext().getLocalizer().getMessage(BaseOutcomeReturningMethodBindingWithResourceParam.class, "idInUrlForCreate", theUrlId); throw new InvalidRequestException(msg); } if (getContext().getVersion().getVersion().isOlderThan(FhirVersionEnum.DSTU3)) { if (isNotBlank(theResourceId)) { String msg = getContext().getLocalizer().getMessage(BaseOutcomeReturningMethodBindingWithResourceParam.class, "idInBodyForCreate", theResourceId); throw new InvalidRequestException(msg); } } else { theResource.setId((IIdType)null); } }
@Override protected void validateResourceIdAndUrlIdForNonConditionalOperation(IBaseResource theResource, String theResourceId, String theUrlId, String theMatchUrl) { if (isNotBlank(theUrlId)) { String msg = getContext().getLocalizer() .getMessage(BaseOutcomeReturningMethodBindingWithResourceParam.class, "idInUrlForCreate", theUrlId); throw new InvalidRequestException(msg); } if (getContext().getVersion().getVersion().isOlderThan(FhirVersionEnum.DSTU3)) { if (isNotBlank(theResourceId)) { String msg = getContext().getLocalizer().getMessage( BaseOutcomeReturningMethodBindingWithResourceParam.class, "idInBodyForCreate", theResourceId); throw new InvalidRequestException(msg); } } else { theResource.setId((IIdType) null); } }
protected IBaseResource getAndMassagePayload(ResourceDeliveryMessage theMsg, CanonicalSubscription theSubscription) { IBaseResource payloadResource = theMsg.getPayload(myFhirContext); if (payloadResource == null || theSubscription.getRestHookDetails().isDeliverLatestVersion()) { IIdType payloadId = theMsg.getPayloadId(myFhirContext); try { payloadResource = myResourceRetriever.getResource(payloadId.toVersionless()); } catch (ResourceGoneException e) { ourLog.warn("Resource {} is deleted, not going to deliver for subscription {}", payloadId.toVersionless(), theSubscription.getIdElement(myFhirContext)); return null; } } IIdType resourceId = payloadResource.getIdElement(); if (theSubscription.getRestHookDetails().isStripVersionId()) { resourceId = resourceId.toVersionless(); payloadResource.setId(resourceId); } return payloadResource; }
private boolean activateSubscription(String theActiveStatus, final IBaseResource theSubscription, String theRequestedStatus) { IFhirResourceDao subscriptionDao = myDaoRegistry.getSubscriptionDao(); IBaseResource subscription = subscriptionDao.read(theSubscription.getIdElement()); subscription.setId(subscription.getIdElement().toVersionless()); ourLog.info("Activating subscription {} from status {} to {}", subscription.getIdElement().toUnqualified().getValue(), theRequestedStatus, theActiveStatus); try { SubscriptionUtil.setStatus(myFhirContext, subscription, theActiveStatus); subscription = subscriptionDao.update(subscription).getResource(); submitResourceModifiedForUpdate(subscription); return true; } catch (final UnprocessableEntityException e) { ourLog.info("Changing status of {} to ERROR", subscription.getIdElement()); SubscriptionUtil.setStatus(myFhirContext, subscription, "error"); SubscriptionUtil.setReason(myFhirContext, subscription, e.getMessage()); subscriptionDao.update(subscription); return false; } }
@Override protected void addParametersForServerRequest(RequestDetails theRequest, Object[] theParams) { if (myIdParamIndex != null) { theParams[myIdParamIndex] = ParameterUtil.convertIdToType(theRequest.getId(), myIdParamType); } if (myResourceParameterIndex != -1) { IBaseResource resource = ((IBaseResource) theParams[myResourceParameterIndex]); String resourceId = resource.getIdElement().getIdPart(); String urlId = theRequest.getId() != null ? theRequest.getId().getIdPart() : null; if (getContext().getVersion().getVersion().isOlderThan(FhirVersionEnum.DSTU3) == false) { resource.setId(theRequest.getId()); } String matchUrl = null; if (myConditionalUrlIndex != -1) { matchUrl = (String) theParams[myConditionalUrlIndex]; matchUrl = defaultIfBlank(matchUrl, null); } validateResourceIdAndUrlIdForNonConditionalOperation(resource, resourceId, urlId, matchUrl); } }
newResource.setId(resName + "/" + theId); IFhirResourceDao<IBaseResource> placeholderResourceDao = (IFhirResourceDao<IBaseResource>) myDaoRegistry.getResourceDao(newResource.getClass()); ourLog.debug("Automatically creating empty placeholder resource: {}", newResource.getIdElement().getValue());
theResource.setId(entity.getIdDt().getValue()); DaoMethodOutcome outcome = toMethodOutcome(entity, theResource).setCreated(false); outcome.setPreviousResource(oldResource);
resourceToDelete.setId(entity.getIdDt());
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()); } }
resourceToDelete.setId(entity.getIdDt());