Search in sources :

Example 31 with Identifier

use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.

the class FileGdbDomainCodeTable method newIdentifier.

private Identifier newIdentifier(final String name) {
    synchronized (this.recordStore) {
        final Identifier id = this.domain.newCodedValue(name);
        this.recordStore.alterDomain(this.domain);
        Logs.info(this, this.domain.getDomainName() + " created code " + id + "=" + name);
        return id;
    }
}
Also used : Identifier(com.revolsys.identifier.Identifier)

Example 32 with Identifier

use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.

the class OpenStreetMapApiLayer method getRecords.

@Override
public List<LayerRecord> getRecords(BoundingBox boundingBox) {
    if (hasGeometryField()) {
        boundingBox = convertBoundingBox(boundingBox);
        if (Property.hasValue(boundingBox)) {
            final Map<Identifier, LayerRecord> recordMap = new HashMap<>();
            final List<BoundingBox> boundingBoxes = getTileBoundingBoxes(boundingBox);
            for (final BoundingBox tileBoundingBox : boundingBoxes) {
                final OsmDocument document = getTile(tileBoundingBox);
                for (final OsmElement record : document.getRecords()) {
                    final Geometry geometry = record.getGeometry();
                    if (geometry != null && !geometry.isEmpty()) {
                        if (boundingBox.intersects(geometry.getBoundingBox())) {
                            final Identifier identifier = record.getIdentifier();
                            final OsmProxyLayerRecord layerRecord = new OsmProxyLayerRecord(this, document, identifier);
                            recordMap.put(identifier, layerRecord);
                        }
                    }
                }
            }
            this.boundingBoxTileMap.keySet().retainAll(boundingBoxes);
            return new ArrayList<>(recordMap.values());
        }
    }
    return Collections.emptyList();
}
Also used : OsmElement(com.revolsys.record.io.format.openstreetmap.model.OsmElement) Geometry(com.revolsys.geometry.model.Geometry) Identifier(com.revolsys.identifier.Identifier) HashMap(java.util.HashMap) BoundingBox(com.revolsys.geometry.model.BoundingBox) ArrayList(java.util.ArrayList) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) OsmDocument(com.revolsys.record.io.format.openstreetmap.model.OsmDocument)

Example 33 with Identifier

use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.

the class FieldDefinition method validate.

public Object validate(Object value) {
    final String fieldName = getName();
    value = toFieldValueException(value);
    if (value == null) {
        if (isRequired()) {
            throw new IllegalArgumentException(fieldName + " is required");
        }
    } else {
        final RecordDefinition recordDefinition = getRecordDefinition();
        final CodeTable codeTable = recordDefinition.getCodeTableByFieldName(fieldName);
        if (codeTable == null) {
            final int maxLength = getLength();
            if (value instanceof Number) {
                final Number number = (Number) value;
                final BigDecimal bigNumber = new BigDecimal(number.toString());
                final int length = bigNumber.precision();
                if (maxLength > 0) {
                    if (length > maxLength) {
                        throw new IllegalArgumentException(fieldName + "=" + value + " length " + length + " > " + maxLength);
                    }
                }
                final int scale = bigNumber.scale();
                final int maxScale = getScale();
                if (maxScale > 0) {
                    if (scale > maxScale) {
                        throw new IllegalArgumentException(fieldName + "=" + value + " scale " + scale + " > " + maxScale);
                    }
                }
                final Number minValue = getMinValue();
                if (minValue != null) {
                    if (NumericComparator.numericCompare(number, minValue) < 0) {
                        throw new IllegalArgumentException(fieldName + "=" + value + " > " + minValue);
                    }
                }
                final Number maxValue = getMaxValue();
                if (maxValue != null) {
                    if (NumericComparator.numericCompare(number, maxValue) > 0) {
                        throw new IllegalArgumentException(fieldName + "=" + value + " < " + maxValue);
                    }
                }
            } else if (value instanceof String) {
                final String string = (String) value;
                final int length = string.length();
                if (maxLength > 0) {
                    if (length > maxLength) {
                        throw new IllegalArgumentException(fieldName + "=" + value + " length " + length + " > " + maxLength);
                    }
                }
            } else if (value instanceof Geometry) {
                final Geometry geometry = (Geometry) value;
                final IsValidOp validOp = new IsValidOp(geometry, false);
                if (!validOp.isValid()) {
                    final String errors = Strings.toString(validOp.getErrors());
                    throw new IllegalArgumentException("Geometry not valid: " + errors);
                }
            }
            if (!this.allowedValues.isEmpty()) {
                if (!this.allowedValues.containsKey(value)) {
                    throw new IllegalArgumentException(fieldName + "=" + value + " not in (" + Strings.toString(",", this.allowedValues) + ")");
                }
            }
        } else {
            final Identifier id = codeTable.getIdentifier(value);
            if (id == null) {
                String codeTableName;
                if (codeTable instanceof CodeTableProperty) {
                    @SuppressWarnings("resource") final CodeTableProperty property = (CodeTableProperty) codeTable;
                    codeTableName = property.getTypeName();
                } else {
                    codeTableName = codeTable.toString();
                }
                throw new IllegalArgumentException("Unable to find code for '" + value + "' in " + codeTableName);
            }
        }
    }
    return value;
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) Geometry(com.revolsys.geometry.model.Geometry) Identifier(com.revolsys.identifier.Identifier) IsValidOp(com.revolsys.geometry.operation.valid.IsValidOp) BigDecimal(java.math.BigDecimal) CodeTableProperty(com.revolsys.record.code.CodeTableProperty)

Example 34 with Identifier

use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.

the class RecordStore method newRecord.

default Record newRecord(final PathName typePath, final Map<String, ? extends Object> values) {
    final RecordDefinition recordDefinition = getRecordDefinition(typePath);
    if (recordDefinition == null) {
        throw new IllegalArgumentException("Cannot find table " + typePath + " for " + this);
    } else {
        final Record record = newRecord(recordDefinition);
        if (record != null) {
            record.setValues(values);
            final String idFieldName = recordDefinition.getIdFieldName();
            if (Property.hasValue(idFieldName)) {
                if (values.get(idFieldName) == null) {
                    final Identifier id = newPrimaryIdentifier(typePath);
                    record.setIdentifier(id);
                }
            }
        }
        return record;
    }
}
Also used : Identifier(com.revolsys.identifier.Identifier) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord)

Example 35 with Identifier

use of com.revolsys.identifier.Identifier in project com.revolsys.open by revolsys.

the class GeometryTest method doWriteTest.

private void doWriteTest(final DataType geometryType, final int axisCount, final int partCount, final int ringCount) {
    final GeometryFactory sourceGeometryFactory = GeometryFactory.floating(3857, axisCount);
    String typeName = geometryType.getName().toUpperCase();
    typeName = typeName.replace("MULTI", "MULTI_");
    final PathName typePath = PathName.newPathName("/ORACLE_TEST/" + typeName + axisCount);
    Geometry geometry = GeometryTestUtil.geometry(sourceGeometryFactory, geometryType, axisCount, partCount, ringCount);
    if (geometry instanceof Polygonal) {
        geometry = geometry.toCounterClockwise();
    }
    try (Transaction transaction = this.recordStore.newTransaction(Propagation.REQUIRES_NEW)) {
        final RecordDefinition recordDefinition = this.recordStore.getRecordDefinition(typePath);
        final Record record = this.recordStore.newRecord(typePath, Collections.singletonMap("GEOMETRY", geometry));
        try (Writer<Record> writer = this.recordStore.newRecordWriter()) {
            writer.write(record);
        }
        final Identifier identifier = record.getIdentifier();
        final Record savedRecord = this.recordStore.getRecord(typePath, identifier);
        Assert.assertNotNull("Saved record", savedRecord);
        final Geometry savedGeometry = savedRecord.getGeometry();
        final GeometryFactory tableGeometryFactory = recordDefinition.getGeometryFactory();
        final Geometry expectedGeometry = geometry.convertGeometry(tableGeometryFactory);
        com.revolsys.geometry.util.Assert.equals("Saved geometry", savedGeometry.equalsExact(expectedGeometry), expectedGeometry, savedGeometry);
        transaction.setRollbackOnly();
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Identifier(com.revolsys.identifier.Identifier) Transaction(com.revolsys.transaction.Transaction) Polygonal(com.revolsys.geometry.model.Polygonal) Record(com.revolsys.record.Record) PathName(com.revolsys.io.PathName) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

Identifier (com.revolsys.identifier.Identifier)56 Record (com.revolsys.record.Record)17 ArrayList (java.util.ArrayList)12 RecordDefinition (com.revolsys.record.schema.RecordDefinition)11 SingleIdentifier (com.revolsys.identifier.SingleIdentifier)8 ListIdentifier (com.revolsys.identifier.ListIdentifier)7 TypedIdentifier (com.revolsys.identifier.TypedIdentifier)6 CodeTable (com.revolsys.record.code.CodeTable)6 RecordReader (com.revolsys.record.io.RecordReader)5 RecordStore (com.revolsys.record.schema.RecordStore)5 Transaction (com.revolsys.transaction.Transaction)5 List (java.util.List)5 Geometry (com.revolsys.geometry.model.Geometry)4 BaseCloseable (com.revolsys.io.BaseCloseable)4 PathName (com.revolsys.io.PathName)4 ArrayRecord (com.revolsys.record.ArrayRecord)4 Query (com.revolsys.record.query.Query)4 OsmElement (com.revolsys.record.io.format.openstreetmap.model.OsmElement)3 FieldDefinition (com.revolsys.record.schema.FieldDefinition)3 CompoundCoordinateSystem (com.revolsys.geometry.cs.CompoundCoordinateSystem)2