Skip to content

Commit ea45b00

Browse files
committed
feat: add sample file processing as post-deployment step 4
- Add bundle_info.json manifests for claim_date_of_loss and claim_hail - Add Step 4 to post_deployment.ps1 and post_deployment.sh - Creates claim batch with schemaset ID - Uploads files with mapped schema IDs - Submits batch for workflow processing - Update DeploymentGuide.md with new step and sample output - Update AVMPostDeploymentGuide.md with manual sample processing instructions - Normalize output prefixes: ASCII dashes for ps1, emojis for sh
1 parent b87a14b commit ea45b00

6 files changed

Lines changed: 330 additions & 23 deletions

File tree

docs/AVMPostDeploymentGuide.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ This document provides guidance on post-deployment steps after deploying the Con
1111
After successfully deploying the Content Processing Solution Accelerator using the AVM template, you need to:
1212

1313
1. **Register schemas** — upload schema files, create a schema set, and link them together
14-
2. **Configure authentication** — set up app registration for secure access
14+
2. **Process sample files** — upload and process sample claim bundles for verification
15+
3. **Configure authentication** — set up app registration for secure access
1516

16-
> **Note:** When deploying via `azd up`, schema registration happens automatically through a post-provisioning hook. AVM deployments require the manual steps below.
17+
> **Note:** When deploying via `azd up`, schema registration and sample processing happen automatically through a post-provisioning hook. AVM deployments require the manual steps below.
1718
1819
## Prerequisites
1920

@@ -73,14 +74,27 @@ The script is idempotent — it skips schemas and schema sets that already exist
7374

7475
> **Want custom schemas?** See [Customize Schema Data](./CustomizeSchemaData.md) to create your own document schemas.
7576
76-
### Step 4: Configure Authentication (Required)
77+
### Step 4: Process Sample File Bundles (Optional)
78+
79+
After schema registration, you can upload and process the included sample claim bundles to verify the deployment is working end to end. Each sample folder (`claim_date_of_loss/`, `claim_hail/`) contains a `bundle_info.json` manifest that maps files to their schema classes.
80+
81+
The workflow for each bundle:
82+
1. **Create a claim batch** with the schema set ID via `PUT /claimprocessor/claims`
83+
2. **Upload each file** with its mapped schema ID via `POST /claimprocessor/claims/{claim_id}/files`
84+
3. **Submit the batch** for processing via `POST /claimprocessor/claims`
85+
86+
You can perform these steps via the web UI or the API directly. See the [API documentation](./API.md) and [Golden Path Workflows](./GoldenPathWorkflows.md) for details.
87+
88+
> **Note:** When deploying via `azd up`, sample file processing happens automatically as Step 4 of the post-provisioning hook.
89+
90+
### Step 5: Configure Authentication (Required)
7791

7892
**This step is mandatory for application access:**
7993

8094
1. Follow [App Authentication Configuration](./ConfigureAppAuthentication.md).
8195
2. Wait up to 10 minutes for authentication changes to take effect.
8296

83-
### Step 5: Verify Deployment
97+
### Step 6: Verify Deployment
8498

8599
1. Access your application using the Web App URL from your deployment output.
86100
2. Confirm the application loads successfully.

docs/DeploymentGuide.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ Schema registration happens **automatically** as part of the `azd up` post-provi
308308
2. Registers the sample schema files (auto claim, damaged car image, police report, repair estimate)
309309
3. Creates an **"Auto Claim"** schema set
310310
4. Adds all registered schemas into the schema set
311+
5. Processes sample file bundles (`claim_date_of_loss/` and `claim_hail/`) — creates claim batches, uploads files with their mapped schemas, and submits them for processing
311312

312313
After successful deployment, the terminal displays container app details and schema registration output:
313314

@@ -355,7 +356,29 @@ Schema registration process completed.
355356
Schema set ID: <id>
356357
Schemas added: 4
357358
============================================================
358-
✅ Schema registration complete.
359+
360+
============================================================
361+
Step 4: Process sample file bundles
362+
============================================================
363+
364+
📂 Processing bundle: claim_date_of_loss
365+
✅ Claim batch created with ID: <id>
366+
✅ Uploaded 'claim_form.pdf' successfully.
367+
✅ Uploaded 'damage_photo.png' successfully.
368+
✅ Uploaded 'police_report.pdf' successfully.
369+
✅ Uploaded 'repair_estimate.pdf' successfully.
370+
✅ Claim batch '<id>' submitted for processing.
371+
372+
📂 Processing bundle: claim_hail
373+
✅ Claim batch created with ID: <id>
374+
✅ Uploaded 'claim_form.pdf' successfully.
375+
✅ Uploaded 'damage_photo.png' successfully.
376+
✅ Uploaded 'repair_estimate.pdf' successfully.
377+
✅ Claim batch '<id>' submitted for processing.
378+
379+
============================================================
380+
Sample file processing completed.
381+
============================================================
359382
```
360383

361384
### 5.2 Configure Authentication (Required)
@@ -373,10 +396,12 @@ Schema registration process completed.
373396

374397
### 5.4 Test the Application
375398

399+
> **Note:** The post-deployment hook automatically uploads and processes two sample claim bundles (`claim_date_of_loss` and `claim_hail`). You can verify the results in the web app immediately after deployment.
400+
376401
**Quick Test Steps:**
377-
1. **Download Samples**: Get sample files from the [samples directory](../src/ContentProcessorAPI/samples)use the `claim_date_of_loss/` or `claim_hail/` folders for auto claim documents.
378-
2. **Upload**: In the app, select the **"Auto Claim"** schema set, choose a schema (e.g., Auto Insurance Claim Form), click Import Content, and upload a sample file.
379-
3. **Review**: Wait for completion (~1 min), then click the row to verify the extracted data against the source document.
402+
1. **Check Processed Results**: Open the web appyou should see the two sample claim batches already processed with extracted data.
403+
2. **Review**: Click a processed claim row to verify the extracted data against the source document.
404+
3. **Upload More (Optional)**: To test additional uploads, get sample files from the [samples directory](../src/ContentProcessorAPI/samples), select the **"Auto Claim"** schema set, and upload via Import Content.
380405

381406
📖 **Detailed Instructions:** See the complete [Golden Path Workflows](./GoldenPathWorkflows.md) guide for step-by-step testing procedures.
382407

infra/scripts/post_deployment.ps1

Lines changed: 143 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Stop script on any error
22
$ErrorActionPreference = "Stop"
33

4-
Write-Host "[Search] Fetching container app info from azd environment..."
4+
Write-Host "- Fetching container app info from azd environment..."
55

66
# Load values from azd env
77
$CONTAINER_WEB_APP_NAME = azd env get-value CONTAINER_WEB_APP_NAME
@@ -32,25 +32,25 @@ $FullPath = Resolve-Path $DataScriptPath
3232

3333
# Output
3434
Write-Host ""
35-
Write-Host "[Info] Web App Details:"
36-
Write-Host " [OK] Name: $CONTAINER_WEB_APP_NAME"
37-
Write-Host " [URL] Endpoint: $CONTAINER_WEB_APP_FQDN"
38-
Write-Host " [Link] Portal URL: $WEB_APP_PORTAL_URL"
35+
Write-Host "- Web App Details:"
36+
Write-Host " - Name: $CONTAINER_WEB_APP_NAME"
37+
Write-Host " - Endpoint: $CONTAINER_WEB_APP_FQDN"
38+
Write-Host " - Portal URL: $WEB_APP_PORTAL_URL"
3939

4040
Write-Host ""
41-
Write-Host "[Info] API App Details:"
42-
Write-Host " [OK] Name: $CONTAINER_API_APP_NAME"
43-
Write-Host " [URL] Endpoint: $CONTAINER_API_APP_FQDN"
44-
Write-Host " [Link] Portal URL: $API_APP_PORTAL_URL"
41+
Write-Host "- API App Details:"
42+
Write-Host " - Name: $CONTAINER_API_APP_NAME"
43+
Write-Host " - Endpoint: $CONTAINER_API_APP_FQDN"
44+
Write-Host " - Portal URL: $API_APP_PORTAL_URL"
4545

4646
Write-Host ""
47-
Write-Host "[Info] Workflow App Details:"
48-
Write-Host " [OK] Name: $CONTAINER_WORKFLOW_APP_NAME"
49-
Write-Host " [Link] Portal URL: $WORKFLOW_APP_PORTAL_URL"
47+
Write-Host "- Workflow App Details:"
48+
Write-Host " - Name: $CONTAINER_WORKFLOW_APP_NAME"
49+
Write-Host " - Portal URL: $WORKFLOW_APP_PORTAL_URL"
5050

5151
Write-Host ""
52-
Write-Host "[Package] Registering schemas and creating schema set..."
53-
Write-Host " [Wait] Waiting for API to be ready..."
52+
Write-Host "- Registering schemas and creating schema set..."
53+
Write-Host " - Waiting for API to be ready..."
5454

5555
$MaxRetries = 10
5656
$RetryInterval = 15
@@ -61,7 +61,7 @@ for ($i = 1; $i -le $MaxRetries; $i++) {
6161
try {
6262
$response = Invoke-WebRequest -Uri "$ApiBaseUrl/schemavault/" -Method GET -UseBasicParsing -TimeoutSec 10 -ErrorAction Stop
6363
if ($response.StatusCode -eq 200) {
64-
Write-Host " [OK] API is ready."
64+
Write-Host " - API is ready."
6565
$ApiReady = $true
6666
break
6767
}
@@ -229,4 +229,132 @@ if (-not $ApiReady) {
229229
Write-Host "Schema registration process completed."
230230
Write-Host " Schemas registered: $($Registered.Count)"
231231
Write-Host ("=" * 60)
232+
233+
# --- Step 4: Process sample file bundles ---
234+
if ($SchemaSetId -and $Registered.Count -gt 0) {
235+
Write-Host ""
236+
Write-Host ("=" * 60)
237+
Write-Host "Step 4: Process sample file bundles"
238+
Write-Host ("=" * 60)
239+
240+
$SamplesDir = Resolve-Path (Join-Path $ScriptDir "..\..\src\ContentProcessorAPI\samples")
241+
$BundleFolders = @("claim_date_of_loss", "claim_hail")
242+
$ClaimProcessorUrl = "$ApiBaseUrl/claimprocessor/claims"
243+
244+
foreach ($bundle in $BundleFolders) {
245+
$bundleDir = Join-Path $SamplesDir $bundle
246+
$bundleInfoPath = Join-Path $bundleDir "bundle_info.json"
247+
248+
if (-not (Test-Path $bundleInfoPath)) {
249+
Write-Host " Skipping '$bundle' - no bundle_info.json found."
250+
continue
251+
}
252+
253+
Write-Host ""
254+
Write-Host " Processing bundle: $bundle"
255+
256+
$bundleManifest = Get-Content $bundleInfoPath -Raw | ConvertFrom-Json
257+
258+
# Step 4a: Create claim batch with schemaset ID
259+
Write-Host " - Creating claim batch..."
260+
try {
261+
$claimResp = Invoke-RestMethod -Uri $ClaimProcessorUrl -Method PUT `
262+
-ContentType "application/json" `
263+
-Body (@{ schema_collection_id = $SchemaSetId } | ConvertTo-Json) `
264+
-TimeoutSec 30 -ErrorAction Stop
265+
$claimId = $claimResp.claim_id
266+
Write-Host " - Claim batch created with ID: $claimId"
267+
} catch {
268+
Write-Host " - Failed to create claim batch. Error: $_"
269+
continue
270+
}
271+
272+
# Step 4b: Upload each file with its mapped schema ID
273+
Add-Type -AssemblyName System.Net.Http
274+
$httpClient = New-Object System.Net.Http.HttpClient
275+
$httpClient.Timeout = [TimeSpan]::FromSeconds(60)
276+
$uploadSuccess = $true
277+
foreach ($entry in $bundleManifest.files) {
278+
$schemaClass = $entry.schema_class
279+
$fileName = $entry.file_name
280+
$filePath = Join-Path $bundleDir $fileName
281+
282+
if (-not (Test-Path $filePath)) {
283+
Write-Host " - File '$fileName' not found. Skipping."
284+
continue
285+
}
286+
287+
$schemaId = $Registered[$schemaClass]
288+
if (-not $schemaId) {
289+
Write-Host " - No schema ID found for '$schemaClass'. Skipping '$fileName'."
290+
continue
291+
}
292+
293+
Write-Host " - Uploading '$fileName' (schema: $schemaClass)..."
294+
295+
$dataPayload = @{
296+
Claim_Id = $claimId
297+
Schema_Id = $schemaId
298+
Metadata_Id = "sample-$bundle"
299+
} | ConvertTo-Json -Compress
300+
301+
$fileBytes = [System.IO.File]::ReadAllBytes((Resolve-Path $filePath))
302+
$mimeType = switch ([System.IO.Path]::GetExtension($fileName).ToLower()) {
303+
".pdf" { "application/pdf" }
304+
".png" { "image/png" }
305+
".jpg" { "image/jpeg" }
306+
".jpeg" { "image/jpeg" }
307+
default { "application/octet-stream" }
308+
}
309+
310+
try {
311+
$multipartContent = New-Object System.Net.Http.MultipartFormDataContent
312+
$jsonContent = [System.Net.Http.StringContent]::new($dataPayload, [System.Text.Encoding]::UTF8, "application/json")
313+
$jsonContent.Headers.ContentDisposition = [System.Net.Http.Headers.ContentDispositionHeaderValue]::Parse("form-data; name=`"data`"")
314+
$multipartContent.Add($jsonContent, "data")
315+
316+
$fileContent = [System.Net.Http.ByteArrayContent]::new($fileBytes)
317+
$fileContent.Headers.ContentDisposition = [System.Net.Http.Headers.ContentDispositionHeaderValue]::Parse("form-data; name=`"file`"; filename=`"$fileName`"")
318+
$fileContent.Headers.ContentType = [System.Net.Http.Headers.MediaTypeHeaderValue]::Parse($mimeType)
319+
$multipartContent.Add($fileContent, "file", $fileName)
320+
321+
$response = $httpClient.PostAsync("$ClaimProcessorUrl/$claimId/files", $multipartContent).Result
322+
$responseBody = $response.Content.ReadAsStringAsync().Result
323+
324+
if ($response.IsSuccessStatusCode) {
325+
Write-Host " - Uploaded '$fileName' successfully."
326+
} else {
327+
Write-Host " - Failed to upload '$fileName'. HTTP Status: $($response.StatusCode)"
328+
Write-Host " - Error: $responseBody"
329+
$uploadSuccess = $false
330+
}
331+
} catch {
332+
Write-Host " - Failed to upload '$fileName'. Error: $_"
333+
$uploadSuccess = $false
334+
}
335+
}
336+
$httpClient.Dispose()
337+
338+
# Step 4c: Launch processing
339+
if ($uploadSuccess) {
340+
Write-Host " - Submitting claim batch for processing..."
341+
try {
342+
Invoke-RestMethod -Uri $ClaimProcessorUrl -Method POST `
343+
-ContentType "application/json" `
344+
-Body (@{ claim_process_id = $claimId } | ConvertTo-Json) `
345+
-TimeoutSec 30 -ErrorAction Stop | Out-Null
346+
Write-Host " - Claim batch '$claimId' submitted for processing."
347+
} catch {
348+
Write-Host " - Failed to submit claim batch. Error: $_"
349+
}
350+
} else {
351+
Write-Host " - Skipping batch submission due to upload failures."
352+
}
353+
}
354+
355+
Write-Host ""
356+
Write-Host ("=" * 60)
357+
Write-Host "Sample file processing completed."
358+
Write-Host ("=" * 60)
359+
}
232360
}

0 commit comments

Comments
 (0)