You can create policies by using the Java client APIs.
RAMSession ramSession = getPolicyContext().getRAMSession(); RAMAsset ramAsset = getPolicyContext().getRAMAsset();
You can use several of the Rational® Asset Manager Java API classes to update the current asset. For example, you might add a relationship or set an action. You can also use the API classes to work with assets, asset attributes, and artifacts.
You can also use the Java APIs to change or create assets besides the one that the policy is running on. You must include the Java client JAR files and use a RAMSession(). For best performance when using ram.client APIs, limit asset updates to a single session.
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());
For the Java client APIs, see: client package and common data package.
See the Example section in this topic and Using Rational Asset Manager Java API for additional examples.
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);
}