Wenn Sie angepasste Richtlinien schreiben, können Sie verschiedene APIs verwenden. Die APIs, die Sie verwenden können, sind von den Assets abhängig, mit denen Sie arbeiten, und auch davon, für welchen Verwendungszweck Sie die Assets nutzen wollen. Sie verwenden z. B. unterschiedliche APIs, um das Asset zu aktualisieren, unter dem eine Richtlinie ausgeführt wird, und um ein Asset zu erstellen.
Richtlinien können mit den Java-Client-APIs erstellt werden.
RAMSession ramSession = getPolicyContext().getRAMSession();
RAMAsset ramAsset = getPolicyContext().getRAMAsset();
Sie können verschiedene der Java™-API-Klassen von Rational Asset Manager verwenden, um das aktuelle Asset zu aktualisieren. Sie können beispielsweise eine Beziehung hinzufügen oder eine Aktion definieren. Sie können außerdem die API-Klassen verwenden, um mit Assets, Assetattributen und Artefakten zu arbeiten.
Sie können die Java-APIs auch zum Ändern oder Erstellen von Assets zusätzlich zu dem Asset verwenden, auf dessen Basis die Richtlinie ausgeführt wird. Die optimale Leistung wird bei Verwendung der ram.client-APIs erzielt, wenn Sie die Assetaktualisierungen auf eine einzige Sitzung beschränken.
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());
Informationen zu den Java-Client-APIs finden Sie unter Clientpaket und unter Allgemeines Datenpaket.
Weitere Beispiele finden Sie unter 'Beispiele' in diesem Abschnitt und unter Rational Asset Manager-Java-APIs verwenden.
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 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;
}
// 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);
}