Class MergeUtil


  • @OpenApiAll
    public class MergeUtil
    extends CompareUtil
    Allows using MagicDraw project merge to merge projects. See Open API manual for the usage details.
    • Constructor Detail

      • MergeUtil

        public MergeUtil()
    • Method Detail

      • acceptChanges

        public static void acceptChanges​(java.util.Set<Change> preferredChanges,
                                         java.util.Set<Change> changes)
                                  throws java.lang.IllegalStateException
        Accept given changes. If change from changes conflicts with change from preferredChanges, it is rejected. The result is - all preferredChanges are accepted, and only not conflicting changes are accepted.
        Parameters:
        preferredChanges - accept all these changes.
        changes - accept only not conflicting changes.
        Throws:
        java.lang.IllegalStateException - if merge is not available
      • showMergeGUI

        public static boolean showMergeGUI​(ProjectDifference projectDifference)
                                    throws java.lang.IllegalStateException
        Show merge GUI.
        Parameters:
        projectDifference - project difference.
        Returns:
        true proceed merging, false - cancel merging.
        Throws:
        java.lang.IllegalStateException - if merge is not available
      • applyChanges

        public static boolean applyChanges​(ProjectDifference difference,
                                           ErrorHandler<java.lang.Exception> errorHandler)
                                    throws java.lang.IllegalStateException
        Apply project difference changes.
        Parameters:
        difference - project difference.
        errorHandler - invoked if error occurs.
        Returns:
        true if changes applied, otherwise - false.
        Throws:
        java.lang.IllegalStateException - if merge is not available, if changes applied on not latest teamwork project version, or trying to merge local project with teamwork project.
      • getConflictingChanges

        public static java.util.Set<Change> getConflictingChanges​(java.util.Set<Change> changes)
        Filter only changes that has conflicts.
        Parameters:
        changes - changes to filter.
        Returns:
        conflicting changes.
      • setChangeState

        public static void setChangeState​(Change change,
                                          ChangeState state)
        Set change state. Dependent, required and conflicting changes states are also modified (if modification is required).
        Parameters:
        change - change to modify state.
        state - new change state.
      • merge

        public static boolean merge​(Project targetProject,
                                    ProjectDescriptor source,
                                    @CheckForNull
                                    ProjectDescriptor ancestor,
                                    @CheckForNull
                                    ConflictResolution conflictResolution,
                                    ErrorHandler<java.lang.Exception> errorHandler,
                                    Optimization optimization)
                             throws java.lang.IllegalStateException
        Merge projects.
        Parameters:
        targetProject - target project.
        source - source project descriptor.
        ancestor - ancestor project descriptor. Pass value only for 3-way merge (null for 2-way merge).
        conflictResolution - define conflict resolution. Used only in 3-way merge. null is treated as ConflictResolution.TARGET_PREFERRED.
        errorHandler - invoked if error occurs. Allows to perform custom action.
        optimization - optimization option.
        Returns:
        true if project merged, otherwise false.
        Throws:
        java.lang.IllegalStateException - if merge is not available, if changes applied on not latest teamwork project version, or trying to merge local project with teamwork project.
      • getID

        public static java.lang.String getID​(BaseElement be)
        Returns element ID, or project id combination with element id for TWC elements.
        Parameters:
        be - base element
        Returns:
        element ID
      • getElementByID

        @CheckForNull
        public static BaseElement getElementByID​(Project project,
                                                 java.lang.String id)
        Return element from project with given simple or derived id. For esi project checks project for found element - if there are more than one project with same local id.
        Parameters:
        project - project
        id - simple or derived id
        Returns:
        element or null
      • getAllIDS

        public static java.util.Collection<java.lang.String> getAllIDS​(Project project)
        Get element IDs of all elements in given project.
        Parameters:
        project - project
        Returns:
        element IDs
      • resetCompositeIDSupport

        public static void resetCompositeIDSupport()
        Reset known composite id support.
      • callInEsiIDSupport

        public static void callInEsiIDSupport​(java.lang.Runnable runnable)
        Executes runnable where getID(BaseElement) uses twc server element id when comparing elements.
        Parameters:
        runnable - runnable to execute
      • registerCreatedElement

        public static void registerCreatedElement​(java.lang.String compositeID,
                                                  ModelObject element)
        Register created element by composite id. Composite id may contain information that element is in module, but in ancestor such module is still not used. When element is registered it can be found by provided composite id.
        Parameters:
        compositeID - composite id.
        element - created element.
      • createRemoteAncestorDescriptorForMerge

        @CheckForNull
        public static ProjectDescriptor createRemoteAncestorDescriptorForMerge​(Project targetProject,
                                                                               long mergeFrom,
                                                                               boolean lock)
        Creates remote ancestor descriptor for merge.
        Parameters:
        targetProject - target project.
        mergeFrom - source version.
        lock - should decomposition lock be taken.
        Returns:
        created descriptor or null.