The File Analysis Suite includes the ability to export collections from a workbook to an FTP location or even send to a file system target. Both options involve calling the FAS Agent (typically installed on-premise) to retrieve the data from the source location and send to the FAS hosted tenant. You can also view all the items in a workbook and export metadata to CSV. Thus, you have a directory of all the collected items pertaining to a workbook and a metadata report in CSV to match. In a simplistic way, this achieves the start of a FOIA collection process.
With the introduction of custom workbook activities, we have possibilities to streamline this collection and reporting into a single action. In fact, we can even bypass invoking the FAS agent to retrieve data if we can programmatically access the source data directly. In this example, we'll show how we can leverage a custom workbook activity to retrieve all items of a Workbook and copy them directly from a File System repository to another file share and generate a set of reports at the same time. The example is written for File System repositories only.
The example uses PowerShell to query your FAS tenant for any workbooks that have a pending custom activity assigned called "foia-1". It then retrieves the list of files and directly copies them to another fileshare path and writes out file properties to CSV as well as to a custom PDF (using an opensource library, iTextSharp and a PowerShell example found on GitHub).
Video to come soon ...
################################################################################################
# FAS Custom Activity - FOIA Collection and Report for File System repositories only
# Retrieves files from a custom workbook activity and copies them directly from the source
# file system to the a new fileshare path. It also writes out metadata details to a CSV file
# and generates a PDF report using the opensource iTextSharp library and a PowerShell example
# from GitHub at https://github.com/dendory/PowerShell-PDF/blob/master/PDF.psm1
# This script looks for workbooks that have a pending custom activity of “foia-1” assigned
################################################################################################
#Export Directory Details
$export = "false"
$exportRootDir = "\\fileshare_path_for_exported_files"
#Create PDF Report
$pdfReport = "true"
$reportTime = Get-Date -Format "dd-MM-yyyy-HH.mm"
if ($pdfReport -eq "true")
{
#Importing itextsharp PDF library and establishing report file including title and logo
Add-Type -Path “$PSScriptRoot\itextsharp.dll”
Import-Module "$PSScriptRoot\PDF.psm1"
$pdf = New-Object iTextSharp.text.Document
Create-PDF -Document $pdf -File "$PSScriptRoot\Custom-Report - $reportTime.pdf" -TopMargin 20 -BottomMargin 20 -LeftMargin 20 -RightMargin 20 -Author "Patrick"
$pdf.Open()
Add-Image -Document $pdf -File "$PSScriptRoot\CyberRes.png"
Add-Title -Document $pdf -Text "FAS Custom Activity Workbook Report - $reportTime" -Color "blue" -Centered
}
$outPutCSV = "$PSScriptRoot\Custom-Report - $reportTime.csv"
New-Item -Force -Path $outPutCSV
Add-Content -Path $outPutCSV -Value "FOIA Collection Items - $reportTime"
Write-Host -ForegroundColor Cyan "FAS Custom Report Start Time: " $reportTime
#Tenant URL
$uri = "YOURTENANT_URL
#Tenant Credentials and Authentication
Write-Output "--Attempting Login"
$auth = @'
{
"tenantId":"YOURTENANT_ID",
"user":"YOURTENANT_USERNAME",
"password":"YOURTENANT_PASSWORD!"
}
'@
$header = @{
"Content-Type"="application/json"
"accept"="application/json"
}
$answer = Invoke-RestMethod -Uri $uri"v1/auth/login" -Method 'Post' -Body $auth -Headers $header
$fasAccessToken=$answer.accessToken
$fasRefreshToken=$answer.refreshToken
Write-Output "Access Token - " $fasAccessToken
Write-Output "Refresh Token - " $fasRefreshToken
#Retrieve Workbooks in a pending state
Write-Output "--Get Pending workbooks"
$header = @{
"Content-Type"="application/json"
"accept"="application/json"
"Authorization"="Bearer $fasAccessToken"
}
$fasWorkbook = Invoke-RestMethod -Uri $uri"ca/v1/workspace/custom-activity-workbooks/foia-1?processingStatus=Pending" -Method 'Get' -Headers $header
$fasWorkbookId = $fasWorkbook.id
$fasWorkbookWorkspaceId = $fasWorkbook.workspaceId
Write-Output $fasWorkbook.name
#Introduce a sleep to show the status change in the FAS Web UI that the workbook is in a pending state
start-sleep -Seconds 5
#Update status of pending workbook to processing
Write-Output "--Set status to Processing for workbook"
$body = @'
{
"status":"Processing",
"successCount":0,
"errorCount":0
}
'@
$header = @{
"Content-Type"="application/json"
"accept"="application/json"
"Authorization"="Bearer $fasAccessToken"
}
$answer = Invoke-RestMethod -Uri $uri"ca/v1/case/$fasWorkbookWorkspaceId/workbook/$fasWorkbookId/custom-activity/foia-1" -Method 'Put' -Body $body -Headers $header
#Introduce a sleep to show the status change in the FAS Web UI that the workbook is in a processing state
#start-sleep -Seconds 5
#Retrieve documents from pending workbook
Write-Output "--Get list of documents"
$header = @{
"accept"="application/json"
"Authorization"="Bearer $fasAccessToken"
}
$answer = Invoke-RestMethod -Uri $uri"ca/v1/case/$fasWorkbookWorkspaceId/workbook/$fasWorkbookId/documents?queryFields=repository_id%2Ctitle%2Cfile_size%2Cfilepath%2Cfile_ext%2Crepository_type&limit=1000" -Method 'Get' -Headers $header
$workbookName = $fasWorkbook.name
if ($export -eq "true")
{
#Create Directory for Export
Write-Host -ForegroundColor Cyan "Export files set to true, creating export directory"
$exportFolder = "$workbookName - $fasWorkbookId - $reportTime"
New-Item -Path $exportRootDir -Name $exportFolder -ItemType "directory"
$exportFolder = "$exportRootDir\$exportFolder"
if ($pdfReport -eq "true")
{
Add-Text -Document $pdf -Text "Export Files = true" -Color "red"
Write-Host -ForegroundColor Cyan "Export Folder set to: " $exportFolder
Add-Text -Document $pdf -Text "Export Folder set to: $exportFolder" -Color "red"
}
}
Else
{
Write-Host -ForegroundColor Cyan "Export files set to false, not creating export directory"
if ($pdfReport -eq "true")
{
Add-Text -Document $pdf -Text "Export Files = false"-Color "red"
}
}
if ($pdfReport -eq "true")
{
#Write out Workbook and Workspace as subtitle
Write-Host -ForegroundColor Cyan "Workspace ID: " $fasWorkbookWorkspaceId
Write-Host -ForegroundColor Cyan "Workbook Name: " $fasWorkbook.name
Write-Host -ForegroundColor Cyan "Workbook ID: " $fasWorkbook.id
Add-Text -Document $pdf -Text "Workspace ID: $fasWorkbookWorkspaceId" -Color "red"
Add-Text -Document $pdf -Text "Workbook Name: $workBookName" -Color "red"
Add-Text -Document $pdf -Text "Workbook ID: $fasWorkbookId" -Color "red"
}
#Iterates through each item in workbook and writes out details to report
ForEach ($i in $answer.documentMetadataList)
{
$fileName = $i.metadata.title
Write-Host -ForegroundColor Cyan "Collecting metadata: " $i.metadata.filepath
Write-Host -ForegroundColor Cyan "Filename : " $fileName
if ($pdfReport -eq "true")
{
Add-Text -Document $pdf -Text "File Name - $fileName"
Add-Table -Document $pdf -Dataset @("File Path", $i.metadata.filepath, "File Extension", $i.metadata.file_ext, "File Size", $i.metadata.file_size, "Document ID", $i.documentId) -Cols 2 -Centered
}
$docPath = $i.metadata.filepath
$docExt = $i.metadata.file_ext
$docSize = $i.metadata.file_size
$docId = $i.documentId
$lineEntry = "$docId,$fileName,$docPath,$docExt,$docSize"
Add-Content -Path $outPutCSV -Value $lineEntry
#Copies file over to FOIA collection folder and prepends the FAS doc ID to the name. Only copies files in repositories of type FILESYSTEM
if ($export -eq "true" -And $i.metadata.repository_type -eq "FILESYSTEM")
{
Copy-Item $i.metadata.filepath -Destination "$exportFolder\$docId-$filename"
}
}
#Set status of workbook to completed
Write-Output "--Set workbook status to Completed"
$body = @'
{
"status":"Completed",
"successCount":0,
"errorCount":0
}
'@
$header = @{
"Content-Type"="application/json"
"accept"="application/json"
"Authorization"="Bearer $fasAccessToken"
}
$answer = Invoke-RestMethod -Uri $uri"ca/v1/case/$fasWorkbookWorkspaceId/workbook/$fasWorkbookId/custom-activity/foia-1" -Method 'Put' -Body $body -Headers $header
#Log out of FAS tenant API
Write-Output "--Logout"
$header = @{
"Content-Type"="text/plain"
"accept"="application/json"
}
$answer = Invoke-RestMethod -Uri $uri"v1/auth/logout" -Method 'Post' -Body $fasRefreshToken -Headers $header
if ($pdfReport -eq "true")
{
$pdf.Close()
}