java.lang.Object
page.codeberg.friedolyn.meta.Downloadable
page.codeberg.friedolyn.meta.PolledMetadata
- All Implemented Interfaces:
Copyable<PolledMetadata>
Represents information about the Friedolyn application that is fetched from the
Friedolyn data repository
.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Someone who is interested in being informed if thecurrently logged-in user
is found to be banned from using the application. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final @NonNull HashSet
<PolledMetadata.BannedUserCallback> Everyone interested in being informed if thecurrently logged-in user
is found to be banned from using the application.private @NonNull ArrayList
<BannedUser> A list of users who, for some reason, are not allowed to use the application.private @NonNull Configuration
Specifies theConfiguration
object that contains the directory where the metadata file is stored.private static URL
TheURL
that points to the metadata file of the application.private boolean
Whether thepollUrl
should be decrypted or not.private static final @NonNull String
The default metadata file that is shipped with the application.private static final @NonNull ReentrantLock
Facilitates mutual exclusion forloading
thedefaultPolledMetadata
.private static final @NonNull URL
The default fullURL
that points to a poll made by the developers asking the end-users for feedback on the application.private static PolledMetadata
The metadata that is shipped with the application in themetadata.default.json
file.private static final @NonNull String
The name of the file that contains the metadata of the application.private static final @NonNull String
The format that themetadata.json
file must adhere to.private static final byte[]
private static final @NonNull String
The first part of theURL
that points to a poll made by the developers asking the end-users for feedback on the application.private URL
private static final @NonNull Preferences
Stores metadata about the metadata, e.g. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Deprecated.Only used by Jackson for deserialisation.private
PolledMetadata
(@NonNull String pollUrl) Deprecated.Only used by Jackson for deserialisation.PolledMetadata
(@NonNull Configuration configuration) Creates a newPolledMetadata
object andtries
to import themetadata.json
file from theinvalid reference
directory
Configuration
.PolledMetadata
(@NonNull Configuration configuration, boolean decryptPollURL) Creates a newPolledMetadata
object andtries
to import themetadata.json
file from theinvalid reference
directory
Configuration
. -
Method Summary
Modifier and TypeMethodDescription@NonNull Optional
<BannedUser> Compares theconfiguration
of the currently logged-in user with thebannedUsers
to see whether the user is prohibited to use the application.@NonNull PolledMetadata
copy()
decryptPollURL
(@NonNull String cipherTextRaw) Decrypts the given cipher text and stores it as the newpollUrl
.boolean
download()
Fetches up-to-date metadata from thedataURL
and saves it to theinvalid reference
directory
configuration
asmetadata.json
.(package private) static @NonNull PolledMetadata
Converts a given JSON file to aPolledMetadata
object.static @NonNull PolledMetadata
Converts a given JSON string to aPolledMetadata
object.@NonNull ArrayList
<@NonNull BannedUser> static @NonNull Optional
<PolledMetadata> Returns a deep copy of thedefaultPolledMetadata
object that holds the metadata shipped with the application.boolean
Tries to read themetadata.json
file from theinvalid reference
directory
configuration
and load thepollUrl
and thebannedUsers
from it.void
importFromFile
(@NonNull File file) private static @NonNull PolledMetadata
Convertsmetadata.default.json
resource file shipped with the application to aPolledMetadata
object.void
registerBannedUserCallback
(@NonNull PolledMetadata.BannedUserCallback callback) Adds the givenPolledMetadata.BannedUserCallback
to the list of listeners that are informed if the currently logged-in user is found to be banned from using the application.boolean
removeBannedUserCallback
(@NonNull PolledMetadata.BannedUserCallback callback) Unsubscribes the givenPolledMetadata.BannedUserCallback
from the list of listeners, meaning it will no longer be notified if the currently logged-in user is found to be banned from using the application.private void
setPollUrl
(@NonNull String url) Deprecated.Only used by Jackson for deserialisation.boolean
wasDownloadedWithin
(@NonNull Duration duration) Checks if the Friedolyn application's metadata was polled more recently than the specified duration, i.e.Methods inherited from class page.codeberg.friedolyn.meta.Downloadable
wasDownloadedWithin
-
Field Details
-
PREFERENCES
Stores metadata about the metadata, e.g. the date and time of the last download. -
defaultPolledMetadata
The metadata that is shipped with the application in themetadata.default.json
file. -
DEFAULT_METADATA_FILE_NAME
-
dataURL
TheURL
that points to the metadata file of the application. It is stored in the Friedolyn data repository. -
FILE_NAME
The name of the file that contains the metadata of the application. It is stored in theinvalid reference
directory
Configuration
.- See Also:
-
JSON_SCHEMA
The format that themetadata.json
file must adhere to. Available online. -
DEFAULT_POLL_URL
-
DEFAULT_METADATA_LOCK
Facilitates mutual exclusion forloading
thedefaultPolledMetadata
. -
POLL_PREFIX
-
configuration
Specifies theConfiguration
object that contains the directory where the metadata file is stored. -
pollUrl
-
decryptPollURL
private boolean decryptPollURLWhether thepollUrl
should be decrypted or not. Will be respected bydecryptPollURL(String)
. -
PASSWORD
-
bannedUsers
A list of users who, for some reason, are not allowed to use the application. The application must refuse to work for these users. -
BANNED_USER_LISTENERS
Everyone interested in being informed if thecurrently logged-in user
is found to be banned from using the application.- See Also:
-
-
Constructor Details
-
PolledMetadata
Creates a newPolledMetadata
object andtries
to import themetadata.json
file from theinvalid reference
directory
Configuration
.- Parameters:
configuration
- Specifies the directory to import the metadata from.- See Also:
-
PolledMetadata
Creates a newPolledMetadata
object andtries
to import themetadata.json
file from theinvalid reference
directory
Configuration
.- Parameters:
configuration
- Specifies the directory to import the metadata from.decryptPollURL
- Whether thepollUrl
should be decrypted or not. Set this tofalse
, if the user has recently taken part in the poll, in order not to waste resources on the heavy decryption process.- See Also:
-
PolledMetadata
Deprecated.Only used by Jackson for deserialisation.- Parameters:
pollUrl
- ThepollUrl
specified in the JSON metadata.
-
PolledMetadata
Deprecated.Only used by Jackson for deserialisation.
-
-
Method Details
-
getPollUrl
-
importFromConfigurationDirectory
public boolean importFromConfigurationDirectory()Tries to read themetadata.json
file from theinvalid reference
directory
configuration
and load thepollUrl
and thebannedUsers
from it.- Returns:
true
if the metadata file was successfully imported,false
otherwise.
-
importFromFile
- Parameters:
file
- The file to read the metadata from.- Throws:
IllegalArgumentException
- If the metadata file is formatted incorrectly. SeefromFile(File)
for details.
-
wasDownloadedWithin
Checks if the Friedolyn application's metadata was polled more recently than the specified duration, i.e. whether the metadata was downloaded within `now - duration`.- Specified by:
wasDownloadedWithin
in classDownloadable
- Parameters:
duration
- The time between the oldest acceptable download date and now.- Returns:
true
if the metadata was downloaded within the specified duration,false
otherwise.
-
download
public boolean download()Fetches up-to-date metadata from thedataURL
and saves it to theinvalid reference
directory
configuration
asmetadata.json
.- Specified by:
download
in classDownloadable
- Returns:
true
if the metadata was successfully downloaded,false
otherwise.
-
getBannedUsers
- Returns:
- A deep copy of the
bannedUsers
list.
-
registerBannedUserCallback
public void registerBannedUserCallback(@NonNull @NonNull PolledMetadata.BannedUserCallback callback) Adds the givenPolledMetadata.BannedUserCallback
to the list of listeners that are informed if the currently logged-in user is found to be banned from using the application. The listener's exact reference will be used (instead of a deep copy) in order to makeremoval
easier.- Parameters:
callback
- The new listener to be added.
-
removeBannedUserCallback
public boolean removeBannedUserCallback(@NonNull @NonNull PolledMetadata.BannedUserCallback callback) Unsubscribes the givenPolledMetadata.BannedUserCallback
from the list of listeners, meaning it will no longer be notified if the currently logged-in user is found to be banned from using the application.- Parameters:
callback
- The listener to be removed. Must be the exact reference that was previouslyregistered
.- Returns:
true
if the listener was successfully removed,false
otherwise.
-
fromFile
@NonNull static @NonNull PolledMetadata fromFile(@NonNull @NonNull File file) throws IOException, IllegalArgumentException, SecurityException, OutOfMemoryError Converts a given JSON file to aPolledMetadata
object.- Parameters:
file
- The file to read the metadata from.- Returns:
- The metadata object represented by the JSON.
- Throws:
IllegalArgumentException
- If the metadata file is formatted incorrectly. SeefromJSON(String)
for details.IOException
- If the file could not be read.SecurityException
- If the file could not be read due to security restrictions.OutOfMemoryError
- If the file is too large to be read.
-
loadDefaultMetadata
Convertsmetadata.default.json
resource file shipped with the application to aPolledMetadata
object.- Returns:
- The metadata represented by the default metadata file.
- Throws:
RuntimeException
- If the default metadata file could not be found, read, or parsed.
-
fromJSON
@NonNull public static @NonNull PolledMetadata fromJSON(@NonNull @NonNull String json) throws IllegalArgumentException, com.fasterxml.jackson.core.JsonProcessingException Converts a given JSON string to aPolledMetadata
object.- Parameters:
json
- The JSON string to read the metadata from. Must adhere to theJSON schema
.- Returns:
- The metadata object represented by the JSON.
- Throws:
IllegalArgumentException
- If the JSON does not match the expected format.com.fasterxml.jackson.core.JsonProcessingException
- SeeObjectMapper.readValue(String, Class)
.
-
setPollUrl
Deprecated.Only used by Jackson for deserialisation.- Parameters:
url
- The newpollUrl
specified in the JSON metadata.- Throws:
IllegalArgumentException
- SeedecryptPollURL(String)
.
-
decryptPollURL
@NonNull private @NonNull Optional<String> decryptPollURL(@NonNull @NonNull String cipherTextRaw) throws IllegalArgumentException Decrypts the given cipher text and stores it as the newpollUrl
.- Parameters:
cipherTextRaw
- The cipher text to decrypt. Must match the format ofCipherText.parse(String)
. Must have been encrypted with thepassword
of this class.- Returns:
- The decrypted poll URL.
- Throws:
IllegalArgumentException
- If the cipher text could not be decrypted.
-
checkForBans
Compares theconfiguration
of the currently logged-in user with thebannedUsers
to see whether the user is prohibited to use the application. If the user is banned,onBansFound
will be called on alllisteners
.- Returns:
- The current user's
BannedUser
equivalent if they're banned. If the developers have left a message to the banned user with an explanation and if decrypting it succeeded, it will be made available viaBannedUser.getDecryptedMessage()
. If the user is not banned, an emptyOptional
will be returned.
-
copy
- Specified by:
copy
in interfaceCopyable<PolledMetadata>
- Returns:
- An entirely new
PolledMetadata
object withdeep copies
of allbannedUsers
- a copy of the
pollUrl
if it is notnull
-
getDefaultPolledMetadata
Returns a deep copy of thedefaultPolledMetadata
object that holds the metadata shipped with the application. If necessary, the metadata will beloaded
from the resources first.- Returns:
- The default metadata. Empty if it could not be loaded.
-