visoft / ruby_odata

OData Consumer for Ruby
http://bit.ly/IntroRubyOData
MIT License
107 stars 52 forks source link

Support m:FC_KeepInContent="false" and m:FC_TargetPath="SyndicationTitle" #6

Closed visoft closed 12 years ago

visoft commented 12 years ago

This issue was brought over from lighthouse... Reported by Nikuliak Aliaksei

If we have m:FC_KeepInContent="false" and m:FC_TargetPath="SyndicationTitle" in metadata like:

<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
  <edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="2.0">
    <Schema Namespace="WK.Velvet.Rsi.V1.Contracts" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://schemas.microsoft.com/ado/2007/05/edm">
      <EntityType Name="UserTracker">
        <Key>
          <PropertyRef Name="Id" />
        </Key>
        <Property Name="Id" Type="Edm.String" Nullable="false" />
        <Property Name="Title" Type="Edm.String" Nullable="true" m:FC_TargetPath="SyndicationTitle" m:FC_ContentKind="text" m:FC_KeepInContent="false" />

        <Property Name="TodayNewsCount" Type="Edm.Int32" Nullable="false" />
        <NavigationProperty Name="TodayNews" Relationship="WK.Velvet.Rsi.V1.Contracts.UserTracker_TodayNews" FromRole="UserTracker" ToRole="TodayNews" />
        <NavigationProperty Name="News" Relationship="WK.Velvet.Rsi.V1.Contracts.UserTracker_News" FromRole="UserTracker" ToRole="News" />
      </EntityType>
...

library is unable to read properties (title in our case) from syndication itself (//feed/entry/title):

<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<feed xml:base="http://velvet.intelliconnect.cch.com/velvet/rsi-v1.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
  <title type="text">UserTrackers</title>
  <id>http://velvet.intelliconnect.cch.com/velvet/rsi-v1.svc/UserTrackers</id>
  <updated>2011-04-14T09:14:17Z</updated>
  <link rel="self" title="UserTrackers" href="UserTrackers" />
  <entry>
    <id>http://velvet.intelliconnect.cch.com/velvet/rsi-v1.svc/UserTrackers('305262')</id>
    <title type="text">Federal Tax News</title>
    <updated>2011-04-14T09:14:17Z</updated>
    <author>
      <name />
    </author>
    <link rel="edit" title="UserTracker" href="UserTrackers('305262')" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/TodayNews" type="application/atom+xml;type=feed" title="TodayNews" href="UserTrackers('305262')/TodayNews" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/News" type="application/atom+xml;type=feed" title="News" href="UserTrackers('305262')/News" />
    <category term="WK.Velvet.Rsi.V1.Contracts.UserTracker" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <content type="application/xml">
      <m:properties>
        <d:Id>305262</d:Id>
        <d:TodayNewsCount m:type="Edm.Int32">16</d:TodayNewsCount>
      </m:properties>
    </content>
  </entry>
...

Also in service.rb we have to fix the following lines (not to throw NPE):

   194        gen_method_name = "#{prop_name}="
   195        if klass.respond_to? gen_method_name.to_sym
   196          klass.send gen_method_name, parse_value(prop)
   197        end
   217            # Add the property
   218            gen_method_name = "#{property_name}="
   219            if klass.respond_to? gen_method_name.to_sym
   220              klass.send gen_method_name, inline_klass
   221            end
visoft commented 12 years ago

This has been fixed in the develop branch https://github.com/visoft/ruby_odata/commit/f21c42f9368e49510b723bbe65937074425db320