Class UiStateHandler


  • public class UiStateHandler
    extends java.lang.Object
    This class contains utility methods for UI-Status related controller logics, such as:
    • Expand/Collapse of UI-Groups
    • Conflict/Error handling
    • cstic-/Groupstate handling
    • message handling
    • Constructor Detail

      • UiStateHandler

        public UiStateHandler()
    • Method Detail

      • countNumberOfUiErrorsPerGroup

        public int countNumberOfUiErrorsPerGroup​(java.util.List<UiGroupData> uiGroups)
        counts the number of UI-Errors for the given group.
        Parameters:
        uiGroups - group to check
        Returns:
        number of errors
      • expandFirstGroupWithCondition

        protected UiGroupData expandFirstGroupWithCondition​(java.util.List<UiGroupData> list,
                                                            java.util.function.Predicate<GroupType> typeCondtion,
                                                            java.util.function.Predicate<UiGroupData> statusCondition)
      • expandFirstGroupWithError

        protected UiGroupData expandFirstGroupWithError​(java.util.List<UiGroupData> list)
      • expandFirstGroupWithErrorOrConflict

        protected UiGroupData expandFirstGroupWithErrorOrConflict​(java.util.List<UiGroupData> list)
      • expandGroupCloseOthers

        protected void expandGroupCloseOthers​(java.util.List<UiGroupData> list,
                                              UiGroupData expandedGroup)
      • findCollapsedErrorCstics

        public java.util.Map<java.lang.String,​org.springframework.validation.FieldError> findCollapsedErrorCstics​(java.util.Map<java.lang.String,​org.springframework.validation.FieldError> userInputToRestore,
                                                                                                                        ConfigurationData latestConfiguration)
        Get all UI-Errors that are attached to currently not visible cstics, because the UI group the cstic is assigned to is currently collapsed.
        Parameters:
        userInputToRestore - Erroneous user input that should be kept and restored during next round trip.
        latestConfiguration - actual configuration
        Returns:
        UI-Errors currently not visible
      • findCollapsedErrorCstics

        protected void findCollapsedErrorCstics​(java.util.Map<java.lang.String,​org.springframework.validation.FieldError> userInputToRestore,
                                                java.util.Map<java.lang.String,​org.springframework.validation.FieldError> userInputToRemeber,
                                                UiGroupData group,
                                                boolean isRootCollapsed)
      • handleAutoExpand

        public UiGroupData handleAutoExpand​(ConfigurationData configData,
                                            UiStatus uiStatus)
        Handles the AutoExpand Mode. This means the first erroneous group is automatically expanded, until the user leaves the auto expand mode or nor more such group exists.
        Parameters:
        configData - current configuration
        uiStatus - current UI status
        Returns:
        group to expand
      • getConflictGroupNo

        public int getConflictGroupNo​(ConfigurationData configData,
                                      UiGroupData uiGroup)
        Get the conflict group index, of the given uiGroup, within the conflict groups. If it is a multi level product always 1 will be returned.
        Parameters:
        configData - The configuration data
        uiGroup - The searched conflict group
        Returns:
        The index of the given conflict group (index count starts with 1)
      • mergeUiErrors

        public java.util.Map<java.lang.String,​org.springframework.validation.FieldError> mergeUiErrors​(java.util.Map<java.lang.String,​org.springframework.validation.FieldError> uiErrorSource,
                                                                                                             java.util.Map<java.lang.String,​org.springframework.validation.FieldError> otherUiErrorSource)
        Merges both given uiError maps into one, taking care of null values.
        Parameters:
        uiErrorSource - UI errors
        otherUiErrorSource - UI erros
        Returns:
        merged map
      • resetGroupStatus

        public void resetGroupStatus​(ConfigurationData configData)
        Resets recursively the UI group status for the whole configuration to GroupStatusType.DEFAULT.
        Parameters:
        configData - configuration to process
      • resetGroupWithSubGroups

        protected void resetGroupWithSubGroups​(java.util.List<UiGroupData> uiGroups)
      • handleValidationErrorsBeforeUpdate

        public java.util.Map<java.lang.String,​org.springframework.validation.FieldError> handleValidationErrorsBeforeUpdate​(ConfigurationData configData,
                                                                                                                                  org.springframework.validation.BindingResult bindingResult)
        Remembers any UI-Validation error including the causing user Input. Then replaces the erroneous value with the last know good value.
        The underlying configuration engine requires valid data for processing, hence we do not send data that failed the UI validation to the engine. Instead the last known good data is send. After the update the erroneous user input is restored. So user is not blocked by UI validation error. Instead he can proceed and resolve the error any time laster.
        Parameters:
        configData - actual configuration
        bindingResult - validation result
        Returns:
        UI errors to remember
        See Also:
        restoreValidationErrorsAfterUpdate(Map, ConfigurationData, BindingResult)
      • getCsticForFieldPath

        public CsticData getCsticForFieldPath​(ConfigurationData configData,
                                              java.lang.String fieldPath)
        Retrieves the cstic form the configuration, by analyzing the provided UI field path.
        For example path "group[1].subGroup[2].cstic[0]", would extract the first cstic of the third subgroup of the second group of the configuration.
        Parameters:
        configData - actual configuration
        fieldPath - UI path the cstic
        Returns:
        extracted cstic
      • restoreValidationErrorsAfterUpdate

        public org.springframework.validation.BindingResult restoreValidationErrorsAfterUpdate​(java.util.Map<java.lang.String,​org.springframework.validation.FieldError> userInputToRestore,
                                                                                               ConfigurationData latestConfiguration,
                                                                                               org.springframework.validation.BindingResult bindingResult)
        Restores UI errors that were remembered before update, after the update was executed.
        Foe more details see handleValidationErrorsBeforeUpdate(ConfigurationData, BindingResult).
        Parameters:
        userInputToRestore - UI errors to restore
        latestConfiguration - actual configuration
        bindingResult - actual UI errors
        Returns:
        updated UI errors
      • restoreValidationErrorsInGroup

        protected void restoreValidationErrorsInGroup​(java.lang.String prefix,
                                                      java.util.Map<java.lang.String,​org.springframework.validation.FieldError> userInputToRestore,
                                                      org.springframework.validation.BindingResult bindingResult,
                                                      UiGroupData group)
      • isEditableUiType

        protected boolean isEditableUiType​(UiType uiType)
      • restoreValidationErrorsOnGetConfig

        public org.springframework.validation.BindingResult restoreValidationErrorsOnGetConfig​(java.util.Map<java.lang.String,​org.springframework.validation.FieldError> userInputToRestore,
                                                                                               ConfigurationData latestConfiguration,
                                                                                               org.springframework.validation.BindingResult bindingResult)
        Restores UI errors that were remembered before update, after the update was executed.
        Foe more details see handleValidationErrorsBeforeUpdate(ConfigurationData, BindingResult).
        Parameters:
        userInputToRestore - UI errors to restore
        latestConfiguration - actual configuration
        bindingResult - actual UI errors
        Returns:
        updated UI errors
      • handleConflictSolverMessage

        public void handleConflictSolverMessage​(UiStatus uiStatus,
                                                int newNumberOfConflicts,
                                                org.springframework.ui.Model model)
        Create UI messages when conflicts occur or when one or all conflicts are solved.
        Parameters:
        uiStatus - oldUiStatus
        newNumberOfConflicts - actual number of conflicts
        model - UI View Model
      • handleDifferentNumberOfNewOldConflictMessages

        protected void handleDifferentNumberOfNewOldConflictMessages​(org.springframework.ui.Model model,
                                                                     int oldNumberOfConflicts,
                                                                     int newNumberOfConflicts)
      • handleProductConfigMessages

        public void handleProductConfigMessages​(java.util.List<ProductConfigMessageData> messages,
                                                org.springframework.ui.Model model)
        Creates a UI-Message for every generic configuration message attached to the actual configuration.
        Parameters:
        messages - list of messages
        model - UI View Model
      • hasNoConflicts

        protected boolean hasNoConflicts​(int oldNumberOfConflicts,
                                         int newNumberOfConflicts)
      • hasOnlyNewConflicts

        protected boolean hasOnlyNewConflicts​(int oldNumberOfConflicts,
                                              int newNumberOfConflicts)
      • hasOnlyOldConflicts

        protected boolean hasOnlyOldConflicts​(int oldNumberOfConflicts,
                                              int newNumberOfConflicts)
      • getFirstGroupWithCsticsDeepSearch

        protected UiGroupData getFirstGroupWithCsticsDeepSearch​(java.util.List<UiGroupData> uiGroups)
      • getGroupIdToDisplayAfterResolvingConflicts

        public java.lang.String getGroupIdToDisplayAfterResolvingConflicts​(ConfigurationData configData,
                                                                           UiStatus uiStatus)
        This method identifies the group to which the UI should navigate after all conflicts are solved. For single-level models this would be the first group containing a cstic. (A UI group may be empty, or only containing other UI group, but no cstics.)
        For multi-level models this would be the last non conflict group (i.e. the group that was displayed before the conflict solver was entered)
        Parameters:
        configData - actual configuration
        uiStatus -
        Returns:
        id of the group that should be navigated to after resolving conflicts
      • checkGroupExistence

        protected boolean checkGroupExistence​(ConfigurationData configData,
                                              java.lang.String groupIdToDisplayUiStatus)
      • getGroupIdWithoutInstanceName

        protected java.lang.String getGroupIdWithoutInstanceName​(java.lang.String groupId)
      • extractInstanceNameFromGroupId

        protected java.lang.String extractInstanceNameFromGroupId​(java.lang.String groupId)
      • determineReplacementGroupId

        protected java.lang.String determineReplacementGroupId​(ConfigurationData configData,
                                                               java.lang.String groupIdToDisplay,
                                                               java.lang.String groupIdToDisplayUiStatus)
      • determineGroupIdForDisplayFromUiStatus

        protected java.lang.String determineGroupIdForDisplayFromUiStatus​(ConfigurationData configData,
                                                                          UiStatus uiStatus,
                                                                          java.lang.String groupIdToDisplay)
      • compileGroupForDisplay

        protected UiGroupData compileGroupForDisplay​(java.util.List<UiGroupData> groups,
                                                     java.lang.String groupIdToDisplay,
                                                     java.util.Deque<java.lang.String> path,
                                                     java.util.Deque<java.lang.String> groupIdPath,
                                                     java.lang.String groupsIdentifier)
      • extractPathAsString

        protected java.lang.String extractPathAsString​(java.util.Deque<java.lang.String> path)
      • getFirstGroupWithCstics

        protected UiGroupData getFirstGroupWithCstics​(java.util.List<UiGroupData> uiGroups)
      • fillAllVisibleCsticIdsOfGroup

        public void fillAllVisibleCsticIdsOfGroup​(java.util.List<UiGroupStatus> groups,
                                                  java.util.List<java.lang.String> csticList)
        Collects the cstic Ids of all cstic of thos group and any subgroup that are currently visible.
        Parameters:
        groups - group to check
        csticList - list of visible cstics
      • fillAllVisibleCsticIds

        protected void fillAllVisibleCsticIds​(java.util.List<UiCsticStatus> cstics,
                                              java.util.List<java.lang.String> pricingInput)