[SOLVED] Web service mapping inside data structure problem (TicketCreate)

Moderator: crythias

Locked
mvelazquezm
Znuny newbie
Posts: 3
Joined: 08 Apr 2015, 11:29
Znuny Version: 3.3.6
Real Name: Mario

[SOLVED] Web service mapping inside data structure problem (TicketCreate)

Post by mvelazquezm »

Hi!

I am creating a web service to create Tickets and I have problems with the key/value mapping.

I have this webservice (key mapping: Petitioner:CustomerUser):

Code: Select all

---
Debugger:
  DebugThreshold: debug
  TestMode: 0
Description: For testing
Provider:
  Operation:
    createTicket:
      Description: To create a new ticket
      MappingInbound:
        Config:
          KeyMapDefault:
            MapTo: ''
            MapType: Keep
          KeyMapExact:
            Petitioner: CustomerUser
          ValueMapDefault:
            MapTo: ''
            MapType: Keep
        Type: Simple
      MappingOutbound:
        Config:
          KeyMapDefault:
            MapTo: ''
            MapType: Keep
          ValueMapDefault:
            MapTo: ''
            MapType: Keep
        Type: Simple
      Type: Ticket::TicketCreate
  Transport:
    Config:
      Authentication: {}
      MaxLength: 1000000000
      NameSpace: http://xxxxxx/otrs/mynamespace
    Type: HTTP::SOAP
RemoteSystem: One system
Requester:
  Transport:
    Config:
      Authentication: {}
    Type: ''
If I launch this SOAP message there is not change:
Incoming data before mapping and Incoming data after mapping are the same in the debugger.
Note: I put "Petitioner" key inside "Ticket" structure.

Code: Select all

$VAR1 = {
  'Article' => {
    'Body' => 'This is an article test',
    'ContentType' => 'text/plain; charset=utf8',
    'Subject' => 'Open of the test incident'
  },
  'Password' => 'passs',
  'Ticket' => {
    'Petitioner' => 'customer',
    'Priority' => 'Medium',
    'Queue' => 'Projects',
    'SLA' => '8x5 Medium Priority Request',
    'Service' => 'Cloud',
    'State' => 'new',
    'Title' => 'Incident',
    'Type' => 'Service Request'
  },
  'UserLogin' => 'user'
};
This gives me the error because I don´t have CustomerUser param: TicketCreate: Ticket->CustomerUser parameter is missing!

But If I put the "petitioner" field at root level, outside the "Ticket" structure, the mapping works, but I still having the same problem:

Incoming data before mapping:

Code: Select all

$VAR1 = {
  'Article' => {
    'Body' => 'This is an article test',
    'ContentType' => 'text/plain; charset=utf8',
    'Subject' => 'Open of the test incident'
  },
  'Password' => 'passs',
   'Petitioner' => 'customer',
  'Ticket' => {
    'Priority' => 'Medium',
    'Queue' => 'Projects',
    'SLA' => '8x5 Medium Priority Request',
    'Service' => 'Cloud',
    'State' => 'new',
    'Title' => 'Incident',
    'Type' => 'Service Request'
  },
  'UserLogin' => 'user'
};
and Incoming data after mapping:

Code: Select all

$VAR1 = {
  'Article' => {
    'Body' => 'This is an article test',
    'ContentType' => 'text/plain; charset=utf8',
    'Subject' => 'Open of the test incident'
  },
  'Password' => 'passs',
   'CustomerUser' => 'customer',
  'Ticket' => {
    'Priority' => 'Medium',
    'Queue' => 'Projects',
    'SLA' => '8x5 Medium Priority Request',
    'Service' => 'Cloud',
    'State' => 'new',
    'Title' => 'Incident',
    'Type' => 'Service Request'
  },
  'UserLogin' => 'user'
};
I still having the same error, because I need the replacement inside the "Ticket" structure.
How Can I define that?

Thanks a lot!

NOTE: The solution is at my last response.
Last edited by mvelazquezm on 09 Apr 2015, 11:56, edited 1 time in total.
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Web service mapping inside data structure problem (TicketCreate)

Post by crythias »

I can't follow your logic. The error message:
mvelazquezm wrote:TicketCreate: Ticket->CustomerUser parameter is missing!
Then you continue about "Petitioner" ...

Yet under "Ticket", you did not include a CustomerUser parameter:

Code: Select all

  'Ticket' => {
    'Priority' => 'Medium',
    'Queue' => 'Projects',
    'SLA' => '8x5 Medium Priority Request',
    'Service' => 'Cloud',
    'State' => 'new',
    'Title' => 'Incident',
    'Type' => 'Service Request'
  },
But instead you put CustomerUser above Ticket:

Code: Select all

   'CustomerUser' => 'customer',
  'Ticket' => {
What you need is to make sure the key is named CustomerUser and not Petitioner.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
mvelazquezm
Znuny newbie
Posts: 3
Joined: 08 Apr 2015, 11:29
Znuny Version: 3.3.6
Real Name: Mario

Re: Web service mapping inside data structure problem (TicketCreate)

Post by mvelazquezm »

Thanks for the response:

The thing here is: Could the mapping change automatically something like this:

This message comes from Remote System
Incoming data before mapping

Code: Select all

...
'Ticket' => {
    'Petitioner' => 'ONE_USER_VALUE',
    ...
}...
For this message:
Incoming data after mapping

Code: Select all

...
'Ticket' => {
    'CustomerUser' => 'ONE_USER_VALUE',
    ...
}...
Could that be done with the Generic Simple Mapping or Should I create a new custom mapping module?

I only get the change if I do it at "root level" but not inside "Ticket" structure.
Thanks again!
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Web service mapping inside data structure problem (TicketCreate)

Post by crythias »

I don't know. It may be that your mapping isn't showing full "path" therefore it's not working. I don't know how it is implemented.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
mvelazquezm
Znuny newbie
Posts: 3
Joined: 08 Apr 2015, 11:29
Znuny Version: 3.3.6
Real Name: Mario

Re: Web service mapping inside data structure problem (TicketCreate)

Post by mvelazquezm »

I have got solution.

I saw the Simple mapping source code (Kernel/GenericInterface/Mapping/Simple.pm) and It doesn´t enter inside a structure.

Thinking in this example input message:

Code: Select all

$VAR1 = {
  'User' => 'peter',
  'Ticket' => {
        'Title' => 'Example',
  	'myPriority' => '2',
  }
If you see Simple.pm code (line 238) at value checks:

Code: Select all

# if value is no string, just pass through
        if ( !IsString($OldValue) ) {
            $ReturnData{$NewKey} = $OldValue;
            next CONFIGKEY;
        }
If we are analysing 'Ticket' key. its value is: "{ title => 'Example', 'mypriority => '2' }
Then like it is not a String. it won´t perform any map.

---

To solve this, I have created a new Mapping module. It is just a copy from Simple Mapping.
And I add a section that manage structures. It is only available for 1 deep level and only for changes from type: "Matches":

I put this code just before the isString check (Line 237 of Simple.mp)

Code: Select all

my $ValueMap = $Config->{ValueMap}->{$NewKey};
		
		#If the OldValue is a new HASH, we have to enter inside and change key and values:
		if (ref $OldValue eq 'HASH') {
			my $internalReturnData;
			my $newIntKey;
			
			STRUCTUREKEY:
			for my $interalKey ( sort keys %{ $OldValue } ) {
				#Key replacement
				if ( $Config->{KeyMapExact} && $Config->{KeyMapExact}->{$interalKey} ) {
					$newIntKey = $Config->{KeyMapExact}->{$interalKey};
				} else {
					$newIntKey = $interalKey;
				}
				
				#Value replacement
				my $internalValue;
				$internalValue = $OldValue->{$interalKey};
				$ValueMap = $Config->{ValueMap}->{$newIntKey};
				if ( $ValueMap->{ValueMapExact} && defined $ValueMap->{ValueMapExact}->{$internalValue} ) {
					$internalReturnData->{$newIntKey} = $ValueMap->{ValueMapExact}->{$internalValue};
					next STRUCTUREKEY;
				} else {
					$internalReturnData->{$newIntKey} = $internalValue;
					next STRUCTUREKEY;
				}
				
			}
			
			$OldValue = $internalReturnData;
		}


I hope this can help!
Thanks again.

Regards
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: [SOLVED] Web service mapping inside data structure problem (TicketCreate)

Post by crythias »

You may want to suggest a pull request on github for this change.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
Locked