Search in sources :

Example 11 with DateData

use of org.javarosa.core.model.data.DateData in project javarosa by opendatakit.

the class RestoreUtils method addData.

public static void addData(FormInstance dm, String xpath, Object data, int dataType) {
    if (data == null) {
        dataType = -1;
    }
    IAnswerData val;
    switch(dataType) {
        case -1:
            val = null;
            break;
        case Constants.DATATYPE_TEXT:
            val = new StringData((String) data);
            break;
        case Constants.DATATYPE_INTEGER:
            val = new IntegerData((Integer) data);
            break;
        case Constants.DATATYPE_LONG:
            val = new LongData((Long) data);
            break;
        case Constants.DATATYPE_DECIMAL:
            val = new DecimalData((Double) data);
            break;
        case Constants.DATATYPE_BOOLEAN:
            val = new StringData(((Boolean) data).booleanValue() ? "t" : "f");
            break;
        case Constants.DATATYPE_DATE:
            val = new DateData((Date) data);
            break;
        case Constants.DATATYPE_DATE_TIME:
            val = new DateTimeData((Date) data);
            break;
        case Constants.DATATYPE_TIME:
            val = new TimeData((Date) data);
            break;
        case Constants.DATATYPE_CHOICE_LIST:
            val = (SelectMultiData) data;
            break;
        default:
            throw new IllegalArgumentException("Don't know how to handle data type [" + dataType + "]");
    }
    TreeReference ref = absRef(xpath, dm);
    if (dm.addNode(ref, val, dataType) == null) {
        throw new RuntimeException("error setting value during object backup [" + xpath + "]");
    }
}
Also used : IAnswerData(org.javarosa.core.model.data.IAnswerData) IntegerData(org.javarosa.core.model.data.IntegerData) LongData(org.javarosa.core.model.data.LongData) Date(java.util.Date) DecimalData(org.javarosa.core.model.data.DecimalData) DateData(org.javarosa.core.model.data.DateData) TreeReference(org.javarosa.core.model.instance.TreeReference) DateTimeData(org.javarosa.core.model.data.DateTimeData) TimeData(org.javarosa.core.model.data.TimeData) DateTimeData(org.javarosa.core.model.data.DateTimeData) StringData(org.javarosa.core.model.data.StringData)

Aggregations

DateData (org.javarosa.core.model.data.DateData)11 Date (java.util.Date)6 DateTimeData (org.javarosa.core.model.data.DateTimeData)4 IntegerData (org.javarosa.core.model.data.IntegerData)4 StringData (org.javarosa.core.model.data.StringData)4 TimeData (org.javarosa.core.model.data.TimeData)4 DecimalData (org.javarosa.core.model.data.DecimalData)3 LongData (org.javarosa.core.model.data.LongData)3 SelectMultiData (org.javarosa.core.model.data.SelectMultiData)3 List (java.util.List)2 BooleanData (org.javarosa.core.model.data.BooleanData)2 GeoPointData (org.javarosa.core.model.data.GeoPointData)2 GeoShapeData (org.javarosa.core.model.data.GeoShapeData)2 GeoTraceData (org.javarosa.core.model.data.GeoTraceData)2 IAnswerData (org.javarosa.core.model.data.IAnswerData)2 SelectOneData (org.javarosa.core.model.data.SelectOneData)2 UncastData (org.javarosa.core.model.data.UncastData)2 Selection (org.javarosa.core.model.data.helper.Selection)2 LocalDateTime (org.joda.time.LocalDateTime)2 Test (org.junit.Test)2