final FudgeField portfolioIdField = message.getByName(PORTFOLIO_ID_FIELD);
final UniqueId portfolioId = portfolioIdField == null ? null : deserializer.fieldValueToObject(UniqueId.class, portfolioIdField);
final String name = message.getFieldValue(String.class, message.getByName(NAME_FIELD));
final UserPrincipal user = deserializer.fieldValueToObject(UserPrincipal.class, message.getByName(USER_FIELD));
final ResultModelDefinition model = deserializer.fieldValueToObject(ResultModelDefinition.class, message.getByName(RESULT_MODEL_DEFINITION_FIELD));
ViewDefinition viewDefinition = new ViewDefinition(
name,
portfolioId,
user,
model);
// FudgeField currencyField = message.getByName(CURRENCY_FIELD);
// if (currencyField != null) {
// viewDefinition.setDefaultCurrency(context.fieldValueToObject(Currency.class, currencyField));
// }
if (message.hasField(CURRENCY_FIELD)) {
String isoCode = message.getString(CURRENCY_FIELD);
viewDefinition.setDefaultCurrency(Currency.of(isoCode));
}
if (message.hasField(MIN_DELTA_CALC_PERIOD_FIELD)) {
viewDefinition.setMinDeltaCalculationPeriod(message.getLong(MIN_DELTA_CALC_PERIOD_FIELD));
}
if (message.hasField(MAX_DELTA_CALC_PERIOD_FIELD)) {
viewDefinition.setMaxDeltaCalculationPeriod(message.getLong(MAX_DELTA_CALC_PERIOD_FIELD));
}
if (message.hasField(MIN_FULL_CALC_PERIOD_FIELD)) {
viewDefinition.setMinFullCalculationPeriod(message.getLong(MIN_FULL_CALC_PERIOD_FIELD));
}
//for backward compatibility of renaming fullDeltaCalcPeriod to minFullCalcPeriod
if (message.hasField("fullDeltaCalcPeriod")) {
viewDefinition.setMinFullCalculationPeriod(message.getLong("fullDeltaCalcPeriod"));
}
if (message.hasField(MAX_FULL_CALC_PERIOD_FIELD)) {
viewDefinition.setMaxFullCalculationPeriod(message.getLong(MAX_FULL_CALC_PERIOD_FIELD));
}
if (message.hasField(PERSISTENT_FIELD)) {
viewDefinition.setPersistent(true);
}
List<FudgeField> calcConfigs = message.getAllByName(CALCULATION_CONFIGURATION_FIELD);
for (FudgeField calcConfigField : calcConfigs) {
FudgeMsg calcConfigMsg = message.getFieldValue(FudgeMsg.class, calcConfigField);
final ViewCalculationConfiguration calcConfig = new ViewCalculationConfiguration(viewDefinition, message.getFieldValue(String.class, calcConfigMsg.getByName(NAME_FIELD)));
for (FudgeField securityTypeRequirementsField : calcConfigMsg.getAllByName(PORTFOLIO_REQUIREMENTS_BY_SECURITY_TYPE_FIELD)) {
FudgeMsg securityTypeRequirementsMsg = (FudgeMsg) securityTypeRequirementsField.getValue();
String securityType = securityTypeRequirementsMsg.getString(SECURITY_TYPE_FIELD);
Set<Pair<String, ValueProperties>> requirements = Sets.newLinkedHashSet();
for (FudgeField requirement : securityTypeRequirementsMsg.getAllByName(PORTFOLIO_REQUIREMENT_FIELD)) {
FudgeMsg reqMsg = (FudgeMsg) requirement.getValue();
String requiredOutput = reqMsg.getString(PORTFOLIO_REQUIREMENT_REQUIRED_OUTPUT_FIELD);
ValueProperties constraints = deserializer.fieldValueToObject(ValueProperties.class, reqMsg.getByName(PORTFOLIO_REQUIREMENT_CONSTRAINTS_FIELD));
requirements.add(Pair.of(requiredOutput, constraints));
}
calcConfig.addPortfolioRequirements(securityType, requirements);
}
for (FudgeField specificRequirementField : calcConfigMsg.getAllByName(SPECIFIC_REQUIREMENT_FIELD)) {
calcConfig.addSpecificRequirement(plat2286Translate(deserializer.fieldValueToObject(ValueRequirement.class, specificRequirementField)));
}
if (calcConfigMsg.hasField(DELTA_DEFINITION_FIELD)) {
calcConfig.setDeltaDefinition(deserializer.fieldValueToObject(DeltaDefinition.class, calcConfigMsg.getByName(DELTA_DEFINITION_FIELD)));
}
if (calcConfigMsg.hasField(DEFAULT_PROPERTIES_FIELD)) {
calcConfig.setDefaultProperties(deserializer.fieldValueToObject(ValueProperties.class,
calcConfigMsg.getByName(DEFAULT_PROPERTIES_FIELD)));
}
if (calcConfigMsg.hasField(RESOLUTION_RULE_TRANSFORM_FIELD)) {
calcConfig.setResolutionRuleTransform(deserializer.fieldValueToObject(ResolutionRuleTransform.class,
calcConfigMsg.getByName(
RESOLUTION_RULE_TRANSFORM_FIELD)));
}
if (calcConfigMsg.hasField(SCENARIO_ID_FIELD)) {
calcConfig.setScenarioId(deserializer.fieldValueToObject(UniqueId.class,
calcConfigMsg.getByName(SCENARIO_ID_FIELD)));
}
if (calcConfigMsg.hasField(SCENARIO_PARAMETERS_ID_FIELD)) {
calcConfig.setScenarioParametersId(deserializer.fieldValueToObject(UniqueId.class,
calcConfigMsg.getByName(SCENARIO_PARAMETERS_ID_FIELD)));
}
List<ViewCalculationConfiguration.Column> columns = Lists.newArrayList();
if (calcConfigMsg.hasField(COLUMNS_FIELD)) {
FudgeField columnsField = calcConfigMsg.getByName(COLUMNS_FIELD);
FudgeMsg columnsMsg = (FudgeMsg) columnsField.getValue();
for (FudgeField field : columnsMsg.getAllFields()) {
FudgeMsg columnMsg = (FudgeMsg) field.getValue();
String header = deserializer.fieldValueToObject(String.class, columnMsg.getByName(HEADER_FIELD));
String valueName = deserializer.fieldValueToObject(String.class, columnMsg.getByName(VALUE_NAME_FIELD));
ValueProperties properties = deserializer.fieldValueToObject(ValueProperties.class, columnMsg.getByName(PORTFOLIO_REQUIREMENT_CONSTRAINTS_FIELD));
columns.add(new ViewCalculationConfiguration.Column(header, valueName, properties));
}
}
calcConfig.setColumns(columns);
viewDefinition.addViewCalculationConfiguration(calcConfig);
}
FudgeField uniqueId = message.getByName("uniqueId");
if (uniqueId != null) {
viewDefinition.setUniqueId(deserializer.fieldValueToObject(UniqueId.class, uniqueId));
}
return viewDefinition;
}