|
| 1 | +package capabilitiesgenerator |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/xml" |
| 5 | + pdoknlv3 "github.com/pdok/mapserver-operator/api/v3" |
| 6 | + "github.com/pdok/mapserver-operator/internal/controller/mapperutils" |
| 7 | + "github.com/pdok/ogc-specifications/pkg/wfs200" |
| 8 | + "github.com/pdok/ogc-specifications/pkg/wsc110" |
| 9 | + smoothoperatorv1 "github.com/pdok/smooth-operator/api/v1" |
| 10 | +) |
| 11 | + |
| 12 | +const ( |
| 13 | + inspireSchemaLocations = "http://inspire.ec.europa.eu/schemas/inspire_dls/1.0 http://inspire.ec.europa.eu/schemas/inspire_dls/1.0/inspire_dls.xsd" |
| 14 | + capabilitiesFilename = "/var/www/config/capabilities_wfs_200.xml" |
| 15 | +) |
| 16 | + |
| 17 | +func MapWFSToCapabilitiesGeneratorInput(wfs *pdoknlv3.WFS, ownerInfo *smoothoperatorv1.OwnerInfo) (Config, error) { |
| 18 | + config := Config{ |
| 19 | + Global: Global{ |
| 20 | + Namespace: mapperutils.GetNamespaceURI(wfs.Spec.Service.Prefix, ownerInfo), |
| 21 | + Prefix: wfs.Spec.Service.Prefix, |
| 22 | + OnlineResourceurl: pdoknlv3.GetBaseURL(), |
| 23 | + Path: mapperutils.GetPath(wfs), |
| 24 | + Version: *mapperutils.GetLabelValueByKey(wfs.ObjectMeta.Labels, "service-version"), |
| 25 | + }, |
| 26 | + Services: Services{ |
| 27 | + WFS200Config: WFS200Config{ |
| 28 | + Filename: capabilitiesFilename, |
| 29 | + Wfs200: wfs200.GetCapabilitiesResponse{ |
| 30 | + |
| 31 | + ServiceProvider: wfs200.ServiceProvider{ |
| 32 | + ProviderSite: struct { |
| 33 | + Type string `xml:"xlink:type,attr" yaml:"type"` |
| 34 | + Href string `xml:"xlink:href,attr" yaml:"href"` |
| 35 | + }(struct { |
| 36 | + Type string |
| 37 | + Href string |
| 38 | + }{ |
| 39 | + Type: "simple", |
| 40 | + Href: pdoknlv3.GetBaseURL(), |
| 41 | + }), |
| 42 | + }, |
| 43 | + ServiceIdentification: wfs200.ServiceIdentification{ |
| 44 | + Title: mapperutils.EscapeQuotes(wfs.Spec.Service.Title), |
| 45 | + Abstract: mapperutils.EscapeQuotes(wfs.Spec.Service.Abstract), |
| 46 | + AccessConstraints: wfs.Spec.Service.AccessConstraints, |
| 47 | + Keywords: &wsc110.Keywords{ |
| 48 | + Keyword: wfs.Spec.Service.Keywords, |
| 49 | + }, |
| 50 | + }, |
| 51 | + |
| 52 | + Capabilities: wfs200.Capabilities{ |
| 53 | + FeatureTypeList: getFeatureTypeList(wfs), |
| 54 | + }, |
| 55 | + XMLName: xml.Name{}, |
| 56 | + Namespaces: wfs200.Namespaces{ // TODO |
| 57 | + XmlnsGML: "", |
| 58 | + XmlnsWFS: "", |
| 59 | + XmlnsOWS: "", |
| 60 | + XmlnsXlink: "", |
| 61 | + XmlnsXSI: "", |
| 62 | + XmlnsFes: "", |
| 63 | + XmlnsInspireCommon: "", |
| 64 | + XmlnsInspireDls: "", |
| 65 | + XmlnsPrefix: "", |
| 66 | + Version: "", |
| 67 | + SchemaLocation: "", |
| 68 | + }, |
| 69 | + }, |
| 70 | + }, |
| 71 | + }, |
| 72 | + } |
| 73 | + |
| 74 | + if wfs.Spec.Service.Inspire != nil { |
| 75 | + config.Global.AdditionalSchemaLocations = inspireSchemaLocations |
| 76 | + |
| 77 | + // Todo set extended capabilities |
| 78 | + config.Services.WFS200Config.Wfs200.Capabilities.OperationsMetadata = wfs200.OperationsMetadata{} |
| 79 | + } |
| 80 | + |
| 81 | + return config, nil |
| 82 | +} |
| 83 | + |
| 84 | +func getFeatureTypeList(wfs *pdoknlv3.WFS) (typeList wfs200.FeatureTypeList) { |
| 85 | + typeList.FeatureType = []wfs200.FeatureType{} |
| 86 | + |
| 87 | + for _, fType := range wfs.Spec.Service.FeatureTypes { |
| 88 | + featureType := wfs200.FeatureType{ |
| 89 | + Name: wfs.Spec.Service.Prefix + fType.Name, |
| 90 | + Title: mapperutils.EscapeQuotes(fType.Title), |
| 91 | + Abstract: mapperutils.EscapeQuotes(fType.Abstract), |
| 92 | + DefaultCRS: &wfs200.CRS{Namespace: "", Code: 1}, // Todo |
| 93 | + OtherCRS: &[]wfs200.CRS{ // Todo |
| 94 | + {Namespace: "", Code: 2}, |
| 95 | + }, |
| 96 | + } |
| 97 | + typeList.FeatureType = append(typeList.FeatureType, featureType) |
| 98 | + } |
| 99 | + return |
| 100 | +} |
0 commit comments