Label Query Question

Post your questions regarding using the Vault and Fortress API in your programs.

Moderator: SourceGear

Post Reply
slmcmahon
Posts: 29
Joined: Sat Mar 29, 2008 6:13 pm
Location: Honolulu, HI
Contact:

Label Query Question

Post by slmcmahon » Tue Apr 15, 2008 5:24 pm

I"m trying to a query for all items with a label of READY_FOR_TEST with the following code:

Code: Select all

ServerOperations.client.LoginOptions.URL = "http://myserver/VaultService";
ServerOperations.client.LoginOptions.User = "admin";
ServerOperations.client.LoginOptions.Password = "password";
ServerOperations.client.LoginOptions.Repository = "Main";
ServerOperations.client.AutoCommit = true;
ServerOperations.client.Verbose = true;
ServerOperations.client.LoginOptions.AccessLevel = VaultConnection.AccessLevelType.Admin;
ServerOperations.Login();

long objId = RepositoryUtil.FindVaultTreeObjectAtReposOrLocalPath("$").ID;
string qryToken;
long rowsRetMain;
long rowsRetRecur;

ServerOperations.client.ClientInstance.BeginLabelQuery(
    "$", 
    objId, 
    true, // get recursive
    true, // get inherited
    true, // get file items
    true, // get folder items
    1000,
    out rowsRetMain, 
    out rowsRetRecur, 
    out qryToken);
VaultLabelItemX[] labelItems;
ServerOperations.client.ClientInstance.GetLabelQueryItems_Recursive(
    qryToken, 0, (int) rowsRetMain, out labelItems);

if (labelItems == null)
    return;

foreach(VaultLabelItemX item in labelItems)
{
    if (item.Name.Equals("READY_FOR_TEST"))
    {
        Console.WriteLine(item.CurrentPath);
    }
}
[TEST 1]
First I test a scenario where that label doesn't exist and it finds a single entry for the one label that I do have CHECKED_IN which is assigned at $

[TEST 2]
Then I choose a single source file entry and apply the READY_FOR_TEST label to it and I run it again and it finds 2 entries. One is the folder level CHECKED_IN label and the other is the single file that I labeled.

[TEST 3]
Then I choose a folder above the single file and assign the READY_FOR_TEST label to that. This time when I run it, I get 2 entries. one is for the folder level READY_FOR_TEST and the other is for the file entry for the same label. What happened to the CHECKED_IN label? I know that I'm not looking for it but it doesn't seem consistent.

[TEST 4]
For one more test, I select several individual files and label them with READY_FOR_TEST and run my code again. This time, I get exactly the same results as TEST 3.

Can you see anything in my code that is just wrong? What I'd like to do is see the same results that I'd see in the desktop client if I right click on "$" and choose "Show Labels" with "Files and Folders" selected "Act recursively" checked. How would I do that in code?

I'd really appreciate help with this one!

Stephen

shannon

Post by shannon » Wed Apr 16, 2008 8:03 am

When you say it doesn't find CHECKED_IN for tests 3 and 4, do you mean that your code doesn't print those out or that the label query isn't returning items with that label?

slmcmahon
Posts: 29
Joined: Sat Mar 29, 2008 6:13 pm
Location: Honolulu, HI
Contact:

Post by slmcmahon » Wed Apr 16, 2008 8:12 am

shannon wrote:When you say it doesn't find CHECKED_IN for tests 3 and 4, do you mean that your code doesn't print those out or that the label query isn't returning items with that label?
The label query actually doesn't return the items. I have a break point on the loop initializer and can see in the locals window that LabelItems contains only two elements and they are both for the READY_FOR_TEST label.

shannon

Post by shannon » Wed Apr 16, 2008 8:48 am

You're passing in rowsRetMain instead of rowsRetRecur to GetLabelQueryItems_Recursive.

slmcmahon
Posts: 29
Joined: Sat Mar 29, 2008 6:13 pm
Location: Honolulu, HI
Contact:

Post by slmcmahon » Wed Apr 16, 2008 9:12 am

shannon wrote:You're passing in rowsRetMain instead of rowsRetRecur to GetLabelQueryItems_Recursive.
Well that certainly fixed it. I appreciate the help!

shannon

Post by shannon » Wed Apr 16, 2008 9:20 am

No trouble at all. Glad it's working properly now.

slmcmahon
Posts: 29
Joined: Sat Mar 29, 2008 6:13 pm
Location: Honolulu, HI
Contact:

Post by slmcmahon » Fri Apr 18, 2008 10:10 am

shannon wrote:No trouble at all. Glad it's working properly now.
Before I go off and reinvent the wheel out of ignorance, I just thought I'd ask here first. How difficult would it be to retrieve the listing of items that inherit from a label? The code that I posted here before that you helped me with will return the folder as well as the files. But what if I wanted to just pay attention to the folder if it exists and list all of the files that inherit that label? Is there a way to do that that doesn't involve getting the label first and then going back and recursively getting all of the files under that folder?

Stephen

shannon

Post by shannon » Fri Apr 18, 2008 12:34 pm

I'm not sure I understand what you're wanting to do exactly. Can you give me more details?

slmcmahon
Posts: 29
Joined: Sat Mar 29, 2008 6:13 pm
Location: Honolulu, HI
Contact:

Post by slmcmahon » Fri Apr 18, 2008 1:09 pm

shannon wrote:I'm not sure I understand what you're wanting to do exactly. Can you give me more details?
What I'm trying to do is a query by label that returns all of the files associated with that label regardless if they are associated by inheritance or by being directly labeled. Basically I want to get the exact results that you would get if you opened the desktop client, selected the root of the tree "$" and chose "View-->Show Labels" and then flipped over to the "Recursive Labels" tab. If I got this list, then I can filter it by the label that I'm looking for.

Stephen

slmcmahon
Posts: 29
Joined: Sat Mar 29, 2008 6:13 pm
Location: Honolulu, HI
Contact:

Post by slmcmahon » Fri Apr 18, 2008 1:16 pm

Actually what I just said is not absolutely correct. What I want to do is list all of the files. I guess I'm already able to do that with the code that you helped me with before. I was hoping to get all of the files listed, not just the directory.

Stephen

shannon

Post by shannon » Fri Apr 18, 2008 1:17 pm

The code you have is basically the way we get that list. We you hoping for a way to get a different type of object back or something else?

shannon

Post by shannon » Fri Apr 18, 2008 1:34 pm

If you're looking for the contents of a label, you might want to take a look at the ClientInstance.GetLabelStructureByID method. That's where we get the information (folder tree and file lists) for the label promotion dialog.

slmcmahon
Posts: 29
Joined: Sat Mar 29, 2008 6:13 pm
Location: Honolulu, HI
Contact:

Post by slmcmahon » Fri Apr 18, 2008 1:44 pm

shannon wrote:If you're looking for the contents of a label, you might want to take a look at the ClientInstance.GetLabelStructureByID method. That's where we get the information (folder tree and file lists) for the label promotion dialog.
Thanks again. I'll go take a look at that now.

shannon

Post by shannon » Fri Apr 18, 2008 2:25 pm

There are also two operations in GetOperations that will perform a get on a label, ProcessCommandGetLabelToTempWorkingFolder and ProcessCommandGetLabelToLocationOutsideWorkingFolder, if that's at all useful.

slmcmahon
Posts: 29
Joined: Sat Mar 29, 2008 6:13 pm
Location: Honolulu, HI
Contact:

Post by slmcmahon » Fri Apr 18, 2008 2:47 pm

shannon wrote:There are also two operations in GetOperations that will perform a get on a label, ProcessCommandGetLabelToTempWorkingFolder and ProcessCommandGetLabelToLocationOutsideWorkingFolder, if that's at all useful.
I don't need to actually get them yet in this code.

Actually I'm finding that the value stored in the VaultRepositoryDelta object after the call to GetLabelStructureByID on a path (not a file) may be just what I need.

The end goal is to be able to provide a query by label for my management to selectively deploy files to a server. They want to be able to specify a label and be able to see all of the files associated with that label with a checkbox that they can select and click a "deploy" button on some or all of them. So if a developer labels a file with READY_FOR_PROD then the manager can query for all files with that label and click a button and they will be written to the production server -- this will end up being the end of the work flow for getting a change deployed to our production server for web applications.

I have no problem getting the files out of the system once they have been identified. Programmatic query by label is the only thing that I'm stumped with. Most everything else is pretty easy to discover because of the availability of your source for the command line client.

My management is very impressed by the Fortress demo that I gave them and have told me that if I can provide these extended interfaces then they are going to purchase it to replace our current installation of Dimensions (or Dimentia, as we like to call it :lol:)

Post Reply