Search in sources :

Example 61 with RequestCallback

use of com.google.gwt.http.client.RequestCallback in project pentaho-platform by pentaho.

the class SchedulesPanel method refresh.

public void refresh() {
    String moduleBaseURL = GWT.getModuleBaseURL();
    String moduleName = GWT.getModuleName();
    String contextURL = moduleBaseURL.substring(0, moduleBaseURL.lastIndexOf(moduleName));
    final String apiEndpoint = "api/scheduler/getJobs";
    RequestBuilder executableTypesRequestBuilder = createRequestBuilder(RequestBuilder.GET, apiEndpoint, contextURL);
    executableTypesRequestBuilder.setHeader(HTTP_ACCEPT_HEADER, JSON_CONTENT_TYPE);
    try {
        executableTypesRequestBuilder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
            // showError(exception);
            }

            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == Response.SC_OK) {
                    allJobs = parseJson(JsonUtils.escapeJsonForEval(response.getText()));
                    filterAndShowData();
                }
            }
        });
    } catch (RequestException e) {
    // showError(e);
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) CsrfRequestBuilder(org.pentaho.mantle.client.csrf.CsrfRequestBuilder) EmptyRequestCallback(org.pentaho.mantle.client.EmptyRequestCallback) RequestCallback(com.google.gwt.http.client.RequestCallback) Request(com.google.gwt.http.client.Request) JSONString(com.google.gwt.json.client.JSONString) RequestException(com.google.gwt.http.client.RequestException)

Example 62 with RequestCallback

use of com.google.gwt.http.client.RequestCallback in project pentaho-platform by pentaho.

the class SchedulesPanel method createUI.

private void createUI(boolean isAdmin, final boolean isScheduler) {
    table.getElement().setId("schedule-table");
    table.setStylePrimaryName("pentaho-table");
    table.setWidth("100%", true);
    // BISERVER-9331 Column sort indicators should be to the right of header text in the Manage Schedules table.
    if (table.getHeaderBuilder() instanceof AbstractHeaderOrFooterBuilder) {
        ((AbstractHeaderOrFooterBuilder<JsJob>) table.getHeaderBuilder()).setSortIconStartOfLine(false);
    }
    final MultiSelectionModel<JsJob> selectionModel = new MultiSelectionModel<JsJob>(new ProvidesKey<JsJob>() {

        public Object getKey(JsJob item) {
            return item.getJobId();
        }
    });
    table.setSelectionModel(selectionModel);
    Label noDataLabel = new Label(Messages.getString("noSchedules"));
    noDataLabel.setStyleName("noDataForScheduleTable");
    table.setEmptyTableWidget(noDataLabel);
    TextColumn<JsJob> idColumn = new TextColumn<JsJob>() {

        public String getValue(JsJob job) {
            return job.getJobId();
        }
    };
    idColumn.setSortable(true);
    TextColumn<JsJob> nameColumn = new TextColumn<JsJob>() {

        public String getValue(JsJob job) {
            return job.getJobName();
        }
    };
    nameColumn.setSortable(true);
    HtmlColumn<JsJob> resourceColumn = new HtmlColumn<JsJob>() {

        @Override
        public String getStringValue(JsJob job) {
            String name = job.getFullResourceName().split("\\.")[0];
            return name.replaceAll("/", "/<wbr/>");
        }
    };
    resourceColumn.setSortable(true);
    HtmlColumn<JsJob> outputPathColumn = new HtmlColumn<JsJob>(new ClickableSafeHtmlCell()) {

        @Override
        public String getStringValue(JsJob jsJob) {
            try {
                String outputPath = jsJob.getOutputPath();
                if (StringUtils.isEmpty(outputPath)) {
                    return BLANK_VALUE;
                }
                outputPath = new SafeHtmlBuilder().appendEscaped(outputPath).toSafeHtml().asString();
                return MessageFormat.format("<span class='workspace-resource-link' title='{0}'>{0}</span>", outputPath);
            } catch (Throwable t) {
                return BLANK_VALUE;
            }
        }
    };
    outputPathColumn.setFieldUpdater(new FieldUpdater<JsJob, SafeHtml>() {

        @Override
        public void update(final int index, final JsJob jsJob, final SafeHtml value) {
            if (value != null && !BLANK_VALUE.equals(value.asString())) {
                final Command errorCallback = new Command() {

                    @Override
                    public void execute() {
                        showValidateOutputLocationError();
                    }
                };
                final Command successCallback = new Command() {

                    @Override
                    public void execute() {
                        openOutputLocation(jsJob.getOutputPath());
                    }
                };
                OutputLocationUtils.validateOutputLocation(jsJob.getOutputPath(), successCallback, errorCallback);
            }
        }
    });
    outputPathColumn.setSortable(true);
    TextColumn<JsJob> scheduleColumn = new TextColumn<JsJob>() {

        public String getValue(JsJob job) {
            try {
                return job.getJobTrigger().getDescription();
            } catch (Throwable t) {
                return BLANK_VALUE;
            }
        }
    };
    scheduleColumn.setSortable(true);
    TextColumn<JsJob> userNameColumn = new TextColumn<JsJob>() {

        public String getValue(JsJob job) {
            try {
                return job.getUserName();
            } catch (Throwable t) {
                return BLANK_VALUE;
            }
        }
    };
    userNameColumn.setSortable(true);
    TextColumn<JsJob> stateColumn = new TextColumn<JsJob>() {

        public String getValue(JsJob job) {
            try {
                // BISERVER-9965
                final String jobState = "COMPLETE".equalsIgnoreCase(job.getState()) ? "FINISHED" : job.getState();
                // not css text-transform because tooltip will use pure text from the cell
                return jobState.substring(0, 1).toUpperCase() + jobState.substring(1).toLowerCase();
            } catch (Throwable t) {
                return BLANK_VALUE;
            }
        }
    };
    stateColumn.setSortable(true);
    TextColumn<JsJob> nextFireColumn = new TextColumn<JsJob>() {

        public String getValue(JsJob job) {
            try {
                Date date = job.getNextRun();
                if (date == null) {
                    return BLANK_VALUE;
                }
                DateTimeFormat format = DateTimeFormat.getFormat(PredefinedFormat.DATE_TIME_MEDIUM);
                return format.format(date);
            } catch (Throwable t) {
                return BLANK_VALUE;
            }
        }
    };
    nextFireColumn.setSortable(true);
    TextColumn<JsJob> lastFireColumn = new TextColumn<JsJob>() {

        public String getValue(JsJob job) {
            try {
                Date date = job.getLastRun();
                if (date == null) {
                    return BLANK_VALUE;
                }
                DateTimeFormat format = DateTimeFormat.getFormat(PredefinedFormat.DATE_TIME_MEDIUM);
                return format.format(date);
            } catch (Throwable t) {
                return BLANK_VALUE;
            }
        }
    };
    lastFireColumn.setSortable(true);
    // table.addColumn(idColumn, "ID");
    table.addColumn(nameColumn, Messages.getString("scheduleName"));
    table.addColumn(scheduleColumn, Messages.getString("recurrence"));
    table.addColumn(resourceColumn, Messages.getString("sourceFile"));
    table.addColumn(outputPathColumn, Messages.getString("outputPath"));
    table.addColumn(lastFireColumn, Messages.getString("lastFire"));
    table.addColumn(nextFireColumn, Messages.getString("nextFire"));
    if (isAdmin) {
        table.addColumn(userNameColumn, Messages.getString("user"));
    }
    table.addColumn(stateColumn, Messages.getString("state"));
    table.addColumnStyleName(0, "backgroundContentHeaderTableCell");
    table.addColumnStyleName(1, "backgroundContentHeaderTableCell");
    table.addColumnStyleName(2, "backgroundContentHeaderTableCell");
    table.addColumnStyleName(3, "backgroundContentHeaderTableCell");
    table.addColumnStyleName(4, "backgroundContentHeaderTableCell");
    table.addColumnStyleName(5, "backgroundContentHeaderTableCell");
    if (isAdmin) {
        table.addColumnStyleName(6, "backgroundContentHeaderTableCell");
    }
    table.addColumnStyleName(isAdmin ? 7 : 6, "backgroundContentHeaderTableCell");
    table.setColumnWidth(nameColumn, 160, Unit.PX);
    table.setColumnWidth(resourceColumn, 200, Unit.PX);
    table.setColumnWidth(outputPathColumn, 180, Unit.PX);
    table.setColumnWidth(scheduleColumn, 170, Unit.PX);
    table.setColumnWidth(lastFireColumn, 120, Unit.PX);
    table.setColumnWidth(nextFireColumn, 120, Unit.PX);
    if (isAdmin) {
        table.setColumnWidth(userNameColumn, 100, Unit.PX);
    }
    table.setColumnWidth(stateColumn, 90, Unit.PX);
    dataProvider.addDataDisplay(table);
    List<JsJob> list = dataProvider.getList();
    ListHandler<JsJob> columnSortHandler = new ListHandler<JsJob>(list);
    columnSortHandler.setComparator(idColumn, new Comparator<JsJob>() {

        public int compare(JsJob o1, JsJob o2) {
            if (o1 == o2) {
                return 0;
            }
            if (o1 != null) {
                return (o2 != null) ? o1.getJobId().compareTo(o2.getJobId()) : 1;
            }
            return -1;
        }
    });
    columnSortHandler.setComparator(nameColumn, new Comparator<JsJob>() {

        public int compare(JsJob o1, JsJob o2) {
            if (o1 == o2) {
                return 0;
            }
            if (o1 != null) {
                return (o2 != null) ? o1.getJobName().compareTo(o2.getJobName()) : 1;
            }
            return -1;
        }
    });
    columnSortHandler.setComparator(resourceColumn, new Comparator<JsJob>() {

        public int compare(JsJob o1, JsJob o2) {
            if (o1 == o2) {
                return 0;
            }
            if (o1 != null) {
                String r1 = o1.getShortResourceName();
                String r2 = null;
                if (o2 != null) {
                    r2 = o2.getShortResourceName();
                }
                return (o2 != null) ? r1.compareTo(r2) : 1;
            }
            return -1;
        }
    });
    columnSortHandler.setComparator(outputPathColumn, new Comparator<JsJob>() {

        public int compare(JsJob o1, JsJob o2) {
            if (o1 == o2) {
                return 0;
            }
            if (o1 != null) {
                String r1 = o1.getOutputPath();
                String r2 = null;
                if (o2 != null) {
                    r2 = o2.getOutputPath();
                }
                return (o2 != null) ? r1.compareTo(r2) : 1;
            }
            return -1;
        }
    });
    columnSortHandler.setComparator(scheduleColumn, new Comparator<JsJob>() {

        public int compare(JsJob o1, JsJob o2) {
            String s1 = o1.getJobTrigger().getDescription();
            String s2 = o2.getJobTrigger().getDescription();
            return s1.compareTo(s2);
        }
    });
    columnSortHandler.setComparator(userNameColumn, new Comparator<JsJob>() {

        public int compare(JsJob o1, JsJob o2) {
            if (o1 == o2) {
                return 0;
            }
            if (o1 != null) {
                return (o2 != null) ? o1.getUserName().compareTo(o2.getUserName()) : 1;
            }
            return -1;
        }
    });
    columnSortHandler.setComparator(stateColumn, new Comparator<JsJob>() {

        public int compare(JsJob o1, JsJob o2) {
            if (o1 == o2) {
                return 0;
            }
            if (o1 != null) {
                return (o2 != null) ? o1.getState().compareTo(o2.getState()) : 1;
            }
            return -1;
        }
    });
    columnSortHandler.setComparator(nextFireColumn, new Comparator<JsJob>() {

        public int compare(JsJob o1, JsJob o2) {
            if (o1 == o2) {
                return 0;
            }
            if (o1 == null || o1.getNextRun() == null) {
                return -1;
            }
            if (o2 == null || o2.getNextRun() == null) {
                return 1;
            }
            if (o1.getNextRun() == o2.getNextRun()) {
                return 0;
            }
            return o1.getNextRun().compareTo(o2.getNextRun());
        }
    });
    columnSortHandler.setComparator(lastFireColumn, new Comparator<JsJob>() {

        public int compare(JsJob o1, JsJob o2) {
            if (o1 == o2) {
                return 0;
            }
            if (o1 == null || o1.getLastRun() == null) {
                return -1;
            }
            if (o2 == null || o2.getLastRun() == null) {
                return 1;
            }
            if (o1.getLastRun() == o2.getLastRun()) {
                return 0;
            }
            return o1.getLastRun().compareTo(o2.getLastRun());
        }
    });
    table.addColumnSortHandler(columnSortHandler);
    table.getColumnSortList().push(idColumn);
    table.getColumnSortList().push(resourceColumn);
    table.getColumnSortList().push(outputPathColumn);
    table.getColumnSortList().push(nameColumn);
    table.getSelectionModel().addSelectionChangeHandler(new Handler() {

        public void onSelectionChange(SelectionChangeEvent event) {
            Set<JsJob> selectedJobs = getSelectedJobs();
            if (!selectedJobs.isEmpty()) {
                final JsJob job = selectedJobs.toArray(new JsJob[0])[0];
                updateJobScheduleButtonStyle(job.getState());
                controlScheduleButton.setEnabled(isScheduler);
                editButton.setEnabled(isScheduler);
                controlScheduleButton.setEnabled(isScheduler);
                scheduleRemoveButton.setEnabled(isScheduler);
                triggerNowButton.setEnabled(isScheduler);
            } else {
                editButton.setEnabled(false);
                controlScheduleButton.setEnabled(false);
                scheduleRemoveButton.setEnabled(false);
                triggerNowButton.setEnabled(false);
            }
        }
    });
    // BISERVER-9965
    table.addCellPreviewHandler(new CellPreviewEvent.Handler<JsJob>() {

        @Override
        public void onCellPreview(CellPreviewEvent<JsJob> event) {
            if ("mouseover".equals(event.getNativeEvent().getType())) {
                final TableCellElement cell = table.getRowElement(event.getIndex()).getCells().getItem(event.getColumn());
                cell.setTitle(cell.getInnerText());
            }
        }
    });
    SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class);
    pager = new SimplePager(TextLocation.CENTER, pagerResources, false, 0, true) {

        @Override
        public void setPageStart(int index) {
            if (getDisplay() != null) {
                Range range = getDisplay().getVisibleRange();
                int pageSize = range.getLength();
                index = Math.max(0, index);
                if (index != range.getStart()) {
                    getDisplay().setVisibleRange(index, pageSize);
                }
            }
        }
    };
    pager.setDisplay(table);
    VerticalPanel tableAndPager = new VerticalPanel();
    tableAndPager.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    Toolbar bar = new Toolbar();
    bar.addSpacer(10);
    bar.add(Toolbar.GLUE);
    // Add control scheduler button
    if (isAdmin) {
        final ToolbarButton controlSchedulerButton = new ToolbarButton(ImageUtil.getThemeableImage(ICON_SMALL_STYLE, "icon-start-scheduler"));
        controlSchedulerButton.setCommand(new Command() {

            public void execute() {
                toggleSchedulerOnOff(controlSchedulerButton, isScheduler);
            }
        });
        updateControlSchedulerButtonState(controlSchedulerButton, isScheduler);
        bar.add(controlSchedulerButton);
        bar.addSpacer(20);
    }
    // Add filter button
    filterButton.setCommand(new Command() {

        public void execute() {
            if (filterDialog == null) {
                filterDialog = new FilterDialog(allJobs, filterDialogCallback);
            } else {
                filterDialog.initUI(allJobs);
            }
            filterDialog.center();
        }
    });
    filterButton.setToolTip(Messages.getString("filterSchedules"));
    if (isAdmin) {
        bar.add(filterButton);
    }
    // Add remove filters button
    filterRemoveButton.setCommand(new Command() {

        public void execute() {
            filterDialog = null;
            filters.clear();
            filterAndShowData();
            filterRemoveButton.setEnabled(false);
            filterButton.setImage(ImageUtil.getThemeableImage(ICON_SMALL_STYLE, "icon-filter-add"));
        }
    });
    filterRemoveButton.setToolTip(Messages.getString("removeFilters"));
    filterRemoveButton.setEnabled(!filters.isEmpty());
    if (isAdmin) {
        bar.add(filterRemoveButton);
    }
    // Add refresh button
    ToolbarButton refresh = new ToolbarButton(ImageUtil.getThemeableImage(ICON_SMALL_STYLE, "icon-refresh"));
    refresh.setToolTip(Messages.getString("refreshTooltip"));
    refresh.setCommand(new Command() {

        public void execute() {
            RefreshSchedulesCommand cmd = new RefreshSchedulesCommand();
            cmd.execute();
        }
    });
    bar.add(refresh);
    bar.addSpacer(20);
    // Add execute now button
    triggerNowButton.setToolTip(Messages.getString("executeNow"));
    triggerNowButton.setCommand(new Command() {

        public void execute() {
            Set<JsJob> selectedJobs = getSelectedJobs();
            if (!selectedJobs.isEmpty()) {
                triggerExecuteNow(selectedJobs);
            }
        }
    });
    triggerNowButton.setEnabled(false);
    bar.add(triggerNowButton);
    // Add control schedule button
    controlScheduleButton.setCommand(new Command() {

        public void execute() {
            Set<JsJob> selectedJobs = getSelectedJobs();
            if (!selectedJobs.isEmpty()) {
                final JsJob job = selectedJobs.toArray(new JsJob[0])[0];
                boolean isRunning = JOB_STATE_NORMAL.equalsIgnoreCase(job.getState());
                final String action = isRunning ? "pauseJob" : "resumeJob";
                controlJobs(selectedJobs, action, RequestBuilder.POST, false);
            }
        }
    });
    controlScheduleButton.setEnabled(false);
    bar.add(controlScheduleButton);
    bar.addSpacer(20);
    // Add edit button
    editButton.setCommand(new Command() {

        public void execute() {
            Set<JsJob> selectedJobs = getSelectedJobs();
            if (!selectedJobs.isEmpty()) {
                final JsJob editJob = selectedJobs.toArray(new JsJob[0])[0];
                canAccessJobRequest(editJob, new RequestCallback() {

                    public void onError(Request request, Throwable exception) {
                        promptForScheduleResourceError(Collections.singleton(editJob));
                    }

                    public void onResponseReceived(Request request, Response response) {
                        boolean canEditJob = "true".equalsIgnoreCase(response.getText());
                        if (!canEditJob) {
                            promptForScheduleResourceError(Collections.singleton(editJob));
                            return;
                        }
                        editJob(editJob);
                    }
                });
            }
        }
    });
    editButton.setEnabled(false);
    editButton.setToolTip(Messages.getString("editTooltip"));
    bar.add(editButton);
    // Add remove button
    scheduleRemoveButton.setCommand(new Command() {

        public void execute() {
            final Set<JsJob> selectedJobs = getSelectedJobs();
            int selectionSize = selectedJobs.size();
            if (selectionSize > 0) {
                final PromptDialogBox prompt = new PromptDialogBox(Messages.getString("warning"), Messages.getString("yes"), Messages.getString("no"), false, true);
                final String promptContent = Messages.getString("deleteConfirmSchedles", "" + selectionSize);
                prompt.setContent(new Label(promptContent));
                prompt.setCallback(new IDialogCallback() {

                    public void okPressed() {
                        controlJobs(selectedJobs, "removeJob", RequestBuilder.DELETE, true);
                        prompt.hide();
                    }

                    public void cancelPressed() {
                        prompt.hide();
                    }
                });
                prompt.center();
            }
        }
    });
    scheduleRemoveButton.setToolTip(Messages.getString("remove"));
    scheduleRemoveButton.setEnabled(false);
    bar.add(scheduleRemoveButton);
    tableAndPager.add(bar);
    tableAndPager.add(table);
    tableAndPager.add(pager);
    // Add it to the root panel.
    setWidget(tableAndPager);
}
Also used : RefreshSchedulesCommand(org.pentaho.mantle.client.commands.RefreshSchedulesCommand) Set(java.util.Set) HashSet(java.util.HashSet) PromptDialogBox(org.pentaho.gwt.widgets.client.dialogs.PromptDialogBox) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) MultiSelectionModel(com.google.gwt.view.client.MultiSelectionModel) Label(com.google.gwt.user.client.ui.Label) JSONString(com.google.gwt.json.client.JSONString) HtmlColumn(org.pentaho.mantle.client.ui.column.HtmlColumn) ToolbarButton(org.pentaho.gwt.widgets.client.toolbar.ToolbarButton) AbstractHeaderOrFooterBuilder(com.google.gwt.user.cellview.client.AbstractHeaderOrFooterBuilder) TextColumn(com.google.gwt.user.cellview.client.TextColumn) Toolbar(org.pentaho.gwt.widgets.client.toolbar.Toolbar) ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) Request(com.google.gwt.http.client.Request) ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) Handler(com.google.gwt.view.client.SelectionChangeEvent.Handler) SimplePager(com.google.gwt.user.cellview.client.SimplePager) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) Range(com.google.gwt.view.client.Range) IDialogCallback(org.pentaho.gwt.widgets.client.dialogs.IDialogCallback) Date(java.util.Date) CellPreviewEvent(com.google.gwt.view.client.CellPreviewEvent) SelectionChangeEvent(com.google.gwt.view.client.SelectionChangeEvent) Response(com.google.gwt.http.client.Response) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) EmptyRequestCallback(org.pentaho.mantle.client.EmptyRequestCallback) RequestCallback(com.google.gwt.http.client.RequestCallback) Command(com.google.gwt.user.client.Command) RefreshSchedulesCommand(org.pentaho.mantle.client.commands.RefreshSchedulesCommand) JSONObject(com.google.gwt.json.client.JSONObject) TableCellElement(com.google.gwt.dom.client.TableCellElement) DateTimeFormat(com.google.gwt.i18n.client.DateTimeFormat)

Example 63 with RequestCallback

use of com.google.gwt.http.client.RequestCallback in project pentaho-platform by pentaho.

the class SchedulesPanel method editJob.

private void editJob(final JsJob editJob) {
    final String jobId = editJob.getJobId();
    final String apiEndpoint = "api/scheduler/jobinfo?jobId=" + URL.encodeQueryString(jobId);
    RequestBuilder executableTypesRequestBuilder = createRequestBuilder(RequestBuilder.GET, apiEndpoint);
    executableTypesRequestBuilder.setHeader(HTTP_ACCEPT_HEADER, JSON_CONTENT_TYPE);
    try {
        executableTypesRequestBuilder.sendRequest(null, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
            // showError(exception);
            }

            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == Response.SC_OK) {
                    final JsJob jsJob = parseJsonJob(JsonUtils.escapeJsonForEval(response.getText()));
                    // check email is setup
                    final String checkEmailEndpoint = "api/emailconfig/isValid";
                    RequestBuilder emailValidRequest = createRequestBuilder(RequestBuilder.GET, checkEmailEndpoint);
                    emailValidRequest.setHeader("accept", "text/plain");
                    try {
                        emailValidRequest.sendRequest(null, new RequestCallback() {

                            public void onError(Request request, Throwable exception) {
                                MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), exception.toString(), false, false, true);
                                dialogBox.center();
                            }

                            public void onResponseReceived(Request request, Response response) {
                                if (response.getStatusCode() == Response.SC_OK) {
                                    final boolean isEmailConfValid = Boolean.parseBoolean(response.getText());
                                    final NewScheduleDialog scheduleDialog = new NewScheduleDialog(jsJob, scheduleDialogCallback, isEmailConfValid);
                                    scheduleDialog.center();
                                }
                            }
                        });
                    } catch (RequestException e) {
                    // showError(e);
                    }
                } else {
                    String message = Messages.getString("serverErrorColon") + " " + response.getStatusCode();
                    MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), message, false, false, true);
                    dialogBox.center();
                }
            }
        });
    } catch (RequestException e) {
    // showError(e);
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) CsrfRequestBuilder(org.pentaho.mantle.client.csrf.CsrfRequestBuilder) EmptyRequestCallback(org.pentaho.mantle.client.EmptyRequestCallback) RequestCallback(com.google.gwt.http.client.RequestCallback) MessageDialogBox(org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox) Request(com.google.gwt.http.client.Request) JSONString(com.google.gwt.json.client.JSONString) RequestException(com.google.gwt.http.client.RequestException) NewScheduleDialog(org.pentaho.mantle.client.dialogs.scheduling.NewScheduleDialog)

Example 64 with RequestCallback

use of com.google.gwt.http.client.RequestCallback in project pentaho-platform by pentaho.

the class SchedulesPanel method triggerExecuteNow.

private void triggerExecuteNow(final Set<JsJob> jobs) {
    final Map<String, List<JsJob>> candidateJobs = new HashMap<String, List<JsJob>>(jobs.size());
    for (JsJob job : jobs) {
        List<JsJob> jobList = candidateJobs.get(job.getFullResourceName());
        if (null == jobList) {
            jobList = new ArrayList<JsJob>();
            candidateJobs.put(job.getFullResourceName(), jobList);
        }
        jobList.add(job);
    }
    canAccessJobListRequest(jobs, new RequestCallback() {

        public void onError(Request request, Throwable exception) {
            promptForScheduleResourceError(jobs);
        }

        public void onResponseReceived(Request request, Response response) {
            final Set<JsJob> executeList = getExecutableJobs(candidateJobs, response);
            // execute job schedules that can be executed
            if (!executeList.isEmpty()) {
                executeJobs(executeList);
            }
            final Set<JsJob> removeList = new HashSet<JsJob>();
            for (JsJob job : jobs) {
                if (!executeList.contains(job)) {
                    removeList.add(job);
                }
            }
            // remove job schedules that no longer can be executed
            if (!removeList.isEmpty()) {
                promptForScheduleResourceError(removeList);
            }
        }
    });
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Request(com.google.gwt.http.client.Request) JSONString(com.google.gwt.json.client.JSONString) Response(com.google.gwt.http.client.Response) EmptyRequestCallback(org.pentaho.mantle.client.EmptyRequestCallback) RequestCallback(com.google.gwt.http.client.RequestCallback) List(java.util.List) ArrayList(java.util.ArrayList)

Example 65 with RequestCallback

use of com.google.gwt.http.client.RequestCallback in project pentaho-platform by pentaho.

the class MantleController method updatePassword.

public void updatePassword(String user, String newPassword, String oldPassword, final ServiceCallback callback) {
    String userName = user;
    String serviceUrl = GWT.getHostPageBaseURL() + "api/userroledao/user";
    RequestBuilder executableTypesRequestBuilder = new RequestBuilder(RequestBuilder.PUT, serviceUrl);
    try {
        executableTypesRequestBuilder.setHeader(HTTP_REQUEST_ACCEPT_HEADER, JSON_REQUEST_HEADER);
        executableTypesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
        executableTypesRequestBuilder.setHeader("Content-Type", JSON_REQUEST_HEADER);
        String json = "{\"userName\": \"" + encodeUri(userName) + "\", \"newPassword\": \"ENC:" + b64encode(newPassword) + "\", \"oldPassword\": \"ENC:" + b64encode(oldPassword) + "\"}";
        executableTypesRequestBuilder.sendRequest(json, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
                handleCallbackError(callback, false, "");
            }

            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() != Response.SC_NO_CONTENT) {
                    handleCallbackError(callback, false, response.getHeader(PUC_VALIDATION_ERROR_MESSAGE));
                } else {
                    callback.serviceResult(true);
                }
            }
        });
    } catch (RequestException e) {
        showXulErrorMessage(Messages.getString(CHANGE_PASS_ERROR_TITLE), Messages.getString(CHANGE_PASS_ERROR_MESSAGE));
        callback.serviceResult(false);
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) Request(com.google.gwt.http.client.Request) RequestException(com.google.gwt.http.client.RequestException)

Aggregations

RequestCallback (com.google.gwt.http.client.RequestCallback)175 Response (com.google.gwt.http.client.Response)170 Request (com.google.gwt.http.client.Request)169 RequestException (com.google.gwt.http.client.RequestException)162 RequestBuilder (com.google.gwt.http.client.RequestBuilder)113 JSONException (com.google.gwt.json.client.JSONException)55 HttpException (com.willshex.gson.web.service.client.HttpException)55 MessageDialogBox (org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox)16 CsrfRequestBuilder (org.pentaho.mantle.client.csrf.CsrfRequestBuilder)14 BlockUsersRequest (com.willshex.blogwt.shared.api.user.call.BlockUsersRequest)12 BlockUsersResponse (com.willshex.blogwt.shared.api.user.call.BlockUsersResponse)12 ChangePasswordRequest (com.willshex.blogwt.shared.api.user.call.ChangePasswordRequest)12 ChangePasswordResponse (com.willshex.blogwt.shared.api.user.call.ChangePasswordResponse)12 ChangeUserAccessRequest (com.willshex.blogwt.shared.api.user.call.ChangeUserAccessRequest)12 ChangeUserAccessResponse (com.willshex.blogwt.shared.api.user.call.ChangeUserAccessResponse)12 ChangeUserDetailsRequest (com.willshex.blogwt.shared.api.user.call.ChangeUserDetailsRequest)12 ChangeUserDetailsResponse (com.willshex.blogwt.shared.api.user.call.ChangeUserDetailsResponse)12 CheckUsernameRequest (com.willshex.blogwt.shared.api.user.call.CheckUsernameRequest)12 CheckUsernameResponse (com.willshex.blogwt.shared.api.user.call.CheckUsernameResponse)12 FollowUsersRequest (com.willshex.blogwt.shared.api.user.call.FollowUsersRequest)12