ViewDefinition viewDefinition;
if (getPortfolioScheme() != null && getPortfolioId() != null) {
viewDefinition = new ViewDefinition(getName(), UniqueId.of(getPortfolioScheme(), getPortfolioId()), getUserName());
if (getPortfolioRequirements() != null) {
for (Map.Entry<String, Map<String, String[]>> config : getPortfolioRequirements().entrySet()) {
ViewCalculationConfiguration calcConfig = getOrCreateCalcConfig(viewDefinition, config.getKey());
for (Map.Entry<String, String[]> security : config.getValue().entrySet()) {
for (String value : security.getValue()) {
final Pair<String, ValueProperties> requirement = parseValueRequirement(value);
calcConfig.addPortfolioRequirement(security.getKey(), requirement.getFirst(), requirement.getSecond());
}
}
}
}
} else {
viewDefinition = new ViewDefinition(getName(), getUserName());
}
viewDefinition.setMinDeltaCalculationPeriod(getMinDeltaCalculationPeriod());
viewDefinition.setMaxDeltaCalculationPeriod(getMaxDeltaCalculationPeriod());
viewDefinition.setMinFullCalculationPeriod(getMinFullCalculationPeriod());
viewDefinition.setMaxFullCalculationPeriod(getMaxFullCalculationPeriod());
if (getSpecificRequirements() != null) {
for (Entry<String, Set<String[]>> config : getSpecificRequirements().entrySet()) {
ViewCalculationConfiguration calcConfig = getOrCreateCalcConfig(viewDefinition, config.getKey());
for (String[] entry : config.getValue()) {
if (entry.length < 4) {
throw new OpenGammaRuntimeException("Not enough members of array in specific requirements. Need [0]=Name [1]=ComputationTargetType [2]=UniqueIdScheme [3]=UniqueIdValue");
}
final Pair<String, ValueProperties> requirement = parseValueRequirement(entry[0]);
String type = entry[1];
String scheme = entry[2];
String value = entry[3];
calcConfig.addSpecificRequirement(new ValueRequirement(requirement.getFirst(), ComputationTargetType.parse(type), UniqueId.of(scheme, value), requirement.getSecond()));
}
}
}
if (getDefaultCurrency() != null) {
viewDefinition.setDefaultCurrency(Currency.of(getDefaultCurrency()));
}
if (getDefaultProperties() != null) {
for (Entry<String, Map<String, String>> defaultProperties : getDefaultProperties().entrySet()) {
ViewCalculationConfiguration calcConfig = getOrCreateCalcConfig(viewDefinition, defaultProperties.getKey());
final ValueProperties.Builder properties = ValueProperties.builder();
for (Entry<String, String> property : defaultProperties.getValue().entrySet()) {
properties.with(property.getKey(), property.getValue());
}
calcConfig.setDefaultProperties(properties.get());
}
}
for (ViewCalculationConfiguration calcConfig : viewDefinition.getAllCalculationConfigurations()) {
if (calcConfig.getDefaultProperties().getValues(ValuePropertyNames.CURRENCY) == null) {
calcConfig.setDefaultProperties(calcConfig.getDefaultProperties().copy().with(ValuePropertyNames.CURRENCY, getDefaultCurrency()).get());
}
}
return viewDefinition;
}