stack_mapper.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. var App = require('app');
  19. App.stackMapper = App.QuickDataMapper.create({
  20. modelStack: App.Stack,
  21. modelOS: App.OperatingSystem,
  22. modelRepo: App.Repository,
  23. configStack: {
  24. id: 'id',
  25. stack_name: 'stack_name',
  26. stack_version: 'stack_version',
  27. active: 'active',
  28. parent_stack_version: 'parent_stack_version',
  29. min_upgrade_version: 'min_upgrade_version',
  30. is_selected: 'is_selected',
  31. config_types: 'config_types',
  32. operating_systems_key: 'operating_systems',
  33. operating_systems_type: 'array',
  34. operating_systems: {
  35. item: 'id'
  36. }
  37. },
  38. configOS: {
  39. id: 'id',
  40. os_type: 'os_type',
  41. stack_name: 'stack_name',
  42. stack_version: 'stack_version',
  43. stack_id: 'stack_id',
  44. repositories_key: 'repositories',
  45. repositories_type: 'array',
  46. repositories: {
  47. item: 'id'
  48. }
  49. },
  50. configRepository: {
  51. id: 'id',
  52. base_url: 'base_url',
  53. default_base_url: 'default_base_url',
  54. latest_base_url: 'latest_base_url',
  55. mirrors_list: 'mirrors_list',
  56. os_type: 'os_type',
  57. repo_id: 'repo_id',
  58. repo_name: 'repo_name',
  59. stack_name: 'stack_name',
  60. stack_version: 'stack_version',
  61. operating_system_id: 'os_id'
  62. },
  63. map: function(json) {
  64. var modelStack = this.get('modelStack');
  65. var modelOS = this.get('modelOS');
  66. var modelRepo = this.get('modelRepo');
  67. var resultStack = [];
  68. var resultOS = [];
  69. var resultRepo = [];
  70. var stackVersions = json.items.filterProperty('Versions.active');
  71. stackVersions.sortProperty('Versions.stack_version').reverse().forEach(function(item) {
  72. var stack = item.Versions;
  73. var operatingSystemsArray = [];
  74. stack.id = stack.stack_name + "-" + stack.stack_version;
  75. item.operating_systems.forEach(function(ops) {
  76. var operatingSystems = ops.OperatingSystems;
  77. var repositoriesArray = [];
  78. ops.repositories.forEach(function(repo) {
  79. repo.Repositories.id = [repo.Repositories.stack_name, repo.Repositories.stack_version, repo.Repositories.os_type, repo.Repositories.repo_id].join('-');
  80. repo.Repositories.os_id = [repo.Repositories.stack_name, repo.Repositories.stack_version, repo.Repositories.os_type].join('-');
  81. resultRepo.push(this.parseIt(repo.Repositories, this.get('configRepository')));
  82. repositoriesArray.pushObject(repo.Repositories);
  83. }, this);
  84. operatingSystems.id = operatingSystems.stack_name + "-" + operatingSystems.stack_version + "-" + operatingSystems.os_type;
  85. operatingSystems.stack_id = operatingSystems.stack_name + "-" + operatingSystems.stack_version;
  86. operatingSystems.repositories = repositoriesArray;
  87. resultOS.push(this.parseIt(operatingSystems, this.get('configOS')));
  88. operatingSystemsArray.pushObject(operatingSystems);
  89. }, this);
  90. stack.operating_systems = operatingSystemsArray;
  91. resultStack.push(this.parseIt(stack, this.get('configStack')));
  92. }, this);
  93. App.store.commit();
  94. App.store.loadMany(modelRepo, resultRepo);
  95. App.store.loadMany(modelOS, resultOS);
  96. App.store.loadMany(modelStack, resultStack);
  97. }
  98. });