<commit_before>/**
 * Copyright (C) 2012 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.integration.tool.marketdata;

import java.util.Arrays;
import java.util.List;

import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.opengamma.component.tool.AbstractComponentTool;
import com.opengamma.core.marketdatasnapshot.StructuredMarketDataSnapshot;
import com.opengamma.id.UniqueId;
import com.opengamma.master.marketdatasnapshot.MarketDataSnapshotMaster;
import com.opengamma.scripts.Scriptable;

/** The entry point for running OpenGamma batches. */
@Scriptable
public class MarketDataSnapshotExportTool extends AbstractComponentTool {

  /** Logger. */
  private static final Logger s_logger = LoggerFactory.getLogger(MarketDataSnapshotExportTool.class);

  /** File name option flag */
  private static final String FILE_NAME_OPT = "f";
  /** Snapshot uid option flag */
  private static final String SNAPSHOT_UID_OPTION = "uid";

  private static final List<String> DEFAULT_PREFERRED_CLASSIFIERS = Arrays.asList("central",
                                                                                  "main",
                                                                                  "default",
                                                                                  "shared",
                                                                                  "combined");

  //-------------------------------------------------------------------------

  /**
   * Main method to run the tool. No arguments are needed.
   *
   * @param args the arguments, unused
   */
  public static void main(final String[] args) { // CSIGNORE
    final boolean success = new MarketDataSnapshotExportTool().initAndRun(args);
    System.exit(success ? 0 : 1);
  }

  @Override
  protected void doRun() throws Exception {
    final MarketDataSnapshotMaster marketDataSnapshotMaster = getRemoteComponentFactory().getMarketDataSnapshotMaster(
        DEFAULT_PREFERRED_CLASSIFIERS);
    if (marketDataSnapshotMaster == null) {
      s_logger.warn("No market data snapshot masters found at {}", getRemoteComponentFactory().getBaseUri());
      return;
    }

    StructuredMarketDataSnapshot snapshot = marketDataSnapshotMaster.get(UniqueId.of("bla", "bla")).getSnapshot();

    snapshot.getBasisViewName();
    snapshot.getCurves();
    snapshot.getGlobalValues();
    snapshot.getName();
    snapshot.getVolatilitySurfaces();
    snapshot.getYieldCurves();


  }

  //-------------------------------------------------------------------------
  @Override
  protected Options createOptions() {
    final Options options = super.createOptions();
    options.addOption(createSnapshotUidOption());
    options.addOption(createFilenameOption());
    return options;
  }

  private static Option createFilenameOption() {
    final Option filenameOption = new Option(FILE_NAME_OPT,
                                             "filename",
                                             true,
                                             "The path to the file to create and export to (CSV, XLS or ZIP)");
    filenameOption.setRequired(true);
    return filenameOption;
  }

  private static Option createSnapshotUidOption() {
    final Option option = new Option(SNAPSHOT_UID_OPTION, "snapshotUid", true, "the snapshot unique identifier");
    option.setArgName("snapshot uid");
    option.setRequired(true);
    return option;
  }

}
<commit_msg>[PLAT-3804] Tool taking uid of snapshot and retrieving from master<commit_after>/**
 * Copyright (C) 2012 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.integration.tool.marketdata;

import java.util.Map;

import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.opengamma.component.tool.AbstractTool;
import com.opengamma.core.marketdatasnapshot.CurveKey;
import com.opengamma.core.marketdatasnapshot.CurveSnapshot;
import com.opengamma.core.marketdatasnapshot.StructuredMarketDataSnapshot;
import com.opengamma.core.marketdatasnapshot.UnstructuredMarketDataSnapshot;
import com.opengamma.core.marketdatasnapshot.VolatilitySurfaceKey;
import com.opengamma.core.marketdatasnapshot.VolatilitySurfaceSnapshot;
import com.opengamma.core.marketdatasnapshot.YieldCurveKey;
import com.opengamma.core.marketdatasnapshot.YieldCurveSnapshot;
import com.opengamma.financial.tool.ToolContext;
import com.opengamma.id.UniqueId;
import com.opengamma.master.marketdatasnapshot.MarketDataSnapshotMaster;
import com.opengamma.scripts.Scriptable;

/** The entry point for running OpenGamma batches. */
@Scriptable
public class MarketDataSnapshotExportTool extends AbstractTool<ToolContext> {

  /** Logger. */
  private static final Logger s_logger = LoggerFactory.getLogger(MarketDataSnapshotExportTool.class);

  /** File name option flag */
  private static final String FILE_NAME_OPT = "f";
  /** Snapshot uid option flag */
  private static final String SNAPSHOT_UID_OPTION = "uid";

  //-------------------------------------------------------------------------

  /**
   * Main method to run the tool. No arguments are needed.
   *
   * @param args the arguments, no null
   */
  public static void main(final String[] args) { // CSIGNORE
    final boolean success = new MarketDataSnapshotExportTool().initAndRun(args, ToolContext.class);
    System.exit(success ? 0 : 1);
  }

  @Override
  protected void doRun() throws Exception {
    final MarketDataSnapshotMaster marketDataSnapshotMaster = getToolContext().getMarketDataSnapshotMaster();
    if (marketDataSnapshotMaster == null) {
      s_logger.warn("No market data snapshot masters found at {}", getToolContext());
      return;
    }

    StructuredMarketDataSnapshot snapshot;
    snapshot = marketDataSnapshotMaster.get(UniqueId.parse(getCommandLine().getOptionValue(SNAPSHOT_UID_OPTION))).getSnapshot();


    String name= snapshot.getName();
    String basisViewName  = snapshot.getBasisViewName();
    UnstructuredMarketDataSnapshot globalValues = snapshot.getGlobalValues();;
    Map<YieldCurveKey, YieldCurveSnapshot> yieldCurves = snapshot.getYieldCurves();;
    Map<CurveKey, CurveSnapshot> curves = snapshot.getCurves();;
    Map<VolatilitySurfaceKey, VolatilitySurfaceSnapshot> volatilitySurfaces = snapshot.getVolatilitySurfaces();;


  }

  //-------------------------------------------------------------------------
  @Override
  protected Options createOptions(boolean mandatoryConfig) {
    final Options options = super.createOptions(mandatoryConfig);
    options.addOption(createSnapshotUidOption());
    options.addOption(createFilenameOption());
    return options;
  }

  private static Option createFilenameOption() {
    final Option filenameOption = new Option(FILE_NAME_OPT,
                                             "filename",
                                             true,
                                             "The path to the file to create and export to (CSV, XLS or ZIP)");
    filenameOption.setRequired(true);
    return filenameOption;
  }

  private static Option createSnapshotUidOption() {
    final Option option = new Option(SNAPSHOT_UID_OPTION, "snapshotUid", true, "the snapshot unique identifier");
    option.setArgName("snapshot uid");
    option.setRequired(true);
    return option;
  }

}

{'fraction_non_alphanumeric': 0.12483539636555176, 'fraction_numerical': 0.002633658151171978, 'mean_word_length': 2.735858337432366, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7493694', 'n_tokens_mistral': 1948, 'n_tokens_neox': 1899, 'n_words': 462}