/** * Constructor * * @param theRequestDetails The request details to wrap * @param theId The ID of the resource being created (note that the ID should have the resource type populated) */ public ActionRequestDetails(RequestDetails theRequestDetails, IIdType theId) { this(theRequestDetails, theId.getResourceType(), theId); }
private void setIdInternal(IIdType theId) { Validate.notBlank(theId.getResourceType(), "theId must contain a resource type"); Validate.notBlank(theId.getIdPart(), "theId must contain an ID part"); myOnType = theId.getResourceType(); myId = theId; }
private void validateResourceTypeAndThrowIllegalArgumentException(IIdType theId) { if (theId.hasResourceType() && !theId.getResourceType().equals(myResourceName)) { throw new IllegalArgumentException("Incorrect resource type (" + theId.getResourceType() + ") for this DAO, wanted: " + myResourceName); } }
@Override public List<StructureDefinition> allStructures() { ArrayList<StructureDefinition> retVal = new ArrayList<>(); for (Map.Entry<IIdType, IBaseResource> next : myIgResources.entrySet()) { if (next.getKey().getResourceType().equals("StructureDefinition")) { retVal.add((StructureDefinition) next.getValue()); } } return retVal; }
@Override public List<StructureDefinition> fetchAllStructureDefinitions(FhirContext theContext) { ArrayList<StructureDefinition> retVal = new ArrayList<>(); for (Map.Entry<IIdType, IBaseResource> next : myIgResources.entrySet()) { if (next.getKey().getResourceType().equals("StructureDefinition")) { retVal.add((StructureDefinition) next.getValue()); } } return retVal; }
@Override public ValueSet fetchCodeSystem(FhirContext theContext, String theSystem) { for (Map.Entry<IIdType, IBaseResource> next : myIgResources.entrySet()) { if (next.getKey().getResourceType().equals("ValueSet")) { ValueSet nextVs = (ValueSet) next.getValue(); if (theSystem.equals(nextVs.getUrl())) { return nextVs; } } } return null; }
private boolean validCriteria(ActiveSubscription theActiveSubscription, IIdType theResourceId) { String criteriaString = theActiveSubscription.getCriteriaString(); String subscriptionId = getId(theActiveSubscription); String resourceType = theResourceId.getResourceType(); if (StringUtils.isBlank(criteriaString)) { return false; } // see if the criteria matches the created object ourLog.trace("Checking subscription {} for {} with criteria {}", subscriptionId, resourceType, criteriaString); String criteriaResource = criteriaString; int index = criteriaResource.indexOf("?"); if (index != -1) { criteriaResource = criteriaResource.substring(0, criteriaResource.indexOf("?")); } if (resourceType != null && !criteriaResource.equals(resourceType)) { ourLog.trace("Skipping subscription search for {} because it does not match the criteria {}", resourceType, criteriaString); return false; } return true; } }
@Override public IAuthRuleBuilderOperationNamedAndScoped onInstance(IIdType theInstanceId) { Validate.notNull(theInstanceId, "theInstanceId must not be null"); Validate.notBlank(theInstanceId.getResourceType(), "theInstanceId does not have a resource type"); Validate.notBlank(theInstanceId.getIdPart(), "theInstanceId does not have an ID part"); OperationRule rule = createRule(); ArrayList<IIdType> ids = new ArrayList<>(); ids.add(theInstanceId); rule.appliesToInstances(ids); return new RuleBuilderOperationNamedAndScoped(rule); }
private void processUrl() { String resourceType = myId.getResourceType(); if (isBlank(resourceType)) { throw new IllegalArgumentException(myContext.getLocalizer().getMessage(I18N_INCOMPLETE_URI_FOR_READ, myId)); } myType = myContext.getResourceDefinition(resourceType); if (myType == null) { throw new IllegalArgumentException(myContext.getLocalizer().getMessage(I18N_CANNOT_DETEMINE_RESOURCE_TYPE, myId)); } }
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(); }
@Override public IBaseResource getResource(IIdType payloadId) throws ResourceGoneException { RuntimeResourceDefinition resourceDef = myFhirContext.getResourceDefinition(payloadId.getResourceType()); return myClient.search().forResource(resourceDef.getName()).withIdAndCompartment(payloadId.getIdPart(), payloadId.getResourceType()).execute(); } }
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; }
@Override public IBaseResource getResource(IIdType payloadId) throws ResourceGoneException { RuntimeResourceDefinition resourceDef = myFhirContext.getResourceDefinition(payloadId.getResourceType()); IFhirResourceDao dao = myDaoRegistry.getResourceDao(resourceDef.getImplementingClass()); return dao.read(payloadId.toVersionless()); } }
@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; }
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 SubscriptionMatchResult match(CanonicalSubscription theSubscription, ResourceModifiedMessage theMsg) { IIdType id = theMsg.getId(myCtx); String resourceType = id.getResourceType(); String resourceId = id.getIdPart(); String criteria = theSubscription.getCriteriaString(); // run the subscriptions query and look for matches, add the id as part of the criteria to avoid getting matches of previous resources rather than the recent resource criteria += "&_id=" + resourceType + "/" + resourceId; IBundleProvider results = performSearch(criteria); ourLog.debug("Subscription check found {} results for query: {}", results.size(), criteria); return SubscriptionMatchResult.fromBoolean(results.size() > 0); }
public void notifyInterceptors(RestOperationTypeEnum theOperationType, ActionRequestDetails theRequestDetails) { if (theRequestDetails.getId() != null && theRequestDetails.getId().hasResourceType() && isNotBlank(theRequestDetails.getResourceType())) { if (theRequestDetails.getId().getResourceType().equals(theRequestDetails.getResourceType()) == false) { throw new InternalErrorException( "Inconsistent server state - Resource types don't match: " + theRequestDetails.getId().getResourceType() + " / " + theRequestDetails.getResourceType()); } } if (theRequestDetails.getUserData().get(PROCESSING_SUB_REQUEST) == Boolean.TRUE) { theRequestDetails.notifyIncomingRequestPreHandled(theOperationType); } List<IServerInterceptor> interceptors = getConfig().getInterceptors(); for (IServerInterceptor next : interceptors) { next.incomingRequestPreHandled(theOperationType, theRequestDetails); } }
@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()); } PatchTypeEnum patchType = (PatchTypeEnum) theArgs[myPatchTypeParameterIndex]; String body = (String) theArgs[myResourceParamIndex]; HttpPatchClientInvocation retVal = createPatchInvocation(getContext(), idDt, patchType, body); for (int idx = 0; idx < theArgs.length; idx++) { IParameter nextParam = getParameters().get(idx); nextParam.translateClientArgumentIntoQueryArgument(getContext(), theArgs[idx], null, null); } return retVal; }
@SuppressWarnings("unchecked") @Override public Object execute() { String resourceName; String id; if (myType != null) { resourceName = myContext.getResourceDefinition(myType).getName(); id = null; } else if (myId != null) { resourceName = myId.getResourceType(); id = myId.getIdPart(); } else { resourceName = null; id = null; } HttpGetClientInvocation invocation = HistoryMethodBinding.createHistoryInvocation(myContext, resourceName, id, mySince, myCount, myAt); IClientResponseHandler handler; handler = new ResourceResponseHandler(myReturnType, getPreferResponseTypes(myType)); return invoke(null, handler, invocation); }
@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; } }