Class SpaceService
java.lang.Object
de.bytestore.hostinger.internal.service.SpaceService
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGenerates a support token using a random UUID.voidAuthorizes the current session by retrieving a new session token from the Space API.voidcache()voidvoidChecks the space session and authorizes if it has expired.voidChecks the support agent user and deactivates access if more than 1 hour has passed since activation.voidSends a request to the internal statistics API to awaken the current statistics instance.getBuilder(String urlIO) Retrieves a builder for making an HTTP request.Retrieves the feedback content from the internal statistics API.Retrieves the current Support-Pin from the Space.booleanChecks if the support agent user is active.booleanChecks if the space session has expired.voidDisables remote access functionality.voidload()Loads data from a JSON file into a SpaceConfig object.voidonApplicationStarted(org.springframework.boot.context.event.ApplicationStartedEvent event) voidRequests a new support PIN from the Space API.voidsave()Saves the current SpaceConfig object to a JSON file.booleansubmitFeedback(String textIO) Submits feedback to the internal statistics API.
-
Constructor Details
-
SpaceService
public SpaceService()
-
-
Method Details
-
onApplicationStarted
@EventListener public void onApplicationStarted(org.springframework.boot.context.event.ApplicationStartedEvent event) -
load
public void load()Loads data from a JSON file into a SpaceConfig object. If the file does not exist, it creates a new JSON file with a default SpaceConfig object.- Throws:
RuntimeException- if an IOException occurs while reading the file
-
cache
public void cache() -
checkForUpdates
public void checkForUpdates() -
reloadAllImages
public void reloadAllImages() -
authorize
public void authorize()Authorizes the current session by retrieving a new session token from the Space API. It uses the username and password from the SpaceConfig object to authenticate the request. If the authorization is successful, it sets the access token and expiry date for the session. Otherwise, it logs an error message with the response from the Space API. If there is an exception while retrieving the session token, it logs an error message as well. -
getSupportPin
Retrieves the current Support-Pin from the Space.- Returns:
- The current Support-Pin as a string.
-
getBuilder
Retrieves a builder for making an HTTP request. The builder includes the "Authorization" header with the access token.- Returns:
- The HttpRequest.Builder instance with the "Authorization" header.
-
addSupportToken
Generates a support token using a random UUID.- Returns:
- A support token string.
-
killRemoteAccess
public void killRemoteAccess()Disables remote access functionality. -
requestNewSupportPin
Requests a new support PIN from the Space API. The method sends a POST request to the internal support endpoint using a UUID retrieved from the license service. If the request is successful and the response contains a valid PIN, it caches the PIN using the system service and returns it. If the request fails or the response does not contain a valid PIN, it logs appropriate warnings or errors and returns a default "XXXX-XXXX-XXXX" PIN.- Returns:
- The new support PIN as a string if successfully retrieved; otherwise, returns "XXXX-XXXX-XXXX".
-
checkSupportAgent
public void checkSupportAgent()Checks the support agent user and deactivates access if more than 1 hour has passed since activation. -
isAgentActive
public boolean isAgentActive()Checks if the support agent user is active.- Returns:
- true if the support agent user is active, false otherwise.
-
isSpaceSessionExpired
public boolean isSpaceSessionExpired()Checks if the space session has expired.- Returns:
- true if the space session has expired, false otherwise.
-
checkSession
public void checkSession()Checks the space session and authorizes if it has expired. If the space session has expired, it retrieves a new session token from the Space API. -
fireStatistics
public void fireStatistics()Sends a request to the internal statistics API to awaken the current statistics instance. The request is sent using the UUID retrieved from the licenseService class. Prints an info message indicating the waking-up process. Handles the response if it has a status code of 200. Otherwise, logs an error message if there is an exception. -
submitFeedback
Submits feedback to the internal statistics API.- Parameters:
textIO- The feedback content as a string.- Returns:
-
getFeedback
Retrieves the feedback content from the internal statistics API.- Returns:
- The feedback content as a string. If there is an error or no feedback is available, an empty string is returned.
-
save
public void save()Saves the current SpaceConfig object to a JSON file.The method first reauthorizes the session by calling the
authorize()method to check for any errors. It then creates a new Gson object with pretty printing enabled and creates a new File object pointing to "./space.json". The method tries to write the SpaceConfig object to the file using the FileUtils.write() method from the Apache Commons IO library. If there is an IOException during the file write operation, a RuntimeException is thrown.- Throws:
RuntimeException- if there is an IOException during the file write operation
-