How to access project name from a query of type portfolioitem - rally

I am trying to match Project name in my query and also trying to print the name of the project associated with each feature record. I know there are plenty of answers but I couldn't find anything that could help me. I am trying to do something like this:
pi_query.type = "portfolioitem"
pi_query.fetch="Name,FormattedID,Owner,c_ScopingTeam,c_AspirationalRelease,c_AssignedProgram,Tags"
#To be configured as per requirement
pi_query.project_scope_up = false
pi_query.project_scope_down = false
pi_query.order = "FormattedID Asc"
pi_query.query_string = "(Project.Name = \"Uni - Serviceability\")"
pi_results = #rally.find(pi_query)
I am trying to match the project name but it simply doesn't work, I also tried printing the name of the project, i tried Project.Name, Project.Values or simply Project. But it doesn't work. I am guessing it is because of my query type which is "portfolioItem" and I can't change my type because I am getting all other attribute values correctly.
Thanks.

Make sure to fetch Project, e.g: feature_query.fetch = "Name,FormattedID,Project"
and this should work:
feature_query.query_string = "(Project.Name = \"My Project\")"
Here is an example where a feature is found by project name.
require 'rally_api'
#Setup custom app information
headers = RallyAPI::CustomHttpHeader.new()
headers.name = "create story in one project, add it to a feature from another project"
headers.vendor = "Nick M RallyLab"
headers.version = "1.0"
# Connection to Rally
config = {:base_url => "https://rally1.rallydev.com/slm"}
config[:username] = "user#co.com"
config[:password] = "secret"
config[:workspace] = "W"
config[:project] = "Product1"
config[:headers] = headers #from RallyAPI::CustomHttpHeader.new()
#rally = RallyAPI::RallyRestJson.new(config)
obj = {}
obj["Name"] = "new story xyz123"
new_s = #rally.create("hierarchicalrequirement", obj)
query = RallyAPI::RallyQuery.new()
query.type = "portfolioitem"
query.fetch = "Name,FormattedID,Project"
query.workspace = {"_ref" => "https://rally1.rallydev.com/slm/webservice/v2.0/workspace/12352608129" }
query.query_string = "(Project.Name = \"Team Group 1\")"
result = #rally.find(query)
feature = result.first
puts feature
field_updates={"PortfolioItem" => feature}
new_s.update(field_updates)

Related

Slashes in Rally Query

I have a Feature name such as: "This / is / the / name / of my feature ". Rally throws me an error when I try to mention this name as a query string. Is there a way to get around this?
Where do you get the error? I tested this query in WS API, a custom grid and a Ruby script using a feature named "feat/ure"
(Name = feat/ure)
and the query worked in all 3 cases.
Here is the Ruby code that query on a feature with forward slash in the name and assigns a new story to it:
require 'rally_api'
#Setup custom app information
headers = RallyAPI::CustomHttpHeader.new()
headers.name = "My Utility"
headers.vendor = "Nick M RallyLab"
headers.version = "1.0"
# Connection to Rally
config = {:base_url => "https://rally1.rallydev.com/slm"}
config[:username] = "user#co.com"
config[:password] = "secret"
config[:workspace] = "W"
config[:project] = "P"
config[:headers] = headers #from RallyAPI::CustomHttpHeader.new()
#rally = RallyAPI::RallyRestJson.new(config)
obj = {}
obj["Name"] = "new story efd3"
new_s = #rally.create("hierarchicalrequirement", obj)
query = RallyAPI::RallyQuery.new()
query.type = "portfolioitem"
query.fetch = "Name,FormattedID"
query.workspace = {"_ref" => "https://rally1.rallydev.com/slm/webservice/v2.0/workspace/111" }
query.project = {"_ref" => "https://rally1.rallydev.com/slm/webservice/v2.0/project/222" }
query.query_string = "(Name = \"feat/ure\")"
result = #rally.find(query)
feature = result.first
puts feature
field_updates={"PortfolioItem" => feature}
new_s.update(field_updates)
You can also utilize the html replacements for those characters.

Returning object type Rally

So I have this query using Rally:
query_result = stuff.slm.find(:hierarchical_requirement, :project => project, :workspace => stuff.workspace, :project_scope_up => false, :project_scope_down => true){ equal :name, parent_name.strip }
and then I do,
parent = query_result.results.first
and I am curious to know what kind of object is assigned to the parent. I am not on the exceptions list in Rally so unable to run the script. But I am writing an SSO integration for this script and having some problems. I feel my problem would be solved if I get to inspect the "parent" because the function is returning this "parent". If anyone has any information on this , please share. Thanks!
A story (HierarchicalRequirement) object is assigned. Using Rally Ruby REST toolkit
The code below prints:
my_story: abc, FormattedID: US86, _ref:https://rally1.rallydev.com/slm/webservice/v2.0/hierarchicalrequirement/12891971030
.
#rally = RallyAPI::RallyRestJson.new(config)
some_name = "abc"
query = RallyAPI::RallyQuery.new()
query.type = :story
query.fetch = "FormattedID"
query.query_string = "(Name = \"#{some_name}\")"
results = #rally.find(query)
my_story = results.first
puts "my_story: #{my_story}, FormattedID: #{my_story["FormattedID"]}, _ref:#{my_story["_ref"]}"
If in your code you try to find a user story based on FormattedID, here is an example. It does not really matter if it is a parent or not, since a parent of a story is a story, and I used "story" instead of "parent" in my script for clarity. A FormattedID is entered as a command line argument in this example. Notice I use story = result.first, and not story=result. Here is a screenshot of the output:
require 'rally_api'
#Setup custom app information
headers = RallyAPI::CustomHttpHeader.new()
headers.name = "find story"
headers.vendor = "Nick M RallyLab"
headers.version = "1.0"
# Connection to Rally
config = {:base_url => "https://rally1.rallydev.com/slm"}
config[:username] = "user#co.com"
config[:password] = "secret"
config[:workspace] = "X"
config[:project] = "Y"
config[:version] = "v2.0"
config[:headers] = headers #from RallyAPI::CustomHttpHeader.new()
unless ARGV.length == 1
puts "enter one argument, e.g. US123, with no spaces"
exit
end
story = nil
story_id = ARGV[0]
puts "find story by FormattedID: #{story_id}"
#rally = RallyAPI::RallyRestJson.new(config)
query = RallyAPI::RallyQuery.new()
query.type = :story
query.fetch = "Name,FormattedID,ScheduleState"
query.workspace = {"_ref" => "https://rally1.rallydev.com/slm/webservice/v2.0/workspace/1111.js" }
query.project = {"_ref" => "https://rally1.rallydev.com/slm/webservice/v2.0/project/2222.js" }
query.project_scope_up = true
query.project_scope_down = true
query.query_string = "(FormattedID = \"#{story_id}\")"
result = #rally.find(query)
if(result.length > 0)
puts "found the story"
story = result.first
puts "FormattedID: #{story["FormattedID"]}, Name: #{story["Name"]}, ScheduleState: #{story["ScheduleState"]}"
else
puts "did not find a story with FormattedID #{story_id}"
end
puts story.class
puts story.inspect

Quering for Test folder that contains a whitespace using rally_api

I’m doing a tool to create Test folders (test suites) and test cases automatically from a xml file that a Jenkins job provides me.
Probably is a silly thing but I cannot find the solution, the thing is when the test folder name contains a white space, I’m not able to query it to see if already exists. I’ve trid to escape the whitespace and also encode it as url but nothing happens.
test_suite_name = ts_line["name"]
if test_suite_name.match(/\s/)
#test_suite_name_nows = test_suite_name.gsub(/ /,"\\ \\")
test_suite_name_nows = URI::encode(test_suite_name)
end
#==================== Querying the test suite in Rally ==========================
test_suite_query = RallyAPI::RallyQuery.new({:type => :testfolder, :query_string => "(Name = #{test_suite_name_nows})"})
Do you know which should be the format for being able to query test folder names as “Test folder1”??
I always get:
/usr/local/rvm/gems/ruby-2.0.0-p195/gems/rally_api-0.9.14/lib/rally_api/rally_json_connection.rb:153:in `send_request': (StandardError)
Error on request - https://rally1.rallydev.com/slm/webservice/1.42/testfolder.js -
{:errors=>["Could not parse: Cannot parse expression \"Version tests\" as a query"]
Thanks a lot.
Here is the format:
query.query_string = "(Name = \"My Test Folder 1\")"
and a full example:
require 'rally_api'
#Setup custom app information
headers = RallyAPI::CustomHttpHeader.new()
headers.name = "find test folder"
headers.vendor = "NickM RallyLab"
headers.version = "1.0"
# Connection to Rally
config = {:base_url => "https://rally1.rallydev.com/slm"}
config[:username] = "user#co.com"
config[:password] = "1984"
config[:workspace] = "W"
config[:project] = "P"
config[:headers] = headers #from RallyAPI::CustomHttpHeader.new()
#rally = RallyAPI::RallyRestJson.new(config)
query = RallyAPI::RallyQuery.new()
query.type = :test_folder
query.fetch = "Name,FormattedID"
query.workspace = {"_ref" => "https://rally1.rallydev.com/slm/webservice/1.43/workspace/12345.js" } #use yoru OID
query.project = {"_ref" => "https://rally1.rallydev.com/slm/webservice/1.43/project/67890.js" } #user yoru OID
query.page_size = 200 #optional - default is 200
query.limit = 1000 #optional - default is 99999
query.project_scope_up = false
query.project_scope_down = true
query.order = "Name Asc"
query.query_string = "(Name = \"My Test Folder 1\")"
results = #rally.find(query)
results.each do |t|
puts "Name: #{t["Name"]}, FormattedID: #{t["FormattedID"]}"
t.read
#.............
end

Django comments app, getting content type

I am trying to create a comments application to use it everywhere where I need it, so I geuss I have to use ContentType to attach comments to different models of my project.
so here:
my model:
class Comment(models.Model):
user = models.ForeignKey(User, blank=True, null=True)
text = models.TextField((u'Текст комментария'))
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')
my view:
def add_comment(request):
if request.method == 'POST':
form = CommentForm(request.POST)
if form.is_valid():
new_comment = Comment()
new_comment.text = request.POST['text']
new_comment.content_type = ???
new_comment.object_id = request.POST['object_id']
new_comment.user = request.user
new_comment.save()
return HttpResponseRedirect(request.META['HTTP_REFERER'])
else: ...
How can I get a content type of the current model I am working with?
I have app NEWS and model Post in it, so I want to comments my Posts.
I know I can use ContentType.objects.get(app_label="news", model="post"), but I am getting exact value, so in that way my comment app will not be multipurpose.
P.S. sorry for bad English.
Check django.contrib.comments.forms.CommentForm.get_comment_create_data: It returns a mapping to be used to create an unsaved comment instance:
return dict(
content_type = ContentType.objects.get_for_model(self.target_object),
object_pk = force_unicode(self.target_object._get_pk_val()),
user_name = self.cleaned_data["name"],
user_email = self.cleaned_data["email"],
user_url = self.cleaned_data["url"],
comment = self.cleaned_data["comment"],
submit_date = datetime.datetime.now(),
site_id = settings.SITE_ID,
is_public = True,
is_removed = False,
)
So I guess that the line your are looking for is:
content_type = ContentType.objects.get_for_model(self.target_object),
Remenber, self is the form instance, and self.target_object() returns the instance that the current comment is attached to.

hidden variable in R

I am using the RLastFM package, and have some question about the function:
> tag.getTopArtists
function (tag, key = lastkey, parse = TRUE)
{
params = list(method = "tag.gettopartists", tag = tag, api_key = lastkey)
ret = getForm(baseurl, .params = params)
doc = xmlParse(ret, asText = TRUE)
if (parse)
doc = p.tag.gettopartists(doc)
return(doc)
}
the author included lastkey as the api_key, but I can't find it by using ls(), where is it?
Thanks.
getAnywhere(lastkey) show you where it is and RLastFM:::lastkey gives you this value. The value isn't exported from namespace of package.
For more details check Writing R Extensions manual, Package name spaces section.