olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kobl...@apache.org
Subject git commit: [OLINGO-324] add date/time convertion
Date Mon, 04 Aug 2014 13:24:46 GMT
Repository: olingo-odata4-js
Updated Branches:
  refs/heads/master 88c0592e6 -> 46937a7af


[OLINGO-324] add date/time convertion


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/commit/46937a7a
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/tree/46937a7a
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/diff/46937a7a

Branch: refs/heads/master
Commit: 46937a7afccff1c67f9233fe530039ff33296905
Parents: 88c0592
Author: Sven Kobler <sven.kobler-morris@sap.com>
Authored: Mon Aug 4 15:24:26 2014 +0200
Committer: Sven Kobler <sven.kobler-morris@sap.com>
Committed: Mon Aug 4 15:24:26 2014 +0200

----------------------------------------------------------------------
 datajs/demo/tester.html       | 393 +++++++++----------------------------
 datajs/src/lib/odata/json.js  |  88 +++++++--
 datajs/src/lib/odata/utils.js |  39 +++-
 3 files changed, 203 insertions(+), 317 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/46937a7a/datajs/demo/tester.html
----------------------------------------------------------------------
diff --git a/datajs/demo/tester.html b/datajs/demo/tester.html
index 55a0ac0..041f7cd 100644
--- a/datajs/demo/tester.html
+++ b/datajs/demo/tester.html
@@ -25,50 +25,109 @@
             .code .text{color:#000000;}
             .code .cdata{color:#008080;}
             .code .comment,.code .ns{color:#666666;}
+
+            .left {
+                left : 20px;
+                position:relative;
+            }
+
         </style>
     </head>   
     <body>
-        <button id="startXML">XML</button><br/>
-        <button id="btnJSON_none">pure JSON odata.metadata=none</button><br/>
-        <button id="btnJSON_minimal">pure JSON odata.metadata=minimal</button><br/>
-        <button id="btnJSON_minimal_to_full">pure JSON odata.metadata=minimal; extendMetadataToLevel=full</button><br/>
-        <button id="btnJSON_minimal_to_all">pure JSON odata.metadata=minimal; extendMetadataToLevel=all</button><br/>
-        <button id="btnJSON_full">pure JSON odata.metadata=full</button><br/>
-        <button id="btnJSON_full_date_conversion">JSON odata.metadata=full (with date
conversion)</button><br/>
-        <button id="btnJSON_full_to_all">JSON odata.metadata=full; extendMetadataToLevel=all
(with adding types for string, bool, numbers)</button><br/>
-        <button id="btnJSON_full_to_all_date_conversion">JSON odata.metadata=full;
extendMetadataToLevel=all (with adding types for string, bool, numbers) (with date conversion)</button><br/>
-        <button id="btnJSON_entry_minimal">Entry pure JSON odata.metadata=minimal</button><br/>
-        <button id="btnJSON_entry_minimal_to_full">Entry pure JSON odata.metadata=minimal;
extendMetadataToLevel=full</button><br/>
-        <button id="btnJSON_entry_minimal_to_all">Entry pure JSON odata.metadata=minimal;
extendMetadataToLevel=all</button><br/>
-
-        <button id="btnMetaData">MetaData</button><br/>
-        <button id="btnJSONwithMetaData">JSON with MetaData</button><br/>
-        <button id="btnPOST_entry_food">POST food entry</button><br/>
-        <button id="btnPOST_entry_categorie">POST categorie entry</button><br/>
-
-        <button id="btnGET_collection_full_simple">GET collection odata.metadata=full</button><br/>
-        <button id="btnGET_collection_minimal_simple">GET collection odata.metadata=minimal</button><br/>
-        <button id="btnGET_collection_full_complex">GET complex collection odata.metadata=full</button><br/>
-        <button id="btnGET_collection_minimal_complex">GET complex collection odata.metadata=minimal</button><br/>
-        <button id="btnGET_property_full_name">GET property odata.metadata=full</button><br/>
-        <button id="btnGET_property_minimal_name">GET property odata.metadata=minimal</button><br/>
-        <button id="btnGET_property_full_complex">GET complex  property odata.metadata=full</button><br/>
-        <button id="btnGET_property_minimal_complex">GET complex property odata.metadata=minimal</button><br/>
+        <table><tr><td valign="top" width="150px">
+            Metadata<br>
+            <input type="radio" id="inMetadata1" name="inMetadata" value="none"/> 
                     
+            <label for="inMetadata1">none</label><br>
+
+            <input type="radio" id="inMetadata2" name="inMetadata" value="minimal" checked="checked"/>
 
+            <label for="inMetadata2">minimal<br>
+            <div class="left">                                   
+                <input type="checkbox" id="inMinimalToFull">                      
            
+                <label for="inMinimalToFull" id="lblInMinimalToFull">minimal to full</label><br>
+            </div>
+
+            <input type="radio" id="inMetadata3" name="inMetadata" value="full"><label
for="inMetadata3">full</label>
+            <br>
+            Recognize Dates<br>
+            <input type="checkbox" id="inRecognizeDates"><label for="check1">yes/no</label><br>
+
+        </td><td>
+            <div id="buttons"></div>
+        </td><td>
+            <button id="btnMetaData">MetaData</button><br/>
+            <button id="btnPOST_entry_food">POST food entry</button><br/>
+            <button id="btnPOST_entry_categorie">POST categorie entry</button><br/>
+        </td></tr></table>
         <div id='resultsArea' data-type="json">
         </div>
         <script>
-            //var x = eval("(function (w, undefined) {alert('A '+JSON.stringify(w.screen));})(this);");
-            //(function () {
-            //    var x = eval("(function (w, undefined) {alert('B '+JSON.stringify(w.screen));})(this);");
-            //})();
-            
+            // Config
+            var config = [
+                { name: 'Feed', url: 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods'},
+                { name: 'Entry', url: 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods(0)'},
+                { name: 'Collection of Complex', url: 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods(0)/Providers'},
+                { name: 'Collection of Simple', url: 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods(0)/AlternativeNames'},
+                { name: 'Complex property', url: 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods(0)/Packaging'},
+                { name: 'Simple property', url: 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods(0)/Name'},
+            ];
+
+            // UI Stuff
+            var createButtonClickHandler = function(nr) {
+                return function() { buttonClick(nr);};
+            };
+
+            var buttonRoot = $('#buttons');
+            $("input[name*='inMetadata'").click( function() {
+                var metadata = $("input[name*='inMetadata']:checked").val();
+                if (metadata === "minimal") {
+                    $("#lblInMinimalToFull").css('color', '#000000');
+                    $("#inMinimalToFull").removeAttr('disabled');
+                } else {
+                    $("#lblInMinimalToFull").css('color', '#999999');
+                    $("#inMinimalToFull").attr('disabled','disabled');
+                }
+            });
+
+            for (var i = 0; i < config.length; i++) {
+                var button = $('<button id="btnArray">'+config[i].name+'</button><br/>"');
+                button.click( createButtonClickHandler(i));
+                buttonRoot.append(button);
+            }
+
+            // Testing 
+            function buttonClick(configNr) {
+                var metadata = $("input[name*='inMetadata']:checked").val();
+                var recognizeDates = $("#inRecognizeDates:checked").val();
+
+                var requestUri = {
+                    requestUri : config[configNr].url
+                };
+
+                if (recognizeDates==='on') {
+                    requestUri.recognizeDates = true;
+                }
+
+                var metaDatasuccess = function(metadata){
+                    datajs.V4.oData.read(requestUri, success, errorFunc, null, null, metadata);
+                };
+
+                if ( metadata === 'full') {
+                    requestUri.headers =  { Accept : 'application/json;odata.metadata=full'
};
+                    datajs.V4.oData.read(requestUri, success, errorFunc);
+                } else if ( metadata === 'minimal') {
+                    requestUri.headers =  { Accept : 'application/json;odata.metadata=minimal'
};
+                    getMetaData(metaDatasuccess);
+                } else {
+                    requestUri.headers =  { Accept : 'application/json;odata.metadata=none'
};
+                    datajs.V4.oData.read(requestUri, success, errorFunc);
+                }
+            }
 
             function show(data) {
                 $('#resultsArea').empty();
-                var code = $('<code data-type="json"></code>').text(JSON.stringify(data))
+                var code = $('<code data-type="json"></code>').text(JSON.stringify(data));
                 $('#resultsArea').append(code);
                 $('code[data-type]').prettify();
-                //$('#resultsArea').prettify();
             }
             function success(data) {
                 show(data);
@@ -94,191 +153,9 @@
                     data: null,
                 };
                 datajs.V4.oData.read(metadataRequest, metaDatasuccess, errorFunc,datajs.V4.oData.metadataHandler);
-            };
-
-            $('#startXML').on("click", function(){
-                //var requestUri = 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods';
-                var requestUri ='http://localhost:4003/sap/bc/ds/odata/v4/ESMixPrimCollComp?$format=xml';
-                datajs.V4.oData.read(requestUri, success, errorFunc);
-            });
-            $('#btnJSON_none').on("click", function(){
-                var requestUri = {
-                    requestUri : 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods',
-                    headers : { Accept : 'application/json;odata.metadata=none' }
-                };
-                datajs.V4.oData.read(requestUri, success, errorFunc);
-            });
-            $('#btnJSON_minimal').on("click", function(){
-                var requestUri = {
-                    requestUri : 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods',
-                    headers : { Accept : 'application/json;odata.metadata=minimal' }
-                };
-                datajs.V4.oData.read(requestUri, success, errorFunc);
-            });
-
-            $('#btnJSON_entry_minimal').on("click", function(){
-                var requestUri = {
-                    requestUri : 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods(0)',
-                    headers : { Accept : 'application/json;odata.metadata=minimal' }
-                };
-                datajs.V4.oData.read(requestUri, success, errorFunc);
-            });
-
-            $('#btnJSON_full').on("click", function(){
-                var requestUri = {
-                    requestUri : 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods',
-                    headers : { Accept : 'application/json;odata.metadata=full' }
-                };
-                datajs.V4.oData.read(requestUri, success, errorFunc);
-            });
-            $('#btnPOST_entry_food').on("click", function(){
-                var requestUri = {
-                    requestUri : 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods(0)/Providers',
-                    headers : { Accept : 'application/json;odata.metadata=full' }
-                };
-                datajs.V4.oData.read(requestUri, success, errorFunc);
-            });
-            $('#btnJSON_full_to_all').on("click", function(){
-                var requestUri = {
-                    requestUri : 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods',
-                    headers : { Accept : 'application/json;odata.metadata=full' },
-                    extendMetadataToLevel : 'all' ,
-                    recognizeDates : false
-                };
-                datajs.V4.oData.read(requestUri, success, errorFunc);
-            });
-
-            $('#btnGET_collection_full_simple').on("click", function(){
-                var metaDatasuccess = function(metadata){
-                    var requestUri = {
-                        requestUri : 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods(0)/AlternativeNames',
-                        headers : { Accept : 'application/json;odata.metadata=full' },
-                        recognizeDates : false
-                    };
-
-                    datajs.V4.oData.read(requestUri, success, errorFunc, null, null, metadata);
-                  
-                }
-                getMetaData(metaDatasuccess);
-            });
-
-            $('#btnGET_collection_full_complex').on("click", function(){
-                var metaDatasuccess = function(metadata){
-                    var requestUri = {
-                        requestUri : 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods(0)/Providers',
-                        headers : { Accept : 'application/json;odata.metadata=full' },
-                        recognizeDates : false
-                    };
-
-                    datajs.V4.oData.read(requestUri, success, errorFunc, null, null, metadata);
-                  
-                }
-                getMetaData(metaDatasuccess);
-            });
-
-            $('#btnGET_property_full_name').on("click", function(){
-                var metaDatasuccess = function(metadata){
-                    var requestUri = {
-                        requestUri : 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods(0)/Name',
-                        headers : { Accept : 'application/json;odata.metadata=full' },
-                        recognizeDates : false
-                    };
-
-                    datajs.V4.oData.read(requestUri, success, errorFunc, null, null, metadata);
-                  
-                }
-                getMetaData(metaDatasuccess);
-            });
-
-            $('#btnGET_property_full_complex').on("click", function(){
-                var metaDatasuccess = function(metadata){
-                    var requestUri = {
-                        requestUri : 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods(0)/Packaging',
-                        headers : { Accept : 'application/json;odata.metadata=full' },
-                        recognizeDates : false
-                    };
-
-                    datajs.V4.oData.read(requestUri, success, errorFunc, null, null, metadata);
-                  
-                }
-                getMetaData(metaDatasuccess);
-            });
-
-            $('#btnGET_property_minimal_name').on("click", function(){
-                var metaDatasuccess = function(metadata){
-                    var requestUri = {
-                        requestUri : 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods(0)/Name',
-                        headers : { Accept : 'application/json;odata.metadata=minimal' },
-                        recognizeDates : false
-                    };
-
-                    datajs.V4.oData.read(requestUri, success, errorFunc, null, null, metadata);
-                  
-                }
-                getMetaData(metaDatasuccess);
-            });
-
-            $('#btnGET_property_minimal_complex').on("click", function(){
-                var metaDatasuccess = function(metadata){
-                    var requestUri = {
-                        requestUri : 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods(0)/Packaging',
-                        headers : { Accept : 'application/json;odata.metadata=minimal' },
-                        recognizeDates : false
-                    };
-
-                    datajs.V4.oData.read(requestUri, success, errorFunc, null, null, metadata);
-                  
-                }
-                getMetaData(metaDatasuccess);
-            });
-
-
-
-            $('#btnGET_collection_minimal_simple').on("click", function(){
-                var metaDatasuccess = function(metadata){
-                    var requestUri = {
-                        requestUri : 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods(0)/AlternativeNames',
-                        headers : { Accept : 'application/json;odata.metadata=minimal' },
-                        recognizeDates : false
-                    };
-
-                    datajs.V4.oData.read(requestUri, success, errorFunc, null, null, metadata);
-                  
-                }
-                getMetaData(metaDatasuccess);
-            });
-
-            $('#btnGET_collection_minimal_complex').on("click", function(){
-                var metaDatasuccess = function(metadata){
-                    var requestUri = {
-                        requestUri : 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods(0)/Providers',
-                        headers : { Accept : 'application/json;odata.metadata=minimal' },
-                        recognizeDates : false
-                    };
+            }
 
-                    datajs.V4.oData.read(requestUri, success, errorFunc, null, null, metadata);
-                  
-                }
-                getMetaData(metaDatasuccess);
-            });
-
-            $('#btnJSON_full_to_all_date_conversion').on("click", function(){
-                var requestUri = {
-                    requestUri : 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods',
-                    headers : { Accept : 'application/json;odata.metadata=full' },
-                    extendMetadataToLevel : 'all' ,
-                    recognizeDates : true
-                };
-                datajs.V4.oData.read(requestUri, success, errorFunc);
-            });
-            $('#btnJSON_full_date_conversion').on("click", function(){
-                var requestUri = {
-                    requestUri : 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods',
-                    headers : { Accept : 'application/json;odata.metadata=full' },
-                    recognizeDates : true
-                };
-                datajs.V4.oData.read(requestUri, success, errorFunc);
-            });
+            /*******Special buttons***********/           
 
             $('#btnMetaData').on("click", function(){
                 var oHeaders = {
@@ -298,86 +175,6 @@
                 datajs.V4.oData.read(metadataRequest, success, errorFunc,datajs.V4.oData.metadataHandler);
             });
 
-
-
-            $('#btnJSON_minimal_to_all').on("click", function(){
-                var metaDatasuccess = function(metadata){
-                    var requestUri = {
-                        requestUri : 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods',
-                        headers : { Accept : 'application/json;odata.metadata=minimal' },
-                        recognizeDates : false
-                    };
-                    //extend to full
-                    datajs.V4.oData.read(requestUri, success, errorFunc, null, null, metadata);
-                    //keep minimal
-                    datajs.V4.oData.read(requestUri, success, errorFunc, null, null, metadata);
-                }
-                getMetaData(metaDatasuccess);
-            });
-
-            $('#btnJSON_minimal_to_full').on("click", function(){
-                var metaDatasuccess = function(metadata){
-                    var requestUri = {
-                        requestUri : 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods',
-                        headers : { Accept : 'application/json;odata.metadata=minimal' },
-                        extendMetadataToLevel : 'full' ,
-                        recognizeDates : false
-                    };
-                    datajs.V4.oData.read(requestUri, success, errorFunc, null, null, metadata);
-                }
-                getMetaData(metaDatasuccess);
-            });
-
-            $('#btnJSON_entry_minimal_to_all').on("click", function(){
-                var metaDatasuccess = function(metadata){
-                    var requestUri = {
-                        requestUri : 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods(0)',
-                        headers : { Accept : 'application/json;odata.metadata=minimal' },
-                        extendMetadataToLevel : 'all' ,
-                        recognizeDates : false
-                    };
-                    datajs.V4.oData.read(requestUri, success, errorFunc, null, null, metadata);
-                }
-                getMetaData(metaDatasuccess);
-            });
-
-            $('#btnJSON_entry_minimal_to_full').on("click", function(){
-                var metaDatasuccess = function(metadata){
-                    var requestUri = {
-                        requestUri : 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods(0)',
-                        headers : { Accept : 'application/json;odata.metadata=minimal' },
-                        extendMetadataToLevel : 'full' ,
-                        recognizeDates : false
-                    };
-                    datajs.V4.oData.read(requestUri, success, errorFunc, null, null, metadata);
-                }
-                getMetaData(metaDatasuccess);
-            });
-
-            $('#btnJSONwithMetaData').on("click", function(){
-                var oHeaders = {
-                    'Accept': 'text/html,application/xhtml+xml,application/xml,application/json;odata.metadata=full',
-                    "Odata-Version": "4.0",
-                    "OData-MaxVersion": "4.0",
-                    "Prefer": "odata.allow-entityreferences"
-                };
-                var metadataRequest =
-                {
-                    headers: oHeaders,
-                    //requestUri: "http://services.odata.org/OData/OData.svc/$metadata",
-                    requestUri: "http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/$metadata",
//"http://localhost:6630/PrimitiveKeys.svc/$metadata",
-                    data: null,
-                };
-
-                var metaDatasuccess = function(metadata){
-                    var requestUri = 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods';
-                    datajs.V4.oData.read(requestUri, success, errorFunc, null, null, metadata);
-                }
-
-
-                datajs.V4.oData.read(metadataRequest, metaDatasuccess, errorFunc,datajs.V4.oData.metadataHandler);
-            });
-
             $('#btnPOST_entry_food').on("click", function(){
                 var requestUri = {
                     requestUri : 'http://localhost:4002/tests/endpoints/FoodStoreDataServiceV4.svc/Foods',
@@ -410,6 +207,8 @@
                 datajs.V4.oData.read(requestUri, success, errorFunc);
             });
 
+
+
         </script>
     </body>
 </html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/46937a7a/datajs/src/lib/odata/json.js
----------------------------------------------------------------------
diff --git a/datajs/src/lib/odata/json.js b/datajs/src/lib/odata/json.js
index edb0b0b..aff4d76 100644
--- a/datajs/src/lib/odata/json.js
+++ b/datajs/src/lib/odata/json.js
@@ -50,7 +50,7 @@ var lookupDefaultEntityContainer = oDataUtils.lookupDefaultEntityContainer;
 var lookupProperty = oDataUtils.lookupProperty;
 var MAX_DATA_SERVICE_VERSION = oDataUtils.MAX_DATA_SERVICE_VERSION;
 var maxVersion = oDataUtils.maxVersion;
-var parseDateTime = oDataUtils.parseDateTime;
+var XXXparseDateTime = oDataUtils.XXXparseDateTime;
 
 var isPrimitiveEdmType = oDataUtils.isPrimitiveEdmType;
 var isGeographyEdmType = oDataUtils.isGeographyEdmType;
@@ -190,6 +190,32 @@ var addType = function(data, name, value ) {
     }
 };
 
+var addTypeNoEdm = function(data, name, value ) {
+    var fullName = name + '@odata.type';
+
+    if ( data[fullName] === undefined) {
+        if ( value.substring(0,4)==='Edm.') {
+            data[fullName] = value.substring(4);
+        } else {
+            data[fullName] = value;
+        }
+
+    }
+};
+
+var addTypeColNoEdm = function(data, name, value ) {
+    var fullName = name + '@odata.type';
+
+    if ( data[fullName] === undefined) {
+        if ( value.substring(0,4)==='Edm.') {
+            data[fullName] = 'Collection('+value.substring(4)+ ')';
+        } else {
+            data[fullName] = 'Collection('+value+ ')';
+        }
+    }
+};
+
+
 var readPayloadFull = function (data, model, recognizeDates) {
     /// <summary>Adds typeinformation for String, Boolean and numerical EDM-types.

     /// The type is determined from the odata-json-format-v4.0.doc specification
@@ -236,14 +262,8 @@ var readPayloadFull = function (data, model, recognizeDates) {
                         }
                         else {
                             if (recognizeDates) {
-                                if (type === '#DateTimeOffset') {
-                                    data[key] = oDataUtils.parseDateTimeOffset(data[key],
true);
-                                } else if (type === '#DateTime') {
-                                    data[key] = oDataUtils.parseDateTimeOffset(data[key],
true);
-                                }
+                                convertDatesNoEdm(data, key, type.substring(1));
                             }
-
-                            // TODO handle more types here 
                         }
                     }
                 }
@@ -616,13 +636,15 @@ var readPayloadMinimalProperty = function (data, model, collectionInfo,
baseURI,
     if (collectionInfo.type !== null) {
         readPayloadMinimalObject(data, collectionInfo, baseURI, model, recognizeDates);
     } else {
-        data['value@odata.type'] = '#'+collectionInfo.typeName;
+        addTypeNoEdm(data,'value', collectionInfo.typeName);
+        //data['value@odata.type'] = '#'+collectionInfo.typeName;
     }
     return data;
 };
 
 var readPayloadMinimalCollection = function (data, model, collectionInfo, baseURI, recognizeDates)
{
-    data['@odata.type'] = '#Collection('+collectionInfo.typeName + ')';
+    //data['@odata.type'] = '#Collection('+collectionInfo.typeName + ')';
+    addTypeColNoEdm(data,'', collectionInfo.typeName);
 
     if (collectionInfo.type !== null) {
         var entries = [];
@@ -730,6 +752,30 @@ var formatRowLiteral = function (value, type) {
     }
 };
 
+var convertDates = function (data, propertyName,type) {
+    if (type === 'Edm.Date') {
+        data[propertyName] = oDataUtils.parseDate(data[propertyName], true);
+    } else if (type === 'Edm.DateTimeOffset') {
+        data[propertyName] = oDataUtils.parseDateTimeOffset(data[propertyName], true);
+    } else if (type === 'Edm.Duration') {
+        data[propertyName] = oDataUtils.parseDuration(data[propertyName], true);
+    } else if (type === 'Edm.Time') {
+        data[propertyName] = oDataUtils.parseTime(data[propertyName], true);
+    }
+};
+
+var convertDatesNoEdm = function (data, propertyName,type) {
+    if (type === 'Date') {
+        data[propertyName] = oDataUtils.parseDate(data[propertyName], true);
+    } else if (type === 'DateTimeOffset') {
+        data[propertyName] = oDataUtils.parseDateTimeOffset(data[propertyName], true);
+    } else if (type === 'Duration') {
+        data[propertyName] = oDataUtils.parseDuration(data[propertyName], true);
+    } else if (type === 'Time') {
+        data[propertyName] = oDataUtils.parseTime(data[propertyName], true);
+    }
+};
+
 var checkProperties = function (data, objectInfoType, baseURI, model, recognizeDates) {
     for (var name in data) {
         if (name.indexOf("@") === -1) {
@@ -743,14 +789,25 @@ var checkProperties = function (data, objectInfoType, baseURI, model,
recognizeD
             }
             
             if ( isArray(propertyValue)) {
-                data[name+'@odata.type'] = '#' + property.type;
+                //data[name+'@odata.type'] = '#' + property.type;
+                if (isCollectionType(property.type)) {
+                    addTypeColNoEdm(data,name,property.type.substring(11,property.type.length-1));
+                } else {
+                    addTypeNoEdm(data,name,property.type);
+                }
+
+
                 for ( var i = 0; i < propertyValue.length; i++) {
                     readPayloadMinimalComplexObject(propertyValue[i], property, baseURI,
model, recognizeDates);
                 }
             } else if (isObject(propertyValue) && (propertyValue !== null)) {
                 readPayloadMinimalComplexObject(propertyValue, property, baseURI, model,
recognizeDates);
             } else {
-                data[name+'@odata.type'] = '#' + property.type;
+                //data[name+'@odata.type'] = '#' + property.type;
+                addTypeNoEdm(data,name,property.type);
+                if (recognizeDates) {
+                    convertDates(data, name, property.type);
+                }
             }
         }
     }
@@ -762,7 +819,9 @@ var readPayloadMinimalComplexObject = function (data, property, baseURI,
model,
         type =property.type.substring(11,property.type.length-1);
     }
 
-    data['@odata.type'] = '#'+type;
+    //data['@odata.type'] = '#'+type;
+    addType(data,'',property.type);
+
 
     var propertyType = lookupComplexType(type, model);
     if (propertyType === null)  {
@@ -773,7 +832,8 @@ var readPayloadMinimalComplexObject = function (data, property, baseURI,
model,
 };
 
 var readPayloadMinimalObject = function (data, objectInfo, baseURI, model, recognizeDates)
{
-    data['@odata.type'] = '#'+objectInfo.typeName;
+    //data['@odata.type'] = '#'+objectInfo.typeName;
+    addType(data,'',objectInfo.typeName);
 
     var keyType = objectInfo.type;
     while ((defined(keyType)) && ( keyType.key === undefined) && (keyType.baseType
!== undefined)) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/46937a7a/datajs/src/lib/odata/utils.js
----------------------------------------------------------------------
diff --git a/datajs/src/lib/odata/utils.js b/datajs/src/lib/odata/utils.js
index 868a3f9..df88e2e 100644
--- a/datajs/src/lib/odata/utils.js
+++ b/datajs/src/lib/odata/utils.js
@@ -889,12 +889,36 @@ var parseDateTimeMaybeOffset = function (value, withOffset, nullOnError)
{
     return result;
 };
 
-var parseDateTime = function (propertyValue, nullOnError) {
-    /// <summary>Parses a string into a DateTime value.</summary>
+var parseDate = function (propertyValue, nullOnError) {
+    /// <summary>Parses a string into a Date object.</summary>
     /// <param name="propertyValue" type="String">Value to parse.</param>
-    /// <returns type="Date">The parsed value.</returns>
+    /// <returns type="Date">The parsed with year, month, day set, time values are
set to 0</returns>
+    var parts = propertyValue.split('-');
+
+    if (parts.length != 3 && nullOnError) {
+        return null;
+    }
+    return new Date(
+        parseInt10(parts[0]),       // Year.
+        parseInt10(parts[1]) - 1,   // Month (zero-based for Date.UTC and setFullYear).
+        parseInt10(parts[2],
+        0,0,0,0)        // Date.
+        );
+
+};
+
+var parseTimeOfDayRE = /^(\d+):(\d+)(:(\d+)(.(\d+))?)?$/;
+
+var parseTimeOfDay = function (propertyValue, nullOnError) {
+    var parts = parseTimeOfDayRE.exec(propertyValue);
+
 
-    return parseDateTimeMaybeOffset(propertyValue, false, nullOnError);
+    return {
+        'h' :parseInt10(parts[1]),
+        'm' :parseInt10(parts[2]),
+        's' :parseInt10(parts[4]),
+        'ms' :parseInt10(parts[6]),
+     };
 };
 
 var parseDateTimeOffset = function (propertyValue, nullOnError) {
@@ -1145,10 +1169,13 @@ exports.maxVersion = maxVersion;
 exports.navigationPropertyKind = navigationPropertyKind;
 exports.normalizeHeaders = normalizeHeaders;
 exports.parseBool = parseBool;
-exports.parseDateTime = parseDateTime;
+
+
+exports.parseDate = parseDate;
 exports.parseDateTimeOffset = parseDateTimeOffset;
 exports.parseDuration = parseDuration;
-exports.parseTimezone = parseTimezone;
+exports.parseTimeOfDay = parseTimeOfDay;
+
 exports.parseInt10 = parseInt10;
 exports.prepareRequest = prepareRequest;
 exports.removeNamespace = removeNamespace;


Mime
View raw message