Search in sources :

Example 6 with ValueAndError

use of com.qcadoo.model.internal.api.ValueAndError in project qcadoo by qcadoo.

the class DefaultEntity method getLongField.

@Override
public Long getLongField(final String fieldName) {
    final Object fieldValue = getField(fieldName);
    if (fieldValue == null) {
        return null;
    }
    if (fieldValue instanceof Long) {
        return (Long) fieldValue;
    }
    final FieldDefinition fieldDefinition = dataDefinition.getField(fieldName);
    if (fieldValue instanceof String && Long.class.equals(fieldDefinition.getType().getType())) {
        if (StringUtils.isBlank((String) fieldValue)) {
            return null;
        }
        final ValueAndError valueAndError = fieldDefinition.getType().toObject(fieldDefinition, fieldValue);
        if (valueAndError.isValid()) {
            return (Long) valueAndError.getValue();
        }
    }
    throw new IllegalArgumentException("Field " + fieldName + " in " + dataDefinition.getPluginIdentifier() + '.' + dataDefinition.getName() + " does not contain correct Long value (current field value: " + fieldValue + ")");
}
Also used : ValueAndError(com.qcadoo.model.internal.api.ValueAndError)

Aggregations

ValueAndError (com.qcadoo.model.internal.api.ValueAndError)6 EnumeratedType (com.qcadoo.model.api.types.EnumeratedType)2 DataAccessTest (com.qcadoo.model.internal.DataAccessTest)2 Test (org.junit.Test)2 TranslationService (com.qcadoo.localization.api.TranslationService)1 DictionaryService (com.qcadoo.model.api.DictionaryService)1 DictionaryType (com.qcadoo.model.internal.types.DictionaryType)1 EnumType (com.qcadoo.model.internal.types.EnumType)1 ZoomLevel (com.qcadoo.view.internal.components.ganttChart.GanttChartScaleImpl.ZoomLevel)1 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1 DateTime (org.joda.time.DateTime)1 JSONObject (org.json.JSONObject)1