Search in sources :

Example 16 with Survey

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()));
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Survey(org.openforis.idm.metamodel.Survey) Schema(org.openforis.idm.metamodel.Schema) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) Test(org.junit.Test)

Example 17 with Survey

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();
}
Also used : Survey(org.openforis.idm.metamodel.Survey) SurveyContext(org.openforis.idm.metamodel.SurveyContext)

Example 18 with Survey

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);
    }
}
Also used : Survey(org.openforis.idm.metamodel.Survey) SurveyUnmarshaller(org.openforis.idm.metamodel.xml.internal.unmarshal.SurveyUnmarshaller) IOException(java.io.IOException)

Example 19 with Survey

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);
        }
    }
}
Also used : IdmInterpretationError(org.openforis.idm.metamodel.IdmInterpretationError) Survey(org.openforis.idm.metamodel.Survey) Matcher(java.util.regex.Matcher) InvalidExpressionException(org.openforis.idm.model.expression.InvalidExpressionException)

Example 20 with Survey

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();
}
Also used : Survey(org.openforis.idm.metamodel.Survey) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) FileOutputStream(java.io.FileOutputStream) File(java.io.File) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Aggregations

Survey (org.openforis.idm.metamodel.Survey)67 Test (org.junit.Test)19 CollectSurvey (org.openforis.collect.model.CollectSurvey)13 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)11 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)10 Schema (org.openforis.idm.metamodel.Schema)10 SurveyContext (org.openforis.idm.metamodel.SurveyContext)8 Entity (org.openforis.idm.model.Entity)4 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)3 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)3 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)3 LookupProvider (org.openforis.idm.metamodel.validation.LookupProvider)3 TestSurveyContext (org.openforis.idm.model.TestSurveyContext)3 IOException (java.io.IOException)2 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)2 NodeChangeSet (org.openforis.collect.model.NodeChangeSet)2 AttributeDefault (org.openforis.idm.metamodel.AttributeDefault)2 CodeList (org.openforis.idm.metamodel.CodeList)2 CodeListService (org.openforis.idm.metamodel.CodeListService)2 ModelVersion (org.openforis.idm.metamodel.ModelVersion)2