Mike Kolesnik has uploaded a new change for review.

Change subject: engine: Added variable replacements to ValidationResult
......................................................................

engine: Added variable replacements to ValidationResult

Added a possibility to include variable replacements in the validation
result, so that variables inside the validation failure message can be
replaced with the given values.

This should make it easier to use validations that require variable
replacements inside the message.

Change-Id: I2ef15a9454cac7ea179fdbac0003944bc0327dcc
Signed-off-by: Mike Kolesnik <mkole...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ValidationResult.java
2 files changed, 37 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/67/10267/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
index 9e7e337..549753e 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
@@ -44,13 +44,13 @@
 import org.ovirt.engine.core.common.businessentities.AsyncTaskResultEnum;
 import org.ovirt.engine.core.common.businessentities.AsyncTaskStatus;
 import org.ovirt.engine.core.common.businessentities.AsyncTaskStatusEnum;
+import org.ovirt.engine.core.common.businessentities.AsyncTasks;
 import org.ovirt.engine.core.common.businessentities.BusinessEntity;
 import org.ovirt.engine.core.common.businessentities.BusinessEntitySnapshot;
 import 
org.ovirt.engine.core.common.businessentities.BusinessEntitySnapshot.EntityStatusSnapshot;
 import 
org.ovirt.engine.core.common.businessentities.BusinessEntitySnapshot.SnapshotType;
 import org.ovirt.engine.core.common.businessentities.QuotaEnforcementTypeEnum;
 import org.ovirt.engine.core.common.businessentities.action_version_map;
-import org.ovirt.engine.core.common.businessentities.AsyncTasks;
 import org.ovirt.engine.core.common.businessentities.storage_pool;
 import org.ovirt.engine.core.common.businessentities.tags;
 import org.ovirt.engine.core.common.errors.VdcBLLException;
@@ -1477,6 +1477,11 @@
     protected boolean validate(ValidationResult validationResult) {
         if (!validationResult.isValid()) {
             addCanDoActionMessage(validationResult.getMessage());
+            if (validationResult.getVariableReplacements() != null) {
+                for (String variableReplacement : 
validationResult.getVariableReplacements()) {
+                    addCanDoActionMessage(variableReplacement);
+                }
+            }
         }
 
         return validationResult.isValid();
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ValidationResult.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ValidationResult.java
index d8c6645..dfb7cbd 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ValidationResult.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ValidationResult.java
@@ -1,5 +1,9 @@
 package org.ovirt.engine.core.bll;
 
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
 import org.ovirt.engine.core.dal.VdcBllMessages;
 
 /**
@@ -18,6 +22,11 @@
      * In case the validation succeeded it is <code>null</code>, otherwise it 
contains the validation failure message.
      */
     private final VdcBllMessages message;
+
+    /**
+     * If there are any replacements for variables in the message, they can be 
set here.
+     */
+    private List<String> variableReplacements;
 
     /**
      * Default validation result is success with no message.
@@ -41,6 +50,20 @@
     }
 
     /**
+     * Validation result for failure with a given message.
+     *
+     * @param message
+     *            The validation failure message.
+     * @param variableReplacements
+     *            Replacements for variables that appear in the message, in 
syntax: "$var text" where $var is the
+     *            variable to be replaced, and the text is the replacement.
+     */
+    public ValidationResult(VdcBllMessages message, String... 
variableReplacements) {
+        this(message);
+        this.variableReplacements = 
Collections.unmodifiableList(Arrays.asList(variableReplacements));
+    }
+
+    /**
      * @return Did the validation succeed or not?
      */
     public boolean isValid() {
@@ -54,6 +77,14 @@
         return message;
     }
 
+    /**
+     * @return <code>null</code> in case there are no replacements, otherwise 
a list of the replacements for message
+     *         variables.
+     */
+    public List<String> getVariableReplacements() {
+        return variableReplacements;
+    }
+
     @Override
     public int hashCode() {
         final int prime = 31;


--
To view, visit http://gerrit.ovirt.org/10267
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2ef15a9454cac7ea179fdbac0003944bc0327dcc
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Mike Kolesnik <mkole...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to