Vitali Yarmolik created OLINGO-462:
--------------------------------------

             Summary: Multiplicity of navigation property is determined 
incorrectly
                 Key: OLINGO-462
                 URL: https://issues.apache.org/jira/browse/OLINGO-462
             Project: Olingo
          Issue Type: Bug
          Components: odata2-core
    Affects Versions: V2 2.0.0
            Reporter: Vitali Yarmolik


There is the following metadata of an OData service:
{code:xml}
<?xml version='1.0' encoding='UTF-8'?>
<edmx:Edmx Version="1.0" 
xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx";>
  <edmx:DataServices m:DataServiceVersion="1.0" 
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata";>
    <Schema Namespace="TestNamespace" 
xmlns="http://schemas.microsoft.com/ado/2008/09/edm";>
      <EntityType Name="Data">
        <Key>
          <PropertyRef Name="Key" />
        </Key>
        <Property Name="Key" Type="Edm.String" Nullable="false" />
        <NavigationProperty Name="Employee" 
Relationship="TestNamespace.Data_Employee" FromRole="Data"
                                        ToRole="Employee" />
      </EntityType>                     
      <EntityType Name="Employee">
        <Key>
          <PropertyRef Name="Key" />
        </Key>
        <Property Name="Key" Type="Edm.String" Nullable="false" />
        <Property Name="firstName" Type="Edm.String" Nullable="true" />
        <Property Name="lastName" Type="Edm.String" Nullable="true" />
        <NavigationProperty Name="colleagues" 
Relationship="TestNamespace.Employee_colleagues" FromRole="Employee" 
ToRole="Employee" />
      </EntityType>
      <Association Name="Data_Employee">
        <End Type="TestNamespace.Data" Multiplicity="1" Role="Data" />
        <End Type="TestNamespace.Employee" Multiplicity="1" Role="Employee" />
      </Association>
      <Association Name="Employee_colleagues">
        <End Type="TestNamespace.Employee" Multiplicity="1" Role="Employee" />
        <End Type="TestNamespace.Employee" Multiplicity="*" Role="Employee" />
      </Association>
      <EntityContainer Name="TestEntityContainer" 
m:IsDefaultEntityContainer="true">
        <EntitySet Name="Data" EntityType="TestNamespace.Data" />
        <EntitySet Name="Employee" EntityType="TestNamespace.Employee" />
        <AssociationSet Name="Data_Employee" 
Association="TestNamespace.Data_Employee">
          <End EntitySet="Data" Role="Data" />
          <End EntitySet="Employee" Role="Employee" />
        </AssociationSet>
        <AssociationSet Name="Employee_colleagues" 
Association="TestNamespace.Employee_colleagues">
          <End EntitySet="Employee" Role="Employee" />
          <End EntitySet="Employee" Role="Employee" />
        </AssociationSet>
      </EntityContainer>
    </Schema>
</edmx:DataServices>
</edmx:Edmx>
{code}

Having such metadata, it is not possible to expand multi-valued 'colleagues' 
navigation property of Employee entity using the following service request: 
{{.../Data?$expand=Employee/colleagues}}

The problem is in 
{{org.apache.olingo.odata2.core.edm.provider.EdmAssociationImplProv.getEndMultiplicity(String
 role)}} method, which is called to determine whether a navigation property is 
a feed or an entry. 
{code:java}
public EdmMultiplicity getEndMultiplicity(final String role) {
    if (association.getEnd1().getRole().equals(role)) {
      return association.getEnd1().getMultiplicity();
    }

    if (association.getEnd2().getRole().equals(role)) {
      return association.getEnd2().getMultiplicity();
    }

    return null;
  }
{code}
When the method is called to return multiplicity of 'colleagues' navigation 
property it returns {{EdmMultiplicity.ONE}} value because 'role' of the 
navigation property is equal to the role of End1, i.e. to the name of the 
containing entity type. As a result, it is expected that the expanded inline 
value will be an OData entry rather than a feed. It, in its turn, results in 
calling the implementation of 
{{org.apache.olingo.odata2.api.ep.callback.OnWriteEntryContent.retrieveEntryResult(WriteEntryCallbackContext)}}
 method to expand the navigation property as an entry. Because the navigation 
property is a feed and is represented as a {{java.util.List}} internally it 
cannot (and should not) be expanded as an entry.
To fix the issue the implementation of 
{{org.apache.olingo.odata2.core.edm.provider.EdmAssociationImplProv.getEndMultiplicity(String
 role)}} method should be changed,




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to