root_service_mapper.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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.rootServiceMapper = App.QuickDataMapper.create({
  20. root_service_model: App.RootService,
  21. root_service_component_model: App.RootServiceComponents,
  22. configRootService: {
  23. id: 'service_name',
  24. service_name: 'service_name',
  25. components_key: 'components',
  26. components_type: 'array',
  27. components: {
  28. item: 'id'
  29. }
  30. },
  31. configRootServiceComponents: {
  32. id: 'component_name',
  33. component_name: 'component_name',
  34. component_version: 'component_version',
  35. server_clock: 'server_clock',
  36. service_name: 'service_name',
  37. properties: 'properties'
  38. },
  39. map: function (data) {
  40. var rootServiceModel = this.get('root_service_model');
  41. var rootServiceComponentModel = this.get('root_service_component_model');
  42. var rootService = {}, rootServiceComponents = [];
  43. rootService.id = rootService.service_name = data.RootService.service_name;
  44. data.components.forEach(function (item) {
  45. item.RootServiceComponents.id = item.RootServiceComponents.component_name;
  46. rootServiceComponents.push(this.parseIt(item.RootServiceComponents, this.configRootServiceComponents));
  47. }, this);
  48. rootService.components = rootServiceComponents;
  49. App.store.commit();
  50. App.store.loadMany(rootServiceComponentModel, rootServiceComponents);
  51. App.store.load(rootServiceModel, this.parseIt(rootService, this.configRootService));
  52. }
  53. });