Java Code Examples for com.google.api.client.util.Strings

The following examples show how to use com.google.api.client.util.Strings. These examples are extracted from open source projects. 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 Project: endpoints-java   Source File: ApiConfigValidator.java    License: Apache License 2.0 6 votes vote down vote up
private static String checkIssuerAudiences(
    ApiIssuerConfigs issuerConfigs, ApiIssuerAudienceConfig issuerAudiences) {
  if (!issuerAudiences.isEmpty()) {
    return null;
  }
  for (Map.Entry<String, Collection<String>> entry : issuerAudiences.asMap().entrySet()) {
    if (!issuerConfigs.hasIssuer(entry.getKey())) {
      return "cannot specify audiences for unknown issuer '" + entry.getKey() + "'";
    }
    for (String audience : entry.getValue()) {
      if (Strings.isNullOrEmpty(audience)) {
        return "issuer '" + entry.getKey() + "' cannot have null or blank audiences";
      }
    }
  }
  return null;
}
 
Example 2
Source Project: dataflow-java   Source File: AnnotateVariants.java    License: Apache License 2.0 6 votes vote down vote up
private String retrieveReferenceBases(Genomics genomics, Annotation annotation) throws IOException {
  StringBuilder b = new StringBuilder();
  String pageToken = "";
  while (true) {
    // TODO: Support full request parameterization for Paginator.References.Bases.
    ListBasesResponse response = genomics.references().bases()
        .list(annotation.getReferenceId())
        .setStart(annotation.getStart())
        .setEnd(annotation.getEnd())
        .setPageToken(pageToken)
        .execute();
    b.append(response.getSequence());
    pageToken = response.getNextPageToken();
    if (Strings.isNullOrEmpty(pageToken)) {
      break;
    }
  }
  return b.toString();
}
 
Example 3
/**
 * @param builder builder
 *
 * @since 1.14
 */
protected AbstractGoogleClient(Builder builder) {
  googleClientRequestInitializer = builder.googleClientRequestInitializer;
  rootUrl = normalizeRootUrl(builder.rootUrl);
  servicePath = normalizeServicePath(builder.servicePath);
  batchPath = builder.batchPath;
  if (Strings.isNullOrEmpty(builder.applicationName)) {
    logger.warning("Application name is not set. Call Builder#setApplicationName.");
  }
  applicationName = builder.applicationName;
  requestFactory = builder.httpRequestInitializer == null
      ? builder.transport.createRequestFactory()
      : builder.transport.createRequestFactory(builder.httpRequestInitializer);
  objectParser = builder.objectParser;
  suppressPatternChecks = builder.suppressPatternChecks;
  suppressRequiredParameterChecks = builder.suppressRequiredParameterChecks;
}
 
Example 4
Source Project: firebase-admin-java   Source File: MulticastMessage.java    License: Apache License 2.0 5 votes vote down vote up
private MulticastMessage(Builder builder) {
  this.tokens = builder.tokens.build();
  checkArgument(!this.tokens.isEmpty(), "at least one token must be specified");
  checkArgument(this.tokens.size() <= 500, "no more than 500 tokens can be specified");
  for (String token : this.tokens) {
    checkArgument(!Strings.isNullOrEmpty(token), "none of the tokens can be null or empty");
  }
  this.data = builder.data.isEmpty() ? null : ImmutableMap.copyOf(builder.data);
  this.notification = builder.notification;
  this.androidConfig = builder.androidConfig;
  this.webpushConfig = builder.webpushConfig;
  this.apnsConfig = builder.apnsConfig;
  this.fcmOptions = builder.fcmOptions;
}
 
Example 5
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) {
	final String authToken = request.getHeader(TOKEN_HEADER);
	if (Strings.isNullOrEmpty(authToken)) {
		throw new RuntimeException("Invaild auth token");
	}

	return getAuthenticationManager().authenticate(new FirebaseAuthenticationToken(authToken));
}
 
Example 6
Source Project: endpoints-java   Source File: ApiConfigValidator.java    License: Apache License 2.0 5 votes vote down vote up
private static String checkIssuers(ApiIssuerConfigs issuers) {
  if (!issuers.isSpecified()) {
    return null;
  }
  for (IssuerConfig issuer : issuers.asMap().values()) {
    if (Strings.isNullOrEmpty(issuer.getName())) {
      return "issuer name cannot be blank";
    } else if (Strings.isNullOrEmpty(issuer.getIssuer())) {
      return "issuer '" + issuer.getName() + "' cannot have a blank issuer value";
    }
  }
  return null;
}
 
Example 7
Source Project: dataflow-java   Source File: CalculateCoverage.java    License: Apache License 2.0 5 votes vote down vote up
@ProcessElement
public void processElement(DoFn<String, String>.ProcessContext c) throws Exception {
  String readGroupSetId = c.element();
  String referenceSetId = GenomicsUtils.getReferenceSetId(readGroupSetId, auth);
  if (Strings.isNullOrEmpty(referenceSetId)) {
    throw new IllegalArgumentException("No ReferenceSetId associated with ReadGroupSetId "
        + readGroupSetId
        + ". All ReadGroupSets in given input must have an associated ReferenceSet.");
  }
  if (!referenceSetIdForAllReadGroupSets.equals(referenceSetId)) {
    throw new IllegalArgumentException("ReadGroupSets in given input must all be associated with"
        + " the same ReferenceSetId : " + referenceSetId);
  }
  c.output(readGroupSetId);
}
 
Example 8
Source Project: dataflow-java   Source File: VerifyBamId.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Run the VerifyBamId algorithm and output the resulting contamination estimate.
 */
public static void main(String[] args) throws GeneralSecurityException, IOException {
  // Register the options so that they show up via --help
  PipelineOptionsFactory.register(Options.class);
  pipelineOptions = PipelineOptionsFactory.fromArgs(args)
      .withValidation().as(Options.class);
  // Option validation is not yet automatic, we make an explicit call here.
  Options.Methods.validateOptions(pipelineOptions);

  // Set up the prototype request and auth.
  StreamVariantsRequest.Builder request = StreamVariantsRequest.newBuilder()
      .setVariantSetId(pipelineOptions.getVariantSetId());
  if (null != pipelineOptions.getProject()) {
    request.setProjectId(pipelineOptions.getProject());
  }
  StreamVariantsRequest prototype = request.build();
  auth = GenomicsOptions.Methods.getGenomicsAuth(pipelineOptions);

  p = Pipeline.create(pipelineOptions);
  registerPipelineCoders(p);

  if (pipelineOptions.getInputDatasetId().isEmpty() && pipelineOptions.getReadGroupSetIds().isEmpty()) {
    throw new IllegalArgumentException("InputDatasetId or ReadGroupSetIds must be specified");
  }

  List<String> rgsIds;
  if (pipelineOptions.getInputDatasetId().isEmpty()) {
    rgsIds = Lists.newArrayList(pipelineOptions.getReadGroupSetIds().split(","));
  } else {
    rgsIds = GenomicsUtils.getReadGroupSetIds(pipelineOptions.getInputDatasetId(), auth);
  }

  // Grab one ReferenceSetId to be used within the pipeline to confirm that all ReadGroupSets
  // are associated with the same ReferenceSet.
  String referenceSetId = GenomicsUtils.getReferenceSetId(rgsIds.get(0), auth);
  if (Strings.isNullOrEmpty(referenceSetId)) {
    throw new IllegalArgumentException("No ReferenceSetId associated with ReadGroupSetId "
        + rgsIds.get(0)
        + ". All ReadGroupSets in given input must have an associated ReferenceSet.");
  }

  // TODO: confirm that variant set also corresponds to the same reference
  // https://github.com/googlegenomics/api-client-java/issues/66

  // Reads in Reads.
  PCollection<Read> reads = p.begin()
      .apply(Create.of(rgsIds))
      .apply(ParDo.of(new CheckMatchingReferenceSet(referenceSetId, auth)))
      .apply(new ReadGroupStreamer(auth, ShardBoundary.Requirement.STRICT, null,
                                   SexChromosomeFilter.INCLUDE_XY));

  /*
  TODO:  We can reduce the number of requests needed to be created by doing the following:
  1. Stream the Variants first (rather than concurrently with the Reads).  Select a subset of
     them equal to some threshold (say 50K by default).
  2. Create the requests for streaming Reads by running a ParDo over the selected Variants
     to get their ranges (we only need to stream Reads that overlap the selected Variants).
  3. Stream the Reads from the created requests.
  */

  // Reads in Variants. TODO potentially provide an option to load the Variants from a file.
  List<StreamVariantsRequest> variantRequests = pipelineOptions.isAllReferences() ?
      ShardUtils.getVariantRequests(prototype, ShardUtils.SexChromosomeFilter.INCLUDE_XY,
          pipelineOptions.getBasesPerShard(), auth) :
      ShardUtils.getVariantRequests(prototype, pipelineOptions.getBasesPerShard(), pipelineOptions.getReferences());

  PCollection<Variant> variants = p.apply(Create.of(variantRequests))
      .apply(new VariantStreamer(auth, ShardBoundary.Requirement.STRICT, VARIANT_FIELDS));

  PCollection<KV<Position, AlleleFreq>> refFreq = getFreq(variants, pipelineOptions.getMinFrequency());

  PCollection<KV<Position, ReadCounts>> readCountsTable =
      combineReads(reads, pipelineOptions.getSamplingFraction(), HASH_PREFIX, refFreq);

  // Converts our results to a single Map of Position keys to ReadCounts values.
  PCollectionView<Map<Position, ReadCounts>> view = readCountsTable
      .apply(View.<Position, ReadCounts>asMap());

  // Calculates the contamination estimate based on the resulting Map above.
  PCollection<String> result = p.begin()
      .apply(Create.of(""))
      .apply(ParDo.of(new Maximizer(view)).withSideInputs(view));

  // Writes the result to the given output location in Cloud Storage.
  result.apply("WriteOutput", TextIO.write().to(pipelineOptions.getOutput()).withoutSharding());

  p.run();
}
 
Example 9
Source Project: dataflow-java   Source File: CalculateCoverage.java    License: Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws GeneralSecurityException, IOException, URISyntaxException {
  // Register the options so that they show up via --help
  PipelineOptionsFactory.register(Options.class);
  options = PipelineOptionsFactory.fromArgs(args).withValidation().as(Options.class);

  auth = GenomicsOptions.Methods.getGenomicsAuth(options);

  p = Pipeline.create(options);
  registerPipelineCoders(p);

  if (options.getBamInput().isEmpty() && options.getInputDatasetId().isEmpty() && options.getReadGroupSetIds().isEmpty()) {
    throw new IllegalArgumentException("BamInput or InputDatasetId or ReadGroupSetIds must be specified");
  }

  PCollection<Read> reads = null;
  String referenceSetId = options.getReferenceSetId();

  if (!options.getBamInput().isEmpty()) {

    if (options.isAllReferences()) {
      throw new IllegalArgumentException("--allReferences is not currently supported for BAM "
      + "file reading. Instead use --references and list all of the genomic regions in the file.");
    }

    final List<Contig> contigs = Lists.newArrayList(Contig.parseContigsFromCommandLine(options.getReferences()));
    final ReaderOptions readerOptions = new ReaderOptions(
        ValidationStringency.LENIENT,
        false);  // Do not include unmapped reads.

    ShardingPolicy policy = new ShardingPolicy() {
      final int MAX_BYTES_PER_SHARD = options.getMaxShardSizeBytes();
      @Override
      public Boolean apply(BAMShard shard) {
        return shard.approximateSizeInBytes() > MAX_BYTES_PER_SHARD;
      }
    };

    reads = ReadBAMTransform.getReadsFromBAMFilesSharded (
        p,
        options,
        auth,
        contigs,
        readerOptions,
        options.getBamInput(),
        policy);

  } else {

    List<String> rgsIds;
    if (options.getInputDatasetId().isEmpty()) {
      rgsIds = Lists.newArrayList(options.getReadGroupSetIds().split(","));
    } else {
      rgsIds = GenomicsUtils.getReadGroupSetIds(options.getInputDatasetId(), auth);
    }

    if (rgsIds.size() < options.getNumQuantiles()) {
      throw new IllegalArgumentException("Number of ReadGroupSets must be greater than or equal to"
          + " the number of requested quantiles.");
    }

    // Grab one ReferenceSetId to be used within the pipeline to confirm that all ReadGroupSets
    // are associated with the same ReferenceSet.
    referenceSetId = GenomicsUtils.getReferenceSetId(rgsIds.get(0), auth);
    if (Strings.isNullOrEmpty(referenceSetId)) {
      throw new IllegalArgumentException("No ReferenceSetId associated with ReadGroupSetId "
          + rgsIds.get(0)
          + ". All ReadGroupSets in given input must have an associated ReferenceSet.");
    }

    reads = p.begin()
        .apply(Create.of(rgsIds))
        .apply(ParDo.of(new CheckMatchingReferenceSet(referenceSetId, auth)))
        .apply(new ReadGroupStreamer(auth, ShardBoundary.Requirement.STRICT, READ_FIELDS, SexChromosomeFilter.INCLUDE_XY));
  }

  // Create our destination AnnotationSet for the associated ReferenceSet.
  AnnotationSet annotationSet = createAnnotationSet(referenceSetId);

  PCollection<KV<PosRgsMq, Double>> coverageMeans = reads.apply("CalculateCoverateMean",
      new CalculateCoverageMean(options.getBucketWidth()));
  PCollection<KV<Position, KV<PosRgsMq.MappingQuality, List<Double>>>> quantiles
      = coverageMeans.apply("CalculateQuantiles", new CalculateQuantiles(options.getNumQuantiles()));
  PCollection<KV<Position, Iterable<KV<PosRgsMq.MappingQuality, List<Double>>>>> answer =
      quantiles.apply(GroupByKey.<Position, KV<PosRgsMq.MappingQuality, List<Double>>>create());
  answer.apply("CreateAnnotations", ParDo.of(new CreateAnnotations(annotationSet.getId(), auth, true)));

  p.run();
}