def _makeInterface(self, publication):
     return self.interfaceClass[VOR.accessURL(
         use=base.getMetaText(publication, "urlUse"))[base.getMetaText(
             publication, "accessURL", macroPackage=publication.parent)],
                                VOR.securityMethod(
                                    standardId=base.getMetaText(
                                        publication, "securityId")), ]
Beispiel #2
0
def getTableForTableDef(tableDef, namesInSet):
	"""returns a VS.table instance for a rscdef.TableDef.

	namesInSet is a set of lowercased qualified table names; we need this
	to figure out which foreign keys to create.
	"""
	name = getEffectiveTableName(tableDef)

	# Fake type=output on the basis of the table name.  We'll have
	# to do something sensible here if this "type" thing ever becomes
	# more meaningful.
	type = None
	if name=="output":
		type = "output"

	res = VS.table(type=type)[
		VS.name[name],
		VS.title[base.getMetaText(tableDef, "title", propagate=False)],
		VS.description[base.getMetaText(tableDef, "description", propagate=True)],
		VS.utype[base.getMetaText(tableDef, "utype")], [
			getTableColumnFromColumn(col, voTableDataTypeFactory)
				for col in tableDef], [
			getForeignKeyForForeignKey(fk, namesInSet)
				for fk in tableDef.foreignKeys]]
	return res
def makeBaseRecord(res, keepTimestamp=False):
	"""returns a dictionary giving the metadata common to resource records.
	"""
	# bomb out if critical metadata is missing
	base.validateStructure(res)
	# bomb out if, for some reason, we can't come up with a resource record
	# for this guy
	builders.getVOResourceElement(res)

	rec = {}
	rec["ivoid"] = base.getMetaText(res, "identifier")
	rec["shortName"] = base.getMetaText(res, "shortName")
	rec["sourceRD"] = res.rd.sourceId
	rec["resId"] = res.id
	rec["title"] = base.getMetaText(res, "title", propagate=True)
	rec["deleted"] = False
	rec["recTimestamp"] = datetime.datetime.utcnow()
	rec["description"] = base.getMetaText(res, "description")
	rec["authors"] = "; ".join(m.getContent("text") 
		for m in res.iterMeta("creator.name", propagate=True))
	dateUpdated = res.getMeta("datetimeUpdated")

	if keepTimestamp:
		try:
			rec["recTimestamp"] = base.getMetaText(res, "recTimestamp")
		except base.NoMetaKey:
			# not published, nothing to keep
			pass

	if dateUpdated is None:
		rec["dateUpdated"] = datetime.datetime.utcnow()
	else:
		rec["dateUpdated"] = str(dateUpdated)
	return rec
Beispiel #4
0
def _addTableMeta(query, tree, table):
    """adds various info items from query and its parsed tree to a
	result table.
	"""
    # Copy over tableDef meta so it doesn't get obscured by what
    # we're setting now.
    for infoMeta in table.tableDef.iterMeta("info", propagate=False):
        table.addMeta("info", infoMeta)

    table.addMeta("info",
                  "",
                  infoName="server",
                  infoValue=base.getConfig("web", "serverURL"))
    table.addMeta("info", "", infoName="query", infoValue=query)

    mth = base.caches.getMTH(None)
    sourceTables = tree.getContributingNames()
    # for 1-table queries, we've already copied the entire table metadata.
    # don't re-copy it.
    tableMetaCopied = len(sourceTables) == 1

    tablesSeen = set()
    for tableName in sourceTables:
        if tableName in tablesSeen:
            continue
        tablesSeen.add(tableName)

        try:
            sourceTD = mth.getTableDefForTable(tableName)
            table.addMeta("info",
                          base.getMetaText(sourceTD.rd, "description", ""),
                          infoName="src_res",
                          infoValue="Contains traces from resource %s" %
                          (sourceTD.rd.sourceId))
            for m in sourceTD.iterMeta("copyright", propagate=True):
                table.addMeta("info",
                              m.getContent("text"),
                              infoName="copyright",
                              infoValue="%s copyright or license" %
                              (sourceTD.rd.sourceId))
            table.addMeta("info",
                          base.getMetaText(sourceTD,
                                           "description",
                                           "",
                                           propagate=False),
                          infoName="src_table",
                          infoValue="Contains traces from table %s" %
                          (sourceTD.getQName()))

            if not tableMetaCopied:
                for m in sourceTD.iterMeta("howtociteLink"):
                    table.addMeta("howtociteLink", m)
                for m in sourceTD.iterMeta("source"):
                    table.addMeta("source", m)
        except base.Error:
            # don't fail just because of funny metadata or tables not found
            pass
def getResourceArgs(resob):
	"""returns the mandatory attributes for constructing a Resource record
	for service in a dictionary.
	"""
	return {
		"created": base.getMetaText(resob, "creationDate", propagate=True),
		"updated": base.getMetaText(resob, "datetimeUpdated", propagate=True),
		"status": base.getMetaText(resob, "status"),
	}
Beispiel #6
0
def getSchemaForRD(rd):
	"""returns a VS.schema instance for an rd.

	No tables are added.  You need to pick and choose them yourself.
	"""
	return VS.schema[
		VS.name[rd.schema.lower()],
		VS.title[base.getMetaText(rd, "title")],
		VS.description[base.getMetaText(rd, "description")],
	]
    def _makeInterface(self, publication):
        paramSrc = publication.parent
        if publication.service:
            paramSrc = publication.service

        return InterfaceMaker._makeInterface(
            self,
            publication)[VS.queryType[base.getMetaText(
                publication, "requestMethod", propagate=False)],
                         VS.resultType[base.getMetaText(
                             publication, "resultType", propagate=False)],
                         getInputParams(publication, paramSrc)]
    def _addToSourceTable(self):
        """adds information about self.tableDef to the tablemeta table.
		"""
        t = DBTable(base.caches.getRD(
            self.__metaRDId).getTableDefById("tablemeta"),
                    connection=self.connection)
        t.addRow({
            "tableName": self.tableDef.getQName(),
            "sourceRD": self.tableDef.rd.sourceId,
            "adql": self.tableDef.adql,
            "tableDesc": base.getMetaText(self.tableDef, "description"),
            "resDesc": base.getMetaText(self.tableDef.rd, "description"),
        })
Beispiel #9
0
    def render_svclink(self, ctx, data):
        """renders a link to a service info with a service title.
		
		data must be an item returned from data_services.
		"""
        return ctx.tag(href=data.getURL("info"))[base.getMetaText(
            data, "title")]
Beispiel #10
0
    def _getMetadataData(self, queryMeta):
        """returns a SIAP-style metadata data item.
		"""
        # XXX TODO: build VOTable directly (rather than from data)
        inputFields = []
        for param in self.service.getInputKeysFor(self):
            # Caution: UPLOAD mangling is a *renderer* thing -- the core
            # doesn't know anything about it.  Hence, parameter adaption
            # is *not* done by adapting the core.  Instead:
            if param.type == "file":
                inputFields.append(dali.getUploadKeyFor(param))
            else:
                inputFields.append(param.change(name="INPUT:" + param.name))
        outputTable = MS(rscdef.TableDef,
                         columns=self.service.getCurOutputFields(queryMeta),
                         id="result")

        nullRowmaker = MS(rscdef.RowmakerDef)
        dataDesc = MS(
            svcs.InputDescriptor,
            makes=[MS(rscdef.Make, table=outputTable, rowmaker=nullRowmaker)],
            params=inputFields,
            parent_=self.service.rd)

        data = rsc.makeData(dataDesc)
        data.tables["result"].votCasts = self._outputTableCasts
        data.setMeta("_type", "results")
        data.addMeta("info", "OK", infoName="QUERY_STATUS", infoValue="OK")
        data.addMeta("info",
                     base.getMetaText(self.service, "title") or "Unnamed",
                     infoName="serviceInfo",
                     infoValue=str(self.service.getURL(self.name)))

        return data
Beispiel #11
0
    def _explain_ssap_xml(cls, service):
        tqKeys = cgi.parse_qs(
            base.getMetaText(service, "ssap.testQuery", default=""))
        # validator php seems to insist on that key
        opts = [
            "batch=yes&"
            "service=http%3A%2F%2Fvoparis-validator.obspm.fr%2Fxml%2F111.xml%3F"
        ]
        for standardKey, default in [("REQUEST", "queryData"), ("SIZE", ""),
                                     ("POS", ""), ("TIME", ""), ("BAND", ""),
                                     ("FORMAT", "ALL")]:
            opts.append("%s=%s" %
                        (standardKey,
                         urllib.quote(tqKeys.pop(standardKey, [default])[0])))
        opts.append("addparams=" +
                    urllib.quote("\n".join("%s=%s" % (k, urllib.quote(v[0]))
                                           for k, v in tqKeys.iteritems())))
        optStr = "&".join(opts)
        if optStr:
            optStr = optStr + "&"

        return T.invisible[
            "a standard SSAP interface as defined by the"
            " IVOA to access spectral or time-series data; SSAP clients"
            " use ",
            service.getURL("ssap.xml"), " to access the service",
            T.invisible(render=T.directive("ifadmin"))[
                " -- ",
                T.a(href="http://voparis-validator.obspm.fr/validator.php?"
                    "spec=Simple+Spectral+Access+1.04&"
                    "format=XHTML&%sserviceURL=%s" %
                    (optStr,
                     urllib.quote(service.getURL("ssap.xml"))))["Validate"]]]
 def _meta_identifier(self):
     # Special case the authority
     if base.getMetaText(self, "resType") == "authority":
         localPart = ""
     else:
         localPart = "/%s/%s" % (self.rd.sourceId, self.id)
     return "ivo://%s%s" % (base.getConfig("ivoa", "authority"), localPart)
def _iterResourceMeta(ctx, dataSet):
	"""adds resource metadata to the Resource parent.
	"""
	yield V.DESCRIPTION[base.getMetaText(dataSet, "description", 
		macroPackage=dataSet.dd.rd, propagate=False)]
	for el in  itertools.chain(
			_iterInfoInfos(dataSet), _iterWarningInfos(dataSet)):
		yield el

	sourcesSeen, citeLinksSeen = set(), set()
	for table in dataSet.tables.values():
		for m in table.iterMeta("source", propagate="True"):
			src = m.getContent("text")
			if src not in sourcesSeen:
				yield V.INFO(name="source", value=src)[
					"This resource contains data associated with the publication"
					" %s."%src]
			sourcesSeen.add(src)

		for m in table.iterMeta("howtociteLink"):
			link = m.getContent("text")
			if link not in citeLinksSeen:
				yield V.INFO(name="howtocite", value=link)[
					"For advice on how to cite the resource(s)"
					" that contributed to this result, see %s"%link]
			citeLinksSeen.add(link)
 def _makeCapability(self, publication):
     return self.capabilityClass[
         VOR.description[base.getMetaText(publication,
                                          "description",
                                          propagate=False,
                                          macroPackage=publication.parent)],
         getInterfaceElement(publication)]
Beispiel #15
0
def formatFault(exc, service):
	if isinstance(exc, base.ValidationError):
		val = ZSI.Fault(ZSI.Fault.Client, unicodeXML(exc))
	else:
		val = ZSI.Fault(ZSI.Fault.Server, unicodeXML(exc))
	return val.AsSOAP(
		nsdict={"tns": base.getMetaText(service, "identifier")})
Beispiel #16
0
    def makePageTitle(cls, rd):
        """returns a suitable title for the rd info page.

		This is a class method to allow other renderers to generate
		titles for link anchors.
		"""
        return "Information on resource '%s'" % base.getMetaText(
            rd, "title", default="%s" % rd.sourceId)
 def _makeCapability(self, publication):
     service = publication.parent
     return CapabilityMaker._makeCapability(self, publication)[
         SLAP.complianceLevel[service.getMeta("slap.complianceLevel",
                                              default="full")], SSAP.
         dataSource[service.getMeta("slap.dataSource", raiseOnFail=True)],
         SSAP.testQuery[SSAP.queryDataCmd[base.getMetaText(
             service, "slap.testQuery", raiseOnFail=True)]], ]
def _makeResource(ctx, data):
	"""returns a Resource node for the rsc.Data instance data.
	"""
	res = V.RESOURCE()
	with ctx.activeContainer(res):
		res(type=base.getMetaText(data, "_type"),
				utype=base.getMetaText(data, "utype"))[
			_iterResourceMeta(ctx, data),
			_iterParams(ctx, data), [
				_makeVOTParam(ctx, param) for param in data.iterParams()],
			_linkBuilder.build(data.dd),
			]
		for table in data:
			with ctx.buildingFromTable(table):
				res[makeTable(ctx, table)]
		res[ctx.overflowElement]
	return res
Beispiel #19
0
 def _explain_scs_xml(cls, service):
     return T.invisible[
         "a standard SCS interface as defined by the"
         " IVOA to access catalog-type data; SCS clients"
         " use ",
         service.getURL("scs.xml"), " to access the service",
         T.invisible(render=T.directive("ifadmin"))
         [" -- ",
          T.a(href="http://nvo.ncsa.uiuc.edu/dalvalidate/"
              "ConeSearchValidater?endpoint=" +
              urllib.quote(service.getURL("scs.xml")) +
              "&RA=%s&DEC=%s&SR=%s&format=html&show=fail&show=warn&show=rec"
              "&op=Validate" %
              (base.getMetaText(service, "testQuery.ra", default="180"),
               base.getMetaText(service, "testQuery.dec", default="60"),
               base.getMetaText(service, "testQuery.sr", default="1"))
              )["Validate"]]]
Beispiel #20
0
def makeSOAPWSDLForService(service, queryMeta):
	"""returns an stanxml definitions element describing service.

	The definitions element also introduces a namespace named after the
	ivoa id of the service, accessible through the tns prefix.
	"""
	serviceId = base.getMetaText(service, "identifier")
	return WSDL.definitions(targetNamespace=serviceId,
			xmlns_tns=serviceId,
			name="%s_wsdl"%base.getMetaText(service, "shortName").replace(" ", "_"))[
		WSDL.import_,
		makeTypesForService(service, queryMeta),
		makeMessagesForService(service),
		makePortTypeForService(service),
		makeSOAPBindingForService(service),
		makeSOAPServiceForService(service),
	]
def getIdentifyElement(registryService):
	"""returns OAI Identify stanxml.

	registryService is the registry we're identifying, i.e. typically
	__system__/services#registry
	"""
	return OAI.Identify[
		OAI.repositoryName[base.getMetaText(registryService, "title")],
		OAI.baseURL[_getOAIURL(registryService)],
		OAI.protocolVersion["2.0"],
		OAI.adminEmail[base.getMetaText(registryService, "contact.email")],
		OAI.earliestDatestamp["1970-01-01T00:00:00Z"],
		OAI.deletedRecord["transient"],
		OAI.granularity["YYYY-MM-DDThh:mm:ssZ"],
		OAI.description[
			getVORMetadataElement(registryService),
		],
	]
    def declareServes(self, data):
        """adds meta to self and data indicating that data is served by
		service.

		This is used by table/@adql and the publish element on data.
		"""
        if data.registration:
            self.addMeta("serviceFor",
                         base.getMetaText(data, "title", default="Anonymous"),
                         ivoId=base.getMetaText(data, "identifier"))
            data.addMeta("servedBy",
                         base.getMetaText(self, "title"),
                         ivoId=base.getMetaText(self, "identifier"))

            # Since this is always initiated by the data, the dependency
            # must show up in its RD to be properly added on publication
            # and to be removed when the data is removed.
            data.rd.addDependency(self.rd, data.rd)
Beispiel #23
0
 def renderHTTP(self, ctx):
     # look for a matching publication in the parent service...
     for pub in self.service.publications:
         if pub.render == self.name:
             break
     else:  # no publication, 404
         raise svcs.UnknownURI(
             "No publication for an external service here.")
     raise svcs.WebRedirect(
         base.getMetaText(pub, "accessURL", macroPackage=self.service))
Beispiel #24
0
def makeSOAPServiceForService(service):
	"""returns stanxml for a WSDL service definition of the SOAP interface
	to service.
	"""
	shortName = base.getMetaText(service, "shortName")
	return WSDL.service(name=shortName)[
		WSDL.port(name="soap_%s"%shortName, binding="tns:soapBinding")[
			SOAP.address(location=service.getURL("soap")),
		]
	]
 def _makeCapability(self, publication):
     service = publication.parent
     return CapabilityMaker._makeCapability(self, publication)[
         SCS.maxSR[base.getMetaText(service, "maxSR", "180")],
         SCS.maxRecords[str(base.getConfig("ivoa", "dalDefaultLimit") *
                            10)], SCS.verbosity["true"],
         SCS.testQuery[
             SCS.ra[service.getMeta("testQuery.ra", raiseOnFail=True)],
             SCS.dec[service.getMeta("testQuery.dec", raiseOnFail=True)],
             SCS.sr[service.getMeta("testQuery.sr", default="0.001")], ], ]
def makeTable(ctx, table):
	"""returns a Table node for the table.Table instance table.
	"""
	sm = valuemappers.SerManager(table, mfRegistry=ctx.mfRegistry,
		idManager=ctx, acquireSamples=ctx.acquireSamples)

	# this must happen before FIELDs and such are serialised to ensure
	# referenced things have IDs.

	result = V.TABLE()
	with ctx.activeContainer(result):
		result(
				name=table.tableDef.id,
				utype=base.getMetaText(table, "utype", macroPackage=table.tableDef,
				propagate=False))[
			# _iterGroups must run before _iterFields and _iterParams since it
			# may need to add ids to the respective items.  XSD-correct ordering of 
			# the elements is done by xmlstan.
			V.DESCRIPTION[base.getMetaText(table, "description", 
				macroPackage=table.tableDef, propagate=False)],
			_iterGroups(ctx, table.tableDef, sm),
			_iterFields(ctx, sm),
			_iterTableParams(ctx, sm),
			_iterNotes(sm),
			_linkBuilder.build(table.tableDef),
			]

		if ctx.version>(1,1):
			result[_iterSTC(table.tableDef, sm)]

		if ctx.produceVODML:
			for ann in table.tableDef.annotations:
				try:
					result[ann.getVOT(ctx)]
				except Exception, msg:
					# never fail just because stupid DM annotation doesn't work out
					base.ui.notifyError("DM annotation failed: %s"%msg)

		return votable.DelayedTable(result,
			sm.getMappedTuples(),
			tableEncoders[ctx.tablecoding],
			overflowElement=ctx.overflowElement)
Beispiel #27
0
 def _writeErrorTable(self, ctx, msg, code=200, queryStatus="ERROR"):
     request = inevow.IRequest(ctx)
     request.setHeader("content-type", base.votableType)
     votable.write(
         V.VOTABLE11[
             V.DESCRIPTION[base.getMetaText(self.service, "description")],
             V.INFO(ID="Error",
                    name="Error",
                    value=str(msg).replace('"', '\\"'))], request)
     request.write("\n")
     return ""
Beispiel #28
0
 def _explain_siap_xml(cls, service):
     return T.invisible[
         "a standard SIAP interface as defined by the"
         " IVOA to access collections of celestial images; SIAP clients"
         " use ",
         service.getURL("siap.xml"), " to access the service",
         T.invisible(
             render=T.directive("ifadmin")
         )[" -- ",
           T.
           a(href=
             "http://nvo.ncsa.uiuc.edu/dalvalidate/SIAValidater?endpoint=" +
             urllib.quote(service.getURL("siap.xml")) +
             "&RA=%s&DEC=%s&RASIZE=%s&DECSIZE=%s&FORMAT=ALL&"
             "format=html&show=fail&show=warn&show=rec&op=Validate" %
             (base.getMetaText(service, "testQuery.pos.ra", default="180"),
              base.getMetaText(service, "testQuery.pos.dec", default="60"),
              base.getMetaText(service, "testQuery.size.ra", default="3"),
              base.getMetaText(service, "testQuery.size.dec", default="3"))
             )["Validate"]]]
def tapabort(querier, args):
    from gavo.protocols import tap

    tap.WORKER_SYSTEM.changeToPhase(
        args.jobId, uws.ERROR,
        "Job aborted by an administrator, probably because the query\n"
        " should be written differently to be less of a resource hog.\n"
        "  Here's what the administrator had to say:\n\n" + args.helpMsg +
        "\n\nIf you have further questions, just send a mail to " +
        base.getMetaText(
            base.caches.getRD("//tap").getById("run"), "contact.email"))
Beispiel #30
0
def _makeTableDoc(tableDef):
    content = RSTFragment()
    content.addHead1(tableDef.getQName())
    content.addNormalizedPara("Defined in %s" %
                              tableDef.rd.sourceId.replace("__system__", "/"))
    content.addNormalizedPara(
        base.getMetaText(tableDef, "description", default="UNDOCUMENTED"))
    content.makeSpace()
    for col in tableDef:
        content.addDLItem(col.name, "(%s) -- %s" % (col.type, col.description))
    content.makeSpace()
    return "".join(content.content)