Search in sources :

Example 16 with ObjectId

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

the class RevTreeBuilder2 method putFeature.

public Node putFeature(final ObjectId id, final String name, @Nullable final BoundingBox bounds, final FeatureType type) {
    Envelope bbox;
    if (bounds == null) {
        bbox = null;
    } else if (bounds instanceof Envelope) {
        bbox = (Envelope) bounds;
    } else {
        bbox = new Envelope(bounds.getMinimum(0), bounds.getMaximum(0), bounds.getMinimum(1), bounds.getMaximum(1));
    }
    RevFeatureType revFeatureType = revFeatureTypes.get(type.getName());
    if (null == revFeatureType) {
        revFeatureType = RevFeatureTypeImpl.build(type);
        revFeatureTypes.put(type.getName(), revFeatureType);
    }
    ObjectId metadataId = revFeatureType.getId().equals(defaultMetadataId) ? ObjectId.NULL : revFeatureType.getId();
    Node node = Node.create(name, id, metadataId, TYPE.FEATURE, bbox);
    put(node);
    return node;
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) Envelope(com.vividsolutions.jts.geom.Envelope) RevFeatureType(org.locationtech.geogig.api.RevFeatureType)

Example 17 with ObjectId

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

the class LocalMappedRemoteRepo method listRefs.

/**
     * List the remote's {@link Ref refs}.
     * 
     * @param getHeads whether to return refs in the {@code refs/heads} namespace
     * @param getTags whether to return refs in the {@code refs/tags} namespace
     * @return an immutable set of refs from the remote
     */
@Override
public ImmutableSet<Ref> listRefs(final boolean getHeads, final boolean getTags) {
    Predicate<Ref> filter = new Predicate<Ref>() {

        @Override
        public boolean apply(Ref input) {
            boolean keep = false;
            if (getHeads) {
                keep = input.getName().startsWith(Ref.HEADS_PREFIX);
            }
            if (getTags) {
                keep = keep || input.getName().startsWith(Ref.TAGS_PREFIX);
            }
            return keep;
        }
    };
    ImmutableSet<Ref> remoteRefs = remoteGeoGig.command(ForEachRef.class).setFilter(filter).call();
    // Translate the refs to their mapped values.
    ImmutableSet.Builder<Ref> builder = new ImmutableSet.Builder<Ref>();
    for (Ref remoteRef : remoteRefs) {
        Ref newRef = remoteRef;
        if (!(newRef instanceof SymRef) && localRepository.graphDatabase().exists(remoteRef.getObjectId())) {
            ObjectId mappedCommit = localRepository.graphDatabase().getMapping(remoteRef.getObjectId());
            if (mappedCommit != null) {
                newRef = new Ref(remoteRef.getName(), mappedCommit);
            }
        }
        builder.add(newRef);
    }
    return builder.build();
}
Also used : UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) ForEachRef(org.locationtech.geogig.api.plumbing.ForEachRef) UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) Ref(org.locationtech.geogig.api.Ref) SymRef(org.locationtech.geogig.api.SymRef) UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) SymRef(org.locationtech.geogig.api.SymRef) ImmutableSet(com.google.common.collect.ImmutableSet) ObjectId(org.locationtech.geogig.api.ObjectId) CommitBuilder(org.locationtech.geogig.api.CommitBuilder) Predicate(com.google.common.base.Predicate)

Example 18 with ObjectId

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

the class AbstractObjectDatabase method putAll.

/**
     * This default implementation calls {@link #putInternal(ObjectId, byte[])} for each object;
     * subclasses may override if appropriate.
     */
@Override
public void putAll(Iterator<? extends RevObject> objects, final BulkOpListener listener) {
    ByteArrayOutputStream rawOut = new ByteArrayOutputStream();
    while (objects.hasNext()) {
        RevObject object = objects.next();
        rawOut.reset();
        writeObject(object, rawOut);
        final byte[] rawData = rawOut.toByteArray();
        final ObjectId id = object.getId();
        final boolean added = putInternal(id, rawData);
        if (added) {
            listener.inserted(object.getId(), rawData.length);
        } else {
            listener.found(object.getId(), null);
        }
    }
}
Also used : RevObject(org.locationtech.geogig.api.RevObject) ObjectId(org.locationtech.geogig.api.ObjectId) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 19 with ObjectId

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

the class FormatCommonV1 method readBucket.

public static final Bucket readBucket(DataInput in) throws IOException {
    final byte[] hash = new byte[20];
    in.readFully(hash);
    ObjectId objectId = ObjectId.createNoClone(hash);
    Envelope bounds = readBBox(in);
    return Bucket.create(objectId, bounds);
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 20 with ObjectId

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

the class LogOpTest method testSinceUntil.

@Test
public void testSinceUntil() throws Exception {
    final ObjectId oid1_1 = insertAndAdd(points1);
    final RevCommit commit1_1 = geogig.command(CommitOp.class).call();
    insertAndAdd(points2);
    final RevCommit commit1_2 = geogig.command(CommitOp.class).call();
    insertAndAdd(lines1);
    final RevCommit commit2_1 = geogig.command(CommitOp.class).call();
    final ObjectId oid2_2 = insertAndAdd(lines2);
    final RevCommit commit2_2 = geogig.command(CommitOp.class).call();
    try {
        logOp = geogig.command(LogOp.class);
        logOp.setSince(oid1_1).call();
        fail("Expected ISE as since is not a commit");
    } catch (IllegalArgumentException e) {
        assertTrue(e.getMessage().contains("since"));
    }
    try {
        logOp = geogig.command(LogOp.class);
        logOp.setSince(null).setUntil(oid2_2).call();
        fail("Expected ISE as until is not a commit");
    } catch (IllegalArgumentException e) {
        assertTrue(e.getMessage().contains("until"));
    }
    List<RevCommit> logs;
    List<RevCommit> expected;
    logOp = geogig.command(LogOp.class);
    logs = toList(logOp.setSince(commit1_2.getId()).setUntil(null).call());
    expected = Arrays.asList(commit2_2, commit2_1);
    assertEquals(expected, logs);
    logOp = geogig.command(LogOp.class);
    logs = toList(logOp.setSince(commit2_2.getId()).setUntil(null).call());
    expected = Collections.emptyList();
    assertEquals(expected, logs);
    logOp = geogig.command(LogOp.class);
    logs = toList(logOp.setSince(commit1_2.getId()).setUntil(commit2_1.getId()).call());
    expected = Arrays.asList(commit2_1);
    assertEquals(expected, logs);
    logOp = geogig.command(LogOp.class);
    logs = toList(logOp.setSince(null).setUntil(commit2_1.getId()).call());
    expected = Arrays.asList(commit2_1, commit1_2, commit1_1);
    assertEquals(expected, logs);
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) LogOp(org.locationtech.geogig.api.porcelain.LogOp) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Aggregations

ObjectId (org.locationtech.geogig.api.ObjectId)361 Test (org.junit.Test)133 RevCommit (org.locationtech.geogig.api.RevCommit)109 NodeRef (org.locationtech.geogig.api.NodeRef)98 RevTree (org.locationtech.geogig.api.RevTree)91 RevObject (org.locationtech.geogig.api.RevObject)53 Ref (org.locationtech.geogig.api.Ref)46 Node (org.locationtech.geogig.api.Node)44 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)38 Feature (org.opengis.feature.Feature)35 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)34 LogOp (org.locationtech.geogig.api.porcelain.LogOp)28 RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)27 LinkedList (java.util.LinkedList)26 ArrayList (java.util.ArrayList)25 RevFeature (org.locationtech.geogig.api.RevFeature)25 IOException (java.io.IOException)23 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)23 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)23 SymRef (org.locationtech.geogig.api.SymRef)22