-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcreate-batch-letters.sh
More file actions
executable file
·169 lines (148 loc) · 5.28 KB
/
create-batch-letters.sh
File metadata and controls
executable file
·169 lines (148 loc) · 5.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/bash
# Bash wrapper script for creating multiple letter batches
# This script creates 3 batches with different specification-id and group-id values
set -e
# Function to display usage
usage() {
echo "Usage: $0 --supplier-id <supplier-id> --environment <environment> --awsAccountId <aws-account-id> [--count <count>] [--status <status>]"
echo ""
echo "Required parameters:"
echo " --supplier-id Supplier ID for the letters"
echo " --environment Environment (e.g., pr147, main, dev)"
echo " --awsAccountId AWS Account ID for S3 bucket resolution"
echo ""
echo "Optional parameters:"
echo " --count Number of letters per batch (default: 835)"
echo " --missing-count Number of letters with missing PDFs (default: 5)"
echo " --status Letter status (default: PENDING)"
echo " --ttl-hours TTL in hours (default: 13140)"
echo ""
echo "Example:"
echo " $0 --supplier-id supplier-123 --environment pr147 --awsAccountId 820178564574"
echo " $0 --supplier-id supplier-123 --environment main --awsAccountId 820178564574 --count 25 --status ACCEPTED"
echo " $0 --supplier-id supplier-123 --environment main --awsAccountId 820178564574 --count 25 --status ACCEPTED --missing-count 3"
exit 1
}
# Default values
COUNT=835 #3 batches = 2505 letters
MISSING_COUNT=5 # Number of letters with missing PDFs
STATUS="PENDING"
TTL_HOURS=13140 # Approximately 18 months
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--supplier-id)
SUPPLIER_ID="$2"
shift 2
;;
--environment)
ENVIRONMENT="$2"
shift 2
;;
--awsAccountId)
AWS_ACCOUNT_ID="$2"
shift 2
;;
--count)
COUNT="$2"
shift 2
;;
--missing-count)
MISSING_COUNT="$2"
shift 2
;;
--status)
STATUS="$2"
shift 2
;;
--ttl-hours)
TTL_HOURS="$2"
shift 2
;;
-h|--help)
usage
;;
*)
echo "Unknown parameter: $1"
usage
;;
esac
done
# Validate required parameters
if [[ -z "$SUPPLIER_ID" || -z "$ENVIRONMENT" || -z "$AWS_ACCOUNT_ID" ]]; then
echo "Error: Missing required parameters"
echo ""
usage
fi
# Validate status
VALID_STATUSES=("PENDING" "ACCEPTED" "REJECTED" "PRINTED" "ENCLOSED" "CANCELLED" "DISPATCHED" "FAILED" "RETURNED" "FORWARDED" "DELIVERED")
if [[ ! " ${VALID_STATUSES[@]} " =~ " ${STATUS} " ]]; then
echo "Error: Invalid status '$STATUS'. Valid statuses: ${VALID_STATUSES[*]}"
exit 1
fi
# Validate count is a positive number
if ! [[ "$COUNT" =~ ^[1-9][0-9]*$ ]]; then
echo "Error: Count must be a positive integer"
exit 1
fi
# Validate missing count is a positive number
if ! [[ "$MISSING_COUNT" =~ ^[1-9][0-9]*$ ]]; then
echo "Error: Missing count must be a positive integer"
exit 1
fi
echo "Creating letter batches with the following configuration:"
echo " Supplier ID: $SUPPLIER_ID"
echo " Environment: $ENVIRONMENT"
echo " AWS Account ID: $AWS_ACCOUNT_ID"
echo " Count per batch: $COUNT"
echo " Letters missing PDFs count: $MISSING_COUNT"
echo " Status: $STATUS"
echo " TTL Hours: $TTL_HOURS"
echo ""
# Get the directory of this script to run npm from the correct location
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
# Change to the project directory
cd "$PROJECT_DIR"
# Define the batches with different specification and group IDs
BATCHES=(
"integration-specification-english:group-english:test-letter-standard:${COUNT}"
"integration-specification-braille:group-accessible:test-letter-standard:${COUNT}"
"integration-specification-arabic:group-international:test-letter-large:${COUNT}"
"integration-specification-missing-pdf:group-error:none:${MISSING_COUNT}"
)
# Counter for tracking batch creation
BATCH_COUNTER=1
TOTAL_BATCHES=${#BATCHES[@]}
TOTAL_LETTERS=$((COUNT * TOTAL_BATCHES))
echo "Creating $TOTAL_BATCHES batches with $COUNT letters each ($TOTAL_LETTERS total letters)..."
echo ""
# Create each batch
for batch in "${BATCHES[@]}"; do
# Parse specification-id, group-id and batch volume from the batch definition
IFS=':' read -r SPEC_ID GROUP_ID TEST_LETTER BATCH_COUNT <<< "$batch"
echo "[$BATCH_COUNTER/$TOTAL_BATCHES] Creating batch with specification-id: $SPEC_ID, group-id: $GROUP_ID-$SUPPLIER_ID"
# Run the npm command
npm run cli -- create-letter-batch \
--supplier-id "$SUPPLIER_ID" \
--environment "$ENVIRONMENT" \
--awsAccountId "$AWS_ACCOUNT_ID" \
--specification-id "$SPEC_ID" \
--group-id "$GROUP_ID-$SUPPLIER_ID" \
--status "$STATUS" \
--count "$BATCH_COUNT" \
--ttl-hours "$TTL_HOURS" \
--test-letter "$TEST_LETTER"
if [[ $? -eq 0 ]]; then
echo "✓ Batch $BATCH_COUNTER completed successfully"
else
echo "✗ Batch $BATCH_COUNTER failed"
exit 1
fi
echo ""
((BATCH_COUNTER++))
done
echo "🎉 All batches created successfully!"
echo "Total letters created: $TOTAL_LETTERS"
echo "Supplier ID: $SUPPLIER_ID"
echo "Environment: $ENVIRONMENT"