Ramesh N has uploaded a new change for review.

Change subject: webadmin: add validation for create brick popup view
......................................................................

webadmin: add validation for create brick popup view

  Adding validations for entities in create brick popup view.

Change-Id: I16d3a2c377a80f37b6f8aba061ad26ac17d9736b
Bug-Url: https://bugzilla.redhat.com/1211976
Signed-off-by: Ramesh Nachimuthu <rnach...@redhat.com>
---
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/gluster/CreateBrickModel.java
A 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/validation/BrickMountPointValidation.java
A 
frontend/webadmin/modules/uicommonweb/src/test/java/org/ovirt/engine/ui/uicommonweb/validation/BrickMountPointValidationTest.java
M 
frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/UIConstants.java
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/gluster/CreateBrickPopupView.java
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/gluster/CreateBrickPopupView.ui.xml
6 files changed, 162 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/89/40989/1

diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/gluster/CreateBrickModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/gluster/CreateBrickModel.java
index 39780d5..dd7e12c 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/gluster/CreateBrickModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/gluster/CreateBrickModel.java
@@ -11,6 +11,13 @@
 import org.ovirt.engine.ui.uicommonweb.models.EntityModel;
 import org.ovirt.engine.ui.uicommonweb.models.ListModel;
 import org.ovirt.engine.ui.uicommonweb.models.Model;
+import org.ovirt.engine.ui.uicommonweb.validation.AsciiNameValidation;
+import org.ovirt.engine.ui.uicommonweb.validation.BrickMountPointValidation;
+import org.ovirt.engine.ui.uicommonweb.validation.IValidation;
+import org.ovirt.engine.ui.uicommonweb.validation.IntegerValidation;
+import org.ovirt.engine.ui.uicommonweb.validation.LengthValidation;
+import org.ovirt.engine.ui.uicommonweb.validation.NotEmptyValidation;
+import org.ovirt.engine.ui.uicompat.ConstantsManager;
 import org.ovirt.engine.ui.uicompat.Event;
 import org.ovirt.engine.ui.uicompat.EventArgs;
 import org.ovirt.engine.ui.uicompat.IEventListener;
@@ -135,7 +142,42 @@
     }
 
     public boolean validate() {
+
+        getLvName().validateEntity(new IValidation[] { new 
NotEmptyValidation(), new LengthValidation(50),
+                new AsciiNameValidation() });
+
+        if (!getLvName().getIsValid()) {
+            return false;
+        }
+
+        getMountPoint().validateEntity(new IValidation[] { new 
NotEmptyValidation(), new BrickMountPointValidation() });
+        if (!getMountPoint().getIsValid()) {
+            return false;
+        }
+
+        IntegerValidation noOfPhysicalDiscsValidation = new 
IntegerValidation();
+        noOfPhysicalDiscsValidation.setMinimum(1);
+        getNoOfPhysicalDisksInRaidVolume().validateEntity(new IValidation[] { 
new NotEmptyValidation(),
+                noOfPhysicalDiscsValidation });
+        if (!getNoOfPhysicalDisksInRaidVolume().getIsValid()) {
+            return false;
+        }
+
+        IntegerValidation stripSizeValidation = new IntegerValidation();
+        stripSizeValidation.setMinimum(1);
+        getStripeSize().validateEntity(new IValidation[] { new 
NotEmptyValidation(),
+                stripSizeValidation });
+        if (!getStripeSize().getIsValid()) {
+            return false;
+        }
+
+        if (getStorageDevices().getSelectedItems() == null || 
getStorageDevices().getSelectedItems().isEmpty()) {
+            
setMessage(ConstantsManager.getInstance().getConstants().selectStorageDevice());
+            return false;
+        }
         return true;
+
+
     }
 
     public String formatSize(double size) {
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/validation/BrickMountPointValidation.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/validation/BrickMountPointValidation.java
new file mode 100644
index 0000000..bc979db
--- /dev/null
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/validation/BrickMountPointValidation.java
@@ -0,0 +1,45 @@
+package org.ovirt.engine.ui.uicommonweb.validation;
+
+import org.ovirt.engine.ui.uicompat.ConstantsManager;
+
+
+public class BrickMountPointValidation extends BaseI18NValidation {
+
+    @Override
+    public ValidationResult validate(Object value) {
+
+        ValidationResult validationResult = super.validate(value);
+        // Ensure that there is no space in the brick mount point. Though its 
allowed in a directory name, gluster
+        // doesn't handle it properly so its better to avoid it.
+        if (validationResult.getSuccess() && value instanceof String && 
((String) value).contains(" ")) { //$NON-NLS-1$
+            validationResult.setSuccess(false);
+            
validationResult.getReasons().add(ConstantsManager.getInstance().getConstants().invalidMountPointMsg());
+        }
+
+        return validationResult;
+
+    }
+
+    @Override
+    protected String composeRegex() {
+        return start() + mountPath() + end();
+    }
+
+    private String mountPath() {
+        return "/(.*?/)?([^\\./|^\\.\\\\]+)(?:\\.([^\\\\]*)|)"; //$NON-NLS-1$
+    }
+
+    protected String start() {
+        return "^"; //$NON-NLS-1$
+    }
+
+    protected String end() {
+        return "$"; //$NON-NLS-1$
+    }
+
+    @Override
+    protected String composeMessage() {
+        return 
ConstantsManager.getInstance().getConstants().invalidMountPointMsg();
+    }
+
+}
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/test/java/org/ovirt/engine/ui/uicommonweb/validation/BrickMountPointValidationTest.java
 
b/frontend/webadmin/modules/uicommonweb/src/test/java/org/ovirt/engine/ui/uicommonweb/validation/BrickMountPointValidationTest.java
new file mode 100644
index 0000000..3915c53
--- /dev/null
+++ 
b/frontend/webadmin/modules/uicommonweb/src/test/java/org/ovirt/engine/ui/uicommonweb/validation/BrickMountPointValidationTest.java
@@ -0,0 +1,52 @@
+package org.ovirt.engine.ui.uicommonweb.validation;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.ovirt.engine.ui.uicommonweb.junit.UiCommonSetup;
+
+@SuppressWarnings("HardcodedFileSeparator")
+public class BrickMountPointValidationTest {
+    @ClassRule
+    public static final UiCommonSetup setup = new UiCommonSetup();
+
+    private BrickMountPointValidation validation;
+
+    @Before
+    public void setUp() {
+        validation = new BrickMountPointValidation();
+    }
+
+    @Test
+    public void validPath() {
+        assertValid("/path/to/dir"); // $NON-NLS-1$
+    }
+
+    @Test
+    public void invalidColonAndPath() {
+        assertInvalid(":/path/to/dir"); // $NON-NLS-1$
+    }
+
+    @Test
+    public void invalidMountPoint() {
+        assertInvalid("/.."); // $NON-NLS-1$
+        assertInvalid("/."); // $NON-NLS-1$
+    }
+
+    /* Helper Methods */
+
+    private void assertValid(String path) {
+        assertTrue(pathToBool(path));
+    }
+
+    private void assertInvalid(String path) {
+        assertFalse(pathToBool(path));
+    }
+
+    private boolean pathToBool(String path) {
+        return validation.validate(path).getSuccess();
+    }
+}
diff --git 
a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/UIConstants.java
 
b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/UIConstants.java
index 396bb7a..e182272 100644
--- 
a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/UIConstants.java
+++ 
b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/UIConstants.java
@@ -2644,5 +2644,11 @@
 
     @DefaultStringValue("Warning : Recommendations for geo-replication not met 
-")
     String geoReplicationRecommendedConfigViolation();
+
+    @DefaultStringValue("Please select a storage device to create brick.")
+    String selectStorageDevice();
+
+    @DefaultStringValue("Invalid Mount Point.")
+    String invalidMountPointMsg();
 }
 
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/gluster/CreateBrickPopupView.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/gluster/CreateBrickPopupView.java
index 3c76655..baa7e17 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/gluster/CreateBrickPopupView.java
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/gluster/CreateBrickPopupView.java
@@ -95,6 +95,10 @@
     @WithElementId
     IntegerEntityModelTextBoxEditor stripeSizeEditor;
 
+    @UiField
+    @Ignore
+    Label messageLabel;
+
     private final Driver driver = GWT.create(Driver.class);
 
     private final ApplicationConstants constants;
@@ -179,4 +183,10 @@
     public void setDeviceInfoVisibility(boolean isVisiable) {
         deviceSelectionInfo.setVisible(isVisiable);
     }
+
+    @Override
+    public void setMessage(String message) {
+        super.setMessage(message);
+        messageLabel.setText(message);
+    }
 }
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/gluster/CreateBrickPopupView.ui.xml
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/gluster/CreateBrickPopupView.ui.xml
index 561a032..2ab30f4 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/gluster/CreateBrickPopupView.ui.xml
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/popup/gluster/CreateBrickPopupView.ui.xml
@@ -10,7 +10,11 @@
                        font-weight: bold;
                        padding: 5px;
                }
-
+               .messageLabel {
+                       color: #FF0000;
+                       left: 10px;
+                       padding-left: 5px;
+               }
                .tablePanel {
                        height: 270px;
                        width: 530px;
@@ -24,7 +28,7 @@
                }
        </ui:style>
 
-       <d:SimpleDialogPanel width="550px" height="575px">
+       <d:SimpleDialogPanel width="550px" height="625px">
                <d:content>
                        <g:FlowPanel>
                                <ge:StringEntityModelTextBoxEditor 
ui:field="lvNameEditor" />
@@ -42,6 +46,7 @@
                                        </g:VerticalPanel>
                                </g:HorizontalPanel>
                                <ge:StringEntityModelLabelEditor 
ui:field="sizeEditor" />
+                               <g:Label ui:field="messageLabel" 
addStyleNames="{style.messageLabel}" />
                        </g:FlowPanel>
                </d:content>
        </d:SimpleDialogPanel>


-- 
To view, visit https://gerrit.ovirt.org/40989
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I16d3a2c377a80f37b6f8aba061ad26ac17d9736b
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.5-gluster
Gerrit-Owner: Ramesh N <rnach...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to