ViewCalculationConfiguration calcConfig = viewDefinition.getCalculationConfiguration(calcConfigName);
final ValueMappings valueMappings = new ValueMappings(_compiledViewDef);
final ViewCalculationResultModel calculationResult = _viewComputationResultModel.getCalculationResult(calcConfigName);
final Map<String, Set<Pair<String, ValueProperties>>> portfolioRequirementsBySecurityType = calcConfig.getPortfolioRequirementsBySecurityType();
Portfolio portfolio = _compiledViewDef.getPortfolio();
PortfolioNodeTraverser traverser = new DepthFirstPortfolioNodeTraverser(new PortfolioNodeTraversalCallback() {
@Override
public void preOrderOperation(PortfolioNode parentNode, Position position) {
UniqueId positionId = position.getUniqueId().toLatest();
// then construct a chained target spec pointing at a specific position.
ComputationTargetSpecification breadcrumbTargetSpec = ComputationTargetSpecification.of(parentNode).containing(ComputationTargetType.POSITION, positionId);
ComputationTargetSpecification targetSpec = ComputationTargetSpecification.of(position);
Map<Pair<String, ValueProperties>, ComputedValueResult> values = calculationResult.getValues(targetSpec);
String securityType = position.getSecurity().getSecurityType();
Set<Pair<String, ValueProperties>> valueRequirements = portfolioRequirementsBySecurityType.get(securityType);
s_logger.error("Processing valueRequirement " + valueRequirements + " for security type " + securityType);
if (valueRequirements != null) {
for (Pair<String, ValueProperties> valueRequirement : valueRequirements) {
ColumnRequirementBySecurityType keyBySec = ColumnRequirementBySecurityType.of(securityType, ColumnRequirement.of(valueRequirement.getFirst(), valueRequirement.getSecond()));
ValueRequirement valueReq = new ValueRequirement(valueRequirement.getFirst(), breadcrumbTargetSpec, valueRequirement.getSecond());
ColumnRequirement key = ColumnRequirement.of(valueRequirement.getFirst(), valueRequirement.getSecond());
ValueSpecification valueSpec = valueMappings.getValueSpecification(calcConfigName, valueReq);
if (valueSpec == null) {
s_logger.error("Couldn't get reverse value spec mapping from requirement: " + valueReq.toString());
incCount(_failureCountBySec, keyBySec);
incCount(_failureCount, key);
_failures.increment();
} else {
ObjectsPair<String, ValueProperties> valueKey = Pair.of(valueSpec.getValueName(), valueSpec.getProperties());
ComputedValueResult computedValueResult = values != null ? values.get(valueKey) : null;
if (computedValueResult != null) {
if (computedValueResult.getValue() instanceof MissingValue) {
incCount(_errorCountBySec, keyBySec);
incCount(_errorCount, key);
_errors.increment();
} else {
incCount(_successCountBySec, keyBySec);
incCount(_successCount, key);
_successes.increment();
}
} else {
incCount(_failureCountBySec, keyBySec);
incCount(_failureCount, key);
_failures.increment();
}
}
incCount(_totalCountBySec, keyBySec);
incCount(_totalCount, key);
_total.increment();
}
}
}
@Override
public void preOrderOperation(PortfolioNode portfolioNode) {
}
@Override
public void postOrderOperation(PortfolioNode parentNode, Position position) {
}
@Override
public void postOrderOperation(PortfolioNode portfolioNode) {
}
private <T> void incCount(Map<T, MutableInt> countMap,
T key) {
if (!countMap.containsKey(key)) {
countMap.put(key, new MutableInt(1));
} else {
countMap.get(key).increment();
}
}
});
traverser.traverse(portfolio.getRootNode());
}
convertToJMXComposites();
} catch (NullPointerException npe) {
s_logger.error("NPE", npe);
}