Class UiStateHandler
java.lang.Object
de.hybris.platform.sap.productconfig.frontend.util.impl.UiStateHandler
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleancheckGroupExistence(ConfigurationData configData, String groupIdToDisplayUiStatus) voidcompileGroupForDisplay(ConfigurationData configData, UiStatus uiStatus) Compiles the group which is currently active for display, and sets the respective attributeConfigurationData.setGroupToDisplay(UiGroupForDisplayData)in configDataprotected UiGroupDatacompileGroupForDisplay(List<UiGroupData> groups, String groupIdToDisplay, Deque<String> path, Deque<String> groupIdPath, String groupsIdentifier) intcountNumberOfUiErrorsPerGroup(List<UiGroupData> uiGroups) counts the number of UI-Errors for the given group.protected StringdetermineGroupIdForDisplayFromUiStatus(ConfigurationData configData, UiStatus uiStatus, String groupIdToDisplay) protected StringdetermineReplacementGroupId(ConfigurationData configData, String groupIdToDisplay, String groupIdToDisplayUiStatus) protected UiGroupDataexpandFirstGroupWithCondition(List<UiGroupData> list, Predicate<GroupType> typeCondtion, Predicate<UiGroupData> statusCondition) protected UiGroupDataprotected UiGroupDataprotected voidexpandGroupCloseOthers(List<UiGroupData> list, UiGroupData expandedGroup) protected StringextractPathAsString(Deque<String> path) protected voidfillAllVisibleCsticIds(List<UiCsticStatus> cstics, List<String> pricingInput) voidfillAllVisibleCsticIdsOfGroup(List<UiGroupStatus> groups, List<String> csticList) Collects the cstic Ids of all cstic of thos group and any subgroup that are currently visible.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.protected voidfindCollapsedErrorCstics(Map<String, org.springframework.validation.FieldError> userInputToRestore, Map<String, org.springframework.validation.FieldError> userInputToRemeber, UiGroupData group, boolean isRootCollapsed) intgetConflictGroupNo(ConfigurationData configData, UiGroupData uiGroup) Get the conflict group index, of the given uiGroup, within the conflict groups.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.Returns the first cstic with statusCsticStatusType.ERROR,CsticStatusType.WARNINGorCsticStatusType.CONFLICT.
Searches the subgroups recursively.protected UiGroupDatagetFirstGroupWithCstics(List<UiGroupData> uiGroups) protected UiGroupDatagetFirstGroupWithCsticsDeepSearch(List<UiGroupData> uiGroups) getGroupIdToDisplayAfterResolvingConflicts(ConfigurationData configData, UiStatus uiStatus) This method identifies the group to which the UI should navigate after all conflicts are solved.protected StringgetGroupIdWithoutInstanceName(String groupId) protected intgetGroupIndex(ConfigurationData configData, PathExtractor extractor) protected UniqueUIKeyGeneratorhandleAutoExpand(ConfigurationData configData, UiStatus uiStatus) Handles the AutoExpand Mode.voidhandleConflictSolverMessage(UiStatus uiStatus, int newNumberOfConflicts, org.springframework.ui.Model model) Create UI messages when conflicts occur or when one or all conflicts are solved.protected voidhandleDifferentNumberOfNewOldConflictMessages(org.springframework.ui.Model model, int oldNumberOfConflicts, int newNumberOfConflicts) voidhandleProductConfigMessages(List<ProductConfigMessageData> messages, org.springframework.ui.Model model) Creates a UI-Message for every generic configuration message attached to the actual configuration.handleValidationErrorsBeforeUpdate(ConfigurationData configData, org.springframework.validation.BindingResult bindingResult) Remembers any UI-Validation error including the causing user Input.protected booleanhasNoConflicts(int oldNumberOfConflicts, int newNumberOfConflicts) protected booleanhasOnlyNewConflicts(int oldNumberOfConflicts, int newNumberOfConflicts) protected booleanhasOnlyOldConflicts(int oldNumberOfConflicts, int newNumberOfConflicts) protected booleanisEditableUiType(UiType uiType) 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.voidresetGroupStatus(ConfigurationData configData) Resets recursively the UI group status for the whole configuration toGroupStatusType.DEFAULT.protected voidresetGroupWithSubGroups(List<UiGroupData> uiGroups) org.springframework.validation.BindingResultrestoreValidationErrorsAfterUpdate(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 seehandleValidationErrorsBeforeUpdate(ConfigurationData, BindingResult).protected voidrestoreValidationErrorsInGroup(String prefix, Map<String, org.springframework.validation.FieldError> userInputToRestore, org.springframework.validation.BindingResult bindingResult, UiGroupData group) org.springframework.validation.BindingResultrestoreValidationErrorsOnGetConfig(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 seehandleValidationErrorsBeforeUpdate(ConfigurationData, BindingResult).voidsetUiKeyGenerator(UniqueUIKeyGenerator uiKeyGenerator)
-
Constructor Details
-
UiStateHandler
public UiStateHandler()
-
-
Method Details
-
countNumberOfUiErrorsPerGroup
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
-
expandFirstGroupWithErrorOrConflict
-
expandGroupCloseOthers
-
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
Returns the first cstic with statusCsticStatusType.ERROR,CsticStatusType.WARNINGorCsticStatusType.CONFLICT.
Searches the subgroups recursively.- Parameters:
group- root group- Returns:
- the first erroneous cstic, or
nullin case the give group and all subgroups are error free
-
handleAutoExpand
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 configurationuiStatus- current UI status- Returns:
- group to expand
-
getConflictGroupNo
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 datauiGroup- 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 errorsotherUiErrorSource- UI erros- Returns:
- merged map
-
resetGroupStatus
Resets recursively the UI group status for the whole configuration toGroupStatusType.DEFAULT.- Parameters:
configData- configuration to process
-
resetGroupWithSubGroups
-
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 configurationbindingResult- validation result- Returns:
- UI errors to remember
- See Also:
-
getCsticForFieldPath
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 configurationfieldPath- 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 seehandleValidationErrorsBeforeUpdate(ConfigurationData, BindingResult).- Parameters:
userInputToRestore- UI errors to restorelatestConfiguration- actual configurationbindingResult- 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
-
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 seehandleValidationErrorsBeforeUpdate(ConfigurationData, BindingResult).- Parameters:
userInputToRestore- UI errors to restorelatestConfiguration- actual configurationbindingResult- 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- oldUiStatusnewNumberOfConflicts- actual number of conflictsmodel- 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 messagesmodel- 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
-
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 configurationuiStatus-- Returns:
- id of the group that should be navigated to after resolving conflicts
-
checkGroupExistence
protected boolean checkGroupExistence(ConfigurationData configData, String groupIdToDisplayUiStatus) -
getGroupIdWithoutInstanceName
-
determineReplacementGroupId
protected String determineReplacementGroupId(ConfigurationData configData, String groupIdToDisplay, String groupIdToDisplayUiStatus) -
determineGroupIdForDisplayFromUiStatus
protected String determineGroupIdForDisplayFromUiStatus(ConfigurationData configData, UiStatus uiStatus, String groupIdToDisplay) -
compileGroupForDisplay
Compiles the group which is currently active for display, and sets the respective attributeConfigurationData.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
-
getFirstGroupWithCstics
-
fillAllVisibleCsticIdsOfGroup
Collects the cstic Ids of all cstic of thos group and any subgroup that are currently visible.- Parameters:
groups- group to checkcsticList- list of visible cstics
-
fillAllVisibleCsticIds
-
getGroupIndex
-
getUiKeyGenerator
-
setUiKeyGenerator
- Parameters:
uiKeyGenerator- the uiKeyGenerator to set
-