Search in sources :

Example 21 with RevFeatureType

use of org.locationtech.geogig.api.RevFeatureType in project GeoGig by boundlessgeo.

the class RevFeatureTypeSerializationTest method testSerializationWGS84.

@Test
public void testSerializationWGS84() throws Exception {
    SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder();
    ftb.add("geom", Polygon.class, DefaultGeographicCRS.WGS84);
    ftb.setName("type");
    SimpleFeatureType ftype = ftb.buildFeatureType();
    RevFeatureType revFeatureType = RevFeatureTypeImpl.build(ftype);
    ObjectWriter<RevFeatureType> writer = factory.createObjectWriter(TYPE.FEATURETYPE);
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    writer.write(revFeatureType, output);
    byte[] data = output.toByteArray();
    assertTrue(data.length > 0);
    ObjectReader<RevFeatureType> reader = factory.createObjectReader(TYPE.FEATURETYPE);
    ByteArrayInputStream input = new ByteArrayInputStream(data);
    RevFeatureType rft = reader.read(revFeatureType.getId(), input);
    assertNotNull(rft);
    FeatureType serializedFeatureType = rft.type();
    assertEquals("EPSG:4326", CRS.toSRS(serializedFeatureType.getCoordinateReferenceSystem()));
}
Also used : RevFeatureType(org.locationtech.geogig.api.RevFeatureType) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) FeatureType(org.opengis.feature.type.FeatureType) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) Test(org.junit.Test)

Example 22 with RevFeatureType

use of org.locationtech.geogig.api.RevFeatureType in project GeoGig by boundlessgeo.

the class AddOpTest method testAddNewPathUsingPathFilter.

@Test
public void testAddNewPathUsingPathFilter() throws Exception {
    insert(points1);
    insert(points2);
    geogig.command(AddOp.class).addPattern("Points/Points.1").call();
    List<DiffEntry> unstaged = toList(repo.index().getStaged(null));
    assertEquals(unstaged.toString(), 2, unstaged.size());
    assertEquals(ChangeType.ADDED, unstaged.get(0).changeType());
    assertEquals(RevObject.TYPE.TREE, unstaged.get(0).getNewObject().getType());
    assertEquals("Points", unstaged.get(0).newName());
    RevFeatureType ft = RevFeatureTypeImpl.build(pointsType);
    ObjectId expectedTreeMdId = ft.getId();
    assertEquals(expectedTreeMdId, unstaged.get(0).getNewObject().getMetadataId());
    assertEquals(ChangeType.ADDED, unstaged.get(1).changeType());
    assertEquals(RevObject.TYPE.FEATURE, unstaged.get(1).getNewObject().getType());
    assertEquals("Points.1", unstaged.get(1).newName());
    assertFalse("feature node's metadata id should not be set, as it uses the parent tree one", unstaged.get(1).getNewObject().getNode().getMetadataId().isPresent());
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Test(org.junit.Test)

Example 23 with RevFeatureType

use of org.locationtech.geogig.api.RevFeatureType in project GeoGig by boundlessgeo.

the class ApplyPatchOpTest method testModifiedFeatureType.

@Test
public void testModifiedFeatureType() throws Exception {
    insert(points2, points3, points1B);
    Patch patch = new Patch();
    RevFeatureType oldFeatureType = RevFeatureTypeImpl.build(pointsType);
    RevFeatureType featureType = RevFeatureTypeImpl.build(modifiedPointsType);
    patch.addFeatureType(featureType);
    patch.addAlteredTree(new FeatureTypeDiff(pointsName, oldFeatureType.getId(), featureType.getId()));
    geogig.command(ApplyPatchOp.class).setPatch(patch).call();
    RevTree root = repo.workingTree().getTree();
    assertNotNull(root);
    Optional<Node> typeTree = findTreeChild(root, pointsName);
    assertTrue(typeTree.isPresent());
    assertEquals(featureType.getId(), typeTree.get().getMetadataId().get());
    Optional<Node> featureNode = findTreeChild(root, NodeRef.appendChild(pointsName, idP2));
    assertTrue(featureNode.isPresent());
    assertEquals(oldFeatureType.getId(), featureNode.get().getMetadataId().get());
    featureNode = findTreeChild(root, NodeRef.appendChild(pointsName, idP1));
    assertTrue(featureNode.isPresent());
    assertFalse(featureNode.get().getMetadataId().isPresent());
}
Also used : FeatureTypeDiff(org.locationtech.geogig.api.plumbing.diff.FeatureTypeDiff) Node(org.locationtech.geogig.api.Node) Patch(org.locationtech.geogig.api.plumbing.diff.Patch) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 24 with RevFeatureType

use of org.locationtech.geogig.api.RevFeatureType in project GeoGig by boundlessgeo.

the class ApplyPatchOpTest method testRemoveEmptyFeatureTypePatch.

@Test
public void testRemoveEmptyFeatureTypePatch() throws Exception {
    WorkingTree workingTree = geogig.getRepository().workingTree();
    workingTree.createTypeTree(pointsName, pointsType);
    geogig.command(AddOp.class).setUpdateOnly(false).call();
    Patch patch = new Patch();
    RevFeatureType featureType = RevFeatureTypeImpl.build(pointsType);
    patch.addFeatureType(featureType);
    patch.addAlteredTree(new FeatureTypeDiff(pointsName, featureType.getId(), null));
    geogig.command(ApplyPatchOp.class).setPatch(patch).call();
    RevTree root = repo.workingTree().getTree();
    assertNotNull(root);
    Optional<Node> typeTree = findTreeChild(root, pointsName);
    assertFalse(typeTree.isPresent());
}
Also used : WorkingTree(org.locationtech.geogig.repository.WorkingTree) FeatureTypeDiff(org.locationtech.geogig.api.plumbing.diff.FeatureTypeDiff) Node(org.locationtech.geogig.api.Node) Patch(org.locationtech.geogig.api.plumbing.diff.Patch) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 25 with RevFeatureType

use of org.locationtech.geogig.api.RevFeatureType in project GeoGig by boundlessgeo.

the class Show method printFormatted.

public void printFormatted(GeogigCLI cli) throws IOException {
    ConsoleReader console = cli.getConsole();
    GeoGIG geogig = cli.getGeogig();
    for (String ref : refs) {
        Optional<RevObject> obj = geogig.command(RevObjectParse.class).setRefSpec(ref).call();
        if (!obj.isPresent()) {
            ref = getFullRef(ref);
            obj = geogig.command(RevObjectParse.class).setRefSpec(ref).call();
        }
        checkParameter(obj.isPresent(), "refspec did not resolve to any object.");
        RevObject revObject = obj.get();
        if (revObject instanceof RevFeature) {
            Optional<RevFeatureType> opt = geogig.command(ResolveFeatureType.class).setRefSpec(ref).call();
            if (opt.isPresent()) {
                RevFeatureType ft = opt.get();
                ImmutableList<PropertyDescriptor> attribs = ft.sortedDescriptors();
                RevFeature feature = (RevFeature) revObject;
                Ansi ansi = super.newAnsi(console.getTerminal());
                ansi.newline().fg(Color.YELLOW).a("ID:  ").reset().a(feature.getId().toString()).newline();
                ansi.fg(Color.YELLOW).a("FEATURE TYPE ID:  ").reset().a(ft.getId().toString()).newline().newline();
                ansi.a("ATTRIBUTES  ").newline();
                ansi.a("----------  ").newline();
                ImmutableList<Optional<Object>> values = feature.getValues();
                int i = 0;
                for (Optional<Object> value : values) {
                    ansi.fg(Color.YELLOW).a(attribs.get(i).getName() + ": ").reset();
                    ansi.a(value.or("[NULL]").toString()).newline();
                    i++;
                }
                console.println(ansi.toString());
            } else {
                CharSequence s = geogig.command(CatObject.class).setObject(Suppliers.ofInstance(revObject)).call();
                console.println(s);
            }
        } else if (revObject instanceof RevTree) {
            RevTree tree = (RevTree) revObject;
            Optional<RevFeatureType> opt = geogig.command(ResolveFeatureType.class).setRefSpec(ref).call();
            checkParameter(opt.isPresent(), "Refspec must resolve to a commit, tree, feature or feature type");
            RevFeatureType ft = opt.get();
            Ansi ansi = super.newAnsi(console.getTerminal());
            ansi.fg(Color.YELLOW).a("TREE ID:  ").reset().a(tree.getId().toString()).newline();
            ansi.fg(Color.YELLOW).a("SIZE:  ").reset().a(Long.toString(tree.size())).newline();
            ansi.fg(Color.YELLOW).a("NUMBER Of SUBTREES:  ").reset().a(Integer.toString(tree.numTrees()).toString()).newline();
            printFeatureType(ansi, ft, true);
            console.println(ansi.toString());
        } else if (revObject instanceof RevCommit) {
            RevCommit commit = (RevCommit) revObject;
            Ansi ansi = super.newAnsi(console.getTerminal());
            ansi.a(Strings.padEnd("Commit:", 15, ' ')).fg(Color.YELLOW).a(commit.getId().toString()).reset().newline();
            ansi.a(Strings.padEnd("Author:", 15, ' ')).fg(Color.GREEN).a(formatPerson(commit.getAuthor())).reset().newline();
            ansi.a(Strings.padEnd("Committer:", 15, ' ')).fg(Color.GREEN).a(formatPerson(commit.getAuthor())).reset().newline();
            ansi.a(Strings.padEnd("Author date:", 15, ' ')).a("(").fg(Color.RED).a(estimateSince(geogig.getPlatform(), commit.getAuthor().getTimestamp())).reset().a(") ").a(new Date(commit.getAuthor().getTimestamp())).newline();
            ansi.a(Strings.padEnd("Committer date:", 15, ' ')).a("(").fg(Color.RED).a(estimateSince(geogig.getPlatform(), commit.getCommitter().getTimestamp())).reset().a(") ").a(new Date(commit.getCommitter().getTimestamp())).newline();
            ansi.a(Strings.padEnd("Subject:", 15, ' ')).a(commit.getMessage()).newline();
            console.println(ansi.toString());
        } else if (revObject instanceof RevFeatureType) {
            Ansi ansi = super.newAnsi(console.getTerminal());
            printFeatureType(ansi, (RevFeatureType) revObject, false);
            console.println(ansi.toString());
        } else {
            throw new InvalidParameterException("Refspec must resolve to a commit, tree, feature or feature type");
        }
        console.println();
    }
}
Also used : ResolveFeatureType(org.locationtech.geogig.api.plumbing.ResolveFeatureType) ConsoleReader(jline.console.ConsoleReader) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) Optional(com.google.common.base.Optional) RevObject(org.locationtech.geogig.api.RevObject) Date(java.util.Date) InvalidParameterException(java.security.InvalidParameterException) RevFeature(org.locationtech.geogig.api.RevFeature) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) CatObject(org.locationtech.geogig.api.plumbing.CatObject) RevObject(org.locationtech.geogig.api.RevObject) Ansi(org.fusesource.jansi.Ansi) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) GeoGIG(org.locationtech.geogig.api.GeoGIG) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit)

Aggregations

RevFeatureType (org.locationtech.geogig.api.RevFeatureType)88 RevFeature (org.locationtech.geogig.api.RevFeature)49 NodeRef (org.locationtech.geogig.api.NodeRef)40 ObjectId (org.locationtech.geogig.api.ObjectId)34 Test (org.junit.Test)31 Optional (com.google.common.base.Optional)28 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)26 RevObject (org.locationtech.geogig.api.RevObject)24 RevTree (org.locationtech.geogig.api.RevTree)24 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)22 SimpleFeature (org.opengis.feature.simple.SimpleFeature)19 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)17 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)14 ImmutableList (com.google.common.collect.ImmutableList)13 File (java.io.File)13 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)13 FeatureBuilder (org.locationtech.geogig.api.FeatureBuilder)13 List (java.util.List)12 GeoGIG (org.locationtech.geogig.api.GeoGIG)12 AddOp (org.locationtech.geogig.api.porcelain.AddOp)12