Package page.codeberg.friedolyn.client
Class FriedolinClient
java.lang.Object
page.codeberg.friedolyn.client.FriedolinClient
- Direct Known Subclasses:
Client,HeadlessBrowser
A client to automatically interact with the University of Jena's Friedolin system.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic enumThe method to use for an HTTP request.static enumIndicates whether and how the device is able to connect to the internet.static classATaskthat can be executed in a differentThreadto log in to Friedolin using the student's credentials specified in theConfigurationpreviously set viasetConfiguration(Configuration)(or the constructor). -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final @NonNull DurationThe lifetime of a session in the University of Jena's Friedolin system. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull StringbuildURL(@NonNull String domain, @NonNull String path, @NonNull Map<@NonNull String, @NonNull String> parameters) Creates a new URL from the given domain, path, and parameters.abstract @NonNull FriedolinClient.InternetConnectivityStatusChecks whether the device is able to reach the internet and resolve domain names.static @NonNull LinkedHashMap<@NonNull String, @NonNull String> decodeQuery(@NonNull String query) Decodes the given query string into a map of keys and values.static @NonNull StringencodeParameters(@NonNull Map<@NonNull String, @NonNull String> parameters) Encodes the given parameters such that they can be used in a URL or in a POST request.@NonNull jakarta.mail.internet.InternetAddressFetches the student's email address from the University of Jena's Friedolin system and updates the configuration accordingly.abstract booleanfetchGrades(@NonNull String... degrees) Fetches the student's grades from the University of Jena's Friedolin system, using the credentials specified in theConfigurationpreviously set viasetConfiguration(Configuration)(or the constructor).@NonNull Stringabstract voidfinish()Exits the headless browser.abstract @NonNull Configurationabstract @NonNull FriedolinClient.FetchClearnameabstract @NonNull FriedolinClient.FetchEmailAddressabstract @NonNull FriedolinClient.Loginbooleanlogin()Logs in to Friedolin in a blocking manner.protected booleansaveResponse(@NonNull String filename, @NonNull String response) Saves the given response to a file with the given filename in theresponsesdirectory.abstract voidsetConfiguration(@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).abstract 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).static @NonNull URLstripAnchor(@NonNull URL url) Removes the HTML anchor from the given URL, if it has one.
-
Field Details
-
SESSION_LIFETIME
The lifetime of a session in the University of Jena's Friedolin system. Currently, you have to log in again after 30 minutes.
-
-
Constructor Details
-
FriedolinClient
public FriedolinClient()
-
-
Method Details
-
getConfiguration
- Returns:
- A deep copy of the preferences that determine the behaviour of this client (not the actual reference, for security reasons).
- Implementation Note:
- It is required that the returned object is a deep copy of the configuration.
-
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).- 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).- Parameters:
configuration- The new configuration to use.- See Also:
- Implementation Note:
- It is required to store the exact object instance instead of calling
copy().
-
login
public boolean login()Logs in to Friedolin in a blocking manner. Due to the notoriously long response times of network requests, it is recommended torunthe non-blockinggetLoginTask()in a separateThreadinstead of calling this method directly, in order not to block the rest of the application (e.g. the GUI).- Returns:
trueif the login was successful,falseotherwise
-
getLoginTask
-
getFetchClearnameTask
-
getFetchEmailAddressTask
-
fetchGrades
public abstract boolean fetchGrades(@NonNull @NonNull String... degrees) throws IllegalArgumentException Fetches the student's grades from the University of Jena's Friedolin system, using the credentials specified in theConfigurationpreviously set viasetConfiguration(Configuration)(or the constructor).- 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.
-
fetchStudentClearname
@NonNull public @NonNull String fetchStudentClearname() throws org.openqa.selenium.NotFoundException- Returns:
- The student's clear name as indicated in the University of Jena's Friedolin system.
- Throws:
org.openqa.selenium.NotFoundException- If the student's clear name could not be found.
-
fetchEmailAddress
@NonNull public @NonNull jakarta.mail.internet.InternetAddress fetchEmailAddress() throws org.openqa.selenium.NotFoundExceptionFetches the student's email address from the University of Jena's Friedolin system and updates the configuration accordingly.- Returns:
- The student's email address as indicated in the University of Jena's Friedolin system.
- Throws:
org.openqa.selenium.NotFoundException- If the student's email address could not be found.
-
finish
public abstract 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. -
getIsLoggedIn
- Returns:
- Whether the student is currently logged in at the University of Jena's Friedolin system. The login
status is only valid for the length of
SESSION_LIFETIME.
-
checkInternetConnectivity
@NonNull public abstract @NonNull FriedolinClient.InternetConnectivityStatus checkInternetConnectivity()Checks whether the device is able to reach the internet and resolve domain names. Will connect to some well-known server. Blocks the current thread for a short time, depending on the implementation.- Returns:
- The current internet status.
- See Also:
-
saveResponse
-
encodeParameters
@NonNull public static @NonNull String encodeParameters(@NonNull @NonNull Map<@NonNull String, @NonNull String> parameters) Encodes the given parameters such that they can be used in a URL or in a POST request.- Parameters:
parameters- The parameters to encode with keys and values.- Returns:
- The encoded parameters as a
Stringin the formatkey1=value1&key2=value2&...
-
buildURL
@NonNull public static @NonNull String buildURL(@NonNull @NonNull String domain, @NonNull @NonNull String path, @NonNull @NonNull Map<@NonNull String, @NonNull String> parameters) Creates a new URL from the given domain, path, and parameters.- Parameters:
domain- The domain to use in the URL, without the protocol. Default protocol is HTTPS.path- The path to use in the URL, without the domain.parameters- The parameters to add to the URL.- Returns:
- The URL as a
String.
-
stripAnchor
@NonNull public static @NonNull URL stripAnchor(@NonNull @NonNull URL url) throws MalformedURLException Removes the HTML anchor from the given URL, if it has one.- Parameters:
url- The URL to remove the anchor from. Will not be modified.- Returns:
- An entirely new URL without the anchor.
- Throws:
MalformedURLException- If the URL is malformed (this is de facto impossible, because the given parameter is already a URL object).
-
decodeQuery
@NonNull public static @NonNull LinkedHashMap<@NonNull String,@NonNull String> decodeQuery(@NonNull @NonNull String query) Decodes the given query string into a map of keys and values.- Parameters:
query- The query string to decode, usually the parameters taken from a URL.- Returns:
- The decoded query as a map of keys and values, in the same order as they appeared in the query string.
-