/** * Returns a feature from the Head of the repository, given its full path * * Returns null if the given path doesn't resolve to a feature * * @param path the path to the feature to return */ public Feature getFeatureFromHead(String path) { String name = NodeRef.nodeFromPath(path); String refSpec = "HEAD:" + path; Optional<RevFeature> revFeature = repository.command(RevObjectParse.class) .setRefSpec(refSpec).call(RevFeature.class); if (revFeature.isPresent()) { RevFeatureType revFeatureType = repository.command(ResolveFeatureType.class) .setRefSpec(refSpec).call().get(); FeatureBuilder builder = new FeatureBuilder(revFeatureType); return builder.build(name, revFeature.get()); } else { return null; } }
@Override protected Optional<RevFeatureType> _call() { Preconditions.checkState(refSpec != null, "ref spec has not been set."); final String fullRefspec; if (refSpec.contains(":")) { fullRefspec = refSpec; } else { fullRefspec = Ref.WORK_HEAD + ":" + refSpec; } final String ref = fullRefspec.substring(0, fullRefspec.indexOf(':')); final String path = fullRefspec.substring(fullRefspec.indexOf(':') + 1); ObjectId parentId = command(ResolveTreeish.class).setTreeish(ref).call().get(); Optional<RevTree> parent = command(RevObjectParse.class).setObjectId(parentId) .call(RevTree.class); if (!parent.isPresent()) { return Optional.absent(); } Optional<NodeRef> node = command(FindTreeChild.class).setParent(parent.get()) .setChildPath(path).call(); if (!node.isPresent()) { return Optional.absent(); } NodeRef found = node.get(); ObjectId metadataID = found.getMetadataId(); Optional<RevFeatureType> ft = command(RevObjectParse.class).setObjectId(metadataID) .call(RevFeatureType.class); return ft; } }
@Test public void testNoFeatureTypeNameSpecified() { exception.expect(IllegalStateException.class); geogig.command(ResolveFeatureType.class).call(); }
@Test public void testNoFeatureTypeNameSpecified() { exception.expect(IllegalStateException.class); geogig.command(ResolveFeatureType.class).call(); }
/** * Returns a feature from the working tree of the repository, given its full path * * Returns null if the given path doesn't resolve to a feature * * @param path the path to the feature to return */ public Feature getFeatureFromWorkingTree(String path) { String name = NodeRef.nodeFromPath(path); String refSpec = "WORK_HEAD:" + path; Optional<RevFeature> revFeature = repository.command(RevObjectParse.class) .setRefSpec(refSpec).call(RevFeature.class); if (revFeature.isPresent()) { RevFeatureType revFeatureType = repository.command(ResolveFeatureType.class) .setRefSpec(refSpec).call().get(); FeatureBuilder builder = new FeatureBuilder(revFeatureType); return builder.build(name, revFeature.get()); } else { return null; } }
@Override protected Optional<RevFeatureType> _call() { Preconditions.checkState(refSpec != null, "ref spec has not been set."); final String fullRefspec; if (refSpec.contains(":")) { fullRefspec = refSpec; } else { fullRefspec = Ref.WORK_HEAD + ":" + refSpec; } final String ref = fullRefspec.substring(0, fullRefspec.indexOf(':')); final String path = fullRefspec.substring(fullRefspec.indexOf(':') + 1); ObjectId parentId = command(ResolveTreeish.class).setTreeish(ref).call().get(); Optional<RevTree> parent = command(RevObjectParse.class).setObjectId(parentId) .call(RevTree.class); if (!parent.isPresent()) { return Optional.absent(); } Optional<NodeRef> node = command(FindTreeChild.class).setParent(parent.get()) .setChildPath(path).call(); if (!node.isPresent()) { return Optional.absent(); } NodeRef found = node.get(); ObjectId metadataID = found.getMetadataId(); Optional<RevFeatureType> ft = command(RevObjectParse.class).setObjectId(metadataID) .call(RevFeatureType.class); return ft; } }
private Feature createFeature(List<String> featureChanges, Map<String, SimpleFeatureBuilder> featureTypes) { String path = featureChanges.get(0); String tree = NodeRef.parentPath(path); String featureId = NodeRef.nodeFromPath(path); if (!featureTypes.containsKey(tree)) { Optional<RevFeatureType> opt = geogig.command(ResolveFeatureType.class) .setRefSpec("WORK_HEAD:" + tree).call(); checkParameter(opt.isPresent(), "The parent tree does not exist: " + tree); SimpleFeatureBuilder builder = new SimpleFeatureBuilder( (SimpleFeatureType) opt.get().type()); featureTypes.put(tree, builder); } SimpleFeatureBuilder ftb = featureTypes.get(tree); SimpleFeatureType ft = ftb.getFeatureType(); for (int i = 1; i < featureChanges.size(); i++) { String[] tokens = featureChanges.get(i).split("\t"); Preconditions.checkArgument(tokens.length == 2, "Wrong attribute definition: " + featureChanges.get(i)); String fieldName = tokens[0]; AttributeDescriptor desc = ft.getDescriptor(fieldName); Preconditions.checkNotNull(desc, "Wrong attribute in feature description"); FieldType type = FieldType.forBinding(desc.getType().getBinding()); Object value = TextValueSerializer.fromString(type, tokens[1]); ftb.set(tokens[0], value); } return ftb.buildFeature(featureId); } }
private Feature createFeature(List<String> featureChanges, Map<String, SimpleFeatureBuilder> featureTypes) { String path = featureChanges.get(0); String tree = NodeRef.parentPath(path); String featureId = NodeRef.nodeFromPath(path); if (!featureTypes.containsKey(tree)) { Optional<RevFeatureType> opt = geogig.command(ResolveFeatureType.class) .setRefSpec("WORK_HEAD:" + tree).call(); checkParameter(opt.isPresent(), "The parent tree does not exist: " + tree); SimpleFeatureBuilder builder = new SimpleFeatureBuilder( (SimpleFeatureType) opt.get().type()); featureTypes.put(tree, builder); } SimpleFeatureBuilder ftb = featureTypes.get(tree); SimpleFeatureType ft = ftb.getFeatureType(); for (int i = 1; i < featureChanges.size(); i++) { String[] tokens = featureChanges.get(i).split("\t"); Preconditions.checkArgument(tokens.length == 2, "Wrong attribute definition: " + featureChanges.get(i)); String fieldName = tokens[0]; AttributeDescriptor desc = ft.getDescriptor(fieldName); Preconditions.checkNotNull(desc, "Wrong attribute in feature description"); FieldType type = FieldType.forBinding(desc.getType().getBinding()); Object value = TextValueSerializer.fromString(type, tokens[1]); ftb.set(tokens[0], value); } return ftb.buildFeature(featureId); } }
private Feature createFeature(List<String> featureChanges, Map<String, SimpleFeatureBuilder> featureTypes) { String path = featureChanges.get(0); String tree = NodeRef.parentPath(path); String featureId = NodeRef.nodeFromPath(path); if (!featureTypes.containsKey(tree)) { Optional<RevFeatureType> opt = geogig.command(ResolveFeatureType.class) .setRefSpec("WORK_HEAD:" + tree).call(); checkParameter(opt.isPresent(), "The parent tree does not exist: " + tree); SimpleFeatureBuilder builder = new SimpleFeatureBuilder( (SimpleFeatureType) opt.get().type()); featureTypes.put(tree, builder); } SimpleFeatureBuilder ftb = featureTypes.get(tree); SimpleFeatureType ft = ftb.getFeatureType(); for (int i = 1; i < featureChanges.size(); i++) { String[] tokens = featureChanges.get(i).split("\t"); Preconditions.checkArgument(tokens.length == 2, "Wrong attribute definition: " + featureChanges.get(i)); String fieldName = tokens[0]; AttributeDescriptor desc = ft.getDescriptor(fieldName); Preconditions.checkNotNull(desc, "Wrong attribute in feature description"); FieldType type = FieldType.forBinding(desc.getType().getBinding()); Object value = TextValueSerializer.fromString(type, tokens[1]); ftb.set(tokens[0], value); } return ftb.buildFeature(featureId); } }
protected void export(final String treeSpec, final DataStore targetStore, final String targetTableName, final ProgressListener progress) { Optional<RevFeatureType> opType = command(ResolveFeatureType.class).setRefSpec(treeSpec) .call(); checkState(opType.isPresent());
@Test public void testObjectNotInIndex() throws Exception { insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("Commit1").call(); Optional<RevFeatureType> featureType = geogig.command(ResolveFeatureType.class) .setRefSpec("WORK_HEAD:" + linesName).call(); assertFalse(featureType.isPresent()); }
protected void export(final String treeSpec, final DataStore targetStore, final String targetTableName, final ProgressListener progress) { Optional<RevFeatureType> opType = command(ResolveFeatureType.class).setRefSpec(treeSpec) .call(); checkState(opType.isPresent());
@Test public void testObjectNotInIndex() throws Exception { insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("Commit1").call(); Optional<RevFeatureType> featureType = geogig.command(ResolveFeatureType.class) .setRefSpec("WORK_HEAD:" + linesName).call(); assertFalse(featureType.isPresent()); }
@Test public void testResolveFeatureTypeFromFeatureRefspec() throws Exception { insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("Commit1").call(); Optional<RevFeatureType> featureType = geogig.command(ResolveFeatureType.class) .setRefSpec("WORK_HEAD:" + NodeRef.appendChild(pointsName, idP1)).call(); assertTrue(featureType.isPresent()); } }
@Test public void testResolveFeatureTypeFromFeatureRefspec() throws Exception { insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("Commit1").call(); Optional<RevFeatureType> featureType = geogig.command(ResolveFeatureType.class) .setRefSpec("WORK_HEAD:" + NodeRef.appendChild(pointsName, idP1)).call(); assertTrue(featureType.isPresent()); } }
@Test public void testResolveFeatureType() throws Exception { insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("Commit1").call(); Optional<RevFeatureType> featureType = geogig.command(ResolveFeatureType.class) .setRefSpec(pointsName).call(); assertTrue(featureType.isPresent()); assertEquals(pointsName, featureType.get().getName().getLocalPart()); assertEquals(TYPE.FEATURETYPE, featureType.get().getType()); }
@Test public void testResolveFeatureType() throws Exception { insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("Commit1").call(); Optional<RevFeatureType> featureType = geogig.command(ResolveFeatureType.class) .setRefSpec(pointsName).call(); assertTrue(featureType.isPresent()); assertEquals(pointsName, featureType.get().getName().getLocalPart()); assertEquals(TYPE.FEATURETYPE, featureType.get().getType()); }
@Test public void testResolveFeatureTypeWithColonInFeatureTypeName() throws Exception { insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("Commit1").call(); Optional<RevFeatureType> featureType = geogig.command(ResolveFeatureType.class) .setRefSpec("WORK_HEAD:" + pointsName).call(); assertTrue(featureType.isPresent()); assertEquals(pointsName, featureType.get().getName().getLocalPart()); assertEquals(TYPE.FEATURETYPE, featureType.get().getType()); }
@Test public void testResolveFeatureTypeWithColonInFeatureTypeName() throws Exception { insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("Commit1").call(); Optional<RevFeatureType> featureType = geogig.command(ResolveFeatureType.class) .setRefSpec("WORK_HEAD:" + pointsName).call(); assertTrue(featureType.isPresent()); assertEquals(pointsName, featureType.get().getName().getLocalPart()); assertEquals(TYPE.FEATURETYPE, featureType.get().getType()); }
@Test public void featureTypeTest() throws Exception { insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("Commit1").call(); Optional<RevFeatureType> featureType = geogig.command(ResolveFeatureType.class) .setRefSpec("WORK_HEAD:" + NodeRef.appendChild(pointsName, idP1)).call(); RevFeatureType ft = null; if (featureType.isPresent()) ft = featureType.get(); Envelope bounds = new EPSGBoundsCalc().getCRSBounds(ft); Envelope wgs84 = new Envelope(-90.0, 90.0, -180.0, 180.0); assertEquals(wgs84, bounds); } }