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;
}
}
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();
}
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;
}
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;
}
}
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();
}
}
Aggregations