private ObjectId getMetadataId(Bounded input) { if (input instanceof Bucket) { return defaultMetadataId; } if (input instanceof Node) { return ((Node) input).getMetadataId().or(defaultMetadataId); } return ((NodeRef) input).getMetadataId(); }
@Override public boolean apply(NodeRef input) { ObjectId metadataId = input.getMetadataId(); return !metadataId.isNull(); } });
/** * @return the metadata {@link ObjectId} of the new object, or {@link ObjectId#NULL} if there * isn't one */ public ObjectId newMetadataId() { NodeRef newObject = getNewObject(); return newObject != null ? newObject.getMetadataId() : ObjectId.NULL; }
private GeoGigFeatureWriter(final FeatureReader<SimpleFeatureType, SimpleFeature> reader, final NodeRef typeRef, final WorkingTree workingTree) { this.reader = reader; this.typePath = typeRef.path(); this.featureTypeId = typeRef.getMetadataId(); this.workingTree = workingTree; }
/** * @return the metadata {@link ObjectId} of the old object, or {@link ObjectId#NULL} if there * isn't one */ public ObjectId oldMetadataId() { NodeRef oldObject = getOldObject(); return oldObject != null ? oldObject.getMetadataId() : ObjectId.NULL; } }
public Iterator<FeatureInfo> apply(List<NodeRef> refs) { Map<ObjectId, RevFeature> correlationIndex = new HashMap<>(refs.size()); ArrayList<ObjectId> ids = new ArrayList<>(refs.size()); refs.forEach(ref->ids.add(ref.getObjectId())); Iterator<RevFeature> all = odb.getAll(ids, NOOP_LISTENER, RevFeature.class); all.forEachRemaining(revFeature -> correlationIndex.put(revFeature.getId(),revFeature)); ArrayList<FeatureInfo> result = new ArrayList<>(refs.size()); refs.forEach( ref-> result.add(FeatureInfo.insert(correlationIndex.get(ref.getObjectId()), ref.getMetadataId(), ref.path() ))); return (result.iterator() ); } }
/** * Hash code is based on {@link #getParentPath() parent path}, {@link #getNode() node} name and * id, and {@link #getMetadataId()} */ @Override public int hashCode() { return 17 ^ (parentPath != null ? parentPath.hashCode() : 1) * node.getObjectId().hashCode() * getMetadataId().hashCode(); }
public void writeNodeRef(NodeRef nodeRef, DataOutput data) throws IOException { writeNode(nodeRef.getNode(), data); data.write(nodeRef.getMetadataId().getRawValue()); data.writeUTF(nodeRef.getParentPath()); }
public void addAlteredTree(DiffEntry diff) { ObjectId oldFeatureType = diff.getOldObject() == null ? null : diff.getOldObject().getMetadataId(); ObjectId newFeatureType = diff.getNewObject() == null ? null : diff.getNewObject().getMetadataId(); String path = diff.oldPath() == null ? diff.newPath() : diff.oldPath(); alteredTrees.add(new FeatureTypeDiff(path, oldFeatureType, newFeatureType)); }
public Name getDescriptorName(NodeRef treeRef) { Preconditions.checkNotNull(treeRef); Preconditions.checkArgument(TYPE.TREE.equals(treeRef.getType())); Preconditions.checkArgument(!treeRef.getMetadataId().isNull(), "NodeRef '%s' is not a feature type reference", treeRef.path()); return new NameImpl(getNamespaceURI(), NodeRef.nodeFromPath(treeRef.path())); }
private void assertNode(Optional<NodeRef> ref, TYPE type, ObjectId expectedMdId, String path) { assertTrue(ref.isPresent()); assertEquals(type, ref.get().getType()); assertEquals(path, ref.get().path()); assertEquals(expectedMdId, ref.get().getMetadataId()); } }
public Map<String, RevFeatureType> getFeatureTypes(@NonNull String rootTreeIsh) { Context context = getContext(); List<NodeRef> treeNodes = context.command(FindFeatureTypeTrees.class) .setRootTreeRef(rootTreeIsh).call(); Iterator<RevFeatureType> types = context.objectDatabase().getAll( Iterables.transform(treeNodes, n -> n.getMetadataId()), BulkOpListener.NOOP_LISTENER, RevFeatureType.class); return Maps.uniqueIndex(types, t -> t.getName().getLocalPart()); }
RevFeatureType getNativeType() { GeogigContentState state = (GeogigContentState) getEntry().getState(getTransaction()); RevFeatureType nativeType = state.getNativeType(); if (nativeType == null) { final NodeRef typeRef = getTypeRef(); final ObjectId metadataId = typeRef.getMetadataId(); Context context = getCommandLocator(); nativeType = context.objectDatabase().getFeatureType(metadataId); state.setNativeType(nativeType); } return nativeType; }
RevFeatureType getNativeType() { GeogigContentState state = (GeogigContentState) getEntry().getState(getTransaction()); RevFeatureType nativeType = state.getNativeType(); if (nativeType == null) { final NodeRef typeRef = getTypeRef(); final ObjectId metadataId = typeRef.getMetadataId(); Context context = getCommandLocator(); nativeType = context.objectDatabase().getFeatureType(metadataId); state.setNativeType(nativeType); } return nativeType; }
@Test public void testPathListing() { Iterator<NodeRef> iter = geogig.command(LsTreeOp.class).setReference("Points").call(); List<NodeRef> nodes = ImmutableList.copyOf(iter); assertEquals(3, nodes.size()); for (NodeRef ref : nodes) { ObjectId metadataId = ref.getMetadataId(); assertFalse(metadataId.isNull()); } }
@Test public void testRefAndPathListing() { Iterator<NodeRef> iter = geogig.command(LsTreeOp.class).setReference("HEAD:Points").call(); List<NodeRef> nodes = ImmutableList.copyOf(iter); assertEquals(3, nodes.size()); for (NodeRef ref : nodes) { ObjectId metadataId = ref.getMetadataId(); assertFalse(metadataId.isNull()); } }
@Test public void testCreateTypeNestedNonExistingParent() throws Exception { NodeRef treeRef = workTree.createTypeTree("path/to/nested/type", pointsType); assertNotNull(treeRef); assertEquals("path/to/nested/type", treeRef.path()); assertEquals("path/to/nested", treeRef.getParentPath()); assertTrue(treeRef.getNode().getMetadataId().isPresent()); assertSame(treeRef.getMetadataId(), treeRef.getNode().getMetadataId().get()); RevFeatureType featureType = repo.objectDatabase().getFeatureType(treeRef.getMetadataId()); assertEquals(pointsType, featureType.type()); }
@Test public void testCreateTypeNestedNonExistingParent() throws Exception { NodeRef treeRef = workTree.createTypeTree("path/to/nested/type", pointsType); assertNotNull(treeRef); assertEquals("path/to/nested/type", treeRef.path()); assertEquals("path/to/nested", treeRef.getParentPath()); assertTrue(treeRef.getNode().getMetadataId().isPresent()); assertEquals(treeRef.getMetadataId(), treeRef.getNode().getMetadataId().get()); RevFeatureType featureType = repo.objectDatabase().getFeatureType(treeRef.getMetadataId()); RevObjectTestUtil.deepEquals(RevFeatureType.builder().type(pointsType).build(), featureType); }
@Test public void testCreateTypeTree() throws Exception { NodeRef treeRef = workTree.createTypeTree("points2", pointsType); assertNotNull(treeRef); assertEquals("points2", treeRef.path()); assertEquals("", treeRef.getParentPath()); assertTrue(treeRef.getNode().getMetadataId().isPresent()); assertEquals(treeRef.getMetadataId(), treeRef.getNode().getMetadataId().get()); RevFeatureType featureType = repo.objectDatabase().getFeatureType(treeRef.getMetadataId()); RevObjectTestUtil.deepEquals(RevFeatureType.builder().type(pointsType).build(), featureType); }
@Test public void testTree() { ObjectId oId = ObjectId.valueOf("abc123000000000000001234567890abcdef0000"); ObjectId metadataId = ObjectId.valueOf("abc123000000000000001234567890abcdef0001"); NodeRef nodeRef = NodeRef.tree("Points", oId, metadataId); assertEquals(oId, nodeRef.getObjectId()); assertEquals(metadataId, nodeRef.getMetadataId()); assertEquals("Points", nodeRef.getNode().getName()); }