Version: 0.6.0
gxngwconn.h
1 /******************************************************************************
2  * Project: wxGIS (GIS Catalog)
3  * Purpose: Remote Connection classes.
4  * Author: Dmitry Baryshnikov (aka Bishop), polimax@mail.ru
5  ******************************************************************************
6 * Copyright (C) 2013,2014 NextGIS
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  ****************************************************************************/
21 #pragma once
22 
23 #include "wxgis/catalog/gxobject.h"
24 #include "wxgis/catalog/gxdataset.h"
25 #include "wxgis/core/json/jsonval.h"
26 #include "wxgis/catalog/contupdater.h"
27 
28 #ifdef wxGIS_USE_CURL
29 
30 #include "wxgis/net/curl.h"
31 
32 #include <wx/hashmap.h>
33 
41 class WXDLLIMPEXP_GIS_CLT wxGxNGWService :
42  public wxGxObjectContainer,
43  public IGxObjectEdit,
44  public IGxRemoteConnection,
45  public IGxObjectNoFilter
46 {
47  DECLARE_CLASS(wxGxNGWService)
48 public:
49  wxGxNGWService(wxGxObject *oParent, const wxString &soName = wxEmptyString, const CPLString &soPath = "");
50  virtual ~wxGxNGWService(void);
51  //wxGxObject
52  virtual wxString GetCategory(void) const { return wxString(_("NextGIS Web service")); };
53  virtual void Refresh(void);
54  //IGxRemoteConnection
55  virtual bool Connect(void);
56  virtual bool Disconnect(void);
57  virtual bool IsConnected(void);
58  //IGxObjectEdit
59  virtual bool Delete(void);
60  virtual bool CanDelete(void) { return true; };
61  virtual bool Rename(const wxString& NewName);
62  virtual bool CanRename(void) { return true; };
63  virtual bool Copy(const CPLString &szDestPath, ITrackCancel* const pTrackCancel);
64  virtual bool CanCopy(const CPLString &szDestPath) { return true; };
65  virtual bool Move(const CPLString &szDestPath, ITrackCancel* const pTrackCancel);
66  virtual bool CanMove(const CPLString &szDestPath) { return CanCopy(szDestPath) & CanDelete(); };
67  //wxGxObjectContainer
68  virtual bool AreChildrenViewable(void) const { return true; };
69  virtual bool HasChildren(void);
70  virtual bool CanCreate(long nDataType, long DataSubtype);
71  //wxGxNGWService
72  virtual wxGISCurl GetCurl();
73  virtual wxString GetLogin() const;
74  virtual wxString GetPassword() const;
75  virtual wxString GetURL() const;
76 protected:
77  virtual void LoadChildren(void);
78  virtual bool ConnectToNGW();
79  virtual void ReadConnectionFile();
80 protected:
81  wxString m_sLogin;
82  wxString m_sPassword;
83  wxString m_sURL;
84  bool m_bChildrenLoaded, m_bIsConnected, m_bIsAuthorized;
85  wxString m_sAuthCookie;
86 };
87 
95 enum wxGISEnumNGWResourcesType
96 {
97  enumNGWResourceTypeNone,
98  enumNGWResourceTypeResourceGroup,
99  enumNGWResourceTypePostgisLayer,
100  enumNGWResourceTypePostgisConnection,
101  enumNGWResourceTypeWMSServerService,
102  enumNGWResourceTypeBaseLayers,
103  enumNGWResourceTypeWebMap,
104  enumNGWResourceTypeWFSServerService,
105  enumNGWResourceTypeVectorLayer
106 };
107 
108 WX_DECLARE_HASH_MAP(int, wxJSONValue, wxIntegerHash, wxIntegerEqual, wxNGWResourceDataMap);
109 
110 
117 class WXDLLIMPEXP_GIS_CLT wxGxNGWResource : public wxGxRemoteId
118 {
119 public:
120  wxGxNGWResource(const wxJSONValue &Data);
121  virtual ~wxGxNGWResource(void);
122 protected:
123  virtual bool DeleteResource();
124  virtual bool RenameResource(const wxString &sNewName);
125  virtual int GetParentResourceId() const = 0;
126  virtual void ReportError(int nHTTPCode, const wxString& sBody);
127 protected:
128  wxGISEnumNGWResourcesType m_eResourceType;
129  bool m_bHasChildren;
130  wxString m_sDescription;
131  wxString m_sDisplayName;
132  //wxArrayString m_aInterfaces;
133  wxString m_sKeyName;
134  int m_nOwnerId;
135  wxArrayString m_aPermissions;
136  wxArrayString m_aScopes;
137  wxGxNGWService *m_pService;
138 };
139 
147 class WXDLLIMPEXP_GIS_CLT wxGxNGWResourceGroup :
149  public IGxObjectEdit,
150  public IGxObjectNoFilter,
151  public wxGxNGWResource
152 {
153  DECLARE_CLASS(wxGxNGWResourceGroup)
154 public:
155  wxGxNGWResourceGroup(wxGxNGWService *pService, const wxJSONValue &Data, wxGxObject *oParent, const wxString &soName = _("Resource Group"), const CPLString &soPath = "");
156  virtual ~wxGxNGWResourceGroup(void);
157  //wxGxObject
158  virtual bool Destroy();
159  virtual wxString GetCategory(void) const { return wxString(_("Resource Group")); };
160  //wxGxObjectContainer
161  virtual void Refresh(void);
162  //wxGxObjectContainer
163  virtual bool AreChildrenViewable(void) const { return true; };
164  virtual bool HasChildren(void);
165  virtual bool CanCreate(long nDataType, long DataSubtype);
166  //IGxObjectEdit
167  virtual bool Delete(void);
168  virtual bool CanDelete(void);
169  virtual bool Rename(const wxString& NewName);
170  virtual bool CanRename(void);
171  virtual bool Copy(const CPLString &szDestPath, ITrackCancel* const pTrackCancel);
172  virtual bool CanCopy(const CPLString &szDestPath);
173  virtual bool Move(const CPLString &szDestPath, ITrackCancel* const pTrackCancel);
174  virtual bool CanMove(const CPLString &szDestPath);
175  //wxGxNGWResourceGroup
176  virtual wxString CheckUniqName(const wxString &sName, const wxString& sAdd = wxT(" "), int nCounter = 0) const;
177  virtual bool CreateResource(const wxString &sName, wxGISEnumNGWResourcesType eType);
178 protected:
179  virtual void LoadChildren(void);
180  virtual wxGxObject* AddResource(const wxJSONValue &Data);
181  virtual bool CreateResourceGroup(const wxString &sName);
182  virtual wxGISEnumNGWResourcesType GetType(const wxJSONValue &Data) const;
183  virtual int GetParentResourceId() const;
184  //wxGxObjectContainerUpdater
185  virtual wxGxObjectMap GetRemoteObjects();
186  virtual void AddObject(int nRemoteId, const wxString &sName);
187 protected:
188  bool m_bHasGeoJSON;
189  wxNGWResourceDataMap m_moJSONData;
190 };
191 
192 
200 class WXDLLIMPEXP_GIS_CLT wxGxNGWRootResource :
201  public wxGxNGWResourceGroup
202 {
203  DECLARE_CLASS(wxGxNGWRootResource)
204 public:
205  wxGxNGWRootResource(wxGxNGWService *pService, wxGxObject *oParent, const wxString &soName = _("Resources"), const CPLString &soPath = "");
206  virtual ~wxGxNGWRootResource(void);
207  //wxGxObject
208  virtual wxString GetCategory(void) const { return wxString(_("NGW resources")); };
209  //IGxObjectEdit
210  virtual bool CanDelete(void);
211  virtual bool CanRename(void);
212  virtual bool CanCopy(const CPLString &szDestPath);
213  virtual bool CanMove(const CPLString &szDestPath);
214 };
215 
223 class WXDLLIMPEXP_GIS_CLT wxGxNGWLayer :
224  public wxGxNGWResource,
225  public wxGxFeatureDataset
226 {
227  DECLARE_CLASS(wxGxNGWLayer)
228 public:
229  wxGxNGWLayer(wxGxNGWService *pService, wxGISEnumNGWResourcesType eType, const wxJSONValue &Data, wxGxObject *oParent, const wxString &soName, const CPLString &soPath = "");
230  virtual ~wxGxNGWLayer(void);
231  //wxGxObject
232  virtual wxString GetCategory(void) const;
233 protected:
234  //create wxGISDataset without openning it
235  virtual wxGISDataset* const GetDatasetFast(void);
236  virtual int GetParentResourceId() const;
237 };
238 
239 #endif // wxGIS_USE_CURL
The JSON value class implementation.
Definition: jsonval.h:91
Definition: gxdataset.h:151
Definition: catalog.h:87
A TrackCancel interface class.
Definition: core.h:144
Definition: gxobject.h:78
Definition: dataset.h:33
Definition: contupdater.h:70
Definition: contupdater.h:36
Definition: catalog.h:51
Definition: curl.h:35
Definition: catalog.h:123
Definition: gxobject.h:37