karishma-tirthani / odata4j

Automatically exported from code.google.com/p/odata4j
0 stars 0 forks source link

DateTime processing #141

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Request a merge with a date property in Atom format
2. The object entity in mergeEntity(String entitySetName, OEntity entity) 
contains the property in String format, instead of the DateTime format

What is the expected output? What do you see instead?
I suppose the object entity in mergeEntity(String entitySetName, OEntity 
entity) should contain a property of type DateTime, just like it happens when 
sending the same request in JSON format.

What version of the product are you using? On what operating system?
0.5

Please provide any additional information below.

Metadata (where you can see the fields startDate and endDate in Appointment are 
in DateTime format):

<?xml version="1.0" encoding="utf-8"?><edmx:Edmx Version="1.0" 
xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" 
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" 
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><edmx:D
ataServices m:DataServiceVersion="1.0"><Schema 
xmlns="http://schemas.microsoft.com/ado/2006/04/edm" 
Namespace="Datastore"><EntityType Name="User"><Key><PropertyRef 
Name="id"></PropertyRef></Key><Property Name="name" Type="Edm.String" 
Nullable="false"></Property><NavigationProperty Name="devices" 
Relationship="Datastore.User.devices" FromRole="User" 
ToRole="Device"></NavigationProperty></EntityType><EntityType 
Name="Device"><Key><PropertyRef Name="id"></PropertyRef></Key><Property 
Name="name" Type="Edm.String" Nullable="false"></Property><Property 
Name="identifier" Type="Edm.String" 
Nullable="false"></Property><NavigationProperty Name="ownerId" 
Relationship="Datastore.Device.ownerId" FromRole="Device" 
ToRole="User"></NavigationProperty></EntityType><EntityType 
Name="Contact"><Key><PropertyRef Name="id"></PropertyRef></Key><Property 
Name="name" Type="Edm.String" Nullable="false"></Property><Property 
Name="phone" Type="Edm.String" Nullable="false"></Property><Property 
Name="email" Type="Edm.String" Nullable="false"></Property><NavigationProperty 
Name="ownerId" Relationship="Datastore.Contact.ownerId" FromRole="Contact" 
ToRole="User"></NavigationProperty></EntityType><EntityType 
Name="Location"><Key><PropertyRef Name="id"></PropertyRef></Key><Property 
Name="lat" Type="Edm.Double" Nullable="false"></Property><Property Name="lng" 
Type="Edm.Double" Nullable="false"></Property><Property Name="time" 
Type="Edm.DateTime" Nullable="false"></Property><NavigationProperty 
Name="ownerId" Relationship="Datastore.Location.ownerId" FromRole="Location" 
ToRole="Device"></NavigationProperty></EntityType><EntityType 
Name="Appointment"><Key><PropertyRef Name="id"></PropertyRef></Key><Property 
Name="name" Type="Edm.String" Nullable="false"></Property><Property 
Name="description" Type="Edm.String" Nullable="false"></Property><Property 
Name="startDate" Type="Edm.DateTime" Nullable="false"></Property><Property 
Name="endDate" Type="Edm.DateTime" 
Nullable="false"></Property></EntityType><EntityContainer Name="Container" 
m:IsDefaultEntityContainer="true"><EntitySet Name="User" 
EntityType="Datastore.User"></EntitySet><EntitySet Name="Device" 
EntityType="Datastore.Device"></EntitySet><EntitySet Name="Contact" 
EntityType="Datastore.Contact"></EntitySet><EntitySet Name="Location" 
EntityType="Datastore.Location"></EntitySet><EntitySet Name="Appointment" 
EntityType="Datastore.Appointment"></EntitySet></EntityContainer></Schema></edmx
:DataServices></edmx:Edmx>

Example request:

POST http://127.0.0.1:8888/datastore.svc/Appointment(199) HTTP/1.1
Origin: http://127.0.0.1:8888
X-HTTP-Method: MERGE
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.24 (KHTML, like 
Gecko) Chrome/19.0.1055.1 Safari/535.24
Content-Type: application/atom+xml
Accept: application/atomsvc+xml;q=0.8, application/json;q=0.5, */*;q=0.1
Referer: http://127.0.0.1:8888/home
DataServiceVersion: 1.0

<entry xmlns="http://www.w3.org/2005/Atom" 
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" 
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><author
><name/></author><title/><content 
type="application/xml"><m:properties><d:startDate>2012-02-29T03:00:00</d:startDa
te><d:endDate>2012-02-29T08:00:00</d:endDate><d:description/><d:name>asergfaserg
</d:name></m:properties></content></entry>

Resulting entity in mergeEntity():

OEntity[OProperty[startDate,EdmSimpleType[Edm.String],2012-02-29T03:00:00],OProp
erty[endDate,EdmSimpleType[Edm.String],2012-02-29T08:00:00],OProperty[descriptio
n,EdmSimpleType[Edm.String],],OProperty[name,EdmSimpleType[Edm.String],asergfase
rg]]

Original issue reported on code.google.com by miguel.ans@gmail.com on 2 Mar 2012 at 11:44

GoogleCodeExporter commented 8 years ago
here is the same example using a JSON request:

Request:

POST http://127.0.0.1:8888/datastore.svc/Appointment(202) HTTP/1.1
Origin: http://127.0.0.1:8888
X-HTTP-Method: MERGE
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.24 (KHTML, like 
Gecko) Chrome/19.0.1055.1 Safari/535.24
Content-Type: application/json
Accept: application/atomsvc+xml;q=0.8, application/json;q=0.5, */*;q=0.1
Referer: http://127.0.0.1:8888/home
DataServiceVersion: 1.0

{"startDate":"/Date(1330479000000)/","endDate":"/Date(1330488000000)/","descript
ion":"","name":"asgvsaerg"}

Resulting entity object:
OEntity[OProperty[startDate,EdmSimpleType[Edm.DateTime],2012-02-29T01:30:00.000]
,OProperty[endDate,EdmSimpleType[Edm.DateTime],2012-02-29T04:00:00.000],OPropert
y[description,EdmSimpleType[Edm.String],],OProperty[name,EdmSimpleType[Edm.Strin
g],asgvsaerg]]

Original comment by miguel.ans@gmail.com on 2 Mar 2012 at 11:47

GoogleCodeExporter commented 8 years ago
And... this is also happening while creating an entity.

Original comment by miguel.ans@gmail.com on 2 Mar 2012 at 11:51

GoogleCodeExporter commented 8 years ago
This problem most probably comes from a missing "type" attribute on the 
property element. If the edm type of a property is not defined in the feed, 
odata4j currently resolves it as Edm.String. I had a similar issue where a 
complex type arrived without type information which breaks feed parsing 
completely.

You could either change your service to include the proper "type" attribute or 
try to apply the patch attached to issue 143 to the current 0.6 snapshot. This 
tries to derive the edm type by looking it up in the service metadata.

Original comment by manuel.r...@gmail.com on 8 Mar 2012 at 2:57

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Thanks for your suggestion but I've tried with odata4j 0.6.0 and the problem 
still exists. I suppose the correct behavior would be to infer the property 
type by the metadata and not by what the client sends, right?

Original comment by miguel.ans@gmail.com on 21 Mar 2012 at 11:58

GoogleCodeExporter commented 8 years ago
The patch hasn't been integrated with odata4j yet. You would have to clone 
odata4j project, apply the patch and build the distribution jar files. Another 
option would be to define the property type attributes in the POST request's 
xml payload.

Original comment by manuel.r...@gmail.com on 21 Mar 2012 at 2:32

GoogleCodeExporter commented 8 years ago
I'm not using Atom currently in my project so I can wait until it's integrated 
in odata4j. Do you have any idea when will this be?
Thank you very much for your help.

Original comment by miguel.ans@gmail.com on 23 Mar 2012 at 8:28

GoogleCodeExporter commented 8 years ago
In the latest codebase, we use the property type if we have the metadata.  
Please reopen if you still see this after running against latest.

Original comment by john.spurlock on 10 Nov 2012 at 11:43