Skip to main content
Continuing Online Operations
Loyola is continuing online operations while we prepare for reopening safely in the fall. Coronavirus resources

Blackboard Interface from LORA (Student Information System): Edit & Filter

Preparing Data for Upload to Blackboard

The captured contents of the WebFOCUS reports must be edited, filtered, and rearranged to meet the needs of Blackboard. The PowerShell code for that editing follows:


########################################################################################
# PREPARE SNAPSHOT FILES FOR POSTING TO BLACKBOARD #
########################################################################################
Function ExplodeLine ($RawLine) { # Convert a report line into an array of fields
$ExlodedLine = @() # Empty Array of Strings
$EmptyArray = @() # This one will stay empty
$DoubleQuote = '"'
$Comma = ','
$Pipe = '|'
$DelimitedLine = ''
If ($RawLine.Substring(0,1) -ne $DoubleQuote) {Return $ExplodedLine} # Not a Data Line if first character is not a double-quote mark
For ($i=0; $i -lt $RawLine.length; $i++) { # Mark field boundaries with pipe character
If (($RawLine[$i] -eq $Comma) -and ($RawLine[$i+1] -eq $DoubleQuote)) {$DelimitedLine += $Pipe}
Else {$DelimitedLine += $RawLine[$i]}
}
$ExplodedLine = $DelimitedLine.Split($Pipe) # Split the line into a an array of string fields
If ($ExplodedLine.count -lt 2) {Return $EmptyArray} # This isn't real data if there aren't at least two fields
For ($i=0; $i -lt $ExplodedLine.count; $i++) {
$Field = $ExplodedLine[$i].Trim()
If ($Field.Length -gt 1) {
If ($Field.Substring(0,1) -eq $DoubleQuote) {$Field = $Field.Substring(1,$Field.length - 1)} # Remove opening double-quote
If ($Field.Substring($Field.Length - 1, 1) -eq $DoubleQuote) {$Field = $Field.Substring(0,$Field.Length-1)} # Remove Closing double-quote
}
$Field = $Field.Trim()
If ($i -eq 0) {$Field = $Field.Replace(' ','')} #Remove internal spaces from first field only (might be course ID)
If ($Field -eq 'P') {$Field = 'Instructor'} #This is the instructor flag in instructor enrollments
If ($Field -eq 'S') {$Field = 'Student'} # This is the student flag in student enrollments
$ExplodedLine[$i] = $Field
}
If ($ExplodedLine[0] -and $ExplodedLine[1]) {Return $ExplodedLine} #If two first fields are not-null, return the whole array.
Return $EmptyArray # If either of the first two fields are null, discard the whole line
}
Function FieldContainsCourseID ($Field) { # Check if the passed field is formatted as a Course ID
$TestArray = @()
$TestArray = $Field.Split('-')
IF ($TestArray.count -eq 4) {Return $True} #Four dashes indicates Course ID
Return $False
}
Function CourseIsExcluded ($Field, [array]$FilterStrings){
ForEach ($FilterString in $FilterStrings) {
If ($Field -like $FilterString) {Return $True} # The field contains a string like one of the exclusion filters
}
Return $False # The field contains none of the exclusion strings
}
Function BuildNewLine ([array]$Fields, $FieldList, $DupeFirst) { # Create a delimited string based on an array of string fields
$NewLine = ''
$Pipe = '|'
If ($Fields.count -lt 1) {Return $NewLine}
For ($i=0; $i -lt $Fields.count; $i++) {
If ($FieldList.Contains([string]($i + 1))) { # Add the field only if the number of the field is in the list of fields to process
If ($NewLine) {$NewLine += $Pipe}
Elseif ($DupeFirst) {
$NewLine += $Fields[$i]
$NewLine += $Pipe
}
$NewLine += $Fields[$i]
}
}
Return $NewLine
}
#
# MAIN PROGRAM
#
Write-Host -ForegroundColor Green "Prepare Snapshot Files for upload to Blackboard."
#
# READ PARAMETERS FILE AND CHECK THAT DIRECTORIES EXIST
#
$Pipe = '|'
$HomeDir
$WFDir = ''
$BBDir = ''
$RenameFrom = ''
$RenameTo = ''
$CourseFilters = @()
$ParamsFileName = 'SISIntegrationParameters.txt'
$HeaderCourses = ''
$HeaderUsers = ''
$HeaderEnroll = ''
If (-not (Test-Path $ParamsFileName)) {
Write-Host -foregroundcolor Green 'Paramaters File Not Found.'
Exit
}
$ParamsFile = Get-Content $ParamsFileName
ForEach ($Line in $ParamsFile) {
$Title = $Line.Split($Pipe)[0]
$Value = $Line.Split($Pipe)[1]
switch ($Title)
{
'HomeDir' {$HomeDir = $Value.Trim()}
'WFDir' {$WFDir = $Value.Trim()}
'BBDir' {$BBDir = $Value.Trim()}
'FNameCourses' {$FNameCourses = $Value.Trim()}
'FNameInstructors' {$FNameInstructors = $Value.Trim()}
'FNameStudents' {$FNameStudents = $Value.Trim()}
'FNameEnrollInst' {$FNameEnrollInst = $Value.Trim()}
'FNameEnrollStud' {$FNameEnrollStud = $Value.Trim()}
'FieldPatternCourses' {$FieldPatternCourses = $Value.Trim()}
'FieldPatternInstructors' {$FieldPatternInstructors = $Value.Trim()}
'FieldPatternStudents' {$FieldPatternStudents = $Value.Trim()}
'FieldPatternEnrollInst' {$FieldPatternEnrollInst = $Value.Trim()}
'FieldPatternEnrollStud' {$FieldPatternEnrollStud = $Value.Trim()}
'RenameFrom' {$RenameFrom = $Value.Trim()}
'RenameTo' {$RenameTo = $Value.Trim()}
'HeaderCourses' {$HeaderCourses = $Value.trim() -replace ",", "|"}
'HeaderUsers' {$HeaderUsers = $Value.trim() -replace ",", "|"}
'HeaderEnroll' {$HeaderEnroll = $Value.trim() -replace ",", "|"}
'Course ID Filter' {$CourseFilters += $Value.Trim()}
}
}
If (-not (Test-Path $WFDir)) {
Write-Host -foregroundcolor Red 'WebFOCUS Directory Not Found!'
Exit
}
If (-not (Test-Path $BBDir)) {
Write-Host -foregroundcolor Red 'BlackBoard Directory Not Found!'
Exit
}
#
# Set Up Voice Synthesizer
#
Add-Type -AssemblyName System.speech
$Synth = New-Object System.Speech.Synthesis.SpeechSynthesizer
$Synth.Rate = 0
$Msg = "Preparing Snapshot files for upload to Blackboard."
Write-Host -ForegroundColor Green $Msg
$Synth.Speak($Msg)
Set-Location $BBDir
Remove-Item "*.txt"
New-Item -path . -name $FNameCourses -itemtype "file"
New-Item -path . -name $FNameInstructors -itemtype "file"
New-Item -path . -name $FNameStudents -itemtype "file"
New-Item -path . -name $FNameEnrollInst -itemtype "file"
New-Item -path . -name $FNameEnrollStud -itemtype "file"
$MustFilterCourses = $False
$DupeFirst = $False
$FieldLimit = 0
$Msg = ''
$OutputHeader = ''
for($i=1; $i -le 5; $i++){
Switch ($i) {
1 { $InputFileName = $WFDir + $FNameCourses
$OutputFileName = $BBDir + $FNameCourses
$OutputHeader = $HeaderCourses
$FieldPattern = $FieldPatternCourses
$DupeFirst = $True
$Msg = 'Processing Courses.'}
2 { $InputFileName = $WFDir + $FNameInstructors
$OutputFileName = $BBDir + $FNameInstructors
$OutputHeader = $HeaderUsers
$FieldPattern = $FieldPatternInstructors
$DupeFirst = $True
$Msg = 'Processing Instructors.'}
3 { $InputFileName = $WFDir + $FNameStudents
$FieldPattern = $FieldPatternStudents
$OutputFileName = $BBDir + $FNameStudents
$OutputHeader = $HeaderUsers
$DupeFirst = $True
$Msg = 'Processing Students.'}
4 { $InputFileName = $WFDir + $FNameEnrollInst
$FieldPattern = $FieldPatternEnrollInst
$OutputFileName = $BBDir + $FNameEnrollInst
$OutputHeader = $HeaderEnroll
$DupeFirst = $False
$Msg = 'Processing Instructor Enrollments.'}
5 { $InputFileName = $WFDir + $FNameEnrollStud
$FieldPattern = $FieldPatternEnrollStud
$OutputFileName = $BBDir + $FnameEnrollStud
$OutputHeader = $HeaderEnroll
$DupeFirst = $False
$Msg = 'Processing Student Enrollments. This may take a moment.'}
}
Write-Host -foregroundcolor Green $Msg
$Synth.Speak($Msg)
$InputFile = New-Object System.IO.StreamReader -Arg $InputFileName
$OutputFile = New-Object System.IO.StreamWriter -Arg $OutputFileName
$OutputHeader = $OutputHeader + "`r`n" # Add CRLF
$OutputFile.Write($OutputHeader)
While ($InputLine = $InputFile.ReadLine()) {
$InputFields = @()
$InputFields = ExplodeLine($InputLine)
If ($InputFields.count -gt 1) {
$OKToProcess = $True
If (FieldContainsCourseID $InputFields[0]) {
IF (CourseIsExcluded $InputFields[0] $CourseFilters) {$OKToProcess = $False}
}
If ($OKToProcess) {
$OutputLine = ''
$OutputLine = BuildNewLine $InputFields $FieldPattern $DupeFirst
If ($OutputLine) {
$OutputLine = $OutputLine + "`r`n" # Add Carriage Return and Line Feed at end of line
$OutputFile.Write($OutputLine)
}
}
}
}
$InputFile.Close()
$OutputFile.Close()
}
$FileNames = Get-ChildItem -Filter '*.txt'
ForEach ($Filename in $Filenames) {
$NewFName = $Filename -replace $RenameFrom, $RenameTo
Rename-Item $Filename $NewFName
}
#
# WRAPUP
#
Get-ChildItem -Path $WFDir
Get-ChildItem -Path $BBDir
$Msg = "Preparation of Snapshot Files Complete."
Write-Host -ForegroundColor Green $Msg
$Synth.Speak($Msg)