Search in sources :

Example 1 with IFrontendMultipleActionAsyncCallback

use of org.ovirt.engine.ui.uicompat.IFrontendMultipleActionAsyncCallback in project ovirt-engine by oVirt.

the class Frontend method runMultipleAction.

/**
 * Run multiple actions using the same {@code ActionType}.
 * @param actionType The action type.
 * @param parameters The list of parameters.
 * @param isRunOnlyIfAllValidationPass A flag to only run the actions if all can be completed.
 * @param callback The callback to call when the operation completes.
 * @param state The state.
 * @param showErrorDialog Should we show an error dialog?
 * @param waitForResult a flag to return the result after running the whole action and not just the can do actions.
 */
public void runMultipleAction(final ActionType actionType, final List<ActionParametersBase> parameters, final boolean isRunOnlyIfAllValidationPass, final IFrontendMultipleActionAsyncCallback callback, final Object state, final boolean showErrorDialog, final boolean waitForResult) {
    VdcOperationCallbackList<VdcOperation<ActionType, ActionParametersBase>, List<ActionReturnValue>> multiCallback = new VdcOperationCallbackList<VdcOperation<ActionType, ActionParametersBase>, List<ActionReturnValue>>() {

        @Override
        public void onSuccess(final List<VdcOperation<ActionType, ActionParametersBase>> operationList, final List<ActionReturnValue> resultObject) {
            // $NON-NLS-1$
            logger.finer("Frontend: successfully executed runMultipleAction, determining result!");
            List<ActionReturnValue> failed = resultObject.stream().filter(v -> !v.isValid()).collect(Collectors.toList());
            if (showErrorDialog && !failed.isEmpty()) {
                translateErrors(failed);
                getEventsHandler().runMultipleActionFailed(actionType, failed);
            }
            if (callback != null) {
                callback.executed(new FrontendMultipleActionAsyncResult(actionType, parameters, resultObject, state));
            }
            fireAsyncActionSucceededEvent(state);
        }

        @Override
        public void onFailure(final List<VdcOperation<ActionType, ActionParametersBase>> operation, final Throwable caught) {
            if (ignoreFailure(caught)) {
                return;
            }
            // $NON-NLS-1$
            logger.log(Level.SEVERE, "Failed to execute runMultipleAction: " + caught, caught);
            failureEventHandler(caught);
            if (callback != null) {
                callback.executed(new FrontendMultipleActionAsyncResult(actionType, parameters, null, state));
            }
            fireAsyncActionFailedEvent(state);
        }
    };
    List<VdcOperation<?, ?>> operationList = parameters.stream().map(p -> new VdcOperation<>(actionType, p, !waitForResult, multiCallback, isRunOnlyIfAllValidationPass)).collect(Collectors.toList());
    fireAsyncOperationStartedEvent(state);
    if (operationList.isEmpty()) {
        // it ourselves.
        if (scheduler == null) {
            scheduler = Scheduler.get();
        }
        scheduler.scheduleDeferred(() -> {
            if (callback != null) {
                List<ActionReturnValue> emptyResult = new ArrayList<>();
                callback.executed(new FrontendMultipleActionAsyncResult(actionType, parameters, emptyResult, state));
            }
        });
    } else {
        getOperationManager().addOperationList(operationList);
    }
}
Also used : QueryType(org.ovirt.engine.core.common.queries.QueryType) MessageFormatter(org.ovirt.engine.ui.frontend.IFrontendEventsHandler.MessageFormatter) Arrays(java.util.Arrays) FrontendActionAsyncResult(org.ovirt.engine.ui.uicompat.FrontendActionAsyncResult) IFrontendActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback) Inject(com.google.inject.Inject) FrontendMultipleActionAsyncResult(org.ovirt.engine.ui.uicompat.FrontendMultipleActionAsyncResult) VdcOperation(org.ovirt.engine.ui.frontend.communication.VdcOperation) Event(org.ovirt.engine.ui.uicompat.Event) VdcOperationCallback(org.ovirt.engine.ui.frontend.communication.VdcOperationCallback) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) IFrontendMultipleActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendMultipleActionAsyncCallback) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) EngineFault(org.ovirt.engine.core.common.errors.EngineFault) ActionType(org.ovirt.engine.core.common.action.ActionType) Map(java.util.Map) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) GwtEvent(com.google.gwt.event.shared.GwtEvent) HasHandlers(com.google.gwt.event.shared.HasHandlers) UserCallback(org.ovirt.engine.ui.frontend.communication.UserCallback) FrontendMultipleQueryAsyncResult(org.ovirt.engine.ui.uicompat.FrontendMultipleQueryAsyncResult) LinkedList(java.util.LinkedList) EventArgs(org.ovirt.engine.ui.uicompat.EventArgs) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) EventBus(com.google.gwt.event.shared.EventBus) AsyncOperationCompleteEvent(org.ovirt.engine.ui.frontend.communication.AsyncOperationCompleteEvent) Collection(java.util.Collection) AsyncOperationStartedEvent(org.ovirt.engine.ui.frontend.communication.AsyncOperationStartedEvent) VdcOperationManager(org.ovirt.engine.ui.frontend.communication.VdcOperationManager) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) RefreshActiveModelEvent(org.ovirt.engine.ui.frontend.communication.RefreshActiveModelEvent) Scheduler(com.google.gwt.core.client.Scheduler) List(java.util.List) StatusCodeException(com.google.gwt.user.client.rpc.StatusCodeException) VdcOperationCallbackList(org.ovirt.engine.ui.frontend.communication.VdcOperationCallbackList) UIConstants(org.ovirt.engine.ui.uicompat.UIConstants) Collections(java.util.Collections) IFrontendMultipleQueryAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendMultipleQueryAsyncCallback) ActionType(org.ovirt.engine.core.common.action.ActionType) VdcOperation(org.ovirt.engine.ui.frontend.communication.VdcOperation) ArrayList(java.util.ArrayList) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) FrontendMultipleActionAsyncResult(org.ovirt.engine.ui.uicompat.FrontendMultipleActionAsyncResult) VdcOperationCallbackList(org.ovirt.engine.ui.frontend.communication.VdcOperationCallbackList) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) VdcOperationCallbackList(org.ovirt.engine.ui.frontend.communication.VdcOperationCallbackList)

Example 2 with IFrontendMultipleActionAsyncCallback

use of org.ovirt.engine.ui.uicompat.IFrontendMultipleActionAsyncCallback in project ovirt-engine by oVirt.

the class UserListModel method onRemove.

public void onRemove() {
    List<DbUser> selectedItems = getSelectedItems();
    ArrayList<ActionParametersBase> userPrms = new ArrayList<>();
    ArrayList<ActionParametersBase> groupPrms = new ArrayList<>();
    for (DbUser item : selectedItems) {
        if (!item.isGroup()) {
            userPrms.add(new IdParameters(item.getId()));
        } else {
            groupPrms.add(new IdParameters(item.getId()));
        }
    }
    IFrontendMultipleActionAsyncCallback lastCallback = result -> Scheduler.get().scheduleDeferred(() -> {
        // Refresh user list.
        syncSearch();
        cancel();
    });
    if (getUserOrGroup() == UserOrGroup.User) {
        if (userPrms.size() > 0) {
            Frontend.getInstance().runMultipleAction(ActionType.RemoveUser, userPrms, lastCallback);
        }
    } else if (getUserOrGroup() == UserOrGroup.Group) {
        if (groupPrms.size() > 0) {
            Frontend.getInstance().runMultipleAction(ActionType.RemoveGroup, groupPrms, lastCallback);
        }
    }
}
Also used : SearchType(org.ovirt.engine.core.common.interfaces.SearchType) TagModel(org.ovirt.engine.ui.uicommonweb.models.tags.TagModel) QueryType(org.ovirt.engine.core.common.queries.QueryType) AttachEntityToTagParameters(org.ovirt.engine.core.common.action.AttachEntityToTagParameters) AddGroupParameters(org.ovirt.engine.core.common.action.AddGroupParameters) SearchObjects(org.ovirt.engine.core.searchbackend.SearchObjects) Guid(org.ovirt.engine.core.compat.Guid) AdSearchType(org.ovirt.engine.ui.uicommonweb.models.users.AdElementListModel.AdSearchType) IFrontendActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback) Inject(com.google.inject.Inject) HelpTag(org.ovirt.engine.ui.uicommonweb.help.HelpTag) TagListModel(org.ovirt.engine.ui.uicommonweb.models.tags.TagListModel) HashMap(java.util.HashMap) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel) IFrontendMultipleActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendMultipleActionAsyncCallback) ArrayList(java.util.ArrayList) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) ActionType(org.ovirt.engine.core.common.action.ActionType) Frontend(org.ovirt.engine.ui.frontend.Frontend) Map(java.util.Map) Tags(org.ovirt.engine.core.common.businessentities.Tags) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) HasEntity(org.ovirt.engine.ui.uicommonweb.models.HasEntity) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) SearchParameters(org.ovirt.engine.core.common.queries.SearchParameters) ActionUtils(org.ovirt.engine.core.common.ActionUtils) UserOrGroup(org.ovirt.engine.core.searchbackend.VdcUserConditionFieldAutoCompleter.UserOrGroup) SearchStringMapping(org.ovirt.engine.ui.uicommonweb.models.SearchStringMapping) Collection(java.util.Collection) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) DbGroup(org.ovirt.engine.core.common.businessentities.aaa.DbGroup) Scheduler(com.google.gwt.core.client.Scheduler) List(java.util.List) ListWithSimpleDetailsModel(org.ovirt.engine.ui.uicommonweb.models.ListWithSimpleDetailsModel) AddUserParameters(org.ovirt.engine.core.common.action.AddUserParameters) TagAssigningModel(org.ovirt.engine.ui.uicommonweb.TagAssigningModel) WebAdminApplicationPlaces(org.ovirt.engine.ui.uicommonweb.place.WebAdminApplicationPlaces) IdParameters(org.ovirt.engine.core.common.action.IdParameters) IFrontendMultipleActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendMultipleActionAsyncCallback) IdParameters(org.ovirt.engine.core.common.action.IdParameters) ArrayList(java.util.ArrayList) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Example 3 with IFrontendMultipleActionAsyncCallback

use of org.ovirt.engine.ui.uicompat.IFrontendMultipleActionAsyncCallback in project ovirt-engine by oVirt.

the class DataCenterGuideModel method onSelectHost.

public void onSelectHost() {
    MoveHost model = (MoveHost) getWindow();
    if (model.getProgress() != null) {
        return;
    }
    if (!model.validate()) {
        return;
    }
    model.setSelectedHosts(new ArrayList<MoveHostData>());
    for (MoveHostData a : model.getItems()) {
        if (a.getIsSelected()) {
            model.getSelectedHosts().add(a);
        }
    }
    Cluster cluster = model.getCluster().getSelectedItem();
    final List<ActionParametersBase> parameterList = new ArrayList<>();
    for (MoveHostData hostData : model.getSelectedHosts()) {
        VDS host = hostData.getEntity();
        // Try to change host's cluster as neccessary.
        if (host.getClusterId() != null && !host.getClusterId().equals(cluster.getId())) {
            parameterList.add(new ChangeVDSClusterParameters(cluster.getId(), host.getId()));
        }
    }
    model.startProgress();
    Frontend.getInstance().runMultipleAction(ActionType.ChangeVDSCluster, parameterList, new IFrontendMultipleActionAsyncCallback() {

        @Override
        public void executed(FrontendMultipleActionAsyncResult result) {
            final DataCenterGuideModel dataCenterGuideModel = (DataCenterGuideModel) result.getState();
            List<MoveHostData> hosts = ((MoveHost) dataCenterGuideModel.getWindow()).getSelectedHosts();
            List<ActionReturnValue> retVals = result.getReturnValue();
            final List<ActionParametersBase> activateVdsParameterList = new ArrayList<>();
            if (retVals != null && hosts.size() == retVals.size()) {
                int i = 0;
                for (MoveHostData selectedHostData : hosts) {
                    VDS selectedHost = selectedHostData.getEntity();
                    if (selectedHost.getStatus() == VDSStatus.PendingApproval && retVals.get(i) != null && retVals.get(i).getSucceeded()) {
                        Frontend.getInstance().runAction(ActionType.ApproveVds, new ApproveVdsParameters(selectedHost.getId()), null, this);
                    } else if (selectedHostData.getActivateHost()) {
                        activateVdsParameterList.add(new VdsActionParameters(selectedHostData.getEntity().getId()));
                    }
                    i++;
                }
            }
            if (activateVdsParameterList.isEmpty()) {
                dataCenterGuideModel.getWindow().stopProgress();
                dataCenterGuideModel.cancel();
                dataCenterGuideModel.postAction();
            } else {
                final String searchString = getVdsSearchString((MoveHost) dataCenterGuideModel.getWindow());
                Timer timer = new Timer() {

                    public void run() {
                        checkVdsClusterChangeSucceeded(searchString, parameterList, activateVdsParameterList);
                    }
                };
                timer.schedule(2000);
            }
        }
    }, this);
}
Also used : IFrontendMultipleActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendMultipleActionAsyncCallback) MoveHost(org.ovirt.engine.ui.uicommonweb.models.hosts.MoveHost) VDS(org.ovirt.engine.core.common.businessentities.VDS) ArrayList(java.util.ArrayList) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) ApproveVdsParameters(org.ovirt.engine.core.common.action.hostdeploy.ApproveVdsParameters) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) FrontendMultipleActionAsyncResult(org.ovirt.engine.ui.uicompat.FrontendMultipleActionAsyncResult) Timer(com.google.gwt.user.client.Timer) ChangeVDSClusterParameters(org.ovirt.engine.core.common.action.ChangeVDSClusterParameters) VdsActionParameters(org.ovirt.engine.core.common.action.VdsActionParameters) AddVdsActionParameters(org.ovirt.engine.core.common.action.hostdeploy.AddVdsActionParameters) MoveHostData(org.ovirt.engine.ui.uicommonweb.models.hosts.MoveHostData) List(java.util.List) ArrayList(java.util.ArrayList)

Example 4 with IFrontendMultipleActionAsyncCallback

use of org.ovirt.engine.ui.uicompat.IFrontendMultipleActionAsyncCallback in project ovirt-engine by oVirt.

the class UiVdcMultipleActionTest method executeCallbacks.

private void executeCallbacks(boolean success, ActionFlowState flowState, List<IFrontendMultipleActionAsyncCallback> callbacks, boolean waitForResult) {
    Collections.shuffle(callbacks);
    for (IFrontendMultipleActionAsyncCallback callback : callbacks) {
        assertNotAllDone(flowState);
        ActionReturnValue result = new ActionReturnValue();
        result.setValid(waitForResult || success);
        result.setSucceeded(waitForResult && success);
        callback.executed(new FrontendMultipleActionAsyncResult(ACTION_TYPE, null, Collections.singletonList(result)));
    }
}
Also used : IFrontendMultipleActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendMultipleActionAsyncCallback) FrontendMultipleActionAsyncResult(org.ovirt.engine.ui.uicompat.FrontendMultipleActionAsyncResult) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue)

Aggregations

IFrontendMultipleActionAsyncCallback (org.ovirt.engine.ui.uicompat.IFrontendMultipleActionAsyncCallback)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)3 FrontendMultipleActionAsyncResult (org.ovirt.engine.ui.uicompat.FrontendMultipleActionAsyncResult)3 Scheduler (com.google.gwt.core.client.Scheduler)2 Inject (com.google.inject.Inject)2 Collection (java.util.Collection)2 Map (java.util.Map)2 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)2 ActionType (org.ovirt.engine.core.common.action.ActionType)2 DbUser (org.ovirt.engine.core.common.businessentities.aaa.DbUser)2 QueryType (org.ovirt.engine.core.common.queries.QueryType)2 ConstantsManager (org.ovirt.engine.ui.uicompat.ConstantsManager)2 IFrontendActionAsyncCallback (org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback)2 EventBus (com.google.gwt.event.shared.EventBus)1 GwtEvent (com.google.gwt.event.shared.GwtEvent)1 HasHandlers (com.google.gwt.event.shared.HasHandlers)1 Timer (com.google.gwt.user.client.Timer)1 StatusCodeException (com.google.gwt.user.client.rpc.StatusCodeException)1