Page 1 of 1
Item promotion using API
Posted: Thu Mar 27, 2008 7:01 am
by Igor.Samoylenko
Hi,
Can you give me a code sample on how to promote an item in a label via API please?
Regards,
Igor.
Posted: Thu Mar 27, 2008 10:40 am
by shannon
This example assumes you have the label name and path, the paths of the items you want to alter, and the desired version number (if you're trying to change a version). You can skip the parts that find the various version ids, etc if you have gotten that info some other way.
Let me know if anything is unclear.
Code: Select all
string url = "http://VaultServer/VaultService";
string username = "user";
string password = "password";
string repository = "Your Repository";
// Set the login options and login/connect to a repository.
ServerOperations.client.LoginOptions.URL = url;
ServerOperations.client.LoginOptions.User = username;
ServerOperations.client.LoginOptions.Password = password;
ServerOperations.client.LoginOptions.Repository = repository;
ServerOperations.Login();
string labelName = "label1";
string labelPath = "$/SomeJavaProject";
// get the objID for the label
long objID = RepositoryUtil.FindVaultTreeObjectAtReposOrLocalPath(labelPath).ID;
string qryToken;
long rowsRetMain;
long rowsRetRecur;
long maxRows = 200;
ServerOperations.client.ClientInstance.BeginLabelQuery(labelPath, objID, false, false, false, false, maxRows, out rowsRetMain, out rowsRetRecur, out qryToken);
VaultLabelItemX[] labelItems;
ServerOperations.client.ClientInstance.GetLabelQueryItems_Main(qryToken, 0, (int) rowsRetMain, out labelItems);
long labelID = 0;
VaultDateTime lastChanged = new VaultDateTime();
// find the right label to get the id
foreach (VaultLabelItemX item in labelItems)
{
if (item.Name.Equals(labelName))
{
labelID = item.LabelID;
lastChanged = item.LastChange;
}
}
VaultClientFile file = RepositoryUtil.FindVaultFileAtReposOrLocalPath("$/SomeJavaProject/a/SomeClass.java");
VaultObjectVersionInfo[] versions = null;
ServerOperations.client.ClientInstance.GetObjectVersionList(file.ID, ref versions, false);
long objVerID = 0;
foreach (VaultObjectVersionInfo v in versions)
{
if (v.Version == 4)
objVerID = v.ObjVerID;
}
VaultLabelPromotionItem pItemChangeVersion = new VaultLabelPromotionItem("SomeJavaProject/a/SomeClass.java", file.ID, 4, objVerID, VaultLabelPromotionChangeType.Modify);
file = RepositoryUtil.FindVaultFileAtReposOrLocalPath("$/SomeJavaProject/b/.project");
VaultLabelPromotionItem pItemAdd = new VaultLabelPromotionItem("SomeJavaProject/b/.project", file.ID, file.Version, file.ObjVerID, VaultLabelPromotionChangeType.Add);
file = RepositoryUtil.FindVaultFileAtReposOrLocalPath("$/SomeJavaProject/a/AnotherClass.java");
VaultLabelPromotionItem pItemDelete = new VaultLabelPromotionItem("SomeJavaProject/a/AnotherClass.java", file.ID, file.Version, file.ObjVerID, VaultLabelPromotionChangeType.Delete);
VaultLabelPromotionItem[] promotionItems = new VaultLabelPromotionItem[] { pItemChangeVersion, pItemAdd, pItemDelete };
int indexFailed;
string rootPathConfl;
int ret = ServerOperations.client.ClientInstance.PromoteLabelItems(labelPath, labelID, labelName, ref lastChanged, promotionItems, out indexFailed, out rootPathConfl);