public Map<String, List<String>> getAllNavigationUUIDColumns(UriInfo uriInfo) throws EdmException{ Map<String, List<String>> navigationsUUIDs = new HashMap<>(); if(uriInfo.getEntityContainer() == null){ return navigationsUUIDs; } List<EdmEntitySet> entitySets = uriInfo.getEntityContainer().getEntitySets(); for(int i=0; i<entitySets.size(); i++){ EdmEntitySet entitySet = entitySets.get(i); EdmEntityType entityType = entitySet.getEntityType(); List<String> navigationProperties = entityType.getNavigationPropertyNames(); for(int j=0; j<navigationProperties.size(); j++){ EdmNavigationProperty navigationProperty = (EdmNavigationProperty) entityType.getProperty(navigationProperties.get(j)); EdmEntitySet navigatedEntitySet = entitySet.getRelatedEntitySet(navigationProperty); navigationsUUIDs.put(navigationProperty.getName(), this.getNavigationUUIDColumns(navigatedEntitySet)); } } return navigationsUUIDs; }
private void appendAdditinalLinks(final XMLStreamWriter writer, final EntityInfoAggregator eia, final Map<String, Object> data) throws EntityProviderException, EdmException, URISyntaxException { final Map<String, Map<String, Object>> links = properties.getAdditionalLinks(); if (links != null && !links.isEmpty()) { for (Entry<String, Map<String, Object>> entry : links.entrySet()) { Map<String, Object> navigationKeyMap = entry.getValue(); final boolean isFeed = (eia.getNavigationPropertyInfo(entry.getKey()).getMultiplicity() == EdmMultiplicity.MANY); if (navigationKeyMap != null && !navigationKeyMap.isEmpty()) { final EntityInfoAggregator targetEntityInfo = EntityInfoAggregator.create( eia.getEntitySet().getRelatedEntitySet( (EdmNavigationProperty) eia.getEntityType().getProperty(entry.getKey()))); appendAtomNavigationLink(writer, createSelfLink(targetEntityInfo, navigationKeyMap, null), entry.getKey(), isFeed, eia, data); } } } }
private void appendAdditinalLinks(final XMLStreamWriter writer, final EntityInfoAggregator eia, final Map<String, Object> data) throws EntityProviderException, EdmException, URISyntaxException { final Map<String, Map<String, Object>> links = properties.getAdditionalLinks(); if (links != null && !links.isEmpty()) { for (Entry<String, Map<String, Object>> entry : links.entrySet()) { Map<String, Object> navigationKeyMap = entry.getValue(); final boolean isFeed = (eia.getNavigationPropertyInfo(entry.getKey()).getMultiplicity() == EdmMultiplicity.MANY); if (navigationKeyMap != null && !navigationKeyMap.isEmpty()) { final EntityInfoAggregator targetEntityInfo = EntityInfoAggregator.create( eia.getEntitySet().getRelatedEntitySet( (EdmNavigationProperty) eia.getEntityType().getProperty(entry.getKey()))); appendAtomNavigationLink(writer, createSelfLink(targetEntityInfo, navigationKeyMap, null), entry.getKey(), isFeed, eia, data); } } } }
private Object readRelatedData(final WriteCallbackContext context) throws ODataException { final EdmEntitySet entitySet = context.getSourceEntitySet(); return dataSource.readRelatedData( entitySet, data instanceof List ? readEntryData((List<?>) data, entitySet.getEntityType(), context .extractKeyFromEntryData()) : data, entitySet.getRelatedEntitySet(context.getNavigationProperty()), Collections.<String, Object> emptyMap()); }
private Object readRelatedData(final WriteCallbackContext context) throws ODataException { final EdmEntitySet entitySet = context.getSourceEntitySet(); return dataSource.readRelatedData( entitySet, data instanceof List ? readEntryData((List<?>) data, entitySet.getEntityType(), context .extractKeyFromEntryData()) : data, entitySet.getRelatedEntitySet(context.getNavigationProperty()), Collections.<String, Object> emptyMap()); }
private Object readRelatedData(final WriteCallbackContext context) throws ODataException { final EdmEntitySet entitySet = context.getSourceEntitySet(); return dataSource.readRelatedData( entitySet, data instanceof List ? readEntryData((List<?>) data, entitySet.getEntityType(), context .extractKeyFromEntryData()) : data, entitySet.getRelatedEntitySet(context.getNavigationProperty()), Collections.<String, Object> emptyMap()); }
private String createCustomTargetLink(final EntityInfoAggregator entityInfo, final String navigationPropertyName, final Map<String, Object> key) throws EntityProviderException, EdmException { String target; final EntityInfoAggregator targetEntityInfo = EntityInfoAggregator.create( entityInfo.getEntitySet().getRelatedEntitySet( (EdmNavigationProperty) entityInfo.getEntityType().getProperty(navigationPropertyName))); target = (properties.getServiceRoot() == null ? "" : properties.getServiceRoot().toASCIIString()) + AtomEntryEntityProducer.createSelfLink(targetEntityInfo, key, null); return target; }
private String createCustomTargetLink(final EntityInfoAggregator entityInfo, final String navigationPropertyName, final Map<String, Object> key) throws EntityProviderException, EdmException { String target; final EntityInfoAggregator targetEntityInfo = EntityInfoAggregator.create( entityInfo.getEntitySet().getRelatedEntitySet( (EdmNavigationProperty) entityInfo.getEntityType().getProperty(navigationPropertyName))); target = (properties.getServiceRoot() == null ? "" : properties.getServiceRoot().toASCIIString()) + AtomEntryEntityProducer.createSelfLink(targetEntityInfo, key, null); return target; }
private String createCustomTargetLink(final EntityInfoAggregator entityInfo, final String navigationPropertyName, final Map<String, Object> key) throws EntityProviderException, EdmException { String target; final EntityInfoAggregator targetEntityInfo = EntityInfoAggregator.create( entityInfo.getEntitySet().getRelatedEntitySet( (EdmNavigationProperty) entityInfo.getEntityType().getProperty(navigationPropertyName))); target = (properties.getServiceRoot() == null ? "" : properties.getServiceRoot().toASCIIString()) + AtomEntryEntitySerializer.createSelfLink(targetEntityInfo, key, null, properties.isKeyAutoGenerated(), false); return target; }
private void appendInlineEntry(final XMLStreamWriter writer, final String navigationPropertyName, final EntityInfoAggregator eia, final Entity data) throws EntityProviderException, XMLStreamException, EdmException { if (data.getNavigations() != null && data.getNavigations().containsKey(navigationPropertyName)) { EdmNavigationProperty navProp = (EdmNavigationProperty) eia.getEntityType().getProperty(navigationPropertyName); Entity inlineData = (Entity) data.getNavigation(navigationPropertyName); if ((inlineData == null) || inlineData.getProperties().size() == 0) { return; } writer.writeStartElement(Edm.NAMESPACE_M_2007_08, FormatXml.M_INLINE); if (inlineData != null && !(inlineData.getProperties().isEmpty())) { inlineData.setWriteProperties(inlineData.getWriteProperties() == null ? data.getWriteProperties() : inlineData .getWriteProperties()); EdmEntitySet inlineEntitySet = eia.getEntitySet().getRelatedEntitySet(navProp); AtomEntryEntitySerializer inlineProducer = new AtomEntryEntitySerializer(inlineData.getWriteProperties()); EntityInfoAggregator inlineEia = EntityInfoAggregator.create(inlineEntitySet, null); inlineProducer.append(writer, inlineEia, inlineData, false, false); } writer.writeEndElement(); } }
private void appendAtomNavigationLinks(final XMLStreamWriter writer, final EntityInfoAggregator eia, final Map<String, Object> data) throws EntityProviderException, EdmException, URISyntaxException { for (String name : eia.getSelectedNavigationPropertyNames()) { final boolean isFeed = (eia.getNavigationPropertyInfo(name).getMultiplicity() == EdmMultiplicity.MANY); final Map<String, Map<String, Object>> links = properties.getAdditionalLinks(); final Map<String, Object> key = links == null ? null : links.get(name); if (key == null || key.isEmpty()) { appendAtomNavigationLink(writer, createSelfLink(eia, data, name), name, isFeed, eia, data); } else { final EntityInfoAggregator targetEntityInfo = EntityInfoAggregator.create( eia.getEntitySet().getRelatedEntitySet((EdmNavigationProperty) eia.getEntityType().getProperty(name))); appendAtomNavigationLink(writer, createSelfLink(targetEntityInfo, key, null), name, isFeed, eia, data); } } }
private void appendAtomNavigationLinks(final XMLStreamWriter writer, final EntityInfoAggregator eia, final Map<String, Object> data) throws EntityProviderException, EdmException, URISyntaxException { for (String name : eia.getSelectedNavigationPropertyNames()) { final boolean isFeed = (eia.getNavigationPropertyInfo(name).getMultiplicity() == EdmMultiplicity.MANY); final Map<String, Map<String, Object>> links = properties.getAdditionalLinks(); final Map<String, Object> key = links == null ? null : links.get(name); if (key == null || key.isEmpty()) { appendAtomNavigationLink(writer, createSelfLink(eia, data, name), name, isFeed, eia, data); } else { final EntityInfoAggregator targetEntityInfo = EntityInfoAggregator.create( eia.getEntitySet().getRelatedEntitySet((EdmNavigationProperty) eia.getEntityType().getProperty(name))); appendAtomNavigationLink(writer, createSelfLink(targetEntityInfo, key, null), name, isFeed, eia, data); } } }
public static EdmEntitySet getEdmEntitySet(final UriInfo uriInfo, Locale locale) throws ODataException { EdmEntitySet entitySet = null; // First must be an entity or a function import. if (uriInfo.getStartEntitySet() != null) { entitySet = uriInfo.getStartEntitySet(); } else if (uriInfo.getFunctionImport() != null) { entitySet = uriInfo.getFunctionImport().getEntitySet(); } else { throw new ODataApplicationException("INVALID_RESOURCE_TYPE", locale, HttpStatusCodes.NOT_IMPLEMENTED, "INVALID_RESOURCE_TYPE_CODE"); } int navigationCount = 0; while (entitySet != null && navigationCount < uriInfo.getNavigationSegments().size()) { final NavigationSegment uriResourceNavigation = uriInfo.getNavigationSegments().get(navigationCount); try { if(entitySet.getRelatedEntitySet(uriResourceNavigation.getNavigationProperty()) == null) { entitySet.getEntityContainer().getEntitySet(uriResourceNavigation.getNavigationProperty().getType().getName()); break; }else { entitySet = entitySet.getRelatedEntitySet(uriResourceNavigation.getNavigationProperty()); } } catch (EdmException e) { throw new ODataApplicationException("NAVIGATION_NOT_SUPPORTED", locale, HttpStatusCodes.NOT_IMPLEMENTED, "NAVIGATION_NOT_SUPPORTED_CODE", e); } navigationCount++; } return entitySet; } }
private void addNavigationSegment(final String keyPredicateName, final EdmNavigationProperty navigationProperty) throws UriSyntaxException, EdmException { final EdmEntitySet targetEntitySet = uriResult.getTargetEntitySet().getRelatedEntitySet(navigationProperty); final EdmEntityType targetEntityType = targetEntitySet.getEntityType(); uriResult.setTargetEntitySet(targetEntitySet); uriResult.setTargetType(targetEntityType); NavigationSegmentImpl navigationSegment = new NavigationSegmentImpl(); navigationSegment.setEntitySet(targetEntitySet); navigationSegment.setNavigationProperty(navigationProperty); if (keyPredicateName != null) { navigationSegment.setKeyPredicates(parseKey(keyPredicateName, targetEntityType)); } uriResult.addNavigationSegment(navigationSegment); }
private void addNavigationSegment(final String keyPredicateName, final EdmNavigationProperty navigationProperty) throws UriSyntaxException, EdmException { final EdmEntitySet targetEntitySet = uriResult.getTargetEntitySet().getRelatedEntitySet(navigationProperty); final EdmEntityType targetEntityType = targetEntitySet.getEntityType(); uriResult.setTargetEntitySet(targetEntitySet); uriResult.setTargetType(targetEntityType); NavigationSegmentImpl navigationSegment = new NavigationSegmentImpl(); navigationSegment.setEntitySet(targetEntitySet); navigationSegment.setNavigationProperty(navigationProperty); if (keyPredicateName != null) { navigationSegment.setKeyPredicates(parseKey(keyPredicateName, targetEntityType)); } uriResult.addNavigationSegment(navigationSegment); }
private void addNavigationSegment(final String keyPredicateName, final EdmNavigationProperty navigationProperty) throws UriSyntaxException, EdmException { final EdmEntitySet targetEntitySet = uriResult.getTargetEntitySet().getRelatedEntitySet(navigationProperty); final EdmEntityType targetEntityType = targetEntitySet.getEntityType(); uriResult.setTargetEntitySet(targetEntitySet); uriResult.setTargetType(targetEntityType); NavigationSegmentImpl navigationSegment = new NavigationSegmentImpl(); navigationSegment.setEntitySet(targetEntitySet); navigationSegment.setNavigationProperty(navigationProperty); if (keyPredicateName != null) { navigationSegment.setKeyPredicates(parseKey(keyPredicateName, targetEntityType)); } uriResult.addNavigationSegment(navigationSegment); }
@Override public WriteFeedCallbackResult retrieveFeedResult(final WriteFeedCallbackContext context) throws ODataApplicationException { try { final EdmEntityType entityType = context.getSourceEntitySet().getRelatedEntitySet(context.getNavigationProperty()).getEntityType(); List<Map<String, Object>> values = new ArrayList<Map<String, Object>>(); Object relatedData = null; try { relatedData = readRelatedData(context); for (final Object entryData : (List<?>) relatedData) { values.add(getStructuralTypeValueMap(entryData, entityType)); } } catch (final ODataNotFoundException e) { values.clear(); } WriteFeedCallbackResult result = new WriteFeedCallbackResult(); result.setFeedData(values); EntityProviderWriteProperties inlineProperties = EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).callbacks( getCallbacks(relatedData, entityType)).expandSelectTree(context.getCurrentExpandSelectTreeNode()) .selfLink(context.getSelfLink()).build(); result.setInlineProperties(inlineProperties); return result; } catch (final ODataException e) { throw new ODataApplicationException(e.getLocalizedMessage(), Locale.ROOT, e); } }
@Override public WriteEntryCallbackResult retrieveEntryResult(final WriteEntryCallbackContext context) throws ODataApplicationException { try { final EdmEntityType entityType = context.getSourceEntitySet().getRelatedEntitySet(context.getNavigationProperty()).getEntityType(); WriteEntryCallbackResult result = new WriteEntryCallbackResult(); Object relatedData; try { relatedData = readRelatedData(context); } catch (final ODataNotFoundException e) { relatedData = null; } if (relatedData == null) { result.setEntryData(Collections.<String, Object> emptyMap()); } else { result.setEntryData(getStructuralTypeValueMap(relatedData, entityType)); EntityProviderWriteProperties inlineProperties = EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).callbacks( getCallbacks(relatedData, entityType)).expandSelectTree(context.getCurrentExpandSelectTreeNode()) .build(); result.setInlineProperties(inlineProperties); } return result; } catch (final ODataException e) { throw new ODataApplicationException(e.getLocalizedMessage(), Locale.ROOT, e); } }
@Override public WriteEntryCallbackResult retrieveEntryResult(final WriteEntryCallbackContext context) throws ODataApplicationException { try { final EdmEntityType entityType = context.getSourceEntitySet().getRelatedEntitySet(context.getNavigationProperty()).getEntityType(); WriteEntryCallbackResult result = new WriteEntryCallbackResult(); Object relatedData; try { relatedData = readRelatedData(context); } catch (final ODataNotFoundException e) { relatedData = null; } if (relatedData == null) { result.setEntryData(Collections.<String, Object> emptyMap()); } else { result.setEntryData(getStructuralTypeValueMap(relatedData, entityType)); EntityProviderWriteProperties inlineProperties = EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).callbacks( getCallbacks(relatedData, entityType)).expandSelectTree(context.getCurrentExpandSelectTreeNode()) .build(); result.setInlineProperties(inlineProperties); } return result; } catch (final ODataException e) { throw new ODataApplicationException(e.getLocalizedMessage(), Locale.ROOT, e); } }
@Override public WriteEntryCallbackResult retrieveEntryResult(final WriteEntryCallbackContext context) throws ODataApplicationException { try { final EdmEntityType entityType = context.getSourceEntitySet().getRelatedEntitySet(context.getNavigationProperty()).getEntityType(); WriteEntryCallbackResult result = new WriteEntryCallbackResult(); Object relatedData; try { relatedData = readRelatedData(context); } catch (final ODataNotFoundException e) { relatedData = null; } if (relatedData == null) { result.setEntryData(Collections.<String, Object> emptyMap()); } else { result.setEntryData(getStructuralTypeValueMap(relatedData, entityType)); EntityProviderWriteProperties inlineProperties = EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).callbacks( getCallbacks(relatedData, entityType)).expandSelectTree(context.getCurrentExpandSelectTreeNode()) .build(); result.setInlineProperties(inlineProperties); } return result; } catch (final ODataException e) { throw new ODataApplicationException(e.getLocalizedMessage(), Locale.ROOT, e); } }