use of org.openforis.idm.metamodel.Survey in project collect by openforis.
the class ProtostuffSerializationTest method testSkipRemovedEntity.
@Test
public void testSkipRemovedEntity() throws Exception {
// Set up
Survey survey = getTestSurvey();
// assignFakeNodeDefinitionIds(survey.getSchema());
Record record1 = createTestRecord(survey);
Entity cluster1 = record1.getRootEntity();
// Write
ModelSerializer ser = new ModelSerializer(10000);
byte[] data = ser.toByteArray(cluster1);
// remove data
cluster1.remove("map_sheet", 1);
cluster1.remove("map_sheet", 0);
Schema schema = survey.getSchema();
EntityDefinition clusterDefn = schema.getRootEntityDefinition("cluster");
NodeDefinition mapSheetDefn = clusterDefn.getChildDefinition("map_sheet");
clusterDefn.removeChildDefinition(mapSheetDefn);
Record record2 = new Record(survey, "2.0", "cluster");
ser.mergeFrom(data, record2.getRootEntity());
// Compare
Assert.assertTrue(record1.getRootEntity().deepEquals(record2.getRootEntity()));
}
use of org.openforis.idm.metamodel.Survey in project collect by openforis.
the class ExternalCodeValidator method getExternalCodeListProvider.
private ExternalCodeListProvider getExternalCodeListProvider(CodeAttribute codeAttribute) {
Survey survey = codeAttribute.getSurvey();
SurveyContext surveyContext = survey.getContext();
return surveyContext.getExternalCodeListProvider();
}
use of org.openforis.idm.metamodel.Survey in project collect by openforis.
the class SurveyIdmlBinder method unmarshal.
public Survey unmarshal(InputStream is, boolean includeCodeListItems) throws IdmlParseException {
try {
SurveyUnmarshaller unmarshaller = new SurveyUnmarshaller(this, includeCodeListItems);
unmarshaller.parse(is, UTF_8);
Survey survey = unmarshaller.getSurvey();
onUnmarshallingComplete(survey);
return survey;
} catch (Exception e) {
throw new IdmlParseException(e);
}
}
use of org.openforis.idm.metamodel.Survey in project collect by openforis.
the class Check method getMessageWithEvaluatedExpressions.
public String getMessageWithEvaluatedExpressions(Attribute<?, ?> context, String preferredLanguage) {
Survey survey = context.getSurvey();
String message;
if (preferredLanguage == null || survey.isDefaultLanguage(preferredLanguage)) {
message = getMessage(survey.getDefaultLanguage());
} else {
message = getMessageInPreferredLanguage(survey, preferredLanguage);
}
if (StringUtils.isBlank(message)) {
return null;
} else {
try {
StringBuffer sb = new StringBuffer();
Matcher matcher = MESSAGE_NESTED_EXPRESSION_PATTERN.matcher(message);
while (matcher.find()) {
String expr = matcher.group(1);
Object val = getExpressionEvaluator(context).evaluateValue(context.getParent(), context, expr);
String replacement = val == null ? "" : val.toString();
matcher.appendReplacement(sb, replacement);
}
matcher.appendTail(sb);
return sb.toString();
} catch (InvalidExpressionException e) {
throw new IdmInterpretationError("Unable to evaluate condition " + condition, e);
}
}
}
use of org.openforis.idm.metamodel.Survey in project collect by openforis.
the class UIOptionsBinderTest method roundTripMarshallingTest.
@Test
public void roundTripMarshallingTest() throws IOException {
String optionsBody = loadTestOptions();
UIOptionsBinder binder = new UIOptionsBinder();
Survey survey = createTestSurvey();
UIOptions uiOptions = binder.unmarshal(survey, UIOptionsConstants.UI_TYPE, optionsBody);
new File("target/test/output").mkdirs();
FileOutputStream fos = new FileOutputStream("target/test/output/marshalled.uioptions.xml");
String marshalled = binder.marshal(uiOptions, survey.getDefaultLanguage());
IOUtils.write(marshalled, fos);
fos.flush();
fos.close();
}
Aggregations