GALAglobal / translationapi

The API is for anyone who wants to adopt best practices for a translation services API to interact with counterparts directly from your application or content management system. The API helps ensure interoperability for the most common tasks.
https://translate.taus.net/translate/taus-translation-api
MIT License
12 stars 3 forks source link

Posting a new translation request ignores creationDatetime attribute #24

Closed achimr closed 9 years ago

achimr commented 9 years ago

Steps to reproduce:

  1. Launch server with "node tausapiserver.js"
  2. Post new translation request: { "translationRequest": { "id": "2b575fdc-f6af-4b9e-850d-9dc0884c6595", "sourceLanguage": "de-DE", "targetLanguage": "en-US", "source": "Hallo Welt", "professional": true, "mt": false, "creationDatetime": "2014-05-20T19:20+01:00", "updateCounter": 0, "status": "initial" } } Result: Successful creation of request: { "id": "2b575fdc-f6af-4b9e-850d-9dc0884c6595", "sourceLanguage": "de-DE", "targetLanguage": "en-US", "source": "Hallo Welt", "mt": false, "professional": true, "status": "initial", "creationDatetime": "2014-10-14T14:51:06.670Z", "updateCounter": 0, "links": [ { "rel": "translation", "href": "http://localhost:3412/v2.0/translation/2b575fdc-f6af-4b9e-850d-9dc0884c6595", "type": "application/json", "title": "Newly created translation request 2b575fdc-f6af-4b9e-850d-9dc0884c6595 + created on Tue Oct 14 2014 10:51:06 GMT-0400 (Eastern Daylight Time)", "verb": "GET" }, { "rel": "translation.cancel", "href": "http://localhost:3412/v2.0/translation/cancel/2b575fdc-f6af-4b9e-850d-9dc0884c6595", "title": "Cancel translation request 2b575fdc-f6af-4b9e-850d-9dc0884c6595", "type": "application/json", "verb": "PATCH" }, { "rel": "translation.reject", "href": "http://localhost:3412/v2.0/translation/reject/2b575fdc-f6af-4b9e-850d-9dc0884c6595", "title": "Reject translation request 2b575fdc-f6af-4b9e-850d-9dc0884c6595", "type": "application/json", "verb": "PATCH" }, { "rel": "translation.confirm", "href": "http://localhost:3412/v2.0/translation/confirm/2b575fdc-f6af-4b9e-850d-9dc0884c6595", "title": "Confirm translation request 2b575fdc-f6af-4b9e-850d-9dc0884c6595", "type": "application/json", "verb": "PATCH" }, { "rel": "translation.accept", "href": "http://localhost:3412/v2.0/translation/accept/2b575fdc-f6af-4b9e-850d-9dc0884c6595", "title": "Accept translation request 2b575fdc-f6af-4b9e-850d-9dc0884c6595", "type": "application/json", "verb": "PATCH" }, { "rel": "translation.patch", "href": "http://localhost:3412/v2.0/translation/2b575fdc-f6af-4b9e-850d-9dc0884c6595", "title": "Patch translation request 2b575fdc-f6af-4b9e-850d-9dc0884c6595", "type": "application/json", "verb": "PATCH" } ] }

Issues: The attribute creationDatetime specified in the request is ignored. Instead the current date/time is used.

Expected: Specified creationDatetime to be put in data set

achimr commented 9 years ago

The server also does not verify the creationDatetime value. It should complain about not being in the UTC time zone (the server won't have the knowledge in which time zone the client is).

heartsomeXPhantom commented 9 years ago

This is complicated and there is no easy function to verify this. We should expect the time zone is created correctly. Normally time and date is created with a server / client function (as in JavaScript or PHP) which automatically create the correct date.

achimr commented 9 years ago

To clarify: the server should not accept ISO-8601 date/times that are not in UTC format. The Javascript engine V8 included in node.js supports ECMAscript 5. With this the Date.parse function can parse ISO-8601. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse You only need to check that the incoming date string ends with a "Z" before parsing. For conversion from a Date object ECMAscript 5 supports Date.toISOstring() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString

heartsomeXPhantom commented 9 years ago

The implementation ignores any incoming dates anyway, as these are attributes which are always generated by the server and cannot be set from external. So I see no need for this check.

achimr commented 9 years ago

Per specification creationDatetime is an allowed optional attribute. The examples in the spec list it too.

heartsomeXPhantom commented 9 years ago

I will add the check in one of the next version. I have to add that the basic idea of the date attributes is that they are always automatically created by the rest server, never entered by the user. And the assumption is that the rest server created correct dates. This is also the reason why the server ignores any dates in a POST or PUT request as they are always geenrated automatically - at least by this test server.

achimr commented 9 years ago

Unfortunately there is one more issue in the latest version (2.0i): creationDatetime is now returned in a creationDatetime: "Mon, 10 Nov 2014 19:28:43 GMT" Expected: ISO-8601 format creationDatetime: "2014-11-10T19:28:43Z"

heartsomeXPhantom commented 9 years ago

toISOString() now used for DateString. Version 2.0j