Arik Hadas has uploaded a new change for review.

Change subject: core: remove duplicated custom properties handling
......................................................................

core: remove duplicated custom properties handling

The logic of extracting the predefined and user properties from VM
custom properties was duplicated in some places. This patch keep only
the one which is located in VmPropertiesUtils and change the other
places to use it.

Change-Id: I4c37a001985da09cbb7e3f78db1e419901d532cf
Signed-off-by: Arik Hadas <aha...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java
2 files changed, 12 insertions(+), 25 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/83/27883/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java
index f818311..167323d 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java
@@ -19,6 +19,7 @@
 import org.ovirt.engine.core.bll.quota.QuotaStorageDependent;
 import org.ovirt.engine.core.bll.quota.QuotaVdsDependent;
 import org.ovirt.engine.core.bll.snapshots.SnapshotsManager;
+import org.ovirt.engine.core.bll.utils.ClusterUtils;
 import org.ovirt.engine.core.bll.utils.PermissionSubject;
 import org.ovirt.engine.core.bll.utils.VmDeviceUtils;
 import org.ovirt.engine.core.bll.validator.StorageDomainValidator;
@@ -71,7 +72,6 @@
 import org.ovirt.engine.core.common.utils.SimpleDependecyInjector;
 import org.ovirt.engine.core.common.utils.customprop.ValidationError;
 import org.ovirt.engine.core.common.utils.customprop.VmPropertiesUtils;
-import 
org.ovirt.engine.core.common.utils.customprop.VmPropertiesUtils.VMCustomProperties;
 import org.ovirt.engine.core.common.validation.group.CreateVm;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
@@ -891,17 +891,9 @@
         vmStatic.setCreatedByUserId(getUserId());
         // Parses the custom properties field that was filled by frontend to
         // predefined and user defined fields
-        if (vmStatic.getCustomProperties() != null) {
-            VMCustomProperties properties =
-                    
VmPropertiesUtils.getInstance().parseProperties(getVdsGroupDAO()
-                            .get(getParameters().getVm().getVdsGroupId())
-                            .getcompatibility_version(),
-                            vmStatic.getCustomProperties());
-            String predefinedProperties = properties.getPredefinedProperties();
-            String userDefinedProperties = 
properties.getUseDefinedProperties();
-            vmStatic.setPredefinedProperties(predefinedProperties);
-            vmStatic.setUserDefinedProperties(userDefinedProperties);
-        }
+        
VmPropertiesUtils.getInstance().separeteCustomPropertiesToUserAndPredefined(
+                ClusterUtils.getCompatibilityVersion(getParameters().getVm()),
+                vmStatic);
 
         updateOriginalTemplate(vmStatic);
 
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java
index a2420f1..9308fe9 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java
@@ -54,10 +54,10 @@
 import org.ovirt.engine.core.common.utils.VmDeviceType;
 import org.ovirt.engine.core.common.utils.customprop.ValidationError;
 import org.ovirt.engine.core.common.utils.customprop.VmPropertiesUtils;
-import 
org.ovirt.engine.core.common.utils.customprop.VmPropertiesUtils.VMCustomProperties;
 import org.ovirt.engine.core.common.validation.group.UpdateVm;
 import org.ovirt.engine.core.compat.DateTime;
 import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.compat.Version;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector;
 import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase;
@@ -81,9 +81,14 @@
         }
 
         if (isVmExist()) {
-            setCustomDefinedProperties(parameters.getVmStaticData());
-            setCustomDefinedProperties(getVm().getStaticData());
+            Version clusterVersion = getVdsGroup().getcompatibility_version();
+            
getVmPropertiesUtils().separeteCustomPropertiesToUserAndPredefined(clusterVersion,
 parameters.getVmStaticData());
+            
getVmPropertiesUtils().separeteCustomPropertiesToUserAndPredefined(clusterVersion,
 getVm().getStaticData());
         }
+    }
+
+    private VmPropertiesUtils getVmPropertiesUtils() {
+        return VmPropertiesUtils.getInstance();
     }
 
     @Override
@@ -609,16 +614,6 @@
         }
 
         return permissionList;
-    }
-
-    private void setCustomDefinedProperties(VmStatic vmStaticDataFromParams) {
-        VMCustomProperties properties =
-                VmPropertiesUtils.getInstance().parseProperties(getVdsGroup()
-                        .getcompatibility_version(),
-                        vmStaticDataFromParams.getCustomProperties());
-
-        
vmStaticDataFromParams.setPredefinedProperties(properties.getPredefinedProperties());
-        
vmStaticDataFromParams.setUserDefinedProperties(properties.getUseDefinedProperties());
     }
 
     @Override


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

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

Reply via email to