com.google.api.client.util.Joiner Java Examples

The following examples show how to use com.google.api.client.util.Joiner. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BigQueryInterpreter.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
public static String printRows(final GetQueryResultsResponse response) {
  StringBuilder msg = new StringBuilder();
  try {
    List<String> schemNames = new ArrayList<String>();
    for (TableFieldSchema schem: response.getSchema().getFields()) {
      schemNames.add(schem.getName());
    }
    msg.append(Joiner.on(TAB).join(schemNames));
    msg.append(NEWLINE);
    for (TableRow row : response.getRows()) {
      List<String> fieldValues = new ArrayList<String>();
      for (TableCell field : row.getF()) {
        fieldValues.add(field.getV().toString());
      }
      msg.append(Joiner.on(TAB).join(fieldValues));
      msg.append(NEWLINE);
    }
    return msg.toString();
  } catch (NullPointerException ex) {
    throw new NullPointerException("SQL Execution returned an error!");
  }
}
 
Example #2
Source File: AuthorizationCodeFlowTest.java    From google-oauth-java-client with Apache License 2.0 6 votes vote down vote up
public void subsetTestNewAuthorizationUrl(Collection<String> scopes) {
  AuthorizationCodeFlow flow =
      new AuthorizationCodeFlow.Builder(BearerToken.queryParameterAccessMethod(),
          new AccessTokenTransport(),
          new JacksonFactory(),
          TOKEN_SERVER_URL,
          new BasicAuthentication(CLIENT_ID, CLIENT_SECRET),
          CLIENT_ID,
          "https://example.com").setScopes(scopes).build();

  AuthorizationCodeRequestUrl url = flow.newAuthorizationUrl();
  if (scopes.isEmpty()) {
    assertNull(url.getScopes());
  } else {
    assertEquals(Joiner.on(' ').join(scopes), url.getScopes());
  }
}
 
Example #3
Source File: OrchestratorRecipeExecutor.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
private void recipesEvent(Long stackId, Status status, Map<String, List<RecipeModel>> recipeMap) {
    List<String> recipes = new ArrayList<>();
    for (Entry<String, List<RecipeModel>> entry : recipeMap.entrySet()) {
        Collection<String> recipeNamesPerHostgroup = new ArrayList<>(entry.getValue().size());
        for (RecipeModel rm : entry.getValue()) {
            recipeNamesPerHostgroup.add(rm.getName());
        }
        if (!recipeNamesPerHostgroup.isEmpty()) {
            String recipeNamesStr = Joiner.on(',').join(recipeNamesPerHostgroup);
            recipes.add(String.format("%s:[%s]", entry.getKey(), recipeNamesStr));
        }
    }

    if (!recipes.isEmpty()) {
        Collections.sort(recipes);
        String messageStr = Joiner.on(';').join(recipes);
        cloudbreakEventService.fireCloudbreakEvent(stackId, status.name(), CLUSTER_UPLOAD_RECIPES, Collections.singletonList(messageStr));
    }
}
 
Example #4
Source File: ManagedServiceAccountKeyCredential.java    From styx with Apache License 2.0 5 votes vote down vote up
private JsonWebToken.Payload jwtPayload() {
  var currentTime = System.currentTimeMillis();
  var payload = new JsonWebToken.Payload();
  payload.setIssuer(getServiceAccountId());
  payload.setAudience(getTokenServerEncodedUrl());
  payload.setIssuedAtTimeSeconds(currentTime / 1000);
  payload.setExpirationTimeSeconds(currentTime / 1000 + 3600);
  payload.setSubject(getServiceAccountUser());
  payload.put("scope", Joiner.on(' ').join(getServiceAccountScopes()));
  return payload;
}
 
Example #5
Source File: GoogleCredential.java    From google-api-java-client with Apache License 2.0 5 votes vote down vote up
@Override
@Beta
protected TokenResponse executeRefreshToken() throws IOException {
  if (serviceAccountPrivateKey == null) {
    return super.executeRefreshToken();
  }
  // service accounts: no refresh token; instead use private key to request new access token
  JsonWebSignature.Header header = new JsonWebSignature.Header();
  header.setAlgorithm("RS256");
  header.setType("JWT");
  header.setKeyId(serviceAccountPrivateKeyId);
  JsonWebToken.Payload payload = new JsonWebToken.Payload();
  long currentTime = getClock().currentTimeMillis();
  payload.setIssuer(serviceAccountId);
  payload.setAudience(getTokenServerEncodedUrl());
  payload.setIssuedAtTimeSeconds(currentTime / 1000);
  payload.setExpirationTimeSeconds(currentTime / 1000 + 3600);
  payload.setSubject(serviceAccountUser);
  payload.put("scope", Joiner.on(' ').join(serviceAccountScopes));
  try {
    String assertion = JsonWebSignature.signUsingRsaSha256(
        serviceAccountPrivateKey, getJsonFactory(), header, payload);
    TokenRequest request = new TokenRequest(
        getTransport(), getJsonFactory(), new GenericUrl(getTokenServerEncodedUrl()),
        "urn:ietf:params:oauth:grant-type:jwt-bearer");
    request.put("assertion", assertion);
    return request.execute();
  } catch (GeneralSecurityException exception) {
    IOException e = new IOException();
    e.initCause(exception);
    throw e;
  }
}
 
Example #6
Source File: StatusUpdate.java    From twitter4j-ads with MIT License 4 votes vote down vote up
HttpParameter[] asHttpParameterArray() {
    ArrayList<HttpParameter> params = new ArrayList<HttpParameter>();
    appendParameter("status", status, params);
    if (-1 != inReplyToStatusId) {
        appendParameter("in_reply_to_status_id", inReplyToStatusId, params);
    }
    if (location != null) {
        appendParameter("lat", location.getLatitude(), params);
        appendParameter("long", location.getLongitude(), params);

    }
    appendParameter("place_id", placeId, params);
    if (!displayCoordinates) {
        appendParameter("display_coordinates", "false", params);
    }
    if (null != mediaFile) {
        params.add(new HttpParameter("media[]", mediaFile));
        params.add(new HttpParameter("possibly_sensitive", possiblySensitive));
    } else if (mediaName != null && mediaBody != null) {
        params.add(new HttpParameter("media[]", mediaName, mediaBody));
        params.add(new HttpParameter("possibly_sensitive", possiblySensitive));
    }

    if (CollectionUtils.isNotEmpty(narrowcastPlaceIds)) {
        appendParameter("narrowcast_place_ids", Joiner.on(',').join(narrowcastPlaceIds), params);
    }

    if (StringUtils.isNotBlank(cardUri)) {
        params.add(new HttpParameter("card_uri", cardUri));
    }

    if (promotedOnly) {
        params.add(new HttpParameter("nullcast", true));
    }

    if (CollectionUtils.isNotEmpty(mediaIds)) {
        params.add(new HttpParameter("media_ids", Joiner.on(',').join(mediaIds)));
    }
    if (StringUtils.isNotBlank(videoId)) {
        params.add(new HttpParameter("video_id", videoId));
    }

    if (StringUtils.isNotBlank(attachmentUrl)) {
        params.add(new HttpParameter("attachment_url", attachmentUrl));
    }
    HttpParameter[] paramArray = new HttpParameter[params.size()];
    return params.toArray(paramArray);
}
 
Example #7
Source File: GoogleCredential.java    From google-api-java-client with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the space-separated OAuth scopes to use with the service account flow or
 * {@code null} if not using the service account flow.
 *
 * @since 1.15
 */
public final String getServiceAccountScopesAsString() {
  return serviceAccountScopes == null ? null : Joiner.on(' ').join(serviceAccountScopes);
}
 
Example #8
Source File: GoogleAccountCredential.java    From google-api-java-client with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs a new instance using OAuth 2.0 scopes.
 *
 * @param context context
 * @param scopes non empty OAuth 2.0 scope list
 * @return new instance
 *
 * @since 1.15
 */
public static GoogleAccountCredential usingOAuth2(Context context, Collection<String> scopes) {
  Preconditions.checkArgument(scopes != null && scopes.iterator().hasNext());
  String scopesStr = "oauth2: " + Joiner.on(' ').join(scopes);
  return new GoogleAccountCredential(context, scopesStr);
}
 
Example #9
Source File: TokenRequest.java    From google-oauth-java-client with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the list of scopes (as specified in <a
 * href="http://tools.ietf.org/html/rfc6749#section-3.3">Access Token Scope</a>) or {@code null}
 * for none.
 *
 * <p>
 * Overriding is only supported for the purpose of calling the super implementation and changing
 * the return type, but nothing else.
 * </p>
 *
 * @param scopes collection of scopes to be joined by a space separator (or a single value
 *        containing multiple space-separated scopes)
 * @since 1.15
 */
public TokenRequest setScopes(Collection<String> scopes) {
  this.scopes = scopes == null ? null : Joiner.on(' ').join(scopes);
  return this;
}
 
Example #10
Source File: AuthorizationRequestUrl.java    From google-oauth-java-client with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the <a href="http://tools.ietf.org/html/rfc6749#section-3.1.1">response type</a>, which
 * must be {@code "code"} for requesting an authorization code, {@code "token"} for requesting an
 * access token (implicit grant), or a list of registered extension values to join with a space.
 *
 * <p>
 * Overriding is only supported for the purpose of calling the super implementation and changing
 * the return type, but nothing else.
 * </p>
 *
 * @since 1.15
 */
public AuthorizationRequestUrl setResponseTypes(Collection<String> responseTypes) {
  this.responseTypes = Joiner.on(' ').join(responseTypes);
  return this;
}
 
Example #11
Source File: AuthorizationRequestUrl.java    From google-oauth-java-client with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the list of scopes (as specified in <a
 * href="http://tools.ietf.org/html/rfc6749#section-3.3">Access Token Scope</a>) or {@code null}
 * for none.
 *
 * <p>
 * Overriding is only supported for the purpose of calling the super implementation and changing
 * the return type, but nothing else.
 * </p>
 *
 * @param scopes collection of scopes to be joined by a space separator (or a single value
 *        containing multiple space-separated scopes) or {@code null} for none
 * @since 1.15
 */
public AuthorizationRequestUrl setScopes(Collection<String> scopes) {
  this.scopes =
      scopes == null || !scopes.iterator().hasNext() ? null : Joiner.on(' ').join(scopes);
  return this;
}
 
Example #12
Source File: AuthorizationCodeFlow.java    From google-oauth-java-client with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the space-separated list of scopes.
 *
 * @since 1.15
 */
public final String getScopesAsString() {
  return Joiner.on(' ').join(scopes);
}