public ODataResponse readEntitySet()

in nuget-feed/src/jetbrains/buildServer/nuget/feed/server/olingo/processor/NuGetPackagesProcessor.java [61:138]


  public ODataResponse readEntitySet(final GetEntitySetUriInfo uriInfo, final String contentType)
    throws ODataException {
    final ODataContext context = getContext();
    final PathInfo pathInfo = context.getPathInfo();
    final URI rootUrlWithAuthenticationType = getRootUrlWithAuthenticationType(context);

    List<V2FeedPackage> data = new ArrayList<>();

    try {
      data.addAll(CollectionsUtil.convertCollection((List<?>) retrieveData(
        uriInfo.getStartEntitySet(),
        uriInfo.getKeyPredicates(),
        uriInfo.getFunctionImport(),
        mapFunctionParameters(uriInfo.getFunctionImportParameters()),
        uriInfo.getCustomQueryOptions()
      ), source -> NuGetMapper.mapPackage((NuGetIndexEntry) source, rootUrlWithAuthenticationType)));
    } catch (final ODataNotFoundException e) {
      LOG.infoAndDebugDetails("Package not found", e);
      data.clear();
    }

    final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
    final InlineCount inlineCountType = uriInfo.getInlineCount();
    final Integer count = applySystemQueryOptions(
      entitySet,
      data,
      uriInfo.getFilter(),
      inlineCountType,
      uriInfo.getOrderBy(),
      getSkipToken(uriInfo),
      uriInfo.getSkip(),
      uriInfo.getTop());


    String nextLink = null;

    // Limit the number of returned entities and provide a "next" link
    // if there are further entities.
    // Almost all system query options in the current request must be carried
    // over to the URI for the "next" link, with the exception of $skiptoken
    // and $skip.
    if (data.size() > SERVER_PAGING_SIZE) {
      if (uriInfo.getOrderBy() == null
        && getSkipToken(uriInfo) == null
        && uriInfo.getSkip() == null
        && uriInfo.getTop() == null) {
        sortInDefaultOrder(entitySet, data);
      }

      nextLink = pathInfo.getRequestUri().toString();
      nextLink = percentEncodeNextLink(nextLink);

      nextLink += (nextLink.contains("?") ? "&" : "?")
        + "$skiptoken=" + getSkipToken(entitySet, data.get(SERVER_PAGING_SIZE - 1));

      data = data.subList(0, Math.min(data.size(), SERVER_PAGING_SIZE));
    }

    final EdmEntityType entityType = entitySet.getEntityType();
    final List<Map<String, Object>> values = new ArrayList<>();
    for (final Object entryData : data) {
      values.add(getStructuralTypeValueMap(entryData, entityType));
    }

    final EntityProviderWriteProperties feedProperties = EntityProviderWriteProperties
      .serviceRoot(pathInfo.getServiceRoot())
      .inlineCountType(inlineCountType)
      .inlineCount(count)
      .expandSelectTree(UriParser.createExpandSelectTree(uriInfo.getSelect(), uriInfo.getExpand()))
      .nextLink(nextLink)
      .build();

    final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeFeed");
    final ODataResponse response = EntityProvider.writeFeed(contentType, entitySet, values, feedProperties);
    context.stopRuntimeMeasurement(timingHandle);

    return ODataResponse.fromResponse(response).build();
  }