line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HPPPM::Demand::Management; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
52828
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
37
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
5
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
1228
|
|
6
|
1
|
|
|
1
|
|
522
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Template; |
8
|
|
|
|
|
|
|
use LWP::UserAgent; |
9
|
|
|
|
|
|
|
use Error::TryCatch; |
10
|
|
|
|
|
|
|
use POSIX qw(strftime); |
11
|
|
|
|
|
|
|
use LWP::Protocol::https; |
12
|
|
|
|
|
|
|
use HTTP::Request::Common; |
13
|
|
|
|
|
|
|
use namespace::autoclean; |
14
|
|
|
|
|
|
|
use English qw(-no_match_vars); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has 'ops_inputs_reqd' => ( |
19
|
|
|
|
|
|
|
is => 'ro', |
20
|
|
|
|
|
|
|
isa => 'HashRef', |
21
|
|
|
|
|
|
|
lazy => 1, |
22
|
|
|
|
|
|
|
builder => '_set_ops_inputs_reqd', |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has 'ops_inputs' => ( |
26
|
|
|
|
|
|
|
is => 'ro', |
27
|
|
|
|
|
|
|
isa => 'HashRef', |
28
|
|
|
|
|
|
|
lazy => 1, |
29
|
|
|
|
|
|
|
builder => '_set_ops_inputs', |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
has 'operations' => ( |
33
|
|
|
|
|
|
|
is => 'rw', |
34
|
|
|
|
|
|
|
isa => 'HashRef', |
35
|
|
|
|
|
|
|
lazy => 1, |
36
|
|
|
|
|
|
|
builder => '_set_operations', |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
has 'service_url' => ( |
40
|
|
|
|
|
|
|
is => 'rw', |
41
|
|
|
|
|
|
|
isa => 'Str', |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
has 'current_operation' => ( |
45
|
|
|
|
|
|
|
is => 'rw', |
46
|
|
|
|
|
|
|
isa => 'Str', |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
has 'user' => ( |
50
|
|
|
|
|
|
|
is => 'rw', |
51
|
|
|
|
|
|
|
isa => 'Str', |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
has 'password' => ( |
55
|
|
|
|
|
|
|
is => 'rw', |
56
|
|
|
|
|
|
|
isa => 'Str', |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
extends 'HPPPM::ErrorHandler'; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
#Stores the mapping between operation and the mandatory inputs/types. |
63
|
|
|
|
|
|
|
#For e.x. "createRequest" operation needs atleast the "requestType" |
64
|
|
|
|
|
|
|
#type to be present in the input fields. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _set_ops_inputs_reqd { |
67
|
|
|
|
|
|
|
my $self = shift; |
68
|
|
|
|
|
|
|
my %ops_inputs_reqd; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
%ops_inputs_reqd |
71
|
|
|
|
|
|
|
= ( |
72
|
|
|
|
|
|
|
#operations => Mandatory inputs/types |
73
|
|
|
|
|
|
|
createRequest => ["serviceUrl", "requestType", "fields"], |
74
|
|
|
|
|
|
|
addRequestNotes => ["serviceUrl", "requestId", "notes"], |
75
|
|
|
|
|
|
|
executeWFTransitions => ["serviceUrl", "receiver", "transition"], |
76
|
|
|
|
|
|
|
deleteRequests => ["serviceUrl", "requestIds"], |
77
|
|
|
|
|
|
|
getRequests => ["serviceUrl", "requestIds"], |
78
|
|
|
|
|
|
|
setRequestFields => ["serviceUrl", "requestId", "fields"], |
79
|
|
|
|
|
|
|
setRequestRemoteReferenceStatus => ["serviceUrl", "receiver", |
80
|
|
|
|
|
|
|
"source", "status", "fields"], |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
return \%ops_inputs_reqd; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
#Stores the mapping between operation and inputs/types. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub _set_ops_inputs { |
90
|
|
|
|
|
|
|
my $self = shift; |
91
|
|
|
|
|
|
|
my %ops_inputs; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
%ops_inputs |
94
|
|
|
|
|
|
|
= ( |
95
|
|
|
|
|
|
|
createRequest => ["serviceUrl", "requestType", "fields", |
96
|
|
|
|
|
|
|
"URLReferences", "notes"], |
97
|
|
|
|
|
|
|
addRequestNotes => ["serviceUrl", "requestId", "notes"], |
98
|
|
|
|
|
|
|
executeWFTransitions => ["serviceUrl", "receiver", "transition"], |
99
|
|
|
|
|
|
|
deleteRequests => ["serviceUrl", "requestIds"], |
100
|
|
|
|
|
|
|
getRequests => ["serviceUrl", "requestIds"], |
101
|
|
|
|
|
|
|
setRequestFields => ["serviceUrl", "requestId", "fields"], |
102
|
|
|
|
|
|
|
setRequestRemoteReferenceStatus => ["serviceUrl", "receiver", |
103
|
|
|
|
|
|
|
"source", "status", "fields"], |
104
|
|
|
|
|
|
|
); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
return \%ops_inputs; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub get_supported_ops { |
111
|
|
|
|
|
|
|
my $self = shift; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
return keys %{ $self->ops_inputs }; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub get_current_oper { |
118
|
|
|
|
|
|
|
my $self = shift; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
return $self->current_operation(); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub get_reqd_inputs { |
125
|
|
|
|
|
|
|
my $self = shift; |
126
|
|
|
|
|
|
|
my $oper = shift; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
return $self->ops_inputs_reqd->{ $oper } if $oper; |
129
|
|
|
|
|
|
|
return $self->ops_inputs_reqd(); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub get_inputs { |
134
|
|
|
|
|
|
|
my $self = shift; |
135
|
|
|
|
|
|
|
my $oper = shift; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
return $self->ops_inputs->{ $oper } if $oper; |
138
|
|
|
|
|
|
|
return $self->ops_inputs(); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub create_request { |
143
|
|
|
|
|
|
|
my $self = shift; |
144
|
|
|
|
|
|
|
my $inputs = shift || confess "No inputs to construct request passed in!"; |
145
|
|
|
|
|
|
|
my $tt = Template->new( INTERPOLATE => 1); |
146
|
|
|
|
|
|
|
my $logger = Log::Log4perl->get_logger( $PROGRAM_NAME ); |
147
|
|
|
|
|
|
|
my $oper = $self->current_operation(); |
148
|
|
|
|
|
|
|
my $req; |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
$inputs->{'DATETIME'} = strftime ('%Y-%m-%dT%H:%M:%SZ', gmtime); |
151
|
|
|
|
|
|
|
$inputs->{'USER'} = $self->user(); |
152
|
|
|
|
|
|
|
$inputs->{'PASSWORD'} = $self->password(); |
153
|
|
|
|
|
|
|
$inputs->{'CURRENT_OPERATION'} = $oper; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
$logger->info("Creating request for $oper operation"); |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
try { |
158
|
|
|
|
|
|
|
$tt->process("templates/$oper".'.tt2', $inputs, \$req) |
159
|
|
|
|
|
|
|
|| throw new Error::Unhandled -text => $tt->error; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
catch Error::Unhandled with { |
162
|
|
|
|
|
|
|
$logger->logcroak($tt->error); |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
$logger->info("Request created successfully!"); |
166
|
|
|
|
|
|
|
$logger->debug("Request created:\n$req"); |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
return $req; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub post_request { |
173
|
|
|
|
|
|
|
my $self = shift; |
174
|
|
|
|
|
|
|
my $url = shift || confess "No WebService url passed in!"; |
175
|
|
|
|
|
|
|
my $req = shift || confess "No request to post passed in!"; |
176
|
|
|
|
|
|
|
my $ct = shift || 'application/xml'; |
177
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(); |
178
|
|
|
|
|
|
|
my $logger = Log::Log4perl->get_logger( $PROGRAM_NAME ); |
179
|
|
|
|
|
|
|
my $oper = $self->current_operation(); |
180
|
|
|
|
|
|
|
my $res; |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
return 0 if ! $self->check_url_availability( $url ); |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
$logger->info("About to POST request to $url"); |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
try { |
187
|
|
|
|
|
|
|
$res = $ua->request( |
188
|
|
|
|
|
|
|
POST => $url, |
189
|
|
|
|
|
|
|
Content_type => $ct, |
190
|
|
|
|
|
|
|
Content => $req, |
191
|
|
|
|
|
|
|
) || throw new Error::Unhandled -text => $res->status_line; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
catch Error::Unhandled with { |
194
|
|
|
|
|
|
|
$logger->logcroak( $res->status_line ); |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
$logger->info("POSTing successful!"); |
198
|
|
|
|
|
|
|
$logger->debug("Response received:\n".$res); |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
return $res->content; |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
1; # End of HPPPM::Demand::Management |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
__END__ |