use of org.opengis.feature.type.PropertyDescriptor in project GeoGig by boundlessgeo.
the class DefaultStepDefinitions method I_have_a_patch_file.
@Given("^I have a patch file$")
public void I_have_a_patch_file() throws Throwable {
Patch patch = new Patch();
String path = NodeRef.appendChild(pointsName, points1.getIdentifier().getID());
Map<PropertyDescriptor, AttributeDiff> map = Maps.newHashMap();
Optional<?> oldValue = Optional.fromNullable(points1.getProperty("sp").getValue());
GenericAttributeDiffImpl diff = new GenericAttributeDiffImpl(oldValue, Optional.of("new"));
map.put(pointsType.getDescriptor("sp"), diff);
FeatureDiff feaureDiff = new FeatureDiff(path, map, RevFeatureTypeImpl.build(pointsType), RevFeatureTypeImpl.build(pointsType));
patch.addModifiedFeature(feaureDiff);
File file = new File(platform.pwd(), "test.patch");
BufferedWriter writer = Files.newWriter(file, Charsets.UTF_8);
PatchSerializer.write(writer, patch);
writer.flush();
writer.close();
}
use of org.opengis.feature.type.PropertyDescriptor in project GeoGig by boundlessgeo.
the class RevFeatureTypeImpl method toString.
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("FeatureType[");
builder.append(getId().toString());
builder.append("; ");
boolean first = true;
for (PropertyDescriptor desc : sortedDescriptors()) {
if (first) {
first = false;
} else {
builder.append(", ");
}
builder.append(desc.getName().getLocalPart());
builder.append(": ");
builder.append(desc.getType().getBinding().getSimpleName());
}
builder.append(']');
return builder.toString();
}
use of org.opengis.feature.type.PropertyDescriptor in project GeoGig by boundlessgeo.
the class DescribeFeatureTypeTest method testDescribeFeatureType.
@Test
public void testDescribeFeatureType() throws Exception {
DescribeFeatureType describe = new DescribeFeatureType();
ImmutableSet<PropertyDescriptor> properties = describe.setFeatureType(featureType).call();
for (PropertyDescriptor prop : properties) {
assertTrue(pointsType.getDescriptors().contains(prop));
}
}
use of org.opengis.feature.type.PropertyDescriptor in project GeoGig by boundlessgeo.
the class ApplyPatchOp method applyPatch.
private void applyPatch(Patch patch) {
final WorkingTree workTree = workingTree();
final StagingDatabase indexDb = stagingDatabase();
if (reverse) {
patch = patch.reversed();
}
List<FeatureInfo> removed = patch.getRemovedFeatures();
for (FeatureInfo feature : removed) {
workTree.delete(NodeRef.parentPath(feature.getPath()), NodeRef.nodeFromPath(feature.getPath()));
}
List<FeatureInfo> added = patch.getAddedFeatures();
for (FeatureInfo feature : added) {
workTree.insert(NodeRef.parentPath(feature.getPath()), feature.getFeature());
}
List<FeatureDiff> diffs = patch.getModifiedFeatures();
for (FeatureDiff diff : diffs) {
String path = diff.getPath();
DepthSearch depthSearch = new DepthSearch(indexDb);
Optional<NodeRef> noderef = depthSearch.find(workTree.getTree(), path);
RevFeatureType oldRevFeatureType = command(RevObjectParse.class).setObjectId(noderef.get().getMetadataId()).call(RevFeatureType.class).get();
String refSpec = Ref.WORK_HEAD + ":" + path;
RevFeature feature = command(RevObjectParse.class).setRefSpec(refSpec).call(RevFeature.class).get();
RevFeatureType newRevFeatureType = getFeatureType(diff, feature, oldRevFeatureType);
ImmutableList<Optional<Object>> values = feature.getValues();
ImmutableList<PropertyDescriptor> oldDescriptors = oldRevFeatureType.sortedDescriptors();
ImmutableList<PropertyDescriptor> newDescriptors = newRevFeatureType.sortedDescriptors();
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder((SimpleFeatureType) newRevFeatureType.type());
Map<Name, Optional<?>> attrs = Maps.newHashMap();
for (int i = 0; i < oldDescriptors.size(); i++) {
PropertyDescriptor descriptor = oldDescriptors.get(i);
if (newDescriptors.contains(descriptor)) {
Optional<Object> value = values.get(i);
attrs.put(descriptor.getName(), value);
}
}
Set<Entry<PropertyDescriptor, AttributeDiff>> featureDiffs = diff.getDiffs().entrySet();
for (Iterator<Entry<PropertyDescriptor, AttributeDiff>> iterator = featureDiffs.iterator(); iterator.hasNext(); ) {
Entry<PropertyDescriptor, AttributeDiff> entry = iterator.next();
if (!entry.getValue().getType().equals(TYPE.REMOVED)) {
Optional<?> oldValue = attrs.get(entry.getKey().getName());
attrs.put(entry.getKey().getName(), entry.getValue().applyOn(oldValue));
}
}
Set<Entry<Name, Optional<?>>> entries = attrs.entrySet();
for (Iterator<Entry<Name, Optional<?>>> iterator = entries.iterator(); iterator.hasNext(); ) {
Entry<Name, Optional<?>> entry = iterator.next();
featureBuilder.set(entry.getKey(), entry.getValue().orNull());
}
SimpleFeature featureToInsert = featureBuilder.buildFeature(NodeRef.nodeFromPath(path));
workTree.insert(NodeRef.parentPath(path), featureToInsert);
}
ImmutableList<FeatureTypeDiff> alteredTrees = patch.getAlteredTrees();
for (FeatureTypeDiff diff : alteredTrees) {
Optional<RevFeatureType> featureType;
if (diff.getOldFeatureType().isNull()) {
featureType = patch.getFeatureTypeFromId(diff.getNewFeatureType());
workTree.createTypeTree(diff.getPath(), featureType.get().type());
} else if (diff.getNewFeatureType().isNull()) {
workTree.delete(diff.getPath());
} else {
featureType = patch.getFeatureTypeFromId(diff.getNewFeatureType());
workTree.updateTypeTree(diff.getPath(), featureType.get().type());
}
}
}
use of org.opengis.feature.type.PropertyDescriptor in project GeoGig by boundlessgeo.
the class ApplyPatchOp method getFeatureType.
private RevFeatureType getFeatureType(FeatureDiff diff, RevFeature oldFeature, RevFeatureType oldRevFeatureType) {
List<String> removed = Lists.newArrayList();
List<AttributeDescriptor> added = Lists.newArrayList();
Set<Entry<PropertyDescriptor, AttributeDiff>> featureDiffs = diff.getDiffs().entrySet();
for (Iterator<Entry<PropertyDescriptor, AttributeDiff>> iterator = featureDiffs.iterator(); iterator.hasNext(); ) {
Entry<PropertyDescriptor, AttributeDiff> entry = iterator.next();
if (entry.getValue().getType() == TYPE.REMOVED) {
removed.add(entry.getKey().getName().getLocalPart());
} else if (entry.getValue().getType() == TYPE.ADDED) {
PropertyDescriptor pd = entry.getKey();
added.add((AttributeDescriptor) pd);
}
}
SimpleFeatureType sft = (SimpleFeatureType) oldRevFeatureType.type();
List<AttributeDescriptor> descriptors = (sft).getAttributeDescriptors();
SimpleFeatureTypeBuilder featureTypeBuilder = new SimpleFeatureTypeBuilder();
featureTypeBuilder.setCRS(sft.getCoordinateReferenceSystem());
featureTypeBuilder.setDefaultGeometry(sft.getGeometryDescriptor().getLocalName());
featureTypeBuilder.setName(sft.getName());
for (int i = 0; i < descriptors.size(); i++) {
AttributeDescriptor descriptor = descriptors.get(i);
if (!removed.contains(descriptor.getName().getLocalPart())) {
featureTypeBuilder.add(descriptor);
}
}
for (AttributeDescriptor descriptor : added) {
featureTypeBuilder.add(descriptor);
}
SimpleFeatureType featureType = featureTypeBuilder.buildFeatureType();
return RevFeatureTypeImpl.build(featureType);
}
Aggregations