-
Notifications
You must be signed in to change notification settings - Fork 24
/
feature_types.go
255 lines (231 loc) · 8.67 KB
/
feature_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
package geoserver
import (
"encoding/json"
"fmt"
"strconv"
)
//CRSType geoserver crs response
type CRSType struct {
Class string `json:"@class,omitempty"`
Value string `json:"$,omitempty"`
}
//UnmarshalJSON custom deserialization to handle published layers of group
func (u *CRSType) UnmarshalJSON(data []byte) error {
var raw interface{}
err := json.Unmarshal(data, &raw)
if err != nil {
return err
}
switch raw := raw.(type) {
case map[string]interface{}:
*u = CRSType{Class: raw["@class"].(string), Value: raw["$"].(string)}
case interface{}:
*u = CRSType{Class: "string", Value: string(data)}
}
return nil
}
//MarshalJSON custom crs serialization
func (u *CRSType) MarshalJSON() ([]byte, error) {
if IsEmpty(u) {
x := ""
return json.Marshal(&x)
} else if !IsEmpty(u.Class) && u.Class == "string" {
return json.Marshal(u.Value)
}
type crsType struct {
Class string `json:"@class,omitempty"`
Value string `json:"$,omitempty"`
}
return json.Marshal(&crsType{
Class: u.Class,
Value: u.Value,
})
}
// FeatureTypeService define all geoserver featuretype operations
type FeatureTypeService interface {
GetFeatureTypes(workspaceName string, datastoreName string) (featureTypes []*Resource, err error)
GetFeatureType(workspaceName string, datastoreName string, featureTypeName string) (featureType *FeatureType, err error)
DeleteFeatureType(workspaceName string, datastoreName string, featureTypeName string, recurse bool) (deleted bool, err error)
}
// Entry is geoserver Entry
type Entry struct {
Key string `json:"@key,omitempty"`
Value string `json:"$,omitempty"`
}
// BoundingBox is geoserver Bounding Box for FeatureType
type BoundingBox struct {
Minx float64 `json:"minx,omitempty"`
Maxx float64 `json:"maxx,omitempty"`
Miny float64 `json:"miny,omitempty"`
Maxy float64 `json:"maxy,omitempty"`
}
//Metadata is the geoserver Metadata
type Metadata struct {
Entry []*Entry `json:"entry,omitempty"`
}
//Keywords is the geoserver Keywords
type Keywords struct {
String []string `json:"string,omitempty"`
}
//ResponseSRS is the geoserver ResponseSRS
type ResponseSRS struct {
String []int `json:"string,omitempty"`
}
// NativeBoundingBox is geoserver NativeBoundingBox for FeatureType
type NativeBoundingBox struct {
BoundingBox
Crs *CRSType `json:"crs,omitempty"`
}
// LatLonBoundingBox is geoserver LatLonBoundingBox for FeatureType
type LatLonBoundingBox struct {
BoundingBox
Crs *CRSType `json:"crs,omitempty"`
}
// MetadataLink is geoserver metadata link
type MetadataLink struct {
Type string `json:"type,omitempty"`
MetadataType string `json:"metadataType,omitempty"`
Content string `json:"content,omitempty"`
}
//MetadataLinks is the geoserver metadata links
type MetadataLinks struct {
MetadataLink []*MetadataLink `json:"metadataLink,omitempty"`
}
//DataLinks is the geoserver FeatureType Datalinks
type DataLinks struct {
DataLink []*MetadataLink `json:"org.geoserver.catalog.impl.DataLinkInfoImpl,omitempty"`
}
//Attributes is the geoserver feature type attributes
type Attributes struct {
Attribute []*Attribute `json:"attribute,omitempty"`
}
// Attribute is geoserver FeatureType Attribute
type Attribute struct {
Name string `json:"name,omitempty"`
MinOccurs int16 `json:"minOccurs,omitempty"`
MaxOccurs int16 `json:"maxOccurs,omitempty"`
Nillable bool `json:"nillable,omitempty"`
Binding string `json:"binding,omitempty"`
Length int16 `json:"length,omitempty"`
}
// FeatureType is geoserver FeatureType
type FeatureType struct {
Name string `json:"name,omitempty"`
NativeName string `json:"nativeName,omitempty"`
Namespace *Resource `json:"namespace,omitempty"`
Title string `json:"title,omitempty"`
Abstract string `json:"abstract,omitempty"`
Keywords *Keywords `json:"keywords,omitempty"`
Metadatalinks *MetadataLinks `json:"metadatalinks,omitempty"`
DataLinks *DataLinks `json:"dataLinks,omitempty"`
NativeCRS *CRSType `json:"nativeCRS,omitempty"`
Srs string `json:"srs,omitempty"`
Enabled bool `json:"enabled,omitempty"`
NativeBoundingBox *NativeBoundingBox `json:"nativeBoundingBox,omitempty"`
LatLonBoundingBox *LatLonBoundingBox `json:"latLonBoundingBox,omitempty"`
ProjectionPolicy string `json:"projectionPolicy,omitempty"`
Metadata *Metadata `json:"metadata,omitempty"`
Store *Resource `json:"store,omitempty"`
CqlFilter string `json:"cqlFilter,omitempty"`
MaxFeatures int32 `json:"maxFeatures,omitempty"`
NumDecimals float32 `json:"numDecimals,omitempty"`
ResponseSRS *ResponseSRS `json:"responseSRS,omitempty"`
CircularArcPresent bool `json:"circularArcPresent,omitempty"`
OverridingServiceSRS bool `json:"overridingServiceSRS,omitempty"`
SkipNumberMatched bool `json:"skipNumberMatched,omitempty"`
LinearizationTolerance bool `json:"linearizationTolerance,omitempty"`
Attributes *Attributes `json:"attributes,omitempty"`
}
// FeatureTypes holds a list of geoserver styles
type FeatureTypes struct {
FeatureType []*Resource `json:"featureType,omitempty"`
}
//FeatureTypesResponseBody is the api body
type FeatureTypesResponseBody struct {
FeatureTypes *FeatureTypes `json:"featureTypes,omitempty"`
}
//FeatureTypesRequestBody is the api body
type FeatureTypesRequestBody struct {
FeatureType *FeatureType `json:"featureTypes,omitempty"`
}
// GetFeatureTypes return all featureTypes in workspace and datastore if error occurred err will be return and nil for featrueTypes
func (g *GeoServer) GetFeatureTypes(workspaceName string, datastoreName string) (featureTypes []*Resource, err error) {
if workspaceName != "" {
workspaceName = fmt.Sprintf("workspaces/%s/", workspaceName)
}
if datastoreName != "" {
datastoreName = fmt.Sprintf("datastores/%s/featuretypes", datastoreName)
}
targetURL := g.ParseURL("rest", workspaceName, datastoreName)
httpRequest := HTTPRequest{
Method: getMethod,
Accept: jsonType,
URL: targetURL,
Query: nil,
}
response, responseCode := g.DoRequest(httpRequest)
if responseCode != statusOk {
featureTypes = nil
err = g.GetError(responseCode, response)
return
}
featureTypesResponse := &FeatureTypesResponseBody{FeatureTypes: &FeatureTypes{FeatureType: make([]*Resource, 0, 0)}}
g.DeSerializeJSON(response, featureTypesResponse)
featureTypes = featureTypesResponse.FeatureTypes.FeatureType
return
}
// DeleteFeatureType Delete FeatureType from geoserver given that workspaceName, datastoreName, featureTypeName
// if featuretype deleted successfully will return true and nil for err
// if error occurred will return false and error for err
func (g *GeoServer) DeleteFeatureType(workspaceName string, datastoreName string, featureTypeName string, recurse bool) (deleted bool, err error) {
if workspaceName != "" {
workspaceName = fmt.Sprintf("workspaces/%s/", workspaceName)
}
if datastoreName != "" {
datastoreName = fmt.Sprintf("datastores/%s/", datastoreName)
}
targetURL := g.ParseURL("rest", workspaceName, datastoreName, "featuretypes", featureTypeName)
httpRequest := HTTPRequest{
Method: deleteMethod,
Accept: jsonType,
URL: targetURL,
Query: map[string]string{"recurse": strconv.FormatBool(recurse)},
}
response, responseCode := g.DoRequest(httpRequest)
if responseCode != statusOk {
deleted = false
err = g.GetError(responseCode, response)
return
}
deleted = true
return
}
// GetFeatureType it return geoserver FeatureType and nil err
// if success else nil for fetureType error for err
func (g *GeoServer) GetFeatureType(workspaceName string, datastoreName string, featureTypeName string) (featureType *FeatureType, err error) {
if workspaceName != "" {
workspaceName = fmt.Sprintf("workspaces/%s/", workspaceName)
}
if datastoreName != "" {
datastoreName = fmt.Sprintf("datastores/%s/featuretypes", datastoreName)
}
targetURL := g.ParseURL("rest", workspaceName, datastoreName, featureTypeName)
httpRequest := HTTPRequest{
Method: getMethod,
Accept: jsonType,
URL: targetURL,
Query: nil,
}
response, responseCode := g.DoRequest(httpRequest)
if responseCode != statusOk {
featureType = nil
err = g.GetError(responseCode, response)
return
}
var featureTypeResponse struct {
FeatureType *FeatureType `json:"featureType,omitempty"`
}
g.DeSerializeJSON(response, &featureTypeResponse)
featureType = featureTypeResponse.FeatureType
return
}