public void handle()

in api-reference-examples/java/te-tag-query/com/facebook/threatexchange/TETagQuery.java [528:643]


    public void handle(
      String[] args,
      int numIDsPerQuery,
      boolean verbose,
      boolean showURLs,
      DescriptorFormatter descriptorFormatter
    ) {
      IndicatorTypeFilterer indicatorTypeFilterer = IndicatorTypeFilterer.createAllFilterer();
      int pageSize = 1000;
      String taggedSince = null;
      String taggedUntil = null;
      boolean includeIndicatorInOutput = true;
      String dataDir = null;

      while (args.length > 0 && args[0].startsWith("-")) {
        String option = args[0];
        args = Arrays.copyOfRange(args, 1, args.length);

        if (option.equals("-h") || option.equals("--help")) {
          usage(0);

        } else if (option.equals("--list")) {
          IndicatorTypeFilterer.list(System.out);
          System.exit(0);
        } else if (option.equals("--data-dir")) {
          if (args.length < 1) {
            usage(1);
          }
          dataDir = args[0];
          args = Arrays.copyOfRange(args, 1, args.length);

        } else if (option.equals("--tagged-since")) {
          if (args.length < 1) {
            usage(1);
          }
          taggedSince = args[0];
          args = Arrays.copyOfRange(args, 1, args.length);

        } else if (option.equals("--tagged-until")) {
          if (args.length < 1) {
            usage(1);
          }
          taggedUntil = args[0];
          args = Arrays.copyOfRange(args, 1, args.length);

        } else if (option.equals("--page-size")) {
          if (args.length < 1) {
            usage(1);
          }
          pageSize = Integer.valueOf(args[0]);
          args = Arrays.copyOfRange(args, 1, args.length);

        } else if (option.equals("--indicator-type")) {
          if (args.length < 1) {
            usage(1);
          }

          indicatorTypeFilterer = IndicatorTypeFilterer.create(args[0]);
          if (indicatorTypeFilterer == null) {
            System.err.printf("%s %s: unrecognized indicator-type filter \"%s\".\n",
              PROGNAME, _verb, args[0]);
            usage(1);
          }

          args = Arrays.copyOfRange(args, 1, args.length);

        } else if (option.equals("--no-print-indicator")) {
          includeIndicatorInOutput = false;

        } else {
          System.err.printf("%s %s: unrecognized option \"%s\".\n",
            PROGNAME, _verb, option);
          usage(1);
        }
      }

      if (args.length != 1) {
        usage(1);
      }
      String tagName = args[0];

      if (dataDir != null) {
        File handle = new File(dataDir);
        boolean ok = handle.exists() || handle.mkdirs();
        if (!ok) {
          System.err.printf("%s: could not create output directory \"%s\"\n",
            PROGNAME, dataDir);
          System.exit(1);
        }
      }

      String tagID = Net.getTagIDFromName(tagName, showURLs);
      if (tagID == null) {
        System.err.printf("%s: could not find tag by name \"%s\".\n",
          PROGNAME, tagName);
        System.exit(1);
      }
      if (verbose) {
        SimpleJSONWriter w = new SimpleJSONWriter();
        w.add("tag_name", tagName);
        w.add("tag_id", tagID);
        System.out.println(w.format());
        System.out.flush();
      }

      // Returns IDs for all descriptors. The return from this bulk-query call
      // gives back only ID code, indicator text, and the uninformative label
      // "THREAT_DESCRIPTOR". From this we can dive in on each item, though,
      // and query for its details one ID at a time.
      IDProcessor processor = new IDDetailsProcessor(numIDsPerQuery, verbose,
        showURLs, indicatorTypeFilterer, includeIndicatorInOutput,
        dataDir, descriptorFormatter);
      Net.getDescriptorIDsByTagID(tagID, verbose, showURLs,
        taggedSince, taggedUntil, pageSize, includeIndicatorInOutput,
        processor);
    }