
#######
Process
#######


****
NAME
****


Kernel::System::ProcessManagement::DB::Process


***********
DESCRIPTION
***********


Process Management DB Process backend


****************
PUBLIC INTERFACE
****************


new()
=====


Don't use the constructor directly, use the ObjectManager instead:


.. code-block:: perl

     my $ProcessObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::DB::Process');



ProcessAdd()
============


add new Process

returns the id of the created process if success or undef otherwise


.. code-block:: perl

     my $ID = $ProcessObject->ProcessAdd(
         EntityID       => 'P1',            # mandatory, exportable unique identifier
         Name           => 'NameOfProcess', # mandatory
         StateEntityID  => 'S1',
         Layout         => $LayoutHashRef,  # mandatory, diagram objects positions to be stored in
                                            #   YAML format
         Config         => $ConfigHashRef,  # mandatory, process configuration to be stored in YAML
                                            #   format
         UserID         => 123,             # mandatory
     );


Returns:


.. code-block:: perl

     $ID = 567;



ProcessDelete()
===============


delete a Process

returns 1 if success or undef otherwise


.. code-block:: perl

     my $Success = $ProcessObject->ProcessDelete(
         ID      => 123,
         UserID  => 123,
     );



ProcessGet()
============


get Process attributes


.. code-block:: perl

     my $Process = $ProcessObject->ProcessGet(
         ID              => 123,          # ID or EntityID is needed
         EntityID        => 'P1',
         Export          => 1,            # (optional) default 1 (0|1), if set to 1, the content of a file stored as preferences will be exported as Base64
         ActivityNames   => 1,            # default 0, 1 || 0, if 0 returns an Activities array
                                          #     with the activity entity IDs, if 1 returns an
                                          #     Activities hash with the activity entity IDs as
                                          #     keys and Activity Names as values
         TransitionNames => 1,            # default 0, 1 || 0, if 0 returns an Transitions array
                                          #     with the transition entity IDs, if 1 returns an
                                          #     Transitions hash with the transition entity IDs as
                                          #     keys and Transition Names as values
         TransitionActionNames => 1,      # default 0, 1 || 0, if 0 returns an TransitionActions array
                                          #     with the TransitionAction entity IDs, if 1 returns an
                                          #     TransitionAction hash with the TransitionAction entity IDs as
                                          #     keys and TransitionAction Names as values
         UserID          => 123,          # mandatory
     );


Returns:


.. code-block:: perl

     $Process = {
         ID            => 123,
         EntityID      => 'P1',
         Name          => 'some name',
         StateEntityID => 'S1',
         State         => 'Active',
         Layout        => $LayoutHashRef,
         Config        => $ConfigHashRef,
         Activities    => ['A1','A2','A3'],
         Activities    => ['T1','T2','T3'],
         CreateTime    => '2012-07-04 15:08:00',
         ChangeTime    => '2012-07-04 15:08:00',
     };
 
     $Process = {
         ID            => 123,
         EntityID      => 'P1',
         Name          => 'some name',
         StateEntityID => 'S1',
         State         => 'Active',
         Layout        => $LayoutHashRef,
         Config        => $ConfigHashRef,
         Activities    => {
             'A1' => 'Activity1',
             'A2' => 'Activity2',
             'A3' => 'Activity3',
         };
         Transitions   => {
             'T1' => 'Transition1',
             'T2' => 'Transition2',
             'T3' => 'Transition3',
         };
         TransitionActions => {
             'TA1' => 'TransitionAction1',
             'TA2' => 'TransitionAction2',
             'TA3' => 'TransitionAction3',
         };
         CreateTime => '2012-07-04 15:08:00',
         ChangeTime => '2012-07-04 15:08:00',
     };



ProcessUpdate()
===============


update Process attributes

returns 1 if success or undef otherwise


.. code-block:: perl

     my $Success = $ProcessObject->ProcessUpdate(
         ID            => 123,             # mandatory
         EntityID      => 'P1',            # mandatory, exportable unique identifier
         Name          => 'NameOfProcess', # mandatory
         StateentityID => 'S1',
         Layout        => $LayoutHashRef,  # mandatory, diagram objects positions to be stored in
                                           #   YAML format
         Config        => $ConfigHashRef,  # mandatory, process configuration to be stored in YAML
                                           #   format
         UserID        => 123,             # mandatory
     );



ProcessList()
=============


get a Process list


.. code-block:: perl

     my $List = $ProcessObject->ProcessList(
         UseEntities     => 0,                   # default 0, 1 || 0. if 0 the return hash keys are
                                                 #    the process IDs otherwise keys are the
                                                 #    process entity IDs
         StateEntityIDs  => ['S1','S2'],         # optional, to filter processes that match listed
                                                 #    state entity IDs
         UserID          => 1,
     );
 
     Returns:
 
     $List = {
         1 => 'NameOfProcess',
     }
 
     or
 
     $List = {
         'P1' => 'NameOfProcess',
     }



ProcessListGet()
================


get a Process list with all process details


.. code-block:: perl

     my $List = $ProcessObject->ProcessListGet(
         UserID      => 1,
     );


Returns:


.. code-block:: perl

     $List = [
         {
             ID            => 123,
             EntityID      => 'P1',
             Name          => 'some name',
             StateEntityID => 'S1',
             State         => 'Active',
             Layout        => $LayoutHashRef,
             Config        => $ConfigHashRef,
             Activities    => ['A1','A2','A3'],
             CreateTime    => '2012-07-04 15:08:00',
             ChangeTime    => '2012-07-04 15:08:00',
         },
         {
             ID            => 456,
             EntityID      => 'P2',
             Name          => 'some name',
             StateEntityID => 'S1',
             State         => 'Active',
             Layout        => $LayoutHashRef,
             Config        => $ConfigHashRef,
             Activities    => ['A3','A4','A5'],
             CreateTime    => '2012-07-04 15:10:00',
             ChangeTime    => '2012-07-04 15:10:00',
         },
     ];



ProcessSearch()
===============


search processes by process name


.. code-block:: perl

     my $ProcessEntityIDs = $ProcessObject->ProcessSearch(
         ProcessName => 'SomeText',       # e. g. "SomeText*", "Some*ext" or ['*SomeTest1*', '*SomeTest2*']
     );
 
     Returns:
 
     $ProcessEntityIDs = [ 'Process-e11e2e9aa83344a235279d4f6babc6ec', 'Process-f8194a25ab0ccddefeb4240c281c1f56' ];



ProcessDump()
=============


gets a complete processes information dump from the DB including: Process State, Activities,
ActivityDialogs, Transitions and TransitionActions


.. code-block:: perl

     my $ProcessDump = $ProcessObject->ProcessDump(
         ResultType  => 'SCALAR'                     # 'SCALAR' || 'HASH' || 'FILE'
         Location    => '/opt/znuny/var/myfile.txt'   # mandatory for ResultType = 'FILE'
         UserID      => 1,
     );


Returns:


.. code-block:: perl

     $ProcessDump = '
         $Self->{'Process'} = {
             'P1' => {
                 'Name' => 'Process 1',
                 'CreateTime' => '2012-07-21 08:11:33',
                 'ChangeTime' => '2012-07-21 08:11:33',
                 'Path' => {
                     'A1' => {
                         'T1' => {
                         'Action' => [
                             'TA1',
                         ],
                     }
                 },
                 'StartActivity'       => 'A1',
                 'StartActivityDialog' => 'AD1',
                 'State'               => 'S1'
             },
             # ...
         };
 
         $Self->{'Process::State'} = {
             'S1' => 'Active',
             'S2' => 'Inactive',
             'S3' => 'FadeAway'
         };
 
         $Self->{'Process::Activity'} = {
             'A1' => {
                 'Name'           => 'Activity 1',
                 'CreateTime'     => '2012-07-21 08:11:33',
                 'ChangeTime'     => '2012-07-21 08:11:33',
                 'ActivityDialog' => {
                     '1' => 'AD1',
                 }
             },
             # ...
         };
 
         $Self->{'Process::ActivityDialog'} = {
             'AD1' => {
                 'Name'             => 'Activity Dialog 1',
                 'CreateTime'       => '2012-07-21 08:11:33',
                 'ChangeTime'       => '2012-07-21 08:11:33',
                 'DescriptionLong'  => 'Longer description',
                 'DescriptionShort' => 'Short description',
                 'FieldOrder'       => [
                     'StateID',
                     'DynamicField_Marke',
                 ],
                 'Fields' => {
                     'StateID' => {
                         'DefaultValue'     => '1',
                         'DescriptionLong'  => 'Longer description',
                         'DescriptionShort' => 'Short description',
                         'Display'          => '0'
                     },
                     'DynamicField_Marke' => {
                         'DescriptionLong'  => 'Longer description',
                         'DescriptionShort' => 'Short description',
                         'Display'          => '2'
                     },
                 },
             #...
         };
 
         $Self->{'Process::Transition'} = {
             'T1' => {
                 'Name'       => 'Transition 1',
                 'ChangeTime' => '2012-07-21 08:11:33',
                 'CreateTime' => '2012-07-21 08:11:33',
                 'Condition'  => {
                     'Type'  => 'and',
                     'Cond1' => {
                         'Fields' => {
                             'DynamicField_Marke' => {
                                 'Match' => 'Teststring',
                                 'Type' => 'String',
                             },
                         },
                         'Type' => 'and',
                     },
                 },
             },
             # ...
         };
 
         $Self->{'Process::Action'} = {
             'TA1' => {
                 'Name'       => 'Queue Move',
                 'CreateTime' => '2012-07-21 08:11:33',
                 'ChangeTime' => '2012-07-21 08:11:33',
                 'Module'     => 'Kernel::System::Process::Transition::Action::QueueMove',
                 'Config'     => {
                     'NewOwner'    => 'root@localhost',
                     'TargetQueue' => 'Raw',
                 },
             },
             # ...
         };
     ';
 
     my $ProcessDump = $ProcessObject->ProcessDump(
         ResultType  => 'HASH'                       # 'SCALAR' || 'HASH' || 'FILE'
         Location    => '/opt/znuny/var/myfile.txt'   # mandatory for ResultType = 'FILE'
         UserID      => 1,
     );


Returns:


.. code-block:: perl

     $ProcessDump = {
         Process => {
             'P1' => {
                 'Name'       => 'Process 1',
                 'CreateTime' => '2012-07-21 08:11:33',
                 'ChangeTime' => '2012-07-21 08:11:33',
                 'Path'       => {
                     'A1' => {
                         'T1' => {
                             'Action' => [
                                 'TA1',
                             ],
                         }
                     },
                     'StartActivity'       => 'A1',
                     'StartActivityDialog' => 'AD1',
                     'State'               => 'S1'
                 },
             },
             # ...
         };
 
         State => {
             'S1' => 'Active',
             'S2' => 'Inactive',
             'S3' => 'FadeAway'
         };
 
         Activity => {
             'A1' => {
                 'Name'           => 'Activity 1',
                 'CreateTime'     => '2012-07-21 08:11:33',
                 'ChangeTime'     => '2012-07-21 08:11:33',
                 'ActivityDialog' => {
                     '1' => 'AD1',
                 }
             },
             # ...
         };
 
         ActivityDialog => {
             'AD1' => {
                 'Name'             => 'Activity Dialog 1',
                 'CreateTime'       => '2012-07-21 08:11:33',
                 'ChangeTime'       => '2012-07-21 08:11:33',
                 'DescriptionLong'  => 'Longer description',
                 'DescriptionShort' => 'Short description',
                 'FieldOrder'       => [
                     'StateID',
                     'DynamicField_Marke',
                 ],
                 'Fields' => {
                     'StateID' => {
                         'DefaultValue'     => '1',
                         'DescriptionLong'  => 'Longer description',
                         'DescriptionShort' => 'Short description',
                         'Display'          => '0'
                     },
                     'DynamicField_Marke' => {
                         'DescriptionLong'  => 'Longer description',
                         'DescriptionShort' => 'Short description',
                         'Display'          => '2'
                     },
                 },
             },
             #...
         };
 
         Transition => {
             'T1' => {
                 'Name'       => 'Transition 1',
                 'ChangeTime' => '2012-07-21 08:11:33',
                 'CreateTime' => '2012-07-21 08:11:33',
                 'Condition'  => {
                     'Type'  => 'and',
                     'Cond1' => {
                         'Fields' => {
                             'DynamicField_Marke' => {
                                 'Match' => 'Teststring',
                                 'Type'  => 'String',
                             },
                         },
                         'Type' => 'and',
                     },
                 },
             },
             # ...
         };
 
         TransitionAction => {
             'TA1' => {
                 'Name'       => 'Queue Move',
                 'CreateTime' => '2012-07-21 08:11:33',
                 'ChangeTime' => '2012-07-21 08:11:33',
                 'Module'     => 'Kernel::System::Process::Transition::Action::QueueMove',
                 'Config'     => {
                     'NewOwner'    => 'root@localhost',
                     'TargetQueue' => 'Raw',
                 },
             },
             # ...
         };
     }
 
     my $ProcessDump = $ProcessObject->ProcessDump(
         ResultType  => 'Location'                     # 'SCALAR' || 'HASH' || 'FILE'
         Location    => '/opt/znuny/var/myfile.txt'     # mandatory for ResultType = 'FILE'
         UserID      => 1,
     );


Returns:


.. code-block:: perl

     $ProcessDump = '/opt/znuny/var/myfile.txt';      # or undef if can't write the file



ProcessExport()
===============


export single process


.. code-block:: perl

     my $ExportProcess = $ProcessObject->ProcessExport(
         ID                       => $ProcessID, # required
         UserID                   => 1,          # required
     );


Returns:


.. code-block:: perl

     $ExportProcess = {
         'Process' => {
             'Name' => 'Application for leave',
             'ChangeTime' => '2024-07-10 10:52:23',
             'EntityID' => 'Process-9690ae9ae455d8614d570149b8ab1199',
             'Config' => {
                 'StartActivityDialog' => 'ActivityDialog-99866d267c0dc899e88db99d14a11f23',
                 'Description' => 'Application for leave',
                 'Path' => {
                 ...
             },
             ...
         },
         'Transitions' => {
             'Transition-cfef609c67c32c11e48c560536ba6b51' => {
                 'CreateTime' => '2024-06-20 09:21:34',
                 'ChangeTime' => '2024-06-20 09:21:34',
                 'Name' => 'RequestSubmitted',
                 ...
             },
             ...
         },
         'Activities' => {
             'Activity-0e102c168616125a4582ed57039e8adc' => {
                 'CreateTime' => '2024-06-20 09:21:34',
                 'ChangeTime' => '2024-06-20 09:21:34',
                 'Name' => 'File Request',
                 ...
             },
             ...
         },
         'TransitionActions' => {
             'TransitionAction-5fad14be3c31ae919bef7d19ee8f4a37' => {
                 'CreateTime' => '2024-06-20 09:21:34',
                 'ChangeTime' => '2024-06-20 09:21:34',
                 'Name' => 'Set state = pending reminder (+7d)',
                 ...
             },
             ...
         },
         'ActivityDialogs' => {
             'ActivityDialog-99866d267c0dc899e88db99d14a11f23' => {
                 'CreateTime' => '2024-06-20 09:21:34',
                 'ChangeTime' => '2024-07-24 13:59:16',
                 'Name' => 'Recording the Application for leave',
                 ...
             },
             ...
         },
     };



ProcessExportFilenameGet()
==========================


get export file name based on process entity name


.. code-block:: perl

     my $Filename = $ProcessObject->ProcessExportFilenameGet(
         Name   => 'Process_1',
         Format => 'YAML',
     );



ProcessImport()
===============


import a process YAML file/content


.. code-block:: perl

     my %ProcessImport = $ProcessObject->ProcessImport(
         Content                   => $YAMLContent, # mandatory, YAML format
         OverwriteExistingEntities => 0,            # 0 || 1
         UserID                    => 1,            # mandatory
     );


Returns:


.. code-block:: perl

     %ProcessImport = (
         Message => 'The Message to show.', # error or success message
         Comment => 'Any comment',          # optional
         Success => 1,                      # 1 if success or undef otherwise
     );



ProcessPreferencesSet()
=======================


Sets process preferences.


.. code-block:: perl

     $ProcessObject->ProcessPreferencesSet(
         ProcessEntityID => 123,
         Key             => 'UserComment',
         Value           => 'some comment',
     );



ProcessPreferencesGet()
=======================


Gets process preferences.


.. code-block:: perl

     my %Preferences = $ProcessObject->ProcessPreferencesGet(
         ProcessEntityID => 123,
         Export          => 1,       # (optional) default 1 (0|1), if set to 1, the content of a file stored as preferences will be exported as Base64
     );


Return:


.. code-block:: perl

     my %Preferences = (
         'UserComment' => 'some comment',
     );



ProcessPreferencesDelete()
==========================


Deletes process preferences.


.. code-block:: perl

     $ProcessObject->ProcessPreferencesDelete(
         ProcessEntityID => 123,
         Key             => 'UserComment',   # optional
     );





