Martin Mucha has uploaded a new change for review. Change subject: webadmin: removed ugly if-else chain ......................................................................
webadmin: removed ugly if-else chain most of given 'rules' can be replaced by polymorphism. Remaining ones(VmPool, DbUser and DbGroup) are probably only badly created and should be fixed to remove this chain altogether. Returning Guid.Empty is not apropriate and should be removed as well. Change-Id: Ic716dc67b90c1d575de14c40b504c984bf0467f2 Signed-off-by: Martin Mucha <mmu...@redhat.com> --- M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java 1 file changed, 22 insertions(+), 69 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/19/33619/1 diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java index 85eb070..3a746b7 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java @@ -1,5 +1,6 @@ package org.ovirt.engine.ui.uicommonweb.dataprovider; +import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -27,6 +28,7 @@ import org.ovirt.engine.core.common.action.gluster.GlusterVolumeRemoveBricksQueriesParameters; import org.ovirt.engine.core.common.businessentities.ActionGroup; import org.ovirt.engine.core.common.businessentities.ArchitectureType; +import org.ovirt.engine.core.common.businessentities.BusinessEntity; import org.ovirt.engine.core.common.businessentities.Disk; import org.ovirt.engine.core.common.businessentities.DiskImage; import org.ovirt.engine.core.common.businessentities.DiskInterface; @@ -37,11 +39,9 @@ import org.ovirt.engine.core.common.businessentities.IVdcQueryable; import org.ovirt.engine.core.common.businessentities.ImageFileType; import org.ovirt.engine.core.common.businessentities.LUNs; -import org.ovirt.engine.core.common.businessentities.MacPool; import org.ovirt.engine.core.common.businessentities.Permissions; import org.ovirt.engine.core.common.businessentities.Provider; import org.ovirt.engine.core.common.businessentities.ProviderType; -import org.ovirt.engine.core.common.businessentities.Quota; import org.ovirt.engine.core.common.businessentities.QuotaEnforcementTypeEnum; import org.ovirt.engine.core.common.businessentities.RepoImage; import org.ovirt.engine.core.common.businessentities.Role; @@ -79,10 +79,7 @@ import org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface; import org.ovirt.engine.core.common.businessentities.network.VmInterfaceType; import org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface; -import org.ovirt.engine.core.common.businessentities.network.VnicProfile; import org.ovirt.engine.core.common.businessentities.network.VnicProfileView; -import org.ovirt.engine.core.common.businessentities.profiles.CpuProfile; -import org.ovirt.engine.core.common.businessentities.profiles.DiskProfile; import org.ovirt.engine.core.common.interfaces.SearchType; import org.ovirt.engine.core.common.mode.ApplicationMode; import org.ovirt.engine.core.common.queries.ArchCapabilitiesParameters; @@ -3220,75 +3217,31 @@ return StringHelper.join("+", values.toArray(new String[] {})); //$NON-NLS-1$ } - public Guid getEntityGuid(Object entity) - { - if (entity instanceof VM) - { - return ((VM) entity).getId(); + public <T extends Serializable> T getEntityGuid(BusinessEntity<T> entity) { + return entity.getId(); + } + + public Guid getEntityGuid(Object entity) { + + if (entity instanceof BusinessEntity) { + //BusinessEntity can have lot of different ID types, but from this context it cannot be determined. + Object id = getEntityGuid((BusinessEntity<?>) entity); + + //check whether result can be casted to Guid, otherwise continue with explicit rules. + if (id instanceof Guid) { + return (Guid) id; + } } - else if (entity instanceof StoragePool) - { - return ((StoragePool) entity).getId(); - } - else if (entity instanceof VDSGroup) - { - return ((VDSGroup) entity).getId(); - } - else if (entity instanceof VDS) - { - return ((VDS) entity).getId(); - } - else if (entity instanceof StorageDomain) - { - return ((StorageDomain) entity).getId(); - } - else if (entity instanceof VmTemplate) - { - return ((VmTemplate) entity).getId(); - } - else if (entity instanceof VmPool) - { + + if (entity instanceof VmPool) { return ((VmPool) entity).getVmPoolId(); - } - else if (entity instanceof DbUser) - { + } else if (entity instanceof DbUser) { return ((DbUser) entity).getId(); - } - else if (entity instanceof DbGroup) - { + } else if (entity instanceof DbGroup) { return ((DbGroup) entity).getId(); + } else { + return Guid.Empty; } - else if (entity instanceof Quota) - { - return ((Quota) entity).getId(); - } - else if (entity instanceof DiskImage) - { - return ((DiskImage) entity).getId(); - } - else if (entity instanceof GlusterVolumeEntity) - { - return ((GlusterVolumeEntity) entity).getId(); - } - else if (entity instanceof Network) - { - return ((Network) entity).getId(); - } - else if (entity instanceof VnicProfile) - { - return ((VnicProfile) entity).getId(); - } - else if (entity instanceof DiskProfile) - { - return ((DiskProfile) entity).getId(); - } - else if (entity instanceof CpuProfile) - { - return ((CpuProfile) entity).getId(); - } else if (entity instanceof MacPool) { - return ((MacPool) entity).getId(); - } - return Guid.Empty; } public boolean isWindowsOsType(Integer osType) { -- To view, visit http://gerrit.ovirt.org/33619 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic716dc67b90c1d575de14c40b504c984bf0467f2 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Martin Mucha <mmu...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches