Gilad Chaplik has uploaded a new change for review. Change subject: webadmin: DataProvider.java cleanup (5/6) ......................................................................
webadmin: DataProvider.java cleanup (5/6) DataProvider is a class which is mostly obsolete, as it contains synchronous calls to the engine, which are not relevant anymore under the GWT platform/infrastructure. The goal is to eliminate this class all-together. In this patch: Removing sync call for IsVmNameUnique, and replacing it with an async call in AsyncDataProvider Change-Id: If11911f94e02a5c115a4c4407b918580704bd9eb Signed-off-by: Gilad Chaplik <gchap...@redhat.com> Bug-Url: https://bugzilla.redhat.com/881747 --- M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/DataProvider.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java 2 files changed, 32 insertions(+), 30 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/21/9721/1 diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/DataProvider.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/DataProvider.java index 8ac3759..fd182ca 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/DataProvider.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/DataProvider.java @@ -5,7 +5,6 @@ import org.ovirt.engine.core.common.businessentities.DbUser; import org.ovirt.engine.core.common.businessentities.IVdcQueryable; import org.ovirt.engine.core.common.interfaces.SearchType; -import org.ovirt.engine.core.common.queries.IsVmWithSameNameExistParameters; import org.ovirt.engine.core.common.queries.SearchParameters; import org.ovirt.engine.core.common.queries.VdcQueryReturnValue; import org.ovirt.engine.core.common.queries.VdcQueryType; @@ -20,19 +19,6 @@ @SuppressWarnings("unused") public final class DataProvider { - public static boolean IsVmNameUnique(String name) - { - VdcQueryReturnValue returnValue = - Frontend.RunQuery(VdcQueryType.IsVmWithSameNameExist, new IsVmWithSameNameExistParameters(name)); - - if (returnValue != null && returnValue.getSucceeded() && returnValue.getReturnValue() != null) - { - return !(Boolean) returnValue.getReturnValue(); - } - - return true; - } - public static ArrayList<DbUser> GetUserList() { VdcQueryReturnValue returnValue = diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java index 0836841..0d8727d 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java @@ -63,7 +63,6 @@ import org.ovirt.engine.ui.frontend.Frontend; import org.ovirt.engine.ui.frontend.INewAsyncCallback; import org.ovirt.engine.ui.uicommonweb.Cloner; -import org.ovirt.engine.ui.uicommonweb.DataProvider; import org.ovirt.engine.ui.uicommonweb.Linq; import org.ovirt.engine.ui.uicommonweb.TagsEqualityComparer; import org.ovirt.engine.ui.uicommonweb.UICommand; @@ -2124,10 +2123,11 @@ }, model); } - private void OnSave() + private void preSave() { - UnitVmModel model = (UnitVmModel) getWindow(); - VM selectedItem = (VM) getSelectedItem(); + final UnitVmModel model = (UnitVmModel) getWindow(); + final String name = (String) model.getName().getEntity(); + if (model.getIsNew() == false && selectedItem == null) { Cancel(); @@ -2141,18 +2141,34 @@ return; } - String name = (String) model.getName().getEntity(); + AsyncDataProvider.IsVmNameUnique(new AsyncQuery(this, new INewAsyncCallback() { - // Check name unicitate. - if (!DataProvider.IsVmNameUnique(name) && name.compareToIgnoreCase(getcurrentVm().getvm_name()) != 0) - { - model.getName().setIsValid(false); - model.getName() - .getInvalidityReasons() - .add(ConstantsManager.getInstance().getConstants().nameMustBeUniqueInvalidReason()); - model.setIsGeneralTabValid(false); - return; - } + @Override + public void OnSuccess(Object target, Object returnValue) { + if (!(Boolean) returnValue && name.compareToIgnoreCase(getcurrentVm().getvm_name()) != 0) { + model.getName() + .getInvalidityReasons() + .add(ConstantsManager.getInstance().getConstants().nameMustBeUniqueInvalidReason()); + model.getName().setIsValid(false); + model.setIsGeneralTabValid(false); + } else { + model.getName() + .getInvalidityReasons().clear(); + model.getName().setIsValid(true); + model.setIsGeneralTabValid(true); + onSave(); + } + } + }), name); + + } + + private void onSave() + { + UnitVmModel model = (UnitVmModel) getWindow(); + VM selectedItem = (VM) getSelectedItem(); + + String name = (String) model.getName().getEntity(); // Save changes. VmTemplate template = (VmTemplate) model.getTemplate().getSelectedItem(); @@ -2746,7 +2762,7 @@ } else if (StringHelper.stringsEqual(command.getName(), "OnSave")) //$NON-NLS-1$ { - OnSave(); + preSave(); } else if (StringHelper.stringsEqual(command.getName(), "OnRemove")) //$NON-NLS-1$ { -- To view, visit http://gerrit.ovirt.org/9721 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If11911f94e02a5c115a4c4407b918580704bd9eb Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Gilad Chaplik <gchap...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches