사용자 정의 정책에서 사용할 API

사용자 정의 정책을 작성할 때 여러 API에서 다음을 사용할 수 있습니다. 사용하는 API는 작업하는 자산과 이러한 자산으로 수행할 작업에 따라 다릅니다. 예를 들어, 자산을 작성한 API가 아닌 다른 API를 사용하여 정책을 실행 중인 자산을 업데이트할 수 있습니다.

현재 자산에 대해 사용할 API

Java 클라이언트 API를 사용하여 정책을 작성할 수 있습니다.

정책을 실행 중인 자산에 대한 업데이트만 작성 중인 경우, 정책 컨텍스트 메소드를 사용하여 세션을 작성하고 자산을 가져올 수 있습니다. RAMSession을 작성하고 현재 RAMAsset를 검색하려면 다음 API를 사용하십시오.
RAMSession ramSession = getPolicyContext().getRAMSession();
RAMAsset ramAsset = getPolicyContext().getRAMAsset();

여러 Rational® Asset Manager Java™ API 클래스를 사용하여 현재 자산을 업데이트할 수 있습니다. 예를 들어, 관계를 추가하거나 조치를 설정할 수 있습니다. 또한 API 클래스를 사용하여 자산, 자산 속성, 아티팩트에 대해 작업할 수 있습니다.

또한 Java API를 사용하여 정책을 실행 중인 자산 옆에 자산을 작성하거나 변경할 수도 있습니다. ram.client API를 사용하는 경우, 최고의 성능을 위해 자산 업데이트를 단일 세션으로 제한하십시오.

사용자 정의 정책 코드에서 다음 단계를 수행하십시오.
  1. getRAMSession 메소드를 사용하여 세션을 작성하십시오. 이러한 세션에 대해 라이센스가 이용되지 않습니다.
  2. getRAMAsset 메소드로 자산을 가져오십시오.
  3. RAMSession 및 RAMAsset API를 사용하여 자산 오퍼레이션을 수행하십시오.
  4. session.putAssets 메소드를 사용하여 변경사항을 하나의 트랜잭션으로 커미트하십시오.
예를 들어, 다음과 같습니다.
RAMSession session = getPolicyContext().getRAMSession();  
RAMAsset currentAsset = this.getPolicyContext().getRAMAsset();  
  
// Use the client APIs to make changes to the asset ...

// You can also modify or create other assets:
			RAMAsset asset = session.createAsset("1.0");
			asset.setName("Test Asset");
			asset.setCommunity(session.getCommunity("Sample Application Development"));
			asset.setAssetType(session.getAssetType("Business Solution"));
			asset.setShortDescription("Test asset");
			asset.setOwners(new RAMUser[] { session.getUser("admin") });
		 	
// Commit changes to the asset repository for the current asset:
			session.putAsset(currentAsset);  

// You can use queueAssetForPut and then putAssets to queue and then 
// commit all assets you have changed in the session as one transaction:
			session.queueAssetForPut(currentAsset);  

// Commit changes to all assets you have changed in the session:
			session.putAssets(new NullProgressMonitor());  	

Java 클라이언트 API에 대해서는 클라이언트 패키지공통 데이터 패키지를 참조하십시오.

추가 예제에 대해서는 이 주제의 예제 섹션과 Rational Asset Manager Java API 사용을 참조하십시오.

  • 자산 가져오기:
    RAMAsset myAsset = getPolicyContext().getRAMAsset();
  • 자산 속성 가져오기 예제:
    AssetAttribute myAttribute = myAsset.getAssetAttribute("Family Name");
    String[] myAttrValue = myAttribute.getValues();
    
    myAttribute = myAsset.getAssetAttribute("Work Item");
    myAttrValue = myAttribute.getValues();
    
    myAttribute = myAsset.getAssetAttribute("Requirement");
    myAttrValue = myAttribute.getValues();
  • 자산을 검색하는 조회 작성:
    SearchQuery query = session.createAssetQuery(queryParam);
    int offset = 0;
    int maxResults = 100;
    query.setResultsStartIndex(offset);
    query.setMaxResults(maxResults);
    		 		 SearchResult result = session.getAssets(query);
  • 자산 작성:
    RAMAsset newAsset = session.createAsset("1.0");
    newAsset.setName("The new related asset");
    newAsset.setCommunity(session.getCommunity("Rational Asset Manager Development"));
    newAsset.setAssetType(session.getAssetType("Specification"));
    newAsset.setShortDescription("The Specification asset is required.");
  • 새 자산의 AssetID 작성:
    AssetID id = new AssetID();
    id.setGUID(newAsset.getId());
    id.setVersion(newAsset.getVersion());
  • 조회 작성, 결과 세트 확인, 자산 수정:
    public Result test() {		try {
    			// Create a query 
    			String queryParam = null; 
       	RAMSession session = getPolicyContext().getRAMSession();
        SearchQuery query = session.createAssetQuery(queryParam);
    			int offset = 0;
    			int maxResults = 100;
    			query.setResultsStartIndex(offset);
    			query.setMaxResults(maxResults);
    		 		 SearchResult result = session.getAssets(query);
    			 
    			if (result != null && result.getAssetSearchResults() != null) {
    				AssetSearchResult[] assets = result.getAssetSearchResults();
    	
    				for (AssetSearchResult asset : assets) {
    					AssetInformation assetInformation = asset.getAsset();
    				// Modify an asset here, for example,
    				// create a "DependsOn" relationship from Release and Implementation type assets to a Specification asset of the same name using the client APIs, like this:
    				// Relationship theRelationships = session.getRelationships
    				// getRelationships().add(newItem);
    				}
    			}
    		}
     
    		// Catch exceptions...
    				Result result = new Result();
    		result.setMessage("Success");
    		return result;
    		 
    	}
  • 자산 아티팩트 정보를 검색하고 아티팩트를 다운로드하기 위해 Rational Asset Manager Java API를 사용하여 폴더 위치 가져오기:
     		// Get the asset
    		RAMAsset ramAsset = getRAMAsset(); 
                
    		 		// Get the location and content of the artifacts
    		RAMFolderArtifact srcFolderArtifact = (RAMFolderArtifact)ramAsset.getArtifactsRoot();
    		Artifact[] srcArtifacts = srcFolderArtifact.computeArtifactsAsFlatList(new NullProgressMonitor());
    		 
    		for (Artifact artifact : srcArtifacts) {
            RAMArtifact ramArtifact = (RAMArtifact) artifact;
    					InputStream is = ramArtifact.downloadContents();
    					f = File.createTempFile("theArtifact", null, new File(ramSession.getLocalStorageLocation()));
    					UtilitiesCommon.copyStreams(is, new FileOutputStream(f), null, true, true);
             }

피드백