<commit_before>/**
 * Copyright (C) 2013 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */

package com.opengamma.master.historicaltimeseries.impl;

import com.opengamma.core.historicaltimeseries.HistoricalTimeSeriesSource;
import com.opengamma.core.value.MarketDataRequirementNames;
import com.opengamma.id.ExternalId;
import com.opengamma.id.ExternalIdBundle;
import com.opengamma.id.ExternalIdBundleWithDates;
import com.opengamma.id.ObjectId;
import com.opengamma.id.UniqueId;
import com.opengamma.master.historicaltimeseries.HistoricalTimeSeriesResolutionResult;
import com.opengamma.master.historicaltimeseries.HistoricalTimeSeriesResolver;
import com.opengamma.master.historicaltimeseries.ManageableHistoricalTimeSeriesInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.threeten.bp.LocalDate;

public class RedisSimulationSeriesResolver implements HistoricalTimeSeriesResolver {

  private static final Logger s_logger = LoggerFactory.getLogger(RedisSimulationSeriesResolver.class);
  private final HistoricalTimeSeriesSource _source;

  public RedisSimulationSeriesResolver(HistoricalTimeSeriesSource source) {
    _source = source;
  }

  @Override
  public HistoricalTimeSeriesResolutionResult resolve(ExternalIdBundle identifierBundle, LocalDate identifierValidityDate, String dataSource, String dataProvider, String dataField,
                                                      String resolutionKey) {
    if (identifierBundle.isEmpty()) {
      return null; // is this the correct action?
    } else if (identifierBundle.size() > 1) {
      s_logger.warn("Attempted to call RedisSimulationSeriesSource with bundle {}. Calls with more than 1 entry in ID bundle are probably misuse of this class.", identifierBundle);
    }
    ExternalId externalId = identifierBundle.getExternalIds().iterator().next();
    final UniqueId uniqueId = UniqueId.of(externalId.getScheme().getName(), externalId.getValue());
    //TODO: This should just be an existence check
    if (_source.getHistoricalTimeSeries(uniqueId, null, true, null, true) == null) {
      return null; // check timeseries actually exists
    }
    if (MarketDataRequirementNames.MARKET_VALUE != dataField) {
      s_logger.warn("Redis simulation returning ts of {} for {}, this may cause this series to be used in the wrong place in calculations", dataField, externalId);
    }
    ManageableHistoricalTimeSeriesInfo htsInfo = new ManageableHistoricalTimeSeriesInfo() {
      @Override
      public UniqueId getUniqueId() {
        return uniqueId;
      }

      @Override
      public ExternalIdBundleWithDates getExternalIdBundle() {
        throw new UnsupportedOperationException("Unsupported operation.");
      }

      @Override
      public String getName() {
        throw new UnsupportedOperationException("Unsupported operation.");
      }

      @Override
      public String getDataField() {
        throw new UnsupportedOperationException("Unsupported operation.");
      }

      @Override
      public String getDataSource() {
        throw new UnsupportedOperationException("Unsupported operation.");
      }

      @Override
      public String getDataProvider() {
        throw new UnsupportedOperationException("Unsupported operation.");
      }

      @Override
      public String getObservationTime() {
        throw new UnsupportedOperationException("Unsupported operation.");
      }

      @Override
      public ObjectId getTimeSeriesObjectId() {
        throw new UnsupportedOperationException("Unsupported operation.");
      }

    };
    HistoricalTimeSeriesResolutionResult result = new HistoricalTimeSeriesResolutionResult(htsInfo);
    return result;
  }
}
<commit_msg>Redis sim source changes to interface and error handling<commit_after>/**
 * Copyright (C) 2013 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */

package com.opengamma.master.historicaltimeseries.impl;

import com.opengamma.core.historicaltimeseries.HistoricalTimeSeriesSource;
import com.opengamma.core.value.MarketDataRequirementNames;
import com.opengamma.id.ExternalId;
import com.opengamma.id.ExternalIdBundle;
import com.opengamma.id.ExternalIdBundleWithDates;
import com.opengamma.id.ObjectId;
import com.opengamma.id.UniqueId;
import com.opengamma.master.historicaltimeseries.HistoricalTimeSeriesResolutionResult;
import com.opengamma.master.historicaltimeseries.HistoricalTimeSeriesResolver;
import com.opengamma.master.historicaltimeseries.ManageableHistoricalTimeSeriesInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.threeten.bp.LocalDate;

public class RedisSimulationSeriesResolver implements HistoricalTimeSeriesResolver {

  private static final Logger s_logger = LoggerFactory.getLogger(RedisSimulationSeriesResolver.class);
  private final HistoricalTimeSeriesSource _source;

  public RedisSimulationSeriesResolver(HistoricalTimeSeriesSource source) {
    _source = source;
  }

  @Override
  public HistoricalTimeSeriesResolutionResult resolve(ExternalIdBundle identifierBundle, LocalDate identifierValidityDate, String dataSource, String dataProvider, String dataField,
                                                      String resolutionKey) {
    if (identifierBundle.isEmpty()) {
      return null; // is this the correct action?
    } else if (identifierBundle.size() > 1) {
      s_logger.warn("Attempted to call RedisSimulationSeriesSource with bundle {}. Calls with more than 1 entry in ID bundle are probably misuse of this class.", identifierBundle);
    }
    ExternalId externalId = identifierBundle.getExternalIds().iterator().next();
    final UniqueId uniqueId = UniqueId.of(externalId.getScheme().getName(), externalId.getValue());
    //TODO: This should just be an existence check
    if (_source.getHistoricalTimeSeries(uniqueId, null, true, null, true) == null) {
      return null; // check timeseries actually exists
    }
    if (MarketDataRequirementNames.MARKET_VALUE != dataField) {
      s_logger.warn("Redis simulation asked for {} for {}, can only handle market value.", dataField, externalId);
      return null;
    }
    ManageableHistoricalTimeSeriesInfo htsInfo = new ManageableHistoricalTimeSeriesInfo() {
      @Override
      public UniqueId getUniqueId() {
        return uniqueId;
      }

      @Override
      public ExternalIdBundleWithDates getExternalIdBundle() {
        throw new UnsupportedOperationException("Unsupported operation.");
      }

      @Override
      public String getName() {
        throw new UnsupportedOperationException("Unsupported operation.");
      }

      @Override
      public String getDataField() {
        throw new UnsupportedOperationException("Unsupported operation.");
      }

      @Override
      public String getDataSource() {
        throw new UnsupportedOperationException("Unsupported operation.");
      }

      @Override
      public String getDataProvider() {
        throw new UnsupportedOperationException("Unsupported operation.");
      }

      @Override
      public String getObservationTime() {
        throw new UnsupportedOperationException("Unsupported operation.");
      }

      @Override
      public ObjectId getTimeSeriesObjectId() {
        throw new UnsupportedOperationException("Unsupported operation.");
      }

    };
    HistoricalTimeSeriesResolutionResult result = new HistoricalTimeSeriesResolutionResult(htsInfo);
    return result;
  }
}

{'fraction_non_alphanumeric': 0.07723954877239549, 'fraction_numerical': 0.00212342402123424, 'mean_word_length': 3.977542932628798, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3234731', 'n_tokens_mistral': 1953, 'n_tokens_neox': 1890, 'n_words': 486}