Bugfix NPE in target percentage (#819)
* Fixed NullPointerException in groups validation callback Signed-off-by: Natalia Kislicyn <natalia.kislicyn@bosch-si.com>
This commit is contained in:
committed by
Jeroen Laverman
parent
fde0cbdf16
commit
3b15e80e95
@@ -48,6 +48,7 @@ import com.vaadin.data.Item;
|
||||
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;
|
||||
@@ -62,6 +63,8 @@ import com.vaadin.ui.TextArea;
|
||||
import com.vaadin.ui.TextField;
|
||||
import com.vaadin.ui.UI;
|
||||
|
||||
import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.getCurrentLocale;
|
||||
|
||||
/**
|
||||
* Define groups for a Rollout
|
||||
*/
|
||||
@@ -331,8 +334,13 @@ public class DefineGroupsLayout extends GridLayout {
|
||||
}
|
||||
|
||||
// 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
|
||||
@@ -340,13 +348,14 @@ public class DefineGroupsLayout extends GridLayout {
|
||||
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() {
|
||||
@@ -463,12 +472,16 @@ public class DefineGroupsLayout extends GridLayout {
|
||||
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"));
|
||||
}
|
||||
@@ -615,7 +628,7 @@ public class DefineGroupsLayout extends GridLayout {
|
||||
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());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user