WsWorkunits.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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/lang",
  19. "dojo/_base/array",
  20. "hpcc/ESPRequest"
  21. ], function (declare, lang, arrayUtil,
  22. ESPRequest) {
  23. return {
  24. WUCreate: function (params) {
  25. return ESPRequest.send("WsWorkunits", "WUCreate", params);
  26. },
  27. WUUpdate: function (params) {
  28. ESPRequest.flattenMap(params.request, "ApplicationValues")
  29. return ESPRequest.send("WsWorkunits", "WUUpdate", params);
  30. },
  31. WUSubmit: function (params) {
  32. return ESPRequest.send("WsWorkunits", "WUSubmit", params);
  33. },
  34. WUResubmit: function (params) {
  35. return ESPRequest.send("WsWorkunits", "WUResubmit", params);
  36. },
  37. WUPublishWorkunit: function (params) {
  38. return ESPRequest.send("WsWorkunits", "WUPublishWorkunit", params);
  39. },
  40. WUQuery: function (params) {
  41. return ESPRequest.send("WsWorkunits", "WUQuery", params);
  42. },
  43. WUInfo: function (params) {
  44. return ESPRequest.send("WsWorkunits", "WUInfo", params);
  45. },
  46. WUGetGraph: function (params) {
  47. return ESPRequest.send("WsWorkunits", "WUGetGraph", params);
  48. },
  49. WUResult: function (params) {
  50. return ESPRequest.send("WsWorkunits", "WUResult", params);
  51. },
  52. WUFile: function (params) {
  53. lang.mixin(params, {
  54. handleAs: "text"
  55. });
  56. return ESPRequest.send("WsWorkunits", "WUFile", params);
  57. },
  58. WUAction: function (wuids, actionType, callback) {
  59. var request = {
  60. Wuids: wuids,
  61. ActionType: actionType
  62. };
  63. ESPRequest.flattenArray(request, "Wuids", "Wuid");
  64. return ESPRequest.send("WsWorkunits", "WUAction", {
  65. request: request,
  66. load: function (response) {
  67. if (lang.exists("WUActionResponse.ActionResults.WUActionResult", response)) {
  68. arrayUtil.forEach(response.WUActionResponse.ActionResults.WUActionResult, function (item, index) {
  69. if (item.Result.indexOf("Failed:") === 0) {
  70. dojo.publish("hpcc/brToaster", {
  71. message: "<h4>" + item.Action + " " + item.Wuid + "</h4>" + "<p>" + item.Result + "</p>",
  72. type: "error",
  73. duration: -1
  74. });
  75. } else {
  76. dojo.publish("hpcc/brToaster", {
  77. message: "<h4>" + item.Action + " " + item.Wuid + "</h4>" + "<p>" + item.Result + "</p>",
  78. type: "message"
  79. });
  80. }
  81. });
  82. }
  83. if (callback && callback.load) {
  84. callback.load(response);
  85. }
  86. },
  87. error: function (err) {
  88. if (callback && callback.error) {
  89. callback.error(err);
  90. }
  91. }
  92. });
  93. },
  94. // Helpers ---
  95. isComplete: function (stateID, actionEx) {
  96. switch (stateID) {
  97. case 1: //WUStateCompiled
  98. if (actionEx && actionEx == "compile") {
  99. return true;
  100. }
  101. break;
  102. case 3: //WUStateCompleted:
  103. case 4: //WUStateFailed:
  104. case 5: //WUStateArchived:
  105. case 7: //WUStateAborted:
  106. return true;
  107. }
  108. return false;
  109. }
  110. };
  111. });