Search in sources :

Example 36 with Survey

use of org.openforis.idm.metamodel.Survey in project collect by openforis.

the class CSVDataImportProcess method setUnitField.

private void setUnitField(Attribute<?, ?> attr, String value, long row, String colName) {
    if (StringUtils.isBlank(value)) {
        ((NumberAttribute<?, ?>) attr).setUnit(null);
    } else {
        Survey survey = attr.getSurvey();
        Unit unit = survey.getUnit(value);
        NumericAttributeDefinition defn = (NumericAttributeDefinition) attr.getDefinition();
        if (unit == null || !defn.getUnits().contains(unit)) {
            ParsingError parsingError = new ParsingError(ErrorType.INVALID_VALUE, row, colName, UNIT_NOT_FOUND_MESSAGE_KEY);
            parsingError.setMessageArgs(new String[] { value });
            status.addParsingError(parsingError);
        } else {
            Field<Integer> field = ((NumberAttribute<?, ?>) attr).getUnitField();
            NodeChangeSet changes = recordUpdater.updateField(field, unit.getId());
            if (nodeChangeBatchProcessor != null) {
                nodeChangeBatchProcessor.add(changes, adminUser.getUsername());
            }
        }
    }
}
Also used : NodeChangeSet(org.openforis.collect.model.NodeChangeSet) CollectSurvey(org.openforis.collect.model.CollectSurvey) Survey(org.openforis.idm.metamodel.Survey) ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) NumberAttribute(org.openforis.idm.model.NumberAttribute) Unit(org.openforis.idm.metamodel.Unit) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition)

Example 37 with Survey

use of org.openforis.idm.metamodel.Survey in project collect by openforis.

the class ValidationMessageBuilder method getComparisonCheckMessageArg.

protected String getComparisonCheckMessageArg(Attribute<?, ?> attribute, String expression, Locale locale) {
    if (StringUtils.isNotBlank(expression)) {
        String result = expression;
        Survey survey = attribute.getSurvey();
        Schema schema = survey.getSchema();
        SurveyContext surveyContext = survey.getContext();
        ExpressionEvaluator expressionEvaluator = surveyContext.getExpressionEvaluator();
        try {
            Entity parentEntity = attribute.getParent();
            EntityDefinition parentDefinition = parentEntity.getDefinition();
            Set<String> referencedPaths = expressionEvaluator.determineReferencedPaths(expression);
            for (String path : referencedPaths) {
                String absolutePath = parentDefinition.getPath() + PATH_SEPARATOR + path;
                NodeDefinition nodeDefinition = schema.getDefinitionByPath(absolutePath);
                String label = getPrettyLabelText(nodeDefinition, locale);
                result = result.replaceAll(nodeDefinition.getName(), label);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return result;
    } else {
        return expression;
    }
}
Also used : Entity(org.openforis.idm.model.Entity) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Survey(org.openforis.idm.metamodel.Survey) Schema(org.openforis.idm.metamodel.Schema) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) ExpressionEvaluator(org.openforis.idm.model.expression.ExpressionEvaluator) SurveyContext(org.openforis.idm.metamodel.SurveyContext)

Example 38 with Survey

use of org.openforis.idm.metamodel.Survey in project collect by openforis.

the class ValidationMessageBuilder method getComparisonCheckMessage.

protected String getComparisonCheckMessage(Attribute<?, ?> attribute, ValidationResult validationResult, Locale locale) {
    Survey survey = attribute.getSurvey();
    String surveyDefaultLanguage = survey.getDefaultLanguage();
    String[] messageArgs = getMessageArgs(attribute, validationResult, locale);
    String nodeLabel = messageArgs[0];
    String[] adaptedArgs = new String[messageArgs.length - 1];
    for (int i = 1; i < messageArgs.length; i++) {
        String arg = messageArgs[i];
        String[] argParts = arg.split(MULTIPLE_MESSAGE_ARGS_SEPARATOR);
        String op = argParts[0];
        String value = argParts[1];
        String opMessageKey = VALIDATION_COMPARE_MESSAGES_PREFIX + op;
        String operator = getMessage(surveyDefaultLanguage, locale, opMessageKey);
        String argAdapted = StringUtils.join(new String[] { operator, value }, " ");
        adaptedArgs[i - 1] = argAdapted;
    }
    String andOperator = StringUtils.join(" ", getMessage(surveyDefaultLanguage, locale, AND_OPERATOR_MESSAGE_KEY), " ");
    String argsConcat = StringUtils.join(adaptedArgs, andOperator);
    String messageKey = getMessageKey(attribute, validationResult);
    Object[] finalMessageArgs = new Object[] { nodeLabel, argsConcat };
    String result = getMessage(surveyDefaultLanguage, locale, messageKey, finalMessageArgs);
    return result;
}
Also used : Survey(org.openforis.idm.metamodel.Survey)

Example 39 with Survey

use of org.openforis.idm.metamodel.Survey in project collect by openforis.

the class DatabaseExternalCodeListProvider method parseRow.

protected ExternalCodeListItem parseRow(Map<String, String> row, CodeList list, int levelIndex) {
    if (row == null) {
        return null;
    }
    String idValue = row.get(ID_COLUMN_NAME);
    Integer id = Integer.valueOf(idValue);
    Map<String, String> parentKeysByLevel = createParentKeyByLevelMap(list, row, levelIndex);
    ExternalCodeListItem item = new ExternalCodeListItem(list, id, parentKeysByLevel, levelIndex + 1);
    String currentLevelKeyColName = getLevelKeyColumnName(list, levelIndex);
    String code = row.get(currentLevelKeyColName);
    item.setCode(code);
    Survey survey = list.getSurvey();
    List<String> languages = survey.getLanguages();
    for (int i = 0; i < languages.size(); i++) {
        String langCode = languages.get(i);
        String colName = LABEL_COLUMN_PREFIX + (i + 1);
        String label = row.get(colName);
        if (label != null) {
            item.setLabel(langCode, label);
        }
    }
    return item;
}
Also used : Survey(org.openforis.idm.metamodel.Survey) CollectSurvey(org.openforis.collect.model.CollectSurvey) ExternalCodeListItem(org.openforis.idm.metamodel.ExternalCodeListItem)

Example 40 with Survey

use of org.openforis.idm.metamodel.Survey in project collect by openforis.

the class ModelDaoIntegrationTest method testSurveyNotFoundById.

@Test
public void testSurveyNotFoundById() {
    Survey survey = surveyManager.loadSurvey(-100);
    assertNull(survey);
}
Also used : Survey(org.openforis.idm.metamodel.Survey) CollectSurvey(org.openforis.collect.model.CollectSurvey) 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