ESPLogicalFile.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. if (args) {
  71. declare.safeMixin(this, args);
  72. }
  73. this.logicalFile = this;
  74. },
  75. save: function (description, args) {
  76. //WsDfu/DFUInfo?FileName=progguide%3A%3Aexampledata%3A%3Akeys%3A%3Apeople.lastname.firstname&UpdateDescription=true&FileDesc=%C2%A0123&Save+Description=Save+Description
  77. var context = this;
  78. WsDfu.DFUInfo({
  79. request: {
  80. FileName: this.Name,
  81. Cluster: this.Cluster,
  82. UpdateDescription: true,
  83. FileDesc: description
  84. },
  85. load: function (response) {
  86. if (lang.exists("DFUInfoResponse.FileDetail", response)) {
  87. context.updateData(response.DFUInfoResponse.FileDetail);
  88. if (args && args.onAfterSend) {
  89. args.onAfterSend(response.DFUInfoResponse.FileDetail);
  90. }
  91. }
  92. }
  93. });
  94. },
  95. doDelete: function (params) {
  96. var context = this;
  97. WsDfu.DFUArrayAction([this], "Delete", {
  98. load: function (response) {
  99. context.refresh();
  100. }
  101. });
  102. },
  103. despray: function (params) {
  104. var context = this;
  105. lang.mixin(params.request, {
  106. sourceLogicalName: this.Name
  107. });
  108. return FileSpray.Despray(params);
  109. },
  110. copy: function (params) {
  111. var context = this;
  112. lang.mixin(params.request, {
  113. sourceLogicalName: this.Name
  114. });
  115. return FileSpray.Copy(params);
  116. },
  117. rename: function (params) {
  118. var context = this;
  119. lang.mixin(params.request, {
  120. srcname: this.Name
  121. });
  122. return FileSpray.Rename(params).then(function (response) {
  123. context.set("Name", params.request.dstname); //TODO - need to monitor DFUWorkunit for success (After ESPDFUWorkunit has been updated to proper singleton).
  124. context.refresh();
  125. return response;
  126. });
  127. },
  128. removeSubfiles: function (subfiles, removeSuperfile) {
  129. var context = this;
  130. return WsDfu.SuperfileAction("remove", this.Name, subfiles, removeSuperfile).then(function (response) {
  131. context.refresh();
  132. return response;
  133. });
  134. },
  135. refresh: function (full) {
  136. return this.getInfo();
  137. },
  138. getInfo: function (args) {
  139. //WsDfu/DFUInfo?Name=progguide::exampledata::keys::people.state.city.zip.lastname.firstname.payload&Cluster=hthor__myeclagent HTTP/1.1
  140. var context = this;
  141. return WsDfu.DFUInfo({
  142. request:{
  143. Name: this.Name,
  144. Cluster: this.Cluster
  145. },
  146. load: function (response) {
  147. if (lang.exists("DFUInfoResponse.FileDetail", response)) {
  148. context.updateData(response.DFUInfoResponse.FileDetail);
  149. if (args && args.onAfterSend) {
  150. args.onAfterSend(response.DFUInfoResponse.FileDetail);
  151. }
  152. }
  153. }
  154. });
  155. },
  156. updateData: function (data) {
  157. this.inherited(arguments);
  158. if (!this.result) {
  159. this.result = ESPResult.Get(data);
  160. }
  161. },
  162. fetchStructure: function (format, onFetchStructure) {
  163. var context = this;
  164. WsDfu.DFUDefFile({
  165. request: {
  166. Name: this.Name,
  167. Format: format
  168. }
  169. }).then(function(response) {
  170. onFetchStructure(response);
  171. });
  172. },
  173. fetchDEF: function (onFetchXML) {
  174. this.fetchStructure("def", onFetchXML);
  175. },
  176. fetchXML: function (onFetchXML) {
  177. this.fetchStructure("xml", onFetchXML);
  178. }
  179. });
  180. return {
  181. Create: function (params) {
  182. retVal = new LogicalFile(params);
  183. retVal.create();
  184. return retVal;
  185. },
  186. Get: function (name) {
  187. var store = new Store();
  188. return store.get(name);
  189. },
  190. CreateLFQueryStore: function (options) {
  191. var store = new Store(options);
  192. return Observable(store);
  193. },
  194. CreateLFQueryObjectStore: function (options) {
  195. var objStore = new ObjectStore({
  196. objectStore: this.CreateLFQueryStore()
  197. });
  198. return objStore;
  199. }
  200. };
  201. });