Attach changeset(or URL) to a task

100 views
Skip to first unread message

Veselin Chiporikov

unread,
Aug 27, 2012, 6:13:44 AM8/27/12
to version...@googlegroups.com
Hi guys,

I am using the VersionOne.APIClient to fetch the status of a V1 story
or defect and if not closed to add a change set to it (a URL to svn
viewer). My question is, can I do the same - attach a changeset or a
URL(s) to a task (TK-34234 for ex.) ? How to check the task state -
open or closed?

/**
* Creates a changeset associated with the given story or defect.
*
*/
public final boolean createChangeSet(String[] arg) {

String oName = arg[0];
String oDate = arg[1];
String rev = arg[2];
String cMessage = arg[3];

String displayID = "D-1111" // for ex.

Object story;
Boolean exit = false;
try {
if (displayID.indexOf('D') == 0) {
story = getInstance().get().defectByDisplayID(displayID);
} else {
story = getInstance().get().storyByDisplayID(displayID);
}
ChangeSet cs = getInstance().create().changeSet("'" +
oName + "'" + " on '" + oDate + "'",
rev);

cs.getPrimaryWorkitems().add((PrimaryWorkitem) story);
cs.setDescription(cMessage);
cs.createLink("ChangeSet: " + revision,
getProperties().getProperty(V1Constants.LINK_URL) + revision, true);
cs.save();
} finally {
exit = true;
}

return exit;
}

Thanks for your help!
Vesko

ibuchanan

unread,
Aug 27, 2012, 9:56:37 AM8/27/12
to version...@googlegroups.com
Vesko,
 
Glad to hear you are making good use of the VersionOne Java SDK.
 
ChangeSets have a relationship to PrimaryWorkitems, which include only Stories and Defects, not Tasks and Tests (which are considered SecondaryWorkitems). You can find this out from a query to "meta" as so:
 
The above may make your question about Task state moot. But, just in case, you can query Task state the same way you can Stories or Defects. If you are having a problem with that, let me know a bit more of the details.
 
Yours truly,
Ian Buchanan
Product Manager for Platform and Integrations

Veselin Chiporikov

unread,
Aug 28, 2012, 2:19:34 AM8/28/12
to version...@googlegroups.com
Thanks Ian, I'll take a look into this.

Regards,
Vesko
> --
> You received this message because you are subscribed to the Google Groups
> "VersionOne-dev" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/versionone-dev/-/q0WDWquu8xYJ.
> To post to this group, send email to version...@googlegroups.com.
> To unsubscribe from this group, send email to
> versionone-de...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/versionone-dev?hl=en.

vesk...@gmail.com

unread,
Aug 28, 2012, 11:20:13 AM8/28/12
to version...@googlegroups.com
Hi again,

I was trying to use the same way for getting the status of a task, as I
use for story, e.g.

String number = "TK-111111" for ex.


BaseAssetFilter.State status;
IAssetType task;

task =
getInstance().getApiClient().getServices().getAssetType("Task");

Query query = new Query(task);
IAttributeDefinition numberAttribute =
task.getAttributeDefinition("Number");
query.getSelection().add(numberAttribute);
IAttributeDefinition assetStateAttribute =
task.getAttributeDefinition("AssetState");
query.getSelection().add(assetStateAttribute);
QueryFind qf = new QueryFind(number); // filter by task Number
query.setFind(qf);

QueryResult result = getServices().retrieve(query);
if (result.getAssets().length == 0) {
System.err.println("\nV1SvnAxway - No such: " + number);
}
Asset story = result.getAssets()[0]; // only one task with that
Number
Attribute defectStatus = story.getAttribute(assetStateAttribute);
if (defectStatus.getOriginalValue().equals(64)) {
status = BaseAssetFilter.State.Active;
} else {
status = BaseAssetFilter.State.Closed;
}

However, defectStatus.getOriginalValue() always returns 128 no matter if
the task is in progress or closed. Please advise.

Thanks a lot,
Vesko

ibuchanan

unread,
Aug 28, 2012, 7:05:14 PM8/28/12
to version...@googlegroups.com
Vesko,

I think the problem is in the QueryFind. QueryFind is for conducing search operations. For example, if you wanted to find the word "Urgent" from a title like "Update Urgent Records". This is not the same as when you use the Search feature in the UI, which will search across a number of fields, not just one. I would have to stare at the SDK source code a bit longer to remember what happens when you don't specify which attribute you want to search so I'm not entirely sure what your code finds. I suspect it's just not the task you expect (hence, the AssetState is always the same).

Since you have the exact task number you want to match, you should just use a simple filter:

FilterTerm term = new FilterTerm(numberAttribute);
term.Equal(number);
query.Filter = term;

Unrelated, you should probably just use getValue() instead of getOriginalValue(). In your code, they will always evaluate to the same thing but getValue() removes the potentially confusing change detection triggers.

Also, you probably want to use the AssetState enumeration instead of BaseAssetFilter. Since it already encodes the possible AssetState values, it will save you from doing the extra if statement.

Hope that helps,
Ian

vesk...@gmail.com

unread,
Aug 29, 2012, 10:32:26 AM8/29/12
to version...@googlegroups.com
Ian,

Your advices helped me a lot! Thank you very much for your time!

Regards,
Vesko
             System.err.println("\nNo such: " + number);
To view this discussion on the web visit https://groups.google.com/d/msg/versionone-dev/-/-kSz1luiWWIJ.
Reply all
Reply to author
Forward
0 new messages