1 """
2 Functions returning xmlstan for various OAI/VOR documents.
3
4 This comprises basic VOResource elements; capabilities and interfaces
5 (i.e. everything to do with renderers) are in registry.capabilities.
6
7 All this only becomes difficult when actually generating VOResource
8 metadata (OAI is plain). For every type of VO resource (CatalogService,
9 Registry, etc), there's a XYResourceMaker, all inheriting ResourceMaker.
10
11 The decision what VOResource type a given service has is passed
12 using common.getResType; this means the resType meta is tried first,
13 using resob.resType as a fallback.
14 """
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 from gavo import base
34 from gavo import stc
35 from gavo import svcs
36 from gavo import utils
37 from gavo.base import meta
38 from gavo.registry import common
39 from gavo.registry import capabilities
40 from gavo.registry import identifiers
41 from gavo.registry import tableset
42 from gavo.registry import servicelist
43 from gavo.registry.model import (
44 OAI, VOR, VOG, DC, RI, VS, OAIDC, VSTD, DOC)
45
46 MS = base.makeStruct
47
48 SF = meta.stanFactory
49 _defaultSet = set(["ivo_managed"])
50
51
52
53 VALIDATING = False
54
55
56
57
59
60
61 src = unicode(children[0])
62 attrs = {}
63 if utils.couldBeABibcode(src):
64 attrs["format"] = "bibcode"
65 return VOR.source(**attrs)[src]
66
67
75
76
77 _vrResourceBuilder = meta.ModelBasedBuilder([
78 ('title', SF(VOR.title)),
79 ('shortName', SF(VOR.shortName)),
80 ('identifier', SF(VOR.identifier)),
81 ('doi', lambda args, localattrs=None: VOR.altIdentifier["doi:"+args[0]]),
82 (None, SF(VOR.curation), [
83 ('publisher', SF(VOR.publisher), (), {
84 "ivoId": "ivoId"}),
85 ('creator', SF(VOR.creator), [
86 ('name', SF(VOR.name)),
87 ('altIdentifier', SF(VOR.altIdentifier)),
88 ('logo', SF(VOR.logo)),]),
89 ('contributor', SF(VOR.contributor), (), {
90 "ivoId": "ivoId"}),
91
92
93
94
95 ('datetimeUpdated', SF(VOR.date, role="updated")),
96 ('date', SF(VOR.date), (), {
97 "role": "role"}),
98 ('_news', _build_dateFromNews, (), {
99 "role": "role",
100 "date": "date"}),
101 ('version', SF(VOR.version)),
102 ('contact', SF(VOR.contact), [
103 ('name', SF(VOR.name), (), {
104 "ivoId": "ivoId"}),
105 ('address', SF(VOR.address)),
106 ('email', SF(VOR.email)),
107 ('telephone', SF(VOR.telephone)),]),]),
108 (None, SF(VOR.content), [
109 ('subject', SF(VOR.subject)),
110 ('description', SF(VOR.description)),
111 ('source', _build_source),
112 ('referenceURL', SF(VOR.referenceURL)),
113 ('type', SF(VOR.type)),
114 ('contentLevel', SF(VOR.contentLevel)),] + [
115
116
117 (None, SF(lambda t=vorTerm:
118 VOR.relationship[VOR.relationshipType[t]]), [
119 (metaName, SF(VOR.relatedResource), (), {
120 "ivoId": "ivoId"})])
121 for metaName, vorTerm in [
122 ("servedBy", "served-by"),
123 ("serviceFor", "service-for"),
124 ("derivedFrom", "dervived-from"),
125 ("relatedTo", "related-to"),
126 ("mirrorOf", "mirror-of"),
127 ("relatedTo", "related-to"),
128 ("uses", "Cites")]
129 ] + [
130
131 (None, SF(lambda term=term:
132 VOR.relationship[VOR.relationshipType[term]]), [
133 (term[0].lower()+term[1:], SF(VOR.relatedResource), (), {
134 "ivoId": "ivoId"})])
135 for term in [
136 "Cites",
137 "IsSupplementTo",
138 "IsSupplementedBy",
139 "IsContinuedBy",
140 "Continues",
141 "IsNewVersionOf",
142 "IsPreviousVersionOf",
143 "IsPartOf",
144 "HasPart",
145 "IsSourceOf",
146 "IsDerivedFrom",
147 "IsIdenticalTo",
148 "IsServiceFor",
149 "IsServedBy"]])
150 ])
151
152
153 _dcBuilder = meta.ModelBasedBuilder([
154 ('title', SF(DC.title)),
155 ('identifier', SF(DC.identifier)),
156 ('creator', None, [
157 ('name', SF(DC.creator))]),
158 ('contributor', None, [
159 ('name', SF(DC.contributor))]),
160 ('description', SF(DC.description)),
161 ('language', SF(DC.language)),
162 ('rights', SF(DC.rights), ()),
163 ('publisher', SF(DC.publisher)),
164 ])
165
166
167 _oaiHeaderBuilder = meta.ModelBasedBuilder([
168 ('identifier', SF(OAI.identifier)),
169 ('recTimestamp', SF(OAI.datestamp)),
170 ('sets', SF(OAI.setSpec))])
171
172
173 _orgMetaBuilder = meta.ModelBasedBuilder([
174 ('facility', SF(VOR.facility)),
175 ('instrument', SF(VOR.instrument)),
176 ])
177
178
179 _standardsMetaBuilder = meta.ModelBasedBuilder([
180 ('endorsedVersion', SF(VSTD.endorsedVersion), (), {
181 'status': 'status',
182 'use': 'use'}),
183 ('deprecated', SF(VSTD.deprecated), ()),
184 ('key', SF(VSTD.key), [
185 ('name', SF(VSTD.name), []),
186 ('description', SF(VSTD.description), [])])])
187
188
204
205
222
223
224 _coverageMetaBuilder = meta.ModelBasedBuilder([
225 ('coverage', SF(VS.coverage), [
226 ('profile', _stcResourceProfile),
227 ('spatial', SF(VS.spatial)),
228 ('temporal', SF(VS.temporal)),
229 ('spectral', SF(VS.spectral)),
230
231
232 ('spatial', _build_footprintURL),
233 ('waveband', SF(VS.waveband)),
234 ('regionOfRegard', SF(VS.regionOfRegard)),
235 ])])
236
237
239 """returns the mandatory attributes for constructing a Resource record
240 for service in a dictionary.
241 """
242 return {
243 "created": base.getMetaText(resob, "creationDate", propagate=True),
244 "updated": base.getMetaText(resob, "datetimeUpdated", propagate=True),
245 "status": base.getMetaText(resob, "status"),
246 }
247
248
261
262
263
264
266 """returns the OAI-PHM access URL for a registry service.
267
268 We don't want to just use getURL(pubreg) since the publication
269 may (and for the publishing registry does) have an accessURL meta.
270 """
271 oaiAccessURL = registryService.getURL("pubreg.xml")
272 for pub in registryService.publications:
273 if pub.render=="pubreg.xml":
274 oaiAccessURL = base.getMetaText(
275 pub, "accessURL", macroPackage=pub.parent)
276 break
277 return oaiAccessURL
278
279
281 """returns OAI Identify stanxml.
282
283 registryService is the registry we're identifying, i.e. typically
284 __system__/services#registry
285 """
286 return OAI.Identify[
287 OAI.repositoryName[base.getMetaText(registryService, "title")],
288 OAI.baseURL[_getOAIURL(registryService)],
289 OAI.protocolVersion["2.0"],
290 OAI.adminEmail[base.getMetaText(registryService, "contact.email")],
291 OAI.earliestDatestamp["1970-01-01T00:00:00Z"],
292 OAI.deletedRecord["transient"],
293 OAI.granularity["YYYY-MM-DDThh:mm:ssZ"],
294 OAI.description[
295 getVORMetadataElement(registryService),
296 ],
297 ]
298
299
306
307
316
317
327
328
344
345
348
349
352
353
356 """returns stanxml for ListRecords in dublin core format.
357
358 resobs is a sequence of res objects.
359 makeRecord(resob, setNames) -> stanxml is a function that returns
360 an OAI.record element. For ivo_vor metadata prefixes, this is overridden.
361 by getVOListRecordsElement.
362 """
363 recs = OAI.ListRecords()
364 for resob in resobs:
365 try:
366 recs[makeRecord(resob, setNames)]
367 except base.NoMetaKey as msg:
368 base.ui.notifyError("Cannot create registry record for %s#%s"
369 " because mandatory meta %s is missing"%(
370 resob.rd.sourceId, resob.id, msg))
371 except Exception as msg:
372 base.ui.notifyError("Cannot create registry record %s. Reason: %s"%(
373 resob, msg))
374 return recs
375
376
380
381
382
383
385 """A base class for the generation of VOResource elements.
386
387 These have a resType attribute specifying which resource type
388 they work for. These types are computed by the getResourceType
389 helper function.
390
391 The makeResource function below tries the ResourceMakers in turn
392 for the "best" one that matches.
393
394 If you create new ResourceMakers, you will have to enter them
395 *in the correct sequence* in the _resourceMakers list below.
396
397 ResourceMaker instances are called with a resob argument and a set
398 of set names. You will want to override the _makeResource(resob)
399 -> xmlstan method and probably the resourceClass element.
400 """
401 resourceClass = RI.Resource
402 resType = None
403
405 """loads all RDs dependent on resob.rd (if present).
406
407 The dependencies are taken from the dc.res_dependencies table. There,
408 they are typically introduced by served-by relationships (see also
409 service.declareServes.
410 """
411 if not hasattr(resob.rd, "cached dependencies"):
412 deps = common.getDependencies(resob.rd.sourceId)
413 setattr(resob.rd, "cached dependencies", deps)
414 else:
415 deps = getattr(resob.rd, "cached dependencies")
416 for dep in deps:
417 base.caches.getRD(dep)
418
419
430
433
434
435 _rightsBuilder = meta.ModelBasedBuilder([
436 ('rights', SF(VOR.rights), (), {
437 'rightsURI': 'rightsURI'}),])
438
439
441 """A ResourceMaker adding rights and capabilities.
442 """
443 resourceClass = VS.DataService
444 resType = "nonTabularService"
445
452
453
455 """A ResourceMaker for DataServices.
456
457 These are services that may have instrument, facility, and coverage
458 metas but have no associated tables. This is not generated by the
459 service classifier currently since we always have a table. You can
460 force generation of such records via setMeta("resType", "dataService").
461 """
462 resourceClass = VS.DataService
463 resType = "dataService"
464
469
470
477
478
479 _registryMetaBuilder = meta.ModelBasedBuilder([
480 ('managedAuthority', SF(VOG.managedAuthority)),])
481
482
491
492
493
500
501
510
511
518
519
523
524
529
530
532 """A base class for Table- and DataResourceMaker.
533 """
534 resourceClass = VS.CatalogResource
535
538
554
555
557 """A ResourceMaker for rscdef.TableDef items (yielding reformed
558 DataCollections)
559 """
560 resType = "table"
561
565
566
568 """A ResourceMaker for rscdef.DataDescriptor items (yielding reformed
569 DataCollections)
570 """
571 resType = "data"
572
576
577
578 _getResourceMaker = utils.buildClassResolver(ResourceMaker,
579 globals().values(), instances=True,
580 key=lambda obj: obj.resType)
581
582
585
586
588 """returns a stanxml for Resource in VOR format.
589
590 There's trouble here in that we have set management on the level of
591 renderers (capabilities). Thus, to come up with capabilities for
592 a given ivorn, we have to know what set is queried. However,
593 OAI GetRecord doesn't specify sets. So, we provide a default
594 set of ivo_managed, assuming that the registry is only interested
595 in records actually VO-registred. This may fly into our face,
596 but I can't see a way around it given the way our services are
597 described.
598 """
599 return getResourceElement(resob, setNames, getVORMetadataElement)
600
601
605
606
610