Search in sources :

Example 6 with AsyncCallback

use of org.ovirt.engine.ui.frontend.AsyncCallback in project ovirt-engine by oVirt.

the class UserPermissionListModel method syncSearch.

@Override
protected void syncSearch() {
    if (getEntity() == null) {
        return;
    }
    IdQueryParameters mlaParams = new IdQueryParameters(getEntity().getId());
    mlaParams.setRefresh(getIsQueryFirstTime());
    Frontend.getInstance().runQuery(QueryType.GetPermissionsOnBehalfByAdElementId, mlaParams, new AsyncQuery<>((AsyncCallback<QueryReturnValue>) returnValue -> {
        ArrayList<Permission> list = returnValue.getReturnValue();
        ArrayList<Permission> newList = new ArrayList<>();
        for (Permission permission : list) {
            if (!permission.getRoleId().equals(ApplicationGuids.quotaConsumer.asGuid())) {
                newList.add(permission);
            }
        }
        setItems(newList);
    }));
    setIsQueryFirstTime(false);
}
Also used : IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) Permission(org.ovirt.engine.core.common.businessentities.Permission) ArrayList(java.util.ArrayList)

Example 7 with AsyncCallback

use of org.ovirt.engine.ui.frontend.AsyncCallback in project ovirt-engine by oVirt.

the class ImportTemplateModel method init.

public void init(final Collection<VmTemplate> externalTemplates, final Guid storageDomainId) {
    Frontend.getInstance().runQuery(QueryType.Search, new SearchParameters(createSearchPattern(externalTemplates), SearchType.VmTemplate), new AsyncQuery<>(new AsyncCallback<QueryReturnValue>() {

        @Override
        public void onSuccess(QueryReturnValue returnValue) {
            UIConstants constants = ConstantsManager.getInstance().getConstants();
            List<VmTemplate> vmtList = returnValue.getReturnValue();
            List<ImportTemplateData> templateDataList = new ArrayList<>();
            for (VmTemplate template : externalTemplates) {
                ImportTemplateData templateData = new ImportTemplateData(template);
                boolean templateExistsInSystem = vmtList.contains(template);
                templateData.setExistsInSystem(templateExistsInSystem);
                if (templateExistsInSystem) {
                    templateData.enforceClone(constants.importTemplateThatExistsInSystemMustClone());
                } else if (!template.isBaseTemplate() && findAnyVmTemplateById(vmtList, template.getBaseTemplateId()) == null) {
                    templateData.enforceClone(constants.importTemplateWithoutBaseMustClone());
                }
                templateDataList.add(templateData);
            }
            setItems(templateDataList);
            withDataCenterLoaded(storageDomainId, r -> doInit());
        }

        private VmTemplate findAnyVmTemplateById(List<VmTemplate> vmtList, Guid templateId) {
            for (VmTemplate vmt : vmtList) {
                if (templateId.equals(vmt.getId())) {
                    return vmt;
                }
            }
            return null;
        }
    }));
}
Also used : AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) SearchParameters(org.ovirt.engine.core.common.queries.SearchParameters) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) ImportTemplateData(org.ovirt.engine.ui.uicommonweb.models.vms.ImportTemplateData) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) ArrayList(java.util.ArrayList) List(java.util.List) UIConstants(org.ovirt.engine.ui.uicompat.UIConstants)

Example 8 with AsyncCallback

use of org.ovirt.engine.ui.frontend.AsyncCallback in project ovirt-engine by oVirt.

the class GlusterClusterSnapshotConfigModel method clusterSelectedItemChanged.

private void clusterSelectedItemChanged() {
    Cluster selectedCluster = getClusters().getSelectedItem();
    if (selectedCluster == null) {
        return;
    }
    AsyncDataProvider.getInstance().getGlusterSnapshotConfig(new AsyncQuery<>(new AsyncCallback<QueryReturnValue>() {

        @Override
        public void onSuccess(QueryReturnValue returnValue) {
            Pair<List<GlusterVolumeSnapshotConfig>, List<GlusterVolumeSnapshotConfig>> configs = returnValue.getReturnValue();
            if (configs != null) {
                List<GlusterVolumeSnapshotConfig> clusterConfigOptions = configs.getFirst();
                Collections.sort(clusterConfigOptions, Comparator.comparing(GlusterVolumeSnapshotConfig::getParamName));
                setModelItems(getClusterConfigOptions(), clusterConfigOptions, existingClusterConfigs);
            } else {
                getClusterConfigOptions().setItems(null);
            }
        }

        private void setModelItems(ListModel<EntityModel<GlusterVolumeSnapshotConfig>> listModel, List<GlusterVolumeSnapshotConfig> cfgs, Map<String, String> fetchedCfgsBackup) {
            List<EntityModel<GlusterVolumeSnapshotConfig>> coll = new ArrayList<>();
            for (GlusterVolumeSnapshotConfig cfg : cfgs) {
                EntityModel<GlusterVolumeSnapshotConfig> cfgModel = new EntityModel<>();
                cfgModel.setEntity(cfg);
                fetchedCfgsBackup.put(cfg.getParamName(), cfg.getParamValue());
                coll.add(cfgModel);
            }
            // set the entity items
            listModel.setItems(coll);
        }
    }), selectedCluster.getId(), null);
}
Also used : GlusterVolumeSnapshotConfig(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotConfig) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) ArrayList(java.util.ArrayList) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with AsyncCallback

use of org.ovirt.engine.ui.frontend.AsyncCallback in project ovirt-engine by oVirt.

the class GlusterVolumeSnapshotListModel method editSnapshotSchedule.

public void editSnapshotSchedule() {
    if (getWindow() != null) {
        return;
    }
    final UIConstants constants = ConstantsManager.getInstance().getConstants();
    final GlusterVolumeSnapshotModel snapshotModel = new GlusterVolumeSnapshotModel(true, true);
    snapshotModel.setHelpTag(HelpTag.edit_volume_snapshot_schedule);
    // $NON-NLS-1$
    snapshotModel.setHashName("edit_volume_snapshot_schedule");
    snapshotModel.setTitle(constants.editVolumeSnapshotScheduleTitle());
    setWindow(snapshotModel);
    snapshotModel.startProgress();
    AsyncDataProvider.getInstance().getVolumeSnapshotSchedule(new AsyncQuery<>(new AsyncCallback<GlusterVolumeSnapshotSchedule>() {

        @Override
        public void onSuccess(final GlusterVolumeSnapshotSchedule schedule) {
            if (schedule == null) {
                snapshotModel.setMessage(ConstantsManager.getInstance().getConstants().unableToFetchVolumeSnapshotSchedule());
                return;
            }
            snapshotModel.getSnapshotName().setEntity(schedule.getSnapshotNamePrefix());
            snapshotModel.getDescription().setEntity(schedule.getSnapshotDescription());
            snapshotModel.getRecurrence().setSelectedItem(schedule.getRecurrence());
            if (schedule.getEndByDate() == null) {
                snapshotModel.getEndByOptions().setSelectedItem(EndDateOptions.NoEndDate);
            } else {
                snapshotModel.getEndByOptions().setSelectedItem(EndDateOptions.HasEndDate);
                snapshotModel.getEndDate().setEntity(schedule.getEndByDate());
            }
            if (schedule.getRecurrence() != GlusterVolumeSnapshotScheduleRecurrence.UNKNOWN) {
                Map<String, String> timeZones = TimeZoneType.GENERAL_TIMEZONE.getTimeZoneList();
                snapshotModel.getTimeZones().setSelectedItem(Linq.firstOrNull(timeZones.entrySet(), item -> item.getKey().startsWith(schedule.getTimeZone())));
            }
            switch(schedule.getRecurrence()) {
                case INTERVAL:
                    snapshotModel.getInterval().setSelectedItem(String.valueOf(schedule.getInterval()));
                    break;
                case HOURLY:
                    break;
                case DAILY:
                    snapshotModel.getExecutionTime().setEntity(getExecutionTimeValue(schedule));
                    break;
                case WEEKLY:
                    List<DayOfWeek> daysList = new ArrayList<>();
                    for (String day : schedule.getDays().split(",")) {
                        // $NON-NLS-1$
                        daysList.add(getDayOfWeek(day));
                    }
                    snapshotModel.getDaysOfTheWeek().setSelectedItem(daysList);
                    snapshotModel.getExecutionTime().setEntity(getExecutionTimeValue(schedule));
                    break;
                case MONTHLY:
                    snapshotModel.getDaysOfMonth().setSelectedItem(schedule.getDays());
                    snapshotModel.getExecutionTime().setEntity(getExecutionTimeValue(schedule));
                    break;
            }
            snapshotModel.getStartAt().setEntity(schedule.getStartDate());
            snapshotModel.stopProgress();
        }

        private DayOfWeek getDayOfWeek(String day) {
            switch(day) {
                case // $NON-NLS-1$
                "Sun":
                    return DayOfWeek.Sunday;
                case // $NON-NLS-1$
                "Mon":
                    return DayOfWeek.Monday;
                case // $NON-NLS-1$
                "Tue":
                    return DayOfWeek.Tuesday;
                case // $NON-NLS-1$
                "Wed":
                    return DayOfWeek.Wednesday;
                case // $NON-NLS-1$
                "Thu":
                    return DayOfWeek.Thursday;
                case // $NON-NLS-1$
                "Fri":
                    return DayOfWeek.Friday;
                case // $NON-NLS-1$
                "Sat":
                    return DayOfWeek.Saturday;
                default:
                    return null;
            }
        }

        private Date getExecutionTimeValue(GlusterVolumeSnapshotSchedule schedule) {
            Date dt = new Date();
            dt.setHours(schedule.getExecutionTime().getHours());
            dt.setMinutes(schedule.getExecutionTime().getMinutes());
            return dt;
        }
    }), getEntity().getId());
    snapshotModel.getClusterName().setEntity(getEntity().getClusterName());
    snapshotModel.getVolumeName().setEntity(getEntity().getName());
    // $NON-NLS-1$
    UICommand okCommand = UICommand.createDefaultOkUiCommand("onEditSnapshotSchedule", this);
    snapshotModel.getCommands().add(okCommand);
    // $NON-NLS-1$
    UICommand cancelCommand = UICommand.createCancelUiCommand("cancel", this);
    snapshotModel.getCommands().add(cancelCommand);
}
Also used : Time(java.sql.Time) TimeZoneType(org.ovirt.engine.core.common.TimeZoneType) Date(java.util.Date) HelpTag(org.ovirt.engine.ui.uicommonweb.help.HelpTag) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) SearchableListModel(org.ovirt.engine.ui.uicommonweb.models.SearchableListModel) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel) ArrayList(java.util.ArrayList) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) DayOfWeek(org.ovirt.engine.core.compat.DayOfWeek) ActionType(org.ovirt.engine.core.common.action.ActionType) Frontend(org.ovirt.engine.ui.frontend.Frontend) GlusterVolumeSnapshotSchedule(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotSchedule) ScheduleGlusterVolumeSnapshotParameters(org.ovirt.engine.core.common.action.gluster.ScheduleGlusterVolumeSnapshotParameters) GlusterSnapshotStatus(org.ovirt.engine.core.common.businessentities.gluster.GlusterSnapshotStatus) Map(java.util.Map) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) GlusterVolumeParameters(org.ovirt.engine.core.common.action.gluster.GlusterVolumeParameters) GlusterVolumeSnapshotEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity) GlusterVolumeSnapshotActionParameters(org.ovirt.engine.core.common.action.gluster.GlusterVolumeSnapshotActionParameters) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) CreateGlusterVolumeSnapshotParameters(org.ovirt.engine.core.common.action.gluster.CreateGlusterVolumeSnapshotParameters) GlusterVolumeSnapshotScheduleRecurrence(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotScheduleRecurrence) Linq(org.ovirt.engine.ui.uicommonweb.Linq) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) GlusterStatus(org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus) List(java.util.List) UIConstants(org.ovirt.engine.ui.uicompat.UIConstants) Comparator(java.util.Comparator) Collections(java.util.Collections) EndDateOptions(org.ovirt.engine.ui.uicommonweb.models.gluster.GlusterVolumeSnapshotModel.EndDateOptions) DayOfWeek(org.ovirt.engine.core.compat.DayOfWeek) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) ArrayList(java.util.ArrayList) Date(java.util.Date) GlusterVolumeSnapshotSchedule(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotSchedule) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) UIConstants(org.ovirt.engine.ui.uicompat.UIConstants)

Example 10 with AsyncCallback

use of org.ovirt.engine.ui.frontend.AsyncCallback in project ovirt-engine by oVirt.

the class SnapshotModel method updateVmConfiguration.

public void updateVmConfiguration(final AsyncCallback<Void> onUpdateAsyncCallback) {
    Snapshot snapshot = getEntity();
    if (snapshot == null) {
        return;
    }
    AsyncDataProvider.getInstance().getVmConfigurationBySnapshot(new AsyncQuery<>(vm -> {
        Snapshot snapshot1 = getEntity();
        if (vm != null && snapshot1 != null) {
            setVm(vm);
            setDisks(vm.getDiskList());
            setNics(vm.getInterfaces());
            setApps(Arrays.asList(snapshot1.getAppList() != null ? snapshot1.getAppList().split(",") : // $NON-NLS-1$
            new String[] {}));
            Collections.sort(getDisks(), new DiskByDiskAliasComparator());
            Collections.sort(getNics(), new LexoNumericNameableComparator<>());
        }
        onUpdateAsyncCallback.onSuccess(null);
    }), snapshot.getId());
}
Also used : NotEmptyValidation(org.ovirt.engine.ui.uicommonweb.validation.NotEmptyValidation) Arrays(java.util.Arrays) Guid(org.ovirt.engine.core.compat.Guid) SpecialAsciiI18NOrNoneValidation(org.ovirt.engine.ui.uicommonweb.validation.SpecialAsciiI18NOrNoneValidation) DiskByDiskAliasComparator(org.ovirt.engine.core.common.businessentities.comparators.DiskByDiskAliasComparator) HelpTag(org.ovirt.engine.ui.uicommonweb.help.HelpTag) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) ArrayList(java.util.ArrayList) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) ActionType(org.ovirt.engine.core.common.action.ActionType) Frontend(org.ovirt.engine.ui.frontend.Frontend) LexoNumericNameableComparator(org.ovirt.engine.core.common.businessentities.comparators.LexoNumericNameableComparator) Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) Version(org.ovirt.engine.core.compat.Version) ICommandTarget(org.ovirt.engine.ui.uicommonweb.ICommandTarget) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) BaseDisk(org.ovirt.engine.core.common.businessentities.storage.BaseDisk) SnapshotStatus(org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotStatus) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) CreateSnapshotForVmParameters(org.ovirt.engine.core.common.action.CreateSnapshotForVmParameters) IValidation(org.ovirt.engine.ui.uicommonweb.validation.IValidation) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) Set(java.util.Set) BusinessEntitiesDefinitions(org.ovirt.engine.core.common.businessentities.BusinessEntitiesDefinitions) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) Collectors(java.util.stream.Collectors) SnapshotType(org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType) List(java.util.List) VM(org.ovirt.engine.core.common.businessentities.VM) LengthValidation(org.ovirt.engine.ui.uicommonweb.validation.LengthValidation) Collections(java.util.Collections) PropertyChangedEventArgs(org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs) Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) LexoNumericNameableComparator(org.ovirt.engine.core.common.businessentities.comparators.LexoNumericNameableComparator) DiskByDiskAliasComparator(org.ovirt.engine.core.common.businessentities.comparators.DiskByDiskAliasComparator)

Aggregations

AsyncCallback (org.ovirt.engine.ui.frontend.AsyncCallback)16 ArrayList (java.util.ArrayList)11 Guid (org.ovirt.engine.core.compat.Guid)8 List (java.util.List)7 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)7 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)6 Frontend (org.ovirt.engine.ui.frontend.Frontend)6 AsyncDataProvider (org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider)6 ConstantsManager (org.ovirt.engine.ui.uicompat.ConstantsManager)5 Collections (java.util.Collections)4 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)4 VM (org.ovirt.engine.core.common.businessentities.VM)4 QueryType (org.ovirt.engine.core.common.queries.QueryType)4 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)4 HelpTag (org.ovirt.engine.ui.uicommonweb.help.HelpTag)4 PropertyChangedEventArgs (org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs)4 UIConstants (org.ovirt.engine.ui.uicompat.UIConstants)4 Arrays (java.util.Arrays)3 Map (java.util.Map)3 Objects (java.util.Objects)3