ESPLogicalFile.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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/WsDfu",
  26. "hpcc/FileSpray",
  27. "hpcc/ESPRequest",
  28. "hpcc/ESPUtil",
  29. "hpcc/ESPResult"
  30. ], function (declare, arrayUtil, lang, Deferred, ObjectStore, QueryResults, Observable, Stateful,
  31. WsDfu, FileSpray, ESPRequest, ESPUtil, ESPResult) {
  32. var _logicalFiles = {};
  33. var Store = declare([ESPRequest.Store], {
  34. service: "WsDfu",
  35. action: "DFUQuery",
  36. responseQualifier: "DFUQueryResponse.DFULogicalFiles.DFULogicalFile",
  37. responseTotalQualifier: "DFUQueryResponse.NumFiles",
  38. idProperty: "Name",
  39. startProperty: "PageStartFrom",
  40. countProperty: "PageSize",
  41. _watched: [],
  42. create: function (id) {
  43. return new LogicalFile({
  44. Name: id
  45. });
  46. },
  47. update: function (id, item) {
  48. var storeItem = this.get(id);
  49. storeItem.updateData(item);
  50. if (!this._watched[id]) {
  51. var context = this;
  52. this._watched[id] = storeItem.watch("changedCount", function (name, oldValue, newValue) {
  53. if (oldValue !== newValue) {
  54. context.notify(storeItem, id);
  55. }
  56. });
  57. }
  58. }
  59. });
  60. var LogicalFile = declare([ESPUtil.Singleton], {
  61. _FileDetailSetter: function(FileDetail) {
  62. this.FileDetail = FileDetail;
  63. this.result = ESPResult.Get(FileDetail);
  64. },
  65. _DirSetter: function (Dir) {
  66. this.set("Directory", Dir);
  67. },
  68. constructor: function (args) {
  69. this.inherited(arguments);
  70. declare.safeMixin(this, args);
  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. updateData: function (data) {
  155. this.inherited(arguments);
  156. if (!this.result) {
  157. this.result = ESPResult.Get(data);
  158. }
  159. },
  160. fetchStructure: function (format, onFetchStructure) {
  161. var context = this;
  162. WsDfu.DFUDefFile({
  163. request: {
  164. Name: this.Name,
  165. Format: format
  166. },
  167. load: function (response) {
  168. onFetchStructure(response);
  169. }
  170. });
  171. },
  172. fetchDEF: function (onFetchXML) {
  173. this.fetchStructure("def", onFetchXML);
  174. },
  175. fetchXML: function (onFetchXML) {
  176. this.fetchStructure("xml", onFetchXML);
  177. }
  178. });
  179. return {
  180. Create: function (params) {
  181. retVal = new LogicalFile(params);
  182. retVal.create();
  183. return retVal;
  184. },
  185. Get: function (name) {
  186. var store = new Store();
  187. return store.get(name);
  188. },
  189. CreateLFQueryStore: function (options) {
  190. var store = new Store(options);
  191. return Observable(store);
  192. },
  193. CreateLFQueryObjectStore: function (options) {
  194. var objStore = new ObjectStore({
  195. objectStore: this.CreateLFQueryStore()
  196. });
  197. return objStore;
  198. }
  199. };
  200. });