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 interfaceSomeone who is interested in being informed if thecurrently logged-in useris 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 useris 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 ConfigurationSpecifies theConfigurationobject that contains the directory where the metadata file is stored.private static URLTheURLthat points to the metadata file of the application.private booleanWhether thepollUrlshould be decrypted or not.private static final @NonNull StringThe default metadata file that is shipped with the application.private static final @NonNull ReentrantLockFacilitates mutual exclusion forloadingthedefaultPolledMetadata.private static final @NonNull URLThe default fullURLthat points to a poll made by the developers asking the end-users for feedback on the application.private static PolledMetadataThe metadata that is shipped with the application in themetadata.default.jsonfile.private static final @NonNull StringThe name of the file that contains the metadata of the application.private static final @NonNull StringThe format that themetadata.jsonfile must adhere to.private static final byte[]private static final @NonNull StringThe first part of theURLthat points to a poll made by the developers asking the end-users for feedback on the application.private URLprivate static final @NonNull PreferencesStores metadata about the metadata, e.g. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateDeprecated.Only used by Jackson for deserialisation.privatePolledMetadata(@NonNull String pollUrl) Deprecated.Only used by Jackson for deserialisation.PolledMetadata(@NonNull Configuration configuration) Creates a newPolledMetadataobject andtriesto import themetadata.jsonfile from thespecified in the giveninvalid reference
directoryConfiguration.PolledMetadata(@NonNull Configuration configuration, boolean decryptPollURL) Creates a newPolledMetadataobject andtriesto import themetadata.jsonfile from thespecified in the giveninvalid reference
directoryConfiguration. -
Method Summary
Modifier and TypeMethodDescription@NonNull Optional<BannedUser> Compares theconfigurationof the currently logged-in user with thebannedUsersto see whether the user is prohibited to use the application.@NonNull PolledMetadatacopy()decryptPollURL(@NonNull String cipherTextRaw) Decrypts the given cipher text and stores it as the newpollUrl.booleandownload()Fetches up-to-date metadata from thedataURLand saves it to thespecified in theinvalid reference
directoryconfigurationasmetadata.json.(package private) static @NonNull PolledMetadataConverts a given JSON file to aPolledMetadataobject.static @NonNull PolledMetadataConverts a given JSON string to aPolledMetadataobject.@NonNull ArrayList<@NonNull BannedUser> static @NonNull Optional<PolledMetadata> Returns a deep copy of thedefaultPolledMetadataobject that holds the metadata shipped with the application.booleanTries to read themetadata.jsonfile from thespecified in theinvalid reference
directoryconfigurationand load thepollUrland thebannedUsersfrom it.voidimportFromFile(@NonNull File file) private static @NonNull PolledMetadataConvertsmetadata.default.jsonresource file shipped with the application to aPolledMetadataobject.voidregisterBannedUserCallback(@NonNull PolledMetadata.BannedUserCallback callback) Adds the givenPolledMetadata.BannedUserCallbackto the list of listeners that are informed if the currently logged-in user is found to be banned from using the application.booleanremoveBannedUserCallback(@NonNull PolledMetadata.BannedUserCallback callback) Unsubscribes the givenPolledMetadata.BannedUserCallbackfrom 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 voidsetPollUrl(@NonNull String url) Deprecated.Only used by Jackson for deserialisation.booleanwasDownloadedWithin(@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.jsonfile. -
DEFAULT_METADATA_FILE_NAME
-
dataURL
TheURLthat 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 thespecified in theinvalid reference
directoryConfiguration.- See Also:
-
JSON_SCHEMA
The format that themetadata.jsonfile must adhere to. Available online. -
DEFAULT_POLL_URL
-
DEFAULT_METADATA_LOCK
Facilitates mutual exclusion forloadingthedefaultPolledMetadata. -
POLL_PREFIX
-
configuration
Specifies theConfigurationobject that contains the directory where the metadata file is stored. -
pollUrl
-
decryptPollURL
private boolean decryptPollURLWhether thepollUrlshould 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 useris found to be banned from using the application.- See Also:
-
-
Constructor Details
-
PolledMetadata
Creates a newPolledMetadataobject andtriesto import themetadata.jsonfile from thespecified in the giveninvalid reference
directoryConfiguration.- Parameters:
configuration- Specifies the directory to import the metadata from.- See Also:
-
PolledMetadata
Creates a newPolledMetadataobject andtriesto import themetadata.jsonfile from thespecified in the giveninvalid reference
directoryConfiguration.- Parameters:
configuration- Specifies the directory to import the metadata from.decryptPollURL- Whether thepollUrlshould 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- ThepollUrlspecified in the JSON metadata.
-
PolledMetadata
Deprecated.Only used by Jackson for deserialisation.
-
-
Method Details
-
getPollUrl
-
importFromConfigurationDirectory
public boolean importFromConfigurationDirectory()Tries to read themetadata.jsonfile from thespecified in theinvalid reference
directoryconfigurationand load thepollUrland thebannedUsersfrom it.- Returns:
trueif the metadata file was successfully imported,falseotherwise.
-
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:
wasDownloadedWithinin classDownloadable- Parameters:
duration- The time between the oldest acceptable download date and now.- Returns:
trueif the metadata was downloaded within the specified duration,falseotherwise.
-
download
public boolean download()Fetches up-to-date metadata from thedataURLand saves it to thespecified in theinvalid reference
directoryconfigurationasmetadata.json.- Specified by:
downloadin classDownloadable- Returns:
trueif the metadata was successfully downloaded,falseotherwise.
-
getBannedUsers
- Returns:
- A deep copy of the
bannedUserslist.
-
registerBannedUserCallback
public void registerBannedUserCallback(@NonNull @NonNull PolledMetadata.BannedUserCallback callback) Adds the givenPolledMetadata.BannedUserCallbackto 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 makeremovaleasier.- Parameters:
callback- The new listener to be added.
-
removeBannedUserCallback
public boolean removeBannedUserCallback(@NonNull @NonNull PolledMetadata.BannedUserCallback callback) Unsubscribes the givenPolledMetadata.BannedUserCallbackfrom 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:
trueif the listener was successfully removed,falseotherwise.
-
fromFile
@NonNull static @NonNull PolledMetadata fromFile(@NonNull @NonNull File file) throws IOException, IllegalArgumentException, SecurityException, OutOfMemoryError Converts a given JSON file to aPolledMetadataobject.- 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.jsonresource file shipped with the application to aPolledMetadataobject.- 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 aPolledMetadataobject.- 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 newpollUrlspecified 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 thepasswordof this class.- Returns:
- The decrypted poll URL.
- Throws:
IllegalArgumentException- If the cipher text could not be decrypted.
-
checkForBans
Compares theconfigurationof the currently logged-in user with thebannedUsersto see whether the user is prohibited to use the application. If the user is banned,onBansFoundwill be called on alllisteners.- Returns:
- The current user's
BannedUserequivalent 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 emptyOptionalwill be returned.
-
copy
- Specified by:
copyin interfaceCopyable<PolledMetadata>- Returns:
- An entirely new
PolledMetadataobject withdeep copiesof allbannedUsers- a copy of the
pollUrlif it is notnull
-
getDefaultPolledMetadata
Returns a deep copy of thedefaultPolledMetadataobject that holds the metadata shipped with the application. If necessary, the metadata will beloadedfrom the resources first.- Returns:
- The default metadata. Empty if it could not be loaded.
-