Package org.locationtech.geogig.api.plumbing.diff

Examples of org.locationtech.geogig.api.plumbing.diff.Patch


    protected  Patch _call() throws RuntimeException {
        Preconditions.checkArgument(patch != null, "No patch file provided");

        VerifyPatchResults verify = command(VerifyPatchOp.class).setPatch(patch)
                .setReverse(reverse).call();
        Patch toReject = verify.getToReject();
        Patch toApply = verify.getToApply();

        if (!applyPartial) {
            if (!toReject.isEmpty()) {
                throw new CannotApplyPatchException(toReject);
            }
View Full Code Here


        return this;
    }

    @Override
    protected  Patch _call() {
        Patch patch = new Patch();
        Map<ObjectId, RevFeatureType> featureTypes = Maps.newHashMap();
        while (diffs.hasNext()) {
            DiffEntry diffEntry = diffs.next();
            final NodeRef newObject = diffEntry.getNewObject();
            final NodeRef oldObject = diffEntry.getOldObject();
            if (diffEntry.changeType() == ChangeType.MODIFIED) {
                RevObject revObject = command(RevObjectParse.class)
                        .setObjectId(diffEntry.newObjectId()).call().get();
                if (revObject instanceof RevFeature) {
                    FeatureDiff diff = command(DiffFeature.class)
                            .setNewVersion(Suppliers.ofInstance(diffEntry.getNewObject()))
                            .setOldVersion(Suppliers.ofInstance(diffEntry.getOldObject())).call();
                    patch.addModifiedFeature(diff);
                } else if (revObject instanceof RevTree) {
                    RevFeatureType oldFeatureType = command(RevObjectParse.class)
                            .setObjectId(diffEntry.getOldObject().getMetadataId())
                            .call(RevFeatureType.class).get();
                    RevFeatureType newFeatureType = command(RevObjectParse.class)
                            .setObjectId(diffEntry.getNewObject().getMetadataId())
                            .call(RevFeatureType.class).get();
                    patch.addFeatureType(oldFeatureType);
                    patch.addFeatureType(newFeatureType);
                    patch.addAlteredTree(diffEntry);
                }

            } else if (diffEntry.changeType() == ChangeType.ADDED) {
                RevObject revObject = command(RevObjectParse.class)
                        .setObjectId(diffEntry.newObjectId()).call().get();
                if (revObject instanceof RevFeature) {
                    RevFeatureType featureType;
                    if (featureTypes.containsKey(newObject.getMetadataId())) {
                        featureType = featureTypes.get(newObject.getMetadataId());
                    } else {
                        featureType = command(RevObjectParse.class)
                                .setObjectId(newObject.getMetadataId()).call(RevFeatureType.class)
                                .get();
                        featureTypes.put(newObject.getMetadataId(), featureType);
                    }

                    FeatureBuilder featureBuilder = new FeatureBuilder(featureType);
                    Feature feature = featureBuilder.build(diffEntry.newObjectId().toString(),
                            (RevFeature) revObject);
                    String name = diffEntry.newPath();
                    patch.addAddedFeature(name, feature, featureType);
                } else if (revObject instanceof RevTree) {
                    ObjectId metadataId = diffEntry.getNewObject().getMetadataId();
                    if (!metadataId.isNull()) {
                        RevFeatureType featureType = command(RevObjectParse.class)
                                .setObjectId(metadataId).call(RevFeatureType.class).get();
                        patch.addAlteredTree(diffEntry);
                        patch.addFeatureType(featureType);
                    }
                }
            } else if (diffEntry.changeType() == ChangeType.REMOVED) {
                RevObject revObject = command(RevObjectParse.class)
                        .setObjectId(diffEntry.oldObjectId()).call().get();
                if (revObject instanceof RevFeature) {
                    RevFeatureType featureType;
                    if (featureTypes.containsKey(oldObject.getMetadataId())) {
                        featureType = featureTypes.get(oldObject.getMetadataId());
                    } else {
                        featureType = command(RevObjectParse.class)
                                .setObjectId(oldObject.getMetadataId()).call(RevFeatureType.class)
                                .get();
                        featureTypes.put(oldObject.getMetadataId(), featureType);
                    }

                    FeatureBuilder featureBuilder = new FeatureBuilder(featureType);
                    Feature feature = featureBuilder.build(diffEntry.oldObjectId().toString(),
                            (RevFeature) revObject);
                    String name = diffEntry.oldPath();
                    patch.addRemovedFeature(name, feature, featureType);
                } else if (revObject instanceof RevTree) {
                    ObjectId metadataId = diffEntry.getOldObject().getMetadataId();
                    if (!metadataId.isNull()) {
                        RevFeatureType featureType = command(RevObjectParse.class)
                                .setObjectId(metadataId).call(RevFeatureType.class).get();
                        patch.addAlteredTree(diffEntry);
                        patch.addFeatureType(featureType);
                    }
                }
            }
        }
View Full Code Here

        setupGeogig();
    }

    @Given("^I have a patch file$")
    public void I_have_a_patch_file() throws Throwable {
        Patch patch = new Patch();
        String path = NodeRef.appendChild(pointsName, points1.getIdentifier().getID());
        Map<PropertyDescriptor, AttributeDiff> map = Maps.newHashMap();
        Optional<?> oldValue = Optional.fromNullable(points1.getProperty("sp").getValue());
        GenericAttributeDiffImpl diff = new GenericAttributeDiffImpl(oldValue, Optional.of("new"));
        map.put(pointsType.getDescriptor("sp"), diff);
        FeatureDiff feaureDiff = new FeatureDiff(path, map, RevFeatureTypeImpl.build(pointsType),
                RevFeatureTypeImpl.build(pointsType));
        patch.addModifiedFeature(feaureDiff);
        File file = new File(platform.pwd(), "test.patch");
        BufferedWriter writer = Files.newWriter(file, Charsets.UTF_8);
        PatchSerializer.write(writer, patch);
        writer.flush();
        writer.close();
View Full Code Here

        } catch (UnsupportedEncodingException e) {
            Closeables.closeQuietly(reader);
            Closeables.closeQuietly(stream);
            throw new IllegalStateException("Error reading patch file " + patchFile, e);
        }
        Patch patch = PatchSerializer.read(reader);
        Closeables.closeQuietly(reader);
        Closeables.closeQuietly(stream);

        VerifyPatchResults verify = cli.getGeogig().command(VerifyPatchOp.class).setPatch(patch)
                .setReverse(reverse).call();
        Patch toReject = verify.getToReject();
        Patch toApply = verify.getToApply();
        if (toReject.isEmpty()) {
            console.println("Patch can be applied.");
        } else {
            console.println("Error: Patch cannot be applied\n");
            console.println("Applicable entries:\n");
            console.println(toApply.toString());
            console.println("\nConflicting entries:\n");
            console.println(toReject.toString());
        }

    }
View Full Code Here

        } catch (UnsupportedEncodingException e) {
            Closeables.closeQuietly(reader);
            Closeables.closeQuietly(stream);
            throw new CommandFailedException("Error reading patch file " + patchFile, e);
        }
        Patch patch = PatchSerializer.read(reader);
        Closeables.closeQuietly(reader);
        Closeables.closeQuietly(stream);

        if (reverse) {
            patch = patch.reversed();
        }

        if (summary) {
            console.println(patch.toString());
        } else if (check) {
            VerifyPatchResults verify = cli.getGeogig().command(VerifyPatchOp.class)
                    .setPatch(patch).call();
            Patch toReject = verify.getToReject();
            Patch toApply = verify.getToApply();
            if (toReject.isEmpty()) {
                console.println("Patch can be applied.");
            } else {
                console.println("Error: Patch cannot be applied\n");
                console.println("Applicable entries:\n");
                console.println(toApply.toString());
                console.println("\nConflicting entries:\n");
                console.println(toReject.toString());
            }
        } else {
            try {
                Patch rejected = geogig.command(ApplyPatchOp.class).setPatch(patch)
                        .setApplyPartial(reject).call();
                if (reject) {
                    if (rejected.isEmpty()) {
                        console.println("Patch applied succesfully");
                    } else {
                        int accepted = patch.count() - rejected.count();
                        StringBuilder sb = new StringBuilder();
                        File file = new File(patchFile.getAbsolutePath() + ".rej");
                        sb.append("Patch applied only partially.\n");
                        sb.append(Integer.toString(accepted) + " changes were applied.\n");
                        sb.append(Integer.toString(rejected.count()) + " changes were rejected.\n");
                        BufferedWriter writer = Files.newWriter(file, Charsets.UTF_8);
                        PatchSerializer.write(writer, patch);
                        writer.flush();
                        writer.close();
                        sb.append("Patch file with rejected changes created at "
View Full Code Here

        return node;
    }

    @Test
    public void testAddFeaturePatch() throws Exception {
        Patch patch = new Patch();
        String path = NodeRef.appendChild(pointsName, points1.getIdentifier().getID());
        patch.addAddedFeature(path, points1, RevFeatureTypeImpl.build(pointsType));
        geogig.command(ApplyPatchOp.class).setPatch(patch).call();
        RevTree root = repo.workingTree().getTree();
        assertNotNull(root);
        Optional<Node> typeTreeId = findTreeChild(root, pointsName);
        RevTree typeTree = repo.getTree(typeTreeId.get().getObjectId());
View Full Code Here

    }

    @Test
    public void testRemoveFeaturePatch() throws Exception {
        insert(points1);
        Patch patch = new Patch();
        String path = NodeRef.appendChild(pointsName, points1.getIdentifier().getID());
        patch.addRemovedFeature(path, points1, RevFeatureTypeImpl.build(pointsType));
        geogig.command(ApplyPatchOp.class).setPatch(patch).call();
        RevTree root = repo.workingTree().getTree();
        assertNotNull(root);
        Optional<Node> featureBlobId = findTreeChild(root, path);
        assertFalse(featureBlobId.isPresent());
View Full Code Here

    }

    @Test
    public void testModifyFeatureAttributePatch() throws Exception {
        insert(points1);
        Patch patch = new Patch();
        String path = NodeRef.appendChild(pointsName, points1.getIdentifier().getID());
        Map<PropertyDescriptor, AttributeDiff> map = Maps.newHashMap();
        Optional<?> oldValue = Optional.fromNullable(points1.getProperty("sp").getValue());
        GenericAttributeDiffImpl diff = new GenericAttributeDiffImpl(oldValue, Optional.of("new"));
        map.put(pointsType.getDescriptor("sp"), diff);
        FeatureDiff feaureDiff = new FeatureDiff(path, map, RevFeatureTypeImpl.build(pointsType),
                RevFeatureTypeImpl.build(pointsType));
        patch.addModifiedFeature(feaureDiff);
        geogig.command(ApplyPatchOp.class).setPatch(patch).call();
        RevTree root = repo.workingTree().getTree();
        Optional<Node> featureBlobId = findTreeChild(root, path);
        assertTrue(featureBlobId.isPresent());
        Iterator<DiffEntry> unstaged = repo.workingTree().getUnstaged(pointsName);
View Full Code Here

    }

    @Test
    public void testModifyFeatureAttributeOutdatedPatch() throws Exception {
        insert(points1_modified);
        Patch patch = new Patch();
        String path = NodeRef.appendChild(pointsName, points1.getIdentifier().getID());
        Map<PropertyDescriptor, AttributeDiff> map = Maps.newHashMap();
        Optional<?> oldValue = Optional.fromNullable(points1.getProperty("sp").getValue());
        GenericAttributeDiffImpl diff = new GenericAttributeDiffImpl(oldValue, Optional.of("new"));
        map.put(pointsType.getDescriptor("sp"), diff);
        FeatureDiff feaureDiff = new FeatureDiff(path, map, RevFeatureTypeImpl.build(pointsType),
                RevFeatureTypeImpl.build(pointsType));
        patch.addModifiedFeature(feaureDiff);
        try {
            geogig.command(ApplyPatchOp.class).setPatch(patch).call();
            fail();
        } catch (CannotApplyPatchException e) {
            assertTrue(true);
View Full Code Here

    }

    @Test
    public void testRemoveFeatureAttributePatch() throws Exception {
        insert(points1B);
        Patch patch = new Patch();
        String path = NodeRef.appendChild(pointsName, points1B.getIdentifier().getID());
        Map<PropertyDescriptor, AttributeDiff> map = Maps.newHashMap();
        Optional<?> oldValue = Optional.fromNullable(points1B.getProperty("extra").getValue());
        GenericAttributeDiffImpl diff = new GenericAttributeDiffImpl(oldValue, null);
        map.put(modifiedPointsType.getDescriptor("extra"), diff);
        FeatureDiff featureDiff = new FeatureDiff(path, map,
                RevFeatureTypeImpl.build(modifiedPointsType), RevFeatureTypeImpl.build(pointsType));
        patch.addModifiedFeature(featureDiff);
        geogig.command(ApplyPatchOp.class).setPatch(patch).call();
        Optional<RevFeature> feature = geogig.command(RevObjectParse.class)
                .setRefSpec("WORK_HEAD:" + path).call(RevFeature.class);
        assertTrue(feature.isPresent());
        ImmutableList<Optional<Object>> values = feature.get().getValues();
View Full Code Here

TOP

Related Classes of org.locationtech.geogig.api.plumbing.diff.Patch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.