Package ca.uhn.fhir.context

Examples of ca.uhn.fhir.context.RuntimeResourceDefinition


      try {
        if ("conformance".equals(method)) {
          returnsResource = true;
          client.conformance();
        } else if ("read".equals(method)) {
          RuntimeResourceDefinition def = getResourceType(theReq);
          String id = StringUtils.defaultString(theReq.getParameter("id"));
          if (StringUtils.isBlank(id)) {
            theResp.sendError(Constants.STATUS_HTTP_400_BAD_REQUEST, "No ID specified");
          }
          returnsResource = true;

          client.read(def.getImplementingClass(), new IdDt(id));

        } else if ("vread".equals(method)) {
          RuntimeResourceDefinition def = getResourceType(theReq);
          String id = StringUtils.defaultString(theReq.getParameter("id"));
          if (StringUtils.isBlank(id)) {
            theResp.sendError(Constants.STATUS_HTTP_400_BAD_REQUEST, "No ID specified");
          }

          String versionId = StringUtils.defaultString(theReq.getParameter("versionid"));
          if (StringUtils.isBlank(versionId)) {
            theResp.sendError(Constants.STATUS_HTTP_400_BAD_REQUEST, "No Version ID specified");
          }
          returnsResource = true;

          client.vread(def.getImplementingClass(), new IdDt(id), new IdDt(versionId));

        } else if ("delete".equals(method)) {
          RuntimeResourceDefinition def = getResourceType(theReq);
          String id = StringUtils.defaultString(theReq.getParameter("id"));
          if (StringUtils.isBlank(id)) {
            theResp.sendError(Constants.STATUS_HTTP_400_BAD_REQUEST, "No ID specified");
          }

          returnsResource = false;

          client.delete(def.getImplementingClass(), new IdDt(id));

        } else if ("history-instance".equals(method)) {
          RuntimeResourceDefinition def = getResourceType(theReq);
          String id = StringUtils.defaultString(theReq.getParameter("id"));
          if (StringUtils.isBlank(id)) {
            theResp.sendError(Constants.STATUS_HTTP_400_BAD_REQUEST, "No ID specified");
          }

          returnsResource = false;

          client.history(def.getImplementingClass(), new IdDt(id));

        } else if ("create".equals(method)) {
          RuntimeResourceDefinition def = getResourceType(theReq);
          String resourceText = StringUtils.defaultString(theReq.getParameter("resource"));
          if (StringUtils.isBlank(resourceText)) {
            theResp.sendError(Constants.STATUS_HTTP_400_BAD_REQUEST, "No resource content specified");
          }

          IResource resource;
          if (client.getEncoding() == null || client.getEncoding() == EncodingEnum.XML) {
            resource = myCtx.newXmlParser().parseResource(def.getImplementingClass(), resourceText);
          } else {
            resource = myCtx.newJsonParser().parseResource(def.getImplementingClass(), resourceText);
          }
          returnsResource = false;

          client.create(resource);

        } else if ("validate".equals(method)) {
          RuntimeResourceDefinition def = getResourceType(theReq);
          String resourceText = StringUtils.defaultString(theReq.getParameter("resource"));
          if (StringUtils.isBlank(resourceText)) {
            theResp.sendError(Constants.STATUS_HTTP_400_BAD_REQUEST, "No resource content specified");
          }

          IResource resource;
          if (client.getEncoding() == null || client.getEncoding() == EncodingEnum.XML) {
            resource = myCtx.newXmlParser().parseResource(def.getImplementingClass(), resourceText);
          } else {
            resource = myCtx.newJsonParser().parseResource(def.getImplementingClass(), resourceText);
          }
          returnsResource = false;

          client.validate(resource);

        } else if ("update".equals(method)) {
          RuntimeResourceDefinition def = getResourceType(theReq);
          String resourceText = StringUtils.defaultString(theReq.getParameter("resource"));
          if (StringUtils.isBlank(resourceText)) {
            theResp.sendError(Constants.STATUS_HTTP_400_BAD_REQUEST, "No resource content specified");
          }

          String id = StringUtils.defaultString(theReq.getParameter("id"));
          if (StringUtils.isBlank(id)) {
            theResp.sendError(Constants.STATUS_HTTP_400_BAD_REQUEST, "No ID specified");
          }

          IResource resource;
          if (client.getEncoding() == null || client.getEncoding() == EncodingEnum.XML) {
            resource = myCtx.newXmlParser().parseResource(def.getImplementingClass(), resourceText);
          } else {
            resource = myCtx.newJsonParser().parseResource(def.getImplementingClass(), resourceText);
          }
          returnsResource = false;

          client.update(new IdDt(id), resource);

        } else if ("searchType".equals(method)) {
          Map<String, List<IQueryParameterType>> params = new HashMap<String, List<IQueryParameterType>>();

          HashSet<String> hashSet = new HashSet<String>(theReq.getParameterMap().keySet());
          String paramName = null;
          IQueryParameterType paramValue = null;
          while (hashSet.isEmpty() == false) {

            String nextKey = hashSet.iterator().next();
            String nextValue = theReq.getParameter(nextKey);
            paramName = null;
            paramValue = null;

            if (nextKey.startsWith("param.token.")) {
              int prefixLength = "param.token.".length();
              paramName = nextKey.substring(prefixLength + 2);
              String systemKey = "param.token." + "1." + paramName;
              String valueKey = "param.token." + "2." + paramName;
              String system = theReq.getParameter(systemKey);
              String value = theReq.getParameter(valueKey);
              paramValue = new IdentifierDt(system, value);
              hashSet.remove(systemKey);
              hashSet.remove(valueKey);
            } else if (nextKey.startsWith("param.string.")) {
              paramName = nextKey.substring("param.string.".length());
              paramValue = new StringDt(nextValue);
            }

            if (paramName != null) {
              if (params.containsKey(paramName) == false) {
                params.put(paramName, new ArrayList<IQueryParameterType>());
              }
              params.get(paramName).add(paramValue);
            }

            hashSet.remove(nextKey);
          }

          RuntimeResourceDefinition def = getResourceType(theReq);

          returnsResource = false;
          client.search(def.getImplementingClass(), params);

        } else {
          theResp.sendError(Constants.STATUS_HTTP_400_BAD_REQUEST, "Invalid method: " + method);
          return;
        }
View Full Code Here


    return retVal;
  }

  public static PostClientInvocation createCreateInvocation(IResource resource, FhirContext context) {
    RuntimeResourceDefinition def = context.getResourceDefinition(resource);
    String resourceName = def.getName();

    StringBuilder urlExtension = new StringBuilder();
    urlExtension.append(resourceName);

    return new PostClientInvocation(context, resource, urlExtension.toString());
View Full Code Here

        if (!StringUtils.equals(theLocalPart, definition.getName())) {
          throw new DataFormatException("Incorrect resource root element '" + theLocalPart + "', expected: '" + definition.getName() + "'");
        }
      }

      RuntimeResourceDefinition def = (RuntimeResourceDefinition) definition;
      myInstance = def.newInstance();
      if (myEntry != null) {
        myEntry.setResource(myInstance);
      }

      push(new ElementCompositeState(this, def, myInstance));
View Full Code Here

        theProvider);

    Delete deleteAnnotation = theMethod.getAnnotation(Delete.class);
    Class<? extends IResource> resourceType = deleteAnnotation.type();
    if (resourceType != IResource.class) {
      RuntimeResourceDefinition def = theContext.getResourceDefinition(resourceType);
      myResourceName = def.getName();
    } else {
      if (theProvider != null && theProvider instanceof IResourceProvider) {
        RuntimeResourceDefinition def = theContext.getResourceDefinition(((IResourceProvider) theProvider).getResourceType());
        myResourceName = def.getName();
      } else {
        throw new ConfigurationException("Can not determine resource type for method '" + theMethod.getName() + "' on type " + theMethod.getDeclaringClass().getCanonicalName() + " - Did you forget to include the resourceType() value on the @"
            + Delete.class.getSimpleName() + " method annotation?");
      }
    }
View Full Code Here

   *
   */
  private void encodeResourceToXmlStreamWriter(IResource theResource, XMLStreamWriter theEventWriter, boolean theIncludedResource) throws XMLStreamException, DataFormatException {
    super.containResourcesForEncoding(theResource);

    RuntimeResourceDefinition resDef = myContext.getResourceDefinition(theResource);
    if (resDef == null) {
      throw new ConfigurationException("Unknown resource type: " + theResource.getClass());
    }

    theEventWriter.writeStartElement(resDef.getName());
    theEventWriter.writeDefaultNamespace(FHIR_NS);

    if (theIncludedResource && StringUtils.isNotBlank(theResource.getId().getValue())) {
      theEventWriter.writeAttribute("id", theResource.getId().getValue());
    }
View Full Code Here

    BaseClientInvocation invocation = CreateMethodBinding.createCreateInvocation(theResource, myContext);
    if (isKeepResponses()) {
      myLastRequest = invocation.asHttpRequest(getServerBase(), createExtraParams(), getEncoding());
    }

    RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);
    final String resourceName = def.getName();

    OutcomeResponseHandler binding = new OutcomeResponseHandler(resourceName);

    MethodOutcome resp = invokeClient(binding, invocation);
    return resp;
View Full Code Here

    BaseClientInvocation invocation = UpdateMethodBinding.createUpdateInvocation(theResource, theIdDt, null, myContext);
    if (isKeepResponses()) {
      myLastRequest = invocation.asHttpRequest(getServerBase(), createExtraParams(), getEncoding());
    }

    RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);
    final String resourceName = def.getName();

    OutcomeResponseHandler binding = new OutcomeResponseHandler(resourceName);
    MethodOutcome resp = invokeClient(binding, invocation);
    return resp;
  }
View Full Code Here

    BaseClientInvocation invocation = ValidateMethodBinding.createValidateInvocation(theResource, null, myContext);
    if (isKeepResponses()) {
      myLastRequest = invocation.asHttpRequest(getServerBase(), createExtraParams(), getEncoding());
    }

    RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);
    final String resourceName = def.getName();

    OutcomeResponseHandler binding = new OutcomeResponseHandler(resourceName);
    MethodOutcome resp = invokeClient(binding, invocation);
    return resp;
  }
View Full Code Here

            entry.addCategory().setTerm(tag.getTerm()).setLabel(tag.getLabel()).setScheme(tag.getScheme());
          }
        }
      }

      RuntimeResourceDefinition def = getContext().getResourceDefinition(next);

      if (next.getId() != null && StringUtils.isNotBlank(next.getId().getValue())) {
        entry.getId().setValue(next.getId().getValue());
        entry.getTitle().setValue(def.getName() + " " + next.getId().getValue());

        StringBuilder b = new StringBuilder();
        b.append(theServerBase);
        b.append('/');
        b.append(def.getName());
        b.append('/');
        String resId = next.getId().getValue();
        b.append(resId);

        /*
 
View Full Code Here

  }

  private FhirContext myContext;

  public List<Object> getValues(IResource theResource, String thePath) {
    RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);

    BaseRuntimeElementCompositeDefinition<?> currentDef = def;
    Object currentObj = theResource;

    List<String> parts = Arrays.asList(thePath.split("\\."));
View Full Code Here

TOP

Related Classes of ca.uhn.fhir.context.RuntimeResourceDefinition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.