#!/bin/bash # # Convert "doctype mapping" CSV to json # Current assumes Mission Global output mapping # # Usage: dtm2json.sh /path/to/csvfile FILE=$1 if [ ! -f "${FILE}" ]; then echo "Input file '${FILE}' not found" echo "Usage: dtm2json.sh /path/to/csv" exit 2 fi cat << EOF // GENERATED FILE - DO NOT EDIT // Created on: `date` { "jobType": "LOAN", "fileType": "DocTypeMappings", "name": "MISSION GLOBAL", // TransformBot :: // 1. The doctype itself is just data within sdc.classification.value.doctype // 2. The filename is assumed (really required) to include a zero padded 4 digit prefix (0001); // optional unique sequence alpha chars (yzz); an underscore and then doctype duplicated from #1 // The logic // 3. The full set of mappings[x] are run against all SDCs and they control many (SLI) to one (customer) // doctype mappings which change the doctype for every sdc ALONG with // changing the actual filename whilst preserving the filename prefix // 4. Finally, the output_naming_rules are applied IN ORDER to munge the output name // OutflowBot :: // 1. Given renamed sdc/doctype model, outflow will write flat or if directed via workflow_config, // hierarchical output using mappings[x].category values // 2. The category names can be prepended or appended using output_naming_rules.category_prefix/suffix // which use subset of substitutions as shown below, namely only {p}, {j} and literal text "output_naming_rules":{ // Prepend (or append) these to all doctype names this is an amalgam of: // * a NumberFormat -- 0000 is the normative SLEDS value // * the token: {%} (the alpha sequence chars) // * the token: {n} (the orig 4 digit sequence) // * the token: {p} (the package name) // * the token: {j} (the job name) // * the token: {*:',#'#} if a subdoc type exists more than once, // append a unique count based on subdoc type occurence indicated by NumberFormat following colon // * a literal that does not have a 0/#/{x} substring // if namePrefix is omitted original name is used // use 0000{%}_ to match default SLEDS behavior "prefix": ["{p}", " - "], "suffix": ["{*:' #'#}"], // Next two apply to mapped doctype itself "upperCase": false, "lowerCase": false, // category naming only "category_prefix": ["{p}", " - "] }, EOF /sl/bin/csv2json.sh --json=mappings --file="${FILE}" 2>/dev/null | awk ' /^{\"mappings\":\[/ { printf "\"mappings\":[\n" next } { print $0 } '