FileSpray.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. var GetDFUWorkunits = declare(null, {
  32. idProperty: "ID",
  33. constructor: function (options) {
  34. declare.safeMixin(this, options);
  35. },
  36. getIdentity: function (object) {
  37. return object[this.idProperty];
  38. },
  39. query: function (query, options) {
  40. var request = {};
  41. lang.mixin(request, options.query);
  42. if (options.start)
  43. request['PageStartFrom'] = options.start;
  44. if (options.count)
  45. request['PageSize'] = options.count;
  46. if (options.sort) {
  47. request['Sortby'] = options.sort[0].attribute;
  48. request['Descending'] = options.sort[0].descending;
  49. }
  50. var results = ESPRequest.send("FileSpray", "GetDFUWorkunits", {
  51. request: request
  52. });
  53. var deferredResults = new Deferred();
  54. deferredResults.total = results.then(function (response) {
  55. if (lang.exists("GetDFUWorkunitsResponse.NumWUs", response)) {
  56. return response.GetDFUWorkunitsResponse.NumWUs;
  57. }
  58. return 0;
  59. });
  60. Deferred.when(results, function (response) {
  61. var workunits = [];
  62. if (lang.exists("GetDFUWorkunitsResponse.results.DFUWorkunit", response)) {
  63. workunits = response.GetDFUWorkunitsResponse.results.DFUWorkunit;
  64. }
  65. deferredResults.resolve(workunits);
  66. });
  67. return QueryResults(deferredResults);
  68. }
  69. });
  70. return {
  71. GetDFUWorkunits: GetDFUWorkunits,
  72. Despray: function (params) {
  73. return ESPRequest.send("FileSpray", "Despray", params);
  74. },
  75. Copy: function (params) {
  76. return ESPRequest.send("FileSpray", "Copy", params);
  77. },
  78. Rename: function (params) {
  79. return ESPRequest.send("FileSpray", "Rename", params);
  80. },
  81. GetDFUWorkunit: function (params) {
  82. return ESPRequest.send("FileSpray", "GetDFUWorkunit", params);
  83. },
  84. DFUWUFile: function (params) {
  85. lang.mixin(params, {
  86. handleAs: "text"
  87. });
  88. return ESPRequest.send("FileSpray", "DFUWUFile", params);
  89. }
  90. };
  91. });