JBAS-1643 Teacher districts must be enabled
authorBill Erickson <berickxx@gmail.com>
Wed, 16 Nov 2016 16:15:29 +0000 (11:15 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Before the SFTP client will process a teacher account file, the district
code must be added to a new TEACHER_DISTRICTS configuration list at the
top of the file.

Also, the SFTP client not skips any files not conforming to the correct
csv file name convention.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/utility-scripts/import_students/sftp-client-agent.sh

index 8b5a523..4fe654e 100755 (executable)
@@ -38,6 +38,12 @@ DISTRICT_CODES=(
     417 # Northshore
 );
 
+# Hard-code the districts eligible for automatic teacher account processing.
+TEACHER_DISTRICTS=(
+    408 # Auburn
+    415 # Kent
+)
+
 function usage {
 
     cat <<USAGE
@@ -47,7 +53,7 @@ function usage {
             $0 -d 415 -l
 
         Options:
-            
+
             -s SFTP Server Hostname
 
             -u SFTP User
@@ -57,7 +63,7 @@ function usage {
             -l List Pending Files
 
             -p Process selected files
-            
+
             -f Fetch pending files
 
             -b Database server
@@ -138,16 +144,35 @@ for code in "${DISTRICT_CODES[@]}"; do
 
         for FILE in $($SSH "$COMMAND -l"); do
             LOCAL_FILE=$(basename $FILE)
+            TEACHER_FLAG=""
 
-            announce "Retrieving file $FILE"
-            $SCP:$FILE $LOCAL_FILE
+            announce "Inspecting file $FILE"
 
-            TEACHER_FLAG=""
-            if [[ $LOCAL_FILE =~ 'teacher' ]]; then
-                announce "Processing a teacher file"
-                TEACHER_FLAG="--teacher"
+            # File format examples:
+            # 415.2016-03-18.csv
+            # 415.teacher.2016-03-18.csv
+            if [[ $LOCAL_FILE =~ ^[0-9]{3}.[0-9]{4}-[0-9]{2}-[0-9]{2}.csv$ ]]; then
+                announce "Found a student file."
+            else
+                if [[ $LOCAL_FILE =~ ^[0-9]{3}.teacher.[0-9]{4}-[0-9]{2}-[0-9]{2}.csv$ ]]; then
+                    announce "Found a teacher file."
+
+                    if [[ " ${TEACHER_DISTRICTS[@]} " =~ " $code " ]]; then
+                        announce "Processing a teacher file"
+                        TEACHER_FLAG="--teacher"
+                    else
+                        announce "District $code not configured for teacher file processing.  Skipping."
+                        continue;
+                    fi
+                else
+                    announce "File has invalid name.  Skipping"
+                    continue;
+                fi
             fi
 
+            announce "Retrieving file $FILE"
+            $SCP:$FILE $LOCAL_FILE
+
             announce "Processing file $LOCAL_FILE"
             INFO=$(perl ./generate-patrons-from-csv.pl \
                 --log-stdout $TEACHER_FLAG \