Search in sources :

Example 1 with File

use of org.openforis.idm.model.File in project collect by openforis.

the class FileAttributeMapper method addNode.

@Override
Node<?> addNode(NodeDefinition defn, Record r, Entity parent) {
    String filename = r.getValueAsString(Data.DATA.TEXT1);
    Long size = r.getValueAsLong(Data.DATA.NUMBER1);
    File value = new File(filename, size);
    return parent.addValue(defn.getName(), value);
}
Also used : File(org.openforis.idm.model.File)

Example 2 with File

use of org.openforis.idm.model.File in project collect by openforis.

the class FileAttributeMapper method setFields.

@Override
void setFields(Node<?> node, InsertSetStep<?> insert) {
    FileAttribute f = (FileAttribute) node;
    File value = f.getValue();
    if (value != null) {
        insert.set(Data.DATA.TEXT1, value.getFilename());
        insert.set(Data.DATA.NUMBER1, toNumeric(value.getSize()));
    }
}
Also used : File(org.openforis.idm.model.File) FileAttribute(org.openforis.idm.model.FileAttribute)

Example 3 with File

use of org.openforis.idm.model.File in project collect by openforis.

the class BaseAttributeUpdateRequestProxy method parseFileAttributeValue.

protected File parseFileAttributeValue(RecordSessionManager sessionManager, CollectRecord record, Integer nodeId, Object value) {
    if (value == null) {
        sessionManager.prepareDeleteTempRecordFile(record, nodeId);
        return null;
    } else {
        if (value instanceof FileWrapper) {
            FileWrapper fileWrapper = (FileWrapper) value;
            java.io.File tempFile = new java.io.File(fileWrapper.getFilePath());
            sessionManager.prepareDeleteTempRecordFile(record, nodeId);
            sessionManager.indexTempRecordFile(tempFile, nodeId);
            return new File(tempFile.getAbsolutePath(), tempFile.length());
        } else {
            throw new IllegalArgumentException("Invalid value type: expected byte[]");
        }
    }
}
Also used : FileWrapper(org.openforis.collect.remoting.service.FileWrapper) File(org.openforis.idm.model.File)

Example 4 with File

use of org.openforis.idm.model.File in project collect by openforis.

the class CSVValueFormatter method format.

public String format(AttributeDefinition defn, Value value) {
    if (value == null) {
        return "";
    } else if (value instanceof BooleanValue) {
        return ((BooleanValue) value).getValue().toString();
    } else if (value instanceof Code) {
        CodeListService codeListService = defn.getSurvey().getContext().getCodeListService();
        CodeList list = ((CodeAttributeDefinition) defn).getList();
        if (codeListService.hasQualifiableItems(list)) {
            return String.format("%s: %s", ((Code) value).getCode(), ((Code) value).getQualifier());
        } else {
            return ((Code) value).getCode();
        }
    } else if (value instanceof Coordinate) {
        return value.toString();
    } else if (value instanceof Date) {
        Date date = (Date) value;
        return String.format("%d/%d/%d", ((Date) value).getDay(), ((Date) value).getMonth(), date.getYear());
    } else if (value instanceof File) {
        return ((File) value).getFilename();
    } else if (value instanceof NumberValue) {
        Number val = ((NumberValue<?>) value).getValue();
        NumberFormat numberFormat = NumberFormat.getInstance(Locale.ENGLISH);
        String formattedVal = numberFormat.format(val);
        return formattedVal;
    } else if (value instanceof NumericRange) {
        Number from = ((NumericRange<?>) value).getFrom();
        Number to = ((NumericRange<?>) value).getFrom();
        String format;
        if (value instanceof IntegerRange) {
            format = "%d-%d";
        } else {
            format = "%f-%f";
        }
        String formattedValue = String.format(Locale.ENGLISH, format, from, to);
        return formattedValue;
    } else if (value instanceof TextValue) {
        return ((TextValue) value).getValue();
    } else if (value instanceof Time) {
        Time time = (Time) value;
        return String.format("%d:%d", time.getHour(), time.getMinute());
    } else
        throw new IllegalArgumentException("Unsupported attribute value type: " + value.getClass().getName());
}
Also used : IntegerRange(org.openforis.idm.model.IntegerRange) CodeListService(org.openforis.idm.metamodel.CodeListService) Time(org.openforis.idm.model.Time) Code(org.openforis.idm.model.Code) Date(org.openforis.idm.model.Date) NumericRange(org.openforis.idm.model.NumericRange) CodeList(org.openforis.idm.metamodel.CodeList) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) Coordinate(org.openforis.idm.model.Coordinate) NumberValue(org.openforis.idm.model.NumberValue) TextValue(org.openforis.idm.model.TextValue) BooleanValue(org.openforis.idm.model.BooleanValue) File(org.openforis.idm.model.File) NumberFormat(java.text.NumberFormat)

Aggregations

File (org.openforis.idm.model.File)4 NumberFormat (java.text.NumberFormat)1 FileWrapper (org.openforis.collect.remoting.service.FileWrapper)1 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)1 CodeList (org.openforis.idm.metamodel.CodeList)1 CodeListService (org.openforis.idm.metamodel.CodeListService)1 BooleanValue (org.openforis.idm.model.BooleanValue)1 Code (org.openforis.idm.model.Code)1 Coordinate (org.openforis.idm.model.Coordinate)1 Date (org.openforis.idm.model.Date)1 FileAttribute (org.openforis.idm.model.FileAttribute)1 IntegerRange (org.openforis.idm.model.IntegerRange)1 NumberValue (org.openforis.idm.model.NumberValue)1 NumericRange (org.openforis.idm.model.NumericRange)1 TextValue (org.openforis.idm.model.TextValue)1 Time (org.openforis.idm.model.Time)1