if ((resolutionKeyConstraints == null) || resolutionKeyConstraints.isEmpty()) {
resolutionKey = null;
} else {
resolutionKey = resolutionKeyConstraints.iterator().next();
}
final HistoricalTimeSeriesResolutionResult resolutionResult = htsResolver.resolve(target.getSecurity().getExternalIdBundle(), null, null, null, dataField, resolutionKey);
if (resolutionResult == null) {
return null;
}
UniqueId htsId = resolutionResult.getHistoricalTimeSeriesInfo().getUniqueId();
final ValueProperties.Builder constraints = ValueProperties.builder();
final Set<String> ageLimitConstraints = desiredValue.getConstraints().getValues(HistoricalTimeSeriesFunctionUtils.AGE_LIMIT_PROPERTY);
if (ageLimitConstraints != null) {
if (ageLimitConstraints.isEmpty()) {
if (desiredValue.getConstraints().isOptional(HistoricalTimeSeriesFunctionUtils.AGE_LIMIT_PROPERTY)) {
constraints.withOptional(HistoricalTimeSeriesFunctionUtils.AGE_LIMIT_PROPERTY);
} else {
constraints.withAny(HistoricalTimeSeriesFunctionUtils.AGE_LIMIT_PROPERTY);
}
} else {
constraints.with(HistoricalTimeSeriesFunctionUtils.AGE_LIMIT_PROPERTY, ageLimitConstraints);
if (desiredValue.getConstraints().isOptional(HistoricalTimeSeriesFunctionUtils.AGE_LIMIT_PROPERTY)) {
constraints.withOptional(HistoricalTimeSeriesFunctionUtils.AGE_LIMIT_PROPERTY);
}
}
}
// Add adjuster / normalisation constraint
final HistoricalTimeSeriesAdjuster adjuster = resolutionResult.getAdjuster();
final String adjustment = (adjuster == null) ? "" : adjuster.getAdjustment(resolutionResult.getHistoricalTimeSeriesInfo().getExternalIdBundle().toBundle()).toString();
constraints.with(HistoricalTimeSeriesFunctionUtils.ADJUST_PROPERTY, adjustment);
ValueRequirement valueRequirement = new ValueRequirement(ValueRequirementNames.HISTORICAL_TIME_SERIES_LATEST, ComputationTargetType.PRIMITIVE, htsId, constraints.get());
return Collections.singleton(valueRequirement);
}