Package org.locationtech.geogig.api

Examples of org.locationtech.geogig.api.Context


            if (onlyTrees) {
                lsStrategy = LsTreeOp.Strategy.TREES_ONLY;
            }
        }

        final Context geogig = this.getCommandLocator(context);

        final Iterator<NodeRef> iter = geogig.command(LsTreeOp.class).setReference(ref)
                .setStrategy(lsStrategy).call();

        context.setResponseContent(new CommandResponse() {

            @Override
View Full Code Here


    StagingDatabase indexDb;

    @Before
    public void setUp() {
        Context injector = Guice.createInjector(Modules.override(new GeogigModule()).with(
                new MemoryModule(null))).getInstance(Context.class);

        odb = injector.objectDatabase();
        indexDb = injector.stagingDatabase();
        odb.open();
        indexDb.open();

        writeBack = injector.command(WriteBack.class);
    }
View Full Code Here

    }

    @Test
    public void testResolveToMultipleIds() {
        StagingDatabase mockIndexDb = mock(StagingDatabase.class);
        Context mockCommands = mock(Context.class);
        RefParse mockRefParse = mock(RefParse.class);

        when(mockRefParse.setName(anyString())).thenReturn(mockRefParse);
        when(mockCommands.command(eq(RefParse.class))).thenReturn(mockRefParse);
        Optional<Ref> ref = Optional.absent();
        when(mockRefParse.call()).thenReturn(ref);

        List<ObjectId> oIds = Arrays.asList(ObjectId.forString("Object 1"),
                ObjectId.forString("Object 2"));
        when(mockIndexDb.lookUp(anyString())).thenReturn(oIds);
        when(mockCommands.stagingDatabase()).thenReturn(mockIndexDb);
        RevParse command = new RevParse();
        command.setContext(mockCommands);

        exception.expect(IllegalArgumentException.class);
        command.setRefSpec(commitId1.toString().substring(0, commitId1.toString().length() - 2))
View Full Code Here

            @Override
            public long currentTimeMillis() {
                return REFERENCE_DATE.getTime();
            }
        };
        Context injector = Guice.createInjector(
                Modules.override(new GeogigModule()).with(new MemoryModule(testPlatform)))
                .getInstance(Context.class);

        fakeGeogig = new GeoGIG(injector, workingDirectory);
        assertNotNull(fakeGeogig.getOrCreateRepository());
View Full Code Here

        command = new RefParse();
        for (String name : allRefs.keySet()) {
            when(mockRefDb.getRef(eq(name))).thenReturn(allRefs.get(name));
        }

        Context mockCommandLocator = mock(Context.class);
        when(mockCommandLocator.refDatabase()).thenReturn(mockRefDb);
        command.setContext(mockCommandLocator);
        ResolveObjectType mockResolveObjectType = mock(ResolveObjectType.class);
        when(mockCommandLocator.command(eq(ResolveObjectType.class))).thenReturn(
                mockResolveObjectType);

        when(mockResolveObjectType.setObjectId((ObjectId) anyObject())).thenReturn(
                mockResolveObjectType);
        when(mockResolveObjectType.call()).thenReturn(TYPE.COMMIT);
View Full Code Here

        coverageRevFeature = RevFeatureBuilder.build(coverageFeature);

        hashCommand = new HashObject();

        Context mockCommandLocator = mock(Context.class);
        hashCommand.setContext(mockCommandLocator);
        when(mockCommandLocator.command(eq(DescribeFeatureType.class))).thenReturn(
                new DescribeFeatureType());
    }
View Full Code Here

    @Before
    public void setUp() throws Exception {

        File workingDirectory = tempFolder.newFolder("mockWorkingDir");
        Platform testPlatform = new TestPlatform(workingDirectory);
        Context injector = Guice.createInjector(
                Modules.override(new GeogigModule()).with(new MemoryModule(testPlatform)))
                .getInstance(Context.class);

        geogit = new GeoGIG(injector);
        assertNotNull(geogit.getOrCreateRepository());
View Full Code Here

    public void run(CommandContext context) {
        if (this.getTransactionId() == null) {
            throw new CommandSpecException(
                    "No transaction was specified, commit requires a transaction to preserve the stability of the repository.");
        }
        final Context geogig = this.getCommandLocator(context);
        RevCommit commit;
        try {
            commit = geogig.command(CommitOp.class)
                    .setAuthor(authorName.orNull(), authorEmail.orNull()).setMessage(message)
                    .setAllowEmpty(true).setAll(all).call();
            assert commit != null;
        } catch (NothingToCommitException noChanges) {
            context.setResponseContent(CommandResponse.warning("Nothing to commit"));
            commit = null;
        } catch (IllegalStateException e) {
            context.setResponseContent(CommandResponse.warning(e.getMessage()));
            commit = null;
        }
        if (commit != null) {
            final RevCommit commitToWrite = commit;
            final ObjectId parentId = commit.parentN(0).or(ObjectId.NULL);
            final Iterator<DiffEntry> diff = geogig.command(DiffOp.class).setOldVersion(parentId)
                    .setNewVersion(commit.getId()).call();

            context.setResponseContent(new CommandResponse() {
                @Override
                public void write(ResponseWriter out) throws Exception {
View Full Code Here

    public void run(CommandContext context) {
        if (this.getTransactionId() == null) {
            throw new CommandSpecException(
                    "No transaction was specified, revert feature requires a transaction to preserve the stability of the repository.");
        }
        final Context geogig = this.getCommandLocator(context);

        Optional<RevTree> newTree = Optional.absent();
        Optional<RevTree> oldTree = Optional.absent();

        // get tree from new commit
        Optional<ObjectId> treeId = geogig.command(ResolveTreeish.class).setTreeish(newCommitId)
                .call();

        Preconditions.checkState(treeId.isPresent(),
                "New commit id did not resolve to a valid tree.");
        newTree = geogig.command(RevObjectParse.class).setRefSpec(treeId.get().toString())
                .call(RevTree.class);
        Preconditions.checkState(newTree.isPresent(), "Unable to read the new commit tree.");

        // get tree from old commit
        treeId = geogig.command(ResolveTreeish.class).setTreeish(oldCommitId).call();

        Preconditions.checkState(treeId.isPresent(),
                "Old commit id did not resolve to a valid tree.");
        oldTree = geogig.command(RevObjectParse.class).setRefSpec(treeId.get().toString())
                .call(RevTree.class);
        Preconditions.checkState(newTree.isPresent(), "Unable to read the old commit tree.");

        // get feature from old tree
        Optional<NodeRef> node = geogig.command(FindTreeChild.class).setParent(oldTree.get())
                .setIndex(true).setChildPath(featurePath).call();
        boolean delete = false;
        if (!node.isPresent()) {
            delete = true;
            node = geogig.command(FindTreeChild.class).setParent(newTree.get()).setIndex(true)
                    .setChildPath(featurePath).call();
            Preconditions.checkState(node.isPresent(),
                    "The feature was not found in either commit tree.");
        }

        // get the new parent tree
        ObjectId metadataId = ObjectId.NULL;
        Optional<NodeRef> parentNode = geogig.command(FindTreeChild.class).setParent(newTree.get())
                .setChildPath(node.get().getParentPath()).setIndex(true).call();

        RevTreeBuilder treeBuilder = null;
        if (parentNode.isPresent()) {
            metadataId = parentNode.get().getMetadataId();
            Optional<RevTree> parsed = geogig.command(RevObjectParse.class)
                    .setObjectId(parentNode.get().getNode().getObjectId()).call(RevTree.class);
            checkState(parsed.isPresent(), "Parent tree couldn't be found in the repository.");
            treeBuilder = new RevTreeBuilder(geogig.stagingDatabase(), parsed.get());
            treeBuilder.remove(node.get().getNode().getName());
        } else {
            treeBuilder = new RevTreeBuilder(geogig.stagingDatabase());
        }

        // put the old feature into the new tree
        if (!delete) {
            treeBuilder.put(node.get().getNode());
        }
        ObjectId newTreeId = geogig.command(WriteBack.class)
                .setAncestor(newTree.get().builder(geogig.stagingDatabase()))
                .setChildPath(node.get().getParentPath()).setToIndex(true)
                .setTree(treeBuilder.build()).setMetadataId(metadataId).call();

        // build new commit with parent of new commit and the newly built tree
        CommitBuilder builder = new CommitBuilder();

        builder.setParentIds(Lists.newArrayList(newCommitId));
        builder.setTreeId(newTreeId);
        builder.setAuthor(authorName.orNull());
        builder.setAuthorEmail(authorEmail.orNull());
        builder.setMessage(commitMessage.or("Reverted changes made to " + featurePath + " at "
                + newCommitId.toString()));

        RevCommit mapped = builder.build();
        context.getGeoGIG().getRepository().objectDatabase().put(mapped);

        // merge commit into current branch
        final Optional<Ref> currHead = geogig.command(RefParse.class).setName(Ref.HEAD).call();
        if (!currHead.isPresent()) {
            throw new CommandSpecException("Repository has no HEAD, can't merge.");
        }

        MergeOp merge = geogig.command(MergeOp.class);
        merge.setAuthor(authorName.orNull(), authorEmail.orNull());
        merge.addCommit(Suppliers.ofInstance(mapped.getId()));
        merge.setMessage(mergeMessage.or("Merged revert of " + featurePath));

        try {
            final MergeReport report = merge.call();

            context.setResponseContent(new CommandResponse() {
                @Override
                public void write(ResponseWriter out) throws Exception {
                    out.start();
                    out.writeMergeResponse(Optional.fromNullable(report.getMergeCommit()), report
                            .getReport().get(), geogig, report.getOurs(), report.getPairs().get(0)
                            .getTheirs(), report.getPairs().get(0).getAncestor());
                    out.finish();
                }
            });
        } catch (Exception e) {
            final RevCommit ours = context.getGeoGIG().getRepository()
                    .getCommit(currHead.get().getObjectId());
            final RevCommit theirs = context.getGeoGIG().getRepository().getCommit(mapped.getId());
            final Optional<ObjectId> ancestor = geogig.command(FindCommonAncestor.class)
                    .setLeft(ours).setRight(theirs).call();
            context.setResponseContent(new CommandResponse() {
                final MergeScenarioReport report = geogig.command(ReportMergeScenarioOp.class)
                        .setMergeIntoCommit(ours).setToMergeCommit(theirs).call();

                @Override
                public void write(ResponseWriter out) throws Exception {
                    out.start();
View Full Code Here

        } else if (!(delete) && newValue == null) {
            throw new CommandSpecException(
                    "Nothing specified to update with, must specify either deletion or new value to update to.");
        }

        final Context geogig = this.getCommandLocator(context);
        Optional<Ref> ref;

        try {
            ref = geogig.command(RefParse.class).setName(name).call();

            if (!ref.isPresent()) {
                throw new CommandSpecException("Invalid name: " + name);
            }

            if (ref.get() instanceof SymRef) {
                Optional<Ref> target = geogig.command(RefParse.class).setName(newValue).call();
                if (target.isPresent() && !(target.get() instanceof SymRef)) {
                    ref = geogig.command(UpdateSymRef.class).setDelete(delete).setName(name)
                            .setNewValue(target.get().getName()).call();
                } else {
                    throw new CommandSpecException("Invalid new target: " + newValue);
                }

            } else {
                Optional<ObjectId> target = geogig.command(RevParse.class).setRefSpec(newValue)
                        .call();
                if (target.isPresent()) {
                    ref = geogig.command(UpdateRef.class).setDelete(delete)
                            .setName(ref.get().getName()).setNewValue(target.get()).call();
                } else {
                    throw new CommandSpecException("Invalid new value: " + newValue);
                }
            }
View Full Code Here

TOP

Related Classes of org.locationtech.geogig.api.Context

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.