Function Description

Pipeline Initializer

The Pipeline Initializer of the Pacemaker Order Update will get all file patterns with the file pattern provider and search for matching files in the import directory.

If files were found, the corresponding file reader will be applied, which returns all created notification documents.

As soon as all documents were collected, the pipeline initializer removes all files from the import directory and invokes the Dispatcher.

File Pattern Provider

First, each instance (e.g. shipment, invoice, …​) has to define a file pattern in the di.xml. This file pattern is used to find the file in the Pacemaker directory.

This declaration consists of the following parts:

  • The pattern instance with a file pattern and the import path for the xml and json format

The file pattern provider will return all declared file patterns.

Example of the shipment file pattern definition
<type name="TechDivision\OrderUpdateFileSystemObserver\Model\FilePatternProvider">
    <arguments>
        <argument name="configuration" xsi:type="array">
            <item name="shipment" xsi:type="array">
                <item name="disabled" xsi:type="boolean">false</item>
                <item name="pattern_instance" xsi:type="object">TechDivision\OrderUpdateFileSystemObserver\Virtual\ShipmentFilePattern</item>
            </item>
            <item name="shipmentxml" xsi:type="array">
                <item name="disabled" xsi:type="boolean">false</item>
                <item name="pattern_instance" xsi:type="object">TechDivision\OrderUpdateFileSystemObserver\Virtual\ShipmentXmlFilePattern</item>
            </item>
        </argument>
    </arguments>
</type>

<virtualType name="TechDivision\OrderUpdateFileSystemObserver\Virtual\ShipmentFilePattern" type="TechDivision\OrderUpdateFileSystemObserver\Model\BaseFilePattern">
    <arguments>
        <argument name="globPattern" xsi:type="string">shipment*.json</argument>
        <argument name="importPath" xsi:type="string">var/pacemaker/import</argument>
    </arguments>
</virtualType>
<virtualType name="TechDivision\OrderUpdateFileSystemObserver\Virtual\ShipmentXmlFilePattern" type="TechDivision\OrderUpdateFileSystemObserver\Model\BaseFilePattern">
    <arguments>
        <argument name="globPattern" xsi:type="string">shipment*.xml</argument>
        <argument name="importPath" xsi:type="string">var/pacemaker/import</argument>
    </arguments>
</virtualType>

File Reader Provider

The file reader provider is another di configuration, which each instance has to declare. This definition is used to read the files for further processing.

Here you can also declare the reader for json and xml files. The Reader gets the content of the file and creates the notification document. Finally, it renames the file with a prefix.

Example of the shipment file reader definition
<type name="TechDivision\OrderUpdateFileSystemObserver\Model\FileReaderProvider">
    <arguments>
        <argument name="configuration" xsi:type="array">
            <item name="shipment" xsi:type="array">
                <item name="disabled" xsi:type="boolean">false</item>
                <item name="pattern_key" xsi:type="string">shipment</item>
                <item name="reader_instance" xsi:type="object">TechDivision\OrderUpdateFileSystemObserverShipment\Model\ShipmentFileReader</item>
            </item>
            <item name="shipmentxml" xsi:type="array">
                <item name="disabled" xsi:type="boolean">false</item>
                <item name="pattern_key" xsi:type="string">shipmentxml</item>
                <item name="reader_instance" xsi:type="object">TechDivision\OrderUpdateFileSystemObserverShipment\Virtual\ShipmentXmlFileReader</item>
            </item>
        </argument>
    </arguments>
</type>

<type name="TechDivision\OrderUpdateFileSystemObserverShipment\Model\ShipmentFileReader">
    <arguments>
        <argument name="serializer" xsi:type="object">Magento\Framework\Serialize\Serializer\Json</argument>
    </arguments>
</type>
<virtualType name="TechDivision\OrderUpdateFileSystemObserverShipment\Virtual\ShipmentXmlFileReader" type="TechDivision\OrderUpdateFileSystemObserverShipment\Model\ShipmentFileReader">
    <arguments>
        <argument name="shipmentResolver" xsi:type="object">TechDivision\OrderUpdateFileSystemObserverShipment\Model\Resolver\Virtual\ShipmentResolverChain</argument>
        <argument name="serializer" xsi:type="object">TechDivision\OrderUpdateNotificationDispatcherApi\Model\Serializer\XmlSerialize</argument>
    </arguments>
</virtualType>

Notification Dispatcher

This dispatcher receives all notification documents and filters and groups the given documents by order. After that, a pipeline will be spawned for each notification and the entry will be saved to the pacemaker_order_update_notification table.

The first step of the pipeline is received by the corresponding notification handler from each instance (e.g. shipment, invoice …​). This is another Chain, which determines which step has to be initialized.

Example of the invoice handler definition
<type name="TechDivision\OrderUpdateNotificationDispatcherApi\Api\NotificationHandlerInterface">
    <arguments>
        <argument name="handlers" xsi:type="array">
            <item name="order.update.invoice" xsi:type="object">TechDivision\OrderUpdateInvoice\Model\InvoiceHandler</item>
        </argument>
    </arguments>
</type>

In the end, the move files step will be added to the pipeline.

Rest Api

The module Pacemaker Order Update Api provides an endpoint /rest/V1/pacemaker/import/order-update-api to get base64 decoded Data and write it to a file with the given filename, which is saved in the default import directory.

{
    "source": {
        "filename": "filexyz.json",
        "data": "ewoia2V5b25lIjogImtleW9uZSIsCiJrZXl0d28iOiAia2V5dHdvIgp9"
    }
}