use of org.opengis.feature.Feature in project GeoGig by boundlessgeo.
the class OSMMapOp method getFeatures.
private Iterator<Feature> getFeatures(String ref) {
Optional<ObjectId> id = command(RevParse.class).setRefSpec(ref).call();
if (!id.isPresent()) {
return Iterators.emptyIterator();
}
LsTreeOp op = command(LsTreeOp.class).setStrategy(Strategy.DEPTHFIRST_ONLY_FEATURES).setReference(ref);
Iterator<NodeRef> iterator = op.call();
Function<NodeRef, Feature> nodeRefToFeature = new Function<NodeRef, Feature>() {
private final //
Map<String, FeatureBuilder> builders = //
ImmutableMap.<//
String, //
FeatureBuilder>of(//
OSMUtils.NODE_TYPE_NAME, //
new FeatureBuilder(RevFeatureTypeImpl.build(OSMUtils.nodeType())), //
OSMUtils.WAY_TYPE_NAME, new FeatureBuilder(RevFeatureTypeImpl.build(OSMUtils.wayType())));
private final RevObjectParse parseCommand = command(RevObjectParse.class);
@Override
@Nullable
public Feature apply(@Nullable NodeRef ref) {
RevFeature revFeature = parseCommand.setObjectId(ref.objectId()).call(RevFeature.class).get();
final String parentPath = ref.getParentPath();
FeatureBuilder featureBuilder = builders.get(parentPath);
String fid = ref.name();
Feature feature = featureBuilder.build(fid, revFeature);
return feature;
}
};
return Iterators.transform(iterator, nodeRefToFeature);
}
use of org.opengis.feature.Feature in project GeoGig by boundlessgeo.
the class CherryPickOpTest method testCherryPickWithConflicts.
@Test
public void testCherryPickWithConflicts() throws Exception {
insertAndAdd(points1);
geogig.command(CommitOp.class).call();
// create branch1, checkout and add a commit
geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
insert(points2);
Feature points1Modified = feature(pointsType, idP1, "StringProp1_2", new Integer(1000), "POINT(1 1)");
insertAndAdd(points1Modified);
geogig.command(AddOp.class).call();
RevCommit branchCommit = geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource(Ref.MASTER).call();
Feature points1ModifiedB = feature(pointsType, idP1, "StringProp1_3", new Integer(2000), "POINT(1 1)");
insert(points1ModifiedB);
geogig.command(AddOp.class).call();
geogig.command(CommitOp.class).call();
try {
geogig.command(CherryPickOp.class).setCommit(Suppliers.ofInstance(branchCommit.getId())).call();
} catch (IllegalStateException e) {
assertTrue(e.getMessage().contains("conflict in Points/Points.1"));
}
Optional<Ref> cherrypickHead = geogig.command(RefParse.class).setName(Ref.CHERRY_PICK_HEAD).call();
assertTrue(cherrypickHead.isPresent());
// check that unconflicted changes are in index and working tree
Optional<RevObject> pts2 = geogig.command(RevObjectParse.class).setRefSpec(Ref.WORK_HEAD + ":" + NodeRef.appendChild(pointsName, idP2)).call();
assertTrue(pts2.isPresent());
assertEquals(RevFeatureBuilder.build(points2), pts2.get());
pts2 = geogig.command(RevObjectParse.class).setRefSpec(Ref.STAGE_HEAD + ":" + NodeRef.appendChild(pointsName, idP2)).call();
assertTrue(pts2.isPresent());
assertEquals(RevFeatureBuilder.build(points2), pts2.get());
// solve and commit
Feature points1Solved = feature(pointsType, idP1, "StringProp1_2", new Integer(2000), "POINT(1 1)");
insert(points1Solved);
geogig.command(AddOp.class).call();
geogig.command(CommitOp.class).setCommit(branchCommit).call();
Optional<RevObject> ptsSolved = geogig.command(RevObjectParse.class).setRefSpec(Ref.WORK_HEAD + ":" + NodeRef.appendChild(pointsName, idP1)).call();
assertTrue(pts2.isPresent());
assertEquals(RevFeatureBuilder.build(points1Solved), ptsSolved.get());
cherrypickHead = geogig.command(RefParse.class).setName(Ref.CHERRY_PICK_HEAD).call();
assertFalse(cherrypickHead.isPresent());
}
use of org.opengis.feature.Feature in project GeoGig by boundlessgeo.
the class CloneOpTest method testClone.
@Test
public void testClone() throws Exception {
// Commit several features to the remote
List<Feature> features = Arrays.asList(points1, lines1, points2, lines2, points3, lines3);
LinkedList<RevCommit> expected = new LinkedList<RevCommit>();
for (Feature f : features) {
ObjectId oId = insertAndAdd(remoteGeogig.geogig, f);
final RevCommit commit = remoteGeogig.geogig.command(CommitOp.class).call();
expected.addFirst(commit);
Optional<RevObject> childObject = remoteGeogig.geogig.command(RevObjectParse.class).setObjectId(oId).call();
assertTrue(childObject.isPresent());
}
// Make sure the remote has all of the commits
Iterator<RevCommit> logs = remoteGeogig.geogig.command(LogOp.class).call();
List<RevCommit> logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(expected, logged);
// Make sure the local repository has no commits prior to clone
logs = localGeogig.geogig.command(LogOp.class).call();
assertNotNull(logs);
assertFalse(logs.hasNext());
// clone from the remote
CloneOp clone = clone();
clone.setDepth(0);
clone.setRepositoryURL(remoteGeogig.envHome.getCanonicalPath()).call();
// Make sure the local repository got all of the commits
logs = localGeogig.geogig.command(LogOp.class).call();
logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(expected, logged);
}
use of org.opengis.feature.Feature in project GeoGig by boundlessgeo.
the class CloneOpTest method testShallowClone.
@Test
public void testShallowClone() throws Exception {
// Commit several features to the remote
List<Feature> features = Arrays.asList(points1, lines1, points2, lines2, points3, lines3);
LinkedList<RevCommit> expected = new LinkedList<RevCommit>();
for (Feature f : features) {
ObjectId oId = insertAndAdd(remoteGeogig.geogig, f);
final RevCommit commit = remoteGeogig.geogig.command(CommitOp.class).call();
expected.addFirst(commit);
Optional<RevObject> childObject = remoteGeogig.geogig.command(RevObjectParse.class).setObjectId(oId).call();
assertTrue(childObject.isPresent());
}
// Make sure the remote has all of the commits
Iterator<RevCommit> logs = remoteGeogig.geogig.command(LogOp.class).call();
List<RevCommit> logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(expected, logged);
// Make sure the local repository has no commits prior to clone
logs = localGeogig.geogig.command(LogOp.class).call();
assertNotNull(logs);
assertFalse(logs.hasNext());
// clone from the remote
CloneOp clone = clone();
clone.setDepth(2);
clone.setRepositoryURL(remoteGeogig.envHome.getCanonicalPath()).call();
// Make sure the local repository got only 2 commits
logs = localGeogig.geogig.command(LogOp.class).call();
logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(2, logged.size());
assertEquals(expected.get(0), logged.get(0));
assertEquals(expected.get(1), logged.get(1));
}
use of org.opengis.feature.Feature in project GeoGig by boundlessgeo.
the class AddOpTest method testAdditionFixesConflict.
@Test
public void testAdditionFixesConflict() throws Exception {
Feature points1Modified = feature(pointsType, idP1, "StringProp1_2", new Integer(1000), "POINT(1 1)");
Feature points1ModifiedB = feature(pointsType, idP1, "StringProp1_3", new Integer(2000), "POINT(1 1)");
insertAndAdd(points1);
geogig.command(CommitOp.class).call();
geogig.command(BranchCreateOp.class).setName("TestBranch").call();
insertAndAdd(points1Modified);
geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource("TestBranch").call();
insertAndAdd(points1ModifiedB);
insertAndAdd(points2);
geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource("master").call();
Ref branch = geogig.command(RefParse.class).setName("TestBranch").call().get();
try {
geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch.getObjectId())).call();
fail();
} catch (MergeConflictsException e) {
assertTrue(true);
}
geogig.command(AddOp.class).call();
List<Conflict> conflicts = geogig.getRepository().stagingDatabase().getConflicts(null, null);
assertTrue(conflicts.isEmpty());
geogig.command(CommitOp.class).call();
Optional<Ref> ref = geogig.command(RefParse.class).setName(Ref.MERGE_HEAD).call();
assertFalse(ref.isPresent());
}
Aggregations