Java Code Examples for org.apache.olingo.commons.api.data.Entity#getNavigationLink()

The following examples show how to use org.apache.olingo.commons.api.data.Entity#getNavigationLink() . 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: DataProvider.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void handleDeleteSingleNavigationProperties(final EdmEntitySet edmEntitySet, final Entity entity,
    final Entity changedEntity) throws DataProviderException {
  final EdmEntityType entityType = edmEntitySet.getEntityType();
  final List<String> navigationPropertyNames = entityType.getNavigationPropertyNames();

  for (final String navPropertyName : navigationPropertyNames) {
    final Link navigationLink = changedEntity.getNavigationLink(navPropertyName);
    final EdmNavigationProperty navigationProperty = entityType.getNavigationProperty(navPropertyName);
    if (!navigationProperty.isCollection() && navigationLink != null && navigationLink.getInlineEntity() == null) {

      // Check if partner is available
      if (navigationProperty.getPartner() != null && entity.getNavigationLink(navPropertyName) != null) {
        Entity partnerEntity = entity.getNavigationLink(navPropertyName).getInlineEntity();
        removeLink(navigationProperty.getPartner(), partnerEntity);
      }

      // Remove link
      removeLink(navigationProperty, entity);
    }
  }
}
 
Example 2
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void setLinks(final Entity entity, final String navigationPropertyName, final Entity... targets) {
  if(targets.length == 0) {
    return;
  }
  
  Link link = entity.getNavigationLink(navigationPropertyName);
  if (link == null) {
    link = new Link();
    link.setRel(Constants.NS_NAVIGATION_LINK_REL + navigationPropertyName);
    link.setType(Constants.ENTITY_SET_NAVIGATION_LINK_TYPE);
    link.setTitle(navigationPropertyName);
    link.setHref(entity.getId().toASCIIString() + "/" + navigationPropertyName);

    EntityCollection target = new EntityCollection();
    target.getEntities().addAll(Arrays.asList(targets));
    link.setInlineEntitySet(target);
    
    entity.getNavigationLinks().add(link);
  } else {
    link.getInlineEntitySet().getEntities().addAll(Arrays.asList(targets));
  }
}
 
Example 3
Source File: DataCreator.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
protected static void setLinks(final Entity entity, final String navigationPropertyName, final Entity... targets) {
  Link link = entity.getNavigationLink(navigationPropertyName);
  if (link == null) {
    link = new Link();
    link.setRel(Constants.NS_NAVIGATION_LINK_REL + navigationPropertyName);
    link.setType(Constants.ENTITY_SET_NAVIGATION_LINK_TYPE);
    link.setTitle(navigationPropertyName);
    EntityCollection target = new EntityCollection();
    target.getEntities().addAll(Arrays.asList(targets));
    link.setInlineEntitySet(target);
    link.setHref(entity.getId().toASCIIString() + "/" + navigationPropertyName);
    entity.getNavigationLinks().add(link);
  } else {
    link.getInlineEntitySet().getEntities().addAll(Arrays.asList(targets));
  }
}
 
Example 4
Source File: ResponseUtil.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public static void setLink(Entity entity, final String navigationPropertyName, final Entity target) {
  Link link = entity.getNavigationLink(navigationPropertyName);
  if (link == null) {
    link = new Link();
    link.setType(Constants.ENTITY_NAVIGATION_LINK_TYPE);
    link.setTitle(navigationPropertyName);
    entity.getNavigationLinks().add(link);
  }
  link.setInlineEntity(target);
}
 
Example 5
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private void setLink(final Entity entity, final String navigationPropertyName, final Entity target) {
  Link link = entity.getNavigationLink(navigationPropertyName);
  if (link == null) {
    link = new Link();
    link.setRel(Constants.NS_NAVIGATION_LINK_REL + navigationPropertyName);
    link.setType(Constants.ENTITY_NAVIGATION_LINK_TYPE);
    link.setTitle(navigationPropertyName);
    link.setHref(target.getId().toASCIIString());
    
    entity.getNavigationLinks().add(link);
  }
  link.setInlineEntity(target);
}
 
Example 6
Source File: ODataDeserializerDeepUpdateTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void esAllPrimExpandedToOne() throws Exception {
  final Entity entity = deserialize("EntityESAllPrimExpandedNavPropertyETTwoPrimOneUpdate.json");

  Link navigationLink = entity.getNavigationLink("NavPropertyETTwoPrimOne");
  assertNotNull(navigationLink);

  assertEquals("NavPropertyETTwoPrimOne", navigationLink.getTitle());
  assertEquals(Constants.ENTITY_NAVIGATION_LINK_TYPE, navigationLink.getType());
  assertNotNull(navigationLink.getInlineEntity());
  assertNull(navigationLink.getInlineEntitySet());
}
 
Example 7
Source File: ODataJsonDeserializerEntityTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void extendedEntityProperty() throws Exception {
  final String payload = "{\n" + 
      "   \"@odata.context\":\"$metadata#ETKeyPrimNav/$entity\",\n" + 
      "   \"@odata.metadataEtag\":\"W/metadataETag\",\n" + 
      "   \"@odata.etag\":\"W/32767\",\n" + 
      "   \"PropertyInt16\":32767,\n" + 
      "   \"PropertyString\":\"string\",\n" + 
      "   \"NavPropertyETKeyPrimNavOne\":\n" + 
      "      {\n" + 
      "         \"@odata.type\":\"#olingo.odata.test1.ETKeyPrimNavDerived\",\n" + 
      "         \"PropertyInt16\":32767,\n" + 
      "         \"PropertyString\":\"First Resource - first\",\n" + 
      "         \"PropertyBoolean\":true\n" + 
      "      }\n" + 
      "   \n" + 
      "}";
  final Entity result = deserialize(payload, "ETKeyPrimNav");
  Assert.assertNotNull(result);
  Link navProperty = result.getNavigationLink("NavPropertyETKeyPrimNavOne");
  Assert.assertNotNull(navProperty);
  Entity e = navProperty.getInlineEntity();
  Assert.assertNotNull(e);
  Assert.assertEquals("olingo.odata.test1.ETKeyPrimNavDerived", e.getType());
  Assert.assertEquals(new Short((short)32767), e.getProperty("PropertyInt16").getValue());
  Assert.assertEquals("First Resource - first", e.getProperty("PropertyString").getValue());
  Assert.assertEquals(true, e.getProperty("PropertyBoolean").getValue());
}
 
Example 8
Source File: ODataDeserializerDeepInsertTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void esAllPrimExpandedToMany() throws Exception {
  final Entity entity = deserialize("EntityESAllPrimExpandedNavPropertyETTwoPrimMany.json");

  Link navigationLink = entity.getNavigationLink("NavPropertyETTwoPrimMany");
  assertNotNull(navigationLink);

  assertEquals("NavPropertyETTwoPrimMany", navigationLink.getTitle());
  assertEquals(Constants.ENTITY_SET_NAVIGATION_LINK_TYPE, navigationLink.getType());
  assertNull(navigationLink.getInlineEntity());
  assertNotNull(navigationLink.getInlineEntitySet());
  assertEquals(1, navigationLink.getInlineEntitySet().getEntities().size());
}
 
Example 9
Source File: DataCreator.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
protected static void setLink(final Entity entity, final String navigationPropertyName, final Entity target) {
  Link link = entity.getNavigationLink(navigationPropertyName);
  if (link == null) {
    link = new Link();
    link.setRel(Constants.NS_NAVIGATION_LINK_REL + navigationPropertyName);
    link.setType(Constants.ENTITY_NAVIGATION_LINK_TYPE);
    link.setTitle(navigationPropertyName);
    link.setHref(target.getId() != null ? target.getId().toASCIIString() : null);
    entity.getNavigationLinks().add(link);
  }
  link.setInlineEntity(target);
}
 
Example 10
Source File: DataCreator.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
protected static void setLinkForContNav(final Entity entity, 
    final String navigationPropertyName, final Entity target) {
  Link link = entity.getNavigationLink(navigationPropertyName);
  if (link == null) {
    link = new Link();
    link.setRel(Constants.NS_NAVIGATION_LINK_REL + navigationPropertyName);
    link.setType(Constants.ENTITY_NAVIGATION_LINK_TYPE);
    link.setTitle(navigationPropertyName);
    link.setHref(entity.getId().toASCIIString() + 
        (navigationPropertyName != null && navigationPropertyName.length() > 0 ? "/" + navigationPropertyName: ""));
    entity.getNavigationLinks().add(link);
  }
  link.setInlineEntity(target);
}
 
Example 11
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public Entity getRelatedEntity(Entity entity, UriResourceNavigation navigationResource) 
    throws ODataApplicationException {
  
  final EdmNavigationProperty edmNavigationProperty = navigationResource.getProperty();
  
  if(edmNavigationProperty.isCollection()) {
    return Util.findEntity(edmNavigationProperty.getType(), getRelatedEntityCollection(entity, navigationResource), 
       navigationResource.getKeyPredicates());
  } else {
    final Link link = entity.getNavigationLink(edmNavigationProperty.getName());
    return link == null ? null : link.getInlineEntity();
  }
}
 
Example 12
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public Entity getRelatedEntity(Entity entity, UriResourceNavigation navigationResource) 
    throws ODataApplicationException {
  
  final EdmNavigationProperty edmNavigationProperty = navigationResource.getProperty();
  
  if(edmNavigationProperty.isCollection()) {
    return Util.findEntity(edmNavigationProperty.getType(), getRelatedEntityCollection(entity, navigationResource), 
       navigationResource.getKeyPredicates());
  } else {
    final Link link = entity.getNavigationLink(edmNavigationProperty.getName());
    return link == null ? null : link.getInlineEntity();
  }
}
 
Example 13
Source File: DataCreator.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private void setLinkWithoutEntityID(Entity entity, String navigationPropertyName, Entity target) {
  Link link = entity.getNavigationLink(navigationPropertyName);
  target.setId(null);
  if (link == null) {
    link = new Link();
    link.setRel(Constants.NS_NAVIGATION_LINK_REL + navigationPropertyName);
    link.setType(Constants.ENTITY_NAVIGATION_LINK_TYPE);
    link.setTitle(navigationPropertyName);
    link.setHref(target.getId() != null ? target.getId().toASCIIString() : null);
    entity.getNavigationLinks().add(link);
  }
  link.setInlineEntity(target);
}
 
Example 14
Source File: ActionData.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
protected static EntityActionResult entityBoundActionWithNavigation(final String name, 
    final Map<String, Parameter> parameters,
    final Map<String, EntityCollection> data, List<UriParameter> keyList, 
    EdmEntitySet edmEntitySet, EdmNavigationProperty navProperty) 
        throws DataProviderException {
  List<Object> keyPropertyValues = new ArrayList<Object>();
  List<String> keyPropertyNames = new ArrayList<String>();
  if ("BAETTwoKeyNavRTETTwoKeyNavParam".equals(name)) {
    if (!keyList.isEmpty()) {
      setBindingPropertyKeyNameAndValue(keyList, edmEntitySet, keyPropertyValues, keyPropertyNames);
      EntityCollection entityCollection = data.get(edmEntitySet.getName());
      Entity entity = getSpecificEntity(entityCollection, keyPropertyValues, keyPropertyNames);
      
      Link link = entity.getNavigationLink(navProperty.getName());
      Entity inlineEntity = link.getInlineEntity();
      ComplexValue complexValue = inlineEntity.getProperty("PropertyComp").asComplex();
      List<Property> complexProperties = complexValue.getValue();
      Iterator<Property> itr = complexProperties.iterator();
      Parameter actionParam = parameters.get("PropertyComp");
      Property actionProp = actionParam.asComplex().getValue().get(0);
      while (itr.hasNext()) {
        Property property = itr.next();
        if (property.getName().equals(actionProp.getName())) {
          property.setValue(actionProp.getValueType(), actionProp.getValue());
          break;
        }
      }
      return new EntityActionResult().setEntity(inlineEntity);
      }
  }
  throw new DataProviderException("Action " + name + " is not yet implemented.",
      HttpStatusCode.NOT_IMPLEMENTED);
}
 
Example 15
Source File: DataProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public Entity createContNav(final EdmEntitySet edmEntitySet, final EdmEntityType edmEntityType, 
    final Entity newEntity, List<UriParameter> keys, String navPropertyName) throws DataProviderException {
  List<Entity> rootEntity = data.get(edmEntitySet.getName()).getEntities();
  EntityCollection entitySet = data.get(edmEntityType.getName());
  entitySet.getEntities().add(newEntity);
  
  
  
  for (Entity entity : rootEntity) {
    if (isRootEntity(entity, keys)){
      String id = entity.getId().toASCIIString() + "/" + navPropertyName + 
          appendKeys(newEntity.getProperties(), edmEntityType.getKeyPredicateNames());
      newEntity.setId(URI.create(id));
      
      Link link = entity.getNavigationLink(navPropertyName);
      if (link == null) {
        link = new Link();
        link.setRel(Constants.NS_NAVIGATION_LINK_REL + navPropertyName);
        link.setType(Constants.ENTITY_NAVIGATION_LINK_TYPE);
        link.setTitle(navPropertyName);
        link.setHref(entity.getId().toASCIIString() + 
            (navPropertyName != null && navPropertyName.length() > 0 ? "/" + navPropertyName: ""));
        entity.getNavigationLinks().add(link);
      }
      if (link.getInlineEntitySet() != null) {
        link.getInlineEntitySet().getEntities().add(newEntity);
      } else {
        EntityCollection collection = new EntityCollection();
        collection.getEntities().add(newEntity);
        link.setInlineEntitySet(collection);
      }
    }
  }
  
  return newEntity;
}
 
Example 16
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public Entity getRelatedEntity(Entity entity, UriResourceNavigation navigationResource) 
    throws ODataApplicationException {
  
  final EdmNavigationProperty edmNavigationProperty = navigationResource.getProperty();
  
  if(edmNavigationProperty.isCollection()) {
    return Util.findEntity(edmNavigationProperty.getType(), getRelatedEntityCollection(entity, navigationResource), 
       navigationResource.getKeyPredicates());
  } else {
    final Link link = entity.getNavigationLink(edmNavigationProperty.getName());
    return link == null ? null : link.getInlineEntity();
  }
}
 
Example 17
Source File: ExpandSystemQueryOptionHandler.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
private void applyExpandOptionToEntity(final Entity entity, final EdmBindingTarget edmBindingTarget,
    final ExpandOption expandOption, final UriInfoResource uriInfo, final Edm edm) throws ODataApplicationException {

  final EdmEntityType entityType = edmBindingTarget.getEntityType();

  for (ExpandItem item : expandOption.getExpandItems()) {
    if(item.getLevelsOption() != null) {
      throw new ODataApplicationException("$levels is not implemented", 
          HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
    }
    
    List<EdmNavigationProperty> navigationProperties = new ArrayList<EdmNavigationProperty>();
    if(item.isStar()) {
      List<EdmNavigationPropertyBinding> bindings = edmBindingTarget.getNavigationPropertyBindings();
      for (EdmNavigationPropertyBinding binding : bindings) {
        EdmElement property = entityType.getProperty(binding.getPath());
        if(property instanceof EdmNavigationProperty) {
          navigationProperties.add((EdmNavigationProperty) property);
        }
      }
    } else {
      final List<UriResource> uriResourceParts = item.getResourcePath().getUriResourceParts();
      if (uriResourceParts.get(0) instanceof UriResourceNavigation) {
        navigationProperties.add(((UriResourceNavigation) uriResourceParts.get(0)).getProperty());
      }
    }

    for (EdmNavigationProperty navigationProperty: navigationProperties) {
      final String navPropertyName = navigationProperty.getName();
      final EdmBindingTarget targetEdmEntitySet = edmBindingTarget.getRelatedBindingTarget(navPropertyName);

      final Link link = entity.getNavigationLink(navPropertyName);
      if (link != null && entityType.getNavigationProperty(navPropertyName).isCollection()) {
        applyOptionsToEntityCollection(link.getInlineEntitySet(),
            targetEdmEntitySet,
            item.getFilterOption(),
            item.getOrderByOption(),
            item.getCountOption(),
            item.getSkipOption(),
            item.getTopOption(),
            item.getExpandOption(),
            uriInfo, edm);
      }
    }
  }
}
 
Example 18
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
public EntityCollection getRelatedEntityCollection(Entity entity, String navigationPropertyName) {
  final Link link = entity.getNavigationLink(navigationPropertyName);
  return link == null ? new EntityCollection() : link.getInlineEntitySet();
}
 
Example 19
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
public EntityCollection getRelatedEntityCollection(Entity entity, UriResourceNavigation navigationResource) {
  final Link link = entity.getNavigationLink(navigationResource.getProperty().getName());
  return link == null ? new EntityCollection() : link.getInlineEntitySet();
}
 
Example 20
Source File: ODataJsonSerializerTest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Test
public void entityESKeyNavContFullMetadataWithContNav() throws Exception {
  final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESKeyNavCont");
  final Entity entity = data.readAll(edmEntitySet).getEntities().get(1);
  Link link = entity.getNavigationLink("NavPropertyETContMany");
  InputStream result = serializerFullMetadata.entityCollection(metadata, 
      edmEntitySet.getEntityType().getNavigationProperty("NavPropertyETContMany").getType(), 
      link.getInlineEntitySet(),
      EntityCollectionSerializerOptions.with()
          .contextURL(ContextURL.with().
              type(edmEntitySet.getEntityType().getNavigationProperty("NavPropertyETContMany").getType())
              .entitySetOrSingletonOrType("ESKeyNavCont(-365)/NavPropertyETContMany").build())
          .build()).getContent();
  final String resultString = IOUtils.toString(result);
  final String expected = "{\"@odata.context\":\"$metadata#ESKeyNavCont%28-365%29%2FNavPropertyETContMany\","
      + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\",\"value\":[{"
      + "\"@odata.type\":\"#olingo.odata.test1.ETCont\",\"@odata.id\":"
      + "\"ESKeyNavCont(-365)/NavPropertyETContMany(-32768)\","
      + "\"[email protected]\":\"#Int16\",\"PropertyInt16\":-32768,"
      + "\"PropertyString\":\"Second Resource - negative values\",\"[email protected]\":"
      + "\"#Int32\",\"PropertyInt32\":-2147483648,\"[email protected]\":\"#Int64\","
      + "\"PropertyInt64\":-9223372036854775808,\"[email protected]\":\"#Single\","
      + "\"PropertySingle\":-1.79E8,\"PropertyDouble\":-179000.0,"
      + "\"[email protected]\":\"#Decimal\",\"PropertyDecimal\":-34,"
      + "\"[email protected]\":\"#Binary\",\"PropertyBinary\":\"ASNFZ4mrze8=\","
      + "\"[email protected]\":\"#Date\",\"PropertyDate\":\"2015-11-05\","
      + "\"[email protected]\":\"#DateTimeOffset\","
      + "\"PropertyDateTimeOffset\":\"2005-12-03T07:17:08Z\","
      + "\"[email protected]\":\"#Duration\","
      + "\"PropertyDuration\":\"PT9S\",\"[email protected]\":"
      + "\"#Guid\",\"PropertyGuid\":\"76543201-23ab-cdef-0123-456789dddfff\","
      + "\"[email protected]\":\"#TimeOfDay\","
      + "\"PropertyTimeOfDay\":\"23:49:14\",\"PropertyBoolean\":false,"
      + "\"[email protected]\":\"#Byte\",\"PropertyByte\":0,"
      + "\"[email protected]\":\"#SByte\",\"PropertySByte\":-128},"
      + "{\"@odata.type\":\"#olingo.odata.test1.ETCont\","
      + "\"@odata.id\":\"ESKeyNavCont(-365)/NavPropertyETContMany(0)\","
      + "\"[email protected]\":\"#Int16\",\"PropertyInt16\":0,"
      + "\"PropertyString\":\"\",\"[email protected]\":\"#Int32\","
      + "\"PropertyInt32\":0,\"[email protected]\":\"#Int64\","
      + "\"PropertyInt64\":0,\"[email protected]\":\"#Single\","
      + "\"PropertySingle\":0.0,\"PropertyDouble\":0.0,"
      + "\"[email protected]\":\"#Decimal\",\"PropertyDecimal\":0,"
      + "\"[email protected]\":\"#Binary\",\"PropertyBinary\":\"\","
      + "\"[email protected]\":\"#Date\",\"PropertyDate\":\"1970-01-01\","
      + "\"[email protected]\":\"#DateTimeOffset\","
      + "\"PropertyDateTimeOffset\":\"2005-12-03T00:00:00Z\","
      + "\"[email protected]\":\"#Duration\",\"PropertyDuration\":\"PT0S\","
      + "\"[email protected]\":\"#Guid\","
      + "\"PropertyGuid\":\"76543201-23ab-cdef-0123-456789cccddd\","
      + "\"[email protected]\":\"#TimeOfDay\","
      + "\"PropertyTimeOfDay\":\"00:01:01\",\"PropertyBoolean\":false,"
      + "\"[email protected]\":\"#Byte\",\"PropertyByte\":0,"
      + "\"[email protected]\":\"#SByte\",\"PropertySByte\":0}]}";        

  Assert.assertEquals(expected, resultString);
}