Java Code Examples for org.apache.olingo.odata2.api.ep.EntityProvider#writeLinks()
The following examples show how to use
org.apache.olingo.odata2.api.ep.EntityProvider#writeLinks() .
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: Processor.java From DataHubSystem with GNU Affero General Public License v3.0 | 4 votes |
@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 2
Source File: ListsProcessor.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@Override public ODataResponse readEntityLinks(final GetEntitySetLinksUriInfo uriInfo, final String contentType) throws ODataException { ArrayList<Object> data = new ArrayList<Object>(); try { data.addAll((List<?>) retrieveData( uriInfo.getStartEntitySet(), uriInfo.getKeyPredicates(), uriInfo.getFunctionImport(), mapFunctionParameters(uriInfo.getFunctionImportParameters()), uriInfo.getNavigationSegments())); } catch (final ODataNotFoundException e) { data.clear(); } final Integer count = applySystemQueryOptions( uriInfo.getTargetEntitySet(), data, uriInfo.getFilter(), uriInfo.getInlineCount(), null, // uriInfo.getOrderBy(), uriInfo.getSkipToken(), uriInfo.getSkip(), uriInfo.getTop()); final EdmEntitySet entitySet = uriInfo.getTargetEntitySet(); List<Map<String, Object>> values = new ArrayList<Map<String, Object>>(); for (final Object entryData : data) { Map<String, Object> entryValues = new HashMap<String, Object>(); for (final EdmProperty property : entitySet.getEntityType().getKeyProperties()) { entryValues.put(property.getName(), valueAccess.getPropertyValue(entryData, property)); } values.add(entryValues); } ODataContext context = getContext(); final EntityProviderWriteProperties entryProperties = EntityProviderWriteProperties .serviceRoot(context.getPathInfo().getServiceRoot()) .inlineCountType(uriInfo.getInlineCount()) .inlineCount(count) .build(); final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeLinks"); final ODataResponse response = EntityProvider.writeLinks(contentType, entitySet, values, entryProperties); context.stopRuntimeMeasurement(timingHandle); return ODataResponse.fromResponse(response).build(); }
Example 3
Source File: ODataJPAResponseBuilderDefault.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@Override public ODataResponse build(final GetEntitySetLinksUriInfo resultsView, final List<Object> jpaEntities, final String contentType) throws ODataJPARuntimeException { EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; try { EdmEntitySet entitySet = resultsView.getTargetEntitySet(); edmEntityType = entitySet.getEntityType(); List<EdmProperty> keyProperties = edmEntityType.getKeyProperties(); List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); for (Object jpaEntity : jpaEntities) { edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, keyProperties); edmEntityList.add(edmPropertyValueMap); } Integer count = null; if (resultsView.getInlineCount() != null) { if ((resultsView.getSkip() != null || resultsView.getTop() != null)) { // when $skip and/or $top is present with $inlinecount count = getInlineCountForNonFilterQueryLinks(edmEntityList, resultsView); } else { // In all other cases count = resultsView.getInlineCount() == InlineCount.ALLPAGES ? edmEntityList.size() : null; } } ODataContext context = oDataJPAContext.getODataContext(); EntityProviderWriteProperties entryProperties = EntityProviderWriteProperties.serviceRoot(context.getPathInfo().getServiceRoot()).inlineCountType( resultsView.getInlineCount()).inlineCount(count).build(); odataResponse = EntityProvider.writeLinks(contentType, entitySet, edmEntityList, entryProperties); odataResponse = ODataResponse.fromResponse(odataResponse).build(); } catch (ODataException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } return odataResponse; }
Example 4
Source File: ListsProcessor.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@Override public ODataResponse readEntityLinks(final GetEntitySetLinksUriInfo uriInfo, final String contentType) throws ODataException { ArrayList<Object> data = new ArrayList<Object>(); try { data.addAll((List<?>) retrieveData( uriInfo.getStartEntitySet(), uriInfo.getKeyPredicates(), uriInfo.getFunctionImport(), mapFunctionParameters(uriInfo.getFunctionImportParameters()), uriInfo.getNavigationSegments())); } catch (final ODataNotFoundException e) { data.clear(); } final Integer count = applySystemQueryOptions( uriInfo.getTargetEntitySet(), data, uriInfo.getFilter(), uriInfo.getInlineCount(), null, // uriInfo.getOrderBy(), uriInfo.getSkipToken(), uriInfo.getSkip(), uriInfo.getTop()); final EdmEntitySet entitySet = uriInfo.getTargetEntitySet(); List<Map<String, Object>> values = new ArrayList<Map<String, Object>>(); for (final Object entryData : data) { Map<String, Object> entryValues = new HashMap<String, Object>(); for (final EdmProperty property : entitySet.getEntityType().getKeyProperties()) { entryValues.put(property.getName(), valueAccess.getPropertyValue(entryData, property)); } values.add(entryValues); } ODataContext context = getContext(); final EntityProviderWriteProperties entryProperties = EntityProviderWriteProperties .serviceRoot(context.getPathInfo().getServiceRoot()) .inlineCountType(uriInfo.getInlineCount()) .inlineCount(count) .build(); final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeLinks"); final ODataResponse response = EntityProvider.writeLinks(contentType, entitySet, values, entryProperties); context.stopRuntimeMeasurement(timingHandle); return ODataResponse.fromResponse(response).build(); }