Java Code Examples for org.apache.olingo.odata2.api.ep.EntityProvider#readFeed()

The following examples show how to use org.apache.olingo.odata2.api.ep.EntityProvider#readFeed() . 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: ODataClient.java    From DataHubSystem with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Reads a feed (the content of an EntitySet).
 * 
 * @param resource_path the resource path to the parent of the requested
 *    EntitySet, as defined in {@link #getResourcePath(URI)}.
 * @param query_parameters Query parameters, as defined in {@link URI}.
 * 
 * @return an ODataFeed containing the ODataEntries for the given 
 *    {@code resource_path}.
 * 
 * @throws HttpException if the server emits an HTTP error code.
 * @throws IOException if the connection with the remote service fails.
 * @throws EdmException if the EDM does not contain the given entitySetName.
 * @throws EntityProviderException if reading of data (de-serialization)
 *    fails.
 * @throws UriSyntaxException violation of the OData URI construction rules.
 * @throws UriNotMatchingException URI parsing exception.
 * @throws ODataException encapsulate the OData exceptions described above.
 * @throws InterruptedException if running thread has been interrupted.
 */
public ODataFeed readFeed(String resource_path,
   Map<String, String> query_parameters) throws IOException, ODataException, InterruptedException
{
   if (resource_path == null || resource_path.isEmpty ())
      throw new IllegalArgumentException (
         "resource_path must not be null or empty.");
   
   ContentType contentType = ContentType.APPLICATION_ATOM_XML;
   
   String absolutUri = serviceRoot.toString () + '/' + resource_path;
   
   // Builds the query parameters string part of the URL.
   absolutUri = appendQueryParam (absolutUri, query_parameters);
   
   InputStream content = execute (absolutUri, contentType, "GET");
   
   return EntityProvider.readFeed (contentType.type (),
      getEntitySet (resource_path), content,
      EntityProviderReadProperties.init ().build ());
}
 
Example 2
Source File: XmlFeedConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void roomsFeedWithEtagEntries() throws Exception {
  InputStream stream = getFileAsStream("feed_rooms_small.xml");
  assertNotNull(stream);

  ODataFeed feed =
      EntityProvider.readFeed("application/atom+xml", MockFacade.getMockEdm().getDefaultEntityContainer()
          .getEntitySet(
              "Rooms"), stream, DEFAULT_PROPERTIES);
  assertNotNull(feed);

  FeedMetadata feedMetadata = feed.getFeedMetadata();
  assertNotNull(feedMetadata);
  assertNotNull(feedMetadata.getNextLink());

  List<ODataEntry> entries = feed.getEntries();
  assertEquals(3, entries.size());
  ODataEntry singleRoom = entries.get(0);
  EntryMetadata roomMetadata = singleRoom.getMetadata();
  assertNotNull(roomMetadata);

  assertEquals("W/\"1\"", roomMetadata.getEtag());
}
 
Example 3
Source File: XmlFeedConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
/**
 * Rooms navigate to Employees and has inline entry Teams
 * E.g: Rooms('1')/nr_Employees?$expand=ne_Team
 * @throws Exception
 */
@Test
public void roomsFeedWithRoomsToEmployeesInlineTeams() throws Exception {
  InputStream stream = getFileAsStream("RoomsToEmployeesWithInlineTeams.xml");
  assertNotNull(stream);
  FeedCallback callback = new FeedCallback();

  EntityProviderReadProperties readProperties = EntityProviderReadProperties.init()
      .mergeSemantic(false).callback(callback).build();

  ODataFeed feed =
      EntityProvider.readFeed("application/atom+xml", MockFacade.getMockEdm().getDefaultEntityContainer()
          .getEntitySet(
              "Employees"), stream, readProperties);
  assertNotNull(feed);
  assertEquals(2, feed.getEntries().size());

  Map<String, Object> inlineEntries = callback.getNavigationProperties();
  getExpandedData(inlineEntries, feed);
  for (ODataEntry entry : feed.getEntries()) {
    assertEquals(10, entry.getProperties().size());
    assertEquals(3, ((ODataEntry)entry.getProperties().get("ne_Team")).getProperties().size());
  }
}
 
Example 4
Source File: GenericODataClient.java    From lemonaid with MIT License 5 votes vote down vote up
protected ODataFeed readFeed(String serviceUri, String contentType, String entitySetName)
		throws IOException, ODataException {
	initialize(serviceUri);
	EdmEntityContainer entityContainer = edm.getDefaultEntityContainer();
	String absolutUri = createUri(serviceUri, entitySetName, null);

	InputStream content = (InputStream) connect(absolutUri, contentType, GET).getContent();
	return EntityProvider.readFeed(contentType, entityContainer.getEntitySet(entitySetName), content,
			EntityProviderReadProperties.init().build());
}
 
Example 5
Source File: ServiceTicketODataConsumer.java    From C4CODATAAPIDEVGUIDE with Apache License 2.0 5 votes vote down vote up
public ODataFeed readFeed(String serviceUri, String contentType,
		String entitySetName, SystemQueryOptions options)
		throws IllegalStateException, IOException, EntityProviderException,
		EdmException {
	Edm edm = readEdm();
	EdmEntityContainer entityContainer = edm.getDefaultEntityContainer();
	String absolutUri = createUri(serviceUri, entitySetName, null, options);

	InputStream content = executeGet(absolutUri, contentType);
	return EntityProvider.readFeed(contentType,
			entityContainer.getEntitySet(entitySetName), content,
			EntityProviderReadProperties.init().build());
}
 
Example 6
Source File: XmlFeedConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void readLargeEmployeesFeed() throws Exception {
  InputStream file = getFileAsStream("LargeEmployeeFeed.xml");
  assertNotNull(file);

  ODataFeed feed =
      EntityProvider.readFeed("application/atom+xml", MockFacade.getMockEdm().getDefaultEntityContainer()
          .getEntitySet(
              "Employees"), file, DEFAULT_PROPERTIES);
  assertNotNull(feed);

  FeedMetadata feedMetadata = feed.getFeedMetadata();
  assertNotNull(feedMetadata);
}
 
Example 7
Source File: XmlFeedConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
/**
 * Room has an Inline Feed Employees and Employee has an inline Entry Team
 * E.g: Rooms?$expand=nr_Employees/ne_Team
 * Empty Inline entity is also part of payload
 * @throws Exception
 */
@Test
public void roomsFeedWithRoomInlineEmployeesWithTeams() throws Exception {
  InputStream stream = getFileAsStream("Rooms_InlineEmployeesTeams.xml");
  assertNotNull(stream);
  FeedCallback callback = new FeedCallback();

  EntityProviderReadProperties readProperties = EntityProviderReadProperties.init()
      .mergeSemantic(false).callback(callback).build();

  ODataFeed feed =
      EntityProvider.readFeed("application/atom+xml", MockFacade.getMockEdm().getDefaultEntityContainer()
          .getEntitySet(
              "Rooms"), stream, readProperties);
  assertNotNull(feed);
  assertEquals(3, feed.getEntries().size());

  Map<String, Object> inlineEntries = callback.getNavigationProperties();
  getExpandedData(inlineEntries, feed);
  for (ODataEntry entry : feed.getEntries()) {
    assertEquals(5, entry.getProperties().size());
    for (ODataEntry innerEntry : ((ODataFeed)entry.getProperties().get("nr_Employees")).getEntries()) {
      assertEquals(10, innerEntry.getProperties().size());
      assertEquals(3, ((ODataEntry)innerEntry.getProperties().get("ne_Team")).getProperties().size());
    }
  }
}
 
Example 8
Source File: XmlFeedConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
/**
 * Rooms has an inline feed Employees and Rooms has Inline entry Buildings
 * E.g: Rooms?$expand=nr_Employees,nr_Building
 * @throws Exception
 */
@Test
public void roomsFeedWithRoomInlineEmployeesInlineBuildings() throws Exception {
  InputStream stream = getFileAsStream("Rooms_InlineEmployees_InlineBuildings.xml");
  assertNotNull(stream);
  FeedCallback callback = new FeedCallback();

  EntityProviderReadProperties readProperties = EntityProviderReadProperties.init()
      .mergeSemantic(false).callback(callback).build();

  ODataFeed feed =
      EntityProvider.readFeed("application/atom+xml", MockFacade.getMockEdm().getDefaultEntityContainer()
          .getEntitySet(
              "Rooms"), stream, readProperties);
  assertNotNull(feed);
  assertEquals(2, feed.getEntries().size());

  Map<String, Object> inlineEntries = callback.getNavigationProperties();
  getExpandedData(inlineEntries, feed);
  for (ODataEntry entry : feed.getEntries()) {
    assertEquals(6, entry.getProperties().size());
    for (ODataEntry employeeEntry : ((ODataFeed)entry.getProperties().get("nr_Employees")).getEntries()) {
      assertEquals(9, employeeEntry.getProperties().size());
    }
    assertEquals(3, ((ODataEntry)entry.getProperties().get("nr_Building")).getProperties().size());
  }
}
 
Example 9
Source File: URLEncodingTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void encodingInQueryPartForFilter() throws Exception {
  Edm edm = new EdmImplProv(new ScenarioEdmProvider());
  final String uriString = "Employees?$format=json&$filter=EmployeeName%20eq%20'Walter%20Winter'";
  HttpResponse response = callUri(uriString);
  checkMediaType(response, HttpContentType.APPLICATION_JSON);
  ODataFeed feed = EntityProvider.readFeed(
      response.getFirstHeader("Content-Type").getValue(),
      edm.getEntityContainer(null).getEntitySet("Employees"),
      response.getEntity().getContent(),
      EntityProviderReadProperties.init().build());
  assertEquals(1, feed.getEntries().size());
}
 
Example 10
Source File: URLEncodingTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void encodingInQueryPartForFilterWithAndEncoded() throws Exception {
  Edm edm = new EdmImplProv(new ScenarioEdmProvider());
  final String uriString = "Employees?$format=json&$filter=EmployeeName%20eq%20'Walter%26Winter'";
  HttpResponse response = callUri(uriString);
  checkMediaType(response, HttpContentType.APPLICATION_JSON);
  ODataFeed feed = EntityProvider.readFeed(
      response.getFirstHeader("Content-Type").getValue(),
      edm.getEntityContainer(null).getEntitySet("Employees"),
      response.getEntity().getContent(),
      EntityProviderReadProperties.init().build());
  assertEquals(0, feed.getEntries().size());
}
 
Example 11
Source File: URLEncodingTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void encodingInQueryPartForFilterWithHiphonEncoded() throws Exception {
  Edm edm = new EdmImplProv(new ScenarioEdmProvider());
  final String uriString = "Employees?$format=json&$filter=EmployeeName%20eq%20'Walter%27%27Winter'";
  HttpResponse response = callUri(uriString);
  
  assertEquals(200, response.getStatusLine().getStatusCode());
  checkMediaType(response, HttpContentType.APPLICATION_JSON);
  ODataFeed feed = EntityProvider.readFeed(
      response.getFirstHeader("Content-Type").getValue(),
      edm.getEntityContainer(null).getEntitySet("Employees"),
      response.getEntity().getContent(),
      EntityProviderReadProperties.init().build());
  assertEquals(0, feed.getEntries().size());
}
 
Example 12
Source File: Client.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public ODataFeed readFeed(final String entityContainerName, final String entitySetName, final String contentType,
    final String query)
    throws IOException, ODataException, HttpException {
  EdmEntityContainer entityContainer = edm.getEntityContainer(entityContainerName);
  String relativeUri;
  if (entityContainer.isDefaultEntityContainer()) {
    relativeUri = entitySetName;
  } else {
    relativeUri = entityContainerName + "." + entitySetName;
  }

  InputStream content = (InputStream) connect(relativeUri, query, contentType, "GET").getContent();
  return EntityProvider.readFeed(contentType, entityContainer.getEntitySet(entitySetName), content,
      EntityProviderReadProperties.init().build());
}