/** * Returns a cloud debugger connection given a user email to indicate the credentials to use. The * function may return null if the user is not logged in. */ @Nullable private static Debugger getClient(final @Nullable String userEmail, final int timeout) { if (Strings.isNullOrEmpty(userEmail)) { LOG.warn("unexpected null email in controller initialize."); return null; } final String hashkey = userEmail + timeout; Debugger cloudDebuggerClient = myDebuggerClientsFromUserEmail.get(hashkey); if (cloudDebuggerClient == null) { try { final CredentialedUser user = GoogleLogin.getInstance().getAllUsers().get(userEmail); final Credential credential = (user != null ? user.getCredential() : null); if (credential != null) { user.getGoogleLoginState() .addLoginListener( new LoginListener() { @Override public void statusChanged(boolean login) { // aggressively remove the cached item on any status change. myDebuggerClientsFromUserEmail.remove(hashkey); } }); HttpRequestInitializer initializer = new HttpRequestInitializer() { @Override public void initialize(HttpRequest httpRequest) throws IOException { httpRequest.setConnectTimeout(timeout); httpRequest.setReadTimeout(timeout); credential.initialize(httpRequest); } }; HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); cloudDebuggerClient = new Builder(httpTransport, JSON_FACTORY, initializer) .setRootUrl(ROOT_URL) .setApplicationName(GoogleLoginUtils.getCurrentPlatformName()) .build() .debugger(); } } catch (IOException ex) { LOG.warn("Error connecting to Cloud Debugger API", ex); } catch (GeneralSecurityException ex) { LOG.warn("Error connecting to Cloud Debugger API", ex); } if (cloudDebuggerClient != null) { myDebuggerClientsFromUserEmail.put(hashkey, cloudDebuggerClient); } } return cloudDebuggerClient; }
private static boolean isSourceLocationValid(SourceLocation sourceLocation) { if (sourceLocation == null) { return false; } if (Strings.isNullOrEmpty(sourceLocation.getPath())) { return false; } if (sourceLocation.getLine() == null) { return false; } return true; }
private void updateUi(TransactionSummary transactionSummary) { MetadataStorage metadataStorage = _mbwManager.getMetadataStorage(); // Set Date Date date = new Date(transactionSummary.time * 1000L); DateFormat dateFormat = new AdaptiveDateFormat(getApplicationContext()); setText(R.id.pop_transaction_date, dateFormat.format(date)); // Set amount long amountSatoshis = getPaymentAmountSatoshis(transactionSummary); String value = _mbwManager.getBtcValueString(amountSatoshis); String fiatValue = _mbwManager.getCurrencySwitcher().getFormattedFiatValue(amountSatoshis, true); String fiatAppendment = ""; if (!Strings.isNullOrEmpty(fiatValue)) { fiatAppendment = " (" + fiatValue + ")"; } setText(R.id.pop_transaction_amount, value + fiatAppendment); // Set label String label = metadataStorage.getLabelByTransaction(transactionSummary.txid); setText(R.id.pop_transaction_label, label); URL url = getUrl(popRequest.getP()); if (url == null) { Toast.makeText(this, "Invalid URL:" + popRequest.getP(), Toast.LENGTH_LONG).show(); finish(); return; } TextView textView = (TextView) findViewById(R.id.pop_recipient_host); textView.setText(url.getHost()); String protocol = url.getProtocol(); if ("https".equals(protocol)) { textView.setCompoundDrawablesWithIntrinsicBounds( R.drawable.holo_dark_ic_action_secure, 0, 0, 0); } else if ("http".equals(protocol)) { textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); } else { Toast.makeText(this, "Unsupported protocol:" + url.getProtocol(), Toast.LENGTH_LONG).show(); finish(); } }
public String getAmbariPassword(Cluster cluster) { if (Strings.isNullOrEmpty(cluster.getCloudbreakAmbariPassword())) { return cluster.getPassword(); } return cluster.getCloudbreakAmbariPassword(); }
public String getAmbariUserName(Cluster cluster) { if (Strings.isNullOrEmpty(cluster.getCloudbreakAmbariUser())) { return cluster.getUserName(); } return cluster.getCloudbreakAmbariUser(); }
public TimeZone getTimeZone() { String timezone = getString("secor.parser.timezone"); return Strings.isNullOrEmpty(timezone) ? TimeZone.getTimeZone("UTC") : TimeZone.getTimeZone(timezone); }