Package org.locationtech.geogig.api

Examples of org.locationtech.geogig.api.GeoGIG


                ClientInfo info = request.getClientInfo();
                Optional<GeoGIG> ggit = getGeogig(request);
                Preconditions.checkState(ggit.isPresent());
                Form options = request.getResourceRef().getQueryAsForm();

                final GeoGIG geogig = ggit.get();

                // make a combined ip address to handle requests from multiple machines in the same
                // external network.
                // e.g.: ext.ern.al.IP.int.ern.al.IP
                String ipAddress = info.getAddress() + "."
                        + options.getFirstValue("internalIp", "");
                LOGGER.debug("Initiating EndPush for '{}'", ipAddress);

                String refspec = options.getFirstValue("refspec", null);
                final ObjectId oid = ObjectId.valueOf(options.getFirstValue("objectId",
                        ObjectId.NULL.toString()));
                final ObjectId originalRefValue = ObjectId.valueOf(options.getFirstValue(
                        "originalRefValue", ObjectId.NULL.toString()));

                Optional<Ref> currentRef = geogig.command(RefParse.class).setName(refspec).call();
                ObjectId currentRefId = currentRef.isPresent() ? currentRef.get().getObjectId()
                        : ObjectId.NULL;
                if (!currentRefId.isNull() && !currentRefId.equals(originalRefValue)) {
                    // Abort push
                    w.write("Push aborted for address: " + ipAddress
View Full Code Here


            ObjectId oid = ObjectId.valueOf(options.getFirstValue("oid", ObjectId.NULL.toString()));
            Request request = getRequest();
            Optional<GeoGIG> ggit = getGeogig(request);
            Preconditions.checkState(ggit.isPresent());

            GeoGIG geogig = ggit.get();
            Repository repository = geogig.getRepository();
            boolean blobExists = repository.blobExists(oid);

            if (blobExists) {
                w.write("1");
            } else {
View Full Code Here

        Request request = getRequest();
        try {
            LOGGER.info("Receiving objects from {}", request.getClientInfo().getAddress());
            Representation representation = request.getEntity();
            input = representation.getStream();
            final GeoGIG ggit = getGeogig(request).get();
            final BinaryPackedObjects unpacker = new BinaryPackedObjects(ggit.getRepository()
                    .objectDatabase());

            CountingInputStream countingStream = new CountingInputStream(input);

            Stopwatch sw = Stopwatch.createStarted();
View Full Code Here

            Preconditions.checkState(ggit.isPresent());

            final String id = (String) request.getAttributes().get("id");
            final ObjectId oid = ObjectId.valueOf(id);

            GeoGIG geogig = ggit.get();
            Repository repository = geogig.getRepository();
            boolean blobExists = repository.blobExists(oid);
            if (blobExists) {
                ObjectResource objectResource = new ObjectResource(oid, geogig);
                objectResource.init(getContext(), request, response);
                return objectResource;
View Full Code Here

            Optional<String> commit = Optional
                    .fromNullable(options.getFirstValue("commitId", null));

            Preconditions.checkState(commit.isPresent(), "No commit specified.");

            GeoGIG ggit = getGeogig(request).get();

            ObjectId commitId = ObjectId.valueOf(commit.get());

            RevCommit revCommit = ggit.getRepository().getCommit(commitId);

            if (revCommit.getParentIds() != null && revCommit.getParentIds().size() > 0) {
                ObjectId parentId = revCommit.getParentIds().get(0);
                final Iterator<DiffEntry> diff = ggit.command(DiffOp.class).setOldVersion(parentId)
                        .setNewVersion(commitId).call();

                while (diff.hasNext()) {
                    DiffEntry diffEntry = diff.next();
                    if (diffEntry.getOldObject() != null) {
View Full Code Here

                    }
                }
            }

            Request request = getRequest();
            final GeoGIG ggit = getGeogig(request).get();
            final Repository repository = ggit.getRepository();
            final Deduplicator deduplicator = ggit.command(CreateDeduplicator.class).call();

            BinaryPackedObjects packer = new BinaryPackedObjects(repository.stagingDatabase());
            Representation rep = new RevObjectBinaryRepresentation(packer, want, have, deduplicator);
            Response response = getResponse();
            response.setEntity(rep);
View Full Code Here

    public void post(Representation entity) {
        InputStream input = null;

        try {
            input = getRequest().getEntity().getStream();
            final GeoGIG ggit = getGeogig(getRequest()).get();
            final Reader body = new InputStreamReader(input);
            final JsonParser parser = new JsonParser();
            final JsonElement conflictJson = parser.parse(body);

            if (conflictJson.isJsonObject()) {
                final JsonObject conflict = conflictJson.getAsJsonObject();
                String featureId = null;
                RevFeature ourFeature = null;
                RevFeatureType ourFeatureType = null;
                RevFeature theirFeature = null;
                RevFeatureType theirFeatureType = null;
                JsonObject merges = null;
                if (conflict.has("path") && conflict.get("path").isJsonPrimitive()) {
                    featureId = conflict.get("path").getAsJsonPrimitive().getAsString();
                }
                Preconditions.checkState(featureId != null);

                if (conflict.has("ours") && conflict.get("ours").isJsonPrimitive()) {
                    String ourCommit = conflict.get("ours").getAsJsonPrimitive().getAsString();
                    Optional<NodeRef> ourNode = parseID(ObjectId.valueOf(ourCommit), featureId,
                            ggit);
                    if (ourNode.isPresent()) {
                        Optional<RevObject> object = ggit.command(RevObjectParse.class)
                                .setObjectId(ourNode.get().objectId()).call();
                        Preconditions.checkState(object.isPresent()
                                && object.get() instanceof RevFeature);

                        ourFeature = (RevFeature) object.get();

                        object = ggit.command(RevObjectParse.class)
                                .setObjectId(ourNode.get().getMetadataId()).call();
                        Preconditions.checkState(object.isPresent()
                                && object.get() instanceof RevFeatureType);

                        ourFeatureType = (RevFeatureType) object.get();
                    }
                }

                if (conflict.has("theirs") && conflict.get("theirs").isJsonPrimitive()) {
                    String theirCommit = conflict.get("theirs").getAsJsonPrimitive().getAsString();
                    Optional<NodeRef> theirNode = parseID(ObjectId.valueOf(theirCommit), featureId,
                            ggit);
                    if (theirNode.isPresent()) {
                        Optional<RevObject> object = ggit.command(RevObjectParse.class)
                                .setObjectId(theirNode.get().objectId()).call();
                        Preconditions.checkState(object.isPresent()
                                && object.get() instanceof RevFeature);

                        theirFeature = (RevFeature) object.get();

                        object = ggit.command(RevObjectParse.class)
                                .setObjectId(theirNode.get().getMetadataId()).call();
                        Preconditions.checkState(object.isPresent()
                                && object.get() instanceof RevFeatureType);

                        theirFeatureType = (RevFeatureType) object.get();
                    }
                }

                if (conflict.has("merges") && conflict.get("merges").isJsonObject()) {
                    merges = conflict.get("merges").getAsJsonObject();
                }
                Preconditions.checkState(merges != null);

                Preconditions.checkState(ourFeatureType != null || theirFeatureType != null);

                SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(
                        (SimpleFeatureType) (ourFeatureType != null ? ourFeatureType.type()
                                : theirFeatureType.type()));

                ImmutableList<PropertyDescriptor> descriptors = (ourFeatureType == null ? theirFeatureType
                        : ourFeatureType).sortedDescriptors();

                for (Entry<String, JsonElement> entry : merges.entrySet()) {
                    int descriptorIndex = getDescriptorIndex(entry.getKey(), descriptors);
                    if (descriptorIndex != -1 && entry.getValue().isJsonObject()) {
                        PropertyDescriptor descriptor = descriptors.get(descriptorIndex);
                        JsonObject attributeObject = entry.getValue().getAsJsonObject();
                        if (attributeObject.has("ours")
                                && attributeObject.get("ours").isJsonPrimitive()
                                && attributeObject.get("ours").getAsBoolean()) {
                            featureBuilder.set(descriptor.getName(), ourFeature == null ? null
                                    : ourFeature.getValues().get(descriptorIndex).orNull());
                        } else if (attributeObject.has("theirs")
                                && attributeObject.get("theirs").isJsonPrimitive()
                                && attributeObject.get("theirs").getAsBoolean()) {
                            featureBuilder.set(descriptor.getName(), theirFeature == null ? null
                                    : theirFeature.getValues().get(descriptorIndex).orNull());
                        } else if (attributeObject.has("value")
                                && attributeObject.get("value").isJsonPrimitive()) {
                            JsonPrimitive primitive = attributeObject.get("value")
                                    .getAsJsonPrimitive();
                            if (primitive.isString()) {
                                try {
                                    Object object = valueFromString(
                                            FieldType.forBinding(descriptor.getType().getBinding()),
                                            primitive.getAsString());
                                    featureBuilder.set(descriptor.getName(), object);
                                } catch (Exception e) {
                                    throw new Exception("Unable to convert attribute ("
                                            + entry.getKey() + ") to required type: "
                                            + descriptor.getType().getBinding().toString());
                                }
                            } else if (primitive.isNumber()) {
                                try {
                                    Object value = valueFromNumber(
                                            FieldType.forBinding(descriptor.getType().getBinding()),
                                            primitive.getAsNumber());
                                    featureBuilder.set(descriptor.getName(), value);
                                } catch (Exception e) {
                                    throw new Exception("Unable to convert attribute ("
                                            + entry.getKey() + ") to required type: "
                                            + descriptor.getType().getBinding().toString());
                                }
                            } else if (primitive.isBoolean()) {
                                try {
                                    Object value = valueFromBoolean(
                                            FieldType.forBinding(descriptor.getType().getBinding()),
                                            primitive.getAsBoolean());
                                    featureBuilder.set(descriptor.getName(), value);
                                } catch (Exception e) {
                                    throw new Exception("Unable to convert attribute ("
                                            + entry.getKey() + ") to required type: "
                                            + descriptor.getType().getBinding().toString());
                                }
                            } else if (primitive.isJsonNull()) {
                                featureBuilder.set(descriptor.getName(), null);
                            } else {
                                throw new Exception("Unsupported JSON type for attribute value ("
                                        + entry.getKey() + ")");
                            }
                        }
                    }
                }
                SimpleFeature feature = featureBuilder
                        .buildFeature(NodeRef.nodeFromPath(featureId));
                RevFeature revFeature = RevFeatureBuilder.build(feature);
                ggit.getRepository().stagingDatabase().put(revFeature);

                getResponse().setEntity(
                        new StringRepresentation(revFeature.getId().toString(),
                                MediaType.TEXT_PLAIN));
            }
View Full Code Here

            Optional<String> commit = Optional
                    .fromNullable(options.getFirstValue("commitId", null));

            Optional<GeoGIG> geogig = getGeogig(request);
            Preconditions.checkState(geogig.isPresent());
            GeoGIG ggit = geogig.get();

            Optional<Integer> depth = Optional.absent();

            if (commit.isPresent()) {
                depth = Optional.of(ggit.getRepository().graphDatabase()
                        .getDepth(ObjectId.valueOf(commit.get())));
            } else {
                depth = ggit.getRepository().getDepth();
            }

            if (depth.isPresent()) {
                w.write(depth.get().toString());
            }
View Full Code Here

                        }

                    }
                }

                final GeoGIG ggit = getGeogig(getRequest()).get();
                final Repository repository = ggit.getRepository();

                RevCommit commit = repository.getCommit(commitId);

                ObjectId parent = ObjectId.NULL;
                if (commit.getParentIds().size() > 0) {
                    parent = commit.getParentIds().get(0);
                }

                Iterator<DiffEntry> changes = ggit.command(DiffOp.class)
                        .setNewVersion(commit.getId()).setOldVersion(parent).setReportTrees(true)
                        .call();
                FilteredDiffIterator filteredChanges = new FilteredDiffIterator(changes,
                        repository, filter) {
                    @Override
View Full Code Here

        File envHome = tempFolder.getRoot();
        Platform testPlatform = new TestPlatform(envHome);
        Context injector = Guice.createInjector(Modules.override(new GeogigModule()).with(
                new MemoryModule(testPlatform))).getInstance(Context.class);

        fakeGeogig = new GeoGIG(injector);
        Repository fakeRepo = fakeGeogig.getOrCreateRepository();
        odb = fakeRepo.objectDatabase();
        search = new DepthSearch(odb);

        RevTreeBuilder root = new RevTreeBuilder(odb);
View Full Code Here

TOP

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

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.