| 1 |
""" |
| 2 |
VOResource capability/interface elements. |
| 3 |
|
| 4 |
The basic mapping from our RD elements to VOResource elements is that |
| 5 |
each renderer on a service translates to a capability with one interface. |
| 6 |
Thus, in the module we mostly deal with publication objects. If you |
| 7 |
need the service object, use publication.parent. |
| 8 |
""" |
| 9 |
|
| 10 |
#c Copyright 2008-2025, the GAVO project <[email protected]> |
| 11 |
#c |
| 12 |
#c This program is free software, covered by the GNU GPL. See the |
| 13 |
#c COPYING file in the source distribution. |
| 14 |
|
| 15 |
import os |
| 16 |
import urllib.parse |
| 17 |
|
| 18 |
from gavo import base |
| 19 |
from gavo import svcs |
| 20 |
from gavo import utils |
| 21 |
from gavo.base import meta |
| 22 |
from gavo.base import osinter |
| 23 |
from gavo.protocols import dali |
| 24 |
from gavo.protocols import tap |
| 25 |
from gavo.registry import tableset |
| 26 |
from gavo.registry.model import ( |
| 27 |
VOR, VOG, VS, SIA, SCS, SLAP, SSAP, TR, DOC, DaFut, VOE) |
| 28 |
|
| 29 |
|
| 30 |
###################### Helpers (TODO: Move to tableset, I guess) |
| 31 |
|
| 32 |
|
| 33 |
def _getParamFromColumn(column, rootElement, typeFactory): |
| 34 |
"""helper for get[Table|Input]ParamFromColumn. |
| 35 |
""" |
| 36 |
return rootElement[ |
| 37 |
VS.name[column.name], |
| 38 |
VS.description[column.description], |
| 39 |
VS.unit[column.unit], |
| 40 |
VS.ucd[column.ucd], |
| 41 |
typeFactory(column.type)] |
| 42 |
|
| 43 |
|
| 44 |
def getInputParamFromColumn(column, rootElement=VS.param): |
| 45 |
"""returns a InputParam element for a rscdef.Column. |
| 46 |
""" |
| 47 |
return _getParamFromColumn(column, rootElement, |
| 48 |
tableset.simpleDataTypeFactory)( |
| 49 |
std=(column.std and "true") or "false") |
| 50 |
|
| 51 |
|
| 52 |
def getInputParams(publication, service): |
| 53 |
"""returns a sequence of vs:param elements for the input of service. |
| 54 |
""" |
| 55 |
inputParams = [] |
| 56 |
renderer = svcs.getRenderer(publication.render) |
| 57 |
if hasattr(service, "getInputKeysFor"): # no params on published tables |
| 58 |
for param in service.getInputKeysFor(renderer): |
| 59 |
# there's similar code in vodal.DALRenderer._getMetadataData; |
| 60 |
# If more mess like this turns up, we'll have to think about |
| 61 |
# a mechanism for per-renderer, pre-service processing, parameter |
| 62 |
# mangling. |
| 63 |
if param.type=="file" and renderer.parameterStyle=="dali": |
| 64 |
param = dali.getUploadKeyFor(param) |
| 65 |
inputParams.append(getInputParamFromColumn(param)) |
| 66 |
|
| 67 |
return inputParams |
| 68 |
|
| 69 |
|
| 70 |
####################### Interfaces |
| 71 |
|
| 72 |
class InterfaceMaker: |
| 73 |
"""An encapsulation of interface construction. |
| 74 |
|
| 75 |
Each interface maker corresponds to a renderer and thus a publication on a |
| 76 |
service. It knows enough about the characteristics of a renderer to create |
| 77 |
interface stan by just calling. |
| 78 |
|
| 79 |
This class is abstract. To build concrete interface makers, at |
| 80 |
least fill out the class variables. You will probably want |
| 81 |
to override the _makeInterface method for some renderers corresponding |
| 82 |
so specially defined interfaces; the default implementation corresponds |
| 83 |
to the VOResource definition. |
| 84 |
""" |
| 85 |
renderer = None |
| 86 |
interfaceClass = VOR.interface |
| 87 |
|
| 88 |
def _makeInterfaceForClass(self, publication, interfaceClass): |
| 89 |
accessURL = base.getMetaText(publication, "accessURL", |
| 90 |
macroPackage=publication.parent) |
| 91 |
|
| 92 |
parts = urllib.parse.urlparse(accessURL) |
| 93 |
map = svcs.getVanityMap().longToShort |
| 94 |
localpart = parts.path[1:] |
| 95 |
if localpart in map: |
| 96 |
# some DAL protocols want ? or & at the end of their accessURLs. |
| 97 |
# Make sure we keep them |
| 98 |
appendChar = '' |
| 99 |
if accessURL[-1] in "?&": |
| 100 |
appendChar = accessURL[-1] |
| 101 |
accessURL = urllib.parse.urlunsplit(parts[:2]+ |
| 102 |
(map[localpart],)+parts[3:5]) |
| 103 |
accessURL = accessURL+appendChar |
| 104 |
|
| 105 |
interface = interfaceClass[ |
| 106 |
VOR.accessURL(use=base.getMetaText(publication, "urlUse"))[ |
| 107 |
accessURL], |
| 108 |
VOR.securityMethod( |
| 109 |
standardId=base.getMetaText(publication, "securityId")), |
| 110 |
[VOR.mirrorURL[v.getContent()] |
| 111 |
for v in publication.iterMeta("mirrorURL") |
| 112 |
if v.getContent()!=accessURL], |
| 113 |
] |
| 114 |
|
| 115 |
try: |
| 116 |
if base.getConfig("ivoa", "registerAlternative"): |
| 117 |
interface[VOR.mirrorURL[osinter.switchProtocol(accessURL)]] |
| 118 |
except ValueError: |
| 119 |
# probably an external URL that we can't switch |
| 120 |
pass |
| 121 |
|
| 122 |
return interface |
| 123 |
|
| 124 |
def _makeInterface(self, publication): |
| 125 |
return self._makeInterfaceForClass(publication, self.interfaceClass) |
| 126 |
|
| 127 |
def __call__(self, publication): |
| 128 |
return self._makeInterface(publication) |
| 129 |
|
| 130 |
|
| 131 |
class StandardParamHTTP(VS.ParamHTTP): |
| 132 |
# Use this for when a standard protocol just wants a vs:ParamHTTP interface. |
| 133 |
_a_role = "std" |
| 134 |
|
| 135 |
|
| 136 |
class VOSIInterface(InterfaceMaker): |
| 137 |
interfaceClass = StandardParamHTTP |
| 138 |
|
| 139 |
|
| 140 |
class VOSIAvInterface(VOSIInterface): |
| 141 |
renderer = "availability" |
| 142 |
|
| 143 |
class VOSICapInterface(VOSIInterface): |
| 144 |
renderer = "capabilities" |
| 145 |
|
| 146 |
class VOSITMInterface(VOSIInterface): |
| 147 |
renderer = "tableMetadata" |
| 148 |
|
| 149 |
def _makeInterface(self, publication): |
| 150 |
return super()._makeInterface(publication)(version="1.1") |
| 151 |
|
| 152 |
|
| 153 |
class DALIInterface(InterfaceMaker): |
| 154 |
interfaceClass = DaFut.daliInterface |
| 155 |
|
| 156 |
def _makeInterface(self, publication): |
| 157 |
# TODO: figure out where I'll get the endpoints in the end; going |
| 158 |
# by publication's render attribute will make this extremely ugly |
| 159 |
# over time. |
| 160 |
res = InterfaceMaker._makeInterface(self, publication)(version="1.1") |
| 161 |
if publication.render!="dali": |
| 162 |
raise NotImplementedError("Don't know how to make DALIInterfaces" |
| 163 |
" for anything but TAP yet.") |
| 164 |
|
| 165 |
return res[ |
| 166 |
DaFut.endpoint[TR.name["sync"]], |
| 167 |
DaFut.endpoint[TR.name["async"], |
| 168 |
DaFut.meta( |
| 169 |
property="http://dc.g-vo.org/static/tap-plan")["dachs"]], |
| 170 |
DaFut.endpoint[TR.name["tables"]], |
| 171 |
DaFut.endpoint[TR.name["examples"]]] |
| 172 |
|
| 173 |
|
| 174 |
class InterfaceWithParams(InterfaceMaker): |
| 175 |
"""An InterfaceMaker on a publication sporting input parameters. |
| 176 |
|
| 177 |
This corresponds to a ParamHTTP interface. |
| 178 |
""" |
| 179 |
interfaceClass = VS.ParamHTTP |
| 180 |
|
| 181 |
def _makeInterface(self, publication): |
| 182 |
paramSrc = publication.parent |
| 183 |
if publication.service: |
| 184 |
paramSrc = publication.service |
| 185 |
|
| 186 |
return InterfaceMaker._makeInterface(self, publication)[ |
| 187 |
VS.queryType[base.getMetaText( |
| 188 |
publication, "requestMethod", propagate=False)], |
| 189 |
VS.resultType[base.getMetaText( |
| 190 |
publication, "resultType", propagate=False)], |
| 191 |
getInputParams(publication, paramSrc) |
| 192 |
] |
| 193 |
|
| 194 |
|
| 195 |
class SIAPInterface(InterfaceWithParams): |
| 196 |
renderer = "siap.xml" |
| 197 |
interfaceClass = SIA.interface |
| 198 |
|
| 199 |
class SIAP2Interface(InterfaceWithParams): |
| 200 |
renderer = "siap2.xml" |
| 201 |
interfaceClass = SIA.interface |
| 202 |
|
| 203 |
class SCSInterface(InterfaceWithParams): |
| 204 |
renderer = "scs.xml" |
| 205 |
interfaceClass = SCS.interface |
| 206 |
|
| 207 |
class SSAPInterface(InterfaceWithParams): |
| 208 |
renderer = "ssap.xml" |
| 209 |
interfaceClass = SSAP.interface |
| 210 |
|
| 211 |
class SLAPInterface(InterfaceWithParams): |
| 212 |
renderer = "slap.xml" |
| 213 |
interfaceClass = SLAP.interface |
| 214 |
|
| 215 |
class DatalinkInterface(InterfaceWithParams): |
| 216 |
renderer = "dlmeta" |
| 217 |
interfaceClass = StandardParamHTTP |
| 218 |
|
| 219 |
class SODASyncInterface(InterfaceMaker): |
| 220 |
# here, we must not inquire parameters, as the core can only |
| 221 |
# tell when it actually has an ID, which we don't have here. |
| 222 |
renderer = "dlget" |
| 223 |
interfaceClass = StandardParamHTTP |
| 224 |
|
| 225 |
class SODAAsyncInterface(SODASyncInterface): |
| 226 |
# same deal as with SODASyncInterface |
| 227 |
renderer = "dlasync" |
| 228 |
|
| 229 |
class EditionInterface(InterfaceMaker): |
| 230 |
# Late DocRegExt's pre-REC evolution, it was decided that it is wise |
| 231 |
# to have media types, too. That led to the introduction of doc:StaticFile. |
| 232 |
# We use a few heuristics to use that rather than the default |
| 233 |
# VOR.WebBrowser: there are a few well-known extensions, and you can |
| 234 |
# give an accessURL.resultType meta, in which case we will always |
| 235 |
# pick DOC.StaticFile. |
| 236 |
renderer = "edition" |
| 237 |
interfaceClass = VOR.WebBrowser |
| 238 |
|
| 239 |
_wellKnownExtensions = { |
| 240 |
".pdf": "application/pdf", |
| 241 |
".ipynb": "application/x-ipynb+json", |
| 242 |
} |
| 243 |
|
| 244 |
def _makeInterface(self, publication): |
| 245 |
# see if we should rather return a StaticFile interface |
| 246 |
mediaType = base.getMetaText( |
| 247 |
publication, |
| 248 |
"accessURL.resultType") |
| 249 |
if not mediaType: |
| 250 |
accessURL = base.getMetaText( |
| 251 |
publication, |
| 252 |
"accessURL", |
| 253 |
macroPackage=publication.parent) |
| 254 |
mediaType = self._wellKnownExtensions.get( |
| 255 |
os.path.splitext(accessURL.split("/")[-1])[1]) |
| 256 |
|
| 257 |
if mediaType: |
| 258 |
interfaceClass = DOC.StaticFile |
| 259 |
else: |
| 260 |
interfaceClass = self.interfaceClass |
| 261 |
|
| 262 |
res = InterfaceMaker._makeInterfaceForClass(self, |
| 263 |
publication, |
| 264 |
interfaceClass)(role="rendered") |
| 265 |
if mediaType: |
| 266 |
res[DOC.resultType[mediaType]] |
| 267 |
|
| 268 |
return res |
| 269 |
|
| 270 |
|
| 271 |
class VTPInterface(InterfaceMaker): |
| 272 |
# We don't have a VTP interface and probably never will. |
| 273 |
# We are having a stub renderer for these now. I'm not sure |
| 274 |
# what this would do in the end. |
| 275 |
renderer = "voevent" |
| 276 |
interfaceClass = VOE.vtpInterface |
| 277 |
|
| 278 |
|
| 279 |
class KafkaInterface(InterfaceMaker): |
| 280 |
# See VTPInterface for renderer consideration. |
| 281 |
renderer = "voevent" |
| 282 |
interfaceClass = VOE.kafkaInterface |
| 283 |
|
| 284 |
|
| 285 |
class TAPInterface(InterfaceMaker): |
| 286 |
# for TAP, result type is tricky, and we don't have good metadata |
| 287 |
# on the accepted input parameters (QUERY, etc). We should really |
| 288 |
# provide them when we have extensions... |
| 289 |
renderer = "dali" |
| 290 |
interfaceClass = TR.interface |
| 291 |
|
| 292 |
def _makeInterface(self, publication): |
| 293 |
return InterfaceMaker._makeInterface(self, publication)( |
| 294 |
version=tap.TAP_VERSION) |
| 295 |
|
| 296 |
|
| 297 |
class ExamplesInterface(InterfaceMaker): |
| 298 |
renderer = "examples" |
| 299 |
interfaceClass = VOR.WebBrowser |
| 300 |
|
| 301 |
|
| 302 |
class SOAPInterface(InterfaceMaker): |
| 303 |
renderer = "soap" |
| 304 |
interfaceClass = VOR.WebService |
| 305 |
|
| 306 |
def _makeInterface(self, publication): |
| 307 |
return InterfaceMaker._makeInterface(self, publication)[ |
| 308 |
VOR.wsdlURL[base.getMetaText(publication, "accessURL")+"?wsdl"], |
| 309 |
] |
| 310 |
|
| 311 |
|
| 312 |
class OAIHTTPInterface(InterfaceMaker): |
| 313 |
renderer = "pubreg.xml" |
| 314 |
interfaceClass = VOG.OAIHTTP |
| 315 |
|
| 316 |
def _makeInterface(self, publication): |
| 317 |
return InterfaceMaker._makeInterface(self, publication)(role="std") |
| 318 |
|
| 319 |
|
| 320 |
class WebBrowserInterface(InterfaceMaker): |
| 321 |
"""An InterfaceMaker on a publication to be consumed by a web browser. |
| 322 |
|
| 323 |
This is abstract since various renderers boil down to this. |
| 324 |
""" |
| 325 |
interfaceClass = VOR.WebBrowser |
| 326 |
|
| 327 |
|
| 328 |
class FormInterface(WebBrowserInterface): |
| 329 |
renderer = "form" |
| 330 |
|
| 331 |
class QPInterface(WebBrowserInterface): |
| 332 |
renderer = "qp" |
| 333 |
|
| 334 |
class DocformInterface(WebBrowserInterface): |
| 335 |
renderer = "docform" |
| 336 |
|
| 337 |
# Actually, statics, externals and customs could be anything, but if you |
| 338 |
# register it, it's better be something a web browser can handle. |
| 339 |
|
| 340 |
class FixedInterface(WebBrowserInterface): |
| 341 |
renderer = "fixed" |
| 342 |
|
| 343 |
class StaticInterface(WebBrowserInterface): |
| 344 |
renderer = "static" |
| 345 |
|
| 346 |
class CustomInterface(WebBrowserInterface): |
| 347 |
renderer = "custom" |
| 348 |
|
| 349 |
class VolatileInterface(WebBrowserInterface): |
| 350 |
renderer = "volatile" |
| 351 |
|
| 352 |
class ExternalInterface(WebBrowserInterface): |
| 353 |
renderer = "external" |
| 354 |
|
| 355 |
class GetProductInterface(WebBrowserInterface): |
| 356 |
renderer = "get" |
| 357 |
|
| 358 |
|
| 359 |
_getInterfaceMaker = utils.buildClassResolver(InterfaceMaker, |
| 360 |
list(globals().values()), instances=True, |
| 361 |
key=lambda obj: obj.renderer, |
| 362 |
default=InterfaceWithParams()) |
| 363 |
|
| 364 |
|
| 365 |
####################### Capabilities |
| 366 |
|
| 367 |
|
| 368 |
class CapabilityMaker(object): |
| 369 |
"""An encapsulation of capability construction. |
| 370 |
|
| 371 |
Each capability (currently) corresponds to a renderer. |
| 372 |
|
| 373 |
You will want to override (some of) the class variables at the top, plus the |
| 374 |
_makeCapability method (that you'll probably still want to upcall for the |
| 375 |
basic functionality). |
| 376 |
|
| 377 |
In particular, you will typically want to override capabilityClass |
| 378 |
with a stanxml element spitting out the right standardIds. |
| 379 |
|
| 380 |
Additionally, if the capability should also appear in data collections |
| 381 |
served by a service with the capability, also define auxiliaryId (that's |
| 382 |
an IVOID like ivo://ivoa.net/std/TAP#aux). These are used in |
| 383 |
getCapabilityElement. |
| 384 |
|
| 385 |
CapabilityMakers are used by calling them. |
| 386 |
""" |
| 387 |
renderer = None |
| 388 |
capabilityClass = VOR.capability |
| 389 |
auxiliaryId = None |
| 390 |
|
| 391 |
def _getInterfaceElement(self, publication): |
| 392 |
"""returns the appropriate interface definition(s) for service and |
| 393 |
renderer. |
| 394 |
""" |
| 395 |
if publication.auxiliary and publication.render=="dali": |
| 396 |
# for now, we want to make ParamHTTP auxiliary interfaces |
| 397 |
# for TAP, not the new-fangled DALI ones. |
| 398 |
interfaceMaker = TAPInterface() |
| 399 |
else: |
| 400 |
interfaceMaker = _getInterfaceMaker(publication.render) |
| 401 |
return interfaceMaker(publication) |
| 402 |
|
| 403 |
def _makeCapability(self, publication): |
| 404 |
return self.capabilityClass[ |
| 405 |
VOR.description[base.getMetaText(publication, "description", |
| 406 |
propagate=False, macroPackage=publication.parent)], |
| 407 |
self._getInterfaceElement(publication)] |
| 408 |
|
| 409 |
def __call__(self, publication): |
| 410 |
return self._makeCapability(publication) |
| 411 |
|
| 412 |
|
| 413 |
class PlainCapabilityMaker(CapabilityMaker): |
| 414 |
"""A capability maker for generic VR.capabilities. |
| 415 |
|
| 416 |
These essentially just set standardId, in addition to what |
| 417 |
the plain capabilities do. |
| 418 |
""" |
| 419 |
standardId = None |
| 420 |
|
| 421 |
def _makeCapability(self, publication): |
| 422 |
return CapabilityMaker._makeCapability(self, publication)( |
| 423 |
standardID=self.standardId) |
| 424 |
|
| 425 |
|
| 426 |
class APICapabilityMaker(CapabilityMaker): |
| 427 |
renderer = "api" |
| 428 |
|
| 429 |
|
| 430 |
class SIACapabilityMaker(CapabilityMaker): |
| 431 |
renderer = "siap.xml" |
| 432 |
capabilityClass = SIA.capability |
| 433 |
auxiliaryId = "ivo://ivoa.net/std/SIA#aux" |
| 434 |
|
| 435 |
def _makeCapability(self, publication): |
| 436 |
service = publication.parent |
| 437 |
return CapabilityMaker._makeCapability(self, publication)[ |
| 438 |
SIA.imageServiceType[service.getMeta("sia.type", raiseOnFail=True)], |
| 439 |
SIA.maxQueryRegionSize[ |
| 440 |
SIA.long[service.getMeta("sia.maxQueryRegionSize.long", default=None)], |
| 441 |
SIA.lat[service.getMeta("sia.maxQueryRegionSize.lat", default=None)], |
| 442 |
], |
| 443 |
SIA.maxImageExtent[ |
| 444 |
SIA.long[service.getMeta("sia.maxImageExtent.long", default=None)], |
| 445 |
SIA.lat[service.getMeta("sia.maxImageExtent.lat", default=None)], |
| 446 |
], |
| 447 |
SIA.maxImageSize[ |
| 448 |
service.getMeta("sia.maxImageSize", default=None), |
| 449 |
], |
| 450 |
SIA.maxFileSize[ |
| 451 |
service.getMeta("sia.maxFileSize", default=None), |
| 452 |
], |
| 453 |
SIA.maxRecords[ |
| 454 |
service.getMeta("sia.maxRecords", |
| 455 |
default=str(base.getConfig("ivoa", "dalHardLimit"))), |
| 456 |
], |
| 457 |
SIA.testQuery[ |
| 458 |
SIA.pos[ |
| 459 |
SIA.long[service.getMeta("testQuery.pos.ra")], |
| 460 |
SIA.lat[service.getMeta("testQuery.pos.dec")], |
| 461 |
], |
| 462 |
SIA.size[ |
| 463 |
SIA.long[service.getMeta("testQuery.size.ra")], |
| 464 |
SIA.lat[service.getMeta("testQuery.size.dec")], |
| 465 |
], |
| 466 |
], |
| 467 |
] |
| 468 |
|
| 469 |
|
| 470 |
class SIAV2CapabilityMaker(SIACapabilityMaker): |
| 471 |
renderer = "siap2.xml" |
| 472 |
capabilityClass = SIA.capability2 |
| 473 |
auxiliaryId = "ivo://ivoa.net/std/SIA#query-aux-2.0" |
| 474 |
|
| 475 |
|
| 476 |
class SCSCapabilityMaker(CapabilityMaker): |
| 477 |
renderer = "scs.xml" |
| 478 |
capabilityClass = SCS.capability |
| 479 |
|
| 480 |
def _makeCapability(self, publication): |
| 481 |
service = publication.service |
| 482 |
return CapabilityMaker._makeCapability(self, publication)[ |
| 483 |
SCS.maxSR[base.getMetaText(service, "maxSR", "180")], |
| 484 |
SCS.maxRecords[str(base.getConfig("ivoa", "dalDefaultLimit")*10)], |
| 485 |
SCS.verbosity["true"], |
| 486 |
SCS.testQuery[ |
| 487 |
SCS.ra[service.getMeta("testQuery.ra", raiseOnFail=True)], |
| 488 |
SCS.dec[service.getMeta("testQuery.dec", raiseOnFail=True)], |
| 489 |
SCS.sr[service.getMeta("testQuery.sr", default="0.001")], |
| 490 |
], |
| 491 |
] |
| 492 |
|
| 493 |
|
| 494 |
class SSACapabilityMaker(CapabilityMaker): |
| 495 |
renderer = "ssap.xml" |
| 496 |
capabilityClass = SSAP.capability |
| 497 |
|
| 498 |
def _makeCapability(self, publication): |
| 499 |
service = publication.parent |
| 500 |
cap = CapabilityMaker._makeCapability(self, publication)[ |
| 501 |
# XXX TODO: see what we need for "full" |
| 502 |
SSAP.complianceLevel[ |
| 503 |
service.getMeta("ssap.complianceLevel", default="minimal")]] |
| 504 |
|
| 505 |
cap[ |
| 506 |
SSAP.dataSource[service.getMeta("ssap.dataSource", raiseOnFail=True)], |
| 507 |
SSAP.creationType[service.getMeta("ssap.creationType", |
| 508 |
default="archival")], |
| 509 |
SSAP.supportedFrame["ICRS"], |
| 510 |
SSAP.maxSearchRadius["90"], |
| 511 |
SSAP.maxRecords[str(base.getConfig("ivoa", "dalHardLimit"))], |
| 512 |
SSAP.defaultMaxRecords[str(base.getConfig("ivoa", "dalDefaultLimit"))], |
| 513 |
SSAP.maxAperture["90"], |
| 514 |
SSAP.testQuery[ |
| 515 |
SSAP.queryDataCmd[base.getMetaText(service, "ssap.testQuery", |
| 516 |
raiseOnFail=True)]], |
| 517 |
] |
| 518 |
return cap |
| 519 |
|
| 520 |
|
| 521 |
class SLAPCapabilityMaker(CapabilityMaker): |
| 522 |
renderer = "slap.xml" |
| 523 |
capabilityClass = SLAP.capability |
| 524 |
|
| 525 |
def _makeCapability(self, publication): |
| 526 |
service = publication.parent |
| 527 |
return CapabilityMaker._makeCapability(self, publication)[ |
| 528 |
SLAP.complianceLevel[ |
| 529 |
service.getMeta("slap.complianceLevel", default="full")], |
| 530 |
SSAP.dataSource[service.getMeta("slap.dataSource", raiseOnFail=True)], |
| 531 |
SSAP.testQuery[ |
| 532 |
SSAP.queryDataCmd[base.getMetaText(service, "slap.testQuery", |
| 533 |
raiseOnFail=True)]], |
| 534 |
] |
| 535 |
|
| 536 |
|
| 537 |
_tapModelBuilder = meta.ModelBasedBuilder([ |
| 538 |
('supportsModel', meta.stanFactory(TR.dataModel), (), |
| 539 |
{"ivoId": "ivoId"})]) |
| 540 |
|
| 541 |
class TAPCapabilityMaker(CapabilityMaker): |
| 542 |
renderer = "dali" |
| 543 |
capabilityClass = TR.capability |
| 544 |
auxiliaryId = "ivo://ivoa.net/std/TAP#aux" |
| 545 |
|
| 546 |
def _getInterfaceElement(self, publication): |
| 547 |
"""for TAP, we return both a 1.0 pseudo-ParamHTTP and a DALIInterface. |
| 548 |
|
| 549 |
The DALIInterface part is experimental for now. |
| 550 |
""" |
| 551 |
yield TAPInterface()(publication) |
| 552 |
if "dali-interface-in-tap" in base.getConfig("future"): |
| 553 |
yield DALIInterface()(publication) |
| 554 |
|
| 555 |
def _makeCapability(self, publication): |
| 556 |
res = CapabilityMaker._makeCapability(self, publication) |
| 557 |
|
| 558 |
with base.getTableConn() as conn: |
| 559 |
from gavo.protocols import tap |
| 560 |
from gavo.adql import ufunctions |
| 561 |
|
| 562 |
res[[ |
| 563 |
TR.dataModel(ivoId=dmivoid)[dmname] |
| 564 |
for dmname, dmivoid in conn.query( |
| 565 |
"select dmname, dmivorn from tap_schema.supportedmodels")]] |
| 566 |
|
| 567 |
udfs = [] |
| 568 |
# the extra set() in the next line is to de-dupe UDFs that have |
| 569 |
# legacy aliases (e.g., gavo_specconv vs. ivo_specconv) |
| 570 |
for udf in set(ufunctions.UFUNC_REGISTRY.values()): |
| 571 |
udfs.append({ |
| 572 |
"signature": udf.adqlUDF_signature, |
| 573 |
"doc": udf.adqlUDF_doc}) |
| 574 |
udfs.extend(udf.adqlUDF_additionalSignatures) |
| 575 |
|
| 576 |
res[ |
| 577 |
# Once we support more than one language, we'll have to |
| 578 |
# revisit this -- the optional features must then become |
| 579 |
# a property of the language. |
| 580 |
[TR.language[ |
| 581 |
TR.name[langName], |
| 582 |
[TR.version(ivoId=ivoId)[version] |
| 583 |
for version, ivoId in versions], |
| 584 |
TR.description[description], |
| 585 |
TR.languageFeatures( |
| 586 |
type="ivo://ivoa.net/std/TAPRegExt#features-udf")[ |
| 587 |
[TR.feature[ |
| 588 |
TR.form[udf["signature"]], |
| 589 |
TR.description[udf["doc"]]] |
| 590 |
for udf in sorted(udfs, key=lambda v: v["signature"])]], |
| 591 |
|
| 592 |
TR.languageFeatures( |
| 593 |
type="ivo://ivoa.net/std/TAPRegExt#features-adqlgeo")[ |
| 594 |
[TR.feature[ |
| 595 |
TR.form[funcName]] |
| 596 |
for funcName in ("BOX", "POINT", "CIRCLE", "POLYGON", |
| 597 |
"REGION", "CENTROID", "COORD1", "COORD2", |
| 598 |
"DISTANCE", "CONTAINS", "INTERSECTS", "AREA")]], |
| 599 |
|
| 600 |
TR.languageFeatures( |
| 601 |
type="ivo://ivoa.net/std/TAPRegExt#features-adql-conditional")[ |
| 602 |
[TR.feature[ |
| 603 |
TR.form[funcName]] |
| 604 |
for funcName in ("COALESCE",)]], |
| 605 |
|
| 606 |
TR.languageFeatures( |
| 607 |
type="ivo://ivoa.net/std/TAPRegExt#features-adql-string")[ |
| 608 |
[TR.feature[ |
| 609 |
TR.form[funcName]] |
| 610 |
for funcName in ("LOWER", "ILIKE", "UPPER")]], |
| 611 |
|
| 612 |
TR.languageFeatures( |
| 613 |
type="ivo://ivoa.net/std/TAPRegExt#features-adql-offset")[ |
| 614 |
[TR.feature[ |
| 615 |
TR.form[funcName]] |
| 616 |
for funcName in ("OFFSET",)]], |
| 617 |
|
| 618 |
TR.languageFeatures( |
| 619 |
type="ivo://ivoa.net/std/TAPRegExt#features-adql-type")[ |
| 620 |
[TR.feature[ |
| 621 |
TR.form[funcName]] |
| 622 |
for funcName in ("CAST",)]], |
| 623 |
|
| 624 |
TR.languageFeatures( |
| 625 |
type="ivo://ivoa.net/std/TAPRegExt#features-adql-unit")[ |
| 626 |
[TR.feature[ |
| 627 |
TR.form[funcName]] |
| 628 |
for funcName in ("IN_UNIT",)]], |
| 629 |
|
| 630 |
TR.languageFeatures( |
| 631 |
type="ivo://ivoa.net/std/TAPRegExt#features-adql-common-table")[ |
| 632 |
[TR.feature[ |
| 633 |
TR.form[funcName]] |
| 634 |
for funcName in ("WITH",)]], |
| 635 |
|
| 636 |
TR.languageFeatures( |
| 637 |
type="ivo://org.gavo.dc/std/exts#extra-adql-keywords")[ |
| 638 |
TR.feature[ |
| 639 |
TR.form["TABLESAMPLE"], |
| 640 |
TR.description["Written after a table reference," |
| 641 |
" TABLESAMPLE(10) will make the database only use" |
| 642 |
" 10% of the rows; these are `somewhat random' in" |
| 643 |
" that the system will use random blocks. This" |
| 644 |
" should be good enough when just testing queries" |
| 645 |
" (and much better than using TOP n)."]], |
| 646 |
TR.feature[ |
| 647 |
TR.form["MOC"], |
| 648 |
TR.description["A geometry function creating MOCs." |
| 649 |
" It either takes a string argument with an ASCII" |
| 650 |
" MOC ('4/13 17-18 8/3002'), or an order and another" |
| 651 |
" geometry."]], |
| 652 |
TR.feature[ |
| 653 |
TR.form["VECTORMATH"], |
| 654 |
TR.description["You can compute with vectors here. See" |
| 655 |
" https://wiki.ivoa.net/twiki/bin/view/IVOA/ADQLVectorMath" |
| 656 |
" for an overview of the functions and operators available."], |
| 657 |
], |
| 658 |
TR.feature[ |
| 659 |
TR.form["CASE"], |
| 660 |
TR.description["The SQL92 CASE expression"], |
| 661 |
], |
| 662 |
], |
| 663 |
|
| 664 |
TR.languageFeatures( |
| 665 |
type="ivo://ivoa.net/std/TAPRegExt#features-adql-sets")[ |
| 666 |
[TR.feature[ |
| 667 |
TR.form[funcName]] |
| 668 |
for funcName in ("UNION", "EXCEPT", "INTERSECT")]]] |
| 669 |
for langName, description, versions |
| 670 |
in tap.getSupportedLanguages()], |
| 671 |
[TR.outputFormat(ivoId=ivoId)[ |
| 672 |
TR.mime[mime], |
| 673 |
[TR.alias[alias] for alias in aliases]] |
| 674 |
for mime, aliases, description, ivoId |
| 675 |
in tap.getSupportedOutputFormats()], |
| 676 |
[TR.uploadMethod(ivoId="ivo://ivoa.net/std/TAPRegExt#%s"%proto) |
| 677 |
for proto in tap.UPLOAD_METHODS], |
| 678 |
TR.retentionPeriod[ |
| 679 |
TR.default[str(base.getConfig("async", "defaultLifetime"))]], |
| 680 |
TR.executionDuration[ |
| 681 |
TR.default[str(base.getConfig("async", "defaultExecTimeSync"))]], |
| 682 |
TR.executionDuration(forMode="async")[ |
| 683 |
TR.default[str(base.getConfig("async", "defaultExecTime"))] |
| 684 |
if "tre-for-mode" in base.getConfig("future") else None], |
| 685 |
TR.outputLimit[ |
| 686 |
TR.default(unit="row")[ |
| 687 |
str(base.getConfig("async", "defaultMAXREC"))], |
| 688 |
TR.hard(unit="row")[ |
| 689 |
str(base.getConfig("async", "hardMAXREC"))]], |
| 690 |
TR.uploadLimit[ |
| 691 |
TR.hard(unit="byte")[ |
| 692 |
str(base.getConfig("web", "maxSyncUploadSize"))]], |
| 693 |
TR.uploadLimit(forMode="async")[ |
| 694 |
TR.hard(unit="byte")[ |
| 695 |
str(base.getConfig("web", "maxUploadSize"))] |
| 696 |
if "tre-for-mode" in base.getConfig("future") else None]] |
| 697 |
return res |
| 698 |
|
| 699 |
|
| 700 |
class RegistryCapabilityMaker(CapabilityMaker): |
| 701 |
renderer = "pubreg.xml" |
| 702 |
capabilityClass = VOG.Harvest |
| 703 |
def _makeCapability(self, publication): |
| 704 |
return CapabilityMaker._makeCapability(self, publication)[ |
| 705 |
VOG.maxRecords[str(base.getConfig("ivoa", "oaipmhPageSize"))]] |
| 706 |
|
| 707 |
|
| 708 |
class VOSICapabilityMaker(PlainCapabilityMaker): |
| 709 |
# A common parent for the VOSI cap. makers. All of those are |
| 710 |
# parallel and only differ by standardID |
| 711 |
capabilityClass = VOG.capability |
| 712 |
|
| 713 |
|
| 714 |
class VOSIAvCapabilityMaker(VOSICapabilityMaker): |
| 715 |
renderer = "availability" |
| 716 |
standardId = "ivo://ivoa.net/std/VOSI#availability" |
| 717 |
|
| 718 |
class VOSICapCapabilityMaker(VOSICapabilityMaker): |
| 719 |
renderer = "capabilities" |
| 720 |
standardId = "ivo://ivoa.net/std/VOSI#capabilities" |
| 721 |
|
| 722 |
class VOSITMCapabilityMaker(VOSICapabilityMaker): |
| 723 |
renderer = "tableMetadata" |
| 724 |
standardId = "ivo://ivoa.net/std/VOSI#tables" |
| 725 |
|
| 726 |
class ExamplesCapabilityMaker(PlainCapabilityMaker): |
| 727 |
renderer = "examples" |
| 728 |
standardId = "ivo://ivoa.net/std/DALI#examples" |
| 729 |
|
| 730 |
class HiPSCapabilityMaker(PlainCapabilityMaker): |
| 731 |
renderer = "hips" |
| 732 |
standardId = "ivo://ivoa.net/std/hips#hips-1.0" |
| 733 |
interfaceClass = StandardParamHTTP |
| 734 |
|
| 735 |
class SOAPCapabilityMaker(CapabilityMaker): |
| 736 |
renderer = "soap" |
| 737 |
|
| 738 |
class FormCapabilityMaker(CapabilityMaker): |
| 739 |
renderer = "form" |
| 740 |
|
| 741 |
class QPCapabilityMaker(CapabilityMaker): |
| 742 |
renderer = "qp" |
| 743 |
|
| 744 |
class ExternalCapabilityMaker(CapabilityMaker): |
| 745 |
renderer = "external" |
| 746 |
|
| 747 |
def _getInterfaceElement(self, publication): |
| 748 |
override = base.getMetaText(publication, "interfaceType") |
| 749 |
if override: |
| 750 |
return globals()[override]()(publication) |
| 751 |
else: |
| 752 |
return CapabilityMaker._getInterfaceElement(self, publication) |
| 753 |
|
| 754 |
class VOEventCapabilityMaker(CapabilityMaker): |
| 755 |
renderer = "voevent" |
| 756 |
capabilityClass = VOE.capability |
| 757 |
|
| 758 |
def _getInterfaceElement(self, publication): |
| 759 |
if publication.hasMeta("interfaceType"): |
| 760 |
return globals()[base.getMetaText(publication, "interfaceType") |
| 761 |
]()(publication) |
| 762 |
else: |
| 763 |
return _getInterfaceMaker(publication.render)(publication) |
| 764 |
|
| 765 |
def _makeCapability(self, publication): |
| 766 |
return CapabilityMaker._makeCapability(self, publication) |
| 767 |
|
| 768 |
class StaticCapabilityMaker(CapabilityMaker): |
| 769 |
renderer = "static" |
| 770 |
|
| 771 |
class VolatileCapabilityMaker(CapabilityMaker): |
| 772 |
renderer = "volatile" |
| 773 |
|
| 774 |
class CustomCapabilityMaker(CapabilityMaker): |
| 775 |
renderer = "custom" |
| 776 |
|
| 777 |
class JPEGCapabilityMaker(CapabilityMaker): |
| 778 |
renderer = "img.jpeg" |
| 779 |
|
| 780 |
class FixedCapabilityMaker(CapabilityMaker): |
| 781 |
renderer = "fixed" |
| 782 |
|
| 783 |
class DocformCapabilityMaker(CapabilityMaker): |
| 784 |
renderer = "docform" |
| 785 |
|
| 786 |
class ProductCapabilityMaker(CapabilityMaker): |
| 787 |
renderer = "get" |
| 788 |
|
| 789 |
|
| 790 |
class DatalinkCapabilityMaker(CapabilityMaker): |
| 791 |
renderer = "dlmeta" |
| 792 |
|
| 793 |
class capabilityClass(VOR.capability): |
| 794 |
_a_standardID = "ivo://ivoa.net/std/DataLink#links-1.1" |
| 795 |
|
| 796 |
|
| 797 |
class SODACapabilityMaker(CapabilityMaker): |
| 798 |
renderer = "dlget" |
| 799 |
|
| 800 |
class capabilityClass(VOR.capability): |
| 801 |
_a_standardID = "ivo://ivoa.net/std/SODA#sync-1.0" |
| 802 |
|
| 803 |
|
| 804 |
class SODAAsyncCapabilityMaker(CapabilityMaker): |
| 805 |
renderer = "dlasync" |
| 806 |
|
| 807 |
class capabilityClass(VOR.capability): |
| 808 |
_a_standardID = "ivo://ivoa.net/std/SODA#async-1.0" |
| 809 |
|
| 810 |
|
| 811 |
class EditionCapabilityMaker(CapabilityMaker): |
| 812 |
renderer = "edition" |
| 813 |
|
| 814 |
capabilityClass = DOC.capability |
| 815 |
|
| 816 |
def _makeCapability(self, publication): |
| 817 |
res = CapabilityMaker._makeCapability(self, publication) |
| 818 |
|
| 819 |
# if there's sourceURL meta, add an interface |
| 820 |
for su in publication.iterMeta("sourceURL"): |
| 821 |
res[ |
| 822 |
VOR.WebBrowser(role="source")[ |
| 823 |
VOR.accessURL[su.getContent()]]] |
| 824 |
|
| 825 |
return res[ |
| 826 |
DOC.languageCode[ |
| 827 |
base.getMetaText(publication, "languageCode", "en")], |
| 828 |
DOC.locTitle[ |
| 829 |
base.getMetaText(publication, "locTitle", None)]] |
| 830 |
|
| 831 |
|
| 832 |
class BiblinksCapabilityMaker(CapabilityMaker): |
| 833 |
renderer = "biblinks.json" |
| 834 |
|
| 835 |
class capabilityClass(VOR.capability): |
| 836 |
_a_standardID = "ivo://ivoa.net/std/BibVO#biblink-harvest-1.0" |
| 837 |
|
| 838 |
|
| 839 |
_getCapabilityMaker = utils.buildClassResolver(CapabilityMaker, |
| 840 |
list(globals().values()), instances=True, |
| 841 |
key=lambda obj: obj.renderer) |
| 842 |
|
| 843 |
|
| 844 |
def getAuxiliaryCapability(publication): |
| 845 |
"""returns a VR.capability element for an auxiliary publication. |
| 846 |
|
| 847 |
That's a plain capability with essentially the interface and a |
| 848 |
standardId obtained from the auxiliaryId attribute of the |
| 849 |
capability's normal maker. |
| 850 |
|
| 851 |
If no auxiliaryId is defined, None is returned (which means no |
| 852 |
capability will be generated). |
| 853 |
""" |
| 854 |
capMaker = _getCapabilityMaker(publication.render) |
| 855 |
if capMaker.auxiliaryId: |
| 856 |
return CapabilityMaker()(publication)(standardID=capMaker.auxiliaryId) |
| 857 |
|
| 858 |
|
| 859 |
def getCapabilityElement(publication): |
| 860 |
"""returns the appropriate capability definition for a publication object. |
| 861 |
""" |
| 862 |
if publication.auxiliary: |
| 863 |
return getAuxiliaryCapability(publication) |
| 864 |
else: |
| 865 |
try: |
| 866 |
maker = _getCapabilityMaker(publication.render) |
| 867 |
except KeyError: |
| 868 |
raise base.ui.logOldExc(base.ReportableError("Do not know how to" |
| 869 |
" produce a capability for the '%s' renderer"%publication.render)) |
| 870 |
return maker(publication) |