ARS-Simple

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

Revision history for ARS-Simple

0.01    2013-12-04
        First version. A set of utility methods to make using ARSPerl simpler.
        Kudos to Joel Murphy et al for developing and maintaining ARSPerl over
        the years.  Thanks also to Remedy Corporation for making the API C available

examples/generate_fid_hash.pl  view on Meta::CPAN

# [ 'EmailAddress'             , 103,          'Optional', 'AR_DATA_TYPE_CHAR', 255 ],
# [ 'FlashboardsLicenseType'   , 111,          'Optional', 'AR_DATA_TYPE_ENUM', undef ],
# [ 'FromConfig'               , 250000003,    'Optional', 'AR_DATA_TYPE_CHAR', 3 ],
# [ 'GroupList'                , 104,          'Optional', 'AR_DATA_TYPE_CHAR', 255 ],
# [ 'GrouplistIT'              , 536870913,    'Optional', 'AR_DATA_TYPE_CHAR', 200 ],
# [ 'InstanceID'               , 490000000,    'Optional', 'AR_DATA_TYPE_CHAR', 38 ],
# [ 'ModifyAll'                , 536870914,    'Optional', 'AR_DATA_TYPE_ENUM', undef ],
# [ 'ObjectID'                 , 490000100,    'Optional', 'AR_DATA_TYPE_CHAR', 38 ],
# [ 'Password'                 , 102,          'Optional', 'AR_DATA_TYPE_CHAR', 30 ],
# [ 'UniqueIdentifier'         , 179,          'Optional', 'AR_DATA_TYPE_CHAR', 38 ],
# [ 'AssetLicenseUsed'         , 220000002,    '*Unknown*', 'AR_DATA_TYPE_INTEGER', undef ],
# [ 'ChangeLicenseUsed'        , 220000003,    '*Unknown*', 'AR_DATA_TYPE_INTEGER', undef ],
# [ 'HelpDeskLicenseUsed'      , 220000004,    '*Unknown*', 'AR_DATA_TYPE_INTEGER', undef ],
# [ 'NumberofLicenseAvailable' , 220000000,    '*Unknown*', 'AR_DATA_TYPE_INTEGER', undef ],
# [ 'SLALicenseUsed'           , 220000001,    '*Unknown*', 'AR_DATA_TYPE_INTEGER', undef ],
# ],
# };


unless ($m && $m->{numMatches})
{

examples/get_data_by_label.pl  view on Meta::CPAN

        'ApplicationLicense'       => 122,          # Optional  type=AR_DATA_TYPE_CHAR 0
        'ApplicationLicenseType'   => 115,          # Optional  type=AR_DATA_TYPE_CHAR 254
        'AssignedTo'               => 4,            # Optional  type=AR_DATA_TYPE_CHAR 254
        'ComputedGrpList'          => 119,          # Optional  type=AR_DATA_TYPE_CHAR 255
        'DefaultNotifyMechanism'   => 108,          # Optional  type=AR_DATA_TYPE_ENUM
        'EmailAddress'             => 103,          # Optional  type=AR_DATA_TYPE_CHAR 255
        'FlashboardsLicenseType'   => 111,          # Optional  type=AR_DATA_TYPE_ENUM
        'FromConfig'               => 250000003,    # Optional  type=AR_DATA_TYPE_CHAR 3
        'GroupList'                => 104,          # Optional  type=AR_DATA_TYPE_CHAR 255
        'UniqueIdentifier'         => 179,          # Optional  type=AR_DATA_TYPE_CHAR 38
        'AssetLicenseUsed'         => 220000002,    # *Unknown* type=AR_DATA_TYPE_INTEGER
        'ChangeLicenseUsed'        => 220000003,    # *Unknown* type=AR_DATA_TYPE_INTEGER
        'HelpDeskLicenseUsed'      => 220000004,    # *Unknown* type=AR_DATA_TYPE_INTEGER
        'NumberofLicenseAvailable' => 220000000,    # *Unknown* type=AR_DATA_TYPE_INTEGER
        'SLALicenseUsed'           => 220000001,    # *Unknown* type=AR_DATA_TYPE_INTEGER
        );

my $data = $ars->get_data_by_label({
        form        => 'User',
        query       => '1=1',
        lfid        => \%fid,

html/Simple.html  view on Meta::CPAN

<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>

<body style="background-color: white">



<ul id="index">
  <li><a href="#NAME">NAME</a></li>
  <li><a href="#VERSION">VERSION</a></li>
  <li><a href="#SYNOPSIS">SYNOPSIS</a></li>
  <li><a href="#METHODS">METHODS</a>
    <ul>
      <li><a href="#new">new</a></li>
      <li><a href="#get_list">get_list</a></li>
      <li><a href="#get_SQL">get_SQL</a></li>
      <li><a href="#get_data_by_label">get_data_by_label</a></li>
      <li><a href="#get_fields">get_fields</a></li>
      <li><a href="#set_max_entries">set_max_entries</a></li>
    </ul>
  </li>
  <li><a href="#PRIVATE-METHODS">PRIVATE METHODS</a>
    <ul>
      <li><a href="#init">_init</a></li>
      <li><a href="#load_qualifier">_load_qualifier</a></li>
      <li><a href="#DESTROY">DESTROY</a></li>
      <li><a href="#check_initialised">_check_initialised</a></li>
      <li><a href="#reset_max_entries">_reset_max_entries</a></li>
    </ul>
  </li>
  <li><a href="#TODO">TODO</a></li>
  <li><a href="#TOOLS">TOOLS</a></li>
  <li><a href="#AUTHOR">AUTHOR</a></li>
  <li><a href="#BUGS">BUGS</a></li>
  <li><a href="#SUPPORT">SUPPORT</a></li>
  <li><a href="#ACKNOWLEDGEMENTS">ACKNOWLEDGEMENTS</a></li>
  <li><a href="#LICENSE-AND-COPYRIGHT">LICENSE AND COPYRIGHT</a></li>
</ul>

html/Simple.html  view on Meta::CPAN

</dd>
<dt id="user">user</dt>
<dd>

<p>The user you wish to connect as (this is often a user with administrator privilages). Note that while this is a required argument, it may be supplied via the configuration file to avoid lots of scripts with the user (and password) in them (less to...

</dd>
<dt id="password">password</dt>
<dd>

<p>The password to the user you wish to connect as. This may come from the configuration file if set.</p>

</dd>
</dl>

<p>There are a number of optional arguments, they are:</p>

<dl>

<dt id="max_returns">max_returns</dt>
<dd>

<p>Set a limit on how many items may be returned from certain calls. Setting this value to 0 sets unlimited returns. This parameter can also be set on individual calls. <b>Note:</b> This is a system wide configuration change and requires administrato...

<p><b>Note: You should not use a value less than the default system value for this field or you may impact normal operation of your system</b></p>

<p>Example usage:</p>

<pre><code> reset_limit =&gt; 0, # unlimited returns</code></pre>

</dd>
<dt id="reset_limit">reset_limit</dt>
<dd>

<p>Once max_returns is used, reset_limit, if set will return the server to nominated max_returns limit (eg 3000), thereby limiting the possible impact on the system of having max_returns set to a high value (eg 0).</p>

<p>Example usage:</p>

<pre><code> reset_limit =&gt; 3000, # max returns back to a suitable maximum of 3000</code></pre>

</dd>
<dt id="ars_debug">ars_debug</dt>
<dd>

<p>Turn on, if true (1), the ARSperl debugging output. Not something you would normally use.</p>

</dd>
<dt id="log">log</dt>
<dd>

html/Simple.html  view on Meta::CPAN


<pre><code> <span class="keyword">use</span> <span class="variable">ARS::Simple</span><span class="operator">;</span>
 <span class="keyword">use</span> <span class="variable">File::Log</span><span class="operator">;</span>
 <span class="keyword">my</span> <span class="variable">$log</span> <span class="operator">=</span> <span class="variable">File::Log</span><span class="operator">-&gt;</span><span class="variable">new</span><span class="operator">();</span>
 <span class="keyword">my</span> <span class="variable">$ars</span> <span class="operator">=</span> <span class="variable">ARS::Simple</span><span class="operator">-&gt;</span><span class="variable">new</span><span class="operator">(</span><span clas...
     <span class="string">server</span>      <span class="operator">=&gt;</span> <span class="string">'my_server'</span><span class="operator">,</span>
     <span class="string">user</span>        <span class="operator">=&gt;</span> <span class="string">'some_admin'</span><span class="operator">,</span>
     <span class="string">password</span>    <span class="operator">=&gt;</span> <span class="string">'password_for_some_admin'</span><span class="operator">,</span>
     <span class="string">log</span>         <span class="operator">=&gt;</span> <span class="variable">$log</span><span class="operator">,</span>
     <span class="string">max_returns</span> <span class="operator">=&gt;</span> <span class="number">0</span><span class="operator">,</span>    <span class="comment"># allow unlimited returns</span>
     <span class="string">reset_limit</span> <span class="operator">=&gt;</span> <span class="number">3000</span><span class="operator">,</span> <span class="comment"># reset to a suitable limit after each call using max_returns</span>
     <span class="string">ars_debug</span>   <span class="operator">=&gt;</span> <span class="number">1</span><span class="operator">,</span>    <span class="comment"># get a whole lot of debugging information (you real should not need)</span>
     <span class="operator">}</span><span class="operator">);</span>
</code></pre>

<h2 id="get_list">get_list</h2>

<p>Method to return an array reference of Entry-Id values for a form. Arguments are passed as an hash reference, with two required parameters, eg:</p>

<pre><code> <span class="comment"># Get theEntry-Id's for all records in the 'User' form.</span>
 <span class="keyword">my</span> <span class="variable">$eids</span> <span class="operator">=</span> <span class="variable">$ars</span><span class="operator">-&gt;</span><span class="variable">get_list</span><span class="operator">(</span><span class...

html/Simple.html  view on Meta::CPAN

</code></pre>

<p>the a query could be something like</p>

<pre><code> <span class="keyword">my</span> <span class="variable">$query</span> <span class="operator">=</span> <span class="string">qq{ '</span><span class="variable">$user</span><span class="string">{UserID}' LIKE "g%" }</span><span class="operato...
 <span class="keyword">my</span> <span class="variable">$eids</span> <span class="operator">=</span> <span class="variable">$ars</span><span class="operator">-&gt;</span><span class="variable">get_list</span><span class="operator">(</span><span class...
</code></pre>

<h2 id="get_SQL">get_SQL</h2>

<p>Run direct SQL on your server, there is only one required argument, the sql, you may optionally set the max_returns value.</p>

<p>The names of the fields can be found from the Admin Tool, under the database tab for a form. This will be the name of the field used in the database view of the Remedy form. <b>Note</b> you do need to replace spaces with and underscore &#39;_&#39;...

<p>Example method call:</p>

<pre><code> <span class="keyword">my</span> <span class="variable">$data</span> <span class="operator">=</span> <span class="variable">$ars</span><span class="operator">-&gt;</span><span class="variable">get_SQL</span><span class="operator">(</span><...
     <span class="string">sql</span> <span class="operator">=&gt;</span> <span class="string">q{select Login_name, Full_Name from User_X where Login_name like 'g%' order by Login_name}</span><span class="operator">,</span>
     <span class="string">max_returns</span> <span class="operator">=&gt;</span> <span class="number">0</span><span class="operator">,</span>
     <span class="operator">}</span><span class="operator">);</span>
</code></pre>

html/Simple.html  view on Meta::CPAN

     <span class="variable">eID1</span><span class="operator">,</span> <span class="operator">{</span><span class="string">Label1</span> <span class="operator">=&gt;</span> <span class="variable">value1</span><span class="operator">,</span> <span cla...
     <span class="variable">eID2</span><span class="operator">,</span> <span class="operator">{</span><span class="string">Label1</span> <span class="operator">=&gt;</span> <span class="variable">value1</span><span class="operator">,</span> <span cla...
     <span class="operator">...</span>
     <span class="operator">}</span><span class="operator">;</span>
</code></pre>

<h2 id="get_fields">get_fields</h2>

<p>get_fields has a required argument, the form you require the field details for. The returned hash reference is the result of a call to ars_GetFieldTable, the keys are the field names and the values are the field ids (fid).</p>

<h2 id="set_max_entries">set_max_entries</h2>

<p>This requires that the &#39;user&#39; has administrator access. This allows the overriding of the <b>system wide</b> maximum rows returned setting AR_SERVER_INFO_MAX_ENTRIES, setting this to zero (0) will allow unlimited returns.</p>

<p><b>Beware of setting this to a small value, it is system wide and could have a major impact on your system</b></p>

<h1 id="PRIVATE-METHODS">PRIVATE METHODS</h1>

<h2 id="init">_init</h2>

<p>Initialisation for new</p>

<h2 id="load_qualifier">_load_qualifier</h2>

<h2 id="DESTROY">DESTROY</h2>

<p>Log out from ARSystem</p>

<h2 id="check_initialised">_check_initialised</h2>

<p>Check to insure that there is a connection to Remedy ARSystem. Returns true if connected.</p>

<h2 id="reset_max_entries">_reset_max_entries</h2>

<p>If set, returns the the system wide AR_SERVER_INFO_MAX_ENTRIES back to a suitable value (eg 3000). This required the &#39;user&#39; has administrator access</p>

<h1 id="TODO">TODO</h1>

<p>Add in the tools below.</p>

<p>Add in further methods to make life easier and your code more readable</p>

<h1 id="TOOLS">TOOLS</h1>

<p><b>NOT DONE YET</b></p>

lib/ARS/Simple.pm  view on Meta::CPAN

        $self->_carp("get_list() requires 'form' and 'query' arguments\n");
        return;
    }


    # Create a qualifier struct
    my $qual = $self->_load_qualifier($args);
    return unless $qual;

    # Set the limit
    $self->set_max_entries($args->{max_returns});

    # Get the entryId
    my @entries = ars_GetListEntry($self->{ctl}, $args->{form}, $qual, 0, 0,
        [{columnWidth => 1, separator => ' ', fieldId => 1 }]  # Minimise the amount of data returned
        );

    # Reset the limit
    $self->_reset_max_entries();


    my @entryIds;
    # Speed hack for large retuns
    $#entryIds = $#entries;
    @entryIds = ();

    for (my $x = 0; $x < $#entries; $x += 2)
    {
        #Assign the entryId's to the array, stripping the query list values

lib/ARS/Simple.pm  view on Meta::CPAN

    {
        $self->_carp("get_data_by_label() requires 'form' and 'query' arguments\n");
        return;
    }

    #-- Create a qualifier struct
    my $qual = $self->_load_qualifier($args);
    return unless $qual;

    # Set the limit
    $self->set_max_entries($args->{max_returns});

    # Get the data from the form defined by qualifier qual
    my %entryList;
    if ($ARS::VERSION >= 1.8)
    {
        %entryList = ars_GetListEntryWithFields($self->{ctl}, $form, $qual, 0, 0, \@fid);
    }
    else
    {
        %entryList = ars_GetListEntryWithFields($self->{ctl}, $form, $qual, 0, \@fid);
    }

    # Reset the limit
    $self->_reset_max_entries();

    unless (%entryList)
    {
        no warnings qw(uninitialized);
        if ($ars_errstr)
        {
            $self->_carp("get_data_by_label() failed.\nError=$ars_errstr\nForm=$form\nQuery=$query\n");
        }
        else
        {

lib/ARS/Simple.pm  view on Meta::CPAN

    }

    return \%entryList;
}

sub get_SQL
{
    my ($self, $args) = @_;

    # Set the limit
    $self->set_max_entries($args->{max_returns});

    # Run the SQL through the ARSystem API
    my $m = ars_GetListSQL($self->{ctl}, $self->{sql});

    # Reset the limit
    $self->_reset_max_entries();

    #    $m = {
    #            "numMatches"   => integer,
    #            "rows"         => [ [r1col1, r1col2], [r2col1, r2col2] ... ],
    #         }
    if ($ars_errstr && $ars_errstr ne '')
    {
        $self->_carp('get_SQL() - ars_GetListSQL error, sql=', $self->{sql}, "\nars_errstr=$ars_errstr\n");
    }

    return $m;
}

sub set_max_entries
{
    my ($self, $max) = @_;

    if (defined $max)
    {
        # Just use the value given
    }
    elsif ($self->{max_returns})
    {
        $max = $self->{max_returns};
    }
    elsif (defined $self->{reset_limit})
    {
        $max = 0;  # Set for unlimited returns if we have a reset limit defined
    }

    if (defined $max)
    {
        unless(ars_SetServerInfo($self->{ctl}, &ARS::AR_SERVER_INFO_MAX_ENTRIES, $max))
        {
            $self->_carp("set_max_entries() - Could not set the AR_SERVER_INFO_MAX_ENTRIES to $max:\n$ars_errstr\n");
        }
    }
}

sub _reset_max_entries
{
    my $self = shift;

    if (defined $self->{reset_limit})
    {
        $self->set_max_entries($self->{reset_limit});
    }
}

sub get_fields
{
    my ($self, $form) = @_;

    # Check required args
    unless ($form)
    {

lib/ARS/Simple.pm  view on Meta::CPAN

            croak "No password defined, quitting\n";
        }
    }
    $user  = $self->{persistant}{user};
    $pword = $self->{persistant}{password};

    # Handle the other passed arguments
    $self->{server}      = $args->{server}      if $args->{server};
    $self->{log}         = $args->{log}         if $args->{log};
    $self->{max_returns} = $args->{max_returns} if defined $args->{max_returns};
    $self->{reset_limit} = $args->{reset_limit} if defined $args->{reset_limit};

    if ($args->{ars_debug})
    {
        $ARS::DEBUGGING = 1;
    }
    $self->{debug} = $args->{debug} ? 1 : 0;

    ## Now connect to Remedy
    if ($self->{server} && $user && $pword)
    {

lib/ARS/Simple.pm  view on Meta::CPAN

        }
    }
    else
    {
        croak(__PACKAGE__ . " object initialisation failed, server, user and password are required\n");
    }
}


    # GG test - need to find and store the current value of AR_SERVER_INFO_MAX_ENTRIES
    #           so we can set reset_limit if not defined
    #my %s = ars_GetServerInfo($self->{ctl});
    #print  Dumper(\%s);


1; # End of ARS::Simple


__END__

=head1 NAME

lib/ARS/Simple.pm  view on Meta::CPAN

=item user

The user you wish to connect as (this is often a user with administrator
privilages).  Note that while this is a required argument, it may be supplied
via the configuration file to avoid lots of scripts with the user (and password)
in them (less to change, not on display so safer).

=item password

The password to the user you wish to connect as.  This may come from the configuration
file if set.

=back

There are a number of optional arguments, they are:

=over 4

=item max_returns

Set a limit on how many items may be returned from certain calls.
Setting this value to 0 sets unlimited returns.  This parameter
can also be set on individual calls. B<Note:> This is a system wide
configuration change and requires administrator privilages on user.

B<Note: You should not use a value less than the default system value
for this field or you may impact normal operation of your system>

Example usage:

 reset_limit => 0, # unlimited returns

=item reset_limit

Once max_returns is used, reset_limit, if set will return the server
to nominated max_returns limit (eg 3000), thereby limiting the possible
impact on the system of having max_returns set to a high value (eg 0).

Example usage:

 reset_limit => 3000, # max returns back to a suitable maximum of 3000

=item ars_debug

Turn on, if true (1), the ARSperl debugging output.
Not something you would normally use.

=item log

Pass a object to use to log erros/information to a log file.
The log object is expected to have methods I<exp> and I<msg>

lib/ARS/Simple.pm  view on Meta::CPAN


 use ARS::Simple;
 use File::Log;
 my $log = File::Log->new();
 my $ars = ARS::Simple->new({
     server      => 'my_server',
     user        => 'some_admin',
     password    => 'password_for_some_admin',
     log         => $log,
     max_returns => 0,    # allow unlimited returns
     reset_limit => 3000, # reset to a suitable limit after each call using max_returns
     ars_debug   => 1,    # get a whole lot of debugging information (you real should not need)
     });

=head2 get_list

Method to return an array reference of Entry-Id values for a form.
Arguments are passed as an hash reference, with two required parameters, eg:

 # Get theEntry-Id's for all records in the 'User' form.
 my $eids = $ars->get_list({ form => 'User', query => '1 = 1' });

lib/ARS/Simple.pm  view on Meta::CPAN

update_record({
    eid  => $eID,           # The Entry-Id/Request-Id to update
    form => $form,          # The form to update
    lvp  => \%lvp,          # The data to be updated as a label => value hash ref
    lfid => \%labelFIDhash  # The label FID hash reference
    });

=head2 get_SQL

Run direct SQL on your server, there is only one required argument,
the sql, you may optionally set the max_returns value.

The names of the fields can be found from the Admin Tool, under
the database tab for a form.  This will be the name of the field
used in the database view of the Remedy form. B<Note> you do need
to replace spaces with and underscore '_' character.

Example method call:

 my $data = $ars->get_SQL({
     sql => q{select Login_name, Full_Name from User_X where Login_name like 'g%' order by Login_name},

lib/ARS/Simple.pm  view on Meta::CPAN

Returns the ARSystem control structure, so you can use it in other
ARSperl calls.

=head2 get_fields

get_fields has a required argument, the form you require the
field details for.  The returned hash reference is the result
of a call to ars_GetFieldTable, the keys are the field names
and the values are the field ids (fid).

=head2 set_max_entries

This requires that the 'user' has administrator access.  This
allows the overriding of the B<system wide> maximum rows returned
setting AR_SERVER_INFO_MAX_ENTRIES, setting this to zero (0) will
allow unlimited returns.

B<Beware of setting this to a small value, it is system wide and
could have a major impact on your system>

=head1 PRIVATE METHODS

=head2 _init

Initialisation for new and handling of cache

=head2 _load_qualifier

Convert a query to a qualifier structure

=head2 _check_initialised

Check to insure that there is a connection to Remedy ARSystem.
Returns true if connected.

=head2 _reset_max_entries

If set, returns the the system wide AR_SERVER_INFO_MAX_ENTRIES back
to a suitable value (eg 3000).  This required the 'user' has administrator
access

=head2 _carp

Complain if something went wrong & possible add to the log file

=head2 DESTROY

Log out from ARSystem

t/01-connect.t  view on Meta::CPAN

use ARS::Simple;
use Test::More;

plan tests => 1;

BEGIN
{
    eval {require './t/config.cache'; };
    if ($@)
    {
        plan( skip_all => "Testing configuration was not set, test not possible" );
    }
}

plan( skip_all => "Automated testing") if ($ENV{PERL_MM_USE_DEFAULT} || $ENV{AUTOMATED_TESTING});

diag( "Testing against server: " .  CCACHE::server());

my $ars = ARS::Simple->new({
        server   => CCACHE::server(),
        user     => CCACHE::user(),



( run in 1.737 second using v1.01-cache-2.11-cpan-49f99fa48dc )