stack_config_properties_mapper.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with this
  4. * work for additional information regarding copyright ownership. The ASF
  5. * licenses this file to you under the Apache License, Version 2.0 (the
  6. * "License"); you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. var App = require('app');
  18. App.stackConfigPropertiesMapper = App.QuickDataMapper.create({
  19. model: App.StackConfigProperty,
  20. config: {
  21. id: 'id',
  22. name: 'StackConfigurations.property_name',
  23. display_name: 'StackConfigurations.property_display_name',
  24. file_name: 'StackConfigurations.type',
  25. description: 'StackConfigurations.property_description',
  26. value: 'StackConfigurations.property_value',
  27. recommended_value: 'StackConfigurations.property_value',
  28. type: 'StackConfigurations.property_type',
  29. service_name: 'StackConfigurations.service_name',
  30. stack_name: 'StackConfigurations.stack_name',
  31. stack_version: 'StackConfigurations.stack_version',
  32. property_depended_by: 'StackConfigurations.property_depended_by',
  33. property_depends_on: 'StackConfigurations.property_depends_on',
  34. value_attributes: 'StackConfigurations.property_value_attributes',
  35. is_final: 'default_is_final',
  36. recommended_is_final: 'default_is_final',
  37. supports_final: 'supports_final',
  38. widget: 'widget',
  39. /**** ui properties ***/
  40. display_type: 'display_type',
  41. category: 'category'
  42. },
  43. map: function (json) {
  44. console.time('stackConfigMapper execution time');
  45. if (json && json.items) {
  46. var configs = [];
  47. json.items.forEach(function(stackItem) {
  48. var configTypeInfo = Em.get(stackItem, 'StackServices.config_types');
  49. stackItem.configurations.forEach(function(config) {
  50. var configType = App.config.getConfigTagFromFileName(config.StackConfigurations.type);
  51. config.id = config.StackConfigurations.property_name + '_' + configType;
  52. config.recommended_is_final = config.StackConfigurations.final === "true";
  53. config.supports_final = !!configTypeInfo[configType] && configTypeInfo[configType].supports.final === "true";
  54. // Map from /dependencies to property_depended_by
  55. config.StackConfigurations.property_depended_by = [];
  56. if (config.dependencies && config.dependencies.length > 0) {
  57. config.dependencies.forEach(function(dep) {
  58. config.StackConfigurations.property_depended_by.push({
  59. type : dep.StackConfigurationDependency.dependency_type,
  60. name : dep.StackConfigurationDependency.dependency_name
  61. });
  62. });
  63. }
  64. /**
  65. * merging stack info with that is stored on UI
  66. * for now is not used; uncomment in will be needed
  67. * this.mergeWithUI(config);
  68. */
  69. this.mergeWithUI(config);
  70. configs.push(this.parseIt(config, this.get('config')));
  71. }, this);
  72. }, this);
  73. App.store.loadMany(this.get('model'), configs);
  74. App.StackService.find().filterProperty('id').forEach(function(service) {
  75. this.setDependentServices(service);
  76. }, this);
  77. }
  78. console.timeEnd('stackConfigMapper execution time');
  79. },
  80. /******************* METHODS TO MERGE STACK PROPERTIES WITH STORED ON UI (NOT USED FOR NOW)*********************************/
  81. /**
  82. * find UI config with current name and fileName
  83. * if there is such property - adds some info to config object
  84. * @param {Object} config
  85. * @method mergeWithUI
  86. */
  87. mergeWithUI: function(config) {
  88. var uiConfigProperty = this.getUIConfig(config.StackConfigurations.property_name, config.StackConfigurations.type);
  89. var displayType = App.permit(App.config.advancedConfigIdentityData(config.StackConfigurations), 'displayType').displayType || 'string';
  90. if (!config.StackConfigurations.property_display_name) {
  91. config.StackConfigurations.property_display_name = uiConfigProperty && uiConfigProperty.displayName ? uiConfigProperty.displayName : config.StackConfigurations.property_name;
  92. }
  93. config.category = uiConfigProperty ? uiConfigProperty.category : 'Advanced ' + App.config.getConfigTagFromFileName(config.StackConfigurations.type);
  94. config.display_type = uiConfigProperty ? uiConfigProperty.displayType || displayType : displayType;
  95. },
  96. /**
  97. * returns config with such name and fileName if there is such on UI
  98. * otherwise returns null
  99. * @param propertyName
  100. * @param siteName
  101. * @returns {Object|null}
  102. * @method getUIConfig
  103. */
  104. getUIConfig: function(propertyName, siteName) {
  105. return App.config.get('preDefinedSiteProperties').filterProperty('filename', siteName).findProperty('name', propertyName);
  106. },
  107. /**
  108. * runs <code>setDependentServicesAndFileNames<code>
  109. * for stack properties for current service
  110. * @method loadDependentConfigs
  111. */
  112. setDependentServices: function(service) {
  113. App.StackConfigProperty.find().filterProperty('serviceName', service.get('serviceName')).forEach(function(stackProperty) {
  114. if (stackProperty.get('propertyDependedBy.length')) {
  115. this._setDependentServices(stackProperty, 'propertyDependedBy', service);
  116. }
  117. }, this);
  118. },
  119. /**
  120. * defines service names for configs and set them to <code>dependentServiceNames<code>
  121. * @param {App.StackConfigProperty} stackProperty
  122. * @param {String} [key='propertyDependedBy'] - attribute to check dependent configs
  123. * @param service
  124. * @private
  125. */
  126. _setDependentServices: function(stackProperty, key, service) {
  127. key = key || 'propertyDependedBy';
  128. if (stackProperty.get(key + '.length') > 0) {
  129. stackProperty.get(key).forEach(function(dependent) {
  130. var tag = App.config.getConfigTagFromFileName(dependent.type);
  131. /** setting dependent serviceNames (without current serviceName) **/
  132. var dependentProperty = App.StackConfigProperty.find(dependent.name + "_" + tag);
  133. if (dependentProperty) {
  134. if (dependentProperty.get('serviceName') && dependentProperty.get('serviceName') != service.get('serviceName') && !service.get('dependentServiceNames').contains(dependentProperty.get('serviceName'))) {
  135. service.set('dependentServiceNames', service.get('dependentServiceNames').concat([dependentProperty.get('serviceName')]));
  136. }
  137. this._setDependentServices(dependentProperty, key, service);
  138. }
  139. }, this);
  140. }
  141. }
  142. });