Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
- Add OMNL/CBK Indonesia submission and audit binder docs, manifests, attestations - Add scripts/omnl transaction-package pipeline, LEI/PvP helpers, jq/lib fixtures - Update entity master data, MASTER_INDEX, TODOS, dbis-rail docs and rulebook - Add proof_package/regulatory skeleton and transaction package zip + snapshot JSON - validate-omnl-rail workflow, forge-verification-proxy tweak, .gitignore hygiene - Bump smom-dbis-138 (cronos verify docs/scripts) and explorer-monorepo (SPA + env report) Made-with: Cursor
117 lines
4.7 KiB
Bash
117 lines
4.7 KiB
Bash
#!/usr/bin/env bash
|
||
# OMNL Fineract — Populate the 15 operating entities as Offices (Organization / Manage Offices).
|
||
# Updates office 1 name to entity 1; creates offices 2–15 as children of office 1 with entity names.
|
||
# LEI is not a native Fineract office field; regulator-facing LEI is carried in OMNL_ENTITY_MASTER_DATA.json
|
||
# and joined to offices in omnl_transaction_package_snapshot.json (see scripts/omnl/jq/enrich-snapshot-entity-master.jq).
|
||
# LEI, EBICS, BIC, etc. may still be entered on the office/entity in the UI using memo or Address2/3-style fields; see OMNL_ENTITY_MASTER_DATA.md (section 2b).
|
||
# Usage: run from repo root; sources omnl-fineract/.env or .env.
|
||
# ENTITY_DATA=<path> JSON entity data (default: docs/04-configuration/mifos-omnl-central-bank/OMNL_ENTITY_MASTER_DATA.json)
|
||
# DRY_RUN=1 print only, do not PUT/POST.
|
||
# OPENING_DATE yyyy-MM-dd for new offices (default: 2026-01-01)
|
||
# Requires: curl, jq.
|
||
|
||
set -euo pipefail
|
||
REPO_ROOT="${REPO_ROOT:-$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)}"
|
||
DRY_RUN="${DRY_RUN:-0}"
|
||
ENTITY_DATA="${ENTITY_DATA:-${REPO_ROOT}/docs/04-configuration/mifos-omnl-central-bank/OMNL_ENTITY_MASTER_DATA.json}"
|
||
OPENING_DATE="${OPENING_DATE:-2026-01-01}"
|
||
|
||
if [ ! -f "$ENTITY_DATA" ]; then
|
||
echo "Entity data file not found: $ENTITY_DATA" >&2
|
||
exit 1
|
||
fi
|
||
|
||
if [ -f "${REPO_ROOT}/omnl-fineract/.env" ]; then
|
||
set +u
|
||
source "${REPO_ROOT}/omnl-fineract/.env" 2>/dev/null || true
|
||
set -u
|
||
elif [ -f "${REPO_ROOT}/.env" ]; then
|
||
set +u
|
||
source "${REPO_ROOT}/.env" 2>/dev/null || true
|
||
set -u
|
||
fi
|
||
|
||
BASE_URL="${OMNL_FINERACT_BASE_URL:-}"
|
||
TENANT="${OMNL_FINERACT_TENANT:-omnl}"
|
||
USER="${OMNL_FINERACT_USER:-app.omnl}"
|
||
PASS="${OMNL_FINERACT_PASSWORD:-}"
|
||
|
||
if [ -z "$BASE_URL" ] || [ -z "$PASS" ]; then
|
||
echo "Set OMNL_FINERACT_BASE_URL and OMNL_FINERACT_PASSWORD (e.g. in omnl-fineract/.env)" >&2
|
||
exit 1
|
||
fi
|
||
|
||
CURL_OPTS=(-s -S -H "Fineract-Platform-TenantId: ${TENANT}" -H "Content-Type: application/json" -u "${USER}:${PASS}")
|
||
|
||
offices_json=$(curl "${CURL_OPTS[@]}" "${BASE_URL}/offices")
|
||
# Response is array of offices
|
||
if ! echo "$offices_json" | jq -e 'type == "array"' >/dev/null 2>&1; then
|
||
echo "Unexpected offices response." >&2
|
||
exit 1
|
||
fi
|
||
|
||
# 1. Update office 1 name to entity 1
|
||
entity1_name=$(jq -r '.entities[] | select(.clientNumber == 1) | .entityName' "$ENTITY_DATA")
|
||
if [ -z "$entity1_name" ] || [ "$entity1_name" = "null" ]; then
|
||
echo "Entity 1 name not found in $ENTITY_DATA" >&2
|
||
exit 1
|
||
fi
|
||
|
||
echo "=== Office 1 (Head Office) ===" >&2
|
||
payload1=$(jq -n \
|
||
--arg name "$entity1_name" \
|
||
--arg openingDate "$OPENING_DATE" \
|
||
'{ name: $name, openingDate: $openingDate, dateFormat: "yyyy-MM-dd", locale: "en" }')
|
||
if [ "$DRY_RUN" = "1" ]; then
|
||
echo " [DRY RUN] PUT offices/1 name=$entity1_name" >&2
|
||
else
|
||
res=$(curl "${CURL_OPTS[@]}" -X PUT -d "$payload1" "${BASE_URL}/offices/1" 2>/dev/null) || true
|
||
if echo "$res" | jq -e '.resourceId // .officeId' >/dev/null 2>&1; then
|
||
echo " Updated office 1 name to: $entity1_name" >&2
|
||
else
|
||
echo " PUT office 1 response: $res" >&2
|
||
fi
|
||
fi
|
||
|
||
# 2. Create offices 2–N as children of office 1 (N = max clientNumber in entity data)
|
||
created=0
|
||
skipped=0
|
||
for num in $(jq -r '.entities[] | select(.clientNumber >= 2) | .clientNumber' "$ENTITY_DATA" 2>/dev/null | sort -n | uniq); do
|
||
entity_name=$(jq -r --argjson n "$num" '.entities[] | select(.clientNumber == $n) | .entityName' "$ENTITY_DATA")
|
||
if [ -z "$entity_name" ] || [ "$entity_name" = "null" ]; then
|
||
echo "Skip: no entity $num in data" >&2
|
||
continue
|
||
fi
|
||
ext_id="OMNL-$num"
|
||
existing=$(echo "$offices_json" | jq -r --arg e "$ext_id" '.[] | select(.externalId == $e) | .id' 2>/dev/null | head -1)
|
||
if [ -n "$existing" ] && [ "$existing" != "null" ]; then
|
||
echo "Skip office $num: already exists (externalId=$ext_id, id=$existing)" >&2
|
||
((skipped++)) || true
|
||
continue
|
||
fi
|
||
|
||
payload=$(jq -n \
|
||
--arg name "$entity_name" \
|
||
--arg openingDate "$OPENING_DATE" \
|
||
--arg externalId "$ext_id" \
|
||
'{ name: $name, parentId: 1, openingDate: $openingDate, externalId: $externalId, dateFormat: "yyyy-MM-dd", locale: "en" }')
|
||
|
||
echo "Create office $num: $entity_name (externalId=$ext_id)" >&2
|
||
if [ "$DRY_RUN" = "1" ]; then
|
||
echo " [DRY RUN] POST offices" >&2
|
||
((created++)) || true
|
||
continue
|
||
fi
|
||
|
||
res=$(curl "${CURL_OPTS[@]}" -X POST -d "$payload" "${BASE_URL}/offices" 2>/dev/null) || true
|
||
if echo "$res" | jq -e '.resourceId // .officeId' >/dev/null 2>&1; then
|
||
new_id=$(echo "$res" | jq -r '.resourceId // .officeId')
|
||
echo " Created officeId=$new_id" >&2
|
||
((created++)) || true
|
||
else
|
||
echo " Failed: $res" >&2
|
||
fi
|
||
done
|
||
|
||
echo "Done: office 1 updated, $created new offices created, $skipped skipped (already existed)." >&2
|