Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix npe target percentage #819

Merged
merged 5 commits into from
Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import com.vaadin.data.Validator;
import com.vaadin.data.util.converter.StringToFloatConverter;
import com.vaadin.data.util.converter.StringToIntegerConverter;
import com.vaadin.data.validator.RangeValidator;
import com.vaadin.data.validator.FloatRangeValidator;
import com.vaadin.data.validator.IntegerRangeValidator;
import com.vaadin.server.FontAwesome;
Expand All @@ -62,6 +63,8 @@
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;

import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.getCurrentLocale;

/**
* Define groups for a Rollout
*/
Expand Down Expand Up @@ -331,22 +334,29 @@ private void setGroupsValidation(final RolloutGroupsValidation validation) {
}

// validate the single groups
final int maxTargets = quotaManagement.getMaxTargetsPerRolloutGroup();
final boolean hasRemainingTargetsError = validationStatus == ValidationStatus.INVALID;
singleGroupsValidation(validation, lastRow, hasRemainingTargetsError);
}

private void singleGroupsValidation(final RolloutGroupsValidation validation, final GroupRow lastRow,
final boolean remainingError) {
final int maxTargets = quotaManagement.getMaxTargetsPerRolloutGroup();

for (int i = 0; i < groupRows.size(); ++i) {
final GroupRow row = groupRows.get(i);
// do not mask the 'remaining targets' error
if (hasRemainingTargetsError && row.equals(lastRow)) {
if (remainingError && row.equals(lastRow)) {
Nkyn marked this conversation as resolved.
Show resolved Hide resolved
continue;
}
row.resetError();
final Long count = groupsValidation.getTargetsPerGroup().get(i);
if (count != null && count > maxTargets) {
row.setError(i18n.getMessage(MESSAGE_ROLLOUT_MAX_GROUP_SIZE_EXCEEDED, maxTargets));
setValidationStatus(ValidationStatus.INVALID);
if (validation != null) {
Nkyn marked this conversation as resolved.
Show resolved Hide resolved
final Long count = validation.getTargetsPerGroup().get(i);
if (count != null && count > maxTargets) {
row.setError(i18n.getMessage(MESSAGE_ROLLOUT_MAX_GROUP_SIZE_EXCEEDED, maxTargets));
setValidationStatus(ValidationStatus.INVALID);
}
}
}

}

private List<RolloutGroupCreate> getGroupsFromRows() {
Expand Down Expand Up @@ -463,12 +473,18 @@ private void removeGroupRow(final GroupRow groupRow) {
private void validateMandatoryPercentage(final Object value) {
if (value != null) {
final String message = i18n.getMessage("message.rollout.field.value.range", 0, 100);
RangeValidator rangeValidator;
if (value instanceof Float) {
new FloatRangeValidator(message, 0F, 100F).validate(value);
rangeValidator = new FloatRangeValidator(message, 0F, 100F);
}
else if (value instanceof Integer) {
Nkyn marked this conversation as resolved.
Show resolved Hide resolved
rangeValidator = new IntegerRangeValidator(message, 0, 100);
}
if (value instanceof Integer) {
new IntegerRangeValidator(message, 0, 100).validate(value);
else {
Nkyn marked this conversation as resolved.
Show resolved Hide resolved
throw new Validator.InvalidValueException(i18n.getMessage("message.rollout.field.value.type"));
Nkyn marked this conversation as resolved.
Show resolved Hide resolved
}
rangeValidator.setMinValueIncluded(false);
rangeValidator.validate(value);
} else {
throw new Validator.EmptyValueException(i18n.getMessage("message.enter.number"));
}
Expand Down Expand Up @@ -615,7 +631,7 @@ public void populateByGroup(final RolloutGroup group) {
targetFilterQuery.setValue(group.getTargetFilterQuery());
populateTargetFilterQuery(group);

targetPercentage.setValue(String.format("%.2f", group.getTargetPercentage()));
targetPercentage.setValue(String.format(getCurrentLocale(), "%.2f", group.getTargetPercentage()));
triggerThreshold.setValue(group.getSuccessConditionExp());
errorThreshold.setValue(group.getErrorConditionExp());

Expand Down
1 change: 1 addition & 0 deletions hawkbit-ui/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ message.rollout.name.empty = Please enter a name for Rollout
message.correct.invalid.value = Please correct invalid values
message.enter.number = Please enter number
message.rollout.field.value.range = Value should be in range {0} to {1}
message.rollout.field.value.type = Invalid type of value
Nkyn marked this conversation as resolved.
Show resolved Hide resolved
message.rollout.filter.target.exists = The selected target filter does not match any existing target
message.rollout.max.group.size.exceeded = The maximum group size of {0} targets is exceeded. Please increase the number of groups or select a different target filter
message.rollout.max.group.size.exceeded.advanced = The maximum size of {0} targets is exceeded for this group. Please re-distribute the targets across the groups and create further groups if needed
Expand Down