use of org.openforis.idm.metamodel.Unit in project collect by openforis.
the class NumericRangeAttribute method getUnit.
public Unit getUnit() {
Integer unitId = getUnitId();
Unit unit = null;
if (unitId != null) {
unit = getSurvey().getUnit(unitId);
} else {
String unitName = getUnitName();
if (unitName != null) {
unit = getSurvey().getUnit(unitName);
}
}
return unit;
}
use of org.openforis.idm.metamodel.Unit in project collect by openforis.
the class SurveyObjectsGenerator method addUnit.
private void addUnit(Survey survey, String name, Dimension dimension, Double conversionFactor, List<String> labels, List<String> abbreviations, Set<String> labelLanguages) {
Unit unit = survey.createUnit();
unit.setName(name);
unit.setDimension(dimension.name().toLowerCase(Locale.ENGLISH));
unit.setConversionFactor(conversionFactor);
for (String label : labels) {
for (String lang : labelLanguages) {
unit.setLabel(lang, label);
}
}
for (String abbr : abbreviations) {
for (String lang : labelLanguages) {
unit.setAbbreviation(lang, abbr);
}
}
survey.addUnit(unit);
}
use of org.openforis.idm.metamodel.Unit in project collect by openforis.
the class RecordConverter method moveDataToNewUnitField.
protected void moveDataToNewUnitField(CollectSurvey survey, Field<String> unitNameField, Field<Integer> unitField) throws RecordConversionException {
unitField.setRemarks(unitNameField.getRemarks());
unitField.setSymbol(unitNameField.getSymbol());
unitField.getState().set(unitNameField.getState().intValue());
String unitName = unitNameField.getValue();
if (unitName != null) {
Unit unit = survey.getUnit(unitName);
if (unit != null) {
unitField.setValue(unit.getId());
} else {
throw new RecordConversionException("Cannot find unit with name: " + unitName);
}
}
unitNameField.getState().set(0);
unitNameField.clear();
}
use of org.openforis.idm.metamodel.Unit in project collect by openforis.
the class JSONValueParser method parseIntegerRange.
public IntegerRange parseIntegerRange(RangeAttributeDefinition attrDef, String value) {
Map<String, Object> map = parseJSONToMap(value);
if (map == null) {
return null;
}
Integer from = getInteger(map, IntegerRange.FROM_FIELD);
Integer to = getInteger(map, IntegerRange.TO_FIELD);
if (to == null) {
to = from;
}
Integer unitId = getInteger(map, NumberValue.UNIT_ID_FIELD);
Unit unit = attrDef.getActualUnit(unitId);
return new IntegerRange(from, to, unit);
}
use of org.openforis.idm.metamodel.Unit in project collect by openforis.
the class JSONValueParser method parseInteger.
public IntegerValue parseInteger(NumberAttributeDefinition attrDef, String value) {
Map<String, Object> map = parseJSONToMap(value, NumberValue.VALUE_FIELD);
if (map == null) {
return null;
}
Integer unitId = getInteger(map, NumberValue.UNIT_ID_FIELD);
Unit unit = attrDef.getActualUnit(unitId);
return new IntegerValue(getInteger(map, NumberValue.VALUE_FIELD), unit);
}
Aggregations