Encompass Index Update Tool

The Index Update Tool takes an XML file as input and updates the index in place without the need to reload the application. This will supplement the daily full data refresh and provide access to more up-to-date data throughout the day. This tool is intended to be called by an external scheduling utility, such as Cron on Linux or an windows event scheduler on Windows Server.

You can start with one of the example scripts in the Usage section and customize to meet your needs.

Prerequisites

  • Java Runtime Environment (JRE) 7
  • Java libraries distributed with the tool (./index-update-tool/lib/)
  • Existing valid index with a known location
  • Existing running Encompass instance
  • Administrative access to ETL and/or application servers

Usage 

The Index Update Tool has three options, all of which are required.

   Option  Description
indexDescr File containing basic index field descriptions (json format)
indexDir Input directory path
input Input file with parts to be added/updates (XML format)

Example - Windows

REM Set this to a valid JDK/JRE 7 installation
set JAVA_HOME=C:\Program Files\Java\jre7

REM Configure to your ENCOMPASS installation home
set ENCOMPASS_HOME=….

REM Configure for location of your description.json
set INDEX_DESCRIPTION_FILE=%ENCOMPASS_HOME%\config\default\description.json

REM Configure location of the input XML
set DELTA_XML = %ENCOMPASS_HOME%\data\delta.xml

REM Configure location of your PRODUCTION parts index
set PRODUCTION_INDEX_DIR=%ENCOMPASS_HOME%data\index\parts

REM Configure logfile
set LOGFILE=%ENCOMPASS_HOME%\logs\index_update_util.log

"%JAVA_HOME%/bin/java.exe" -jar index-update-tool\index-update-tool-1.0.X.jar^
-indexDescr %INDEX_DESCIRPITION_FILE% -indexDir %PRODUCTION_INDEX_DIR%^
-input %DELTA_FILE% >> %LOGFILE% 2>&1

Example - Linux

#!/bin/bash

#Set this to a valid JDK/JRE 7 installation
export JAVA_HOME= /usr/share/java…..

#Configure to your ENCOMPASS installation home
export ENCOMPASS_HOME=….

#Configure for location of your description.json
export INDEX_DESCRIPTION_FILE=$ENCOMPASS_HOME/config/default/description.json

#Configure location of the input XML
export DELTA_XML = $ENCOMPASS_HOME/data/delta.xml

#Configure location of your PRODUCTION parts index
export PRODUCTION_INDEX_DIR=$ENCOMPASS_HOME/data/index/parts

#Configure logfile
export LOGFILE=$ENCOMPASS_HOME/logs/index_update_util.log

$JAVA_HOME/bin/java -jar ./index-update-tool-1.0.5.jar \
-indexDescr $INDEX_DESCIRPITION_FILE -indexDir $PRODUCTION_INDEX_DIR \
-input $DELTA_FILE 1&2 >> $LOGFILE

XML Format

The update utility will insert a new entry into the index with the required fields, cpn and type, followed by any other fields to be made available to that record. These new records will appear to the App immediately on the next search. The App does not need to be restarted for changes to take effect.

Please note the App will only be able to search and display fields that already are configured in the config.xml, therefore new fields may be added, however they will not appear until appropriate config.xml changes are made and the App is restarted.

This is an example of the XML input required.

<part-data>

<item cpn="value" type="value" ... fieldN="value">

<catalog>catalog1</catalog>

<catalog>catalog2</catalog>

</item>

...

</part-data>

Required Fields:

Field Description 
cpn Part number to be updated
type Must match a type field already present in index

Catalog specification is optional.

CSV Conversion

There is a helper Python script (csv2xml.py) that can convert a CSV file to the correct XML format. The CSV should simply list the part attributes. It also supports a delimited list of catalogs.

Note: This requires Python 2.7

Arguments

Argument Type Description
input Required Input CSV file
output Required Output XML file
-separator,-s Optional Separator for the catalogs list. The default is | (pipe).

Usage Example

python csv2xml.py infile.csv outfile.xml

With custom delimiter (tilde):

python csv2xml.py infile.csv outfile.xml -s ~

Full Script

import xml.etree.ElementTree as ET

import csv

import argparse

 

def main():

parser = argparse.ArgumentParser()

# input and output are positional and required args

parser.add_argument('input', help = 'Input file path')

parser.add_argument('output', help = 'Output file path')

# separator is optional, specify before or after input/output

parser.add_argument('-s', '--separator', help = 'Catalog list separator')

args = parser.parse_args()

 

# This is the separator for the list of catalogs

# Defaults to | but can specify with (-s|--separator)

sep = '|'

if args.separator:

sep = args.separator

 

# Create root element

pd = ET.Element('part-data')

with open(args.input) as part_csv:

# Parse csv to dict

r = csv.DictReader(part_csv)

for row in r:

item = ET.SubElement(pd, 'item')

# catalogs not an attribute, pop it out as list if present

if 'catalogs' in row:

cats = row.pop("catalogs").split(sep)

# then create sub elements

# Note: this creates an empty tag rather than no tag when the field is

# present but empty (might only be when some have values)

for cat in cats:

ce = ET.SubElement(item, 'catalog')

ce.text = cat

# Set item elements attribute to the dict

item.attrib = row

 

with open(args.output, 'wb') as o:

o.write(ET.tostring(pd))

 

if __name__ == "__main__":

main()

Have more questions? Submit a request

0 Comments

Article is closed for comments.
Powered by Zendesk