Skip to content

Commit 542608c

Browse files
DongbumleeTejasri-Microsoft
authored andcommitted
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 e24b1da commit 542608c

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
@@ -311,6 +311,7 @@ Schema registration happens **automatically** as part of the `azd up` post-provi
311311
2. Registers the sample schema files (auto claim, damaged car image, police report, repair estimate)
312312
3. Creates an **"Auto Claim"** schema set
313313
4. Adds all registered schemas into the schema set
314+
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
314315

315316
After successful deployment, the terminal displays container app details and schema registration output:
316317

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

364387
### 5.2 Configure Authentication (Automatic)
@@ -420,10 +443,12 @@ The automation is fully compatible with the WAF / production profile (`main.waf.
420443
421444
### 5.4 Test the Application
422445
446+
> **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.
447+
423448
**Quick Test Steps:**
424-
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.
425-
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.
426-
3. **Review**: Wait for completion (~1 min), then click the row to verify the extracted data against the source document.
449+
1. **Check Processed Results**: Open the web appyou should see the two sample claim batches already processed with extracted data.
450+
2. **Review**: Click a processed claim row to verify the extracted data against the source document.
451+
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.
427452
428453
📖 **Detailed Instructions:** See the complete [Golden Path Workflows](./GoldenPathWorkflows.md) guide for step-by-step testing procedures.
429454

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

243371
# --- Configure Entra ID authentication (app registrations + EasyAuth) ---

0 commit comments

Comments
 (0)