org.apache.olingo.odata2.api.ODataCallback Java Examples

The following examples show how to use org.apache.olingo.odata2.api.ODataCallback. 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: JsonEntryEntityProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void entryWithExpandedEntryWithRegisteredNullCallback() throws Exception {
  final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  Map<String, Object> roomData = new HashMap<String, Object>();
  roomData.put("Id", "1");
  roomData.put("Version", 1);

  ExpandSelectTreeNode node1 = createRoomNode();

  Map<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>();
  callbacks.put("nr_Building", null);

  new JsonEntityProvider().writeEntry(entitySet, roomData,
      EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).expandSelectTree(node1).callbacks(callbacks)
          .build());

}
 
Example #2
Source File: XmlExpandProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test(expected = EntityProviderException.class)
public void expandSelectedEmployeesWithFacets() throws Exception {
  Edm edm = MockFacade.getMockEdm();
  EdmTyped imageUrlProperty = edm.getEntityType("RefScenario", "Employee").getProperty("ImageUrl");
  EdmFacets facets = mock(EdmFacets.class);
  when(facets.getMaxLength()).thenReturn(1);
  when(((EdmProperty) imageUrlProperty).getFacets()).thenReturn(facets);

  ExpandSelectTreeNode selectTree = getSelectExpandTree("Rooms('1')", "nr_Employees", "nr_Employees");

  HashMap<String, ODataCallback> callbacksRoom = createCallbacks("Rooms");
  EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.serviceRoot(BASE_URI).expandSelectTree(selectTree)
          .callbacks(callbacksRoom)
          .build();
  AtomEntityProvider provider = createAtomEntityProvider();
  ODataResponse response =
      provider.writeEntry(edm.getDefaultEntityContainer().getEntitySet("Rooms"), roomData,
          properties);

  String xmlString = verifyResponse(response);
  assertXpathNotExists("/a:entry/m:properties", xmlString);
  assertXpathExists("/a:entry/a:link", xmlString);
  verifyEmployees(employeeXPathString, xmlString);
}
 
Example #3
Source File: Processor.java    From DataHubSystem with GNU Affero General Public License v3.0 6 votes vote down vote up
private Map<String, ODataCallback> makeCallbacks(List<String> expandables, Expander expander)
{
   Objects.requireNonNull(expandables);
   Objects.requireNonNull(expander);
   if (expandables.isEmpty())
   {
      return Collections.emptyMap();
   }

   Map<String, ODataCallback> res = new HashMap<>(expandables.size());
   for (String navlink_name: expandables)
   {
      res.put(navlink_name, expander);
   }
   return res;
}
 
Example #4
Source File: XmlExpandProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void expandSelectedTeamNullOmitInline() throws Exception {
  ExpandSelectTreeNode selectTree = getSelectExpandTree("Employees('1')", "ne_Team", "ne_Team");

  HashMap<String, ODataCallback> callbacksEmployee = createCallbacks("Employees");
  EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.serviceRoot(BASE_URI).expandSelectTree(selectTree).callbacks(callbacksEmployee)
      .omitInlineForNullData(true).build();
  AtomEntityProvider provider = createAtomEntityProvider();
  ODataResponse response =
      provider.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"),
          employeeData, properties);

  String xmlString = verifyResponse(response);
  verifyNavigationProperties(xmlString, F, F, T);
  assertXpathExists(teamXPathString, xmlString);
  assertXpathNotExists("/a:entry/m:properties", xmlString);
  assertXpathNotExists(teamXPathString +  "/m:inline", xmlString);
  assertXpathNotExists(teamXPathString +  "/m:inline/a:entry", xmlString);
}
 
Example #5
Source File: JsonFeedWithDeltaLinkProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private String writeRoomData(final EdmEntitySet entitySet, final TombstoneCallback tombstoneCallback)
    throws URISyntaxException, EntityProviderException, IOException {
  Map<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>();
  callbacks.put(TombstoneCallback.CALLBACK_KEY_TOMBSTONE, tombstoneCallback);

  EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.serviceRoot(new URI(BASE_URI)).callbacks(callbacks).build();

  final ODataResponse response = new JsonEntityProvider().writeFeed(entitySet, roomsData,
      properties);
  assertNotNull(response);
  assertNotNull(response.getEntity());
  assertNull("EntitypProvider must not set content header", response.getContentHeader());

  final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
  assertNotNull(json);

  validate(json);

  return json;
}
 
Example #6
Source File: XmlFeedWithTombstonesProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void deltaLinkPresent() throws Exception {
  initializeRoomData(2);
  initializeDeletedRoomData();
  TombstoneCallback tombstoneCallback =
      new TombstoneCallbackImpl(deletedRoomsData, BASE_URI.toASCIIString() + "Rooms?!deltatoken=1234");
  callbacks = new HashMap<String, ODataCallback>();
  callbacks.put(TombstoneCallback.CALLBACK_KEY_TOMBSTONE, tombstoneCallback);

  EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.serviceRoot(BASE_URI).callbacks(callbacks).build();
  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");

  String xmlString = execute(properties, entitySet);
  assertXpathExists("/a:feed/at:deleted-entry", xmlString);
  assertXpathExists("/a:feed/a:link[@rel=\"delta\" and @href=\"" + BASE_URI.toASCIIString()
      + "Rooms?!deltatoken=1234" + "\"]", xmlString);
}
 
Example #7
Source File: XmlFeedWithTombstonesProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void deltaLinkAndDataNull() throws Exception {
  initializeRoomData(2);
  initializeDeletedRoomData();
  TombstoneCallback tombstoneCallback = new TombstoneCallbackImpl(null, null);
  callbacks = new HashMap<String, ODataCallback>();
  callbacks.put(TombstoneCallback.CALLBACK_KEY_TOMBSTONE, tombstoneCallback);

  EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.serviceRoot(BASE_URI).callbacks(callbacks).build();
  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");

  String xmlString = execute(properties, entitySet);
  assertXpathNotExists("/a:feed/at:deleted-entry", xmlString);
  assertXpathNotExists("/a:feed/a:link[@rel=\"http://odata.org/delta\" and @href]", xmlString);
}
 
Example #8
Source File: ODataJPAServiceFactory.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T extends ODataCallback> T getCallback(final Class<T> callbackInterface) {
  if (setDetailErrors == true) {
    if (callbackInterface.isAssignableFrom(ODataErrorCallback.class)) {
      return (T) new ODataJPAErrorCallback();
    }
  }
  if (onJPAWriteContent != null) {
    if (callbackInterface.isAssignableFrom(OnJPAWriteContent.class)) {
      return (T) onJPAWriteContent;
    }
  }
  if (oDataJPATransaction != null) {
    if (callbackInterface.isAssignableFrom(ODataJPATransaction.class)) {
      return (T) oDataJPATransaction;
    }
  }
  return null;
}
 
Example #9
Source File: XmlExpandProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void expandSelectedEmployees() throws Exception {
  ExpandSelectTreeNode selectTree = getSelectExpandTree("Rooms('1')", "nr_Employees", "nr_Employees");

  HashMap<String, ODataCallback> callbacksRoom = createCallbacks("Rooms");
  EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.serviceRoot(BASE_URI).expandSelectTree(selectTree).callbacks(callbacksRoom)
          .build();
  AtomEntityProvider provider = createAtomEntityProvider();
  ODataResponse response =
      provider.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"), roomData,
          properties);

  String xmlString = verifyResponse(response);
  assertXpathNotExists("/a:entry/m:properties", xmlString);
  assertXpathExists("/a:entry/a:link", xmlString);
  verifyEmployees(employeeXPathString, xmlString);
}
 
Example #10
Source File: XmlExpandProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void expandSelectedEmployeesIgnoreFacets() throws Exception {
  Edm edm = MockFacade.getMockEdm();
  EdmTyped imageUrlProperty = edm.getEntityType("RefScenario", "Employee").getProperty("ImageUrl");
  EdmFacets facets = mock(EdmFacets.class);
  when(facets.getMaxLength()).thenReturn(1);
  when(((EdmProperty) imageUrlProperty).getFacets()).thenReturn(facets);

  ExpandSelectTreeNode selectTree = getSelectExpandTree("Rooms('1')", "nr_Employees", "nr_Employees");

  HashMap<String, ODataCallback> callbacksRoom = createCallbacks("Rooms");
  EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.serviceRoot(BASE_URI).expandSelectTree(selectTree).callbacks(callbacksRoom)
          .callbacks(callbacksRoom).validatingFacets(false)
          .build();
  AtomEntityProvider provider = createAtomEntityProvider();
  ODataResponse response =
      provider.writeEntry(edm.getDefaultEntityContainer().getEntitySet("Rooms"), roomData,
          properties);

  String xmlString = verifyResponse(response);
  assertXpathNotExists("/a:entry/m:properties", xmlString);
  assertXpathExists("/a:entry/a:link", xmlString);
  verifyEmployees(employeeXPathString, xmlString);
}
 
Example #11
Source File: XmlExpandProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void expandSelectedEmployeesWithBuilder() throws Exception {
  EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  List<String> navigationPropertyNames = new ArrayList<String>();
  navigationPropertyNames.add("nr_Employees");
  ExpandSelectTreeNode selectTree =
      ExpandSelectTreeNode.entitySet(entitySet).expandedLinks(navigationPropertyNames).build();

  HashMap<String, ODataCallback> callbacksRoom = createCallbacks("Rooms");
  EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.serviceRoot(BASE_URI).expandSelectTree(selectTree).callbacks(callbacksRoom)
          .build();
  AtomEntityProvider provider = createAtomEntityProvider();
  ODataResponse response =
      provider.writeEntry(entitySet, roomData,
          properties);

  String xmlString = verifyResponse(response);
  assertXpathNotExists("/a:entry/m:properties", xmlString);
  assertXpathExists("/a:entry/a:link", xmlString);
  verifyEmployees(employeeXPathString, xmlString);
}
 
Example #12
Source File: XmlExpandProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void expandSelectedEmployeesWithSelfLink() throws Exception {
  ExpandSelectTreeNode selectTree = getSelectExpandTree("Rooms('1')", "nr_Employees", "nr_Employees");

  HashMap<String, ODataCallback> callbacksRoom = createCallbacks("Rooms");
  EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.serviceRoot(BASE_URI).expandSelectTree(selectTree).callbacks(callbacksRoom)
          .build();
  AtomEntityProvider provider = createAtomEntityProvider();
  ODataResponse response =
      provider.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"), roomData,
          properties);

  String xmlString = verifyResponse(response);
  assertXpathNotExists("/a:entry/m:properties", xmlString);
  assertXpathExists("/a:entry/a:link", xmlString);
  verifyEmployees(employeeXPathString, xmlString);
  assertXpathExists(employeeXPathString + "/m:inline/a:feed/a:link[@href=\"Rooms('1')/nr_Employees\"]", xmlString);
}
 
Example #13
Source File: XmlExpandProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void deepExpandSelectedEmployees() throws Exception {
  ExpandSelectTreeNode selectTree = getSelectExpandTree("Rooms('1')", "nr_Employees/ne_Room", "nr_Employees/ne_Room");

  HashMap<String, ODataCallback> callbacksRoom = createCallbacks("Rooms");
  EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.serviceRoot(BASE_URI).expandSelectTree(selectTree).callbacks(callbacksRoom)
          .build();
  AtomEntityProvider provider = createAtomEntityProvider();
  ODataResponse response =
      provider.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"), roomData,
          properties);

  String xmlString = verifyResponse(response);
  assertXpathNotExists("/a:entry/m:properties", xmlString);
  assertXpathExists(employeeXPathString, xmlString);
  assertXpathExists(employeeXPathString + "/m:inline/a:feed" + roomXPathString, xmlString);
  assertXpathExists(employeeXPathString + "/m:inline/a:feed" + roomXPathString
      + "/m:inline/a:entry/a:content/m:properties", xmlString);
}
 
Example #14
Source File: XmlExpandProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void deepExpandSelectedEmployeesWithRoomId() throws Exception {
  ExpandSelectTreeNode selectTree =
      getSelectExpandTree("Rooms('1')", "nr_Employees/ne_Room/Id", "nr_Employees/ne_Room");

  HashMap<String, ODataCallback> callbacksRoom = createCallbacks("Rooms");
  EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.serviceRoot(BASE_URI).expandSelectTree(selectTree).callbacks(callbacksRoom)
          .build();
  AtomEntityProvider provider = createAtomEntityProvider();
  ODataResponse response =
      provider.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"), roomData,
          properties);

  String xmlString = verifyResponse(response);
  assertXpathNotExists("/a:entry/m:properties", xmlString);
  assertXpathExists(employeeXPathString, xmlString);
  assertXpathExists(employeeXPathString + "/m:inline/a:feed" + roomXPathString, xmlString);
  assertXpathExists(employeeXPathString + "/m:inline/a:feed" + roomXPathString + "/m:inline", xmlString);
  assertXpathExists(employeeXPathString + "/m:inline/a:feed" + roomXPathString + "/m:inline/a:entry", xmlString);
  assertXpathExists(employeeXPathString + "/m:inline/a:feed" + roomXPathString
      + "/m:inline/a:entry/a:content/m:properties/d:Id", xmlString);
}
 
Example #15
Source File: XmlExpandProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void expandSelectedRoom() throws Exception {
  ExpandSelectTreeNode selectTree = getSelectExpandTree("Employees('1')", "ne_Room", "ne_Room");

  HashMap<String, ODataCallback> callbacksEmployee = createCallbacks("Employees");
  EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.serviceRoot(BASE_URI).expandSelectTree(selectTree).callbacks(callbacksEmployee)
          .build();
  AtomEntityProvider provider = createAtomEntityProvider();
  ODataResponse response =
      provider.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"),
          employeeData, properties);

  String xmlString = verifyResponse(response);
  verifyNavigationProperties(xmlString, F, T, F);
  assertXpathNotExists("/a:entry/m:properties", xmlString);
  verifyRoom(roomXPathString, xmlString);
}
 
Example #16
Source File: XmlExpandProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void expandSelectedTeamNull() throws Exception {
  ExpandSelectTreeNode selectTree = getSelectExpandTree("Employees('1')", "ne_Team", "ne_Team");

  HashMap<String, ODataCallback> callbacksEmployee = createCallbacks("Employees");
  EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.serviceRoot(BASE_URI).expandSelectTree(selectTree).callbacks(callbacksEmployee)
          .build();
  AtomEntityProvider provider = createAtomEntityProvider();
  ODataResponse response =
      provider.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"),
          employeeData, properties);

  String xmlString = verifyResponse(response);
  verifyNavigationProperties(xmlString, F, F, T);
  assertXpathNotExists("/a:entry/m:properties", xmlString);
  assertXpathExists(teamXPathString + "/m:inline", xmlString);
  assertXpathNotExists(teamXPathString + "/m:inline/a:entry", xmlString);
}
 
Example #17
Source File: JsonEntryEntityProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void entryWithExpandedFeedButEmptyDataOmitInline() throws Exception {
  final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Buildings");
  Map<String, Object> buildingData = new HashMap<String, Object>();
  buildingData.put("Id", "1");

  ExpandSelectTreeNode node1 = createBuildingNode();

  Map<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>();
  callbacks.put("nb_Rooms", new EmptyFeedCallback());

  final ODataResponse response =
      new JsonEntityProvider().writeEntry(entitySet, buildingData,
          EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).expandSelectTree(node1)
              .omitInlineForNullData(true).callbacks(callbacks).build());
  assertNotNull(response);
  assertNotNull(response.getEntity());
  assertNull("EntitypProvider must not set content header", response.getContentHeader());

  Map<String, Object> buildingEntry = checkRoom(response);
  assertTrue(buildingEntry.containsKey("nb_Rooms"));
  assertNotNull(buildingEntry.get("nb_Rooms"));
  assertTrue(((Map<String, Object>) buildingEntry.get("nb_Rooms")).size() == 1);
  assertTrue(((Map<String, Object>) buildingEntry.get("nb_Rooms")).containsKey("__deferred"));
}
 
Example #18
Source File: XmlExpandProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void expandSelectedRoomsNull() throws Exception {
  ExpandSelectTreeNode selectTree = getSelectExpandTree("Buildings('1')", "nb_Rooms", "nb_Rooms");

  HashMap<String, ODataCallback> callbacksEmployee = createCallbacks("Buildings");
  EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.serviceRoot(BASE_URI).expandSelectTree(selectTree).callbacks(callbacksEmployee)
          .build();
  AtomEntityProvider provider = createAtomEntityProvider();
  ODataResponse response =
      provider.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Buildings"),
          buildingData, properties);

  String xmlString = verifyResponse(response);
  assertXpathNotExists("/a:entry/m:properties", xmlString);
  assertXpathExists(buildingXPathString + "/m:inline", xmlString);

  assertXpathExists(buildingXPathString + "/m:inline/a:feed", xmlString);
  assertXpathExists(buildingXPathString + "/m:inline/a:feed/a:id", xmlString);
  assertXpathExists(buildingXPathString + "/m:inline/a:feed/a:title", xmlString);
  assertXpathExists(buildingXPathString + "/m:inline/a:feed/a:updated", xmlString);
  assertXpathExists(buildingXPathString + "/m:inline/a:feed/a:author", xmlString);
  assertXpathExists(buildingXPathString + "/m:inline/a:feed/a:author/a:name", xmlString);
  assertXpathExists(buildingXPathString + "/m:inline/a:feed/a:link[@href=\"Buildings('1')/nb_Rooms\"]", xmlString);
  assertXpathNotExists(buildingXPathString + "/m:inline/a:feed/a:entry", xmlString);
}
 
Example #19
Source File: MyCallback.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public WriteEntryCallbackResult retrieveEntryResult(final WriteEntryCallbackContext context) {
  WriteEntryCallbackResult result = new WriteEntryCallbackResult();
  try {
    if ("Employees".equals(context.getSourceEntitySet().getName())) {
      if ("ne_Room".equals(context.getNavigationProperty().getName())) {
        HashMap<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>();
        for (String navPropName : context.getSourceEntitySet().getRelatedEntitySet(context.getNavigationProperty())
            .getEntityType().getNavigationPropertyNames()) {
          callbacks.put(navPropName, this);
        }
        EntityProviderWriteProperties inlineProperties =
            EntityProviderWriteProperties.serviceRoot(baseUri).callbacks(callbacks).expandSelectTree(
                context.getCurrentExpandSelectTreeNode()).build();
        result.setEntryData(dataProvider.getRoomData());
        result.setInlineProperties(inlineProperties);
      } else if ("ne_Team".equals(context.getNavigationProperty().getName())) {
        result.setEntryData(null);
      }
    }
  } catch (EdmException e) {
    throw new ODataRuntimeException("EdmException:", e);
  }
  return result;
}
 
Example #20
Source File: ExpandSelectProducerWithBuilderTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void expandBuilding() throws Exception {
  EdmEntitySet roomsSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  List<String> expandedNavigationProperties = new ArrayList<String>();
  expandedNavigationProperties.add("nr_Building");

  ExpandSelectTreeNode expandSelectTree =
      ExpandSelectTreeNode.entitySet(roomsSet).expandedLinks(expandedNavigationProperties).build();

  Map<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>();
  callbacks.put("nr_Building", new LocalCallback());
  EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.fromProperties(DEFAULT_PROPERTIES).callbacks(callbacks).expandSelectTree(
          expandSelectTree).build();
  ODataResponse entry = EntityProvider.writeEntry("application/xml", roomsSet, roomData, properties);

  String xml = StringHelper.inputStreamToString((InputStream) entry.getEntity());
  assertXpathExists("/a:entry/a:content/m:properties", xml);
  assertXpathExists("/a:entry/a:link[@type]/m:inline", xml);
}
 
Example #21
Source File: ExpandSelectProducerWithBuilderTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void expandBuildingAndSelectIdFromRoom() throws Exception {
  EdmEntitySet roomsSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  List<String> expandedNavigationProperties = new ArrayList<String>();
  expandedNavigationProperties.add("nr_Building");

  List<String> selectedProperties = new ArrayList<String>();
  selectedProperties.add("Id");

  ExpandSelectTreeNode expandSelectTree =
      ExpandSelectTreeNode.entitySet(roomsSet).selectedProperties(selectedProperties).expandedLinks(
          expandedNavigationProperties).build();

  Map<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>();
  callbacks.put("nr_Building", new LocalCallback());
  EntityProviderWriteProperties properties =
      EntityProviderWriteProperties.fromProperties(DEFAULT_PROPERTIES).callbacks(callbacks).expandSelectTree(
          expandSelectTree).build();
  ODataResponse entry = EntityProvider.writeEntry("application/xml", roomsSet, roomData, properties);

  String xml = StringHelper.inputStreamToString((InputStream) entry.getEntity());
  assertXpathExists("/a:entry/a:content/m:properties/d:Id", xml);
  assertXpathNotExists("/a:entry/a:content/m:properties/d:Name", xml);
  assertXpathExists("/a:entry/a:link[@type]/m:inline", xml);
}
 
Example #22
Source File: JsonEntryEntityProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void entryWithExpandedEntryButNullData() throws Exception {
  final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  Map<String, Object> roomData = new HashMap<String, Object>();
  roomData.put("Id", "1");
  roomData.put("Version", 1);
  ExpandSelectTreeNode node1 = createRoomNode();
  
  Map<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>();
  callbacks.put("nr_Building", new NullEntryCallback());

  final ODataResponse response =
      new JsonEntityProvider().writeEntry(entitySet, roomData,
          EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).expandSelectTree(node1)
              .callbacks(callbacks).build());
  assertNotNull(response);
  assertNotNull(response.getEntity());
  assertNull("EntitypProvider must not set content header", response.getContentHeader());

  Map<String, Object> roomEntry = checkRoom(response);
  assertTrue(roomEntry.containsKey("nr_Building"));
  assertNull(roomEntry.get("nr_Building"));
}
 
Example #23
Source File: JsonEntryEntityProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void entryWithExpandedEntryButNullDataOmitData() throws Exception {
  final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  Map<String, Object> roomData = new HashMap<String, Object>();
  roomData.put("Id", "1");
  roomData.put("Version", 1);

  ExpandSelectTreeNode node1 = createRoomNode();
  Map<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>();
  callbacks.put("nr_Building", new NullEntryCallback());

  final ODataResponse response =
      new JsonEntityProvider().writeEntry(entitySet, roomData,
          EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).expandSelectTree(node1)
          .callbacks(callbacks).omitInlineForNullData(true).build());
  assertNotNull(response);
  assertNotNull(response.getEntity());
  assertNull("EntitypProvider must not set content header", response.getContentHeader());

  Map<String, Object> roomEntry = checkRoom(response);
  assertTrue(roomEntry.containsKey("nr_Building"));
  assertNotNull(roomEntry.get("nr_Building"));
  assertTrue(((Map<String, Object>) roomEntry.get("nr_Building")).size() == 1);
  assertTrue(((Map<String, Object>) roomEntry.get("nr_Building")).containsKey("__deferred"));
}
 
Example #24
Source File: JsonEntryEntityProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void entryWithExpandedEntryButEmptyData() throws Exception {
  final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
  Map<String, Object> roomData = new HashMap<String, Object>();
  roomData.put("Id", "1");
  roomData.put("Version", 1);

  ExpandSelectTreeNode node1 = createRoomNode();

  Map<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>();
  callbacks.put("nr_Building", new EmptyEntryCallback());

  ODataResponse response =
      new JsonEntityProvider().writeEntry(entitySet, roomData,
          EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).expandSelectTree(node1)
              .callbacks(callbacks).build());
  assertNotNull(response);
  assertNotNull(response.getEntity());
  assertNull("EntitypProvider must not set content header", response.getContentHeader());

  Map<String, Object> roomEntry = checkRoom(response);
  assertTrue(roomEntry.containsKey("nr_Building"));
  assertNull(roomEntry.get("nr_Building"));
}
 
Example #25
Source File: JsonEntryEntityProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void entryWithExpandedFeedInClientUseCase() throws Exception {
  final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Buildings");
  Map<String, Object> buildingData = new HashMap<String, Object>();
  buildingData.put("Id", "1");

  ExpandSelectTreeNode node1 = createBuildingNode();

  DataFeedCallback callback = new DataFeedCallback();
  Map<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>();
  callbacks.put("nb_Rooms", callback);

  final ODataResponse response =
      new JsonEntityProvider().writeEntry(entitySet, buildingData,
          EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).expandSelectTree(node1)
              .callbacks(callbacks).responsePayload(false).build());
  final String json = verifyResponse(response);
  assertEquals("{\"d\":{\"__metadata\":{\"id\":\"" + BASE_URI + "Buildings('1')\","
      + "\"uri\":\"" + BASE_URI + "Buildings('1')\",\"type\":\"RefScenario.Building\"},"
      + "\"nb_Rooms\":[{\"__metadata\":{\"id\":\"" + BASE_URI + "Rooms('1')\","
      + "\"uri\":\"" + BASE_URI + "Rooms('1')\",\"type\":\"RefScenario.Room\",\"etag\":\"W/\\\"1\\\"\"},"
      + "\"Id\":\"1\",\"Name\":null,\"Seats\":null,\"Version\":1,"
      + "\"nr_Employees\":{\"__deferred\":{\"uri\":\"" + BASE_URI + "Rooms('1')/nr_Employees\"}},"
      + "\"nr_Building\":{\"__deferred\":{\"uri\":\"" + BASE_URI + "Rooms('1')/nr_Building\"}}}]}}",
      json);
}
 
Example #26
Source File: JsonEntryEntityProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void entryWithExpandedFeed() throws Exception {
  final EdmEntitySet entitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Buildings");
  Map<String, Object> buildingData = new HashMap<String, Object>();
  buildingData.put("Id", "1");

  ExpandSelectTreeNode node1 = createBuildingNode();

  Map<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>();
  callbacks.put("nb_Rooms", new DataFeedCallback());

  final ODataResponse response =
      new JsonEntityProvider().writeEntry(entitySet, buildingData,
          EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).expandSelectTree(node1)
              .callbacks(callbacks).build());
  final String json = verifyResponse(response);
  assertEquals("{\"d\":{\"__metadata\":{\"id\":\"" + BASE_URI + "Buildings('1')\","
      + "\"uri\":\"" + BASE_URI + "Buildings('1')\",\"type\":\"RefScenario.Building\"},"
      + "\"nb_Rooms\":{\"results\":[{\"__metadata\":{\"id\":\"" + BASE_URI + "Rooms('1')\","
      + "\"uri\":\"" + BASE_URI + "Rooms('1')\",\"type\":\"RefScenario.Room\",\"etag\":\"W/\\\"1\\\"\"},"
      + "\"Id\":\"1\",\"Name\":null,\"Seats\":null,\"Version\":1,"
      + "\"nr_Employees\":{\"__deferred\":{\"uri\":\"" + BASE_URI + "Rooms('1')/nr_Employees\"}},"
      + "\"nr_Building\":{\"__deferred\":{\"uri\":\"" + BASE_URI + "Rooms('1')/nr_Building\"}}}]}}}",
      json);
}
 
Example #27
Source File: JPAServiceFactory.java    From lemonaid with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T extends ODataCallback> T getCallback(final Class<T> callbackInterface) {
	if (setDetailErrors == true) {
		if (callbackInterface.isAssignableFrom(ODataErrorCallback.class)) {
			return (T) new ODataJPAErrorCallback();
		}
	}
	if (onJPAWriteContent != null) {
		if (callbackInterface.isAssignableFrom(OnJPAWriteContent.class)) {
			return (T) onJPAWriteContent;
		}
	}
	if (oDataJPATransaction != null) {
		if (callbackInterface.isAssignableFrom(ODataJPATransaction.class)) {
			return (T) oDataJPATransaction;
		}
	}
	return null;
}
 
Example #28
Source File: BenefitsODataServiceFactory.java    From cloud-sfsf-benefits-ext with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T extends ODataCallback> T getCallback(final Class<? extends ODataCallback> callbackInterface) {
	setDetailErrors(true);

	if (callbackInterface.isAssignableFrom(ODataErrorCallback.class)) {
		return (T) new SimpleODataErrorCallback();
	}
	return null;
}
 
Example #29
Source File: DebugCallbackFactoryFlase.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T extends ODataCallback> T getCallback(final Class<T> callbackInterface) {
  if (callbackInterface.isAssignableFrom(FitErrorCallback.class)) {
    return (T) new FitErrorCallback();
  } else if (callbackInterface.isAssignableFrom(ODataDebugCallback.class)) {
    return (T) new ODataDebugCallback() {
      @Override
      public boolean isDebugEnabled() {
        return false;
      }
    };
  }
  return null;
}
 
Example #30
Source File: ScenarioServiceFactory.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T extends ODataCallback> T getCallback(final Class<T> callbackInterface) {
  return (T) (callbackInterface.isAssignableFrom(ScenarioErrorCallback.class) ?
      new ScenarioErrorCallback() : callbackInterface.isAssignableFrom(ODataDebugCallback.class) ?
          new ScenarioDebugCallback() : super.getCallback(callbackInterface));
}