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());
}
}
}
}
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;
}
}
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;
}
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;
}
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);
}
Aggregations