@@ -5,6 +5,10 @@ import {SuperMap} from '../SuperMap';
55import { IPortalServiceBase } from './iPortalServiceBase' ;
66import { IPortalAddResourceParam } from './iPortalAddResourceParam' ;
77import { IPortalRegisterServiceParam } from "./iPortalRegisterServiceParam" ;
8+ import { IPortalAddDataParam } from "./iPortalAddDataParam" ;
9+ import { IPortalDataMetaInfoParam } from "./iPortalDataMetaInfoParam" ;
10+ import { IPortalDataStoreInfoParam } from "./iPortalDataStoreInfoParam" ;
11+ import { IPortalDataConnectionInfoParam } from "./iPortalDataConnectionInfoParam" ;
812/**
913 * @class SuperMap.iPortalUser
1014 * @classdesc iPortal 门户中用户信息的封装类。用于管理用户资源,包括可删除,添加资源。
@@ -117,6 +121,98 @@ export class IPortalUser extends IPortalServiceBase {
117121 resolve ( errMsg ) ;
118122 } )
119123 }
124+
125+ /**
126+ * @function SuperMap.iPortalUser.prototype.uploadDataRequest
127+ * @description 上传数据。
128+ * @param {number } id - 上传数据的资源id。
129+ * @param {Object } formData - 请求体为文本数据流。
130+ * @returns {Promise } 返回包含上传数据操作的 Promise 对象。
131+ */
132+ uploadDataRequest ( id , formData ) {
133+ var uploadDataUrl = this . iportalUrl + "/web/mycontent/datas/" + id + "/upload.json" ;
134+ return this . request ( "POST" , uploadDataUrl , formData ) ;
135+ }
136+
137+ /**
138+ * @function SuperMap.iPortalUser.prototype.addData
139+ * @description 上传/注册数据。
140+ * @param {SuperMap.iPortalAddDataParam } params - 上传/注册数据所需的参数。
141+ * @param {Object } [formData] - 请求体为文本数据流(上传数据时传入)。
142+ * @returns {Promise } 返回上传/注册数据的 Promise 对象。
143+ */
144+ addData ( params , formData ) {
145+ if ( ! ( params instanceof IPortalAddDataParam ) ) {
146+ this . getErrMsgPromise ( "params is not instanceof iPortalAddDataParam !" ) ;
147+ }
148+ var datasUrl = this . iportalUrl + "/web/mycontent/datas.json" ;
149+ var entity = {
150+ fileName :params . fileName ,
151+ tags :params . tags ,
152+ type :params . type
153+ } ;
154+ var type = params . type . toLowerCase ( ) ;
155+ var dataMetaInfo ;
156+ if ( type === "excel" || type === "csv" ) {
157+ if ( ! ( params . dataMetaInfo instanceof IPortalDataMetaInfoParam ) ) {
158+ this . getErrMsgPromise ( "params.dataMetaInfo is not instanceof iPortalDataMetaInfoParam !" ) ;
159+ }
160+ dataMetaInfo = {
161+ xField :params . dataMetaInfo . xField ,
162+ yField :params . dataMetaInfo . yField
163+ }
164+ if ( type === 'csv' ) {
165+ dataMetaInfo . fileEncoding = params . dataMetaInfo . fileEncoding
166+ }
167+ entity . coordType = "WGS84" ;
168+ entity . dataMetaInfo = dataMetaInfo ;
169+ } else if ( type === "hdfs" || type === "hbase" ) {
170+ if ( ! ( params . dataMetaInfo instanceof IPortalDataMetaInfoParam ) ) {
171+ this . getErrMsgPromise ( "params.dataMetaInfo is not instanceof iPortalDataMetaInfoParam !" ) ;
172+ }
173+ if ( ! ( params . dataMetaInfo . dataStoreInfo instanceof IPortalDataStoreInfoParam ) ) {
174+ this . getErrMsgPromise ( "params.dataMetaInfo.dataStoreInfo is not instanceof iPortalDataStoreInfoParam !" ) ;
175+ }
176+ var dataStoreInfo = {
177+ type :params . dataMetaInfo . dataStoreInfo . type
178+ }
179+ switch ( type ) {
180+ case "hdfs" :
181+ dataStoreInfo . url = params . dataMetaInfo . dataStoreInfo . url ;
182+ dataMetaInfo = {
183+ url : params . dataMetaInfo . url ,
184+ dataStoreInfo :dataStoreInfo
185+ }
186+ break ;
187+ case "hbase" :
188+ if ( ! ( params . dataMetaInfo . dataStoreInfo . connectionInfo instanceof IPortalDataConnectionInfoParam ) ) {
189+ this . getErrMsgPromise ( "params.dataMetaInfo.dataStoreInfo.connectionInfo is not instanceof iPortalDataConnectionInfoParam !" ) ;
190+ }
191+ dataStoreInfo . connectionInfo = {
192+ dataBase :params . dataMetaInfo . dataStoreInfo . connectionInfo . dataBase ,
193+ server :params . dataMetaInfo . dataStoreInfo . connectionInfo . server ,
194+ engineType :'HBASE'
195+ }
196+ dataStoreInfo . datastoreType = "SPATIAL" ; //该字段SPATIAL表示HBASE注册
197+ dataMetaInfo = {
198+ dataStoreInfo :dataStoreInfo
199+ }
200+ break ;
201+ }
202+ entity . dataMetaInfo = dataMetaInfo ;
203+ }
204+ return this . request ( "POST" , datasUrl , JSON . stringify ( entity ) ) . then ( res => {
205+ if ( type === "hdfs" || type === "hbase" ) {
206+ return res ;
207+ } else {
208+ if ( res . childID ) {
209+ return this . uploadDataRequest ( res . childID , formData ) ;
210+ } else {
211+ return res . customResult ;
212+ }
213+ }
214+ } )
215+ }
120216}
121217
122218SuperMap . iPortalUser = IPortalUser ;
0 commit comments