|
1 | 1 | package capabilitiesgenerator |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "encoding/xml" |
5 | 4 | "fmt" |
6 | 5 | "github.com/pdok/ogc-specifications/pkg/wms130" |
7 | 6 | "strconv" |
@@ -205,37 +204,137 @@ func mapServiceProvider(provider *smoothoperatorv1.ServiceProvider) (serviceProv |
205 | 204 | } |
206 | 205 |
|
207 | 206 | func MapWMSToCapabilitiesGeneratorInput(wms *pdoknlv3.WMS, ownerInfo *smoothoperatorv1.OwnerInfo) (*capabilitiesgenerator.Config, error) { |
208 | | - //featureTypeList, err := getFeatureTypeList(wms, ownerInfo) |
209 | | - //if err != nil { |
210 | | - // return nil, err |
211 | | - //} |
| 207 | + abstract := mapperutils.EscapeQuotes(wms.Spec.Service.Abstract) |
| 208 | + var fees *string = nil |
| 209 | + if wms.Spec.Service.Fees != nil { |
| 210 | + feesPtr := mapperutils.EscapeQuotes(*wms.Spec.Service.Fees) |
| 211 | + fees = &feesPtr |
| 212 | + } |
212 | 213 |
|
213 | 214 | config := capabilitiesgenerator.Config{ |
214 | 215 | Global: capabilitiesgenerator.Global{ |
215 | 216 | Namespace: mapperutils.GetNamespaceURI("prefix", ownerInfo), |
216 | 217 | Prefix: "prefix", |
217 | 218 | Onlineresourceurl: pdoknlv3.GetHost(), |
218 | | - Path: pdoknlv3.GetBaseURLPath(wms), |
| 219 | + Path: "/" + pdoknlv3.GetBaseURLPath(wms), |
219 | 220 | Version: *mapperutils.GetLabelValueByKey(wms.ObjectMeta.Labels, "service-version"), |
220 | 221 | }, |
221 | 222 | Services: capabilitiesgenerator.Services{ |
222 | 223 | WMS130Config: &capabilitiesgenerator.WMS130Config{ |
223 | 224 | Filename: wmsCapabilitiesFilename, |
224 | 225 | Wms130: wms130.GetCapabilitiesResponse{ |
225 | | - XMLName: xml.Name{}, |
226 | | - Namespaces: wms130.Namespaces{}, |
227 | | - WMSService: wms130.WMSService{}, |
228 | | - Capabilities: wms130.Capabilities{}, |
| 226 | + WMSService: wms130.WMSService{ |
| 227 | + Name: "WMS", |
| 228 | + Title: mapperutils.EscapeQuotes(wms.Spec.Service.Title), |
| 229 | + Abstract: &abstract, |
| 230 | + KeywordList: &wms130.Keywords{Keyword: wms.Spec.Service.Keywords}, |
| 231 | + OnlineResource: wms130.OnlineResource{Href: &wms.Spec.Service.URL}, |
| 232 | + ContactInformation: getContactInformation(ownerInfo), |
| 233 | + Fees: fees, |
| 234 | + AccessConstraints: &wms.Spec.Service.AccessConstraints, |
| 235 | + LayerLimit: nil, |
| 236 | + MaxWidth: nil, |
| 237 | + MaxHeight: nil, |
| 238 | + }, |
| 239 | + Capabilities: wms130.Capabilities{ |
| 240 | + WMSCapabilities: wms130.WMSCapabilities{ |
| 241 | + Request: wms130.Request{ |
| 242 | + GetCapabilities: wms130.RequestType{}, |
| 243 | + GetMap: wms130.RequestType{}, |
| 244 | + GetFeatureInfo: nil, |
| 245 | + }, |
| 246 | + Exception: wms130.ExceptionType{Format: []string{"XML", "BLANK"}}, |
| 247 | + ExtendedCapabilities: nil, |
| 248 | + Layer: nil, |
| 249 | + }, |
| 250 | + OptionalConstraints: wms130.OptionalConstraints{}, |
| 251 | + }, |
229 | 252 | }, |
230 | 253 | }, |
231 | 254 | }, |
232 | 255 | } |
233 | 256 |
|
234 | 257 | if wms.Spec.Service.Inspire != nil { |
235 | 258 | config.Global.AdditionalSchemaLocations = inspireSchemaLocations |
236 | | - //metadataURL, _ := replaceMustachTemplate(ownerInfo.Spec.MetadataUrls.CSW.HrefTemplate, wms.Spec.Service.Inspire.ServiceMetadataURL.CSW.MetadataIdentifier) |
| 259 | + metadataURL, _ := replaceMustachTemplate(ownerInfo.Spec.MetadataUrls.CSW.HrefTemplate, wms.Spec.Service.Inspire.ServiceMetadataURL.CSW.MetadataIdentifier) |
237 | 260 |
|
| 261 | + defaultLanguage := wms130.Language{Language: wms.Spec.Service.Inspire.Language} |
| 262 | + |
| 263 | + config.Services.WMS130Config.Wms130.Capabilities.ExtendedCapabilities = &wms130.ExtendedCapabilities{ |
| 264 | + MetadataURL: wms130.ExtendedMetadataURL{URL: metadataURL, MediaType: metadataMediaType}, |
| 265 | + SupportedLanguages: wms130.SupportedLanguages{ |
| 266 | + DefaultLanguage: defaultLanguage, |
| 267 | + SupportedLanguage: &[]wms130.Language{defaultLanguage}, |
| 268 | + }, |
| 269 | + ResponseLanguage: defaultLanguage, |
| 270 | + } |
238 | 271 | } |
239 | 272 |
|
240 | 273 | return &config, nil |
241 | 274 | } |
| 275 | + |
| 276 | +func getContactInformation(ownerInfo *smoothoperatorv1.OwnerInfo) *wms130.ContactInformation { |
| 277 | + result := wms130.ContactInformation{ |
| 278 | + ContactPersonPrimary: nil, |
| 279 | + ContactPosition: nil, |
| 280 | + ContactAddress: nil, |
| 281 | + ContactVoiceTelephone: nil, |
| 282 | + ContactFacsimileTelephone: nil, |
| 283 | + ContactElectronicMailAddress: nil, |
| 284 | + } |
| 285 | + |
| 286 | + providedContactInformation := ownerInfo.Spec.WMS.ContactInformation |
| 287 | + |
| 288 | + if providedContactInformation == nil { |
| 289 | + return &result |
| 290 | + } |
| 291 | + |
| 292 | + if providedContactInformation.ContactPersonPrimary != nil { |
| 293 | + contactPerson := "" |
| 294 | + if providedContactInformation.ContactPersonPrimary.ContactPerson != nil { |
| 295 | + contactPerson = *providedContactInformation.ContactPersonPrimary.ContactPerson |
| 296 | + } |
| 297 | + contactOrganisation := "" |
| 298 | + if providedContactInformation.ContactPersonPrimary.ContactOrganization != nil { |
| 299 | + contactOrganisation = *providedContactInformation.ContactPersonPrimary.ContactOrganization |
| 300 | + } |
| 301 | + |
| 302 | + contactPersonPrimary := wms130.ContactPersonPrimary{ |
| 303 | + ContactPerson: contactPerson, |
| 304 | + ContactOrganization: contactOrganisation, |
| 305 | + } |
| 306 | + result.ContactPersonPrimary = &contactPersonPrimary |
| 307 | + } |
| 308 | + |
| 309 | + result.ContactPosition = providedContactInformation.ContactPosition |
| 310 | + if providedContactInformation.ContactAddress != nil { |
| 311 | + contactAddressInput := providedContactInformation.ContactAddress |
| 312 | + contactAddress := wms130.ContactAddress{ |
| 313 | + AddressType: pointerValOrDefault(contactAddressInput.AddressType, ""), |
| 314 | + Address: pointerValOrDefault(contactAddressInput.Address, ""), |
| 315 | + City: pointerValOrDefault(contactAddressInput.City, ""), |
| 316 | + StateOrProvince: pointerValOrDefault(contactAddressInput.StateOrProvince, ""), |
| 317 | + PostalCode: pointerValOrDefault(contactAddressInput.PostCode, ""), |
| 318 | + Country: pointerValOrDefault(contactAddressInput.Country, ""), |
| 319 | + } |
| 320 | + result.ContactAddress = &contactAddress |
| 321 | + } |
| 322 | + |
| 323 | + result.ContactVoiceTelephone = providedContactInformation.ContactVoiceTelephone |
| 324 | + result.ContactFacsimileTelephone = providedContactInformation.ContactFacsimileTelephone |
| 325 | + result.ContactElectronicMailAddress = providedContactInformation.ContactElectronicMailAddress |
| 326 | + |
| 327 | + return &result |
| 328 | +} |
| 329 | + |
| 330 | +func pointerValOrDefault[T any](pointer *T, defaultValue T) T { |
| 331 | + if pointer != nil { |
| 332 | + return *pointer |
| 333 | + } else { |
| 334 | + return defaultValue |
| 335 | + } |
| 336 | +} |
| 337 | + |
| 338 | +func asPtr[T any](value T) *T { |
| 339 | + return &value |
| 340 | +} |
0 commit comments