use of com.revolsys.record.ArrayRecord in project com.revolsys.open by revolsys.
the class FieldCalculator method updateRecord.
@Override
protected void updateRecord(final LayerRecord record) {
final Bindings bindings = newBindings();
bindings.putAll(record);
bindings.put("record", new ArrayRecord(record));
try {
final FieldDefinition fieldDefinition = getFieldDefinition();
final String fieldName = fieldDefinition.getName();
Object value = this.script.eval(bindings);
value = fieldDefinition.toFieldValueException(value);
record.setValue(fieldName, value);
} catch (final ScriptException e) {
Exceptions.throwUncheckedException(e);
}
}
use of com.revolsys.record.ArrayRecord in project com.revolsys.open by revolsys.
the class FieldCalculator method validateExpression.
private void validateExpression() {
boolean valid = true;
final String scriptText = this.expressionField.getText();
if (scriptText.isEmpty()) {
valid = false;
} else {
try {
this.script = this.scriptEngineCompiler.compile(scriptText);
final Bindings bindings = newBindings();
final AbstractRecordLayer layer = getLayer();
final RecordDefinition recordDefinition = layer.getRecordDefinition();
final Record record = new ArrayRecord(recordDefinition);
for (final FieldDefinition field : layer.getFieldDefinitions()) {
bindings.put(field.getName(), null);
}
bindings.put("record", record);
this.script.eval(bindings);
this.errorsField.setText(null);
} catch (final Throwable e) {
String errorMessage = e.getMessage();
if (!Property.hasValue(errorMessage)) {
errorMessage = "null pointer";
}
this.errorsField.setText(errorMessage);
this.errorsField.setCaretPosition(0);
valid = false;
this.script = null;
}
}
setFormValid(valid);
}
use of com.revolsys.record.ArrayRecord in project com.revolsys.open by revolsys.
the class MergeRecordsDialog method run.
public void run() {
try {
final List<LayerRecord> originalRecords = this.layer.getMergeableSelectedRecords();
String errorMessage = "";
final DataType geometryType = this.layer.getGeometryType();
this.mergedRecords = new HashMap<>();
if (originalRecords.size() < 2) {
errorMessage = " at least two records must be selected to merge.";
} else if (!DataTypes.LINE_STRING.equals(geometryType) && !DataTypes.MULTI_LINE_STRING.equals(geometryType)) {
errorMessage = "Merging " + geometryType + " not currently supported";
} else {
final RecordGraph graph = new RecordGraph();
for (final LayerRecord originalRecord : originalRecords) {
Geometry geometry = originalRecord.getGeometry();
if (geometry != null && !geometry.isEmpty()) {
geometry = this.layer.getGeometryFactory().geometry(LineString.class, geometry);
if (geometry instanceof LineString) {
final Record mergeableRecord = new ArrayRecord(originalRecord);
mergeableRecord.setGeometryValue(geometry);
this.mergeableToOiginalRecordMap.put(mergeableRecord, originalRecord);
graph.addEdge(mergeableRecord);
}
}
}
for (final Node<Record> node : graph.nodes()) {
if (node != null) {
final List<Edge<Record>> edges = node.getEdges();
if (edges.size() == 2) {
final Edge<Record> edge1 = edges.get(0);
final Record record1 = edge1.getObject();
final Edge<Record> edge2 = edges.get(1);
final Record record2 = edge2.getObject();
if (record1 != record2) {
final Record mergedRecord = this.layer.getMergedRecord(node, record1, record2);
graph.addEdge(mergedRecord);
edge1.remove();
edge2.remove();
final Set<LayerRecord> sourceRecords = new LinkedHashSet<>();
// TODO verify orientation to ensure they are in the correct
// order
// and see if they are reversed
CollectionUtil.addIfNotNull(sourceRecords, this.mergeableToOiginalRecordMap.get(record1));
CollectionUtil.addAllIfNotNull(sourceRecords, this.mergedRecords.remove(record1));
CollectionUtil.addIfNotNull(sourceRecords, this.mergeableToOiginalRecordMap.get(record2));
CollectionUtil.addAllIfNotNull(sourceRecords, this.mergedRecords.remove(record2));
this.mergedRecords.put(mergedRecord, sourceRecords);
replaceRecord(mergedRecord, record1);
replaceRecord(mergedRecord, record2);
}
}
}
}
}
final String message = errorMessage;
Invoke.later(() -> setMergedRecords(message, this.mergedRecords));
} catch (final Throwable e) {
Logs.error(this, "Error " + this, e);
}
}
use of com.revolsys.record.ArrayRecord in project com.revolsys.open by revolsys.
the class RecordWriterGeometryWriter method write.
@Override
public void write(final Geometry geometry) {
final RecordDefinition recordDefinition = Records.newGeometryRecordDefinition();
final Record object = new ArrayRecord(recordDefinition);
object.setGeometryValue(geometry);
this.writer.write(object);
}
Aggregations