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. Sie müssen die JAR-Dateien des Java-Clients einbinden und dann RAMSession() verwenden. 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());
import com.ibm.ram.common.* import com.ibm.ram.client.*
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.
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;
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);
}