use of org.openforis.idm.metamodel.Survey in project collect by openforis.
the class UIOptionsBinderTest method testUnmarshall.
@Test
public void testUnmarshall() throws IOException {
String optionsBody = loadTestOptions();
UIOptionsBinder binder = new UIOptionsBinder();
Survey survey = createTestSurvey();
UIOptions uiOptions = binder.unmarshal(survey, UIOptionsConstants.UI_TYPE, optionsBody);
assertNotNull(uiOptions);
List<UITabSet> tabSets = uiOptions.getTabSets();
assertEquals(1, tabSets.size());
UITabSet clusterRootTabSet = tabSets.get(0);
assertEquals("cluster", clusterRootTabSet.getName());
List<UITab> tabs = clusterRootTabSet.getTabs();
assertEquals(4, tabs.size());
UITab plotTab = tabs.get(1);
assertEquals("plot", plotTab.getName());
String label = plotTab.getLabel("en");
assertEquals("Plot", label);
assertEquals(clusterRootTabSet, plotTab.getParent());
List<UITab> plotInnerTabs = plotTab.getTabs();
assertEquals(6, plotInnerTabs.size());
UITab plotDetTab = plotInnerTabs.get(0);
assertEquals("plot_det", plotDetTab.getName());
}
use of org.openforis.idm.metamodel.Survey in project collect by openforis.
the class CalculatedAttributeTest method createTestSurvey.
/**
* Creates a test survey in which there is a bill with a list of items.
* For each item there is a price, a quantity and a total
* (calculated using the an expression or a constant).
*
* @return
*/
private Survey createTestSurvey() {
SurveyContext surveyContext = new TestSurveyContext();
Survey survey = surveyContext.createSurvey();
Schema schema = survey.getSchema();
EntityDefinition root = schema.createEntityDefinition();
root.setName("bill");
schema.addRootEntityDefinition(root);
EntityDefinition item = schema.createEntityDefinition();
item.setName("item");
root.addChildDefinition(item);
NumberAttributeDefinition qty = schema.createNumberAttributeDefinition();
qty.setType(Type.INTEGER);
qty.setName("qty");
item.addChildDefinition(qty);
NumberAttributeDefinition price = schema.createNumberAttributeDefinition();
price.setName("price");
item.addChildDefinition(price);
NumberAttributeDefinition total = schema.createNumberAttributeDefinition();
total.setName("total");
total.setCalculated(true);
total.addAttributeDefault(new AttributeDefault("qty * (price - (price * discount_percent div 100))"));
item.addChildDefinition(total);
TimeAttributeDefinition time = schema.createTimeAttributeDefinition();
time.setName("time");
time.addAttributeDefault(new AttributeDefault("idm:currentTime()"));
item.addChildDefinition(time);
TimeAttributeDefinition timeAlias = schema.createTimeAttributeDefinition();
timeAlias.setName("time_alias");
timeAlias.setCalculated(true);
timeAlias.addAttributeDefault(new AttributeDefault("time"));
item.addChildDefinition(timeAlias);
NumberAttributeDefinition discountPercent = schema.createNumberAttributeDefinition();
discountPercent.setType(Type.INTEGER);
discountPercent.setName("discount_percent");
discountPercent.setCalculated(true);
discountPercent.addAttributeDefault(new AttributeDefault("30", "qty > 50"));
discountPercent.addAttributeDefault(new AttributeDefault("20", "qty > 20"));
discountPercent.addAttributeDefault(new AttributeDefault("10", "qty > 10"));
discountPercent.addAttributeDefault(new AttributeDefault("0", "true()"));
item.addChildDefinition(discountPercent);
return survey;
}
use of org.openforis.idm.metamodel.Survey in project collect by openforis.
the class DefaultValueTest method createTestSurvey.
/**
* Creates a test survey in which there is a bill with a list of items.
* For each item there is a price, a quantity and a total
* (calculated using the an expression or a constant).
*
* @return
*/
protected Survey createTestSurvey() {
SurveyContext surveyContext = new TestSurveyContext();
Survey survey = surveyContext.createSurvey();
Schema schema = survey.getSchema();
EntityDefinition root = schema.createEntityDefinition();
root.setName("bill");
schema.addRootEntityDefinition(root);
EntityDefinition item = schema.createEntityDefinition();
item.setName("item");
root.addChildDefinition(item);
NumberAttributeDefinition qty = schema.createNumberAttributeDefinition();
qty.setType(Type.INTEGER);
qty.setName("qty");
item.addChildDefinition(qty);
NumberAttributeDefinition price = schema.createNumberAttributeDefinition();
price.setName("price");
item.addChildDefinition(price);
NumberAttributeDefinition total = schema.createNumberAttributeDefinition();
total.setName("total");
item.addChildDefinition(total);
{
AttributeDefault attributeDefault = new AttributeDefault();
attributeDefault.setExpression("qty * price");
attributeDefault.setCondition("price > 0");
total.addAttributeDefault(attributeDefault);
}
{
AttributeDefault attributeDefault = new AttributeDefault();
attributeDefault.setValue("0");
attributeDefault.setCondition("price = 0");
total.addAttributeDefault(attributeDefault);
}
return survey;
}
use of org.openforis.idm.metamodel.Survey in project collect by openforis.
the class CustomFunctions method getSurvey.
protected static Survey getSurvey(ExpressionContext context) {
ModelJXPathContext jxPathContext = (ModelJXPathContext) context.getJXPathContext();
Survey survey = jxPathContext.getSurvey();
return survey;
}
use of org.openforis.idm.metamodel.Survey in project collect by openforis.
the class IDMFunctions method samplingPointDataLookup.
private static Object samplingPointDataLookup(ExpressionContext context, String attribute, String... keys) {
if (validateSamplingPointKeys(keys)) {
LookupProvider lookupProvider = getLookupProvider(context);
Survey survey = getSurvey(context);
Object data = lookupProvider.lookupSamplingPointData(survey, attribute, keys);
return data;
} else {
return null;
}
}
Aggregations