Get Tag ID rally query - rally

I am using this function to get Project ID in Rally.
def getProjectID(projectName)
results = #rally.find(RallyAPI::RallyQuery.new({:type => :project, :query_string => "(Name = \"" + projectName + "\")"}))
project = results.first.read
#projectID = project.ObjectID
end
Can anyone suggest me anything on these lines to get the Tag ID, given the Tag Name. Thanks!

This code prints tag's ObjectID after it queried tags by Name:
require 'rally_api'
#Setup custom app information
headers = RallyAPI::CustomHttpHeader.new()
headers.name = "Find Tag's ObjectID given the Name"
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[:version] = "v2.0"
config[:headers] = headers #from RallyAPI::CustomHttpHeader.new()
rally = RallyAPI::RallyRestJson.new(config)
tagQuery = RallyAPI::RallyQuery.new()
tagQuery.type = :tag #userstory or hierarchical_requirement or hierarchicalrequirement will also work
tagQuery.fetch = "ObjectID"
tagQuery.project = {"_ref" => "https://rally1.rallydev.com/slm/webservice/v2.0/project/2222.js" }
tagQuery.order = "Name Asc"
tagQuery.query_string = "(Name = \"tag1\")"
tagResults = rally.find(tagQuery)
myTag = tagResults.first
puts "ObjectID: #{myTag.ObjectID}"

Related

How can I multi-edit tasks to assign each to a different user story?

In Rally, it takes a few clicks in the UI to re-parent a task. When many tasks have to be reparented it is impractical to do it one at a time. The drop down on "Multi-Edit: Task" page allows to change Name, State, Estimate, ToDo, and Owner but does not allow to change Work Product even when this column is added to a custom view on a Tasks summary page.
It is not possible to bulk-reassign tasks to a different user story in the UI. Here is a Ruby code, using Rally Ruby REST tookit
that re-assign a group of tasks based on a tag to a different story.
It is using stop_after variable just to put some guardrails around the bulk edit.
require 'rally_api'
headers = RallyAPI::CustomHttpHeader.new()
headers.name = "bulk action: set workproduct on tasks"
headers.vendor = "Nick M RallyLab"
headers.version = "1.0"
config = {:base_url => "https://rally1.rallydev.com/slm"}
config[:username] = "user#co.com"
config[:password] = "secret"
config[:workspace] = "W"
config[:project] = "P1"
config[:headers] = headers
#rally = RallyAPI::RallyRestJson.new(config)
query = RallyAPI::RallyQuery.new()
query.type = :task
query.fetch = "Name,FormattedID,Description,WorkProduct"
query.workspace = {"_ref" => "https://rally1.rallydev.com/slm/webservice/v2.0/workspace/1111" }
query.project = {"_ref" => "https://rally1.rallydev.com/slm/webservice/v2.0/project/2222" }
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 = "(Tags.Name = tag1)"
story = {"_ref" => "https://rally1.rallydev.com/slm/webservice/v2.0/hierarchicalrequirement/33333" }
tasks_results = #rally.find(query)
tasks = [];
stop_after = 10
count = 0
tasks_results.each do |t|
count +=1
break if count > stop_after
puts "Name: #{t["Name"]}, FormattedID: #{t["FormattedID"]}"
t.read
tasks << t
end
tasks.each do |t|
puts "acting on Name: #{t["Name"]}, FormattedID: #{t["FormattedID"]}"
field_updates = {"WorkProduct" => story}
t.update(field_updates)
end

mysql update for five tables

I have looked and looked, mostly at UPDATE with multiple tables. Once or twice I searched specificially with 5 tables. The examples mostly show only two tables.
When I run the code below I get this message:
update for memret 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(M.first = test, M.last = nine, M.address1 = 999 woodland, M.zip = 21122, M.emai' at line 5
From my research this happens to many. I have switched around the code numerous times. This is my latest stab at what might fly but it crashed with the same message as above.
This code is below followed by the mysql db record.
Help please!
$sql = "UPDATE membership AS M
LEFT JOIN address2 AS A2 ON M.memno1 = A2.memno2
LEFT JOIN contact AS Con ON M.memno1 = Con.memno3
LEFT JOIN workers AS W ON M.memno1 = W.memno4
LEFT JOIN comments AS Com ON M.memno1 = Com.memno5";
$sql.=" SET (M.first = $first, M.last = $last, M.address1 = $address1,";
$sql.=" M.zip = $zip, M.email = $email, M.password = $password,";
$sql.=" M.secq = $secq,M.seca = $seca,";
$sql.=" A2.address2 = $address2,";
$sql.=" Con.home = $home, Con.cell = $cell, Con.work = $work,";
$sql.=" W.webhelp = $webhelp, W.locorg = $locorg, W.candasst = $candasst,";
$sql.=" W.loccam = $loccam, W.other = $other, W.otherexp = $otherexp,";
$sql.=" Com.comment = $comment) WHERE memno1=$memno";
$result = mysql_query($sql) or die("update for memret 1: ".mysql_error());
memno1 first last address1 zip email password secq seca memno2 address2 memno3 home cell work memno4 webhelp locorg candasst loccam other otherexp memno5 comment memno6 office first last address1 address2 zip
9 test nine 999 woodland 21122 tn9#aol.com tn9999 house wreck 9 dump 9 1232224444 333556666 2223335555 9 yes yes ceo 9 test new side
This is an SQL injection. If I read the error message correctly, $address1 is "999 woodland" which will not be treated correctly by the SQL parser.
Stop substituting raw variables into query strings. (And stop using mysql_* functions, too. They're deprecated.) A prepared statement will go a long way here.
// assumes an existing PDO database connection in $conn
// requires exception-handling code (PDOException)
// requires you to check that e.g. integer fields will be updated with integers
$sql = "UPDATE membership AS M
LEFT JOIN address2 AS A2 ON M.memno1 = A2.memno2
LEFT JOIN contact AS Con ON M.memno1 = Con.memno3
LEFT JOIN workers AS W ON M.memno1 = W.memno4
LEFT JOIN comments AS Com ON M.memno1 = Com.memno5
SET (M.first = :first, M.last = :last, M.address1 = :address1,
M.zip = :zip, M.email = :email, M.password = :password,
M.secq = :secq, M.seca = :seca,
A2.address2 = :address2,
Con.home = :home, Con.cell = :cell, Con.work = :work,
W.webhelp = :webhelp, W.locorg = :locorg, W.candasst = :candasst,
W.loccam = :loccam, W.other = :other, W.otherexp = :otherexp,
Com.comment = :comment) WHERE memno1 = :memno";
$query = $conn->prepare($sql);
$params = array(":first" => $first, ":last" => $last, ":address1" => $address1,
":zip" => $zip, ":email" => $email, ":password" => $password,
":secq" => $secq, ":seca" => $seca,
":address2" => $address2,
":home" => $home, ":cell" => $cell, ":work" => $work,
":webhelp" => $webhelp, ":locorg" => $locorg,
":candasst" => $candasst,
":loccam" => $loccam, ":other" => $other,
":otherexp" => $otherexp,
":comment" => $comment, ":memno" => $memno);
$did_we_succeed = $query->execute($params);

Do Threading in Rails for massive requests

I am having the following code
def test
t1 = Time.now
#lat = params[:lat]
#lng = params[:lng]
#vehicleid = params[:vehicle_id]
#address = GoogleGeocoder.reverse_geocode([#lat, #lng]).full_address
speed = params[:speed]
speed ||= 0
Tracking.create(:latitude => #lat, :longitude => #lng, :address => #address, :vehicle_id => #vehicleid, :speed => speed)
uid = Vehicle.select('user_id').where('vehicle_id=?', #vehicleid)
gid = VehicleGeozone.where('vehicle_id=?', #vehicleid)
email = User.select('email').where('user_id=?', uid[0].user_id)
gzone = Geozone.where('geozone_id=?', gid[0].geozone_id)
#geofence = Geofence.where('geozone_id = ?', gzone[0].geozone_id)
if gzone[0].zonetype == 'polygon'
infence = false
res = isPointInPoly(#lat.to_f, #lng.to_f, #geofence)
else
res = isPointInCircle(#lat.to_f, #lng.to_f, #geofence[0].latitude, #geofence[0].longitude, #geofence[0].radius)
end
if res == true
AlertMailer.geofence(email[0].email).deliver
end
t2 = Time.now
render :text => '{"message":"success"}'
end
This test function is called every 5 seconds.
From t1 and t2 found that processing this function requires 7 seconds.
Is there a way to use threading so that I can move some intensive code of isPointInCircle and isPointInPoly into separate threads?

Limit dynamic field with cocoon gem in rails 3

I am using cocoon gem for adding dynamic fields in my webform, now i want to restrict them to add only six fields, how can I do it?
below is the code I am using in my helper:
def link_to_add_association(*args, &block)
if block_given?
f = args[0]
association = args[1]
html_options = args[2] || {}
link_to_add_association(capture(&block), f, association, html_options)
else
name = args[0]
f = args[1]
association = args[2]
html_options = args[3] || {}
html_options[:class] = [html_options[:class], "add_fields"].compact.join(' ')
html_options[:'data-association'] = association.to_s.singularize
html_options[:'data-associations'] = association.to_s.pluralize
new_object = f.object.class.reflect_on_association(association).klass.new
html_options[:'data-template'] = CGI.escapeHTML(render_association(association, f, new_object)).html_safe
link_to(name, '#', html_options )
end
end
Thanks for your help in advance.
You could do that using JavaScript and Cocoon helper method before and after insert. So what you could do
.bind('cocoon:after-insert', function() {
/* ...
1. check to see if the number of nested fields added is equal to what you want
2. if it is equal, hide the link_to_add_association link
... */
})

How do I assign a new element of an object in Rails 3.1?

#comments = []
#preComments = Comment.where(:resource_hash => resource_hash).
sort(:created_at.desc).all
#preComments.each do |comment|
newComment = comment
u = ::User.find_by_id comment.user_id
newComment.display_name = "Some name"
if u.image_location.nil?
newComment.image_location = "defaultpic"
else
newComment.image_location = u.image_location
end
p u
#comments << newComment
p "HERE!!!!!"
end
That's my code, but I get an error saying
undefined method `display_name=' for #
So how do I assign a display_name?
Disclosure : I've never use MongoMapper
So my best bet is : just add display_name as part of the Comment schema. In models/comment.rb :
class Comment
include MongoMapper::Document
key :display_name, String
key ...
[...]
end