Class FriendRehostingManager


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

      • FriendRehostingManager

        public FriendRehostingManager()
    • Method Detail

      • 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.
      • 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,
                                                           Person user)
                                                    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.
        user - the executing user.
        Returns:
        the set of subtasks required to complete the re-hosting process.
        Throws:
        FriendRehostingException - if retrieving the subtasks fails.
      • getSubtaskPreview

        protected abstract FriendRehostingPreview getSubtaskPreview​(Task subtask,
                                                                    URI source,
                                                                    Person user)
                                                             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.
        user - the executing user.
        Returns:
        the preview results.
        Throws:
        FriendRehostingException - if preview cannot be computed.
      • startPreview

        public void startPreview​(URI uri,
                                 Friend source,
                                 Friend target,
                                 Person user)
                          throws FriendRehostingException
        Starts the (asynchronous) preview of a re-hosting task for a given friend.
        Parameters:
        uri - the URI of the service to access the re-hosting task.
        source - the original friend definition.
        target - the new friend definition.
        user - the executing user.
        Throws:
        FriendRehostingException - if the Task cannot be started.
        NullPointerException - if any argument is null.
      • 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,
                                                                Person user)
                                                         throws FriendRehostingException
        Performs the actual re-hosting over a subtask.
        Parameters:
        subtask - the current subtask.
        originalContext - the original context to replace.
        targetContext - the new context.
        user - the executing user.
        Returns:
        the number of failed re-hosted links (values) per artifact (keys).
        Throws:
        FriendRehostingException - if the re-hosting fails.
      • 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.
      • 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.