use of org.ovirt.engine.ui.uicommonweb.validation.RegexValidation in project ovirt-engine by oVirt.
the class KeyValueModel method setKeyValueString.
public void setKeyValueString(List<String> lines) {
if (lines == null) {
return;
}
allKeyValueMap = new HashMap<>();
allRegExKeys = new HashMap<>();
RegexValidation regexValidation = new RegexValidation();
// $NON-NLS-1$
regexValidation.setExpression("\\^\\((([a-zA-Z0-9_]+[|]+)*)[a-zA-Z0-9_]+\\)\\$");
String[] splitLine;
for (String line : lines) {
if (line.isEmpty()) {
continue;
}
splitLine = line.split(KEY_VALUE_DELIMETER, 2);
String key = splitLine[0];
allKeyValueMap.put(key, splitLine[1]);
ValidationResult valid = regexValidation.validate(allKeyValueMap.get(key));
if (valid.getSuccess()) {
String[] values = allKeyValueMap.get(key).substring(2, allKeyValueMap.get(key).length() - 2).split(// $NON-NLS-1$
"\\|");
allRegExKeys.put(key, Arrays.asList(values));
}
}
deserialize(saveEntity);
}
use of org.ovirt.engine.ui.uicommonweb.validation.RegexValidation in project ovirt-engine by oVirt.
the class KeyValueModel method validate.
public boolean validate() {
setIsValid(true);
if (getItems() == null || !getIsAvailable()) {
return true;
}
boolean isValid = true;
for (KeyValueLineModel keyValueLineModel : getItems()) {
String key = keyValueLineModel.getKeys().getSelectedItem();
if (!isKeyValid(key)) {
continue;
}
keyValueLineModel.getValue().setIsValid(true);
RegexValidation regexValidation = new RegexValidation();
regexValidation.setMessage(ConstantsManager.getInstance().getMessages().customPropertyValueShouldBeInFormatReason(key, allKeyValueMap.get(key)));
regexValidation.setExpression(allKeyValueMap.get(key));
keyValueLineModel.getValue().validateEntity(new IValidation[] { regexValidation });
isValid &= keyValueLineModel.getValue().getIsValid();
}
setIsValid(isValid);
return isValid;
}
use of org.ovirt.engine.ui.uicommonweb.validation.RegexValidation in project ovirt-engine by oVirt.
the class StorageListModel method storageNameValidation.
public void storageNameValidation() {
StorageModel model = (StorageModel) getWindow();
String name = model.getName().getEntity();
model.getName().setIsValid(true);
AsyncDataProvider.getInstance().isStorageDomainNameUnique(new AsyncQuery<>(isNameUnique -> {
final StorageModel storageModel = (StorageModel) getWindow();
String name1 = storageModel.getName().getEntity();
String tempVar = storageModel.getOriginalName();
// $NON-NLS-1$
String originalName = (tempVar != null) ? tempVar : "";
if (!isNameUnique && name1.compareToIgnoreCase(originalName) != 0) {
storageModel.getName().getInvalidityReasons().add(ConstantsManager.getInstance().getConstants().nameMustBeUniqueInvalidReason());
storageModel.getName().setIsValid(false);
postStorageNameValidation();
} else {
AsyncDataProvider.getInstance().getStorageDomainMaxNameLength(new AsyncQuery<>(nameMaxLength -> {
RegexValidation tempVar2 = new RegexValidation();
// $NON-NLS-1$ //$NON-NLS-2$
tempVar2.setExpression("^[A-Za-z0-9_-]{1," + nameMaxLength + "}$");
tempVar2.setMessage(ConstantsManager.getInstance().getMessages().nameCanContainOnlyMsg(nameMaxLength));
storageModel.getName().validateEntity(new IValidation[] { new NotEmptyValidation(), tempVar2 });
postStorageNameValidation();
}));
}
}), name);
}
use of org.ovirt.engine.ui.uicommonweb.validation.RegexValidation in project ovirt-engine by oVirt.
the class DataCenterGuideModel method onAddStorage.
public void onAddStorage() {
StorageModel model = (StorageModel) getWindow();
String storageName = model.getName().getEntity();
AsyncDataProvider.getInstance().isStorageDomainNameUnique(new AsyncQuery<>(isNameUnique -> {
StorageModel storageModel = (StorageModel) getWindow();
String name = storageModel.getName().getEntity();
String tempVar = storageModel.getOriginalName();
// $NON-NLS-1$
String originalName = (tempVar != null) ? tempVar : "";
if (!isNameUnique && name.compareToIgnoreCase(originalName) != 0) {
storageModel.getName().getInvalidityReasons().add(ConstantsManager.getInstance().getConstants().nameMustBeUniqueInvalidReason());
storageModel.getName().setIsValid(false);
}
AsyncDataProvider.getInstance().getStorageDomainMaxNameLength(new AsyncQuery<>(nameMaxLength -> {
StorageModel storageModel1 = (StorageModel) getWindow();
RegexValidation tempVar2 = new RegexValidation();
// $NON-NLS-1$ //$NON-NLS-2$
tempVar2.setExpression("^[A-Za-z0-9_-]{1," + nameMaxLength + "}$");
tempVar2.setMessage(ConstantsManager.getInstance().getMessages().nameCanContainOnlyMsg(nameMaxLength));
storageModel1.getName().validateEntity(new IValidation[] { new NotEmptyValidation(), tempVar2 });
postOnAddStorage();
}));
}), storageName);
}
use of org.ovirt.engine.ui.uicommonweb.validation.RegexValidation in project ovirt-engine by oVirt.
the class NetworkModel method validate.
private boolean validate() {
LengthValidation tempVar = new LengthValidation();
tempVar.setMaxLength(BusinessEntitiesDefinitions.NETWORK_NAME_SIZE);
RegexValidation tempVar2 = new RegexValidation();
tempVar2.setIsNegate(true);
// $NON-NLS-1$
tempVar2.setExpression("^(bond)");
tempVar2.setMessage(ConstantsManager.getInstance().getConstants().networkNameStartMsg());
getName().validateEntity(new IValidation[] { new NotEmptyValidation(), tempVar, tempVar2 });
LengthValidation tempVar3 = new LengthValidation();
tempVar3.setMaxLength(40);
getDescription().validateEntity(new IValidation[] { tempVar3 });
getComment().validateEntity(new IValidation[] { new SpecialAsciiI18NOrNoneValidation() });
getVLanTag().setIsValid(true);
if (getHasVLanTag().getEntity()) {
IntegerValidation tempVar4 = new IntegerValidation();
tempVar4.setMinimum(0);
tempVar4.setMaximum(4094);
getVLanTag().validateEntity(new IValidation[] { new NotEmptyValidation(), tempVar4 });
}
IntegerValidation tempVar5 = new IntegerValidation();
tempVar5.setMinimum(68);
getMtu().validateEntity(new IValidation[] { new NotEmptyValidation(), tempVar5 });
getDnsConfigurationModel().validate();
getExternalProviders().validateSelectedItem(new IValidation[] { new NotEmptyValidation() });
boolean subnetValid = true;
if (getExternal().getEntity() && getCreateSubnet().getEntity()) {
subnetValid = getSubnetModel().validate();
}
boolean profilesValid = true;
Iterable<VnicProfileModel> profiles = getProfiles().getItems();
for (VnicProfileModel profileModel : profiles) {
if (!profileModel.validate()) {
profilesValid = false;
}
}
getNetworkLabel().validateSelectedItem(new IValidation[] { new AsciiNameValidation() });
setValidTab(TabName.GENERAL_TAB, isGeneralTabValid());
setValidTab(TabName.SUBNET_TAB, subnetValid);
setValidTab(TabName.PROFILES_TAB, profilesValid);
ValidationCompleteEvent.fire(getEventBus(), this);
return allTabsValid();
}
Aggregations