Driver

Introduction
The driver function is created using Spring Boot. If you are unfamiliar with Spring Boot (or if it's just been a while since you've used it), please review the Spring Boot documentation or the series of videos by Spring Framework Guru on YouTube. Links to each (specifically, links 7 and 8) are available in the Additional Reading Section of this documentation.

Class Variables
The two helper variables in the AppApplication class are designed to call their respective class constructors (either createTemplate() or analyzeData() ). This will ensure the credentials that each uses to connect to Google for authentication will have the appropriate callback URIs and tokens.

The remaining variables (referred to as the storage variables throughout this document) are used to store basic information about the spreadsheet being worked on such as the number of students taking the assignment and the name of the assignment itself. This is to ensure that this data can be accessed after the OAuth call has been completed.

main()
Simply put, this function begins the code for the entire project. This will cause the code to run in the background and be ready to accept incoming requests.

createTemplate()
This function takes in the assignmentName, numStudents, and numQuestions variables and stores them in their appropriate storage variable (more on these in the Class Variables section). Then, the URL to access Google's OAuth login is generated and stored in the googleURL variable. Then the user is redirected to this function.

After this point, the user will either be asked to login with their Google credentials or a previously saved credential will be found and used instead. After this, the user will be redirected to the callback URL. The function our code uses to control this is the templateOAuth() function.

templateOAuth()
This function requires the authorization code provided by Google (stored in the authCode variable) to continue. If one is not provided, then the Google OAuth fails and an error page will be shown.

If the authCode is returned successfully however, the code will create the spreadsheet and get the spreadsheet URL using the spreadsheetURL() function. Then, user will be sent to the congratulations() function with the spreadsheet URL passed through to create a link directly to the Google Sheet that contains the completed template.

congratulations()
This function simply returns the congratulations.html page after analysis has been completed.

No further code is run on the spreadsheet until the user clicks the Analysis button in their template. To see this process, see the analyze() function description on this page.

analyze()
When the user has clicked the Analyze button on the template's dashboard, this function will run. It begins by taking in the variables passed in from the Analyze button's URL - each of these are set automatically when the template is created, no action is required on the user's part. Each of these variables is stored in their respective storage variable (see more about these in the Class Variables section of this page). Then, the URL to access Google's OAuth login is generated and stored in the googleURL variable. Then the user is redirected to this function.

After this point, the user will either be asked to login with their Google credentials or a previously saved credential will be found and used instead. After this, the user will be redirected to the callback URL. The function our code uses to control this is the analysisOAuth() function.

analysisOAuth()
This function requires the authorization code provided by Google (stored in the authCode variable) to continue. If one is not provided, then the Google OAuth fails and an error page will be shown.

If the authCode is returned successfully however, the code will analyze the spreadsheet per the code in the analyzeData class. Then, user will be sent to the analysisComplete() function with the spreadsheet URL passed through to create a link directly to the Google Sheet that contains the analyzed spreadsheet.

analysisComplete()
Returns the congratulations.html page.

error()
Returns the error.html page. This page can be deleted to use the built in error page from Thymeleaf, or can be customized to fit your needs. A tutorial for creating your own error pages in Link 9 in the Additional Reading section.