Search in sources :

Example 26 with CodeTable

use of com.revolsys.record.code.CodeTable in project com.revolsys.open by revolsys.

the class Record method getValueByPath.

@SuppressWarnings("unchecked")
default <T> T getValueByPath(final CharSequence path) {
    final int fieldIndex = getFieldIndex(path);
    if (fieldIndex == -1) {
        final RecordDefinition recordDefinition = getRecordDefinition();
        final String[] propertyPath = path.toString().split("\\.");
        Object propertyValue = this;
        for (int i = 0; i < propertyPath.length && propertyValue != null; i++) {
            final String propertyName = propertyPath[i];
            if (propertyValue instanceof Record) {
                final Record record = (Record) propertyValue;
                if (record.hasField(propertyName)) {
                    propertyValue = record.getValue(propertyName);
                    if (propertyValue == null) {
                        return null;
                    } else if (i + 1 < propertyPath.length) {
                        final CodeTable codeTable = recordDefinition.getCodeTableByFieldName(propertyName);
                        if (codeTable != null) {
                            propertyValue = codeTable.getMap(propertyValue);
                        }
                    }
                } else {
                    return null;
                }
            } else if (propertyValue instanceof Map) {
                final Map<String, Object> map = (Map<String, Object>) propertyValue;
                propertyValue = map.get(propertyName);
                if (propertyValue == null) {
                    return null;
                } else if (i + 1 < propertyPath.length) {
                    final CodeTable codeTable = recordDefinition.getCodeTableByFieldName(propertyName);
                    if (codeTable != null) {
                        propertyValue = codeTable.getMap(propertyValue);
                    }
                }
            } else {
                try {
                    final Object object = propertyValue;
                    propertyValue = Property.getSimple(object, propertyName);
                } catch (final IllegalArgumentException e) {
                    Logs.debug(this, "Path does not exist " + path, e);
                    return null;
                }
            }
        }
        return (T) propertyValue;
    } else {
        return getValue(fieldIndex);
    }
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) HashMap(java.util.HashMap) Map(java.util.Map) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 27 with CodeTable

use of com.revolsys.record.code.CodeTable in project com.revolsys.open by revolsys.

the class Record method getCodeValue.

@SuppressWarnings("unchecked")
default <T> T getCodeValue(final int fieldIndex) {
    Object value = getValue(fieldIndex);
    if (Property.hasValue(value)) {
        final FieldDefinition fieldDefinition = getFieldDefinition(fieldIndex);
        final CodeTable codeTable = fieldDefinition.getCodeTable();
        if (codeTable != null) {
            value = codeTable.getValue(value);
        }
    }
    return (T) value;
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) FieldDefinition(com.revolsys.record.schema.FieldDefinition)

Example 28 with CodeTable

use of com.revolsys.record.code.CodeTable in project com.revolsys.open by revolsys.

the class Records method getFieldByPath.

@SuppressWarnings("unchecked")
static <T> T getFieldByPath(final Record record, final String path) {
    if (path == null) {
        return null;
    } else {
        final RecordDefinition recordDefinition = record.getRecordDefinition();
        final String[] propertyPath = path.split("\\.");
        Object propertyValue = record;
        for (int i = 0; i < propertyPath.length && propertyValue != null; i++) {
            final String propertyName = propertyPath[i];
            if (propertyValue instanceof Record) {
                final Record recordValue = (Record) propertyValue;
                if (recordValue.hasField(propertyName)) {
                    propertyValue = getValue(recordValue, propertyName);
                    if (propertyValue == null) {
                        return null;
                    } else if (i + 1 < propertyPath.length) {
                        final CodeTable codeTable = recordDefinition.getCodeTableByFieldName(propertyName);
                        if (codeTable != null) {
                            propertyValue = codeTable.getMap(Identifier.newIdentifier(propertyValue));
                        }
                    }
                } else {
                    return null;
                }
            } else if (propertyValue instanceof Map) {
                final Map<String, Object> map = (Map<String, Object>) propertyValue;
                propertyValue = map.get(propertyName);
                if (propertyValue == null) {
                    return null;
                } else if (i + 1 < propertyPath.length) {
                    final CodeTable codeTable = recordDefinition.getCodeTableByFieldName(propertyName);
                    if (codeTable != null) {
                        propertyValue = codeTable.getMap(Identifier.newIdentifier(propertyValue));
                    }
                }
            } else {
                try {
                    final Object object = propertyValue;
                    propertyValue = Property.getSimple(object, propertyName);
                } catch (final IllegalArgumentException e) {
                    throw new IllegalArgumentException("Path does not exist " + path, e);
                }
            }
        }
        return (T) propertyValue;
    }
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) Map(java.util.Map) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 29 with CodeTable

use of com.revolsys.record.code.CodeTable in project com.revolsys.open by revolsys.

the class AbstractRecordTableModel method toDisplayValue.

public String toDisplayValue(final int rowIndex, final int attributeIndex, final Object objectValue) {
    String text;
    final RecordDefinition recordDefinition = getRecordDefinition();
    final String fieldName = getColumnFieldName(attributeIndex);
    if (objectValue == null || fieldName == null) {
        if (recordDefinition.isIdField(fieldName)) {
            return "NEW";
        } else {
            text = "-";
        }
    } else {
        if (objectValue instanceof Geometry) {
            final Geometry geometry = (Geometry) objectValue;
            return geometry.getGeometryType();
        }
        CodeTable codeTable = null;
        if (!recordDefinition.isIdField(fieldName)) {
            codeTable = recordDefinition.getCodeTableByFieldName(fieldName);
        }
        if (codeTable == null) {
            text = DataTypes.toString(objectValue);
        } else {
            if (codeTable.isLoaded()) {
                final List<Object> values = codeTable.getValues(Identifier.newIdentifier(objectValue));
                if (values == null || values.isEmpty()) {
                    text = DataTypes.toString(objectValue);
                } else {
                    text = Strings.toString(values);
                }
            } else {
                if (!codeTable.isLoading()) {
                    final CodeTable tableToLoad = codeTable;
                    Invoke.background("Load " + codeTable, () -> loadCodeTable(tableToLoad));
                }
                text = "...";
            }
        }
        if (text.length() == 0) {
            text = "-";
        }
    }
    return text;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) CodeTable(com.revolsys.record.code.CodeTable) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 30 with CodeTable

use of com.revolsys.record.code.CodeTable in project com.revolsys.open by revolsys.

the class RecordRowTableModel method toCopyValue.

@Override
public String toCopyValue(final int rowIndex, int fieldIndex, final Object recordValue) {
    if (fieldIndex < this.fieldsOffset) {
        return DataTypes.toString(recordValue);
    } else {
        fieldIndex -= this.fieldsOffset;
        String text;
        final RecordDefinition recordDefinition = getRecordDefinition();
        final String fieldName = getColumnFieldName(fieldIndex);
        if (recordValue == null) {
            return null;
        } else {
            if (recordValue instanceof Geometry) {
                final Geometry geometry = (Geometry) recordValue;
                return geometry.toString();
            }
            CodeTable codeTable = null;
            if (!recordDefinition.isIdField(fieldName)) {
                codeTable = recordDefinition.getCodeTableByFieldName(fieldName);
            }
            if (codeTable == null) {
                text = DataTypes.toString(recordValue);
            } else {
                final List<Object> values = codeTable.getValues(Identifier.newIdentifier(recordValue));
                if (values == null || values.isEmpty()) {
                    return null;
                } else {
                    text = Strings.toString(values);
                }
            }
            if (text.length() == 0) {
                return null;
            }
        }
        return text;
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) CodeTable(com.revolsys.record.code.CodeTable) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

CodeTable (com.revolsys.record.code.CodeTable)30 RecordDefinition (com.revolsys.record.schema.RecordDefinition)15 FieldDefinition (com.revolsys.record.schema.FieldDefinition)9 Identifier (com.revolsys.identifier.Identifier)6 ArrayList (java.util.ArrayList)5 Geometry (com.revolsys.geometry.model.Geometry)4 DataType (com.revolsys.datatype.DataType)3 PathName (com.revolsys.io.PathName)3 BetweenOperatorNode (com.akiban.sql.parser.BetweenOperatorNode)2 BinaryArithmeticOperatorNode (com.akiban.sql.parser.BinaryArithmeticOperatorNode)2 BinaryLogicalOperatorNode (com.akiban.sql.parser.BinaryLogicalOperatorNode)2 BinaryOperatorNode (com.akiban.sql.parser.BinaryOperatorNode)2 CastNode (com.akiban.sql.parser.CastNode)2 ColumnReference (com.akiban.sql.parser.ColumnReference)2 ConstantNode (com.akiban.sql.parser.ConstantNode)2 InListOperatorNode (com.akiban.sql.parser.InListOperatorNode)2 IsNullNode (com.akiban.sql.parser.IsNullNode)2 LikeEscapeOperatorNode (com.akiban.sql.parser.LikeEscapeOperatorNode)2 NotNode (com.akiban.sql.parser.NotNode)2 NumericConstantNode (com.akiban.sql.parser.NumericConstantNode)2