Package ca.uhn.fhir.rest.server

Examples of ca.uhn.fhir.rest.server.IBundleProvider


    for (IResource next : resources) {
      oldIds.add(next.getId());
    }
   
    Object response= invokeServerMethod(theMethodParams);
    IBundleProvider retVal = toResourceList(response);
   
    if (retVal.size() != resources.size()) {
      throw new InternalErrorException("Transaction bundle contained " + resources.size() + " entries, but server method response contained " + retVal.size() + " entries (must be the same)");
    }
   
    List<IResource> retResources = retVal.getResources(0, retVal.size());
    for (int i =0; i < resources.size(); i++) {
      IdDt oldId = oldIds.get(i);
      IResource newRes = retResources.get(i);
      if (newRes.getId() == null || newRes.getId().isEmpty()) {
        throw new InternalErrorException("Transaction method returned resource at index " + i + " with no id specified - IResource#setId(IdDt)");
View Full Code Here


      theMethodParams[myIdParamIndex] = theRequest.getId();
    }

    Object response = invokeServerMethod(theMethodParams);

    final IBundleProvider resources = toResourceList(response);
   
    /*
     * We wrap the response so we can verify that it has the ID and version set,
     * as is the contract for history
     */
    return new IBundleProvider() {
     
      @Override
      public int size() {
        return resources.size();
      }
     
      @Override
      public List<IResource> getResources(int theFromIndex, int theToIndex) {
        List<IResource> retVal = resources.getResources(theFromIndex, theToIndex);
        int index = theFromIndex;
        for (IResource nextResource : retVal) {
          if (nextResource.getId() == null || isBlank(nextResource.getId().getIdPart())) {
            throw new InternalErrorException("Server provided resource at index " + index + " with no ID set (using IResource#setId(IdDt))");
          }
          if (isBlank(nextResource.getId().getVersionIdPart())) {
            IdDt versionId = (IdDt) ResourceMetadataKeyEnum.VERSION_ID.get(nextResource);
            if (versionId == null || versionId.isEmpty()) {
              throw new InternalErrorException("Server provided resource at index " + index + " with no Version ID set (using IResource#setId(IdDt))");
            }
          }
          index++;
        }
        return retVal;
      }
     
      @Override
      public InstantDt getPublished() {
        return resources.getPublished();
      }
    };
  }
View Full Code Here

    Integer count = RestfulServer.extractCountParameter(theRequest.getServletRequest());

    boolean respondGzip=theRequest.isRespondGzip();

    IBundleProvider result = invokeServer(theRequest, params);
    switch (getReturnType()) {
    case BUNDLE:
      RestfulServer.streamResponseAsBundle(theServer, theResponse, result, responseEncoding, theRequest.getFhirServerBase(), theRequest.getCompleteUrl(), prettyPrint, requestIsBrowser, narrativeMode, 0, count, null, respondGzip);
      break;
    case RESOURCE:
      if (result.size() == 0) {
        throw new ResourceNotFoundException(theRequest.getId());
      } else if (result.size() > 1) {
        throw new InternalErrorException("Method returned multiple resources");
      }
      RestfulServer.streamResponseAsResource(theServer, theResponse, result.getResources(0, 1).get(0), responseEncoding, prettyPrint, requestIsBrowser, narrativeMode, respondGzip);
      break;
    }
  }
View Full Code Here

    Integer count = RestfulServer.extractCountParameter(theRequest.getServletRequest());

    boolean respondGzip = theRequest.isRespondGzip();

    HttpServletResponse response = theRequest.getServletResponse();
    IBundleProvider result = invokeServer(theRequest, params);
    switch (getReturnType()) {
    case BUNDLE:

      Bundle bundle = RestfulServer.createBundleFromBundleProvider(theServer, response, result, responseEncoding, theRequest.getFhirServerBase(), theRequest.getCompleteUrl(), prettyPrint, requestIsBrowser, narrativeMode, 0, count, null);

      for (int i = theServer.getInterceptors().size() - 1; i >= 0; i--) {
        IServerInterceptor next = theServer.getInterceptors().get(i);
        boolean continueProcessing = next.outgoingResponse(theRequest, bundle, theRequest.getServletRequest(), theRequest.getServletResponse());
        if (!continueProcessing) {
          return;
        }
      }

      RestfulServer.streamResponseAsBundle(theServer, response, bundle, responseEncoding, theRequest.getFhirServerBase(), prettyPrint, narrativeMode, respondGzip);
      break;
    case RESOURCE:
      if (result.size() == 0) {
        throw new ResourceNotFoundException(theRequest.getId());
      } else if (result.size() > 1) {
        throw new InternalErrorException("Method returned multiple resources");
      }

      IResource resource = result.getResources(0, 1).get(0);

      for (int i = theServer.getInterceptors().size() - 1; i >= 0; i--) {
        IServerInterceptor next = theServer.getInterceptors().get(i);
        boolean continueProcessing = next.outgoingResponse(theRequest, resource, theRequest.getServletRequest(), theRequest.getServletResponse());
        if (!continueProcessing) {
View Full Code Here

      oldIds.put(next, next.getId());
    }

    // Call the server implementation method
    Object response = invokeServerMethod(theMethodParams);
    IBundleProvider retVal = toResourceList(response);

    /*
    int offset = 0;
    if (retVal.size() != resources.size()) {
      if (retVal.size() > 0 && retVal.getResources(0, 1).get(0) instanceof OperationOutcome) {
        offset = 1;
      } else {
        throw new InternalErrorException("Transaction bundle contained " + resources.size() + " entries, but server method response contained " + retVal.size() + " entries (must be the same)");
      }
    }
     */
   
    List<IResource> retResources = retVal.getResources(0, retVal.size());
    for (int i = 0; i < retResources.size(); i++) {
      IdDt oldId = oldIds.get(retResources.get(i));
      IResource newRes = retResources.get(i);
      if (newRes.getId() == null || newRes.getId().isEmpty()) {
        if (!(newRes instanceof OperationOutcome)) {
View Full Code Here

      theMethodParams[myIdParamIndex] = theRequest.getId();
    }

    Object response = invokeServerMethod(theMethodParams);

    final IBundleProvider resources = toResourceList(response);
   
    /*
     * We wrap the response so we can verify that it has the ID and version set,
     * as is the contract for history
     */
    return new IBundleProvider() {
     
      @Override
      public int size() {
        return resources.size();
      }
     
      @Override
      public List<IResource> getResources(int theFromIndex, int theToIndex) {
        List<IResource> retVal = resources.getResources(theFromIndex, theToIndex);
        int index = theFromIndex;
        for (IResource nextResource : retVal) {
          if (nextResource.getId() == null || isBlank(nextResource.getId().getIdPart())) {
            throw new InternalErrorException("Server provided resource at index " + index + " with no ID set (using IResource#setId(IdDt))");
          }
          if (isBlank(nextResource.getId().getVersionIdPart())) {
            IdDt versionId = (IdDt) ResourceMetadataKeyEnum.VERSION_ID.get(nextResource);
            if (versionId == null || versionId.isEmpty()) {
              throw new InternalErrorException("Server provided resource at index " + index + " with no Version ID set (using IResource#setId(IdDt))");
            }
          }
          index++;
        }
        return retVal;
      }
     
      @Override
      public InstantDt getPublished() {
        return resources.getPublished();
      }
    };
  }
View Full Code Here

    Integer count = RestfulServer.extractCountParameter(theRequest.getServletRequest());

    boolean respondGzip = theRequest.isRespondGzip();

    IBundleProvider result = invokeServer(theRequest, params);
    switch (getReturnType()) {
    case BUNDLE:
      RestfulServer.streamResponseAsBundle(theServer, theResponse, result, responseEncoding, theRequest.getFhirServerBase(), theRequest.getCompleteUrl(), prettyPrint, requestIsBrowser, narrativeMode, 0, count, null, respondGzip);
      break;
    case RESOURCE:
      if (result.size() == 0) {
        throw new ResourceNotFoundException(theRequest.getId());
      } else if (result.size() > 1) {
        throw new InternalErrorException("Method returned multiple resources");
      }
      RestfulServer.streamResponseAsResource(theServer, theResponse, result.getResources(0, 1).get(0), responseEncoding, prettyPrint, requestIsBrowser, narrativeMode, respondGzip, theRequest.getFhirServerBase());
      break;
    }
  }
View Full Code Here

    for (IResource next : resources) {
      oldIds.add(next.getId());
    }
   
    Object response= invokeServerMethod(theMethodParams);
    IBundleProvider retVal = toResourceList(response);
   
    if (retVal.size() != resources.size()) {
      throw new InternalErrorException("Transaction bundle contained " + resources.size() + " entries, but server method response contained " + retVal.size() + " entries (must be the same)");
    }
   
    List<IResource> retResources = retVal.getResources(0, retVal.size());
    for (int i =0; i < resources.size(); i++) {
      IdDt oldId = oldIds.get(i);
      IResource newRes = retResources.get(i);
      if (newRes.getId() == null || newRes.getId().isEmpty()) {
        throw new InternalErrorException("Transaction method returned resource at index " + i + " with no id specified - IResource#setId(IdDt)");
View Full Code Here

      theMethodParams[myIdParamIndex] = theRequest.getId();
    }

    Object response = invokeServerMethod(theMethodParams);

    final IBundleProvider resources = toResourceList(response);
   
    /*
     * We wrap the response so we can verify that it has the ID and version set,
     * as is the contract for history
     */
    return new IBundleProvider() {
     
      @Override
      public int size() {
        return resources.size();
      }
     
      @Override
      public List<IResource> getResources(int theFromIndex, int theToIndex) {
        List<IResource> retVal = resources.getResources(theFromIndex, theToIndex);
        int index = theFromIndex;
        for (IResource nextResource : retVal) {
          if (nextResource.getId() == null || isBlank(nextResource.getId().getIdPart())) {
            throw new InternalErrorException("Server provided resource at index " + index + " with no ID set (using IResource#setId(IdDt))");
          }
          if (isBlank(nextResource.getId().getVersionIdPart())) {
            IdDt versionId = (IdDt) ResourceMetadataKeyEnum.VERSION_ID.get(nextResource);
            if (versionId == null || versionId.isEmpty()) {
              throw new InternalErrorException("Server provided resource at index " + index + " with no Version ID set (using IResource#setId(IdDt))");
            }
          }
          index++;
        }
        return retVal;
      }
     
      @Override
      public InstantDt getPublished() {
        return resources.getPublished();
      }
    };
  }
View Full Code Here

TOP

Related Classes of ca.uhn.fhir.rest.server.IBundleProvider

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.