java.lang.Object
de.hybris.platform.sap.productconfig.frontend.util.impl.UiStateHandler

public class UiStateHandler extends 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 Details

    • UiStateHandler

      public UiStateHandler()
  • Method Details

    • countNumberOfUiErrorsPerGroup

      public int countNumberOfUiErrorsPerGroup(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(List<UiGroupData> list, Predicate<GroupType> typeCondtion, Predicate<UiGroupData> statusCondition)
    • expandFirstGroupWithError

      protected UiGroupData expandFirstGroupWithError(List<UiGroupData> list)
    • expandFirstGroupWithErrorOrConflict

      protected UiGroupData expandFirstGroupWithErrorOrConflict(List<UiGroupData> list)
    • expandGroupCloseOthers

      protected void expandGroupCloseOthers(List<UiGroupData> list, UiGroupData expandedGroup)
    • findCollapsedErrorCstics

      public Map<String,org.springframework.validation.FieldError> findCollapsedErrorCstics(Map<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(Map<String,org.springframework.validation.FieldError> userInputToRestore, Map<String,org.springframework.validation.FieldError> userInputToRemeber, UiGroupData group, boolean isRootCollapsed)
    • getFirstCsticWithErrorInGroup

      public CsticData getFirstCsticWithErrorInGroup(UiGroupData group)
      Returns the first cstic with status CsticStatusType.ERROR, CsticStatusType.WARNING or CsticStatusType.CONFLICT.
      Searches the subgroups recursively.
      Parameters:
      group - root group
      Returns:
      the first erroneous cstic, or null in case the give group and all subgroups are error free
    • 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 Map<String,org.springframework.validation.FieldError> mergeUiErrors(Map<String,org.springframework.validation.FieldError> uiErrorSource, Map<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(List<UiGroupData> uiGroups)
    • handleValidationErrorsBeforeUpdate

      public Map<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:
    • getCsticForFieldPath

      public CsticData getCsticForFieldPath(ConfigurationData configData, String fieldPath)
      Retrieves the cstic form the configuration, by analyzing the provided UI field path.
      For example path "groups[1].subGroups[2].cstics[0].value", 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(Map<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(String prefix, Map<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(Map<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(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(List<UiGroupData> uiGroups)
    • getGroupIdToDisplayAfterResolvingConflicts

      public 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, String groupIdToDisplayUiStatus)
    • getGroupIdWithoutInstanceName

      protected String getGroupIdWithoutInstanceName(String groupId)
    • determineReplacementGroupId

      protected String determineReplacementGroupId(ConfigurationData configData, String groupIdToDisplay, String groupIdToDisplayUiStatus)
    • determineGroupIdForDisplayFromUiStatus

      protected String determineGroupIdForDisplayFromUiStatus(ConfigurationData configData, UiStatus uiStatus, String groupIdToDisplay)
    • compileGroupForDisplay

      public void compileGroupForDisplay(ConfigurationData configData, UiStatus uiStatus)
      Compiles the group which is currently active for display, and sets the respective attribute ConfigurationData.setGroupToDisplay(UiGroupForDisplayData) in configData
      Parameters:
      configData -
      uiStatus - Can be null, in this case we use the first group as group to display
    • compileGroupForDisplay

      protected UiGroupData compileGroupForDisplay(List<UiGroupData> groups, String groupIdToDisplay, Deque<String> path, Deque<String> groupIdPath, String groupsIdentifier)
    • extractPathAsString

      protected String extractPathAsString(Deque<String> path)
    • getFirstGroupWithCstics

      protected UiGroupData getFirstGroupWithCstics(List<UiGroupData> uiGroups)
    • fillAllVisibleCsticIdsOfGroup

      public void fillAllVisibleCsticIdsOfGroup(List<UiGroupStatus> groups, List<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(List<UiCsticStatus> cstics, List<String> pricingInput)
    • getGroupIndex

      protected int getGroupIndex(ConfigurationData configData, PathExtractor extractor)
    • getUiKeyGenerator

      protected UniqueUIKeyGenerator getUiKeyGenerator()
    • setUiKeyGenerator

      public void setUiKeyGenerator(UniqueUIKeyGenerator uiKeyGenerator)
      Parameters:
      uiKeyGenerator - the uiKeyGenerator to set