|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +######################################################################### |
| 3 | +# |
| 4 | +# Copyright 2019, GeoSolutions Sas. |
| 5 | +# Jendrusk also was here |
| 6 | +# All rights reserved. |
| 7 | +# |
| 8 | +# This source code is licensed under the MIT license found in the |
| 9 | +# LICENSE.txt file in the root directory of this source tree. |
| 10 | +# |
| 11 | +######################################################################### |
| 12 | +try: |
| 13 | + from urllib.parse import urljoin |
| 14 | +except BaseException: |
| 15 | + from urlparse import urljoin |
| 16 | + |
| 17 | +from geoserver.support import ( |
| 18 | + ResourceInfo, StaticResourceInfo, |
| 19 | + xml_property, |
| 20 | + read_bool, read_float, read_int, read_string, |
| 21 | + write_bool, write_float, write_int, write_string) |
| 22 | + |
| 23 | + |
| 24 | +def write_subclass(sbc): |
| 25 | + def write(builder, sbc): |
| 26 | + sbc.serialize_all(builder) |
| 27 | + return write |
| 28 | + |
| 29 | + |
| 30 | +class Contact(StaticResourceInfo): |
| 31 | + resource_type = "contact" |
| 32 | + |
| 33 | + def __init__(self, dom): |
| 34 | + super(Contact, self).__init__() |
| 35 | + self.dom = dom |
| 36 | + |
| 37 | + addressCity = xml_property("addressCity", read_string) |
| 38 | + addressCountry = xml_property("addressCountry", read_string) |
| 39 | + addressType = xml_property("addressType", read_string) |
| 40 | + contactEmail = xml_property("contactEmail", read_string) |
| 41 | + contactOrganization = xml_property("contactOrganization", read_string) |
| 42 | + contactPerson = xml_property("contactPerson", read_string) |
| 43 | + contactPosition = xml_property("contactPosition", read_string) |
| 44 | + |
| 45 | + writers = { |
| 46 | + "addressCity": write_string("addressCity"), |
| 47 | + "addressCountry": write_string("addressCountry"), |
| 48 | + "addressType": write_string("addressType"), |
| 49 | + "contactEmail": write_string("contactEmail"), |
| 50 | + "contactOrganization": write_string("contactOrganization"), |
| 51 | + "contactPerson": write_string("contactPerson"), |
| 52 | + "contactPosition": write_string("contactPosition") |
| 53 | + } |
| 54 | + |
| 55 | + |
| 56 | +class Settings(StaticResourceInfo): |
| 57 | + resource_type = "settings" |
| 58 | + |
| 59 | + def __init__(self, dom): |
| 60 | + super(Settings, self).__init__() |
| 61 | + self.dom = dom |
| 62 | + |
| 63 | + id = xml_property("id", read_string) |
| 64 | + contact = xml_property("contact", Contact) |
| 65 | + charset = xml_property("charset", read_string) |
| 66 | + numDecimals = xml_property("numDecimals", read_int) |
| 67 | + onlineResource = xml_property("onlineResource", read_string) |
| 68 | + verbose = xml_property("verbose", read_bool) |
| 69 | + verboseExceptions = xml_property("verboseExceptions", read_bool) |
| 70 | + localWorkspaceIncludesPrefix = xml_property("localWorkspaceIncludesPrefix", read_bool) |
| 71 | + |
| 72 | + writers = { |
| 73 | + "id": write_string("id"), |
| 74 | + "contact": write_subclass("contact"), |
| 75 | + "charset": write_string("charset"), |
| 76 | + "numDecimals": write_int("numDecimals"), |
| 77 | + "onlineResource": write_string("onlineResource"), |
| 78 | + "verbose": write_bool("verbose"), |
| 79 | + "verboseExceptions": write_bool("verboseExceptions"), |
| 80 | + "localWorkspaceIncludesPrefix": write_bool("localWorkspaceIncludesPrefix"), |
| 81 | + } |
| 82 | + |
| 83 | + |
| 84 | +class Jai(StaticResourceInfo): |
| 85 | + |
| 86 | + def __init__(self, dom): |
| 87 | + super(Jai, self).__init__() |
| 88 | + self.dom = dom |
| 89 | + |
| 90 | + resource_type = "jai" |
| 91 | + |
| 92 | + allowInterpolation = xml_property("allowInterpolation", read_bool) |
| 93 | + recycling = xml_property("recycling", read_bool) |
| 94 | + tilePriority = xml_property("tilePriority", read_int) |
| 95 | + tileThreads = xml_property("tileThreads", read_int) |
| 96 | + memoryCapacity = xml_property("memoryCapacity", read_float) |
| 97 | + memoryThreshold = xml_property("memoryThreshold", read_float) |
| 98 | + imageIOCache = xml_property("imageIOCache", read_bool) |
| 99 | + pngAcceleration = xml_property("pngAcceleration", read_bool) |
| 100 | + jpegAcceleration = xml_property("jpegAcceleration", read_bool) |
| 101 | + allowNativeMosaic = xml_property("allowNativeMosaic", read_bool) |
| 102 | + allowNativeWarp = xml_property("allowNativeWarp", read_bool) |
| 103 | + |
| 104 | + writers = { |
| 105 | + "allowInterpolation": write_bool("allowInterpolation"), |
| 106 | + "recycling": write_bool("recycling"), |
| 107 | + "tilePriority": write_int("tilePriority"), |
| 108 | + "tileThreads": write_int("tileThreads"), |
| 109 | + "memoryCapacity": write_float("memoryCapacity"), |
| 110 | + "memoryThreshold": write_float("memoryThreshold"), |
| 111 | + "imageIOCache": write_bool("imageIOCache"), |
| 112 | + "pngAcceleration": write_bool("pngAcceleration"), |
| 113 | + "jpegAcceleration": write_bool("jpegAcceleration"), |
| 114 | + "allowNativeMosaic": write_bool("allowNativeMosaic"), |
| 115 | + "allowNativeWarp": write_bool("allowNativeWarp")} |
| 116 | + |
| 117 | + |
| 118 | +class CoverageAccess(StaticResourceInfo): |
| 119 | + |
| 120 | + def __init__(self, dom): |
| 121 | + super(CoverageAccess, self).__init__() |
| 122 | + self.dom = dom |
| 123 | + |
| 124 | + resource_type = "coverageAccess" |
| 125 | + |
| 126 | + maxPoolSize = xml_property("maxPoolSize", read_int) |
| 127 | + corePoolSize = xml_property("corePoolSize", read_int) |
| 128 | + keepAliveTime = xml_property("keepAliveTime", read_int) |
| 129 | + queueType = xml_property("queueType", read_string) |
| 130 | + imageIOCacheThreshold = xml_property("imageIOCacheThreshold", read_int) |
| 131 | + |
| 132 | + writers = { |
| 133 | + "maxPoolSize": write_int("maxPoolSize"), |
| 134 | + "corePoolSize": write_int("corePoolSize"), |
| 135 | + "keepAliveTime": write_int("keepAliveTime"), |
| 136 | + "queueType": write_string("queueType"), |
| 137 | + "imageIOCacheThreshold": write_int("imageIOCacheThreshold") |
| 138 | + } |
| 139 | + |
| 140 | + |
| 141 | +class GlobalSettings(ResourceInfo): |
| 142 | + resource_type = "global" |
| 143 | + save_method = "put" |
| 144 | + |
| 145 | + def __init__(self, catalog): |
| 146 | + super(GlobalSettings, self).__init__() |
| 147 | + self._catalog = catalog |
| 148 | + |
| 149 | + @property |
| 150 | + def catalog(self): |
| 151 | + return self._catalog |
| 152 | + |
| 153 | + @property |
| 154 | + def href(self): |
| 155 | + return urljoin( |
| 156 | + f"{self.catalog.service_url}/", |
| 157 | + "settings" |
| 158 | + ) |
| 159 | + |
| 160 | + settings = xml_property("settings", Settings) |
| 161 | + jai = xml_property("jai", Jai) |
| 162 | + coverageAccess = xml_property("coverageAccess", CoverageAccess) |
| 163 | + updateSequence = xml_property("updateSequence", lambda x: int(x.text)) |
| 164 | + featureTypeCacheSize = xml_property("featureTypeCacheSize", lambda x: int(x.text)) |
| 165 | + globalServices = xml_property("globalServices", lambda x: x.text.lower() == 'true') |
| 166 | + xmlPostRequestLogBufferSize = xml_property("xmlPostRequestLogBufferSize", lambda x: int(x.text)) |
| 167 | + |
| 168 | + writers = { |
| 169 | + 'settings': write_subclass("settings"), |
| 170 | + 'jai': write_subclass("jai"), |
| 171 | + 'coverageAccess': write_subclass("coverageAccess"), |
| 172 | + 'featureTypeCacheSize': write_int("featureTypeCacheSize"), |
| 173 | + 'globalServices': write_bool("globalServices"), |
| 174 | + 'xmlPostRequestLogBufferSize': write_int("xmlPostRequestLogBufferSize") |
| 175 | + } |
| 176 | + |
| 177 | + def __repr__(self): |
| 178 | + return f"settings @ {self.href}" |
0 commit comments