示例#1
0
  @Override
  public void sendAnalytics(String event, HashMap<String, String> params) {
    if (analyticsId == null) {
      return;
    }

    String url =
        "http://www.bluenotepad.com/api/log?"
            + "notepad="
            + analyticsId
            + "&session="
            + sessionId
            + "&event="
            + event;
    if (params != null) {
      for (String key : params.keySet()) {
        url += "&" + key + "=" + params.get(key).replace("&nbsp;", " ");
      }
    }
    String encodedUrl = URL.encode(url);
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, encodedUrl);
    try {
      builder.sendRequest(
          null,
          new RequestCallback() {
            public void onError(Request request, Throwable exception) {}

            public void onResponseReceived(Request request, Response response) {}
          });
    } catch (RequestException e) {
    }
  }
示例#2
0
  public void getMessages() {

    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(URLGET));

    try {
      Request request =
          builder.sendRequest(
              null,
              new RequestCallback() {
                public void onError(Request request, Throwable exception) {}

                public void onResponseReceived(Request request, Response response) {
                  if (200 == response.getStatusCode()) {
                    IResponse serverResponse = decodeJSON(response.getText());
                    processResponse(serverResponse);

                  } else {

                    Window.alert("Messages couldn't  been recieved");
                  }
                }
              });
    } catch (RequestException e) {
      // Couldn't connect to server
    }
  }
  public static void performLogin(final AsyncCallback<Boolean> callback) {
    // let's only login if we are not actually logged in
    try {
      final String url = GWT.getHostPageBaseURL() + "api/mantle/isAuthenticated"; // $NON-NLS-1$
      RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
      requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
      requestBuilder.setHeader("accept", "text/plain");
      requestBuilder.sendRequest(
          null,
          new RequestCallback() {

            public void onError(Request request, Throwable caught) {
              MantleLoginDialog dialog = new MantleLoginDialog(callback, false);
              dialog.show();
            }

            public void onResponseReceived(Request request, Response response) {
              if (!"true".equalsIgnoreCase(response.getText())) {
                MantleLoginDialog dialog = new MantleLoginDialog(callback, false);
                dialog.show();
              }
            }
          });
    } catch (RequestException e) {
      MantleLoginDialog dialog = new MantleLoginDialog(callback, false);
      dialog.show();
    }
  }
  protected void initializeExecutableFileTypes() {
    final String moduleBaseURL = GWT.getModuleBaseURL();
    final String moduleName = GWT.getModuleName();
    final String contextURL = moduleBaseURL.substring(0, moduleBaseURL.lastIndexOf(moduleName));
    final String url = contextURL + "api/repos/executableTypes"; // $NON-NLS-1$
    RequestBuilder executableTypesRequestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    executableTypesRequestBuilder.setHeader("accept", "application/json");
    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) {
                JSONObject jsonObject = (JSONObject) JSONParser.parse(response.getText());
                JSONArray jsonList = (JSONArray) jsonObject.get("executableFileTypeDto");
                for (int i = 0; i < jsonList.size(); i++) {
                  JSONObject executableType = (JSONObject) jsonList.get(i);
                  executableFileExtensions.add(
                      executableType.get("extension").isString().stringValue());
                }
              } else {
                // showServerError(response);
              }
            }
          });
    } catch (RequestException e) {
      // showError(e);
    }
  }
  /** @param node */
  public void makePublic(final FileNode node, boolean isPublic) {
    String url = node.getRepository() + "/permissions";
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.POST, url);
    builder.setHeader("Content-type", "application/x-www-form-urlencoded");
    StringBuilder args = new StringBuilder();
    args.append("isPublic=");
    args.append(URL.encodeQueryString(Boolean.toString(isPublic)));
    args.append("&filename=");
    args.append(URL.encodeQueryString(getCanonicalName(node)));
    try {
      Request request =
          builder.sendRequest(
              args.toString(),
              new RequestCallback() {
                public void onError(Request request, Throwable exception) {
                  // displayError("Couldn't retrieve JSON "+exception.getMessage());
                }

                public void onResponseReceived(Request request, Response response) {
                  GWT.log("Got reply");
                  if (200 == response.getStatusCode()) {
                    GWT.log("Reply is" + response.getText());
                    GWT.log("Headers is " + response.getHeadersAsString());
                    GWT.log("Status Text " + response.getStatusText());
                    fetchFiles(repositoryUri, node.getPath());
                  } else {
                    Window.alert(
                        "Update failure: " + response.getStatusText() + " " + response.getText());
                  }
                }
              });
    } catch (RequestException e) {
      Window.alert("Update exception: " + e.toString());
    }
  }
  public void getRepo(String repoUri) {
    // Send request to server and catch any errors.
    this.lastRepoURI = repoUri;
    // this.lastPrefix = null;
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, repoUri);
    try {
      Request request =
          builder.sendRequest(
              null,
              new RequestCallback() {
                public void onError(Request request, Throwable exception) {
                  // displayError("Couldn't retrieve JSON "+exception.getMessage());
                }

                public void onResponseReceived(Request request, Response response) {
                  GWT.log(response.getStatusCode() + " " + response.getText());
                  if (200 == response.getStatusCode()) {
                    Repository repo = Repository.asRepository(response.getText());
                    updateRepo(repo);
                  } else {
                    Window.alert(
                        "Update failure: " + response.getStatusText() + " " + response.getText());
                  }
                }
              });
    } catch (RequestException e) {
      Window.alert("Update exception: " + e.toString());
    }
  }
示例#7
0
  private void postyRequest(String url, String data) {
    final RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, url);
    rb.setHeader("Content-type", "application/x-www-form-urlencoded");
    try {
      rb.sendRequest(
          data,
          new RequestCallback() {
            public void onError(final Request request, final Throwable exception) {
              Window.alert(exception.getMessage());
            }

            public void onResponseReceived(final Request request, final Response response) {
              // Window.alert(response.getText());
              int id = Integer.parseInt(response.getText());
              if (id == 1) {
                String url = "http://localhost:3000/workers.json";
                getRequest(url);
              } else if (id > 1) {
                Frame frame = new Frame("http://localhost:3000/workshops/summary");
                RootPanel.get().add(frame);
                mainPanel.clear();
                mainPanel.add(frame);
                // Window.alert("" + id);
              } else {
                userBox.setText("");
                passBox.setText("");
              }
            }
          });
    } catch (final Exception e) {
      Window.alert(e.getMessage());
    }
  }
  private void initializeSystemRoles() {
    final String url = GWT.getHostPageBaseURL() + "api/userrole/systemRoles"; // $NON-NLS-1$
    RequestBuilder executableTypesRequestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    executableTypesRequestBuilder.setHeader("accept", "application/json");
    try {
      executableTypesRequestBuilder.sendRequest(
          null,
          new RequestCallback() {

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

            public void onResponseReceived(Request request, Response response) {
              if (response.getStatusCode() == Response.SC_OK) {

                JsUserRoleList roleList =
                    (JsUserRoleList) parseRoleList(JsonUtils.escapeJsonForEval(response.getText()));
                JsArrayString jsRoleNames = roleList.getRoles();
                for (int i = 0; i < jsRoleNames.length(); i++) {
                  systemRoles.add(jsRoleNames.get(i));
                }
                Collections.sort(systemRoles);
              } else {
              }
            }
          });
    } catch (RequestException e) {
    }
  }
  public void activate() {
    processLDAPmode();
    initializeActionBaseSecurityElements();
    initializeAvailableUsers(null);

    final String url = GWT.getHostPageBaseURL() + "api/system/authentication-provider";
    RequestBuilder executableTypesRequestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    executableTypesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    executableTypesRequestBuilder.setHeader("accept", "application/json");
    try {
      executableTypesRequestBuilder.sendRequest(
          null,
          new RequestCallback() {

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

            public void onResponseReceived(Request request, Response response) {
              boolean usingLDAP = response.getText().contains("ldap");
              if (usingLDAP) {
                initializeRoles(null, "api/userrolelist/roles", rolesListBox);
              } else {
                initializeRoles(null, "api/userroledao/roles", rolesListBox);
              }
              initializeRoles(null, "api/userrolelist/extraRoles", systemRolesListBox);
            }
          });
    } catch (RequestException e) {
      // ignored
    }
  }
示例#10
0
  public static void retrieveAncestors(final Event event, final PathHandler handler) {
    String url = "/ReactomeRESTfulAPI/RESTfulWS/queryEventAncestors/" + event.getDbId();
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    requestBuilder.setHeader("Accept", "application/json");
    try {
      requestBuilder.sendRequest(
          null,
          new RequestCallback() {
            @Override
            public void onResponseReceived(Request request, Response response) {
              try {
                JSONArray list = JSONParser.parseStrict(response.getText()).isArray();
                Ancestors ancestors = new Ancestors(list);
                List<Path> paths =
                    getPathsWithoutOrphanPathways(ancestors.getPathsContaining(event));
                handler.onPathsRetrieved(paths);
              } catch (Exception ex) {
                // ToDo: Look into new Error Handling
              }
            }

            @Override
            public void onError(Request request, Throwable exception) {
              // ToDo: Look into new Error Handling
            }
          });
    } catch (RequestException ex) {
      // ToDo: Look into new Error Handling
    }
  }
  private void modifyUserRoles(final String userName, String serviceUrl) {
    RequestBuilder executableTypesRequestBuilder =
        new RequestBuilder(RequestBuilder.PUT, serviceUrl);
    try {
      executableTypesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
      executableTypesRequestBuilder.sendRequest(
          null,
          new RequestCallback() {
            public void onError(Request request, Throwable exception) {
              displayErrorInMessageBox(
                  Messages.getString("Error"), exception.getLocalizedMessage());
            }

            public void onResponseReceived(Request request, Response response) {
              checkForError(Messages.getString("Error"), response);
              getRolesForUser(userName);
              initializeRoles(
                  rolesListBox.getValue(rolesListBox.getSelectedIndex()),
                  "api/userroledao/roles",
                  rolesListBox);
            }
          });
    } catch (RequestException e) {
      displayErrorInMessageBox(Messages.getString("Error"), e.getLocalizedMessage());
    }
  }
  public void deleteFolder(final FileNode object) {
    String filename = getCanonicalName(object);

    String url = this.repo.getUri() + "/folder?filename=" + URL.encodeQueryString(filename);
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.DELETE, url);
    try {
      Request request =
          builder.sendRequest(
              null,
              new RequestCallback() {
                public void onError(Request request, Throwable exception) {
                  // displayError("Couldn't retrieve JSON "+exception.getMessage());
                }

                public void onResponseReceived(Request request, Response response) {
                  GWT.log(response.getStatusCode() + " " + response.getText());
                  if (200 != response.getStatusCode()) {
                    Window.alert(
                        "Delete failure: " + response.getStatusText() + " " + response.getText());
                  }
                }
              });
    } catch (RequestException e) {
      Window.alert("Delete exception: " + e.toString());
    }
  }
  public void saveUser(final String name, final String password) {
    String serviceUrl = GWT.getHostPageBaseURL() + "api/userroledao/createUser";
    RequestBuilder executableTypesRequestBuilder =
        new RequestBuilder(RequestBuilder.PUT, serviceUrl);
    try {
      executableTypesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
      executableTypesRequestBuilder.setHeader("Content-Type", "application/json");
      String json =
          "{\"userName\": \""
              + encodeUri(name)
              + "\", \"password\": \""
              + encodeUri(password)
              + "\"}";
      executableTypesRequestBuilder.sendRequest(
          json,
          new RequestCallback() {
            public void onError(Request request, Throwable exception) {
              displayErrorInMessageBox(
                  Messages.getString("Error"), exception.getLocalizedMessage());
            }

            public void onResponseReceived(Request request, Response response) {
              initializeAvailableUsers(name);
              initializeRoles(
                  rolesListBox.getValue(rolesListBox.getSelectedIndex()),
                  "api/userroledao/roles",
                  rolesListBox);
            }
          });
    } catch (RequestException e) {
      displayErrorInMessageBox(Messages.getString("Error"), e.getLocalizedMessage());
    }
  }
  private void processLDAPmode() {
    final String url = GWT.getHostPageBaseURL() + "api/system/authentication-provider";
    RequestBuilder executableTypesRequestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    executableTypesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    executableTypesRequestBuilder.setHeader("accept", "application/json");
    try {
      executableTypesRequestBuilder.sendRequest(
          null,
          new RequestCallback() {

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

            public void onResponseReceived(Request request, Response response) {
              boolean usingLDAP = !response.getText().contains("ldap");
              usersLabelPanel.setVisible(usingLDAP);
              usersPanel.setVisible(usingLDAP);
              newRoleButton.setVisible(usingLDAP);
              deleteRoleButton.setVisible(usingLDAP);

              if (!usingLDAP) {
                mainTabPanel.getTab(0).setVisible(false);
                mainTabPanel.selectTab(1);
              } else {
                mainTabPanel.getTab(0).setVisible(true);
                mainTabPanel.selectTab(0);
              }
            }
          });
    } catch (RequestException e) {
      // ignored
    }
  }
  protected void performOperation() {
    final String url = GWT.getHostPageBaseURL() + "plugin/reporting/api/cache/clear"; // $NON-NLS-1$
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, url);
    requestBuilder.setHeader("accept", "text/text");
    requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    try {
      requestBuilder.sendRequest(
          null,
          new RequestCallback() {

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

            public void onResponseReceived(Request request, Response response) {
              MessageDialogBox dialogBox =
                  new MessageDialogBox(
                      Messages.getString("info"),
                      Messages.getString("reportingDataCacheFlushedSuccessfully"),
                      false,
                      false,
                      true); //$NON-NLS-1$ //$NON-NLS-2$
              dialogBox.center();
            }
          });
    } catch (RequestException e) {
      Window.alert(e.getMessage());
      // showError(e);
    }
  }
  public void deleteRoles() {

    String selectedRoles = "";
    for (int i = 0; i < rolesListBox.getItemCount(); i++) {
      if (rolesListBox.isItemSelected(i)) {
        selectedRoles = selectedRoles + encodeUri(rolesListBox.getValue(i)) + "|";
      }
    }

    String serviceUrl =
        GWT.getHostPageBaseURL() + "api/userroledao/deleteRoles?roleNames=" + selectedRoles;
    RequestBuilder executableTypesRequestBuilder =
        new RequestBuilder(RequestBuilder.PUT, serviceUrl);
    try {
      executableTypesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
      executableTypesRequestBuilder.sendRequest(
          null,
          new RequestCallback() {
            public void onError(Request request, Throwable exception) {
              displayErrorInMessageBox(
                  Messages.getString("Error"), exception.getLocalizedMessage());
            }

            public void onResponseReceived(Request request, Response response) {
              checkForError(Messages.getString("Error"), response);
              availableMembersListBox.clear();
              selectedMembersListBox.clear();
              initializeRoles(null, "api/userroledao/roles", rolesListBox);
              initializeAvailableUsers(usersListBox.getValue(usersListBox.getSelectedIndex()));
            }
          });
    } catch (RequestException e) {
      displayErrorInMessageBox(Messages.getString("Error"), e.getLocalizedMessage());
    }
  }
示例#17
0
    @Override
    void send(String message, final AsyncCallback<Void> callback) {
      RequestBuilder request = new RequestBuilder(RequestBuilder.POST, serviceUrl());
      try {
        request.sendRequest(
            message,
            new RequestCallback() {
              @Override
              public void onResponseReceived(Request request, Response response) {
                // when a connection is abruptly closed (for instance when a user presses F5
                // the statuscode seems to be 0, the call could have arrived at the server though
                if (response.getStatusCode() != Response.SC_OK && response.getStatusCode() != 0) {
                  logger.log(
                      Level.SEVERE,
                      "Failed to send server message: ["
                          + response.getStatusText()
                          + ","
                          + response.getStatusCode()
                          + "]");
                  callback.onFailure(
                      new StatusCodeException(response.getStatusCode(), response.getStatusText()));
                } else {
                  callback.onSuccess(null);
                }
              }

              @Override
              public void onError(Request request, Throwable exception) {
                callback.onFailure(exception);
              }
            });
      } catch (RequestException ex) {
        callback.onFailure(ex);
      }
    }
  public void getAnnotationList(String annotates, final boolean forceDecorate) {
    if (annotates.contains("?")) {
      annotates = annotates.substring(0, annotates.indexOf('?'));
    }
    String url = controller.getAnnoteaServerUrl() + "?w3c_annotates=" + annotates;
    RequestBuilder getRequest = new RequestBuilder(RequestBuilder.GET, URL.encode(url));
    try {
      getRequest.sendRequest(
          null,
          new RequestCallback() {
            public void onError(Request request, Throwable exception) {}

            public void onResponseReceived(Request request, Response response) {
              responseManager.processAnnotationListResponse(response.getText());
              if (forceDecorate) {
                // Force all the annotations to be redecorated
                controller.updateAnnotations(true);
              }
            }
          });
    } catch (RequestException e) {
      GWT.log("Error while requesting annotations: " + url, e);
      Log.debug("Error while requesting annotations: " + url, e);
      Window.alert(e.toString());
    }
  }
  public void submitAnnotation(Annotation newAnnotation) {
    AnnotationXmlGenerator xmlGenerator =
        new AnnotationXmlGenerator(webConfiguration, newAnnotation);
    String request = xmlGenerator.generateXml();
    postRequest =
        new RequestBuilder(RequestBuilder.POST, URL.encode(controller.getAnnoteaServerUrl()));
    try {
      postRequest.sendRequest(
          request,
          new RequestCallback() {
            public void onError(Request request, Throwable exception) {
              Window.alert("Error while sending data to annotea server: " + exception.toString());
            }

            public void onResponseReceived(Request request, Response response) {
              responseManager.processSubmitAnnotationResponse(response.getText());
              getAnnotationList(controller.getDocumentUrl());
              controller.reloadAnnotations();
            }
          });
    } catch (Throwable e) {
      GWT.log("Error while sending new annotation", e);
      Log.debug("Error while sending new annotation", e);
    }
  }
  public void deleteAnnotation(String annotates, final Annotation annotation) {
    if (annotates.contains("?")) {
      annotates = annotates.substring(0, annotates.indexOf('?'));
    }

    String url = controller.getAnnoteaServerUrl() + "/" + annotation.getUUID();
    url += "?document_url=" + annotates;
    RequestBuilder req = new RequestBuilder("DELETE", url) {
          // nothing to override... used to make a *real* HTTP DELETE request
        };

    try {
      req.sendRequest(
          null,
          new RequestCallback() {
            public void onError(Request arg0, Throwable arg1) {}

            public void onResponseReceived(Request arg0, Response arg1) {
              getAnnotationList(Window.Location.getHref(), true);
              controller.reloadAnnotations();
            }
          });
    } catch (RequestException e) {
      GWT.log("Error while deleting an annotation: " + url, e);
      Log.debug("Error while deleting an annotation: " + url, e);
    }
  }
示例#21
0
  /**
   * @see void
   *     org.openxdata.server.admin.client.view.treeview.StudiesTreeView#onSetFileContents(String)
   */
  public static void onSetFileContents(
      final Tree tree, final TreeItem item, String contents, final PopupPanel popup) {

    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, "formopen");

    try {
      builder.sendRequest(
          null,
          new RequestCallback() {
            @Override
            public void onResponseReceived(Request request, Response response) {

              FormUtil.dlg.setText("Importing.......");
              FormUtil.dlg.center();

              final Response resp = response;

              Scheduler.get()
                  .scheduleDeferred(
                      new ScheduledCommand() {
                        @Override
                        public void execute() {
                          try {
                            Editable editable = StudyImport.importStudyItem(resp.getText());
                            if (editable == null) {
                              FormUtil.dlg.hide();
                              Window.alert("Invalid Import File");
                              return;
                            }

                            if (editable instanceof StudyDef) {
                              setStudyContent(tree, popup, editable);
                            } else if (editable instanceof FormDef) {
                              setFormContents(tree, item, popup, editable);
                            } else if (editable instanceof FormDefVersion) {
                              setFormDefVersionContents(tree, item, popup, editable);
                            }

                            FormUtil.dlg.hide();

                            MainViewControllerFacade.saveData();
                          } catch (Exception ex) {
                            FormUtil.dlg.hide();
                            FormUtil.displayException(ex);
                          }
                        }
                      });
            }

            @Override
            public void onError(Request request, Throwable ex) {
              FormUtil.displayException(ex);
            }
          });
    } catch (RequestException ex) {
      FormUtil.displayException(ex);
    }
  }
  protected boolean addBlockoutPeriod(
      final JSONObject schedule, final JsJobTrigger trigger, String urlSuffix) {
    String url = GWT.getHostPageBaseURL() + "api/scheduler/blockout/" + urlSuffix; // $NON-NLS-1$

    RequestBuilder addBlockoutPeriodRequest = new RequestBuilder(RequestBuilder.POST, url);
    addBlockoutPeriodRequest.setHeader("accept", "text/plain"); // $NON-NLS-1$ //$NON-NLS-2$
    addBlockoutPeriodRequest.setHeader(
        "Content-Type", "application/json"); // $NON-NLS-1$ //$NON-NLS-2$
    addBlockoutPeriodRequest.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");

    // Create a unique blockout period name
    final Long duration = trigger.getBlockDuration();
    final String blockoutPeriodName =
        trigger.getScheduleType()
            + Random.nextInt()
            + ":"
            + //$NON-NLS-1$
            /* PentahoSessionHolder.getSession().getName() */ "admin"
            + ":"
            + duration; //$NON-NLS-1$ //$NON-NLS-2$

    // Add blockout specific parameters
    JSONObject addBlockoutParams = schedule;
    addBlockoutParams.put("jobName", new JSONString(blockoutPeriodName)); // $NON-NLS-1$
    addBlockoutParams.put("duration", new JSONNumber(duration)); // $NON-NLS-1$
    addBlockoutParams.put("timeZone", new JSONString(scheduleEditorWizardPanel.getTimeZone()));

    try {
      addBlockoutPeriodRequest.sendRequest(
          addBlockoutParams.toString(),
          new RequestCallback() {
            public void onError(Request request, Throwable exception) {
              MessageDialogBox dialogBox =
                  new MessageDialogBox(
                      Messages.getString("error"),
                      exception.toString(),
                      false,
                      false,
                      true); //$NON-NLS-1$
              dialogBox.center();
              setDone(false);
            }

            public void onResponseReceived(Request request, Response response) {
              if (response.getStatusCode() == Response.SC_OK) {
                if (null != callback) {
                  callback.okPressed();
                }
              }
            }
          });
    } catch (RequestException e) {
      // ignored
    }

    return true;
  }
  private void initializeLogicalRoleMappings() {
    final String url = GWT.getHostPageBaseURL() + "api/userrole/logicalRoleMap"; // $NON-NLS-1$
    RequestBuilder executableTypesRequestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    executableTypesRequestBuilder.setHeader("accept", "application/json");
    try {
      executableTypesRequestBuilder.sendRequest(
          null,
          new RequestCallback() {

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

            public void onResponseReceived(Request request, Response response) {
              if (response.getStatusCode() == Response.SC_OK) {
                JsLogicalRoleMap logicalRoleMap =
                    (JsLogicalRoleMap)
                        parseRoleMappings(JsonUtils.escapeJsonForEval(response.getText()));
                if (logicalRoles.size() == 0) {
                  for (int i = 0; i < logicalRoleMap.getLogicalRoles().length(); i++) {

                    CheckBox permCB =
                        new CheckBox(logicalRoleMap.getLogicalRoles().get(i).getLocalizedName());
                    permCB.addValueChangeHandler(SecurityPanel.this);
                    permissionPanel.add(permCB);
                    logicalRoles.put(
                        logicalRoleMap.getLogicalRoles().get(i).getLocalizedName(),
                        new LogicalRoleInfo(
                            logicalRoleMap.getLogicalRoles().get(i).getRoleName(), permCB));
                  }
                }
                for (int j = 0; j < logicalRoleMap.getRoleAssignments().length(); j++) {
                  String roleName = logicalRoleMap.getRoleAssignments().get(j).getRoleName();
                  List<String> logicalRoles = new ArrayList<String>();
                  for (int k = 0;
                      k
                          < logicalRoleMap
                              .getRoleAssignments()
                              .get(j)
                              .getAssignedLogicalRoles()
                              .length();
                      k++) {
                    logicalRoles.add(
                        logicalRoleMap
                            .getRoleAssignments()
                            .get(j)
                            .getAssignedLogicalRoles()
                            .get(k));
                  }
                  masterRoleMap.put(roleName, logicalRoles);
                }
              } else {
              }
            }
          });
    } catch (RequestException e) {
    }
  }
  private void getUsersInRole(String role) {
    final String url =
        GWT.getHostPageBaseURL() + "api/userroledao/roleMembers?roleName=" + encodeUri(role);
    RequestBuilder executableTypesRequestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    executableTypesRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    executableTypesRequestBuilder.setHeader("accept", "application/xml");
    try {
      executableTypesRequestBuilder.sendRequest(
          null,
          new RequestCallback() {

            public void onError(Request request, Throwable exception) {
              displayErrorInMessageBox(
                  Messages.getString("Error"), exception.getLocalizedMessage());
            }

            public void onResponseReceived(Request request, Response response) {
              selectedMembersListBox.clear();
              String txt = response.getText();
              Document doc = XMLParser.parse(txt);
              NodeList users = doc.getElementsByTagName("users");
              for (int i = 0; i < users.getLength(); i++) {
                Node userNode = users.item(i);
                String user = userNode.getFirstChild().getNodeValue();
                selectedMembersListBox.addItem(user);
              }

              Timer t =
                  new Timer() {
                    public void run() {
                      if (usersListBox.getItemCount() > 0) {
                        cancel();
                        // availableMembersListBox = usersListBox - selectedMembersListBox
                        availableMembersListBox.clear();
                        for (int i = 0; i < usersListBox.getItemCount(); i++) {
                          String user = usersListBox.getValue(i);
                          boolean isSelected = false;
                          for (int j = 0; j < selectedMembersListBox.getItemCount(); j++) {
                            if (selectedMembersListBox.getValue(j).equals(user)) {
                              isSelected = true;
                            }
                          }
                          if (!isSelected) {
                            availableMembersListBox.addItem(user);
                          }
                        }
                      }
                    }
                  };
              t.scheduleRepeating(100);
            }
          });
    } catch (RequestException e) {
      displayErrorInMessageBox(Messages.getString("Error"), e.getLocalizedMessage());
    }
  }
  /**
   * Before creating a new schedule, we want to check to see if the schedule that is being created
   * is going to conflict with any one of the blockout periods if one is provisioned.
   *
   * @param schedule
   * @param trigger
   */
  protected void verifyBlockoutConflict(final JSONObject schedule, final JsJobTrigger trigger) {
    String url = GWT.getHostPageBaseURL() + "api/scheduler/blockout/blockstatus"; // $NON-NLS-1$

    RequestBuilder blockoutConflictRequest = new RequestBuilder(RequestBuilder.POST, url);
    blockoutConflictRequest.setHeader("accept", "application/json"); // $NON-NLS-1$ //$NON-NLS-2$
    blockoutConflictRequest.setHeader(
        "Content-Type", "application/json"); // $NON-NLS-1$ //$NON-NLS-2$
    blockoutConflictRequest.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");

    final JSONObject verifyBlockoutParams = schedule;
    verifyBlockoutParams.put("jobName", new JSONString(scheduleName)); // $NON-NLS-1$

    try {
      blockoutConflictRequest.sendRequest(
          verifyBlockoutParams.toString(),
          new RequestCallback() {
            public void onError(Request request, Throwable exception) {
              MessageDialogBox dialogBox =
                  new MessageDialogBox(
                      Messages.getString("error"),
                      exception.toString(),
                      false,
                      false,
                      true); //$NON-NLS-1$
              dialogBox.center();
              setDone(false);
            }

            public void onResponseReceived(Request request, Response response) {
              if (response.getStatusCode() == Response.SC_OK) {
                JsBlockStatus statusResponse =
                    (JsBlockStatus) parseJson(JsonUtils.escapeJsonForEval(response.getText()));

                // Determine if this schedule conflicts all the time or some of the time
                boolean partiallyBlocked =
                    Boolean.parseBoolean(statusResponse.getPartiallyBlocked());
                boolean totallyBlocked = Boolean.parseBoolean(statusResponse.getTotallyBlocked());
                if (partiallyBlocked || totallyBlocked) {
                  promptDueToBlockoutConflicts(totallyBlocked, partiallyBlocked, schedule, trigger);
                } else {
                  // Continue with other panels in the wizard (params, email)
                  handleWizardPanels(schedule, trigger);
                }
              } else {
                handleWizardPanels(schedule, trigger);
              }
            }
          });
    } catch (RequestException e) {
      // ignored
    }

    super.nextClicked();
  }
  private void populateTimeZonePicker() {

    String url = GWT.getHostPageBaseURL() + "api/system/timezones"; // $NON-NLS-1$
    RequestBuilder timeZonesRequest = new RequestBuilder(RequestBuilder.GET, url);
    timeZonesRequest.setHeader("accept", "application/json"); // $NON-NLS-1$ //$NON-NLS-2$
    timeZonesRequest.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    try {
      timeZonesRequest.sendRequest(
          null,
          new RequestCallback() {

            @Override
            public void onResponseReceived(Request request, Response response) {
              timeZonePicker.clear();
              String responseText = response.getText();
              JSONValue value = JSONParser.parseLenient(responseText);
              JSONObject object = value.isObject();
              value = object.get("timeZones");
              JSONValue serverTZvalue = object.get("serverTzId");
              JSONString serverTZIdString = serverTZvalue.isString();
              String serverTZId = serverTZIdString.stringValue();
              object = value.isObject();
              value = object.get("entry");
              JSONArray timeZonesJSONArray = value.isArray();
              for (int i = 0; i < timeZonesJSONArray.size(); i++) {
                JSONValue entryValue = timeZonesJSONArray.get(i);
                JSONObject entryObject = entryValue.isObject();
                JSONValue keyValue = entryObject.get("key");
                JSONValue theValue = entryObject.get("value");
                String key = keyValue.isString().stringValue();
                String valueForKey = theValue.isString().stringValue();
                timeZonePicker.addItem(valueForKey, key);
              }
              for (int i = 0; i < timeZonePicker.getItemCount(); i++) {
                if (timeZonePicker.getValue(i).equalsIgnoreCase(serverTZId)) {
                  timeZonePicker.setSelectedIndex(i);
                  break;
                }
              }
            }

            @Override
            public void onError(Request request, Throwable exception) {
              // TODO Auto-generated method stub

            }
          });
    } catch (RequestException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  /** @param view */
  public void fetchFiles(String repoURI, final String prefix) {
    String url = repoURI + "/list";
    if (prefix != null) {
      url += "?prefix=" + URL.encodeQueryString(prefix);
    }
    this.lastRepoURI = repoURI;
    this.lastPrefix = prefix;
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, url);
    try {
      builder.sendRequest(
          null,
          new RequestCallback() {

            public void onError(Request request, Throwable exception) {
              GWT.log("Couldn't retrieve JSON " + exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
              if (200 == response.getStatusCode()) {
                GWT.log(response.getText());
                RepoListResponse result = RepoListResponse.parseJSON(response.getText());
                List<FileNode> crumbs = result.getCrumbs();
                List<FileNode> namesWithPlaceholders = result.getFiles();
                if (crumbs != null && placeholderMap != null) {
                  String lastPath = "";
                  if (crumbs.size() > 1) {
                    FileNode lastCrumb = crumbs.get(crumbs.size() - 1);
                    lastPath = getCanonicalName(lastCrumb) + "/";
                  }
                  GWT.log("lastPath=" + lastPath);
                  if (placeholderMap.containsKey(lastPath)) {
                    java.util.Collection<FileNode> placeholders =
                        placeholderMap.get(lastPath).values();
                    namesWithPlaceholders =
                        new ArrayList<FileNode>(placeholders.size() + result.getFiles().size());
                    GWT.log("adding placeholder");
                    namesWithPlaceholders.addAll(placeholders);
                    namesWithPlaceholders.addAll(result.getFiles());
                  }
                }
                updateRepoContent(result.getCrumbs(), namesWithPlaceholders);
              } else {
                GWT.log("Couldn't retrieve JSON (" + response.getStatusText() + ")");
              }
            }
          });
    } catch (RequestException e) {
      GWT.log("Couldn't retrieve JSON " + e.getMessage());
    }
  }
示例#28
0
	public void loadSelectedProcedureInfo() {
		if (Util.getProgramMode() == ProgramMode.STUBBED) {

		} else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
			String[] params = { procs.toString() };
			RequestBuilder builder = new RequestBuilder(
					RequestBuilder.POST,
					URL
							.encode(Util
									.getJsonRequest(
											"org.freemedsoftware.api.ClaimLog.getProceduresInfo",
											params)));
			try {
				builder.sendRequest(null, new RequestCallback() {
					public void onError(Request request, Throwable ex) {
						Window.alert(ex.toString());
					}

					@SuppressWarnings("unchecked")
					public void onResponseReceived(Request request,
							Response response) {

						if (Util.checkValidSessionResponse(response.getText())) {
							if (200 == response.getStatusCode()) {
								try {
									HashMap<String, String>[] result = (HashMap<String, String>[]) JsonUtil
											.shoehornJson(JSONParser
													.parseStrict(response.getText()),
													"HashMap<String,String>[]");
									if (result != null) {
										if (result.length > 0) {
											proceduresInfoTable
													.loadData(result);
										}
									}
								} catch (Exception e) {

								}
							} else {
							}
						}
					}
				});
			} catch (RequestException e) {
				Window.alert(e.toString());
			}

		} else {
		}
	}
  private void saveSecuritySettings(final AsyncCallback<Boolean> callback) {
    JSONObject jsNewRoleAssignments = new JSONObject();
    JSONArray jsLogicalRoleAssignments = new JSONArray();
    int x = 0;
    for (Map.Entry<String, List<String>> roleAssignment : newRoleAssignments.entrySet()) {
      JSONArray jsLogicalRoles = new JSONArray();
      int y = 0;
      for (String logicalRoleName : roleAssignment.getValue()) {
        jsLogicalRoles.set(y++, new JSONString(logicalRoleName));
      }
      JSONObject jsRoleAssignment = new JSONObject();
      jsRoleAssignment.put("roleName", new JSONString(roleAssignment.getKey()));
      jsRoleAssignment.put("logicalRoles", jsLogicalRoles);
      jsLogicalRoleAssignments.set(x++, jsRoleAssignment);
    }
    jsNewRoleAssignments.put("logicalRoleAssignments", jsLogicalRoleAssignments);
    RequestBuilder saveSettingRequestBuilder =
        new RequestBuilder(RequestBuilder.PUT, contextURL + "api/userrole/roleAssignments");
    saveSettingRequestBuilder.setHeader(
        "Content-Type", "application/json"); // $NON-NLS-1$//$NON-NLS-2$
    WaitPopup.getInstance().setVisible(true);
    try {
      saveSettingRequestBuilder.sendRequest(
          jsNewRoleAssignments.toString(),
          new RequestCallback() {

            @Override
            public void onError(Request request, Throwable exception) {
              WaitPopup.getInstance().setVisible(false);
              callback.onFailure(exception);
            }

            @Override
            public void onResponseReceived(Request request, Response response) {
              WaitPopup.getInstance().setVisible(false);
              if (response.getStatusCode() == 200) {
                masterRoleMap.putAll(newRoleAssignments);
                newRoleAssignments.clear();
                callback.onSuccess(true);
              } else {
                callback.onSuccess(false);
              }
            }
          });
    } catch (RequestException e) {
      WaitPopup.getInstance().setVisible(false);
      callback.onFailure(e);
    }
  }
        public void execute() {
          solutionTree.setShowLocalizedFileNames(!solutionTree.isShowLocalizedFileNames());

          // update setting
          final String url =
              GWT.getHostPageBaseURL()
                  + "api/user-settings/MANTLE_SHOW_LOCALIZED_FILENAMES"; //$NON-NLS-1$
          RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
          try {
            builder.sendRequest(
                "" + solutionTree.isShowLocalizedFileNames(), EmptyRequestCallback.getInstance());
          } catch (RequestException e) {
            // showError(e);
          }
        }