@Override public ODataResponse writeFeed(EdmEntitySet entitySet, EntityCollection data) throws EntityProviderException { final EntityCollectionSerializerProperties properties = data == null ? EntityCollectionSerializerProperties.serviceRoot(null).build() : data.getCollectionProperties() == null ? EntityCollectionSerializerProperties.serviceRoot(null).build() : data.getCollectionProperties(); final EntityInfoAggregator entityInfo = EntityInfoAggregator.create(entitySet, null); CircleStreamBuffer buffer = new CircleStreamBuffer(); try { BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(buffer.getOutputStream(), DEFAULT_CHARSET)); new JsonFeedEntitySerializer(properties).appendAsObject(writer, entityInfo, data); writer.flush(); buffer.closeWrite(); return ODataResponse.entity(buffer.getInputStream()).build(); } catch (EntityProviderException e) { buffer.close(); throw e; } catch (Exception e) { buffer.close(); throw new EntityProviderProducerException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } }
private void appendInlineFeed(final XMLStreamWriter writer, final String navigationPropertyName, final EntityInfoAggregator eia, final Entity data) throws EntityProviderException, XMLStreamException, EdmException { if (eia.getNavigationPropertyNames().contains(navigationPropertyName) && data != null && data.getNavigations().containsKey(navigationPropertyName)) { EdmNavigationProperty navProp = (EdmNavigationProperty) eia.getEntityType().getProperty(navigationPropertyName); if (navProp == null) { throw new EntityProviderProducerException(EntityProviderException.EXPANDNOTSUPPORTED); } EntityCollection inlineData; inlineData = (EntityCollection) data.getNavigation(navigationPropertyName); if (inlineData == null) { inlineData = new EntityCollection(); } if (inlineData.getEntities().isEmpty()) { return; } writer.writeStartElement(Edm.NAMESPACE_M_2007_08, FormatXml.M_INLINE); EntityCollectionSerializerProperties inlineProperties = inlineData.getCollectionProperties() == null ? EntityCollectionSerializerProperties.serviceRoot(data.getWriteProperties().getServiceRoot()).build() : inlineData.getCollectionProperties(); EdmEntitySet inlineEntitySet = eia.getEntitySet().getRelatedEntitySet(navProp); AtomFeedSerializer inlineFeedProducer = new AtomFeedSerializer(inlineProperties); inlineData.setCollectionProperties(inlineProperties); EntityInfoAggregator inlineEia = EntityInfoAggregator.create(inlineEntitySet, null); inlineFeedProducer.append(writer, inlineEia, inlineData, true); writer.writeEndElement(); } }
@Override public ODataResponse writeFeed(EdmEntitySet entitySet, EntityCollection data) throws EntityProviderException { CircleStreamBuffer csb = new CircleStreamBuffer(); try { if(data == null){ throw new EntityProviderProducerException(EntityProviderException.NULL_VALUE); } OutputStream outStream = csb.getOutputStream(); XMLStreamWriter writer = XmlHelper.getXMLOutputFactory().createXMLStreamWriter(outStream, DEFAULT_CHARSET); writer.writeStartDocument(DEFAULT_CHARSET, XML_VERSION); EntityCollectionSerializerProperties properties = data.getCollectionProperties(); AtomFeedSerializer atomFeedProvider = new AtomFeedSerializer(properties); EntityInfoAggregator eia = EntityInfoAggregator.create(entitySet, null); atomFeedProvider.append(writer, eia, data, false); writer.flush(); csb.closeWrite(); return ODataResponse.entity(csb.getInputStream()).build(); } catch (EntityProviderException e) { csb.close(); throw e; } catch (XMLStreamException e) { csb.close(); throw new EntityProviderProducerException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } }
private void appendEntries(final XMLStreamWriter writer, final EntityInfoAggregator eia, final EntityCollection data) throws EntityProviderException { AtomEntryEntitySerializer entryProvider; for (Entity singleEntryData : data.getEntities()) { entryProvider = singleEntryData.getWriteProperties() == null? data.getGlobalEntityProperties() == null ? new AtomEntryEntitySerializer (EntitySerializerProperties.serviceRoot(data.getCollectionProperties().getServiceRoot()).build()) : new AtomEntryEntitySerializer(data.getGlobalEntityProperties()): new AtomEntryEntitySerializer(singleEntryData.getWriteProperties()); entryProvider.append(writer, eia, singleEntryData, false, true); } }
throw new EntityProviderException(EntityProviderException.NULL_VALUE); final EntityCollectionSerializerProperties inlineProperties = inlineData.getCollectionProperties() == null ? EntityCollectionSerializerProperties. serviceRoot(properties.getServiceRoot()).build() : inlineData.getCollectionProperties(); JsonFeedEntitySerializer jsonFeedEntityProducer = new JsonFeedEntitySerializer(inlineProperties); final EntityInfoAggregator inlineEntityInfo =