private Index updateIndex(String treeName, @Nullable String... extraAttributes) { List<String> extraAtts = null; if (extraAttributes != null) { extraAtts = Lists.newArrayList(extraAttributes); } Index index = geogig.command(UpdateIndexOp.class)// .setOverwrite(true)// .setTreeRefSpec(treeName)// .setExtraAttributes(extraAtts)// .setBounds(new Envelope(-180, 180, -90, 90))// .call(); return index; } }
private Index updateIndex(String treeName, @Nullable String... extraAttributes) { List<String> extraAtts = null; if (extraAttributes != null) { extraAtts = Lists.newArrayList(extraAttributes); } Index index = geogig.command(UpdateIndexOp.class)// .setOverwrite(true)// .setTreeRefSpec(treeName)// .setExtraAttributes(extraAtts)// .setBounds(new Envelope(-180, 180, -90, 90))// .call(); return index; } }
@Test public void testUpdateIndexOverwriteSameAttribute() { createIndex("x"); exception.expect(IllegalArgumentException.class); exception.expectMessage("Nothing to update..."); geogig.command(UpdateIndexOp.class)// .setTreeRefSpec(worldPointsLayer.getName())// .setExtraAttributes(Lists.newArrayList("x"))// .setOverwrite(true)// .call(); }
@Test public void testUpdateIndexOverwriteSameAttribute() { createIndex("x"); exception.expect(IllegalStateException.class); exception.expectMessage("Nothing to update..."); geogig.command(UpdateIndexOp.class)// .setTreeRefSpec(worldPointsLayer.getName())// .setExtraAttributes(Lists.newArrayList("x"))// .setOverwrite(true)// .call(); }
.setOverwrite(overwrite)//
@Test public void testUpdateIndexOverwriteExistingAttributes() { createIndex("x"); Index index = geogig.command(UpdateIndexOp.class)// .setTreeRefSpec(worldPointsLayer.getName())// .setExtraAttributes(Lists.newArrayList("y"))// .setOverwrite(true)// .call(); IndexInfo indexInfo = indexdb.getIndexInfo(worldPointsLayer.getName(), "geom").get(); assertEquals(indexInfo, index.info()); assertEquals(worldPointsLayer.getName(), indexInfo.getTreeName()); assertEquals("geom", indexInfo.getAttributeName()); assertEquals(IndexType.QUADTREE, indexInfo.getIndexType()); assertEquals(2, indexInfo.getMetadata().size()); assertTrue(indexInfo.getMetadata().containsKey(IndexInfo.MD_QUAD_MAX_BOUNDS)); assertEquals(new Envelope(-180, 180, -90, 90), indexInfo.getMetadata().get(IndexInfo.MD_QUAD_MAX_BOUNDS)); assertTrue(indexInfo.getMetadata().containsKey(IndexInfo.FEATURE_ATTRIBUTES_EXTRA_DATA)); List<String> extraAttributes = Lists.newArrayList( (String[]) indexInfo.getMetadata().get(IndexInfo.FEATURE_ATTRIBUTES_EXTRA_DATA)); assertEquals(1, extraAttributes.size()); assertTrue(extraAttributes.contains("y")); ObjectId canonicalFeatureTreeId = geogig.command(ResolveTreeish.class) .setTreeish("HEAD:" + worldPointsLayer.getName()).call().get(); Optional<ObjectId> indexedTreeId = indexdb.resolveIndexedTree(indexInfo, canonicalFeatureTreeId); assertTrue(indexedTreeId.isPresent()); assertEquals(indexedTreeId.get(), index.indexTreeId()); IndexTestSupport.verifyIndex(geogig, indexedTreeId.get(), canonicalFeatureTreeId, "y"); }
@Test public void testUpdateIndexOverwriteExistingAttributes() { createIndex("x"); Index index = geogig.command(UpdateIndexOp.class)// .setTreeRefSpec(worldPointsLayer.getName())// .setExtraAttributes(Lists.newArrayList("y"))// .setOverwrite(true)// .call(); IndexInfo indexInfo = indexdb.getIndexInfo(worldPointsLayer.getName(), "geom").get(); assertEquals(indexInfo, index.info()); assertEquals(worldPointsLayer.getName(), indexInfo.getTreeName()); assertEquals("geom", indexInfo.getAttributeName()); assertEquals(IndexType.QUADTREE, indexInfo.getIndexType()); assertEquals(2, indexInfo.getMetadata().size()); assertTrue(indexInfo.getMetadata().containsKey(IndexInfo.MD_QUAD_MAX_BOUNDS)); assertEquals(new Envelope(-180, 180, -90, 90), indexInfo.getMetadata().get(IndexInfo.MD_QUAD_MAX_BOUNDS)); assertTrue(indexInfo.getMetadata().containsKey(IndexInfo.FEATURE_ATTRIBUTES_EXTRA_DATA)); List<String> extraAttributes = Lists.newArrayList( (String[]) indexInfo.getMetadata().get(IndexInfo.FEATURE_ATTRIBUTES_EXTRA_DATA)); assertEquals(1, extraAttributes.size()); assertTrue(extraAttributes.contains("y")); ObjectId canonicalFeatureTreeId = geogig.command(ResolveTreeish.class) .setTreeish("HEAD:" + worldPointsLayer.getName()).call().get(); Optional<ObjectId> indexedTreeId = indexdb.resolveIndexedTree(indexInfo, canonicalFeatureTreeId); assertTrue(indexedTreeId.isPresent()); assertEquals(indexedTreeId.get(), index.indexTreeId()); IndexTestSupport.verifyIndex(geogig, indexedTreeId.get(), canonicalFeatureTreeId, "y"); }
@Override protected void runInternal(GeogigCLI cli) throws InvalidParameterException, CommandFailedException, IOException { Repository repo = cli.getGeogig().getRepository(); Envelope envelope = SpatialOps.parseNonReferencedBBOX(bbox); Index index = repo.command(UpdateIndexOp.class)// .setTreeRefSpec(treeRefSpec)// .setAttributeName(attribute)// .setExtraAttributes(extraAttributes)// .setOverwrite(overwrite)// .setAdd(add)// .setIndexHistory(indexHistory)// .setBounds(envelope)// .setProgressListener(cli.getProgressListener())// .call(); if (cli.getProgressListener().isCanceled()) { cli.getConsole().println("Index update cancelled."); } else { cli.getConsole().println( "Index updated successfully: " + index.indexTreeId().toString().substring(0, 8)); } } }
@Test public void testUpdateIndexRemoveExistingAttributes() { createIndex("x"); Index index = geogig.command(UpdateIndexOp.class)// .setTreeRefSpec(worldPointsLayer.getName())// .setExtraAttributes(null)// .setOverwrite(true)// .call(); IndexInfo indexInfo = indexdb.getIndexInfo(worldPointsLayer.getName(), "geom").get(); assertEquals(indexInfo, index.info()); assertEquals(worldPointsLayer.getName(), indexInfo.getTreeName()); assertEquals("geom", indexInfo.getAttributeName()); assertEquals(IndexType.QUADTREE, indexInfo.getIndexType()); assertEquals(1, indexInfo.getMetadata().size()); assertTrue(indexInfo.getMetadata().containsKey(IndexInfo.MD_QUAD_MAX_BOUNDS)); assertEquals(new Envelope(-180, 180, -90, 90), indexInfo.getMetadata().get(IndexInfo.MD_QUAD_MAX_BOUNDS)); assertFalse(indexInfo.getMetadata().containsKey(IndexInfo.FEATURE_ATTRIBUTES_EXTRA_DATA)); ObjectId canonicalFeatureTreeId = geogig.command(ResolveTreeish.class) .setTreeish("HEAD:" + worldPointsLayer.getName()).call().get(); Optional<ObjectId> indexedTreeId = indexdb.resolveIndexedTree(indexInfo, canonicalFeatureTreeId); assertTrue(indexedTreeId.isPresent()); assertEquals(indexedTreeId.get(), index.indexTreeId()); IndexTestSupport.verifyIndex(geogig, indexedTreeId.get(), canonicalFeatureTreeId); }
@Test public void testUpdateIndexRemoveExistingAttributes() { createIndex("x"); Index index = geogig.command(UpdateIndexOp.class)// .setTreeRefSpec(worldPointsLayer.getName())// .setExtraAttributes(null)// .setOverwrite(true)// .call(); IndexInfo indexInfo = indexdb.getIndexInfo(worldPointsLayer.getName(), "geom").get(); assertEquals(indexInfo, index.info()); assertEquals(worldPointsLayer.getName(), indexInfo.getTreeName()); assertEquals("geom", indexInfo.getAttributeName()); assertEquals(IndexType.QUADTREE, indexInfo.getIndexType()); assertEquals(1, indexInfo.getMetadata().size()); assertTrue(indexInfo.getMetadata().containsKey(IndexInfo.MD_QUAD_MAX_BOUNDS)); assertEquals(new Envelope(-180, 180, -90, 90), indexInfo.getMetadata().get(IndexInfo.MD_QUAD_MAX_BOUNDS)); assertFalse(indexInfo.getMetadata().containsKey(IndexInfo.FEATURE_ATTRIBUTES_EXTRA_DATA)); ObjectId canonicalFeatureTreeId = geogig.command(ResolveTreeish.class) .setTreeish("HEAD:" + worldPointsLayer.getName()).call().get(); Optional<ObjectId> indexedTreeId = indexdb.resolveIndexedTree(indexInfo, canonicalFeatureTreeId); assertTrue(indexedTreeId.isPresent()); assertEquals(indexedTreeId.get(), index.indexTreeId()); IndexTestSupport.verifyIndex(geogig, indexedTreeId.get(), canonicalFeatureTreeId); }