lib/WebService/UMLSKS/ConnectUMLS.pm untested

filter: Statementstmt 0.0% 0 / 40 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 53 CC 2 SCAR 10.6
CC
2
Cov
0%
connect_umls
6.0
new
2.0
get_pt
2.0
CRAP 2.9
1 =head1 NAME
2  
3 WebService::UMLSKS::ConnectUMLS - Authenticate the user before accessing UMLSKS with valid username and password.
4  
5 =head1 SYNOPSIS
6  
7 =head2 Basic Usage
8  
9 use WebService::UMLSKS::ConnectUMLS;
10  
11 print "Enter username to connect to UMLSKS:";
12 my $username = <>;
13 print "Enter password:";
14 ReadMode 'noecho';
15 my $pwd = ReadLine 0;
16 ReadMode 'normal';
17 my $c = new Connect;
18 my $service = $c->connect_umls( $username, $pwd );
19  
20  
21 =head1 DESCRIPTION
22  
23 This module has package ConnectUMLS which has three subroutines 'new', 'get_pt' and 'connect_umls'.
24 This module takes the username and password from getUserDetails module and connects to the authentication server.
25 It returns a valid proxy ticket if the user is valid or returns an invalid service object if UMLS sends an invalid proxy ticket.
26  
27 =head1 SUBROUTINES
28  
29 The subroutines are as follows:
30  
31 =cut
32  
33 ###############################################################################
34 ########## CODE STARTS HERE #################################################
35  
36  
37 # This module has package Connect which has three subroutines 'new', 'get_pt' and 'connect_umls'.
38  
39 use warnings;
40 use SOAP::Lite;
41 use strict;
42 no warnings qw/redefine/; #http://www.perlmonks.org/?node_id=582220
43 package WebService::UMLSKS::ConnectUMLS;
44  
45 use Log::Message::Simple qw[msg error debug];
46  
47 # This sub creates a new object of Connect
48  
49  
50 =head2 new
51  
52 This sub creates a new object of ConnectUMLS.
53  
54 =cut
55  
56 sub new {
57 my $class = shift;
58 my $self = {};
59 bless( $self, $class );
60 return $self;
61 }
62  
63 #-------Following code is taken from the reference program provided by Olivier B.
64 #-------and is modified according to the need of the application.
65  
66 # These are the Universal Resource Identifier for WSDL and authentication service.
67 # These URIs will be used for authentication of the user.
68 # Please see 'http://umlsks.nlm.nih.gov/DocPortlet/html/dGuide/appls/appls1.html' for details.
69  
70 my $KSAUTH_WSDL_URI =
71 #'http://mor.nlm.nih.gov/auth-ob.wsdl';
72 'https://uts-ws.nlm.nih.gov/authorization/services/AuthorizationPort?WSDL';
73 #'http://mor.nlm.nih.gov/auth-ob.wsdl';
74 my $UMLSKS_WSDL_URI =
75 'https://uts-ws.nlm.nih.gov/UMLSKS/services/UMLSKSService?wsdl';
76 #'http://umlsks.nlm.nih.gov/UMLSKS/services/UMLSKSService?WSDL';
77 my $UMLSKS_URI =
78 #'https://uts-ws.nlm.nih.gov';
79 #'https://uts.nlm.nih.gov';
80 'http://umlsks.nlm.nih.gov';
81 my $pt_service;
82 my $pgt;
83  
84  
85 =head2 connect_umls
86  
87 This sub takes username and password as arguments
88 and returns a proxy ticket object after it authenticates the user.
89  
90 =cut
91  
92 sub connect_umls {
93 my $self = shift;
94 my $username = shift;
95 my $pwd = shift;
96 my $verbose = shift;
97  
98 # Initialize Authentication service.
99  
100 $pt_service = SOAP::Lite->service($KSAUTH_WSDL_URI);
101  
102 # Get proxy granting ticket.
103  
104 $pgt = $pt_service->getProxyGrantTicket( $username, $pwd );
105  
106 # If proxy granting ticket is not defined dispalying the error message.
107  
108 if ( not defined $pgt ) {
109 print "\nYou entered wrong username or password\n";
110 return 0;
111 }
112  
113 # If pgt is obtained, user is a valid user.
114  
115 else {
116 msg("\nProxy granting ticket : $pgt", $verbose);
117  
118 # Get proxy ticket.
119  
120 my $pt = get_pt();
121 msg("\n Proxy Ticket:$pt",$verbose);
122  
123 # Initialize UMLSKS service.
124  
125 my $service = SOAP::Lite->service($UMLSKS_WSDL_URI);
126 msg("\n service=$service\n",$verbose);
127 return $service;
128  
129 }
130  
131 }
132  
133 # This sub returns the proxy ticket.
134  
135 =head2 get_pt
136  
137 This sub returns a proxy ticket.
138  
139 =cut
140  
141 sub get_pt {
142 return $pt_service->getProxyTicket( $pgt, $UMLSKS_URI );
143 }
144  
145 1;
146  
147 #-------------------------------PERLDOC STARTS HERE-------------------------------------------------------------
148  
149  
150  
151  
152 =head1 SEE ALSO
153  
154 ValidateTerm.pm GetUserData.pm Query.pm ws-getUMLSInfo.pl
155  
156 =cut
157  
158 =head1 AUTHORS
159  
160 Mugdha Choudhari, University of Minnesota Duluth
161 E<lt>chou0130 at d.umn.eduE<gt>
162  
163 Ted Pedersen, University of Minnesota Duluth
164 E<lt>tpederse at d.umn.eduE<gt>
165  
166  
167  
168  
169 =head1 COPYRIGHT
170  
171 Copyright (C) 2011, Mugdha Choudhari, Ted Pedersen
172  
173 This program is free software; you can redistribute it and/or modify
174 it under the terms of the GNU General Public License as published by
175 the Free Software Foundation; either version 2 of the License, or (at
176 your option) any later version.
177  
178 This program is distributed in the hope that it will be useful, but
179 WITHOUT ANY WARRANTY; without even the implied warranty of
180 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
181 General Public License for more details.
182  
183 You should have received a copy of the GNU General Public License
184 along with this program; if not, write to
185 The Free Software Foundation, Inc.,
186 59 Temple Place - Suite 330,
187 Boston, MA 02111-1307, USA.
188  
189 =cut
190  
191 #---------------------------------PERLDOC ENDS HERE---------------------------------------------------------------