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());
}
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());
}
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();
}
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);
}
Aggregations