Class FriendRehostingManager

java.lang.Object
com.sodius.oslc.server.core.FriendRehostingManager

public abstract class FriendRehostingManager extends Object
Manages the re-hosting of a friend application.
Since:
3.1.1
  • Constructor Details

    • FriendRehostingManager

      public FriendRehostingManager()
  • Method Details

    • getInstance

      public static FriendRehostingManager getInstance()
      Returns the current manager instance.
      Returns:
      the current instance.
      See Also:
    • setInstance

      public static void setInstance(FriendRehostingManager manager)
      Replaces the current manager instance with the given one.
      Parameters:
      manager - the new manager.
    • getPersonServiceClass

      public Class<? extends PersonService> getPersonServiceClass()
      Convenient method to retrieve the actual PersonService class implemented by an application. This method is used to create URIs to the final Person service which can change the service path.
      Returns:
      the actual PersonService class with the real path to the service end-point.
    • saveLog

      protected abstract void saveLog(FriendRehostingManager.LogLevel level, Task task, String message) throws FriendRehostingException
      Saves a Task's log entry. Implementation of this class MUST keep apart the logging messages of each task.
      Parameters:
      level - the log level.
      task - the owner task.
      message - the message to log.
      Throws:
      FriendRehostingException - if saving fails.
    • log

      protected void log(FriendRehostingManager.LogLevel level, Task task, String message, Object... args)
      Logs a message with a given Level and non-interpolated arguments.
      Parameters:
      level - the logging level.
      task - the owner task.
      message - the non-interpolated message.
      args - the arguments to interpolate.
    • log

      protected void log(Throwable e, Task task, String message)
      Convenient method to log an error when an exception occurs.
      Parameters:
      e - the occurred exception.
      task - the owner task.
      message - the heading message.
    • saveTask

      protected abstract void saveTask(Task task) throws FriendRehostingException
      Creates (or updates) a task. When this method is called to save a subtask for the first time, the extended property oslc:order will be present so implementations can take advantage of it and use it to determine the proper order when the subtasks are retrieved.
      Parameters:
      task - the task to save.
      Throws:
      FriendRehostingException - if saving fails.
    • saveRehostingFriend

      protected abstract void saveRehostingFriend(Friend friend) throws FriendRehostingException
      Saves the re-hosting friend into a temporary location. The entry MUST be removed when the process is concluded. Implementations MUST care about saving the extended properties dcterms:source and dcterms:creator as well as making sure the friend will be accessible by its identifier (which is the same as the re-hosting task process).
      Parameters:
      friend - the re-hosting friend.
      Throws:
      FriendRehostingException - if saving fails.
    • getRehostingFriend

      protected abstract Friend getRehostingFriend(String identifier) throws FriendRehostingException
      Gets the re-hosting friend from the temporary location.
      Parameters:
      identifier - the friend (re-hosting task) identifier.
      Returns:
      the friend being re-hosted
      Throws:
      FriendRehostingException - if retrieving the friend fails.
    • getRehostingSubtasks

      protected abstract List<Task> getRehostingSubtasks(Task task, URI source) throws FriendRehostingException
      Determines the subtasks required to complete the re-hosting process, typically one per impacted project which means: an OSLC-enabled project associated with at least one remote project having the source context. Implementations can include additional subtask to change the remote project associations, for example, or to perform any GC-related duty.

      Implementations MUST fill only the title and description properties and SHOULD use the project/container title (or key) as the subtask title. Subtasks MUST come in the desired execution order and the getTask(String) method implementation MUST retrieve them in the same order.

      Parameters:
      task - the main re-hosting task.
      source - the original context URI.
      Returns:
      the set of subtasks required to complete the re-hosting process.
      Throws:
      FriendRehostingException - if retrieving the subtasks fails.
      Since:
      4.0.0
    • getSubtaskPreview

      protected abstract FriendRehostingPreview getSubtaskPreview(Task subtask, URI source) throws FriendRehostingException
      Computes a subtask preview. Implementations MUST determine how many links in how many artifacts are impacted. It is up to the implementation to decide whether to keep track of these artifacts/links ids for a possible faster re-hosting phase or not.
      Parameters:
      subtask - the current subtask.
      source - the original context URI.
      Returns:
      the preview results.
      Throws:
      FriendRehostingException - if preview cannot be computed.
      Since:
      4.0.0
    • startPreview

      public void startPreview(URI uri, Friend source, Friend target) throws FriendRehostingException
      Starts the (asynchronous) preview of a re-hosting task for a given friend and the current user.
      Parameters:
      uri - the URI of the service to access the re-hosting task.
      source - the original friend definition.
      target - the new friend definition.
      Throws:
      FriendRehostingException - if the Task cannot be started.
      NullPointerException - if any argument is null.
      Since:
      4.0.0
    • getTask

      public abstract Optional<Task> getTask(String identifier) throws FriendRehostingException
      Gets the re-hosting task for a given identifier.
      Parameters:
      identifier - the task's identifier.
      Returns:
      an empty optional if no re-hosting process is undergoing; the contained task reference otherwise.
      Throws:
      FriendRehostingException - if the Task cannot be retrieved.
    • getSubtasksIds

      protected String[] getSubtasksIds(Task parent)
      Convenient method to retrieve the subtasks ids, if any, from a parent task.
      Parameters:
      parent - the parent task.
      Returns:
      identifiers of the subtasks.
    • rehostSubtask

      protected abstract Map<String,Long> rehostSubtask(Task subtask, URI originalContext, URI targetContext) throws FriendRehostingException
      Performs the actual re-hosting over a subtask and the current user.
      Parameters:
      subtask - the current subtask.
      originalContext - the original context to replace.
      targetContext - the new context.
      Returns:
      the number of failed re-hosted links (values) per artifact (keys).
      Throws:
      FriendRehostingException - if the re-hosting fails.
      Since:
      4.0.0
    • startRehost

      public void startRehost(Task task) throws FriendRehostingException
      Starts the re-hosting process on the given task and for the current user.
      Parameters:
      task - the (preview) task to re-host.
      Throws:
      FriendRehostingException - if the Task cannot be moved to the re-host phase.
      NullPointerException - if any argument is null.
      Since:
      4.0.0
    • conclude

      protected abstract void conclude(Task task, Friend friend) throws FriendRehostingException
      Removes all temporary data associated with the given task and, if the status is FriendRehostingManager.Status.COMPLETED, persists the given friend in the storage. Implementations MUST remove the re-hosting friend from the temporary location and SHOULD use the same DB transaction, if applicable, to commit all DB data at once.
      Parameters:
      task - the given task.
      friend - the (updated) re-hosting friend.
      Throws:
      FriendRehostingException - if task cannot be concluded.
    • conclude

      public void conclude(Task task) throws FriendRehostingException
      Concludes a given task, for the current user, by cleaning all temporary data (if the status is either FriendRehostingManager.Status.PREVIEWED or FriendRehostingManager.Status.COMPLETED and by committing the target friend if the status is FriendRehostingManager.Status.COMPLETED only.
      Parameters:
      task - the given task.
      Throws:
      FriendRehostingException - if the Task cannot be completed.
      Since:
      4.0.0
    • writeLog

      public abstract void writeLog(Task task, boolean includeSubtasksLogs, OutputStream os) throws IOException, FriendRehostingException
      Writes the task log on a given output stream.
      Parameters:
      task - the given task.
      includeSubtasksLogs - whether to include subtasks logs.
      os - the given output stream.
      Throws:
      IOException - if some IO exception occurs.
      FriendRehostingException - if the writing cannot be completed by any other reason.