dataset_mapper.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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.dataSetMapper = App.QuickDataMapper.create({
  20. model: App.Dataset,
  21. Jobs_model: App.DataSetJob,
  22. config: {
  23. id: 'name',
  24. name: 'name',
  25. status: 'status',
  26. source_cluster_name: 'sourceClusterName',
  27. target_cluster_name: 'targetClusterName',
  28. source_dir: 'sourceDir',
  29. target_dir: 'targetDir',
  30. frequency: 'frequency',
  31. frequency_unit: 'frequencyUnit',
  32. schedule_start_date: 'scheduleStartDate',
  33. schedule_end_date: 'scheduleEndDate',
  34. dataset_jobs_key: 'instances',
  35. dataset_jobs_type: 'array',
  36. dataset_jobs: {
  37. item: 'id'
  38. }
  39. },
  40. jobs_config: {
  41. id: 'id',
  42. name: 'name',
  43. status : 'status',
  44. start_date: 'startTime',
  45. end_date: 'endTime',
  46. dataset_id: 'dataset'
  47. },
  48. map: function (json) {
  49. if (!this.get('model')) {
  50. return;
  51. }
  52. if (json && json.length > 0) {
  53. var datasetResults = [];
  54. var dataSetJobResults = [];
  55. json.forEach(function (item) {
  56. item.instances.forEach(function (job) {
  57. var newInstance = this.parseIt(job, this.get('jobs_config'));
  58. dataSetJobResults.push(newInstance);
  59. }, this);
  60. var newitem = this.parseIt(item, this.get('config'));
  61. datasetResults.push(newitem);
  62. }, this);
  63. App.store.loadMany(this.get('Jobs_model'), dataSetJobResults);
  64. App.store.loadMany(this.get('model'), datasetResults);
  65. }
  66. }
  67. });