This commit is contained in:
2024-10-14 00:08:40 +02:00
parent dbfba56f66
commit 1462d52e13
4572 changed files with 2658864 additions and 0 deletions

View File

@@ -0,0 +1,180 @@
# --
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.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;
our $ObjectManagerDisabled = 1;
=head1 NAME
Kernel::GenericInterface::Invoker::Test::Test - GenericInterface test Invoker backend
=head1 PUBLIC INTERFACE
=head2 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};
return $Self;
}
=head2 PrepareRequest()
prepare the invocation of the configured remote web service.
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}->{TicketNumber} ) ) {
return $Self->{DebuggerObject}->Error( Summary => 'Got no TicketNumber' );
}
my %ReturnData;
$ReturnData{TicketNumber} = $Param{Data}->{TicketNumber};
# check Action
if ( IsStringWithData( $Param{Data}->{Action} ) ) {
$ReturnData{Action} = $Param{Data}->{Action} . 'Test';
}
# check request for system time
if ( IsStringWithData( $Param{Data}->{GetSystemTime} ) && $Param{Data}->{GetSystemTime} ) {
$ReturnData{SystemTime} = $Kernel::OM->Create('Kernel::System::DateTime')->ToEpoch();
}
return {
Success => 1,
Data => \%ReturnData,
};
}
=head2 HandleResponse()
handle response data of the configured remote web service.
my $Result = $InvokerObject->HandleResponse(
ResponseSuccess => 1, # success status of the remote web service
ResponseErrorMessage => '', # in case of web service 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}->{TicketNumber} ) ) {
return $Self->{DebuggerObject}->Error( Summary => 'Got no TicketNumber!' );
}
# prepare TicketNumber
my %ReturnData = (
TicketNumber => $Param{Data}->{TicketNumber},
);
# 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;
=head1 TERMS AND CONDITIONS
This software is part of the OTRS project (L<https://otrs.org/>).
This software comes with ABSOLUTELY NO WARRANTY. For details, see
the enclosed file COPYING for license information (GPL). If you
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
=cut

View File

@@ -0,0 +1,153 @@
# --
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
# --
package Kernel::GenericInterface::Invoker::Test::TestSimple;
use strict;
use warnings;
use Kernel::System::VariableCheck qw(IsString IsStringWithData);
our $ObjectManagerDisabled = 1;
=head1 NAME
Kernel::GenericInterface::Invoker::Test::TestSimple - GenericInterface test Invoker backend
=head1 PUBLIC INTERFACE
=head2 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};
return $Self;
}
=head2 PrepareRequest()
prepare the invocation of the configured remote web service.
This will just return the data that was passed to the function.
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 ) = @_;
return {
Success => 1,
Data => $Param{Data},
};
}
=head2 HandleResponse()
handle response data of the configured remote web service.
This will just return the data that was passed to the function.
my $Result = $InvokerObject->HandleResponse(
ResponseSuccess => 1, # success status of the remote web service
ResponseErrorMessage => '', # in case of web service 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} ) {
return {
Success => 0,
ErrorMessage => $Param{ResponseErrorMessage},
};
}
if ( $Param{Data}->{ResponseContent} && $Param{Data}->{ResponseContent} =~ m{ReSchedule=1} ) {
# ResponseContent has URI like params, convert them into a hash
my %QueryParams = split /[&=]/, $Param{Data}->{ResponseContent};
# unscape URI strings in query parameters
for my $Param ( sort keys %QueryParams ) {
$QueryParams{$Param} = URI::Escape::uri_unescape( $QueryParams{$Param} );
}
# fix ExecutrionTime param
if ( $QueryParams{ExecutionTime} ) {
$QueryParams{ExecutionTime} =~ s{(\d+)\+(\d+)}{$1 $2};
}
return {
Success => 0,
ErrorMessage => 'Re-Scheduling...',
Data => \%QueryParams,
};
}
return {
Success => 1,
Data => $Param{Data},
};
}
1;
=head1 TERMS AND CONDITIONS
This software is part of the OTRS project (L<https://otrs.org/>).
This software comes with ABSOLUTELY NO WARRANTY. For details, see
the enclosed file COPYING for license information (GPL). If you
did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
=cut