yarn-node-app.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. /**
  19. * Licensed to the Apache Software Foundation (ASF) under one
  20. * or more contributor license agreements. See the NOTICE file
  21. * distributed with this work for additional information
  22. * regarding copyright ownership. The ASF licenses this file
  23. * to you under the Apache License, Version 2.0 (the
  24. * "License"); you may not use this file except in compliance
  25. * with the License. You may obtain a copy of the License at
  26. *
  27. * http://www.apache.org/licenses/LICENSE-2.0
  28. *
  29. * Unless required by applicable law or agreed to in writing, software
  30. * distributed under the License is distributed on an "AS IS" BASIS,
  31. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  32. * See the License for the specific language governing permissions and
  33. * limitations under the License.
  34. */
  35. import DS from 'ember-data';
  36. import Ember from 'ember';
  37. export default DS.JSONAPISerializer.extend({
  38. internalNormalizeSingleResponse(store, primaryModelClass, payload) {
  39. if (payload.app) {
  40. payload = payload.app;
  41. }
  42. var fixedPayload = {
  43. id: payload.id,
  44. type: primaryModelClass.modelName,
  45. attributes: {
  46. appId: payload.id,
  47. state: payload.state,
  48. user: payload.user,
  49. containers: payload.containerids
  50. }
  51. };
  52. return fixedPayload;
  53. },
  54. normalizeSingleResponse(store, primaryModelClass, payload, id,
  55. requestType) {
  56. // payload is of the form {"app":{}}
  57. var p = this.internalNormalizeSingleResponse(store,
  58. primaryModelClass, payload);
  59. return { data: p };
  60. },
  61. normalizeArrayResponse(store, primaryModelClass, payload, id,
  62. requestType) {
  63. // expected return response is of the form { data: [ {}, {} ] }
  64. var normalizedArrayResponse = {};
  65. // payload is of the form { "apps" : { "app": [ {},{},{} ] } }
  66. if (payload.apps) {
  67. normalizedArrayResponse.data = payload.apps.app.map(singleApp => {
  68. return this.internalNormalizeSingleResponse(store, primaryModelClass,
  69. singleApp);
  70. }, this);
  71. } else {
  72. // No container reported inside containers.
  73. // Response of the form { "apps": null }
  74. normalizedArrayResponse.data = Ember.makeArray({
  75. id: "dummy",
  76. type: primaryModelClass.modelName,
  77. attributes: {}});
  78. }
  79. return normalizedArrayResponse;
  80. }
  81. });