Search in sources :

Example 1 with DiffOp

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

the class CreatePatchOpTest method testCreatePatchUsingIndex.

@Test
public void testCreatePatchUsingIndex() throws Exception {
    insertAndAdd(points1, points2);
    geogig.command(CommitOp.class).setAll(true).call();
    final String featureId = points1.getIdentifier().getID();
    final Feature modifiedFeature = feature((SimpleFeatureType) points1.getType(), featureId, "changedProp", new Integer(1500), null);
    insertAndAdd(modifiedFeature);
    insertAndAdd(points3);
    deleteAndAdd(points2);
    delete(points3);
    DiffOp op = geogig.command(DiffOp.class);
    op.setCompareIndex(true);
    Iterator<DiffEntry> diffs = op.call();
    Patch patch = geogig.command(CreatePatchOp.class).setDiffs(diffs).call();
    assertEquals(3, patch.count());
    assertEquals(1, patch.getAddedFeatures().size());
    assertEquals(1, patch.getRemovedFeatures().size());
    assertEquals(1, patch.getModifiedFeatures().size());
    assertEquals(RevFeatureTypeImpl.build(pointsType), patch.getFeatureTypes().get(0));
    assertEquals(NodeRef.appendChild(pointsName, idP2), patch.getRemovedFeatures().get(0).getPath());
    assertEquals(NodeRef.appendChild(pointsName, idP3), patch.getAddedFeatures().get(0).getPath());
}
Also used : DiffOp(org.locationtech.geogig.api.porcelain.DiffOp) Feature(org.opengis.feature.Feature) Patch(org.locationtech.geogig.api.plumbing.diff.Patch) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Test(org.junit.Test)

Example 2 with DiffOp

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

the class CreatePatchOpTest method testCreatePatchAddNewEmptyPath.

@Test
public void testCreatePatchAddNewEmptyPath() throws Exception {
    insert(points1);
    delete(points1);
    DiffOp op = geogig.command(DiffOp.class).setReportTrees(true);
    Iterator<DiffEntry> diffs = op.call();
    // ArrayList<DiffEntry> list = Lists.newArrayList(diffs);
    Patch patch = geogig.command(CreatePatchOp.class).setDiffs(diffs).call();
    assertEquals(1, patch.getAlteredTrees().size());
}
Also used : DiffOp(org.locationtech.geogig.api.porcelain.DiffOp) Patch(org.locationtech.geogig.api.plumbing.diff.Patch) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Test(org.junit.Test)

Example 3 with DiffOp

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

the class FormatPatch method runInternal.

/**
     * Executes the format-patch command with the specified options.
     */
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
    checkParameter(refSpec.size() < 3, "Commit list is too long :%s", refSpec);
    GeoGIG geogig = cli.getGeogig();
    checkParameter(file != null, "Patch file not specified");
    DiffOp diff = geogig.command(DiffOp.class).setReportTrees(true);
    String oldVersion = resolveOldVersion();
    String newVersion = resolveNewVersion();
    diff.setOldVersion(oldVersion).setNewVersion(newVersion).setCompareIndex(cached);
    Iterator<DiffEntry> entries;
    if (paths.isEmpty()) {
        entries = diff.setProgressListener(cli.getProgressListener()).call();
    } else {
        entries = Iterators.emptyIterator();
        for (String path : paths) {
            Iterator<DiffEntry> moreEntries = diff.setFilter(path).setProgressListener(cli.getProgressListener()).call();
            entries = Iterators.concat(entries, moreEntries);
        }
    }
    if (!entries.hasNext()) {
        cli.getConsole().println("No differences found");
        return;
    }
    Patch patch = geogig.command(CreatePatchOp.class).setDiffs(entries).call();
    FileOutputStream fos = new FileOutputStream(file);
    OutputStreamWriter out = new OutputStreamWriter(fos, "UTF-8");
    PatchSerializer.write(out, patch);
}
Also used : DiffOp(org.locationtech.geogig.api.porcelain.DiffOp) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) Patch(org.locationtech.geogig.api.plumbing.diff.Patch) GeoGIG(org.locationtech.geogig.api.GeoGIG) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 4 with DiffOp

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

the class Diff method runInternal.

/**
     * Executes the diff command with the specified options.
     */
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
    checkParameter(refSpec.size() <= 2, "Commit list is too long :%s", refSpec);
    checkParameter(!(nogeom && summary), "Only one printing mode allowed");
    checkParameter(!(bounds && count), "Only one of --bounds or --count is allowed");
    checkParameter(!(cached && refSpec.size() > 1), "--cached allows zero or one ref specs to compare the index with.");
    GeoGIG geogig = cli.getGeogig();
    String oldVersion = resolveOldVersion();
    String newVersion = resolveNewVersion();
    List<String> paths = removeEmptyPaths();
    if (bounds) {
        DiffBounds diff = geogig.command(DiffBounds.class).setOldVersion(oldVersion).setNewVersion(newVersion).setCompareIndex(cached);
        diff.setPathFilters(paths);
        CoordinateReferenceSystem crs = parseCrs();
        if (crs != null) {
            diff.setCRS(crs);
        }
        DiffSummary<BoundingBox, BoundingBox> diffBounds = diff.call();
        BoundsDiffPrinter.print(geogig, cli.getConsole(), diffBounds);
        return;
    }
    if (count) {
        if (oldVersion == null) {
            oldVersion = Ref.HEAD;
        }
        if (newVersion == null) {
            newVersion = cached ? Ref.STAGE_HEAD : Ref.WORK_HEAD;
        }
        DiffCount cdiff = geogig.command(DiffCount.class).setOldVersion(oldVersion).setNewVersion(newVersion);
        cdiff.setFilter(paths);
        DiffObjectCount count = cdiff.call();
        ConsoleReader console = cli.getConsole();
        console.println(String.format("Trees changed: %d, features changed: %,d", count.treeCount(), count.featureCount()));
        console.flush();
        return;
    }
    DiffOp diff = geogig.command(DiffOp.class);
    diff.setOldVersion(oldVersion).setNewVersion(newVersion).setCompareIndex(cached);
    Iterator<DiffEntry> entries;
    if (paths.isEmpty()) {
        entries = diff.setProgressListener(cli.getProgressListener()).call();
    } else {
        entries = Iterators.emptyIterator();
        for (String path : paths) {
            Iterator<DiffEntry> moreEntries = diff.setFilter(path).setProgressListener(cli.getProgressListener()).call();
            entries = Iterators.concat(entries, moreEntries);
        }
    }
    if (!entries.hasNext()) {
        cli.getConsole().println("No differences found");
        return;
    }
    DiffPrinter printer;
    if (summary) {
        printer = new SummaryDiffPrinter();
    } else {
        printer = new FullDiffPrinter(nogeom, false);
    }
    DiffEntry entry;
    while (entries.hasNext()) {
        entry = entries.next();
        printer.print(geogig, cli.getConsole(), entry);
    }
}
Also used : DiffBounds(org.locationtech.geogig.api.plumbing.DiffBounds) ConsoleReader(jline.console.ConsoleReader) DiffOp(org.locationtech.geogig.api.porcelain.DiffOp) DiffObjectCount(org.locationtech.geogig.api.plumbing.diff.DiffObjectCount) BoundingBox(org.opengis.geometry.BoundingBox) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) DiffCount(org.locationtech.geogig.api.plumbing.DiffCount) GeoGIG(org.locationtech.geogig.api.GeoGIG) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 5 with DiffOp

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

the class GeoGigAPI method getFeaturesToCommit.

/**
     * Returns an array with the features that are staged and ready to be commited. If noDeletions
     * is true, it doesn't include features to be removed, only those ones to be added or modified,
     * so it can be used to check the new data that will get commited into the repository
     * 
     * @return
     */
public Feature[] getFeaturesToCommit(String path, boolean noDeletions) {
    DiffOp diffOp = repository.command(DiffOp.class);
    diffOp.setCompareIndex(true);
    diffOp.setFilter(path);
    Iterator<DiffEntry> diffs = diffOp.call();
    List<Feature> list = Lists.newArrayList();
    while (diffs.hasNext()) {
        DiffEntry diff = diffs.next();
        if (!diff.changeType().equals(ChangeType.REMOVED) || !noDeletions) {
            RevFeature revFeature = repository.command(RevObjectParse.class).setObjectId(diff.newObjectId()).call(RevFeature.class).get();
            RevFeatureType revFeatureType = repository.command(RevObjectParse.class).setObjectId(diff.getNewObject().getMetadataId()).call(RevFeatureType.class).get();
            FeatureBuilder builder = new FeatureBuilder(revFeatureType);
            list.add(builder.build(diff.getNewObject().name(), revFeature));
        }
    }
    return list.toArray(new Feature[0]);
}
Also used : FeatureBuilder(org.locationtech.geogig.api.FeatureBuilder) DiffOp(org.locationtech.geogig.api.porcelain.DiffOp) RevFeature(org.locationtech.geogig.api.RevFeature) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) Feature(org.opengis.feature.Feature) RevFeature(org.locationtech.geogig.api.RevFeature) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Aggregations

DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)9 DiffOp (org.locationtech.geogig.api.porcelain.DiffOp)9 Patch (org.locationtech.geogig.api.plumbing.diff.Patch)7 Test (org.junit.Test)6 GeoGIG (org.locationtech.geogig.api.GeoGIG)2 WorkingTree (org.locationtech.geogig.repository.WorkingTree)2 Feature (org.opengis.feature.Feature)2 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ConsoleReader (jline.console.ConsoleReader)1 FeatureBuilder (org.locationtech.geogig.api.FeatureBuilder)1 RevFeature (org.locationtech.geogig.api.RevFeature)1 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)1 DiffBounds (org.locationtech.geogig.api.plumbing.DiffBounds)1 DiffCount (org.locationtech.geogig.api.plumbing.DiffCount)1 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)1 DiffObjectCount (org.locationtech.geogig.api.plumbing.diff.DiffObjectCount)1 BoundingBox (org.opengis.geometry.BoundingBox)1 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)1