123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- /*##############################################################################
- # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- ############################################################################## */
- define([
- "dojo/_base/declare",
- "dojo/_base/array",
- "dojo/_base/lang",
- "dojo/_base/Deferred",
- "dojo/data/ObjectStore",
- "dojo/store/util/QueryResults",
- "dojo/store/Observable",
- "dojo/Stateful",
- "hpcc/WsDfu",
- "hpcc/FileSpray",
- "hpcc/ESPRequest",
- "hpcc/ESPUtil",
- "hpcc/ESPResult"
- ], function (declare, arrayUtil, lang, Deferred, ObjectStore, QueryResults, Observable, Stateful,
- WsDfu, FileSpray, ESPRequest, ESPUtil, ESPResult) {
- var _logicalFiles = {};
- var Store = declare([ESPRequest.Store], {
- service: "WsDfu",
- action: "DFUQuery",
- responseQualifier: "DFUQueryResponse.DFULogicalFiles.DFULogicalFile",
- responseTotalQualifier: "DFUQueryResponse.NumFiles",
- idProperty: "Name",
- startProperty: "PageStartFrom",
- countProperty: "PageSize",
- _watched: [],
- create: function (id) {
- return new LogicalFile({
- Name: id
- });
- },
- update: function (id, item) {
- var storeItem = this.get(id);
- storeItem.updateData(item);
- if (!this._watched[id]) {
- var context = this;
- this._watched[id] = storeItem.watch("changedCount", function (name, oldValue, newValue) {
- if (oldValue !== newValue) {
- context.notify(storeItem, id);
- }
- });
- }
- }
- });
- var LogicalFile = declare([ESPUtil.Singleton], {
- _FileDetailSetter: function(FileDetail) {
- this.FileDetail = FileDetail;
- this.result = ESPResult.Get(FileDetail);
- },
- _DirSetter: function (Dir) {
- this.set("Directory", Dir);
- },
- constructor: function (args) {
- this.inherited(arguments);
- declare.safeMixin(this, args);
- this.logicalFile = this;
- },
- save: function (description, args) {
- //WsDfu/DFUInfo?FileName=progguide%3A%3Aexampledata%3A%3Akeys%3A%3Apeople.lastname.firstname&UpdateDescription=true&FileDesc=%C2%A0123&Save+Description=Save+Description
- var context = this;
- WsDfu.DFUInfo({
- request: {
- FileName: this.Name,
- Cluster: this.Cluster,
- UpdateDescription: true,
- FileDesc: description
- },
- load: function (response) {
- if (lang.exists("DFUInfoResponse.FileDetail", response)) {
- context.updateData(response.DFUInfoResponse.FileDetail);
- if (args && args.onAfterSend) {
- args.onAfterSend(response.DFUInfoResponse.FileDetail);
- }
- }
- }
- });
- },
- doDelete: function (params) {
- var context = this;
- WsDfu.DFUArrayAction([this], "Delete", {
- load: function (response) {
- context.refresh();
- }
- });
- },
- despray: function (params) {
- var context = this;
- lang.mixin(params.request, {
- sourceLogicalName: this.Name
- });
- return FileSpray.Despray(params);
- },
- copy: function (params) {
- var context = this;
- lang.mixin(params.request, {
- sourceLogicalName: this.Name
- });
- return FileSpray.Copy(params);
- },
- rename: function (params) {
- var context = this;
- lang.mixin(params.request, {
- srcname: this.Name
- });
- return FileSpray.Rename(params).then(function (response) {
- context.set("Name", params.request.dstname); //TODO - need to monitor DFUWorkunit for success (After ESPDFUWorkunit has been updated to proper singleton).
- context.refresh();
- return response;
- });
- },
- removeSubfiles: function (subfiles, removeSuperfile) {
- var context = this;
- return WsDfu.SuperfileAction("remove", this.Name, subfiles, removeSuperfile).then(function (response) {
- context.refresh();
- return response;
- });
- },
- refresh: function (full) {
- return this.getInfo();
- },
- getInfo: function (args) {
- //WsDfu/DFUInfo?Name=progguide::exampledata::keys::people.state.city.zip.lastname.firstname.payload&Cluster=hthor__myeclagent HTTP/1.1
- var context = this;
- return WsDfu.DFUInfo({
- request:{
- Name: this.Name,
- Cluster: this.Cluster
- },
- load: function (response) {
- if (lang.exists("DFUInfoResponse.FileDetail", response)) {
- context.updateData(response.DFUInfoResponse.FileDetail);
- if (args && args.onAfterSend) {
- args.onAfterSend(response.DFUInfoResponse.FileDetail);
- }
- }
- }
- });
- },
- updateData: function (data) {
- this.inherited(arguments);
- if (!this.result) {
- this.result = ESPResult.Get(data);
- }
- },
- fetchStructure: function (format, onFetchStructure) {
- var context = this;
- WsDfu.DFUDefFile({
- request: {
- Name: this.Name,
- Format: format
- },
- load: function (response) {
- onFetchStructure(response);
- }
- });
- },
- fetchDEF: function (onFetchXML) {
- this.fetchStructure("def", onFetchXML);
- },
- fetchXML: function (onFetchXML) {
- this.fetchStructure("xml", onFetchXML);
- }
- });
- return {
- Create: function (params) {
- retVal = new LogicalFile(params);
- retVal.create();
- return retVal;
- },
- Get: function (name) {
- var store = new Store();
- return store.get(name);
- },
- CreateLFQueryStore: function (options) {
- var store = new Store(options);
- return Observable(store);
- },
- CreateLFQueryObjectStore: function (options) {
- var objStore = new ObjectStore({
- objectStore: this.CreateLFQueryStore()
- });
- return objStore;
- }
- };
- });
|