Abfragen von LinkList über Rest

Hilfe zu Znuny Problemen aller Art
Locked
StefanSa
Znuny newbie
Posts: 1
Joined: 21 Jun 2016, 11:31
Znuny Version: 4.0.7

Abfragen von LinkList über Rest

Post by StefanSa »

Hallo an alle.

Ich bin dabei die Restschnittstelle um ein Modul zu erweitern. dabei handelt es sich um die Abfrage von Verknüpfungen von ConfigItems.
Beispiel: Was ist alles mit Configitem 2377 verknüpft?

Ich bin dabei auf Probleme beim Schreiben des Adapters gestoßen, welches die Anfragen von Rest an die interne API weiterleitet.
Ansprechen möchte ich die Funktion LinkList von LinkObject (Siehe https://github.com/OTRS/otrs/blob/1e908 ... ct.pm#L901 )

Dabei habe ich mich an http://stackoverflow.com/questions/3467 ... or-rest-in Orientiert.

Bisher habe ich folgendes:
Zum Registrieren meiner Restschnittstelle habe ich folgende GenericInterfaceLinkObjectConnector.xml erstellt

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<otrs_config version="1.0" init="Application">
<ConfigItem Name="GenericInterface::Operation::Module###LinkObject::LinkList" Required="0" Valid="1">
        <Description Translatable="1">GenericInterface module registration for the operation layer.</Description>
        <Group>GenericInterface</Group>
        <SubGroup>GenericInterface::Operation::ModuleRegistration</SubGroup>
        <Setting>
            <Hash>
                <Item Key="Name">LinkList</Item>
                <Item Key="Controller">LinkObject</Item>
                <Item Key="ConfigDialog">AdminGenericInterfaceOperationDefault</Item>
            </Hash>
        </Setting>
    </ConfigItem>
</otrs_config>
Meine LinkList.pm sieht wiefolgt aus (Angelehnt an die LinkAdd aus dem StackOverflow-Artikel):

Code: Select all

package Kernel::GenericInterface::Operation::LinkObject::LinkList;

use strict;
use warnings;

use Kernel::GenericInterface::Operation::Common;
use Kernel::System::LinkObject;
use Kernel::System::VariableCheck qw(IsStringWithData IsHashRefWithData);

=head1 NAME

Kernel::GenericInterface::Operation::LinkObject::LinkAdd - GenericInterface Link Create Operation backend

=head1 SYNOPSIS

=head1 PUBLIC INTERFACE

=over 4

=cut

=item new()

usually, you want to create an instance of this
by using Kernel::GenericInterface::Operation->new();

=cut

sub new {
    my ( $Type, %Param ) = @_;

    my $Self = {};
    bless( $Self, $Type );


    # check needed objects
    for my $Needed (
          qw(DebuggerObject WebserviceID)
        )
    {
        if ( !$Param{$Needed} ) {
            return {
                Success      => 0,
                ErrorMessage => "LinkList.pm: Got no $Needed!"
            };
        }

        $Self->{$Needed} = $Param{$Needed};
    }

    # create additional objects

    $Self->{OperationName} = 'LinkList';
    $Self->{LinkObject}
        = $Kernel::OM->Get('Kernel::System::LinkObject');

  #  $Self->{CommonObject} = Kernel::GenericInterface::Operation::Common->new( %{$Self} );
  #  $Kernel::OM->Get('Kernel::System::Log')->Log(
  #                  Priority => 'error',
  #                  Message  => "Init Done2!",
  #              );
    return $Self;
}

=item Run()
get all existing links for a given object
Return
    $LinkList = {
        Ticket => {
            Normal => {
                Source => {
                    12  => 1,
                    212 => 1,
                    332 => 1,
                },
            },
            ParentChild => {
                Source => {
                    5 => 1,
                    9 => 1,
                },
                Target => {
                    4  => 1,
                    8  => 1,
                    15 => 1,
                },
            },
        },
        FAQ => {
            ParentChild => {
                Source => {
                    5 => 1,
                },
            },
        },
    };
    my $LinkList = $LinkObject->LinkList(
        Object    => 'Ticket',
        Key       => '321',
        Object2   => 'FAQ',         # (optional)
        State     => 'Valid',
        Type      => 'ParentChild', # (optional)
        Direction => 'Target',      # (optional) default Both (Source|Target|Both)
        UserID    => 1,
    );

=cut

sub Run {
    my ( $Self, %Param ) = @_;

    # check needed stuff
    if ( !IsHashRefWithData( $Param{Data} ) ) {
        #   return $Self->{CommonObject}->ReturnError(
        #     ErrorCode    => 'LinkList.MissingParameter',
        #     ErrorMessage => "LinkList: The request is empty!",
        # );
    }


    # https://github.com/OTRS/otrs/blob/1e908159a5dbdcfb94cc35d13bf15b04ac3e6a24/Kernel/System/LinkObject.pm Zeile 900
    my $LinkList = $Self->{LinkObject}->LinkList(
        %Param,
    );

    if ( !$LinkList ) {
        # return $Self->{CommonObject}->ReturnError(
        #     ErrorCode    => 'LinkList.AuthFail',
        #     ErrorMessage => "LinkList: Authorization failing!",
        # );
    }

    return {
        Success => 1,
        Data    => {
            Result => $LinkList,
        },
    };
    =item
    my ( $Self, %Param ) = @_;

    # check needed stuff
    if ( !IsHashRefWithData( $Param{Data} ) ) {
        #   return $Self->{CommonObject}->ReturnError(
        #     ErrorCode    => 'LinkList.MissingParameter',
        #     ErrorMessage => "LinkList: The request is empty!",
        # );
    }


    # https://github.com/OTRS/otrs/blob/1e908159a5dbdcfb94cc35d13bf15b04ac3e6a24/Kernel/System/LinkObject.pm Zeile 900
    my $LinkList = $Self->{LinkObject}->LinkList(
        %Param,
    );

    if ( !$LinkList ) {
        # return $Self->{CommonObject}->ReturnError(
        #     ErrorCode    => 'LinkList.AuthFail',
        #     ErrorMessage => "LinkList: Authorization failing!",
        # );
    }

    return {
        Success => 1,
        Data    => {
            Result => $LinkList,
        },
    };
    =cut
}

1;
Nachfolgend noch ein Datenpaket, welches ich an Rest übergeben möchte:

Code: Select all

var option = { 	uri: webservice + 'LinkList',
  						method: 'GET',
  						rejectUnauthorized: false,
  						requestCert: true,
  						agent: false,
  						json: { "Password": password,  "UserLogin":username, "Data" :{ "Object" : "Location","Limit": 1000, "state": "Production","Key": search, "UserID" : 1 } }
Passwort, Username und Key werden mit Variablen von meinem Node.JS-Server gefüllt

Im Webservice ist die Operation ebenfalls unter <WebserviceURL>/LinkList erreichbar.

Ausgaben über den OTRS Log haben gezeigt, dass die Anfragen erfolgreich an Run() weitergegeben werden, jedoch kommes dann zu Fehlern bei my ( $Self, %Param ) = @_;, wo als Error ein Parserfehler auf Undefined kommt.

Leider bin ich bei Perl und mit der OTRS-API noch blutiger Anfänger, sodass ich für jedwede Hilfe dankbar bin. Bei meiner bisherigen Suche bin ich leider auf kein entsprechendes Script gestoßen.
Locked