Skip Menu |

This queue is for tickets about the RT-Client-REST CPAN distribution.

Report information
The Basics
Id: 68673
Status: resolved
Priority: 0/
Queue: RT-Client-REST

People
Owner: DMITRI [...] cpan.org
Requestors: mohy [...] pair.com
t_pascal [...] zennet.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: How to get RT ticket links.
Date: Tue, 2 Jun 2009 09:28:04 -0400 (EDT)
To: bug-RT-Client-REST [...] rt.cpan.org
From: Mohy Farag <mohy [...] pair.com>
How can I get a hash of links from rt? By links I mean (Depends on, Depended on by, Parents, Children, Refers to and, Referred to by). This will be a script in perl that runs remotely and connects to an RT machine. my research led me to module RT::Client::REST. It can retrieve other info on a ticket but not the links. any idea how I can get a hash of links from rt? Currently RT::Client::REST->show() only returns $VAR1 = { 'TimeEstimated' => '', 'Status' => 'open', 'Queue' => 'q1', 'AdminCc' => '', 'Requestors' => 'log@log.com', 'Started' => 'Thu Feb 19 1:02:58 2009', 'InitialPriority' => '40', 'Starts' => 'Not set', 'TimeWorked' => '', 'id' => 'ticket/2', 'Told' => 'Not set', 'Cc' => '', 'Subject' => 'test ticket', 'FinalPriority' => '90', 'TimeLeft' => '', 'Creator' => 'guy', 'Owner' => 'guy', 'Resolved' => 'Not set', 'Created' => 'Tue Feb 17 13:22:11 2009', 'Priority' => '42', 'Due' => 'Not set' }; -Mohy Show quoted text
_______________________________________________
Subject: Submit patch to allow different link types and add get_links() sub
Date: Mon, 6 Jun 2011 11:12:50 -0700
To: bug-rt-client-rest [...] rt.cpan.org
From: "T. Pascal" <t_pascal [...] zennet.com>
The present code does have features for tickets but is hardcoded; this patch is a little big more generic to function with at-1.2.3. It also adds a new function, get_links() which returns a hash of arrays of linktype => [id,id...] information. Here is some example code that uses the patch below: ($s_id) = $rt->search(type => 'asset', query => "Name=\'test1\'"); ($d_id) = $rt->search(type => 'asset', query => "Name=\'test2\'"); $rt->link(type=>'asset',src=>$s_id,dst=>$d_id,link_type=>'RunsOn'); my $links = $rt->get_links(type=>'asset',id=>$s_id); I have not tested the code with tickets so functionality may have broken there. Asset functionality works properly. --- /usr/lib/perl5/site_perl/5.8.8/RT/Client/REST.pm 2010-07-06 01:22:31.000000000 -0700 +++ REST.pm 2011-06-06 10:38:34.000000000 -0700 @@ -167,6 +167,51 @@ return $k; } +sub get_links { + my $self = shift; + + $self->_assert_even(@_); + + my %opts = @_; + + my $type = $self->_valid_type(delete($opts{type}) || 'ticket'); + my $id = $self->_valid_numeric_object_id(delete($opts{id})); + + my $form = form_parse( + $self->_submit("$type/$id/links/$id")->decoded_content + ); + my ($c, $o, $k, $e) = @{$$form[0]}; + + if (!@$o && $c) { + RT::Client::REST::Exception->_rt_content_to_exception($c)->throw; + } + + # Turn the links into id lists + foreach my $key (keys(%$k)) { + try { + $self->_valid_link_type($key); + my @list = split(/\s*,\s*/,$k->{$key}); + my @newlist = (); + foreach my $val (@list) { + if ($val =~ /\/(\d+)$/) { + # We just want the ids, not the URI + push(@newlist,$1); + } else { + # Something we don't recognise + push(@newlist,$val); + } + } + # Copy the newly created list + $k->{$key} = (); + $k->{$key} = \@newlist; + } catch RT::Client::REST::InvalidParameterValueException with { + # Skip it because the keys are not always valid e.g., 'id' + } + } + + return $k; +} + sub get_transaction_ids { my $self = shift; @@ -375,7 +420,7 @@ return; } -sub link_tickets { +sub link { my $self = shift; $self->_assert_even(@_); my %opts = @_; @@ -383,8 +428,9 @@ @opts{qw(src dst)}; my $ltype = $self->_valid_link_type(delete($opts{link_type})); my $del = (exists($opts{'unlink'}) ? 1 : ''); + my $type = $self->_valid_type(delete($opts{type}) || 'ticket'); - $self->_submit("ticket/link", { + $self->_submit("$type/link", { id => $src, rel => $ltype, to => $dst, @@ -394,7 +440,10 @@ return; } -sub unlink_tickets { shift->link_tickets(@_, unlink => 1) } +sub link_tickets { shift->link(@_, type => 'ticket') } + +sub unlink { shift->link(@_, unlink => 1) } +sub unlink_tickets { shift->link(@_, type => 'ticket', unlink => 1) } sub _ticket_action { my $self = shift; @@ -657,7 +706,7 @@ sub _valid_link_type { my ($self, $type) = @_; my @types = qw(DependsOn DependedOnBy RefersTo ReferredToBy HasMember - MemberOf); + MemberOf RunsOn IsRunning ComponentOf HasComponent); unless (grep { lc($type) eq lc($_) } @types) { RT::Client::REST::InvalidParameterValueException->throw(
Subject: Re: [rt.cpan.org #46616] How to get RT ticket links.
Date: Fri, 10 Jun 2011 15:28:14 -0700
To: bug-rt-client-rest [...] rt.cpan.org, mohy [...] pair.com
From: "T. Pascal" <t_pascal [...] zennet.com>
You can check out my proposed patch in ticket 68673 (https://rt.cpan.org/Ticket/Display.html?id=68673). Any testing and feedback on that would be good.
Hi! I applied your patch on RT:Client::REST 0.43. Please note that I've been changing the code because yours seemed centered around RT's CMDB plugin, and didn't account for the fact that links can also be plain URLs (not only links to other elements in RT). Please play around a bit with the API and feel free to comment and/or send more patches (it's not public yet, so we can still make changes to the links bit). Thanks for contributing. JLMARTIN
Hi! I applied your patch on RT:Client::REST 0.43. Please note that I've been changing the code because yours seemed centered around RT's CMDB plugin, and didn't account for the fact that links can also be plain URLs (not only links to other elements in RT). Please play around a bit with the API and feel free to comment and/or send more patches (it's not public yet, so we can still make changes to the links bit). Thanks for contributing. JLMARTIN
The code in the patch is in, so we could close this ticket. However, get_links() is not documented.
On Tue May 06 16:58:36 2014, DMITRI wrote: Show quoted text
> The code in the patch is in, so we could close this ticket. However, > get_links() is not documented.
Documented in next release: https://github.com/dtikhonov/RT-Client-REST/commit/e058ae6ad158a9678db6b92d9213f9f5e2f680bc
Fixed in 0.49. Resolving.