Package page.codeberg.friedolyn.client
Class HeadlessBrowser
java.lang.Object
page.codeberg.friedolyn.client.FriedolinClient
page.codeberg.friedolyn.client.HeadlessBrowser
An alternative to the default
Client that uses a browser without a graphical user interface to interact
with the University of Jena's Friedolin system. Therefore, this class is very resource-intensive and should only be
used if the hardware is capable of running a headless browser. NOT recommended for use on devices like
a Raspberry Pi.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassclassclassNested classes/interfaces inherited from class page.codeberg.friedolyn.client.FriedolinClient
FriedolinClient.HTTP_REQUEST_TYPE, FriedolinClient.InternetConnectivityStatus -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate @NonNull ConfigurationThe configuration with all parameters required to log in at the University of Jena's Friedolin system.static final @NonNull URLprivate final @NonNull org.openqa.selenium.WebDriverThe Selenium web driver, i.e.private final @NonNull ReentrantLockWhether the headless browser is currently logged in at the University of Jena's Friedolin system.Fields inherited from class page.codeberg.friedolyn.client.FriedolinClient
SESSION_LIFETIME -
Constructor Summary
ConstructorsConstructorDescriptionHeadlessBrowser(@NonNull Configuration configuration) Creates a new headless browser instance with the provided configuration. -
Method Summary
Modifier and TypeMethodDescriptionprivate booleanAccepts the obligation of use in order to access the grade table.Checks whether theDRIVERhas internet access.booleanChecks whether the headless browser is currently logged in at the University of Jena's Friedolin system and updates theisLoggedInfield accordingly.booleanfetchGrades(@NonNull String... degrees) Fetches the student's grades from the University of Jena's Friedolin system, using the credentials specified in theConfigurationpreviously set viaFriedolinClient.setConfiguration(Configuration)(or the constructor).private booleanfetchGradesForDegree(@NonNull String degree) Fetches the grades for the specified degree.voidfinish()Exits the headless browser.@NonNull HeadlessBrowser.FetchClearname@NonNull HeadlessBrowser.FetchEmailAddress@NonNull HeadlessBrowser.LoginvoidsetConfiguration(@NonNull Configuration configuration) Updates the preferences that determine the behaviour of this client with a deep copy of the given configuration (not the actual reference, for security reasons).voidsetConfigurationReference(@NonNull Configuration configuration) Updates the preferences that determine the behaviour of this client with the exact reference of the givenConfiguration(instead of just a deep copy).Methods inherited from class page.codeberg.friedolyn.client.FriedolinClient
buildURL, decodeQuery, encodeParameters, fetchEmailAddress, fetchStudentClearname, getConfiguration, getIsLoggedIn, login, saveResponse, stripAnchor
-
Field Details
-
DNS_OVER_HTTPS_URL
-
configuration
The configuration with all parameters required to log in at the University of Jena's Friedolin system. -
DRIVER
@NonNull private final @NonNull org.openqa.selenium.WebDriver DRIVERThe Selenium web driver, i.e. the headless browser. -
isLoggedIn
-
IS_LOGGED_IN_LOCK
-
-
Constructor Details
-
HeadlessBrowser
Creates a new headless browser instance with the provided configuration. Since an entire browser is started, it is strongly recommended to execute the construction of this object in a separate thread when the constructor is invoked from a graphical user interface.- Parameters:
configuration- The configuration with all parameters required to log in at the University of Jena's Friedolin system.
-
-
Method Details
-
finish
public void finish()Exits the headless browser. This method should be called when the headless browser is no longer needed but the application is still running, in order not to waste resources longer than necessary. Yes, Java has a garbage collector, but there may be situations where the parent of this object is still in use but does not need the headless browser anymore.- Specified by:
finishin classFriedolinClient
-
getLoginTask
- Specified by:
getLoginTaskin classFriedolinClient- Returns:
- A
Taskthat can be executed in a differentThreadto log in to Friedolin.
-
setConfiguration
Updates the preferences that determine the behaviour of this client with a deep copy of the given configuration (not the actual reference, for security reasons).- Specified by:
setConfigurationin classFriedolinClient- Parameters:
configuration- The new configuration to use.- See Also:
- Implementation Note:
- It is required that a deep copy of the given configuration is stored.
-
setConfigurationReference
Updates the preferences that determine the behaviour of this client with the exact reference of the givenConfiguration(instead of just a deep copy).- Specified by:
setConfigurationReferencein classFriedolinClient- Parameters:
configuration- The new configuration to use.- See Also:
- Implementation Note:
- It is required to store the exact object instance instead of calling
copy().
-
fetchGradesForDegree
private boolean fetchGradesForDegree(@NonNull @NonNull String degree) throws IllegalArgumentException Fetches the grades for the specified degree. IMPORTANT: It is absolutely REQUIRED that the currently opened page is the course list page.- Parameters:
degree- The degree to fetch the grades for.- Returns:
trueif the grades could be fetched,falseotherwise.- Throws:
IllegalArgumentException- If the student is not enrolled in the specified degree.
-
fetchGrades
Fetches the student's grades from the University of Jena's Friedolin system, using the credentials specified in theConfigurationpreviously set viaFriedolinClient.setConfiguration(Configuration)(or the constructor).- Specified by:
fetchGradesin classFriedolinClient- Parameters:
degrees- The academic degrees to fetch the grades for. If none are specified, all degrees present inwill be fetched.invalid reference
Configuration#getAcademicDegrees()- Returns:
trueif the grades were fetched successfully,falseotherwise.- Throws:
IllegalArgumentException- If any of the given degrees is not present in the configuration.
-
acceptObligationOfUse
private boolean acceptObligationOfUse()Accepts the obligation of use in order to access the grade table.- Returns:
trueif the obligation of use could be accepted,falseotherwise.
-
getFetchClearnameTask
- Specified by:
getFetchClearnameTaskin classFriedolinClient- Returns:
- A
Taskthat can be executed in a differentThreadto fetch the student's real name (e.g.Edward Snowden) from the University of Jena's Friedolin system.
-
getFetchEmailAddressTask
- Specified by:
getFetchEmailAddressTaskin classFriedolinClient- Returns:
- A
Taskthat can be executed in a differentThreadto fetch the student's email address (e.g.edward.snowden@uni-jena.de).
-
checkLoginStatus
public boolean checkLoginStatus()Checks whether the headless browser is currently logged in at the University of Jena's Friedolin system and updates theisLoggedInfield accordingly.- Returns:
trueif the headless browser is currently logged in,falseotherwise.
-
checkInternetConnectivity
Checks whether theDRIVERhas internet access.- Specified by:
checkInternetConnectivityin classFriedolinClient- Returns:
- The internet connectivity status of the
DRIVER. - See Also:
- Implementation Note:
- In order to rule out DNS issues, we
first try to connect to 116.202.120.166
(i.e.
web-fsn-02of the Tor Project). Then, we connect to codeberg.org to take DNS into consideration.
-