建立及執行查詢

有時您需要收集特定的一組構件。您可能需要編譯一組失敗的測試,以包含在狀態報告中。查詢可以收集一組構件,並顯示結果讓您採取動作。

開始之前

查詢是用 SPARQL 查詢語言寫成。(SPARQL 是「已鏈結生命週期資料」的查詢語言。)因此,您必須知道 SPARQL 查詢語言,才能從頭開始建立查詢。

關於這項作業

下列步驟顯示如何建立和執行三項自訂查詢。每一個查詢都有加上註釋,因此您可以自訂它供自己使用。

程序

  1. 開啟「查詢」對話框。

    在主功能表中,按一下查詢 > 建立查詢

  2. 在「查詢」對話框中,輸入查詢的名稱。
  3. 輸入查詢的說明。

    當您將游標放在「我的查詢」或「共用查詢」畫面中的查詢時,會顯示說明。

  4. 將此查詢儲存在我的查詢資料夾中。

    每當您要建立查詢供自己或團隊使用時,請建立查詢,並將它儲存到我的查詢這個專用資料夾中。在測試並修訂查詢來收集您需要的構件之後,即可提供查詢作為共用。

  5. 取代或修改查詢程式碼範例來變更它。
    • 取代查詢程式碼範例。從以下範例區段中的三個範例,選擇一項查詢。複製查詢,並貼到欄位中。
    • 另外,也可以用您的自訂程式碼來修改預設 SPARQL 查詢程式碼範例。

      平台可以使用標準的編輯鍵。編輯 SPARQL 查詢時,可以輸入 Alt+/ 以取得內容輔助。

      如果您需要的字首與所顯示的不同,請按一下新增字首按鈕。

      如果您想要設定參數來建立查詢,以提示使用者輸入值,您可以現在或以後新增它。 參數識別您要搜尋的一組構件的性質。例如,您可以新增參數來搜尋自特定日期以來修改過的構件,或由特定使用者修改的構件。

      對查詢新增提示參數,可使查詢更有彈性,因為使用者在執行查詢時可指定參數值。 參數值會替換至查詢字串中,並自訂查詢結果。

      參數值通常使用類似 $workitem$ 的格式

      雖然您可以新增何種參數的完整語法很複雜,但一般格式包括:

      $name$

      $name.field$

      $name;format="formatString"$

      $name.field;format="formatString"$

      StringTemplate 是範本引擎,用來實作 SPARQL 查詢字串中的參數替代。Rational® Engineering Lifecycle Manager 不支援有空格的參數(即使 StringTemplate 支援)。

      StringTemplate 提要中檢視 StringTemplate 的一組簡化語法規則。您必須使用 $...$ 作為定界字元,而非提要中指定的 <...>

      如果您在查詢中使用一個以上的參數,請瞭解對參數化查詢進行疑難排解中的已知問題。

      如果要檢視日期、列舉和系統參數以及每個系統參數之範例輸出的表格,請參閱預先定義的查詢參數

      如果要進一步瞭解如何在「查詢」對話框中設定參數,則可以將游標移至 SPARQL 查詢參數區段右側的小問號,來閱讀浮動說明。

  6. 按一下建立,來建立查詢。
  7. 按一下執行,來執行查詢。
  8. 對「查詢結果」頁面中的構件採取動作。請按一下構件,然後按一下右側箭頭,以顯示功能表。
    • 開啟構件:啟動用來建立該構件的原生工具,並在該工具中顯示構件。
    • 顯示內容:在結果視窗中顯示構件的內容。
    • 開始分析:載入預設影響分析設定檔。請按一下執行,以開始分析。

    透過按一下右上方的下載為試算表圖示,將查詢下載為 .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
}

下一步


意見