/**
 * Copyright (C) 2013 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.engine.marketdata.manipulator;

import com.opengamma.engine.value.ValueSpecification;
import com.opengamma.id.ExternalId;

/**
 * Extracts the structure id for a market data point from a value specification.
 */
public class MarketDataPointNodeExtractor extends NodeExtractor<ExternalId> {

  /**
   * Constructs an market data point extractor.
   */
  public MarketDataPointNodeExtractor() {
    super("Market_Value");
  }

  /**
   * Gets the structured key from the passed value specification. The specification will previously have
   * been matched against the configured specification name so can be assumed to be of the correct type.
   *
   * @param spec the specification to construct a key for, not null
   * @return a structured key for the structure handled by the value spec.
   */
  @Override
  public StructureIdentifier<ExternalId> getStructuredIdentifier(ValueSpecification spec) {
    return StructureIdentifier.of(ExternalId.parse(spec.getProperty("Id")));
  }
}

@@ -185,16 +185,76 @@
 lator;%0A%0A
+import com.opengamma.core.value.MarketDataRequirementNames;%0A
 import c
@@ -299,16 +299,16 @@
 cation;%0A
-
 import c
@@ -334,16 +334,50 @@
 ernalId;
+%0Aimport com.opengamma.id.UniqueId;
 %0A%0A/**%0A *
@@ -654,22 +654,47 @@
 per(
-%22
 Market
-_Value%22
+DataRequirementNames.MARKET_VALUE
 );%0A 
@@ -1167,24 +1167,68 @@
 ion spec) %7B%0A
+    if (spec.getProperty(%22Id%22) != null) %7B%0A  
     return S
@@ -1292,14 +1292,413 @@
 Id%22)));%0A
+    %7D else %7B%0A      // Id may not always be present - maybe with snapshots? (get External from UniqueId)%0A      UniqueId uniqueId = spec.getTargetSpecification().getUniqueId();%0A      String scheme = uniqueId.getScheme();%0A      if (scheme.startsWith(%22ExternalId-%22)) %7B%0A        scheme = scheme.substring(11);%0A      %7D%0A      return StructureIdentifier.of(ExternalId.of(scheme, uniqueId.getValue()));%0A    %7D%0A
   %7D%0A%7D%0A

Make market data point shifts work with snapshots