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 TypeClassDescriptionclass
class
class
Nested classes/interfaces inherited from class page.codeberg.friedolyn.client.FriedolinClient
FriedolinClient.HTTP_REQUEST_TYPE, FriedolinClient.InternetConnectivityStatus
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate @NonNull Configuration
The configuration with all parameters required to log in at the University of Jena's Friedolin system.static final @NonNull URL
private final @NonNull org.openqa.selenium.WebDriver
The Selenium web driver, i.e.private final @NonNull ReentrantLock
Whether 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 boolean
Accepts the obligation of use in order to access the grade table.Checks whether theDRIVER
has internet access.boolean
Checks whether the headless browser is currently logged in at the University of Jena's Friedolin system and updates theisLoggedIn
field accordingly.boolean
fetchGrades
(@NonNull String... degrees) Fetches the student's grades from the University of Jena's Friedolin system, using the credentials specified in theConfiguration
previously set viaFriedolinClient.setConfiguration(Configuration)
(or the constructor).private boolean
fetchGradesForDegree
(@NonNull String degree) Fetches the grades for the specified degree.void
finish()
Exits the headless browser.@NonNull HeadlessBrowser.FetchClearname
@NonNull HeadlessBrowser.FetchEmailAddress
@NonNull HeadlessBrowser.Login
void
setConfiguration
(@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).void
setConfigurationReference
(@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:
finish
in classFriedolinClient
-
getLoginTask
- Specified by:
getLoginTask
in classFriedolinClient
- Returns:
- A
Task
that can be executed in a differentThread
to 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:
setConfiguration
in 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:
setConfigurationReference
in 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:
true
if the grades could be fetched,false
otherwise.- 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 theConfiguration
previously set viaFriedolinClient.setConfiguration(Configuration)
(or the constructor).- Specified by:
fetchGrades
in classFriedolinClient
- Parameters:
degrees
- The academic degrees to fetch the grades for. If none are specified, all degrees present ininvalid reference
Configuration#getAcademicDegrees()
- Returns:
true
if the grades were fetched successfully,false
otherwise.- 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:
true
if the obligation of use could be accepted,false
otherwise.
-
getFetchClearnameTask
- Specified by:
getFetchClearnameTask
in classFriedolinClient
- Returns:
- A
Task
that can be executed in a differentThread
to fetch the student's real name (e.g.Edward Snowden
) from the University of Jena's Friedolin system.
-
getFetchEmailAddressTask
- Specified by:
getFetchEmailAddressTask
in classFriedolinClient
- Returns:
- A
Task
that can be executed in a differentThread
to 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 theisLoggedIn
field accordingly.- Returns:
true
if the headless browser is currently logged in,false
otherwise.
-
checkInternetConnectivity
Checks whether theDRIVER
has internet access.- Specified by:
checkInternetConnectivity
in 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-02
of the Tor Project). Then, we connect to codeberg.org to take DNS into consideration.
-