创建和运行查询

有时,需要收集特定的工件集。 您可能要编译一组失败的测试以包括在状态报告中。查询可以收集一组工件并显示结果以供您执行操作。

开始之前

查询以 SPARQL 查询语言编写。(SPARQL 是用于关联生命周期数据的查询语言。)因此,您必须了解 SPARQL 查询语言才能从头开始创建查询。

关于此任务

下列步骤显示了如何创建和运行 3 个定制查询。对每个查询都添加了注释,以便您可以对其进行定制以供您使用。

过程

  1. 打开“查询”对话框。

    在主菜单中,选择查询 > 创建查询

  2. 在“查询”对话框中,输入查询的名称。
  3. 输入查询的描述。

    当您将光标悬浮在“我的查询”或“共享查询”屏幕中的查询上方时,将显示该描述。

  4. 将此查询保存在我的查询文件夹中。

    每当创建查询以供您自己或团队使用时,请创建该查询并将其保存到专用文件夹我的查询。测试并优化查询以收集您需要的工件之后,您可以共享该查询。

  5. 通过替换或修改样本查询代码来更改此代码。
    • 替换样本查询代码。从下面的示例部分中的 3 个示例中选择一个查询。复制该查询并将其粘贴到该字段中。
    • 此外,使用您的定制代码来修改缺省样本 SPARQL 查询代码。

      标准编辑键适用于您的平台。 编辑 SPARQL 查询时,可以按 Control+空格键以获得内容帮助。

      在 V4.0.4 和更低版本中,查询代码呈黑色显示,没有内容帮助。

      如果您需要与所显示的前缀不同的前缀,请单击添加前缀按钮。

      如果您想要设置参数以创建一个将提示用户输入值的查询,那么您可以立即添加此参数,或者稍后添加此参数。参数用于标识您要搜索的一组工件的特征。例如,您可以添加参数以搜索自从某一日期以来已修改的工件或者某一用户已修改的工件。

      对查询添加提示参数可使该查询更灵活,这是因为用户可以在运行该查询时指定参数值。会将参数值替换到查询字符串中,并定制查询结果。

      通常,参数值使用 $workitem$ 之类的格式

      尽管您可以作为参数来添加的完整语法可能会很复杂,但是典型格式包括:

      $name$

      $name.field$

      $name;format="formatString"$

      $name.field;format="formatString"$

      StringTemplate 是用来在 SPARQL 查询字符串中实现参数替换的模板引擎。Rational® Engineering Lifecycle Manager 不支持参数中包含空格,尽管 StringTemplate 支持这种情况。

      请在以下位置查看 StringTemplate 的一组简化后的语法规则:StringTemplate cheat sheet。必须使用 $...$(而不是使用 <...>)作为定界符,这在备忘单中进行指定。

      要了解有关在“查询”对话框中设置参数的更多信息,请通过将光标悬浮在 SPARQL 查询参数部分右侧的小问号上以阅读悬浮式帮助。

  6. 通过单击创建来创建查询。
  7. 通过单击运行来运行查询。
  8. 对“查询结果”页面中的工件执行操作。 单击工件,然后单击右侧的箭头以显示菜单。
    • 打开工件将启动在其中创建该工件的本机工具并在该工具中显示该工件。
    • 显示属性将在结果窗口中显示工件的属性。
    • 开始分析将装入缺省影响分析概要文件。单击运行以开始分析。

    在 V4.0.6 和更高版本中,可通过单击右上方的下载为电子表格图标来将查询下载为 .csv 电子表格。

示例

以下示例显示了如何查询指定给 Susan 的所有已打开的工程变更请求。

指定给 Susan 的已打开的 ECR

# Name: Open ECRs assigned to Susan
# Description: Show all open ECRs assigned to Susan

# Prefixes used in this query
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX oslc_cm: <http://open-services.net/ns/cm#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?cr ?title ?contrib
WHERE
{
	# Find all ECRs - in this example, we find work items of type "Task"; change this to the type of work item you use
	?cr rdf:type oslc_cm:ChangeRequest ;
		dcterms:type "Task"^^xsd:string ;
		dcterms:title ?title ;
		dcterms:contributor ?contrib .

	# Change the name string to match the user name you want
	FILTER regex(str(?contrib),"susan")

	# Find open CRs (those with status that is none of closed, fixed, or verified)
	# You can adjust this to use any combination of the OSLC CM state predicates
	# oslc_cm:closed, oslc_cm:inprogress, oslc_cm:fixed, oslc_cm:approved, oslc_cm:reviewed, and oslc_cm:verified
	{
		?cr oslc_cm:closed "false"^^xsd:boolean ;
			oslc_cm:fixed "false"^^xsd:boolean .
	}
	# for example, the following alternative to the above clause would find CRs that are either in progress or not closed:
	# {
	#	{ ?cr oslc_cm:inprogress "true"^^xsd:boolean } UNION { ?cr oslc_cm:closed "false"^^xsd:boolean }
	# }
}

以下示例显示了如何查询失败的测试用例以及指定给我自己的测试用例。

失败的测试

# Name: Failing tests
# Descriptions: Testcases that fail and are assigned to me

# Prefixes used in this query
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX oslc_qm: <http://open-services.net/ns/qm#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?testcase ?title
WHERE
{
	# Find failing test results, and their owning testcase
	?testResult rdf:type oslc_qm:TestResult ;
		oslc_qm:status "com.ibm.rqm.execution.common.state.failed"^^xsd:string ;
		oslc_qm:reportsOnTestCase ?testcase .

	# Select just the testcases assigned to me
	# Change the name string to match the user name you want
	?testcase dcterms:contributor ?user.
	FILTER regex(str(?user), "tony")

	# Find the matching testcase titles
	?testcase dcterms:title ?title .
}

以下示例显示了如何查询受变更请求的更改影响的工件。

受 CR 的更改影响的工件

# Description: Find artifacts impacted by a change to a Change Request
# Follows links such as CR->tracks->REQ->[elaboratedBy->REQ | specifiedBy->REQ]->[verifiedBy->TC | elaboratedBy->ME]

# Prefixes used in this query
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX oslc_cm: <http://open-services.net/ns/cm#>
PREFIX oslc_rm: <http://open-services.net/ns/rm#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?cr ?type ?title ?owner
WHERE
{
	?cr a oslc_cm:ChangeRequest ;
		dcterms:identifier ?id ;
		(oslc_cm:tracksRequirement|oslc_rm:trackedBy|oslc_rm:elaboratedBy|oslc_rm:specifiedBy|oslc_rm:validatedBy)* ?uri .
	?uri dcterms:title ?title
	OPTIONAL
	{
		?uri rdf:type/rdfs:label ?type ;
	}
	OPTIONAL
	{
		# This part of the query picks up user names from either JTS user URIs or from DOORS FOAF entries,
		# and avoids getting the DOORS user URI as well as that FOAF entry
		{
			?uri dcterms:contributor/foaf:name ?owner
		}
		UNION
		{
			?uri dcterms:contributor ?owner
			FILTER NOT EXISTS { ?owner foaf:name ?x }
		}
	}
}

# Either provide one or more work item ID numbers here,
# or remove or comment out the entire VALUES section to look at all work items
VALUES ?id
{
	"626"^^xsd:string
	"627"^^xsd:string
}

下一步做什么


反馈