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
Changes from all 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,28 @@ private void setGroupsValidation(final RolloutGroupsValidation validation) {
}

// validate the single groups
final int maxTargets = quotaManagement.getMaxTargetsPerRolloutGroup();
singleGroupsValidation(lastRow);
}

private void singleGroupsValidation(final GroupRow lastRow) {
final boolean hasRemainingTargetsError = validationStatus == ValidationStatus.INVALID;
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)) {
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 (groupsValidation != null) {
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);
}
}
}

}

private List<RolloutGroupCreate> getGroupsFromRows() {
Expand Down Expand Up @@ -463,12 +472,16 @@ 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);
}
if (value instanceof Integer) {
new IntegerRangeValidator(message, 0, 100).validate(value);
rangeValidator = new FloatRangeValidator(message, 0F, 100F);
} else if (value instanceof Integer) {
rangeValidator = new IntegerRangeValidator(message, 0, 100);
} else {
throw new Validator.InvalidValueException(i18n.getMessage("message.enter.number"));
}
rangeValidator.setMinValueIncluded(false);
rangeValidator.validate(value);
} else {
throw new Validator.EmptyValueException(i18n.getMessage("message.enter.number"));
}
Expand Down Expand Up @@ -615,7 +628,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