ESPLogicalFile.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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/store/Observable",
  22. "dojo/Stateful",
  23. "hpcc/WsDfu",
  24. "hpcc/FileSpray",
  25. "hpcc/ESPRequest",
  26. "hpcc/ESPUtil",
  27. "hpcc/ESPResult"
  28. ], function (declare, arrayUtil, lang, Deferred, Observable, Stateful,
  29. WsDfu, FileSpray, ESPRequest, ESPUtil, ESPResult) {
  30. var _logicalFiles = {};
  31. var Store = declare([ESPRequest.Store], {
  32. service: "WsDfu",
  33. action: "DFUQuery",
  34. responseQualifier: "DFUQueryResponse.DFULogicalFiles.DFULogicalFile",
  35. responseTotalQualifier: "DFUQueryResponse.NumFiles",
  36. idProperty: "Name",
  37. startProperty: "PageStartFrom",
  38. countProperty: "PageSize",
  39. _watched: [],
  40. create: function (id) {
  41. return new LogicalFile({
  42. Name: 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. });
  58. var LogicalFile = declare([ESPUtil.Singleton], {
  59. _FileDetailSetter: function(FileDetail) {
  60. this.FileDetail = FileDetail;
  61. this.result = ESPResult.Get(FileDetail);
  62. },
  63. _DirSetter: function (Dir) {
  64. this.set("Directory", Dir);
  65. },
  66. constructor: function (args) {
  67. this.inherited(arguments);
  68. if (args) {
  69. declare.safeMixin(this, args);
  70. }
  71. this.logicalFile = this;
  72. },
  73. save: function (description, args) {
  74. //WsDfu/DFUInfo?FileName=progguide%3A%3Aexampledata%3A%3Akeys%3A%3Apeople.lastname.firstname&UpdateDescription=true&FileDesc=%C2%A0123&Save+Description=Save+Description
  75. var context = this;
  76. WsDfu.DFUInfo({
  77. request: {
  78. FileName: this.Name,
  79. Cluster: this.Cluster,
  80. UpdateDescription: true,
  81. FileDesc: description
  82. },
  83. load: function (response) {
  84. if (lang.exists("DFUInfoResponse.FileDetail", response)) {
  85. context.updateData(response.DFUInfoResponse.FileDetail);
  86. if (args && args.onAfterSend) {
  87. args.onAfterSend(response.DFUInfoResponse.FileDetail);
  88. }
  89. }
  90. }
  91. });
  92. },
  93. doDelete: function (params) {
  94. var context = this;
  95. WsDfu.DFUArrayAction([this], "Delete", {
  96. load: function (response) {
  97. context.refresh();
  98. }
  99. });
  100. },
  101. despray: function (params) {
  102. var context = this;
  103. lang.mixin(params.request, {
  104. sourceLogicalName: this.Name
  105. });
  106. return FileSpray.Despray(params);
  107. },
  108. copy: function (params) {
  109. var context = this;
  110. lang.mixin(params.request, {
  111. sourceLogicalName: this.Name
  112. });
  113. return FileSpray.Copy(params);
  114. },
  115. rename: function (params) {
  116. var context = this;
  117. lang.mixin(params.request, {
  118. srcname: this.Name
  119. });
  120. return FileSpray.Rename(params).then(function (response) {
  121. context.set("Name", params.request.dstname); //TODO - need to monitor DFUWorkunit for success (After ESPDFUWorkunit has been updated to proper singleton).
  122. context.refresh();
  123. return response;
  124. });
  125. },
  126. removeSubfiles: function (subfiles, removeSuperfile) {
  127. var context = this;
  128. return WsDfu.SuperfileAction("remove", this.Name, subfiles, removeSuperfile).then(function (response) {
  129. context.refresh();
  130. return response;
  131. });
  132. },
  133. refresh: function (full) {
  134. return this.getInfo();
  135. },
  136. getInfo: function (args) {
  137. //WsDfu/DFUInfo?Name=progguide::exampledata::keys::people.state.city.zip.lastname.firstname.payload&Cluster=hthor__myeclagent HTTP/1.1
  138. var context = this;
  139. return WsDfu.DFUInfo({
  140. request:{
  141. Name: this.Name,
  142. Cluster: this.Cluster
  143. },
  144. load: function (response) {
  145. if (lang.exists("DFUInfoResponse.FileDetail", response)) {
  146. context.updateData(response.DFUInfoResponse.FileDetail);
  147. if (args && args.onAfterSend) {
  148. args.onAfterSend(response.DFUInfoResponse.FileDetail);
  149. }
  150. }
  151. }
  152. });
  153. },
  154. getLeaf: function () {
  155. var nameParts = this.Name.split("::");
  156. return nameParts.length ? nameParts[nameParts.length - 1] : "";
  157. },
  158. updateData: function (data) {
  159. this.inherited(arguments);
  160. if (!this.result) {
  161. this.result = ESPResult.Get(data);
  162. }
  163. },
  164. fetchStructure: function (format, onFetchStructure) {
  165. var context = this;
  166. WsDfu.DFUDefFile({
  167. request: {
  168. Name: this.Name,
  169. Format: format
  170. }
  171. }).then(function(response) {
  172. onFetchStructure(response);
  173. });
  174. },
  175. fetchDEF: function (onFetchXML) {
  176. this.fetchStructure("def", onFetchXML);
  177. },
  178. fetchXML: function (onFetchXML) {
  179. this.fetchStructure("xml", onFetchXML);
  180. }
  181. });
  182. return {
  183. Create: function (params) {
  184. retVal = new LogicalFile(params);
  185. retVal.create();
  186. return retVal;
  187. },
  188. Get: function (name) {
  189. var store = new Store();
  190. return store.get(name);
  191. },
  192. CreateLFQueryStore: function (options) {
  193. var store = new Store(options);
  194. return Observable(store);
  195. }
  196. };
  197. });