use of org.locationtech.geogig.api.RevFeatureType in project GeoGig by boundlessgeo.
the class PatchSerializer method addElement.
private static void addElement(List<String> lines, Patch patch, Map<String, RevFeatureType> featureTypes) {
String[] headerTokens = lines.get(0).split("\t");
if (headerTokens.length == 4 || headerTokens.length == 3) {
// modified // modification
if (lines.size() == 1) {
// feature type
FeatureTypeDiff diff = new FeatureTypeDiff(headerTokens[0], ObjectId.valueOf(headerTokens[1]), ObjectId.valueOf(headerTokens[2]));
patch.addAlteredTree(diff);
} else {
// feature
String element = Joiner.on("\n").join(lines.subList(1, lines.size()));
ByteArrayInputStream stream;
stream = new ByteArrayInputStream(element.getBytes(Charsets.UTF_8));
String operation = headerTokens[0].trim();
if (operation.equals("M")) {
String fullPath = headerTokens[1].trim();
String oldMetadataId = headerTokens[2].trim();
String newMetadataId = headerTokens[3].trim();
RevFeatureType newRevFeatureType = featureTypes.get(newMetadataId);
RevFeatureType oldRevFeatureType = featureTypes.get(oldMetadataId);
Map<PropertyDescriptor, AttributeDiff> map = Maps.newHashMap();
for (int i = 1; i < lines.size(); i++) {
addDifference(lines.get(i), map, oldRevFeatureType, newRevFeatureType);
}
FeatureDiff featureDiff = new FeatureDiff(fullPath, map, oldRevFeatureType, newRevFeatureType);
patch.addModifiedFeature(featureDiff);
} else if (operation.equals("A") || operation.equals("R")) {
String fullPath = headerTokens[1].trim();
String featureTypeId = headerTokens[2].trim();
RevFeatureType revFeatureType;
revFeatureType = featureTypes.get(featureTypeId);
FeatureBuilder featureBuilder = new FeatureBuilder(revFeatureType);
ObjectReader<RevFeature> reader = factory.createFeatureReader();
RevFeature revFeature = reader.read(null, stream);
Feature feature = featureBuilder.build(NodeRef.nodeFromPath(fullPath), revFeature);
if (operation.equals("R")) {
patch.addRemovedFeature(fullPath, feature, revFeatureType);
} else {
patch.addAddedFeature(fullPath, feature, revFeatureType);
}
} else {
throw new IllegalArgumentException("Wrong patch content: " + lines.get(0));
}
}
} else if (headerTokens.length == 1) {
// feature type definition
String element = Joiner.on("\n").join(lines);
ByteArrayInputStream stream = new ByteArrayInputStream(element.getBytes(Charsets.UTF_8));
String[] tokens = lines.get(1).split("\t");
ObjectReader<RevFeatureType> reader = factory.createFeatureTypeReader();
RevFeatureType featureType = reader.read(null, stream);
featureTypes.put(featureType.getId().toString(), featureType);
} else {
throw new IllegalArgumentException("Wrong patch content: " + lines.get(0));
}
}
use of org.locationtech.geogig.api.RevFeatureType in project GeoGig by boundlessgeo.
the class CommitOpTest method testCommitAddsFeatureTypeToObjectDatabase.
@Test
public void testCommitAddsFeatureTypeToObjectDatabase() throws Exception {
insertAndAdd(points1);
ObjectId id = RevFeatureTypeImpl.build(pointsType).getId();
geogig.command(AddOp.class).addPattern(".").call();
RevCommit commit = geogig.command(CommitOp.class).call();
assertNotNull(commit);
RevFeatureType type = geogig.getRepository().objectDatabase().getFeatureType(id);
assertEquals(id, type.getId());
}
use of org.locationtech.geogig.api.RevFeatureType in project GeoGig by boundlessgeo.
the class ShpExportDiff method getFeatureType.
private SimpleFeatureType getFeatureType(String path, GeogigCLI cli) {
checkParameter(path != null, "No path specified.");
String refspec;
if (path.contains(":")) {
refspec = path;
} else {
refspec = "WORK_HEAD:" + path;
}
checkParameter(!refspec.endsWith(":"), "No path specified.");
final GeoGIG geogig = cli.getGeogig();
Optional<ObjectId> rootTreeId = geogig.command(ResolveTreeish.class).setTreeish(refspec.split(":")[0]).call();
checkParameter(rootTreeId.isPresent(), "Couldn't resolve '" + refspec + "' to a treeish object");
RevTree rootTree = geogig.getRepository().getTree(rootTreeId.get());
Optional<NodeRef> featureTypeTree = geogig.command(FindTreeChild.class).setChildPath(refspec.split(":")[1]).setParent(rootTree).setIndex(true).call();
checkParameter(featureTypeTree.isPresent(), "pathspec '" + refspec.split(":")[1] + "' did not match any valid path");
Optional<RevObject> revObject = cli.getGeogig().command(RevObjectParse.class).setObjectId(featureTypeTree.get().getMetadataId()).call();
if (revObject.isPresent() && revObject.get() instanceof RevFeatureType) {
RevFeatureType revFeatureType = (RevFeatureType) revObject.get();
if (revFeatureType.type() instanceof SimpleFeatureType) {
return (SimpleFeatureType) revFeatureType.type();
} else {
throw new InvalidParameterException("Cannot find feature type for the specified path");
}
} else {
throw new InvalidParameterException("Cannot find feature type for the specified path");
}
}
use of org.locationtech.geogig.api.RevFeatureType in project GeoGig by boundlessgeo.
the class ExportOp method getFeatures.
private static Iterator<SimpleFeature> getFeatures(final RevTree typeTree, final ObjectDatabase database, final ObjectId defaultMetadataId, final ProgressListener progressListener) {
Iterator<NodeRef> nodes = new DepthTreeIterator("", defaultMetadataId, typeTree, database, Strategy.FEATURES_ONLY);
// progress reporting
nodes = Iterators.transform(nodes, new Function<NodeRef, NodeRef>() {
private AtomicInteger count = new AtomicInteger();
@Override
public NodeRef apply(NodeRef input) {
progressListener.setProgress((count.incrementAndGet() * 100.f) / typeTree.size());
return input;
}
});
Function<NodeRef, SimpleFeature> asFeature = new Function<NodeRef, SimpleFeature>() {
private Map<ObjectId, FeatureBuilder> ftCache = Maps.newHashMap();
@Override
@Nullable
public SimpleFeature apply(final NodeRef input) {
final ObjectId metadataId = input.getMetadataId();
final RevFeature revFeature = database.getFeature(input.objectId());
FeatureBuilder featureBuilder = getBuilderFor(metadataId);
Feature feature = featureBuilder.build(input.name(), revFeature);
feature.getUserData().put(Hints.USE_PROVIDED_FID, true);
feature.getUserData().put(RevFeature.class, revFeature);
feature.getUserData().put(RevFeatureType.class, featureBuilder.getType());
if (feature instanceof SimpleFeature) {
return (SimpleFeature) feature;
}
return null;
}
private FeatureBuilder getBuilderFor(final ObjectId metadataId) {
FeatureBuilder featureBuilder = ftCache.get(metadataId);
if (featureBuilder == null) {
RevFeatureType revFtype = database.getFeatureType(metadataId);
featureBuilder = new FeatureBuilder(revFtype);
ftCache.put(metadataId, featureBuilder);
}
return featureBuilder;
}
};
Iterator<SimpleFeature> asFeatures = Iterators.transform(nodes, asFeature);
UnmodifiableIterator<SimpleFeature> filterNulls = Iterators.filter(asFeatures, Predicates.notNull());
return filterNulls;
}
use of org.locationtech.geogig.api.RevFeatureType in project GeoGig by boundlessgeo.
the class CachingModuleTest method ft.
private static RevFeatureType ft(String name) {
SimpleFeatureType type;
try {
type = DataUtilities.createType("", name, RepositoryTestCase.pointsTypeSpec);
} catch (SchemaException e) {
throw Throwables.propagate(e);
}
RevFeatureType rft = RevFeatureTypeImpl.build(type);
return rft;
}
Aggregations