Package ca.uhn.fhir.model.api

Examples of ca.uhn.fhir.model.api.Bundle


  public Object invokeClient(String theResponseMimeType, Reader theResponseReader, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws IOException {
    IParser parser = createAppropriateParserForParsingResponse(theResponseMimeType, theResponseReader, theResponseStatusCode);

    switch (getReturnType()) {
    case BUNDLE: {
      Bundle bundle;
      if (myResourceType != null) {
        bundle = parser.parseBundle(myResourceType, theResponseReader);
      } else {
        bundle = parser.parseBundle(theResponseReader);
      }
      switch (getMethodReturnType()) {
      case BUNDLE:
        return bundle;
      case LIST_OF_RESOURCES:
        return bundle.toListOfResources();
      case RESOURCE:
        List<IResource> list = bundle.toListOfResources();
        if (list.size() == 0) {
          return null;
        } else if (list.size() == 1) {
          return list.get(0);
        } else {
View Full Code Here


    theHttpResponse.setCharacterEncoding(Constants.CHARSET_UTF_8);

    theServer.addHeadersToResponse(theHttpResponse);

    Bundle bundle = new Bundle();
    bundle.getAuthorName().setValue(getClass().getCanonicalName());
    bundle.getBundleId().setValue(UUID.randomUUID().toString());
    bundle.getPublished().setToCurrentTimeInLocalTimeZone();
    bundle.getLinkBase().setValue(theServerBase);
    bundle.getLinkSelf().setValue(theCompleteUrl);

    for (IResource next : theResult) {
      BundleEntry entry = new BundleEntry();
      bundle.getEntries().add(entry);

      entry.setResource(next);
      TagList list = (TagList) next.getResourceMetadata().get(ResourceMetadataKeyEnum.TAG_LIST);
      if (list != null) {
        for (Tag tag : list) {
          if (StringUtils.isNotBlank(tag.getTerm())) {
            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);

        /*
         * If this is a history operation, we add the version of the
         * resource to the self link to indicate the version
         */
        if (getResourceOperationType() == RestfulOperationTypeEnum.HISTORY_INSTANCE || getResourceOperationType() == RestfulOperationTypeEnum.HISTORY_TYPE || getSystemOperationType() == RestfulOperationSystemEnum.HISTORY_SYSTEM) {
          IdDt versionId = getIdFromMetadataOrNullIfNone(next.getResourceMetadata(), ResourceMetadataKeyEnum.VERSION_ID);
          if (versionId != null) {
            b.append('/');
            b.append(Constants.PARAM_HISTORY);
            b.append('/');
            b.append(versionId.getValue());
          } else {
            throw new InternalErrorException("Server did not provide a VERSION_ID in the resource metadata for resource with ID " + resId);
          }
        }

        InstantDt published = getInstantFromMetadataOrNullIfNone(next.getResourceMetadata(), ResourceMetadataKeyEnum.PUBLISHED);
        if (published == null) {
          entry.getPublished().setToCurrentTimeInLocalTimeZone();
        } else {
          entry.setPublished(published);
        }

        InstantDt updated = getInstantFromMetadataOrNullIfNone(next.getResourceMetadata(), ResourceMetadataKeyEnum.UPDATED);
        if (updated != null) {
          entry.setUpdated(updated);
        }

        TagList tagList = getTagListFromMetadataOrNullIfNone(next.getResourceMetadata(), ResourceMetadataKeyEnum.TAG_LIST);
        if (tagList != null) {
          for (Tag nextTag : tagList) {
            entry.addCategory(nextTag);
          }
        }

        boolean haveQ = false;
        if (thePrettyPrint) {
          b.append('?').append(Constants.PARAM_PRETTY).append("=true");
          haveQ = true;
        }
        if (theResponseEncoding == EncodingEnum.JSON) {
          if (!haveQ) {
            b.append('?');
            haveQ = true;
          } else {
            b.append('&');
          }
          b.append(Constants.PARAM_FORMAT).append("=json");
        }
        if (theNarrativeMode != NarrativeModeEnum.NORMAL) {
          b.append(Constants.PARAM_NARRATIVE).append("=").append(theNarrativeMode.name().toLowerCase());
        }
        entry.getLinkSelf().setValue(b.toString());
      }
    }

    bundle.getTotalResults().setValue(theResult.size());

    PrintWriter writer = theHttpResponse.getWriter();
    try {
      if (theNarrativeMode == NarrativeModeEnum.ONLY) {
        for (IResource next : theResult) {
View Full Code Here

        myLastRequest = invocation.asHttpRequest(getServerBase(), createExtraParams(), getEncoding());
      }

      BundleResponseHandler binding = new BundleResponseHandler(myResourceType);

      Bundle resp = invokeClient(binding, invocation, myLogRequestAndResponse);
      return resp;

    }
View Full Code Here

    parseBundleChildren(object, state);

    state.endingElement();

    Bundle retVal = state.getObject();

    return retVal;
  }
View Full Code Here

  public Object invokeClient(String theResponseMimeType, Reader theResponseReader, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws IOException {
    IParser parser = createAppropriateParser(theResponseMimeType, theResponseReader, theResponseStatusCode);

    switch (getReturnType()) {
    case BUNDLE: {
      Bundle bundle = parser.parseBundle(theResponseReader);
      switch (getMethodReturnType()) {
      case BUNDLE:
        return bundle;
      case LIST_OF_RESOURCES:
        return bundle.toListOfResources();
      case RESOURCE:
        List<IResource> list = bundle.toListOfResources();
        if (list.size() == 0) {
          return null;
        } else if (list.size() == 1) {
          return list.get(0);
        } else {
View Full Code Here

    theHttpResponse.setCharacterEncoding("UTF-8");

    theServer.addHapiHeader(theHttpResponse);

    Bundle bundle = new Bundle();
    bundle.getAuthorName().setValue(getClass().getCanonicalName());
    bundle.getBundleId().setValue(UUID.randomUUID().toString());
    bundle.getPublished().setToCurrentTimeInLocalTimeZone();
    bundle.getLinkBase().setValue(theServerBase);
    bundle.getLinkSelf().setValue(theCompleteUrl);

    for (IResource next : theResult) {
      BundleEntry entry = new BundleEntry();
      bundle.getEntries().add(entry);

      entry.setResource(next);

      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);

        /*
         * If this is a history operation, we add the version of the
         * resource to the self link to indicate the version
         */
        if (getResourceOperationType() == RestfulOperationTypeEnum.HISTORY_INSTANCE || getResourceOperationType() == RestfulOperationTypeEnum.HISTORY_TYPE || getSystemOperationType() == RestfulOperationSystemEnum.HISTORY_SYSTEM) {
          IdDt versionId = getIdFromMetadataOrNullIfNone(next.getResourceMetadata(), ResourceMetadataKeyEnum.VERSION_ID);
          if (versionId != null) {
            b.append('/');
            b.append(Constants.PARAM_HISTORY);
            b.append('/');
            b.append(versionId.getValue());
          } else {
            throw new InternalErrorException("Server did not provide a VERSION_ID in the resource metadata for resource with ID " + resId);
          }
        }

        InstantDt published = getInstantFromMetadataOrNullIfNone(next.getResourceMetadata(), ResourceMetadataKeyEnum.PUBLISHED);
        if (published == null) {
          entry.getPublished().setToCurrentTimeInLocalTimeZone();
        } else {
          entry.setPublished(published);
        }

        InstantDt updated = getInstantFromMetadataOrNullIfNone(next.getResourceMetadata(), ResourceMetadataKeyEnum.UPDATED);
        if (updated != null) {
          entry.setUpdated(updated);
        }

        boolean haveQ = false;
        if (thePrettyPrint) {
          b.append('?').append(Constants.PARAM_PRETTY).append("=true");
          haveQ = true;
        }
        if (theResponseEncoding == EncodingUtil.JSON) {
          if (!haveQ) {
            b.append('?');
            haveQ = true;
          } else {
            b.append('&');
          }
          b.append(Constants.PARAM_FORMAT).append("=json");
        }
        if (theNarrativeMode != NarrativeModeEnum.NORMAL) {
          b.append(Constants.PARAM_NARRATIVE).append("=").append(theNarrativeMode.name().toLowerCase());
        }
        entry.getLinkSelf().setValue(b.toString());
      }
    }

    bundle.getTotalResults().setValue(theResult.size());

    PrintWriter writer = theHttpResponse.getWriter();
    try {
      if (theNarrativeMode == NarrativeModeEnum.ONLY) {
        for (IResource next : theResult) {
View Full Code Here

    parseBundleChildren(object, state);

    state.endingElement();

    Bundle retVal = state.getObject();

    return retVal;
  }
View Full Code Here

    public void enteringNewElement(String theNamespaceURI, String theLocalPart) throws DataFormatException {
      if (!"feed".equals(theLocalPart)) {
        throw new DataFormatException("Expecting outer element called 'feed', found: " + theLocalPart);
      }

      myInstance = new Bundle();
      push(new AtomState(myInstance));

    }
View Full Code Here

      contentType = encoding.getResourceContentType();
    } else if (myBundle != null) {
      contents = parser.encodeBundleToString(myBundle);
      contentType = encoding.getBundleContentType();
    } else if (myResources != null) {
      Bundle bundle = RestfulServer.createBundleFromResourceList(myContext, "", myResources, "", "", myResources.size());
      contents = parser.encodeBundleToString(bundle);
      contentType = encoding.getBundleContentType();
    } else if (myContents != null) {
      contents = myContents;
      if (myContentsIsBundle) {
View Full Code Here

  public Object invokeClient(String theResponseMimeType, Reader theResponseReader, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws IOException {
    IParser parser = createAppropriateParserForParsingResponse(theResponseMimeType, theResponseReader, theResponseStatusCode);

    switch (getReturnType()) {
    case BUNDLE: {
      Bundle bundle;
      if (myResourceType != null) {
        bundle = parser.parseBundle(myResourceType, theResponseReader);
      } else {
        bundle = parser.parseBundle(theResponseReader);
      }
      switch (getMethodReturnType()) {
      case BUNDLE:
        return bundle;
      case LIST_OF_RESOURCES:
        return bundle.toListOfResources();
      case RESOURCE:
        List<IResource> list = bundle.toListOfResources();
        if (list.size() == 0) {
          return null;
        } else if (list.size() == 1) {
          return list.get(0);
        } else {
View Full Code Here

TOP

Related Classes of ca.uhn.fhir.model.api.Bundle

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.