Skip to content

Commit 97dbbda

Browse files
author
guylabs
committed
#10 - Fix issue with raw type values being processed
1 parent c438714 commit 97dbbda

File tree

5 files changed

+91
-15
lines changed

5 files changed

+91
-15
lines changed

dist/angular-spring-data-rest.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ angular.module("spring-data-rest").provider("SpringDataRestAdapter", function ()
163163
var urlTemplates = "";
164164

165165
// split the resourceObject to extract the URL templates for the $resource method
166-
if(hasUrlTemplate(resourceObject)) {
166+
if (hasUrlTemplate(resourceObject)) {
167167
var extractedUrlTemplates = extractUrlTemplates(resourceObject);
168168
resourceObject = extractedUrlTemplates[0];
169169
urlTemplates = extractedUrlTemplates[1];
@@ -292,10 +292,14 @@ angular.module("spring-data-rest").provider("SpringDataRestAdapter", function ()
292292
var processedDataArray = [];
293293
var processedDataArrayPromise;
294294
angular.forEach(value, function (arrayValue, arrayKey) {
295-
processedDataArrayPromise = processDataFunction({data: arrayValue}, fetchLinkNames, recursive).then(function (processedResponseData) {
296-
processedDataArray[arrayKey] = processedResponseData;
297-
});
298-
promisesArray.push(processedDataArrayPromise);
295+
if (angular.isObject(arrayValue)) {
296+
processedDataArrayPromise = processDataFunction({data: arrayValue}, fetchLinkNames, recursive).then(function (processedResponseData) {
297+
processedDataArray[arrayKey] = processedResponseData;
298+
});
299+
promisesArray.push(processedDataArrayPromise);
300+
} else {
301+
processedDataArray[arrayKey] = arrayValue;
302+
}
299303
});
300304

301305
// after the last data array promise has been resolved add the result to the processed data
@@ -304,7 +308,7 @@ angular.module("spring-data-rest").provider("SpringDataRestAdapter", function ()
304308
processedData[config.embeddedNewKey][key] = processedDataArray;
305309
})
306310
}
307-
} else {
311+
} else if (angular.isObject(value)) {
308312
// single objects are processed directly
309313
promisesArray.push(processDataFunction({data: value}, fetchLinkNames, recursive).then(function (processedResponseData) {
310314
processedData[config.embeddedNewKey][key] = processedResponseData;
@@ -350,7 +354,7 @@ angular.module("spring-data-rest").provider("SpringDataRestAdapter", function ()
350354
* @returns {[]} the first element is the raw resource name and the second is the extracted URL templates
351355
*/
352356
function extractUrlTemplates(resourceName) {
353-
if(hasUrlTemplate(resourceName)) {
357+
if (hasUrlTemplate(resourceName)) {
354358
var indexOfSlash = resourceName.indexOf("/");
355359
return [resourceName.substr(0, indexOfSlash), resourceName.substr(indexOfSlash, resourceName.length)];
356360
}

dist/angular-spring-data-rest.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/angular-spring-data-rest-provider.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ angular.module("spring-data-rest").provider("SpringDataRestAdapter", function ()
151151
var urlTemplates = "";
152152

153153
// split the resourceObject to extract the URL templates for the $resource method
154-
if(hasUrlTemplate(resourceObject)) {
154+
if (hasUrlTemplate(resourceObject)) {
155155
var extractedUrlTemplates = extractUrlTemplates(resourceObject);
156156
resourceObject = extractedUrlTemplates[0];
157157
urlTemplates = extractedUrlTemplates[1];
@@ -280,10 +280,14 @@ angular.module("spring-data-rest").provider("SpringDataRestAdapter", function ()
280280
var processedDataArray = [];
281281
var processedDataArrayPromise;
282282
angular.forEach(value, function (arrayValue, arrayKey) {
283-
processedDataArrayPromise = processDataFunction({data: arrayValue}, fetchLinkNames, recursive).then(function (processedResponseData) {
284-
processedDataArray[arrayKey] = processedResponseData;
285-
});
286-
promisesArray.push(processedDataArrayPromise);
283+
if (angular.isObject(arrayValue)) {
284+
processedDataArrayPromise = processDataFunction({data: arrayValue}, fetchLinkNames, recursive).then(function (processedResponseData) {
285+
processedDataArray[arrayKey] = processedResponseData;
286+
});
287+
promisesArray.push(processedDataArrayPromise);
288+
} else {
289+
processedDataArray[arrayKey] = arrayValue;
290+
}
287291
});
288292

289293
// after the last data array promise has been resolved add the result to the processed data
@@ -292,7 +296,7 @@ angular.module("spring-data-rest").provider("SpringDataRestAdapter", function ()
292296
processedData[config.embeddedNewKey][key] = processedDataArray;
293297
})
294298
}
295-
} else {
299+
} else if (angular.isObject(value)) {
296300
// single objects are processed directly
297301
promisesArray.push(processDataFunction({data: value}, fetchLinkNames, recursive).then(function (processedResponseData) {
298302
processedData[config.embeddedNewKey][key] = processedResponseData;
@@ -338,7 +342,7 @@ angular.module("spring-data-rest").provider("SpringDataRestAdapter", function ()
338342
* @returns {[]} the first element is the raw resource name and the second is the extracted URL templates
339343
*/
340344
function extractUrlTemplates(resourceName) {
341-
if(hasUrlTemplate(resourceName)) {
345+
if (hasUrlTemplate(resourceName)) {
342346
var indexOfSlash = resourceName.indexOf("/");
343347
return [resourceName.substr(0, indexOfSlash), resourceName.substr(indexOfSlash, resourceName.length)];
344348
}

test/angular-spring-data-rest-provider.embedded.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,20 @@ describe("the response with the embedded values", function () {
145145
this.rootScope.$apply();
146146
});
147147

148+
it("must not process raw type values", function () {
149+
var embeddedNewKey = this.config.embeddedNewKey;
150+
151+
this.processedDataPromise = SpringDataRestAdapter.process(mockWithRawEmbeddedValueTypes());
152+
153+
this.processedDataPromise.then(function (processedData) {
154+
// expect that the raw id values are not modified
155+
expect(processedData[embeddedNewKey][0].id).toBe(1400);
156+
expect(processedData[embeddedNewKey][0][embeddedNewKey].id).toBe(15);
157+
expect(processedData[embeddedNewKey][1].id).toBe(52);
158+
expect(processedData[embeddedNewKey][1][embeddedNewKey].id).toBe(15);
159+
});
160+
161+
this.rootScope.$apply();
162+
});
163+
148164
});

test/angular-spring-data-rest.helper.spec.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,3 +314,55 @@ var mockWithoutHrefPropertyData = function () {
314314
);
315315
};
316316

317+
var mockWithRawEmbeddedValueTypes = function () {
318+
return angular.copy(
319+
{
320+
"_embedded": {
321+
"timeSeries": [{
322+
"id": 1400,
323+
"lastDate": "1991-01-06T23:00:00.000+0000",
324+
"data": [89.34576078, 90.86743282, 91.5561206, 91.52988487],
325+
"tsDataType": "CLOSE",
326+
"_embedded": {
327+
"asset": {
328+
"id": 15,
329+
"ticker": "BUHY:IND",
330+
"description": "Bloomberg USD High Yield Corporate Bond Index",
331+
"provider": "BLOOMBERG",
332+
"assetClass": "INDEX",
333+
"indexType": "BOND",
334+
"assetClassForType": "INDEX"
335+
}
336+
},
337+
"_links": {
338+
"self": {
339+
"href": "http://localhost:8080/alphaquant-web/restdata/timeSeries/1400"
340+
}
341+
}
342+
}, {
343+
"id": 52,
344+
"lastDate": "2015-05-31T22:00:00.000+0000",
345+
"data": [156.931961, 157.007523, 156.968109, 157.001785, 156.967865, 100.0],
346+
"tsDataType": "OPEN",
347+
"_embedded": {
348+
"asset": {
349+
"id": 15,
350+
"ticker": "BUHY:IND",
351+
"description": "Bloomberg USD High Yield Corporate Bond Index",
352+
"provider": "BLOOMBERG",
353+
"assetClass": "INDEX",
354+
"indexType": "BOND",
355+
"assetClassForType": "INDEX"
356+
}
357+
},
358+
"_links": {
359+
"self": {
360+
"href": "http://localhost:8080/alphaquant-web/restdata/timeSeries/52"
361+
}
362+
}
363+
}]
364+
}
365+
}
366+
);
367+
};
368+

0 commit comments

Comments
 (0)