Unable to manually create a view


#1

Hi,

I’ve looked at the DemoViewsPopulater and have created a test case with two methods:

public static void main(String[] args) { // CSIGNORE
	ViewLoader loader = new ViewLoader();
	try {
		loader.test();

	} catch (Exception ex) {
		ex.printStackTrace();
	} finally {
		loader.close();
	}
	System.exit(0);
}

public void test()
  {
	  
	  UniqueId id = UniqueId.of(ObjectId.parse("DbPrt~1246"), portfolioName);
	  ViewDefinition viewDef =  makeEquityViewDefinition(portfolioName, id);
	  
		ConfigDocument<ViewDefinition> configDocument = new ConfigDocument<ViewDefinition>(ViewDefinition.class);
		configDocument.setName(viewDef.getName());
		configDocument.setValue(viewDef);

		final Object value = configDocument.getValue();
		FUDGE_CONTEXT = FudgeContext.GLOBAL_DEFAULT;
		FudgeMsgEnvelope env = FUDGE_CONTEXT.toFudgeMsg(value);
		int test = 0;
  }
  
  first I tried the version in DemoLoader and then stripped it to a more basic
  
  	private ViewDefinition makeEquityViewDefinition(String portfolioName,			UniqueId portfolioId) {
  		ViewDefinition equityViewDefinition = new ViewDefinition(portfolioName + " View", portfolioId, UserPrincipal.getTestUser());
  		equityViewDefinition.setDefaultCurrency(Currency.USD);
  		equityViewDefinition.setMaxFullCalculationPeriod(30000L);
  		equityViewDefinition.setMinFullCalculationPeriod(500L);
  		equityViewDefinition.setMinDeltaCalculationPeriod(500L);
  		equityViewDefinition.setMaxDeltaCalculationPeriod(30000L);
  		equityViewDefinition.addPortfolioRequirementName("Default",	EquitySecurity.SECURITY_TYPE, ValueRequirementNames.PNL);
  		return equityViewDefinition;
  	}

In both cases, I get the following error

org.fudgemsg.FudgeRuntimeException: Unable to serialise EMPTY
at org.fudgemsg.mapping.JavaBeanBuilder.buildMessage(JavaBeanBuilder.java:205)
at org.fudgemsg.mapping.FudgeSerializer.objectToFudgeMsg(FudgeSerializer.java:219)
at org.fudgemsg.mapping.FudgeSerializer.addToMessageWithClassHeaders(FudgeSerializer.java:175)
at org.fudgemsg.mapping.JavaBeanBuilder.buildMessage(JavaBeanBuilder.java:199)
at org.fudgemsg.mapping.FudgeSerializer.objectToFudgeMsg(FudgeSerializer.java:219)
at org.fudgemsg.mapping.FudgeSerializer.addToMessageWithClassHeaders(FudgeSerializer.java:175)
at org.fudgemsg.mapping.FudgeSerializer.addToMessageWithClassHeaders(FudgeSerializer.java:144)
at org.fudgemsg.mapping.SetBuilder.buildMessage(SetBuilder.java:58)
at org.fudgemsg.mapping.SetBuilder.buildMessage(SetBuilder.java:1)
at org.fudgemsg.mapping.FudgeSerializer.objectToFudgeMsg(FudgeSerializer.java:219)
at org.fudgemsg.mapping.FudgeSerializer.addToMessageWithClassHeaders(FudgeSerializer.java:175)
at org.fudgemsg.mapping.JavaBeanBuilder.buildMessage(JavaBeanBuilder.java:199)
at org.fudgemsg.mapping.FudgeSerializer.objectToFudgeMsg(FudgeSerializer.java:219)
at org.fudgemsg.mapping.FudgeSerializer.addToMessageWithClassHeaders(FudgeSerializer.java:175)
at org.fudgemsg.mapping.FudgeSerializer.addToMessageWithClassHeaders(FudgeSerializer.java:144)
at org.fudgemsg.mapping.ListBuilder.buildMessage(ListBuilder.java:55)
at org.fudgemsg.mapping.ListBuilder.buildMessage(ListBuilder.java:1)
at org.fudgemsg.mapping.FudgeSerializer.objectToFudgeMsg(FudgeSerializer.java:219)
at org.fudgemsg.mapping.FudgeSerializer.addToMessageWithClassHeaders(FudgeSerializer.java:175)
at org.fudgemsg.mapping.JavaBeanBuilder.buildMessage(JavaBeanBuilder.java:199)
at org.fudgemsg.mapping.FudgeSerializer.objectToFudgeMsg(FudgeSerializer.java:219)
at org.fudgemsg.FudgeContext.toFudgeMsg(FudgeContext.java:462)
at ViewLoader.test(ViewLoader.java:79)
at ViewLoader.main(ViewLoader.java:55)
Caused by: java.lang.IllegalAccessException: Class org.fudgemsg.mapping.JavaBeanBuilder can not access a member of class com.opengamma.engine.value.ValueProperties$EmptyPropertiesImpl with modifiers "public"
at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.fudgemsg.mapping.JavaBeanBuilder.buildMessage(JavaBeanBuilder.java:200)
… 23 more

Any pointers greatly appreciated.
Thanks in advance,


#2

Try using OpenGammaFudgeContext.getInstance() instead of FudgeContext.GLOBAL_DEFAULT and see if that helps


#3

Hi Stephen, still no joy I’m afraid. Here’s the updated code:
public void test()
{

	  UniqueId id = UniqueId.of(ObjectId.parse("DbPrt~1246"), portfolioName);
	  ViewDefinition viewDef =  makeEquityViewDefinition(portfolioName, id);
	  
		ConfigDocument<ViewDefinition> configDocument = new ConfigDocument<ViewDefinition>(ViewDefinition.class);
		configDocument.setName(viewDef.getName());
		configDocument.setValue(viewDef);

		final Object value = configDocument.getValue();
		log.info("*************New context...");
		FudgeContext ctx = OpenGammaFudgeContext.getInstance() ;
		FudgeMsgEnvelope env = ctx.toFudgeMsg(value);
  }


private ViewDefinition makeEquityViewDefinition(String portfolioName,			UniqueId portfolioId) {
	ViewDefinition equityViewDefinition = new ViewDefinition(portfolioName + " View", portfolioId, UserPrincipal.getTestUser());
	equityViewDefinition.setDefaultCurrency(Currency.USD);
	equityViewDefinition.setMaxFullCalculationPeriod(30000L);
	equityViewDefinition.setMinFullCalculationPeriod(500L);
	equityViewDefinition.setMinDeltaCalculationPeriod(500L);
	equityViewDefinition.setMaxDeltaCalculationPeriod(30000L);
	equityViewDefinition.addPortfolioRequirementName("Default",	EquitySecurity.SECURITY_TYPE, ValueRequirementNames.PNL);
	return equityViewDefinition;
}

#4

Did you get a different exception?

The exception above occurs when OpenGammaFudgeContext is not used. Basically, OpenGammaFudgeContext registers a large number of FudgeBuilder instances which build the actual message. If there are no builders registered, then Fudge falls back to a default (JavaBeanBuilder, SetBuilder, ListBuilder). As a general rule, OpenGamma should never be using JavaBeanBuilder.


#5

Thanks for the explanation, Stephen - that helped me determine where the issue was. School boy error in my definition for the input classpath led to the AnnotationDB not scanning the OG libraries.