ComputationTargetSpecification nodeSpec = null;
// [PLAT-2286] This is a hack to almost support trivial nesting, e.g. for the PositionWeight function. Recognition of complex target types needs doing properly.
final ComputationTargetSpecification[] targets = getPortfolioGrid().getGridStructure().getTargets();
for (int i = 0; i < targets.length; i++) {
final ComputationTargetSpecification target = targets[i];
ViewTargetResultModel targetResult = resultModel.getTargetResult(target);
if (target.getType().isTargetType(ComputationTargetType.PORTFOLIO_NODE)) {
nodeSpec = target;
} else if ((nodeSpec != null) && target.getType().isTargetType(ComputationTargetType.POSITION)) {
final ViewTargetResultModel scopedResult = resultModel.getTargetResult(nodeSpec.containing(ComputationTargetType.POSITION, target.getUniqueId()));
if (scopedResult != null) {
if (targetResult != null) {
final Map<String, Collection<ComputedValueResult>> newResult = new HashMap<String, Collection<ComputedValueResult>>();
for (final String calcConfig : targetResult.getCalculationConfigurationNames()) {
newResult.put(calcConfig, new ArrayList<ComputedValueResult>(targetResult.getAllValues(calcConfig)));
}
for (final String calcConfig : scopedResult.getCalculationConfigurationNames()) {
final Collection<ComputedValueResult> scopedValues = scopedResult.getAllValues(calcConfig);
Collection<ComputedValueResult> values = newResult.get(calcConfig);
if (values == null) {
values = new ArrayList<ComputedValueResult>(scopedValues.size());
newResult.put(calcConfig, values);
}
for (final ComputedValueResult value : scopedValues) {
values.add(new ComputedValueResult(new ValueSpecification(value.getSpecification().getValueName(), target, value.getSpecification().getProperties()), value.getValue(), value
.getAggregatedExecutionLog()));
}
}
targetResult = new ViewTargetResultModel() {
@Override
public Collection<String> getCalculationConfigurationNames() {
return newResult.keySet();
}