| 1 |
""" |
| 2 |
Resources that are not services. |
| 3 |
""" |
| 4 |
|
| 5 |
#c Copyright 2008-2025, the GAVO project <[email protected]> |
| 6 |
#c |
| 7 |
#c This program is free software, covered by the GNU GPL. See the |
| 8 |
#c COPYING file in the source distribution. |
| 9 |
|
| 10 |
|
| 11 |
from gavo import base |
| 12 |
from gavo import rscdef |
| 13 |
from gavo import svcs |
| 14 |
from gavo.base import meta |
| 15 |
|
| 16 |
|
| 17 |
class NonServiceResource( |
| 18 |
base.Structure, |
| 19 |
base.StandardMacroMixin, |
| 20 |
base.ComputedMetaMixin): |
| 21 |
"""A base class for resources that are not services. |
| 22 |
""" |
| 23 |
def _meta_identifier(self): |
| 24 |
# Special case the authority |
| 25 |
if base.getMetaText(self, "resType")=="authority": |
| 26 |
localPart = "" |
| 27 |
else: |
| 28 |
localPart = "/%s/%s"%(self.rd.sourceId, self.id) |
| 29 |
return "ivo://%s%s"%(base.getConfig("ivoa", "authority"), localPart) |
| 30 |
|
| 31 |
|
| 32 |
def _nodata(instance, request, tag): |
| 33 |
return [] |
| 34 |
|
| 35 |
|
| 36 |
class ResRec(rscdef.IVOMetaMixin, svcs.GetURLMixin, NonServiceResource): |
| 37 |
"""A resource for pure registration purposes. |
| 38 |
|
| 39 |
A Resource without (much) DaCHS-defined behaviour. This can be |
| 40 |
Organizations or Instruments, but possibly also external services. |
| 41 |
|
| 42 |
All resources must either have an id (which is used in the construction of |
| 43 |
their IVOID), or you must give an identifier meta item. |
| 44 |
|
| 45 |
You must further set the following meta items: |
| 46 |
|
| 47 |
- resType specifying the kind of resource record. You should not |
| 48 |
use this element to build resource records for services or tables |
| 49 |
(use the normal elements, even if the actual resources are external |
| 50 |
to DaCHS). resType can be registry, organization, authority, |
| 51 |
deleted, or anything else for which registry.builders has a |
| 52 |
handling class. |
| 53 |
- title |
| 54 |
- subject(s) |
| 55 |
- description |
| 56 |
- referenceURL |
| 57 |
- creationDate |
| 58 |
|
| 59 |
Additional meta keys (e.g., accessURL for a registry) may be required |
| 60 |
depending on resType. See the registry section in the operator's guide. |
| 61 |
|
| 62 |
ResRecs can also have publication children. These will be turned into |
| 63 |
the appropriate capabilities depending on the value of the render |
| 64 |
attribute. |
| 65 |
""" |
| 66 |
name_ = "resRec" |
| 67 |
_rd = rscdef.RDAttribute() |
| 68 |
|
| 69 |
metaModel = ("resType(1), title(1), subject, description(1)," |
| 70 |
" referenceURL(1), creationDate(1)," |
| 71 |
" contentLevel(? voc:voresource/content_level)") |
| 72 |
|
| 73 |
_publications = base.StructListAttribute("publications", |
| 74 |
childFactory=svcs.Publication, |
| 75 |
description="Capabilities the record should have (this is empty" |
| 76 |
" for standards, organisations, instruments, etc.)") |
| 77 |
|
| 78 |
# we add a few "constant" attributes to make this work with the |
| 79 |
# info renderer |
| 80 |
limitTo = None |
| 81 |
nevowRenderers = {} |
| 82 |
nevowDataFunctions = { |
| 83 |
"inputFields": _nodata, |
| 84 |
"htmlOutputFields": _nodata, |
| 85 |
"votableOutputFields": _nodata} |
| 86 |
|
| 87 |
@property |
| 88 |
def allowed(self): |
| 89 |
# for services, we enumerate usable renderers here; that doesn't |
| 90 |
# make sense for resRecs. Instead, we list the renderers mentioned |
| 91 |
# in publications. |
| 92 |
return [p.render for p in self.publications] |
| 93 |
|
| 94 |
def onElementComplete(self): |
| 95 |
super().onElementComplete() |
| 96 |
self.core = base.makeStruct(svcs.NullCore, parent_=self) |
| 97 |
self.setMetaParent(self.rd) |
| 98 |
|
| 99 |
def getPublicationsForSet(self, names): |
| 100 |
"""returns publications for set names in names. |
| 101 |
|
| 102 |
names must be a python set. |
| 103 |
""" |
| 104 |
for pub in self.publications: |
| 105 |
if pub.sets&names: |
| 106 |
yield pub |
| 107 |
|
| 108 |
def getTableSet(self): |
| 109 |
for relatedTable in self.iterMeta("tableset"): |
| 110 |
yield base.resolveCrossId(relatedTable.getContent("text")) |
| 111 |
|
| 112 |
def getBrowserURL(self, fq=True): |
| 113 |
return None |
| 114 |
|
| 115 |
def _meta_sets(self): |
| 116 |
# This is a copy of the corresponding code in svcs.Service. |
| 117 |
# See there for more info. |
| 118 |
sets = set() |
| 119 |
for p in self.publications: |
| 120 |
sets |= p.sets |
| 121 |
return meta.MetaItem.fromSequence( |
| 122 |
[meta.MetaValue(s) for s in sets]) |
| 123 |
|
| 124 |
|
| 125 |
class _FakeRD(object): |
| 126 |
def __init__(self, id): |
| 127 |
self.sourceId = id |
| 128 |
|
| 129 |
|
| 130 |
class DeletedResource(NonServiceResource): |
| 131 |
"""a remainder of a deleted resource. These are always built from information |
| 132 |
in the database, since that is the only place they are remembered. |
| 133 |
""" |
| 134 |
resType = "deleted" |
| 135 |
|
| 136 |
_resTuple = base.RawAttribute("resTuple") |
| 137 |
|
| 138 |
def _meta_status(self): |
| 139 |
return "deleted" |
| 140 |
|
| 141 |
def _meta_identifier(self): |
| 142 |
return self.resTuple["ivoid"] |
| 143 |
|
| 144 |
def completeElement(self, ctx): |
| 145 |
super().completeElement(ctx) |
| 146 |
self.rd = _FakeRD(self.resTuple["sourceRD"]) |
| 147 |
self.id = self.resTuple["resId"] |
| 148 |
self.setMeta("_metadataUpdated", self.resTuple["recTimestamp"]) |