FileSpray.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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/Deferred",
  20. "dojo/store/util/QueryResults",
  21. "dojo/store/JsonRest",
  22. "dojo/store/Memory",
  23. "dojo/store/Cache",
  24. "dojo/store/Observable",
  25. "dojox/xml/parser",
  26. "hpcc/ESPBase",
  27. "hpcc/ESPRequest"
  28. ], function (declare, lang, Deferred, QueryResults, JsonRest, Memory, Cache, Observable,
  29. parser,
  30. ESPBase, ESPRequest) {
  31. return {
  32. States: {
  33. 0: "unknown",
  34. 1: "scheduled",
  35. 2: "queued",
  36. 3: "started",
  37. 4: "aborted",
  38. 5: "failed",
  39. 6: "finished",
  40. 7: "monitoring",
  41. 8: "aborting"
  42. },
  43. CommandMessages: {
  44. 1: "Copy",
  45. 2: "Remove",
  46. 3: "Move",
  47. 4: "Rename",
  48. 5: "Replicate",
  49. 6: "Spray (Import)",
  50. 7: "Despray (Export)",
  51. 8: "Add",
  52. 9: "Transfer",
  53. 10: "Save Map",
  54. 11: "Add Group",
  55. 12: "Server",
  56. 13: "Monitor",
  57. 14: "Copy Merge",
  58. 15: "Super Copy"
  59. },
  60. FormatMessages: {
  61. 0: "fixed",
  62. 1: "csv",
  63. 2: "utf8",
  64. 3: "utf8n",
  65. 4: "utf16",
  66. 5: "utf16le",
  67. 6: "utf16be",
  68. 7: "utf32",
  69. 8: "utf32le",
  70. 9: "utf32be",
  71. 10: "variable",
  72. 11: "recfmvb",
  73. 12: "recfmv",
  74. 13: "variablebigendian"
  75. },
  76. GetDFUWorkunits: function (params) {
  77. return ESPRequest.send("FileSpray", "GetDFUWorkunits", params);
  78. },
  79. DFUWorkunitsAction: function (wuids, actionType, callback) {
  80. var request = {
  81. wuids: wuids,
  82. Type: actionType
  83. };
  84. ESPRequest.flattenArray(request, "wuids", "ID");
  85. return ESPRequest.send("FileSpray", "DFUWorkunitsAction", {
  86. request: request,
  87. load: function (response) {
  88. if (lang.exists("DFUWorkunitsActionResponse.ActionResults.WUActionResult", response)) {
  89. arrayUtil.forEach(response.WUActionResponse.ActionResults.WUActionResult, function (item, index) {
  90. if (item.Result.indexOf("Failed:") === 0) {
  91. dojo.publish("hpcc/brToaster", {
  92. message: "<h4>" + item.Action + " " + item.Wuid + "</h4>" + "<p>" + item.Result + "</p>",
  93. type: "error",
  94. duration: -1
  95. });
  96. } else {
  97. dojo.publish("hpcc/brToaster", {
  98. message: "<h4>" + item.Action + " " + item.Wuid + "</h4>" + "<p>" + item.Result + "</p>",
  99. type: "message"
  100. });
  101. }
  102. });
  103. }
  104. if (callback && callback.load) {
  105. callback.load(response);
  106. }
  107. },
  108. error: function (err) {
  109. if (callback && callback.error) {
  110. callback.error(err);
  111. }
  112. }
  113. });
  114. },
  115. Despray: function (params) {
  116. return ESPRequest.send("FileSpray", "Despray", params);
  117. },
  118. Copy: function (params) {
  119. return ESPRequest.send("FileSpray", "Copy", params);
  120. },
  121. Rename: function (params) {
  122. return ESPRequest.send("FileSpray", "Rename", params);
  123. },
  124. GetDFUWorkunit: function (params) {
  125. return ESPRequest.send("FileSpray", "GetDFUWorkunit", params);
  126. },
  127. UpdateDFUWorkunit: function (params) {
  128. return ESPRequest.send("FileSpray", "UpdateDFUWorkunit", params);
  129. },
  130. DFUWUFile: function (params) {
  131. lang.mixin(params, {
  132. handleAs: "text"
  133. });
  134. return ESPRequest.send("FileSpray", "DFUWUFile", params);
  135. },
  136. isComplete: function (state) {
  137. switch (state) {
  138. case 4:
  139. case 5:
  140. case 6:
  141. return true;
  142. }
  143. return false;
  144. }
  145. };
  146. });