Procedure 16.9. Processing an Inbound FixedLength

  1. Create an Inbound Interface

    Platform uses Inbound Interfaces to consume data in FixedLength format.

    Open your MPT and navigate the Outline view to Inbound Interfaces. Right-click and press "Add Inbound Interface".
    images/download/attachments/144836052/AddInterface-version-1-modificationdate-1645136844000-api-v2.png
    For this example, we will create an Inbound Interface to process an inbound FixedLength for Order. Choose format type as FixedLength
    images/download/attachments/144836052/AddFixLenInterface-version-1-modificationdate-1645136856000-api-v2.png

  2. Configure the processor to process the FixedLength file

    The inbound FixedLength file will need a processor which can traverse through the file line by line to create FixedLengthRows and its fields and then convert them to a model. So, the processor tab has an option to specify the fully qualified name of the processor which will be used to process the FixedLength file.
    images/download/attachments/144836052/FixLenInterfaceProcessor-version-1-modificationdate-1645136864000-api-v2.png

  3. Converting FixedLengthRows to ModelList

    The processor class must provide the implementation for converting List<FixLenRow> to ModelList. This is done by overriding the method processFixLenRows(List<FixLenRow> fixLenRows, Message message, PlatformUserContext context) which returns ModelList.
    The processor class should also implement its default constructor which should invoke the superclass constructor:


    public SampleFixLenProcessor() {
    super("ZPTS", "Order.xml");
    }

    The superclass constructor must be invoked with the parameters as module prefix and the XML rule file name.

    There are two more parameters that can be set (if needed) while invoking the superclass constructor - allowParseWithErrorRecords and defaultMessageDetailEnabled.

    The boolean flag allowParseWithErrorRecords is by default set to true, and if it is overridden using the constructor as false, then if there are any parse errors in any one record, all the other records will also fail of the FixedLengthFile. The flag defaultMessageDetailEnabled is by default set to false and if it is overridden using the constructor as true, then message detail will be created by default from the base processor for the fixedLength records.

    Invoking the superclass constructor using all four parameters:


    public SampleFixLenProcessorV2() {
    super("ZPTS", "Order.xml",true, true);
    }

    Sample implementation of processFixLenRows method in FixedLength processor:

    @Override
    public ModelList processFixLenRows(List<FixLenRow> fixLenRows, Message message, PlatformUserContext context) throws Exception {
    Map<String,Order> orders = new HashMap<String,Order>();
    ModelList modelListMsg = JAXBUtil.FACTORY.createModelList();
    modelListMsg.setCustomModelName(Order.STANDARD_MODEL_NAME);
    modelListMsg.setValueChainId(context.getValueChainId());
    modelListMsg.setActionName("PLT.InsertOrUpdate");
    Order order = null;
    int orderLineItemNumber = 1;
    for(FixLenRow fixLenRow : fixLenRows) {
    String orderNumber = fixLenRow.getFieldValue(SampleFixLenConstants.FIELD_DLQ_NUMBER);
    if(!orders.containsKey(orderNumber)) {
    order = new Order();
    order.setOrderNumber(orderNumber);
    orders.put(orderNumber,order);
    order.setCreationEnterpriseName(SampleFixLenConstants.ENT_NAME);
    order.setCreationOrganizationName(SampleFixLenConstants.ORG_NAME);
    modelListMsg.add(order, ModuleService.getXmlns(Order.MODEL_TYPE));
    orderLineItemNumber = 1;
    }
    else {
    order = orders.get(orderNumber);
    }
    OrderLineItem orderLineItem = new OrderLineItem();
    orderLineItem.setOrderLineItemNumber(""+orderLineItemNumber);
    orderLineItemNumber++;
    String itemName = fixLenRow.getFieldValue(SampleFixLenConstants.FIELD_CUSTOMER_REFERENCE);
    if(StringUtils.isNullOrBlank(itemName)) {
    throw new Exception("Item name is not provided");
    }
    orderLineItem.setItemName(itemName.trim());
    orderLineItem.setItemEnterpriseName(SampleFixLenConstants.ENT_NAME);
    String requestQuantity = fixLenRow.getFieldValue(SampleFixLenConstants.FIELD_QUANTITY_TO_DELIVER);
    orderLineItem.setShippedQuantity(Double.parseDouble(requestQuantity.trim()));
    order.getOrderLineItems().add(orderLineItem);
    }
    modelListMsg = writeModelList(modelListMsg,context);
    return modelListMsg;
    }
    For every inbound fixedLength row processed, there will be a messageDetail entry created which will record all the details including errors if present.