Created
August 15, 2016 15:00
-
-
Save xhoy/11024759210935c5628d0ffe8be63754 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- | |
# Copyright (C) 2001-2016 OTRS AG, http://otrs.com/ | |
# -- | |
# This software comes with ABSOLUTELY NO WARRANTY. For details, see | |
# the enclosed file COPYING for license information (AGPL). If you | |
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt. | |
# -- | |
package Kernel::GenericInterface::Invoker::Test::Test; | |
use strict; | |
use warnings; | |
use Kernel::System::VariableCheck qw(IsString IsStringWithData); | |
# prevent 'Used once' warning for Kernel::OM | |
use Kernel::System::ObjectManager; | |
use Kernel::System::Ticket | |
#use Kernel::System::Ticket::Article | |
our $ObjectManagerDisabled = 1; | |
=head1 NAME | |
Kernel::GenericInterface::Invoker::Test::Test - GenericInterface test Invoker backend | |
=head1 SYNOPSIS | |
=head1 PUBLIC INTERFACE | |
=over 4 | |
=cut | |
=item new() | |
usually, you want to create an instance of this | |
by using Kernel::GenericInterface::Invoker->new(); | |
=cut | |
sub new { | |
my ( $Type, %Param ) = @_; | |
# allocate new hash for object | |
my $Self = {}; | |
bless( $Self, $Type ); | |
# check needed params | |
if ( !$Param{DebuggerObject} ) { | |
return { | |
Success => 0, | |
ErrorMessage => "Got no DebuggerObject!" | |
}; | |
} | |
$Self->{DebuggerObject} = $Param{DebuggerObject}; | |
$Self->{TicketObject} = Kernel::System::Ticket->new( %Param ); | |
return $Self; | |
} | |
=item PrepareRequest() | |
prepare the invocation of the configured remote webservice. | |
my $Result = $InvokerObject->PrepareRequest( | |
Data => { # data payload | |
... | |
}, | |
); | |
$Result = { | |
Success => 1, # 0 or 1 | |
ErrorMessage => '', # in case of error | |
Data => { # data payload after Invoker | |
... | |
}, | |
}; | |
=cut | |
sub PrepareRequest { | |
my ( $Self, %Param ) = @_; | |
# we need a TicketNumber | |
if ( !IsStringWithData( $Param{Data}->{TicketID} ) ) { | |
return $Self->{DebuggerObject}->Error( Summary => 'Got no TicketNumber' ); | |
} | |
my %TicketInfo = $Self->{TicketObject}->TicketGet( | |
TicketID => $Param{Data}->{TicketID}, | |
UserID => 1, | |
); | |
my $TicketTime = $Self->{TicketObject}->TicketAccountedTimeGet( | |
TicketID => $Param{Data}->{TicketID}, | |
); | |
#my %ArticleInfo = $Self->{TicketObject}->ArticleGet( | |
# TicketID => $Param{Data}->{TicketID}, | |
#); | |
my %ReturnData; | |
$ReturnData{TicketID} = $Param{Data}->{TicketID}; | |
# check Action | |
if ( IsStringWithData( $Param{Data}->{Action} ) ) { | |
# $ReturnData{Action} = $Param{Data}->{Action} . 'Test'; | |
$ReturnData{Action} = $Param{Data}->{Action}; | |
} | |
# check request for system time | |
if ( IsStringWithData( $Param{Data}->{GetSystemTime} ) && $Param{Data}->{GetSystemTime} ) { | |
$ReturnData{SystemTime} = $Kernel::OM->Get('Kernel::System::Time')->SystemTime(); | |
} | |
return { | |
Success => 1, | |
Data => \$TicketTime , #\%TicketInfo, \%ReturnData, | |
}; | |
} | |
=item HandleResponse() | |
handle response data of the configured remote webservice. | |
my $Result = $InvokerObject->HandleResponse( | |
ResponseSuccess => 1, # success status of the remote webservice | |
ResponseErrorMessage => '', # in case of webservice error | |
Data => { # data payload | |
... | |
}, | |
); | |
$Result = { | |
Success => 1, # 0 or 1 | |
ErrorMessage => '', # in case of error | |
Data => { # data payload after Invoker | |
... | |
}, | |
}; | |
=cut | |
sub HandleResponse { | |
my ( $Self, %Param ) = @_; | |
# if there was an error in the response, forward it | |
if ( !$Param{ResponseSuccess} ) { | |
if ( !IsStringWithData( $Param{ResponseErrorMessage} ) ) { | |
return $Self->{DebuggerObject}->Error( | |
Summary => 'Got response error, but no response error message!', | |
); | |
} | |
return { | |
Success => 0, | |
ErrorMessage => $Param{ResponseErrorMessage}, | |
}; | |
} | |
# we need a TicketNumber | |
if ( !IsStringWithData( $Param{Data}->{TicketID} ) ) { | |
return $Self->{DebuggerObject}->Error( Summary => 'Got no TicketNumber!' ); | |
} | |
# prepare TicketNumber | |
my %ReturnData = ( | |
TicketNumber => $Param{Data}->{TicketID}, | |
); | |
# check Action | |
if ( IsStringWithData( $Param{Data}->{Action} ) ) { | |
if ( $Param{Data}->{Action} !~ m{ \A ( .*? ) Test \z }xms ) { | |
return $Self->{DebuggerObject}->Error( | |
Summary => 'Got Action but it is not in required format!', | |
); | |
} | |
$ReturnData{Action} = $1; | |
} | |
return { | |
Success => 1, | |
Data => \%ReturnData, | |
}; | |
} | |
1; | |
=back | |
=head1 TERMS AND CONDITIONS | |
This software is part of the OTRS project (L<http://otrs.org/>). | |
This software comes with ABSOLUTELY NO WARRANTY. For details, see | |
the enclosed file COPYING for license information (AGPL). If you | |
did not receive this file, see L<http://www.gnu.org/licenses/agpl.txt>. | |
=cut |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment