Java Code Examples for org.apache.olingo.odata2.api.ep.EntityProviderException#COMMON

The following examples show how to use org.apache.olingo.odata2.api.ep.EntityProviderException#COMMON . 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: AtomEntryEntityProducer.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private void appendAtomNavigationLink(final XMLStreamWriter writer, final String target,
    final String navigationPropertyName, final boolean isFeed, final EntityInfoAggregator eia,
    final Map<String, Object> data) throws EntityProviderException, EdmException, URISyntaxException {
  try {
    writer.writeStartElement(FormatXml.ATOM_LINK);
    writer.writeAttribute(FormatXml.ATOM_HREF, target);
    writer.writeAttribute(FormatXml.ATOM_REL, Edm.NAMESPACE_REL_2007_08 + navigationPropertyName);
    writer.writeAttribute(FormatXml.ATOM_TITLE, navigationPropertyName);
    if (isFeed) {
      writer.writeAttribute(FormatXml.ATOM_TYPE, ContentType.APPLICATION_ATOM_XML_FEED.toString());
      appendInlineFeed(writer, navigationPropertyName, eia, data, target);
    } else {
      writer.writeAttribute(FormatXml.ATOM_TYPE, ContentType.APPLICATION_ATOM_XML_ENTRY.toString());
      appendInlineEntry(writer, navigationPropertyName, eia, data);
    }
    writer.writeEndElement();
  } catch (XMLStreamException e) {
    throw new EntityProviderProducerException(EntityProviderException.COMMON, e);
  }
}
 
Example 2
Source File: ProviderFacadeImpl.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private static ContentTypeBasedEntityProvider create(final ContentType contentType) throws EntityProviderException {
  try {
    switch (contentType.getODataFormat()) {
    case ATOM:
    case XML:
      return new AtomEntityProvider(contentType.getODataFormat());
    case JSON:
      return new JsonEntityProvider();
    default:
      throw new ODataNotAcceptableException(ODataNotAcceptableException.NOT_SUPPORTED_CONTENT_TYPE
          .addContent(contentType));
    }
  } catch (final ODataNotAcceptableException e) {
    throw new EntityProviderException(EntityProviderException.COMMON, e);
  }
}
 
Example 3
Source File: EntityInfoAggregator.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private Map<String, EntityPropertyInfo> createPropertyInfoObjects(final EdmStructuralType type,
    final List<String> propertyNames) throws EntityProviderException {
  try {
    Map<String, EntityPropertyInfo> infos = new HashMap<String, EntityPropertyInfo>();

    for (String propertyName : propertyNames) {
      EdmProperty property = (EdmProperty) type.getProperty(propertyName);

      checkETagRelevant(property);

      EntityPropertyInfo info = createEntityPropertyInfo(property);
      infos.put(info.getName(), info);
      checkTargetPathInfo(property, info);
    }

    return infos;
  } catch (EdmException e) {
    throw new EntityProviderException(EntityProviderException.COMMON, e);
  }
}
 
Example 4
Source File: AtomEntryEntitySerializer.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private void appendAtomNavigationLink(final XMLStreamWriter writer, final String target,
    final String navigationPropertyName, final boolean isFeed) 
        throws EntityProviderException, EdmException, URISyntaxException { //NOSONAR
  try {
    writer.writeStartElement(FormatXml.ATOM_LINK);
    writer.writeAttribute(FormatXml.ATOM_HREF, target);
    writer.writeAttribute(FormatXml.ATOM_REL, Edm.NAMESPACE_REL_2007_08 + navigationPropertyName);
    writer.writeAttribute(FormatXml.ATOM_TITLE, navigationPropertyName);
    if (isFeed) {
      writer.writeAttribute(FormatXml.ATOM_TYPE, ContentType.APPLICATION_ATOM_XML_FEED.toString());
    } else {
      writer.writeAttribute(FormatXml.ATOM_TYPE, ContentType.APPLICATION_ATOM_XML_ENTRY.toString());
    }
  } catch (XMLStreamException e) {
    throw new EntityProviderProducerException(EntityProviderException.COMMON, e);
  }
}
 
Example 5
Source File: AtomEntryEntityProducer.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private void appendAtomContentLink(final XMLStreamWriter writer, final EntityInfoAggregator eia,
    final Map<String, Object> data, final String selfLink) throws EntityProviderException, EdmException {
  try {
    String mediaResourceMimeType = null;
    EdmMapping entityTypeMapping = eia.getEntityType().getMapping();
    if (entityTypeMapping != null) {
      String mediaResourceMimeTypeKey = entityTypeMapping.getMediaResourceMimeTypeKey();
      if (mediaResourceMimeTypeKey != null) {
        mediaResourceMimeType = (String) data.get(mediaResourceMimeTypeKey);
      }
    }
    if (mediaResourceMimeType == null) {
      mediaResourceMimeType = ContentType.APPLICATION_OCTET_STREAM.toString();
    }

    writer.writeStartElement(FormatXml.ATOM_LINK);
    writer.writeAttribute(FormatXml.ATOM_HREF, selfLink + "/$value");
    writer.writeAttribute(FormatXml.ATOM_REL, Edm.LINK_REL_EDIT_MEDIA);
    writer.writeAttribute(FormatXml.ATOM_TYPE, mediaResourceMimeType);
    writer.writeEndElement();
  } catch (XMLStreamException e) {
    throw new EntityProviderProducerException(EntityProviderException.COMMON, e);
  }
}
 
Example 6
Source File: ODataClientImpl.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private ContentTypeBasedDeserializer createDeserializer(ContentType contentType)
    throws EntityProviderException {
  try {
    switch (contentType.getODataFormat()) {
    case ATOM:
    case XML:
      return new AtomSerializerDeserializer(contentType.getODataFormat());
    case JSON:
      return new JsonSerializerDeserializer();
    default:
      throw new ODataNotAcceptableException(ODataNotAcceptableException.NOT_SUPPORTED_CONTENT_TYPE
          .addContent(contentType));
    }
  } catch (final ODataNotAcceptableException e) {
    throw new EntityProviderException(EntityProviderException.COMMON, e);
  }
}
 
Example 7
Source File: AtomEntryEntitySerializer.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private void appendProperties(final XMLStreamWriter writer, final EntityInfoAggregator eia,
    final Map<String, Object> data) throws EntityProviderException {
  try {
    {
      if (!data.isEmpty() && data.size() > 0) {
        writer.writeStartElement(Edm.NAMESPACE_M_2007_08, FormatXml.M_PROPERTIES);
        for (String propertyName : eia.getPropertyNames()) {
          if (data.containsKey(propertyName)) {
            appendPropertyNameValue(writer, eia, data, propertyName);
          }
        }
        writer.writeEndElement();
      }
    }
  } catch (XMLStreamException e) {
    throw new EntityProviderProducerException(EntityProviderException.COMMON, e);
  }
}
 
Example 8
Source File: XmlLinkEntityProducer.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
public void append(final XMLStreamWriter writer, final EntityInfoAggregator entityInfo,
    final Map<String, Object> data, final boolean isRootElement) throws EntityProviderException {
  try {
    writer.writeStartElement(FormatXml.D_URI);
    if (isRootElement) {
      writer.writeDefaultNamespace(Edm.NAMESPACE_D_2007_08);
    }
    if (properties.getServiceRoot() != null) {
      writer.writeCharacters(properties.getServiceRoot().toASCIIString());
    }
    writer.writeCharacters(AtomEntryEntityProducer.createSelfLink(entityInfo, data, null));
    writer.writeEndElement();
    writer.flush();
  } catch (final XMLStreamException e) {
    throw new EntityProviderProducerException(EntityProviderException.COMMON, e);
  }
}
 
Example 9
Source File: AtomFeedProducer.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private void appendDeletedEntries(final XMLStreamWriter writer, final EntityInfoAggregator eia,
    final TombstoneCallback callback) throws EntityProviderException {
  TombstoneCallbackResult callbackResult = callback.getTombstoneCallbackResult();
  List<Map<String, Object>> tombstoneData = callbackResult.getDeletedEntriesData();
  if (tombstoneData != null) {
    TombstoneProducer tombstoneProducer = new TombstoneProducer();
    tombstoneProducer.appendTombstones(writer, eia, properties, tombstoneData);
  }

  String deltaLink = callbackResult.getDeltaLink();
  if (deltaLink != null) {
    try {
      writer.writeStartElement(FormatXml.ATOM_LINK);
      writer.writeAttribute(FormatXml.ATOM_REL, FormatXml.ATOM_DELTA_LINK);
      writer.writeAttribute(FormatXml.ATOM_HREF, deltaLink);
      writer.writeEndElement();
    } catch (XMLStreamException e) {
      throw new EntityProviderProducerException(EntityProviderException.COMMON, e);
    }
  }
}
 
Example 10
Source File: AtomEntryEntitySerializer.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private void appendAtomContentLink(final XMLStreamWriter writer, final EntityInfoAggregator eia,
    final Map<String, Object> data, final String selfLink) throws EntityProviderException, EdmException {
  try {
    String mediaResourceMimeType = null;
    EdmMapping entityTypeMapping = eia.getEntityType().getMapping();
    if (entityTypeMapping != null) {
      String mediaResourceMimeTypeKey = entityTypeMapping.getMediaResourceMimeTypeKey();
      if (mediaResourceMimeTypeKey != null) {
        mediaResourceMimeType = (String) data.get(mediaResourceMimeTypeKey);
      }
    }
    if (mediaResourceMimeType == null) {
      mediaResourceMimeType = ContentType.APPLICATION_OCTET_STREAM.toString();
    }

    writer.writeStartElement(FormatXml.ATOM_LINK);
    writer.writeAttribute(FormatXml.ATOM_HREF, selfLink + VALUE);
    writer.writeAttribute(FormatXml.ATOM_REL, Edm.LINK_REL_EDIT_MEDIA);
    writer.writeAttribute(FormatXml.ATOM_TYPE, mediaResourceMimeType);
    writer.writeEndElement();
  } catch (XMLStreamException e) {
    throw new EntityProviderProducerException(EntityProviderException.COMMON, e);
  }
}
 
Example 11
Source File: JsonUtils.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public static int startJson(final JsonReader reader) throws EntityProviderException {
  // The enclosing "d" and "results" are optional - so we cannot check for the presence
  // but we have to read over them in case they are present.
  JsonToken token;
  try {
    token = reader.peek();
    int openJsonObjects = 0;
    if (JsonToken.BEGIN_OBJECT == token) {
      reader.beginObject();
      openJsonObjects++;
      token = reader.peek();
      if (JsonToken.NAME == token) {
        String name = reader.nextName();
        if (!("d".equals(name) ^ "results".equals(name))) {
          // TODO I18N
          throw new EntityProviderException(EntityProviderException.COMMON, name +
              " not expected, only d or results");
        }
      }

      token = reader.peek();
      if (JsonToken.BEGIN_OBJECT == token) {
        reader.beginObject();
        openJsonObjects++;
      } else if (JsonToken.BEGIN_ARRAY == token) {
        // TODO I18N
        throw new EntityProviderException(EntityProviderException.COMMON, "Array not expected");
      }
    }

    return openJsonObjects;
  } catch (IOException e) {
    // TODO I18N
    throw new EntityProviderException(EntityProviderException.COMMON, e);
  }
}
 
Example 12
Source File: AtomFeedSerializer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
/**
 * This serializes the xml payload feed
 * @param writer
 * @param eia
 * @param data
 * @param isInline
 * @throws EntityProviderException
 */
public void append(final XMLStreamWriter writer, final EntityInfoAggregator eia,
    final EntityCollection data, final boolean isInline) throws EntityProviderException {
  try {
    if (properties.getServiceRoot() == null) {
      throw new EntityProviderProducerException(EntityProviderException.MANDATORY_WRITE_PROPERTY);
    }
    
    writer.writeStartElement(FormatXml.ATOM_FEED);
    if (!isInline) {
      writer.writeDefaultNamespace(Edm.NAMESPACE_ATOM_2005);
      writer.writeNamespace(Edm.PREFIX_M, Edm.NAMESPACE_M_2007_08);
      writer.writeNamespace(Edm.PREFIX_D, Edm.NAMESPACE_D_2007_08);
      
    }
    writer.writeAttribute(Edm.PREFIX_XML, Edm.NAMESPACE_XML_1998, FormatXml.XML_BASE, properties.getServiceRoot()
        .toASCIIString());

    // write all atom infos (mandatory and optional)
    appendAtomMandatoryParts(writer, eia);
    appendAtomSelfLink(writer, eia);
  

    appendEntries(writer, eia, data);

   

 
    writer.writeEndElement();
  } catch (XMLStreamException e) {
    throw new EntityProviderProducerException(EntityProviderException.COMMON, e);
  }
}
 
Example 13
Source File: AtomFeedProducer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private void appendInlineCount(final XMLStreamWriter writer, final Integer inlineCount)
    throws EntityProviderException {
  if (inlineCount == null || inlineCount < 0) {
    throw new EntityProviderProducerException(EntityProviderException.INLINECOUNT_INVALID);
  }
  try {
    writer.writeStartElement(Edm.NAMESPACE_M_2007_08, FormatXml.M_COUNT);
    writer.writeCharacters(String.valueOf(inlineCount));
    writer.writeEndElement();
  } catch (XMLStreamException e) {
    throw new EntityProviderProducerException(EntityProviderException.COMMON, e);
  }
}
 
Example 14
Source File: AtomFeedProducer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private void appendNextLink(final XMLStreamWriter writer, final String nextLink) throws EntityProviderException {
  try {
    writer.writeStartElement(FormatXml.ATOM_LINK);
    writer.writeAttribute(FormatXml.ATOM_HREF, nextLink);
    writer.writeAttribute(FormatXml.ATOM_REL, FormatXml.ATOM_NEXT_LINK);
    writer.writeEndElement();
  } catch (XMLStreamException e) {
    throw new EntityProviderProducerException(EntityProviderException.COMMON, e);
  }
}
 
Example 15
Source File: AtomEntryEntityProducer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private void appendAtomOptionalPart(final XMLStreamWriter writer, final String name, final String value,
    final boolean writeType) throws EntityProviderException {
  try {
    if (value != null) {
      writer.writeStartElement(name);
      if (writeType) {
        writer.writeAttribute(FormatXml.ATOM_TYPE, FormatXml.ATOM_TEXT);
      }
      writer.writeCharacters(value);
      writer.writeEndElement();
    }
  } catch (XMLStreamException e) {
    throw new EntityProviderProducerException(EntityProviderException.COMMON, e);
  }
}
 
Example 16
Source File: EntityInfoAggregator.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private void checkETagRelevant(final EdmProperty edmProperty) throws EntityProviderException {
  try {
    if (edmProperty.getFacets() != null && edmProperty.getFacets().getConcurrencyMode() == EdmConcurrencyMode.Fixed) {
      etagPropertyNames.add(edmProperty.getName());
    }
  } catch (EdmException e) {
    throw new EntityProviderException(EntityProviderException.COMMON, e);
  }
}
 
Example 17
Source File: AtomEntryEntityProducer.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private void appendInlineEntry(final XMLStreamWriter writer, final String navigationPropertyName,
    final EntityInfoAggregator eia, final Map<String, Object> data) throws EntityProviderException,
    XMLStreamException, EdmException {

  if (eia.getExpandedNavigationPropertyNames().contains(navigationPropertyName)) {
    if (properties.getCallbacks() != null && properties.getCallbacks().containsKey(navigationPropertyName)) {

      EdmNavigationProperty navProp = (EdmNavigationProperty) eia.getEntityType().getProperty(navigationPropertyName);
      WriteEntryCallbackContext context = new WriteEntryCallbackContext();
      context.setSourceEntitySet(eia.getEntitySet());
      context.setCurrentWriteProperties(properties);
      context.setNavigationProperty(navProp);
      context.setEntryData(data);
      ExpandSelectTreeNode subNode = properties.getExpandSelectTree().getLinks().get(navigationPropertyName);
      context.setCurrentExpandSelectTreeNode(subNode);

      ODataCallback callback = properties.getCallbacks().get(navigationPropertyName);
      if (callback == null) {
        throw new EntityProviderProducerException(EntityProviderException.EXPANDNOTSUPPORTED);
      }
      WriteEntryCallbackResult result;
      try {
        result = ((OnWriteEntryContent) callback).retrieveEntryResult(context);
      } catch (ODataApplicationException e) {
        throw new EntityProviderProducerException(EntityProviderException.COMMON, e);
      }
      Map<String, Object> inlineData = result.getEntryData();
      
      // This statement is used for the client use case. Flag should never be set on server side
      if (properties.isOmitInlineForNullData() && (inlineData == null || inlineData.isEmpty())) {
        return;
      }

      writer.writeStartElement(Edm.NAMESPACE_M_2007_08, FormatXml.M_INLINE);
      if (inlineData != null && !inlineData.isEmpty()) {
        EntityProviderWriteProperties inlineProperties = result.getInlineProperties();
        EdmEntitySet inlineEntitySet = eia.getEntitySet().getRelatedEntitySet(navProp);
        AtomEntryEntityProducer inlineProducer = new AtomEntryEntityProducer(inlineProperties);
        EntityInfoAggregator inlineEia =
            EntityInfoAggregator.create(inlineEntitySet, inlineProperties.getExpandSelectTree());
        inlineProducer.append(writer, inlineEia, inlineData, false, false);
      }

      writer.writeEndElement();
    }
  }

}
 
Example 18
Source File: AtomEntryEntityProducer.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private void appendInlineFeed(final XMLStreamWriter writer, final String navigationPropertyName,
    final EntityInfoAggregator eia, final Map<String, Object> data, final String self)
    throws EntityProviderException, XMLStreamException, EdmException, URISyntaxException {

  if (eia.getExpandedNavigationPropertyNames().contains(navigationPropertyName)) {
    if (properties.getCallbacks() != null && properties.getCallbacks().containsKey(navigationPropertyName)) {

      EdmNavigationProperty navProp = (EdmNavigationProperty) eia.getEntityType().getProperty(navigationPropertyName);
      WriteFeedCallbackContext context = new WriteFeedCallbackContext();
      context.setSourceEntitySet(eia.getEntitySet());
      context.setNavigationProperty(navProp);
      context.setEntryData(data);
      context.setCurrentWriteProperties(properties);
      ExpandSelectTreeNode subNode = properties.getExpandSelectTree().getLinks().get(navigationPropertyName);
      context.setCurrentExpandSelectTreeNode(subNode);
      context.setSelfLink(new URI(self));

      ODataCallback callback = properties.getCallbacks().get(navigationPropertyName);
      if (callback == null) {
        throw new EntityProviderProducerException(EntityProviderException.EXPANDNOTSUPPORTED);
      }
      WriteFeedCallbackResult result;
      try {
        result = ((OnWriteFeedContent) callback).retrieveFeedResult(context);
      } catch (ODataApplicationException e) {
        throw new EntityProviderProducerException(EntityProviderException.COMMON, e);
      }
      List<Map<String, Object>> inlineData = result.getFeedData();
      if (inlineData == null) {
        inlineData = new ArrayList<Map<String, Object>>();
      }
      
      // This statement is used for the client use case. Flag should never be set on server side
      if (properties.isOmitInlineForNullData() && inlineData.isEmpty()) {
        return;
      }
      writer.writeStartElement(Edm.NAMESPACE_M_2007_08, FormatXml.M_INLINE);

      EntityProviderWriteProperties inlineProperties = result.getInlineProperties();
      EdmEntitySet inlineEntitySet = eia.getEntitySet().getRelatedEntitySet(navProp);
      AtomFeedProducer inlineFeedProducer = new AtomFeedProducer(inlineProperties);
      EntityInfoAggregator inlineEia =
          EntityInfoAggregator.create(inlineEntitySet, inlineProperties.getExpandSelectTree());
      inlineFeedProducer.append(writer, inlineEia, inlineData, true);

      writer.writeEndElement();
    }
  }
}
 
Example 19
Source File: EntityInfoAggregator.java    From olingo-odata2 with Apache License 2.0 3 votes vote down vote up
/**
 * Create an {@link EntityPropertyInfo} based on given {@link EdmProperty}
 * 
 * @param property
 * for which the {@link EntityPropertyInfo} is created.
 * @return created {@link EntityPropertyInfo}
 * @throws EntityProviderException
 * if create of {@link EntityPropertyInfo} something goes wrong (e.g. exceptions during
 * access of {@link EdmProperty}).
 */
public static EntityPropertyInfo create(final EdmProperty property) throws EntityProviderException {
  try {
    EntityInfoAggregator eia = new EntityInfoAggregator();
    return eia.createEntityPropertyInfo(property);
  } catch (EdmException e) {
    throw new EntityProviderException(EntityProviderException.COMMON, e);
  }
}
 
Example 20
Source File: EntityInfoAggregator.java    From olingo-odata2 with Apache License 2.0 3 votes vote down vote up
/**
 * Create an map of <code>complex type property name</code> to {@link EntityPropertyInfo} based on given
 * {@link EdmComplexType}
 * 
 * @param complexType
 * for which the {@link EntityPropertyInfo} is created.
 * @return created map of <code>complex type property name</code> to {@link EntityPropertyInfo}
 * @throws EntityProviderException
 * if create of {@link EntityPropertyInfo} something goes wrong (e.g. exceptions during
 * access of {@link EntityPropertyInfo}).
 */
public static Map<String, EntityPropertyInfo> create(final EdmComplexType complexType)
    throws EntityProviderException {
  try {
    EntityInfoAggregator entityInfo = new EntityInfoAggregator();
    return entityInfo.createPropertyInfoObjects(complexType, complexType.getPropertyNames());
  } catch (EdmException e) {
    throw new EntityProviderException(EntityProviderException.COMMON, e);
  }
}