Lior Vernia has uploaded a new change for review. Change subject: webadmin: Warning when editing Network Provider URL ......................................................................
webadmin: Warning when editing Network Provider URL User is warned in case of changing Provider URL when it had already provided networks. Also added infrastructure for easy addition in the future of similar checks for other Provider types. Change-Id: Id71b5f916258f0250c2d5f1c6d77e9c1a9a9516e Signed-off-by: Lior Vernia <lver...@redhat.com> --- M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/EditProviderModel.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/ProviderModel.java M frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/UIConstants.java 3 files changed, 112 insertions(+), 6 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/52/15652/1 diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/EditProviderModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/EditProviderModel.java index 41abbf5..f559438 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/EditProviderModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/EditProviderModel.java @@ -1,16 +1,109 @@ package org.ovirt.engine.ui.uicommonweb.models.providers; +import java.util.Collection; +import java.util.EnumMap; +import java.util.Set; + +import org.ovirt.engine.core.common.VdcObjectType; import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.businessentities.Provider; +import org.ovirt.engine.core.common.businessentities.network.Network; +import org.ovirt.engine.core.common.queries.IdQueryParameters; +import org.ovirt.engine.core.common.queries.VdcQueryReturnValue; +import org.ovirt.engine.core.common.queries.VdcQueryType; +import org.ovirt.engine.core.compat.StringHelper; +import org.ovirt.engine.ui.frontend.AsyncQuery; +import org.ovirt.engine.ui.frontend.Frontend; +import org.ovirt.engine.ui.frontend.INewAsyncCallback; +import org.ovirt.engine.ui.uicommonweb.UICommand; +import org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel; import org.ovirt.engine.ui.uicommonweb.models.SearchableListModel; import org.ovirt.engine.ui.uicompat.ConstantsManager; +@SuppressWarnings("deprecation") public class EditProviderModel extends ProviderModel { + + private static final String CMD_APPROVE = "OnApprove"; //$NON-NLS-1$ + private static final String CMD_CANCEL = "OnCancel"; //$NON-NLS-1$ + + private final String oldUrl; + private Set<VdcObjectType> providedTypes; + private EnumMap<VdcObjectType, Boolean> queriesRun = new EnumMap<VdcObjectType, Boolean>(VdcObjectType.class); + private EnumMap<VdcObjectType, Boolean> queriesReturned = new EnumMap<VdcObjectType, Boolean>(VdcObjectType.class); + private boolean entitiesProvided = true; public EditProviderModel(SearchableListModel sourceListModel, Provider provider) { super(sourceListModel, VdcActionType.UpdateProvider, provider); setTitle(ConstantsManager.getInstance().getConstants().editProviderTitle()); setHashName("edit_provider"); //$NON-NLS-1$ + oldUrl = provider.getUrl(); + } + + @Override + protected void preSave() { + startProgress(null); + if (!StringHelper.stringsEqualIgnoreCase((String) getUrl().getEntity(), oldUrl)) { + providedTypes = provider.getType().getProvidedTypes(); + initQueries(); + + if (providedTypes.contains(VdcObjectType.Network)) { + Frontend.RunQuery(VdcQueryType.GetAllNetworksForProvider, + new IdQueryParameters(provider.getId()), + new AsyncQuery(null, new INewAsyncCallback() { + @SuppressWarnings("unchecked") + @Override + public void onSuccess(Object model, Object returnValue) { + if (!((Collection<Network>) ((VdcQueryReturnValue) returnValue).getReturnValue()).isEmpty()) { + entitiesProvided = false; + } + updateQueries(VdcObjectType.Network); + } + })); + } + } + } + + private void initQueries() { + if (providedTypes.contains(VdcObjectType.Network)) { + queriesRun.put(VdcObjectType.Network, true); + } + } + + private void updateQueries(VdcObjectType type) { + queriesReturned.put(type, true); + if (queriesReturned.equals(queriesRun)) { + stopProgress(); + if (entitiesProvided) { + ConfirmationModel confirmationModel = new ConfirmationModel(); + confirmationModel.setMessage(ConstantsManager.getInstance().getConstants().providerUrlWarningTitle()); + confirmationModel.setMessage(ConstantsManager.getInstance().getConstants().providerUrlWarningText()); + UICommand cmdOk = new UICommand(CMD_APPROVE, this); + cmdOk.setTitle(ConstantsManager.getInstance().getConstants().ok()); + cmdOk.setIsDefault(true); + confirmationModel.getCommands().add(cmdOk); + UICommand cmdCancel = new UICommand(CMD_CANCEL, this); + cmdCancel.setTitle(ConstantsManager.getInstance().getConstants().cancel()); + cmdCancel.setIsCancel(true); + confirmationModel.getCommands().add(cmdCancel); + sourceListModel.setConfirmWindow(confirmationModel); + } + } + } + + private void cancel() { + sourceListModel.setConfirmWindow(null); + } + + @Override + public void executeCommand(UICommand command) { + super.executeCommand(command); + + if (StringHelper.stringsEqual(command.getName(), CMD_APPROVE)) { + cancel(); + actualSave(); + } else if (StringHelper.stringsEqual(command.getName(), CMD_CANCEL)) { + cancel(); + } } } diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/ProviderModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/ProviderModel.java index 596f64d..d7170e0 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/ProviderModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/ProviderModel.java @@ -42,9 +42,9 @@ private static final String CMD_CANCEL_IMPORT = "CancelImport"; //$NON-NLS-1$ private static final String EMPTY_ERROR_MESSAGE = ""; //$NON-NLS-1$ - private final ListModel sourceListModel; + protected final ListModel sourceListModel; private final VdcActionType action; - private final Provider provider; + protected final Provider provider; private EntityModel name = new EntityModel(); private ListModel type = new ListModel(); @@ -181,14 +181,21 @@ } } + protected void preSave() { + actualSave(); + } + + protected void actualSave() { + flush(); + Frontend.RunAction(action, new ProviderParameters(provider)); + cancel(); + } + private void onSave() { if (!validate()) { return; } - - flush(); - Frontend.RunAction(action, new ProviderParameters(provider)); - cancel(); + preSave(); } private void onTest() { 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 f4af714..990f46e 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 @@ -1876,6 +1876,12 @@ @DefaultStringValue("Edit Provider") String editProviderTitle(); + @DefaultStringValue("Change Provider URL") + String providerUrlWarningTitle(); + + @DefaultStringValue("Entities provided by this Provider currently exist in the data center. Changing the URL might hurt their proper functioning.") + String providerUrlWarningText(); + @DefaultStringValue("Remove Provider(s)") String removeProviderTitle(); -- To view, visit http://gerrit.ovirt.org/15652 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id71b5f916258f0250c2d5f1c6d77e9c1a9a9516e Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Lior Vernia <lver...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches