Search in sources :

Example 1 with VdcOperationCallbackList

use of org.ovirt.engine.ui.frontend.communication.VdcOperationCallbackList 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 VdcOperationCallbackList

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

the class Frontend method runMultipleQueries.

/**
 * Run multiple queries in a single request to the back-end.
 * @param queryTypeList A list of {@code QueryType}s.
 * @param queryParamsList A list of parameters associated with each query.
 * @param callback The callback to call when the query completes.
 * @param state The state object.
 */
public void runMultipleQueries(final List<QueryType> queryTypeList, final List<QueryParametersBase> queryParamsList, final IFrontendMultipleQueryAsyncCallback callback, final Object state) {
    VdcOperationCallbackList<VdcOperation<QueryType, QueryParametersBase>, List<QueryReturnValue>> multiCallback = new VdcOperationCallbackList<VdcOperation<QueryType, QueryParametersBase>, List<QueryReturnValue>>() {

        @Override
        public void onSuccess(final List<VdcOperation<QueryType, QueryParametersBase>> operationList, final List<QueryReturnValue> resultObject) {
            // $NON-NLS-1$
            logger.finer("Succesful returned result from runMultipleQueries!");
            FrontendMultipleQueryAsyncResult f = new FrontendMultipleQueryAsyncResult(queryTypeList, queryParamsList, resultObject);
            callback.executed(f);
            fireAsyncQuerySucceededEvent(state);
        }

        @Override
        public void onFailure(final List<VdcOperation<QueryType, QueryParametersBase>> operationList, final Throwable caught) {
            try {
                if (ignoreFailure(caught)) {
                    return;
                }
                // $NON-NLS-1$
                logger.log(Level.SEVERE, "Failed to execute runMultipleQueries: " + caught, caught);
                FrontendMultipleQueryAsyncResult f = new FrontendMultipleQueryAsyncResult(queryTypeList, queryParamsList, null);
                failureEventHandler(caught);
                callback.executed(f);
            } finally {
                fireAsyncQueryFailedEvent(state);
            }
        }
    };
    List<VdcOperation<?, ?>> operationList = new ArrayList<>();
    for (int i = 0; i < queryTypeList.size(); i++) {
        QueryParametersBase parameters = queryParamsList.get(i);
        // Why do we do this?
        parameters.setRefresh(false);
        initQueryParamsFilter(parameters);
        operationList.add(new VdcOperation<>(queryTypeList.get(i), parameters, true, multiCallback, false));
    }
    fireAsyncOperationStartedEvent(state);
    getOperationManager().addOperationList(operationList);
}
Also used : VdcOperation(org.ovirt.engine.ui.frontend.communication.VdcOperation) ArrayList(java.util.ArrayList) FrontendMultipleQueryAsyncResult(org.ovirt.engine.ui.uicompat.FrontendMultipleQueryAsyncResult) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) VdcOperationCallbackList(org.ovirt.engine.ui.frontend.communication.VdcOperationCallbackList) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) VdcOperationCallbackList(org.ovirt.engine.ui.frontend.communication.VdcOperationCallbackList) QueryType(org.ovirt.engine.core.common.queries.QueryType)

Aggregations

ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 QueryParametersBase (org.ovirt.engine.core.common.queries.QueryParametersBase)2 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)2 QueryType (org.ovirt.engine.core.common.queries.QueryType)2 VdcOperation (org.ovirt.engine.ui.frontend.communication.VdcOperation)2 VdcOperationCallbackList (org.ovirt.engine.ui.frontend.communication.VdcOperationCallbackList)2 FrontendMultipleQueryAsyncResult (org.ovirt.engine.ui.uicompat.FrontendMultipleQueryAsyncResult)2 Scheduler (com.google.gwt.core.client.Scheduler)1 EventBus (com.google.gwt.event.shared.EventBus)1 GwtEvent (com.google.gwt.event.shared.GwtEvent)1 HasHandlers (com.google.gwt.event.shared.HasHandlers)1 StatusCodeException (com.google.gwt.user.client.rpc.StatusCodeException)1 Inject (com.google.inject.Inject)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Level (java.util.logging.Level)1