ESPQuery.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################## */
  16. define([
  17. "dojo/_base/declare",
  18. "dojo/_base/array",
  19. "dojo/_base/lang",
  20. "dojo/_base/Deferred",
  21. "dojo/data/ObjectStore",
  22. "dojo/store/util/QueryResults",
  23. "dojo/store/Observable",
  24. "dojo/Stateful",
  25. "hpcc/WsWorkunits",
  26. "hpcc/ESPRequest",
  27. "hpcc/ESPUtil",
  28. "hpcc/ESPResult"
  29. ], function (declare, arrayUtil, lang, Deferred, ObjectStore, QueryResults, Observable, Stateful,
  30. WsWorkunits, ESPRequest, ESPUtil, ESPResult) {
  31. var _logicalFiles = {};
  32. var Store = declare([ESPRequest.Store], {
  33. service: "WsWorkunits",
  34. action: "WUListQueries",
  35. responseQualifier: "WUListQueriesResponse.QuerysetQueries.QuerySetQuery",
  36. idProperty: "Id",
  37. startProperty: "PageStartFrom",
  38. countProperty: "NumberOfQueries",
  39. _watched: [],
  40. create: function (id) {
  41. return new Query({
  42. Id: id
  43. });
  44. },
  45. update: function (id, item) {
  46. var storeItem = this.get(id);
  47. storeItem.updateData(item);
  48. if (!this._watched[id]) {
  49. var context = this;
  50. this._watched[id] = storeItem.watch("changedCount", function (name, oldValue, newValue) {
  51. if (oldValue !== newValue) {
  52. context.notify(storeItem, id);
  53. }
  54. });
  55. }
  56. },
  57. preProcessRow: function (item, request, query, options) {
  58. var ErrorCount = 0;
  59. var Suspended = false;
  60. if (lang.exists("Clusters", item)) {
  61. arrayUtil.forEach(item.Clusters.ClusterQueryState, function(cqs, idx){
  62. if (lang.exists("Errors", cqs) && cqs.Errors != null && cqs.Errors != "" && cqs.State == "Suspended"){
  63. ErrorCount++
  64. Suspended = true;
  65. }
  66. });
  67. }
  68. lang.mixin(item, {
  69. ErrorCount:ErrorCount,
  70. Suspended: Suspended
  71. });
  72. }
  73. });
  74. var Query = declare([ESPUtil.Singleton], {
  75. constructor: function (args) {
  76. this.inherited(arguments);
  77. if (args) {
  78. declare.safeMixin(this, args);
  79. }
  80. },
  81. refresh: function (full) {
  82. return this.getDetails();
  83. },
  84. getDetails: function (args) {
  85. var context = this;
  86. return WsWorkunits.WUQueryDetails({
  87. request:{
  88. QueryId: this.Id,
  89. QuerySet: this.QuerySetId
  90. }
  91. }).then(function (response) {
  92. if (lang.exists("WUQueryDetailsResponse", response)) {
  93. context.updateData(response.WUQueryDetailsResponse);
  94. }
  95. });
  96. },
  97. doAction: function (action) {
  98. var context = this;
  99. return WsWorkunits.WUQuerysetQueryAction([{
  100. QuerySetId: this.QuerySetId,
  101. Id: this.Id,
  102. Name: this.Name
  103. }], action).then(function (responses) {
  104. context.refresh();
  105. });
  106. },
  107. setSuspended: function (suspended) {
  108. return this.doAction(suspended ? "Suspend" : "Unsuspend");
  109. },
  110. setActivated: function (activated) {
  111. return this.doAction(activated ? "Activate" : "Deactivate");
  112. },
  113. doDelete: function () {
  114. return this.doAction("Delete");
  115. }
  116. });
  117. return {
  118. Get: function (Id) {
  119. var store = new Store();
  120. return store.get(Id);
  121. },
  122. CreateQueryStore: function (options) {
  123. var store = new Store(options);
  124. return new Observable(store);
  125. }
  126. };
  127. });