List of Artifacts
3 answers
Hi,
how do I get a list of artifacts names from a given asset using RAM Client API?
Any sample code?
Thx
Here are two ways....
1) Convert the artifacts to a flat list and iterate over that....
RAMFolderArtifact root = (RAMFolderArtifact)asset.getArtifactsRoot();
Artifact[] artifacts = root.computeArtifactsAsFlatList(new RAMStatusMonitor());
for(Artifact artifact : artifacts){
String name = artifact.getName();
//Do something with the name
}
2) Recurse over the artifact tree...
FolderArtifact root = asset.getArtifactsRoot();
List<String> names = new ArrayList<String>();
collectArtifactNames(root, names);
private void collectArtifactNames(FolderArtifact folder, List<String> names){
for(Artifact artifact : folder.getChildren()){
if(artifact instanceof FolderArtifact){
collectArtifactNames((FolderArtifact)artifact, names);
}
else{
names.add(artifact.getName());
}
}
}