org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties.ODataEntityProviderPropertiesBuilder Java Examples

The following examples show how to use org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties.ODataEntityProviderPropertiesBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ODataJPAResponseBuilderDefault.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private static EntityProviderWriteProperties getEntityProviderProperties(final ODataJPAContext odataJPAContext,
    final GetEntityUriInfo resultsView) throws ODataJPARuntimeException {
  ODataEntityProviderPropertiesBuilder entityFeedPropertiesBuilder = null;
  ExpandSelectTreeNode expandSelectTree = null;
  try {
    entityFeedPropertiesBuilder =
        EntityProviderWriteProperties.serviceRoot(odataJPAContext.getODataContext().getPathInfo().getServiceRoot());
    expandSelectTree = UriParser.createExpandSelectTree(resultsView.getSelect(), resultsView.getExpand());
    entityFeedPropertiesBuilder.expandSelectTree(expandSelectTree);
    entityFeedPropertiesBuilder.callbacks(JPAExpandCallBack.getCallbacks(odataJPAContext.getODataContext()
        .getPathInfo().getServiceRoot(), expandSelectTree, resultsView.getExpand()));
  } catch (ODataException e) {
    throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
  }

  return entityFeedPropertiesBuilder.build();
}
 
Example #2
Source File: ODataJPAResponseBuilderDefault.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private static EntityProviderWriteProperties getEntityProviderPropertiesforPost(
    final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException {
  ODataEntityProviderPropertiesBuilder entityFeedPropertiesBuilder = null;
  try {
    entityFeedPropertiesBuilder =
        EntityProviderWriteProperties.serviceRoot(odataJPAContext.getODataContext().getPathInfo().getServiceRoot());
  } catch (ODataException e) {
    throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
  }

  return entityFeedPropertiesBuilder.build();
}
 
Example #3
Source File: JPAExpandCallBack.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private EntityProviderWriteProperties getInlineEntityProviderProperties(final WriteCallbackContext context)
    throws EdmException {
  ODataEntityProviderPropertiesBuilder propertiesBuilder = EntityProviderWriteProperties.serviceRoot(baseUri);
  propertiesBuilder.callbacks(getCallbacks(baseUri, context.getCurrentExpandSelectTreeNode(), expandList));
  propertiesBuilder.expandSelectTree(context.getCurrentExpandSelectTreeNode());
  return propertiesBuilder.build();
}
 
Example #4
Source File: Processor.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public ODataResponse readEntityLinks(GetEntitySetLinksUriInfo uri_info, String content_type)
      throws ODataException
{
   // Target of the link to create
   EdmEntitySet link_target_es = uri_info.getTargetEntitySet();

   // Gets the entityset containing the navigation link to `link_target_es`
   //EdmEntitySet  target_es = getLinkFromES(new AdaptableUriInfo(uri_info));
   //EdmEntityType target_et = target_es.getEntityType();

   // Gets the `collection` part of the URI.
   KeyPredicate start_kp =
      (uri_info.getKeyPredicates().isEmpty()) ? null : uri_info.getKeyPredicates().get(0);

   boolean do_pagination = false;
   // force pagination on products and when $skip and/or $top are provided
   if (link_target_es.getName().equals(Model.PRODUCT.getName()) ||
       uri_info.getSkip() != null || uri_info.getTop()!= null)
   {
      do_pagination = true;
   }

   Map results = Navigator.<Map>navigate(uri_info.getStartEntitySet(), start_kp,
         uri_info.getNavigationSegments(), Map.class);

   if (!(results instanceof SubMap))
   {
      do_pagination = false;
   }

   int maxrows = CONFIGURATION_MANAGER.getOdataConfiguration().getMaxRows();

   int skip = (uri_info.getSkip() == null) ? 0 : uri_info.getSkip();
   int top = (uri_info.getTop() == null) ? maxrows : uri_info.getTop();
   FilterExpression filter = uri_info.getFilter();
   if (do_pagination && (filter != null || skip != 0 || top != 0))
   {
      SubMapBuilder smb = ((SubMap) results).getSubMapBuilder();
      smb.setFilter(filter);
      smb.setSkip(skip);
      smb.setTop(top);
      results = smb.build();
   }

   // Feeds the EntitySetResponseBuilder.
   List<Map<String, Object>> building = new ArrayList<>();
   Iterator<AbstractEntity> it = results.values().iterator();
   int i;
   for (i = 0; it.hasNext() && (!do_pagination || i<top) ; i++)
   {
      building.add(it.next().toEntityResponse(makeLink().toString()));
   }

   ODataEntityProviderPropertiesBuilder builder
         = EntityProviderWriteProperties.serviceRoot(makeLink());

   // Creates the `next` link.
   if (do_pagination && i == top && it.hasNext())
   {
      i += skip;
      builder.nextLink(makeNextLink(i));
   }

   if (it instanceof Closeable)
   {
      try
      {
         ((Closeable) it).close();
      }
      catch (IOException e)
      {
         LOGGER.warn("Cannot close iterator:", e);
      }
   }

   return EntityProvider.writeLinks(content_type, link_target_es, building, builder.build());
}
 
Example #5
Source File: ODataJPAResponseBuilderDefault.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private static EntityProviderWriteProperties getEntityProviderProperties(final ODataJPAContext odataJPAContext,
    final GetEntitySetUriInfo resultsView, final List<Map<String, Object>> edmEntityList)
    throws ODataJPARuntimeException {
  ODataEntityProviderPropertiesBuilder entityFeedPropertiesBuilder = null;
  ODataContext context = odataJPAContext.getODataContext();

  Integer count = null;
  if (resultsView.getInlineCount() != null) {
     count = getInlineCountForNonFilterQueryEntitySet(edmEntityList, resultsView);
  }

  try {
    PathInfo pathInfo = context.getPathInfo();
    URI serviceRoot = pathInfo.getServiceRoot();

    entityFeedPropertiesBuilder =
        EntityProviderWriteProperties.serviceRoot(pathInfo.getServiceRoot());
    JPAPaging paging = odataJPAContext.getPaging();
    if (odataJPAContext.getPageSize() > 0 && paging != null && paging.getNextPage() > 0) {
      String nextLink =
          serviceRoot.relativize(pathInfo.getRequestUri()).toString();
      nextLink = percentEncodeNextLink(nextLink);
      nextLink += (nextLink != null ? nextLink.contains("?") ? "&" : "?" : "?")
          + "$skiptoken=" + odataJPAContext.getPaging().getNextPage();
      entityFeedPropertiesBuilder.nextLink(nextLink);
    }
    entityFeedPropertiesBuilder.inlineCount(count);
    entityFeedPropertiesBuilder.inlineCountType(resultsView.getInlineCount());
    ExpandSelectTreeNode expandSelectTree =
        UriParser.createExpandSelectTree(resultsView.getSelect(), resultsView.getExpand());

    Map<String, ODataCallback> expandCallBack =
        JPAExpandCallBack.getCallbacks(serviceRoot, expandSelectTree, resultsView.getExpand());

    Map<String, ODataCallback> callBackMap = new HashMap<String, ODataCallback>();
    callBackMap.putAll(expandCallBack);

    String deltaToken = ODataJPATombstoneContext.getDeltaToken();
    if (deltaToken != null) {
      callBackMap.put(TombstoneCallback.CALLBACK_KEY_TOMBSTONE, new JPATombstoneCallBack(serviceRoot.toString(),
          resultsView, deltaToken));
    }

    entityFeedPropertiesBuilder.callbacks(callBackMap);
    entityFeedPropertiesBuilder.expandSelectTree(expandSelectTree);

  } catch (ODataException e) {
    throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
  }

  return entityFeedPropertiesBuilder.build();
}