1# -- 2# Copyright (C) 2001-2020 OTRS AG, https://otrs.com/ 3# -- 4# This software comes with ABSOLUTELY NO WARRANTY. For details, see 5# the enclosed file COPYING for license information (GPL). If you 6# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt. 7# -- 8 9package Kernel::GenericInterface::Invoker::Test::Test; 10 11use strict; 12use warnings; 13 14use Kernel::System::VariableCheck qw(IsString IsStringWithData); 15 16# prevent 'Used once' warning for Kernel::OM 17use Kernel::System::ObjectManager; 18 19our $ObjectManagerDisabled = 1; 20 21=head1 NAME 22 23Kernel::GenericInterface::Invoker::Test::Test - GenericInterface test Invoker backend 24 25=head1 PUBLIC INTERFACE 26 27=head2 new() 28 29usually, you want to create an instance of this 30by using Kernel::GenericInterface::Invoker->new(); 31 32=cut 33 34sub new { 35 my ( $Type, %Param ) = @_; 36 37 # allocate new hash for object 38 my $Self = {}; 39 bless( $Self, $Type ); 40 41 # check needed params 42 if ( !$Param{DebuggerObject} ) { 43 return { 44 Success => 0, 45 ErrorMessage => "Got no DebuggerObject!" 46 }; 47 } 48 49 $Self->{DebuggerObject} = $Param{DebuggerObject}; 50 51 return $Self; 52} 53 54=head2 PrepareRequest() 55 56prepare the invocation of the configured remote web service. 57 58 my $Result = $InvokerObject->PrepareRequest( 59 Data => { # data payload 60 ... 61 }, 62 ); 63 64 $Result = { 65 Success => 1, # 0 or 1 66 ErrorMessage => '', # in case of error 67 Data => { # data payload after Invoker 68 ... 69 }, 70 }; 71 72=cut 73 74sub PrepareRequest { 75 my ( $Self, %Param ) = @_; 76 77 # we need a TicketNumber 78 if ( !IsStringWithData( $Param{Data}->{TicketNumber} ) ) { 79 return $Self->{DebuggerObject}->Error( Summary => 'Got no TicketNumber' ); 80 } 81 82 my %ReturnData; 83 84 $ReturnData{TicketNumber} = $Param{Data}->{TicketNumber}; 85 86 # check Action 87 if ( IsStringWithData( $Param{Data}->{Action} ) ) { 88 $ReturnData{Action} = $Param{Data}->{Action} . 'Test'; 89 } 90 91 # check request for system time 92 if ( IsStringWithData( $Param{Data}->{GetSystemTime} ) && $Param{Data}->{GetSystemTime} ) { 93 $ReturnData{SystemTime} = $Kernel::OM->Create('Kernel::System::DateTime')->ToEpoch(); 94 } 95 96 return { 97 Success => 1, 98 Data => \%ReturnData, 99 }; 100} 101 102=head2 HandleResponse() 103 104handle response data of the configured remote web service. 105 106 my $Result = $InvokerObject->HandleResponse( 107 ResponseSuccess => 1, # success status of the remote web service 108 ResponseErrorMessage => '', # in case of web service error 109 Data => { # data payload 110 ... 111 }, 112 ); 113 114 $Result = { 115 Success => 1, # 0 or 1 116 ErrorMessage => '', # in case of error 117 Data => { # data payload after Invoker 118 ... 119 }, 120 }; 121 122=cut 123 124sub HandleResponse { 125 my ( $Self, %Param ) = @_; 126 127 # if there was an error in the response, forward it 128 if ( !$Param{ResponseSuccess} ) { 129 if ( !IsStringWithData( $Param{ResponseErrorMessage} ) ) { 130 131 return $Self->{DebuggerObject}->Error( 132 Summary => 'Got response error, but no response error message!', 133 ); 134 } 135 136 return { 137 Success => 0, 138 ErrorMessage => $Param{ResponseErrorMessage}, 139 }; 140 } 141 142 # we need a TicketNumber 143 if ( !IsStringWithData( $Param{Data}->{TicketNumber} ) ) { 144 145 return $Self->{DebuggerObject}->Error( Summary => 'Got no TicketNumber!' ); 146 } 147 148 # prepare TicketNumber 149 my %ReturnData = ( 150 TicketNumber => $Param{Data}->{TicketNumber}, 151 ); 152 153 # check Action 154 if ( IsStringWithData( $Param{Data}->{Action} ) ) { 155 if ( $Param{Data}->{Action} !~ m{ \A ( .*? ) Test \z }xms ) { 156 157 return $Self->{DebuggerObject}->Error( 158 Summary => 'Got Action but it is not in required format!', 159 ); 160 } 161 $ReturnData{Action} = $1; 162 } 163 164 return { 165 Success => 1, 166 Data => \%ReturnData, 167 }; 168} 169 1701; 171 172=head1 TERMS AND CONDITIONS 173 174This software is part of the OTRS project (L<https://otrs.org/>). 175 176This software comes with ABSOLUTELY NO WARRANTY. For details, see 177the enclosed file COPYING for license information (GPL). If you 178did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>. 179 180=cut 181