use of org.activityinfo.geoadmin.merge2.view.profile.FieldProfile in project activityinfo by bedatadriven.
the class FormMappingBuilder method build.
public Observable<List<FieldMapping>> build() {
// the source to the target field
for (FieldProfile targetField : target.getFields()) {
if (targetField.getNode().isRoot())
if (SimpleFieldMapping.isSimple(targetField)) {
buildSimpleMapping(targetField);
}
}
// Add mappings for ReferenceFields, for which we have to perform look ups
for (FormTree.Node targetNode : target.getFormTree().getRootFields()) {
if (targetNode.isReference()) {
buildReferenceMapping(targetNode.getField());
}
}
// Add mapping for geography, IIF source and target have exactly one GeoArea
Set<FormField> targetGeoFields = findGeoFields(target.getFormTree());
Set<FormField> sourceGeoFields = findGeoFields(source.getFormTree());
if (targetGeoFields.size() == 1 && sourceGeoFields.size() == 1) {
FormField sourceField = Iterables.getOnlyElement(sourceGeoFields);
FormField targetField = Iterables.getOnlyElement(targetGeoFields);
mappings.add(Observable.<FieldMapping>just(new GeoAreaFieldMapping(source.getField(sourceField.getId()), targetField)));
}
return Observable.flatten(SynchronousScheduler.INSTANCE, mappings);
}
use of org.activityinfo.geoadmin.merge2.view.profile.FieldProfile in project activityinfo by bedatadriven.
the class FieldScoreMatrix method calculateScore.
private double calculateScore(int i, int j) {
FieldProfile x = sourceColumns.get(i);
FieldProfile y = targetColumns.get(j);
if (x.isText() && y.isText()) {
return scoreTextColumnMatch(x, y);
} else if (x.isGeoArea() && y.isGeoArea()) {
return scoreGeoAreaMatch(x, y);
} else {
return 0;
}
}
use of org.activityinfo.geoadmin.merge2.view.profile.FieldProfile in project activityinfo by bedatadriven.
the class LookupDialogTableModel method getValueAt.
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
if (columnIndex == SCORE_COLUMN) {
return scoreFormat.format(scores[rowIndex]);
} else {
int targetRow = targetCandidateRows.get(rowIndex);
FieldProfile targetField = targetKeyFields.get(columnIndex - 1);
return targetField.getView().getString(targetRow);
}
}
use of org.activityinfo.geoadmin.merge2.view.profile.FieldProfile in project activityinfo by bedatadriven.
the class LookupDialog method buildReferenceMatch.
/**
* Build a ReferenceMatch that can be stored as part of the model.
* since this will form part of the model "state" it cannot depend
* on computed values in any way, so we need to map our row indices and SourceKeys
* back to the original ids.
*
* @param candidateIndex the index within the list of candidate target matches (from LookupGraph)
*/
private ReferenceMatch buildReferenceMatch(int candidateIndex) {
ResourceId targetId = tableModel.getTargetInstanceId(candidateIndex);
Map<FieldPath, String> keyMap = new HashMap<>();
java.util.List<FieldProfile> keyFields = lookupTable.getSourceKeyFields();
for (int i = 0; i < keyFields.size(); i++) {
keyMap.put(keyFields.get(i).getPath(), sourceKey.get(i));
}
return new ReferenceMatch(keyMap, targetId);
}
use of org.activityinfo.geoadmin.merge2.view.profile.FieldProfile in project activityinfo by bedatadriven.
the class ImportView method updateGeometry.
private void updateGeometry(GeoAdminClient client, Map<ResourceId, ResourceId> idMap) throws IOException {
FeatureSourceStorageProvider catalog = new FeatureSourceStorageProvider();
FeatureSourceStorage formStorage = (FeatureSourceStorage) catalog.getForm(getModel().getSourceFormId().get()).get();
ResourceId targetFormId = getModel().getTargetFormId().get();
FieldProfile targetField = getTargetProfile().get().getGeometryField();
if (targetField == null) {
System.err.println("No geometry field to update.");
return;
}
int sourceIndex = formStorage.getGeometryAttributeIndex();
if (sourceIndex == -1) {
System.err.println("No source geometry field.");
return;
}
SimpleFeatureSource featureSource = formStorage.getFeatureSource();
GeometryType geometryType = (GeometryType) featureSource.getSchema().getDescriptor(sourceIndex).getType();
GeometryConverter converter = new GeometryConverter(geometryType);
SimpleFeatureIterator it = featureSource.getFeatures().features();
while (it.hasNext()) {
SimpleFeature feature = it.next();
ResourceId sourceId = ResourceId.valueOf(feature.getID());
ResourceId targetId = idMap.get(sourceId);
if (targetId != null) {
Geometry geometry = converter.toWgs84(feature.getAttribute(sourceIndex));
System.out.print("Updating geometry for " + targetId + " [" + geometry.getGeometryType() + "] ... ");
try {
client.updateGeometry(targetFormId, targetId, targetField.getId(), geometry);
System.out.println("OK");
} catch (Exception e) {
System.out.println("ERROR: " + e.getMessage());
}
}
}
}
Aggregations