Search in sources :

Example 1 with ChangeContainer

use of org.openstreetmap.osmosis.core.container.v0_6.ChangeContainer in project GeoGig by boundlessgeo.

the class CreateOSMChangesetOpTest method testCreateChangesets.

@Test
public void testCreateChangesets() throws Exception {
    String filename = getClass().getResource("nodes_for_changeset.xml").getFile();
    File file = new File(filename);
    geogig.command(OSMImportOp.class).setDataSource(file.getAbsolutePath()).call();
    long unstaged = geogig.getRepository().workingTree().countUnstaged("node").count();
    assertTrue(unstaged > 0);
    geogig.command(AddOp.class).call();
    geogig.command(CommitOp.class).setMessage("commit1").call();
    filename = getClass().getResource("nodes_for_changeset2.xml").getFile();
    file = new File(filename);
    geogig.command(OSMImportOp.class).setDataSource(file.getAbsolutePath()).call();
    unstaged = geogig.getRepository().workingTree().countUnstaged("node").count();
    assertTrue(unstaged > 0);
    geogig.command(AddOp.class).call();
    geogig.command(CommitOp.class).setMessage("commit2").call();
    Iterator<ChangeContainer> changes = geogig.command(CreateOSMChangesetOp.class).setNewVersion("HEAD").setOldVersion("HEAD~1").call();
    List<ChangeContainer> list = Lists.newArrayList(changes);
    assertEquals(3, list.size());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) ChangeContainer(org.openstreetmap.osmosis.core.container.v0_6.ChangeContainer) File(java.io.File) Test(org.junit.Test)

Example 2 with ChangeContainer

use of org.openstreetmap.osmosis.core.container.v0_6.ChangeContainer in project GeoGig by boundlessgeo.

the class CreateOSMChangesetOpTest method testCreateChangesetsWithIdReplacement.

@Test
public void testCreateChangesetsWithIdReplacement() throws Exception {
    String filename = getClass().getResource("nodes_for_changeset.xml").getFile();
    File file = new File(filename);
    geogig.command(OSMImportOp.class).setDataSource(file.getAbsolutePath()).call();
    long unstaged = geogig.getRepository().workingTree().countUnstaged("node").count();
    assertTrue(unstaged > 0);
    geogig.command(AddOp.class).call();
    geogig.command(CommitOp.class).setMessage("commit1").call();
    filename = getClass().getResource("nodes_for_changeset3.xml").getFile();
    file = new File(filename);
    geogig.command(OSMImportOp.class).setDataSource(file.getAbsolutePath()).call();
    unstaged = geogig.getRepository().workingTree().countUnstaged("node").count();
    assertTrue(unstaged > 0);
    geogig.command(AddOp.class).call();
    geogig.command(CommitOp.class).setMessage("commit2").call();
    Iterator<ChangeContainer> changes = geogig.command(CreateOSMChangesetOp.class).setNewVersion("HEAD").setOldVersion("HEAD~1").setId(1l).call();
    List<ChangeContainer> list = Lists.newArrayList(changes);
    assertEquals(3, list.size());
    assertEquals(1l, list.get(0).getEntityContainer().getEntity().getChangesetId());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) ChangeContainer(org.openstreetmap.osmosis.core.container.v0_6.ChangeContainer) File(java.io.File) Test(org.junit.Test)

Example 3 with ChangeContainer

use of org.openstreetmap.osmosis.core.container.v0_6.ChangeContainer in project GeoGig by boundlessgeo.

the class CreateOSMChangeset method runInternal.

/**
     * Executes the command with the specified options.
     */
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
    checkParameter(refSpec.size() < 3, "Commit list is too long :" + refSpec);
    GeoGIG geogig = cli.getGeogig();
    CreateOSMChangesetOp op = geogig.command(CreateOSMChangesetOp.class);
    String oldVersion = resolveOldVersion();
    String newVersion = resolveNewVersion();
    op.setOldVersion(oldVersion).setNewVersion(newVersion).setId(id);
    Iterator<ChangeContainer> entries;
    entries = op.setProgressListener(cli.getProgressListener()).call();
    if (!entries.hasNext()) {
        cli.getConsole().println("No differences found");
        return;
    }
    BufferedWriter bufWriter = new BufferedWriter(new FileWriter(new File(file)));
    XmlChangeWriter writer = new XmlChangeWriter(bufWriter);
    while (entries.hasNext()) {
        ChangeContainer change = entries.next();
        writer.process(change);
    }
    writer.complete();
    bufWriter.flush();
}
Also used : ChangeContainer(org.openstreetmap.osmosis.core.container.v0_6.ChangeContainer) FileWriter(java.io.FileWriter) XmlChangeWriter(org.openstreetmap.osmosis.xml.v0_6.XmlChangeWriter) CreateOSMChangesetOp(org.locationtech.geogig.osm.internal.CreateOSMChangesetOp) File(java.io.File) GeoGIG(org.locationtech.geogig.api.GeoGIG) BufferedWriter(java.io.BufferedWriter)

Example 4 with ChangeContainer

use of org.openstreetmap.osmosis.core.container.v0_6.ChangeContainer in project GeoGig by boundlessgeo.

the class CreateOSMChangesetOp method _call.

/**
     * Executes the diff operation.
     * 
     * @return an iterator to a set of differences between the two trees
     * @see DiffEntry
     */
@Override
protected Iterator<ChangeContainer> _call() {
    Iterator<DiffEntry> nodeIterator = command(DiffOp.class).setFilter(OSMUtils.NODE_TYPE_NAME).setNewVersion(newRefSpec).setOldVersion(oldRefSpec).setReportTrees(false).call();
    Iterator<DiffEntry> wayIterator = command(DiffOp.class).setFilter(OSMUtils.WAY_TYPE_NAME).setNewVersion(newRefSpec).setOldVersion(oldRefSpec).setReportTrees(false).call();
    Iterator<DiffEntry> iterator = Iterators.concat(nodeIterator, wayIterator);
    final EntityConverter converter = new EntityConverter();
    Function<DiffEntry, ChangeContainer> function = new Function<DiffEntry, ChangeContainer>() {

        @Override
        @Nullable
        public ChangeContainer apply(@Nullable DiffEntry diff) {
            NodeRef ref = diff.changeType().equals(ChangeType.REMOVED) ? diff.getOldObject() : diff.getNewObject();
            RevFeature revFeature = command(RevObjectParse.class).setObjectId(ref.objectId()).call(RevFeature.class).get();
            RevFeatureType revFeatureType = command(RevObjectParse.class).setObjectId(ref.getMetadataId()).call(RevFeatureType.class).get();
            SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder((SimpleFeatureType) revFeatureType.type());
            ImmutableList<PropertyDescriptor> descriptors = revFeatureType.sortedDescriptors();
            ImmutableList<Optional<Object>> values = revFeature.getValues();
            for (int i = 0; i < descriptors.size(); i++) {
                PropertyDescriptor descriptor = descriptors.get(i);
                Optional<Object> value = values.get(i);
                featureBuilder.set(descriptor.getName(), value.orNull());
            }
            SimpleFeature feature = featureBuilder.buildFeature(ref.name());
            Entity entity = converter.toEntity(feature, id);
            EntityContainer container;
            if (entity instanceof Node) {
                container = new NodeContainer((Node) entity);
            } else {
                container = new WayContainer((Way) entity);
            }
            ChangeAction action = diff.changeType().equals(ChangeType.ADDED) ? ChangeAction.Create : diff.changeType().equals(ChangeType.MODIFIED) ? ChangeAction.Modify : ChangeAction.Delete;
            return new ChangeContainer(container, action);
        }
    };
    return Iterators.transform(iterator, function);
}
Also used : Entity(org.openstreetmap.osmosis.core.domain.v0_6.Entity) WayContainer(org.openstreetmap.osmosis.core.container.v0_6.WayContainer) ChangeAction(org.openstreetmap.osmosis.core.task.common.ChangeAction) Node(org.openstreetmap.osmosis.core.domain.v0_6.Node) EntityContainer(org.openstreetmap.osmosis.core.container.v0_6.EntityContainer) NodeContainer(org.openstreetmap.osmosis.core.container.v0_6.NodeContainer) Way(org.openstreetmap.osmosis.core.domain.v0_6.Way) Function(com.google.common.base.Function) NodeRef(org.locationtech.geogig.api.NodeRef) RevFeature(org.locationtech.geogig.api.RevFeature) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) ChangeContainer(org.openstreetmap.osmosis.core.container.v0_6.ChangeContainer) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) Optional(com.google.common.base.Optional) DiffOp(org.locationtech.geogig.api.porcelain.DiffOp) SimpleFeature(org.opengis.feature.simple.SimpleFeature) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) Nullable(javax.annotation.Nullable) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Aggregations

ChangeContainer (org.openstreetmap.osmosis.core.container.v0_6.ChangeContainer)4 File (java.io.File)3 Test (org.junit.Test)2 AddOp (org.locationtech.geogig.api.porcelain.AddOp)2 Function (com.google.common.base.Function)1 Optional (com.google.common.base.Optional)1 BufferedWriter (java.io.BufferedWriter)1 FileWriter (java.io.FileWriter)1 Nullable (javax.annotation.Nullable)1 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)1 GeoGIG (org.locationtech.geogig.api.GeoGIG)1 NodeRef (org.locationtech.geogig.api.NodeRef)1 RevFeature (org.locationtech.geogig.api.RevFeature)1 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)1 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)1 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)1 DiffOp (org.locationtech.geogig.api.porcelain.DiffOp)1 CreateOSMChangesetOp (org.locationtech.geogig.osm.internal.CreateOSMChangesetOp)1 SimpleFeature (org.opengis.feature.simple.SimpleFeature)1 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)1