1

I am trying to retrieve workitems from TFS Server using OData4j 0.7 in Java.

Here is my code:

public List<TFSWorkItem> getWorkItems(final String projectName)  
{
    final List<TFSWorkItem> tfsWorkItems = new ArrayList<TFSWorkItem>();
    String filter = String.format("Project eq '%s'", projectName);
    Enumerable<OEntity> workItems = consumer.getEntities("WorkItems").filter(filter).execute();
    for (OEntity workitem : workItems)
    {
        System.out.println(workitem.getProperty("Title", String.class));
    }
}

When I run this code I get a

Exception in thread "main" java.lang.IllegalArgumentException: Illegal datetime format 2013-03-15T14:22:08.077+05:30
at org.odata4j.internal.InternalUtil.parseDateTimeFromXml(InternalUtil.java:96)

On further debugging the code I found that OData4j when trying to map the retrieved date from TFS server finds it incompatible .

Date retrieved from TFS :

2013-03-15T14:22:08.077+05:30

Date expected by OData4j :

2013-03-15T14:22:08.077

Is there a way where I can avoid this?

Updated

For anybody who is facing the same issue.

I have modified my code to :

    final String fields = "Id,Project,Title";
    Enumerable<OEntity> workItems = consumer.getEntities("WorkItems").filter(filter).select(fields.toString()).execute();
    for (OEntity workitem : workItems)
    {
        System.out.println("Id : " + workitem.getProperty("Id").getValue());
        System.out.println("Project : "+workitem.getProperty("Project").getValue());
        System.out.println("Title : "+workitem.getProperty("Title").getValue());
    }

Since I need only these fields to process I have given a select query to select "Id","Project" and "Title" instead of fetching all fields. This is a temporary fix unless I find a better solution.

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

I think I figured this out. Check out this post: OData4J exception

Basically, it boils down to setting the value of an Edm.DateTime column in C# code using DateTime.Now. The OData Producer should be using DateTime.UtcNow.

DateTime.Now includes local time zone information. Microsoft's code sees the local time zone info in the DateTime structure and sends back the Edm.DataTime field formatted as an Edm.DateTimeOffset string. The DateTime.UtcNow property does not include any time zone information, so it is correctly formatted as an Edm.DateTime string when it is sent back to the OData Consumer.

I suspect this might be a bug in Microsoft's WCF Data Services stack or their Entity Framework.

Community
  • 1
  • 1
Quantium
  • 1,779
  • 1
  • 14
  • 14