Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OData v4 support #39

Open
mackayj opened this issue Oct 7, 2014 · 43 comments
Open

OData v4 support #39

mackayj opened this issue Oct 7, 2014 · 43 comments

Comments

@mackayj
Copy link

mackayj commented Oct 7, 2014

Looks like there is a beta out for odatajs which gives OData v4 support to javascript.

http://olingo.apache.org/doc/javascript/

https://github.com/apache/olingo-odata4-js/tree/master/odatajs

We'd love to use OData v4 as it has many improvements over OData v3 which is what breeze (and any other js library) supports right now.

@Devora
Copy link

Devora commented Oct 19, 2014

+1

@michaelbromley
Copy link

I really really need OData v4 support in order to move forward on a very important project.

I just started hacking on the olingo odatajs library and I am putting together my own Breeze adapter to work with it. I've only been working on it for a few hours so far but I got GET requests seemingly working okay.

If this proves to be robust and useable, I will publish it somewhere.

@wardbell
Copy link
Member

wardbell commented Nov 5, 2014

Do stay in touch on that.

@nkgm
Copy link

nkgm commented Nov 7, 2014

Is official breeze support something we should hope to see fairly soon?
@michaelbromley 👍

@michaelbromley
Copy link

@wardbell sure thing. I've currently implemented the "read" side of things - it is working with the usual Breeze query methods like expand() and skip() and so on and links up the entities where relationships exist.

I'm currently working on write functionality - unfortunately the server API has not yet implemented batch mode so I am just waiting on that before I continue (hopefully it's working in the next day or so).

@michaelbromley
Copy link

For anyone interested, I have made a repo with my progress so far. note it's a quick-and-dirty hack of the existing adapter at the moment, don't judge me! 😉 https://github.com/michaelbromley/breezejs-odata4-adapter

Contribution is very welcome!

@nkgm
Copy link

nkgm commented Nov 27, 2014

Thanks @michaelbromley this is hugely appreciated - even more so, considering IdeaBlade would not appear to have any immediate plans to support the standard.

@snowping
Copy link

+1

@lelong37
Copy link

lelong37 commented Mar 7, 2015

+10

@levmatta
Copy link

+1

1 similar comment
@alehro
Copy link

alehro commented Mar 30, 2015

+1

@BoyceLyu
Copy link

+10086

@superstevek
Copy link

Is there an ETA for when OData v4 will be supported yet?

@wardbell
Copy link
Member

We are working on it now. We've been talking to the Microsoft OData team about lingering issues on their end that prevent us from proceeding ... or at least we don't want to move forward until we know what our path will be and what guidance we can give to you.

They've been very helpful and responsive and that has been great. I feel we'll have some good news soon.

@superstevek
Copy link

Hi Ward thanks for the info, We are keen to use breeze as it looks great, do you have any feeling for timeframes, 1 month, 3 months, 6 months, longer?

@wardbell
Copy link
Member

I have a feeling it will be 1 to 2 months. Not a commitment. But I'll be surprised and disappointed if it takes 2 months. We have options even if they aren't preferred options. HTH

@superstevek
Copy link

Thanks Ward that is great info, much appreciated.

@tschettler
Copy link
Contributor

Thanks @wardbell, I understand these things take time, especially when it comes to dealing with issues with the implementation of the new specification and I will voice my appreciation for your persistence! This has been a long time coming for me.

@crockelsET
Copy link

Hi, is there any update on when this may be available please?

@gordon-matt
Copy link

+1 : it's rather odd that OData v4 has been out for so long and breeze still doesn't support it. When is this happening??

@tschettler
Copy link
Contributor

I've created an updated OData V4 adapter based on the one from @michaelbromley that I have successfully integrated with ASP.NET WebApi OData 4: https://github.com/tschettler/breezejs-odata4-adapter

Fixes:

  • In the odatajs library itself, require was being initialized globally, so wrapped it in an IIFE
  • $metadata retrieval, including fixing up relationships and navigation properties for entities
  • Data retrieval using standard breezejs queries, including $expand
  • $batch support for CUD operations
  • Added IEEE754Compatible header so big decimals and integers parsed as string values are understood correctly

Not tested:

  • $select
  • paging with $top and $skip
  • anything else not listed in fixes

The adapter logic still needs some commenting and general cleanup, but I hope this helps someone.

-- Travis

@hemantsathe
Copy link

Hi Travis (@tschettler),
Thanks a lot for taking efforts to update this. Making the odatajs as IIFE fixed my issue. I have now been able to successfully make this work with my Angular code. This link also helped me fix the changes from datajs to olingo odatajs. Can you also let me know if caching the metadata is possible?

Regards,
Hemant

@tschettler
Copy link
Contributor

Glad to hear it helped you @hemantsathe!

I don't think it would be too difficult to cache the metadata, are you thinking of caching using localStorage or along those lines? I save the metadata to a local variable before I give it to breeze so that I can pass it back to odatajs for the $batch operation. With a little effort, you could check for a cached version of the metadata in the fetchMetaData function, before the odatajs.oData.read call.

@hemantsathe
Copy link

Thanks @tschettler . Will try that. I am getting an error on line 210 at schema.entityContainer.entitySet.find where find on an array is undefined. Are you using any library for this this function? This looks like ECMA2015 feature in JavaScript.

[Update] I changed the find function calls to filter and also returned the zeroth element from the result if available. This made the code work. There is a bug in breeze though. It processes the Guid values as guid'<guid-value>' whereas OData V4 expects only plain guid-value without quotes. I fixed both these changes on my side and most of the stuff is working. There are few changes in syntax between v3 and v4 but those should not be blocking.

Regards,
Hemant

tschettler added a commit to tschettler/breezejs-odata4-adapter that referenced this issue Aug 21, 2015
Fixes formatting for OData V4 primitives, based on the new JSON format,
issue referenced in
Breeze/breeze.js#39 (comment)
@tschettler
Copy link
Contributor

Thanks @hemantsathe,

You're right, sorry about that, there was a polyfill function. I changed it to use breeze.core.arrayFirst, in two places that were using it. tschettler/breezejs-odata4-adapter@f9785e4

The OData formatting issue you see with guids would also be present with any other primitives that use the verbose JSON format. I've updated the adapter to register new fmtOData functions for the affected data types. tschettler/breezejs-odata4-adapter@f4a333a

I tested a couple of the data types. There are likely still some issues present, but this will provide a way to configure the correct formats from the adapter.

@JanEggers
Copy link

hi @wardbell

any news on the official support of V4?

@cdennig
Copy link

cdennig commented Nov 11, 2015

hi there,

we are also waiting to use odata v4 together with breeze. are there any news you can share here regarding the integration?

thanks in advance...

chris

@ssiwach8
Copy link

@tschettler @muchaelbromley @wardbell @hemantsathe Any updatee here guys? I have been trying go use your custom adapter also but things are not moving forward in my code... Not sure how/what extra configuration you are having to make breeze work with odata v4. Please let me know if there is anything I am missing. I run into issue of 'require()' not defined as soon as I try to initialize above mentioned adapter even afterr having q.js.

@tschettler
Copy link
Contributor

@ssiwach8 Are you using the custom odatajs-4.0.0.js file from my forked adapter? The version from Apache registers the require() function into the global scope, so I have wrapped the initialization logic in an IIFE in the custom version. See the Usage section of the readme for more details.

The only other thing I've had to do is define odatajs in requirejs, I suppose you may need to do something similar if you are using a different AMD loader:

    define('odatajs', odatajs);

Can you provide more information on the error you are getting?

@ssiwach8
Copy link

@tschettler Yes I have downloaded both the files from your fork only. I got rid of the 'require not defined' error now but my Metadata query is still failing. Everything seems fine till the execution reaches Line # 84 of breezeOdataV4Adapter.js where after making the metadata read call it falls into its error promise section and displays an alert giving error as shown below:

"Error: Metadata query failed for: http://mysite/webapi/odata/$metadata;"

In fiddler it shows that the header for this is 'HTTP/1.1 405 Method Not Allowed'.
Strangely if I hit the same URL in browser or fiddler(standalone) it executes just fine. Not sure what is happening here. I also tried to manipulate the header at line # 87 of breezeOdataV4Adapter.js where the odatajs.odata.read() request is made for metadata but still no luck.
Please show a ray of hope here, I really need this to work.
UPDATE: As I drilled down further in fiddler the request header is like: OPTIONS /WebAPI/odata/$metadata HTTP/1.1.
Error seems to be because of the reason that method with which call is being made is "OPTIONS". Any thoughts on how we change it to "GET"?
Thanks in advance.

@cdennig
Copy link

cdennig commented Nov 25, 2015

Hi @ssiwach8,

this is correct and has nothing to do with breeze. This comes from the pre-flight request (CORS-related, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Preflighted_requests). You have to allow the verb OPTIONS via header field "Access-Control-Allow-Methods" on your server where the API runs.

Cheers,
Chris

@ssiwach8
Copy link

Hey,
Ok, so here is my thing.
I got the Options verb setting handled on my API server but then following things happened and I made following fixes:

  1. For entities which did not have any navigation property with them breezeodatav4adapter threw error at line # 148 so I put the whole loop under a condition to execute only if a navigation property exists.
  2. After this breeze.debug.js threw error at line # 9223 where it was checking related Navigation Property of something undefined -> dp : included a check here also to set only if it exists.
    With these 2 fixes I was able to read the data with metadata.
    But as soon as I tried for an insert operation It broke down with error: "Cannot attach an object of type (" + entity.entityType.name + ") to an EntityManager without first setting its key or setting its entityType 'AutoGeneratedKeyType' property to something other than 'None'". Fortunately all the tables in my database have autoGenerated primary key so I set the same everywhere in breeze.debug.js.
    I know these all are very dirty patches and these are certainly making my entity cache very unstable but I was desperate to make breeze work with odata v4 asap and seems like I have hit a dead end now. While performing a stand alone insert operation as soon as I call savechanges() it created a temp value for my primary key to send with data but I handled that too and deleted it from the data being sent.
    The problem now is that I don't understand why my POST request is getting an error 400 'Bad Request'
    below is the request body from fiddler:

--batch_d482-0e88-a8e7
Content-Type: application/json; boundary=changeset_c141-fe65-2290

--changeset_c141-fe65-2290
Content-Type: application/json
Content-Transfer-Encoding: binary

POST GCCP.WebAPI/odata/NoticeText HTTP/1.1
Content-ID: 1
Content-Type: application/json;IEEE754Compatible=true
Accept: application/json;q=0.9, /;q=0.1
OData-Version: 4.0
OData-MaxVersion: 4.0

{ "entityData": "to be sent to server" }
--changeset_c141-fe65-2290--

--batch_d482-0e88-a8e7--

Please suggest where and how I should make changes to insert an entity into my entity set named 'NoticeText' here? This weekend is all I have to prove the concept else the project architecture will move in different direction dropping breeze out of the picture.

@tschettler
Copy link
Contributor

@ssiwach8,

I apologize for the issues, I basically just got it working for my own use without additional testing yet.

You should be able to do what you need for identities without changing breeze. Try getting the entityType from the metadataStore and then calling setProperties on it. Something like:

    var noticeTextType = myEntityManager.metadataStore.getEntityType("NoticeText");
    noticeTextType.setProperties({ autoGeneratedKeyType: AutoGeneratedKeyType.Identity });

Also, the adapter uses batch requests, so you would need to enable batch routing in your WebApi. If you are using ASP.NET WebApi 2, this article lists configuring the OData endpoint for batch requests:
http://blogs.msdn.com/b/webdev/archive/2013/11/01/introducing-batch-support-in-web-api-and-web-api-odata.aspx

@meirb
Copy link

meirb commented May 15, 2016

any news regarding breeze official support for odatav4?

@lelong37
Copy link

+10000000

@MirzaAbazovic
Copy link

From Oct 7, 2014 until now and still no OData 4 Support.
Is Breeze dead ? Apache olingo (odatajs) is supporting OData 4 but I really prefer Breeze api.
Also https://github.com/janhommes/o.js is promising but in beta v0.3.0

@kferstl
Copy link
Contributor

kferstl commented Jul 22, 2016

+1
found this alternative, also looks promising: http://jaydata.org/

@tschettler
Copy link
Contributor

If you do want to use breeze with OData 4, check out my OData 4 adapter, it has worked very well for me:

https://github.com/tschettler/breezejs-odata4-adapter

It's a work in progress, but I plan to keep supporting it until breeze gets official OData 4 support.

@nigel-dewar
Copy link

Any word on BreezeJS support for OData v4?

@nigel-dewar
Copy link

???

@albertoVieiraNeto
Copy link

I'm currently searching for javascript datasource for a new project, one of the requirements is odata v4, is odata v4 officially supported by breeze? I saw a bunch of optional libraries/wrappers/forks from contributors and don't get me wrong I'm very thankful but would be awesome if it was officially supported.

@tschettler
Copy link
Contributor

While breeze.js does not currently support OData 4, I've been actively developing a library with the goal to enable full OData 4 support for the existing breeze.js library: https://github.com/tschettler/breeze-odata4

It's a work in progress, but it already has support for many OData 4 features. You're welcome to give it a try and let me know what you think.

@victorperez2911
Copy link

3 years.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests