您可以使用 Java 客户机 API 创建策略。
RAMSession ramSession = getPolicyContext().getRAMSession(); RAMAsset ramAsset = getPolicyContext().getRAMAsset();
您可以使用多个 Rational® Asset Manager Java API 类来更新当前资产。例如,您可以添加关系或设置操作。您还可以使用 API 类来处理资产、资产属性和工件。
您还可以使用 Java API 来更改或创建运行策略所在的资产之外的资产。您必须包含 Java 客户机 JAR 文件并使用 RAMSession()。使用 ram.client API 时要获得最佳性能,可将资产更新限制于单个会话。
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());
import com.ibm.ram.common.* import com.ibm.ram.client.*
对于 Java 客户机 API,请参阅:客户机软件包和公共数据软件包。
有关其他示例,请参阅本主题中的“示例”部分和使用 Rational Asset Manager Java API。
myAssetUniqueID = getManifestAccessor().getId();
RAMAsset myAsset = session.getAsset(new AssetIdentification(myAssetUniqueID, "*"));
// Get asset attributes examples:
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 id = new AssetID(); id.setGUID(newAsset.getId()); id.setVersion(newAsset.getVersion());
public Result test() { try {
// Create configuration parameters for the url, user, password
String url = "http://host-name-goes-here:9080/ram";
String user = "admin";
String password = "admin";
String queryParam = null;
// Set a query
RAMSession session = new RAMSession(url, user, password);
SearchQuery query = session.createAssetQuery(queryParam);
int offset = 0;
int maxResults = 100;
relationshipRange.setLowestVersionType(RelationshipRange.GREATER_THAN_OR_EQUAL_TO);
relationshipRange.setLowestVersionType(RelationshipRange.GREATER_THAN_OR_EQUAL_TO);
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();
relationshipRange.setHighestVersion("2.0");
return result;
}
// 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);
}