use of org.locationtech.geogig.osm.internal.log.OSMLogEntry in project GeoGig by boundlessgeo.
the class OSMImportOp method _call.
@Override
protected Optional<OSMReport> _call() {
checkNotNull(urlOrFilepath);
ObjectId oldTreeId = workingTree().getTree().getId();
File osmDataFile = null;
final InputStream osmDataStream;
if (urlOrFilepath.startsWith("http")) {
osmDataStream = downloadFile();
} else {
osmDataFile = new File(urlOrFilepath);
Preconditions.checkArgument(osmDataFile.exists(), "File does not exist: " + urlOrFilepath);
try {
osmDataStream = new BufferedInputStream(new FileInputStream(osmDataFile), 1024 * 1024);
} catch (FileNotFoundException e) {
throw Throwables.propagate(e);
}
}
ProgressListener progressListener = getProgressListener();
progressListener.setDescription("Importing into GeoGig repo...");
EntityConverter converter = new EntityConverter();
OSMReport report;
try {
report = parseDataFileAndInsert(osmDataFile, osmDataStream, converter);
} finally {
Closeables.closeQuietly(osmDataStream);
}
if (!progressListener.isCanceled() && report != null) {
ObjectId newTreeId = workingTree().getTree().getId();
if (!noRaw) {
if (mapping != null || filter != null) {
progressListener.setDescription("Staging features...");
command(AddOp.class).setProgressListener(progressListener).call();
progressListener.setDescription("Committing features...");
command(CommitOp.class).setMessage(message).setProgressListener(progressListener).call();
OSMLogEntry entry = new OSMLogEntry(newTreeId, report.getLatestChangeset(), report.getLatestTimestamp());
command(AddOSMLogEntry.class).setEntry(entry).call();
if (filter != null) {
command(WriteOSMFilterFile.class).setEntry(entry).setFilterCode(filter).call();
}
if (mapping != null) {
command(WriteOSMMappingEntries.class).setMapping(mapping).setMappingLogEntry(new OSMMappingLogEntry(oldTreeId, newTreeId)).call();
}
}
}
}
return Optional.fromNullable(report);
}
use of org.locationtech.geogig.osm.internal.log.OSMLogEntry in project GeoGig by boundlessgeo.
the class OSMUpdateOp method _call.
/**
* Executes the {@code OSMUpdateOp} operation.
*
* @return a {@link OSMDownloadReport} of the operation
*/
@Override
protected Optional<OSMReport> _call() {
final Optional<Ref> currHead = command(RefParse.class).setName(Ref.HEAD).call();
Preconditions.checkState(currHead.isPresent(), "Repository has no HEAD, can't update.");
Preconditions.checkState(currHead.get() instanceof SymRef, "Can't update from detached HEAD");
List<OSMLogEntry> entries = command(ReadOSMLogEntries.class).call();
checkArgument(!entries.isEmpty(), "Not in a geogig repository with OSM data");
Iterator<RevCommit> log = command(LogOp.class).setFirstParentOnly(false).setTopoOrder(false).call();
RevCommit lastCommit = null;
OSMLogEntry lastEntry = null;
while (log.hasNext()) {
RevCommit commit = log.next();
for (OSMLogEntry entry : entries) {
if (entry.getId().equals(commit.getTreeId())) {
lastCommit = commit;
lastEntry = entry;
break;
}
}
if (lastCommit != null) {
break;
}
}
checkNotNull(lastCommit, "The current branch does not contain OSM data");
command(BranchCreateOp.class).setSource(lastCommit.getId().toString()).setName(OSMUtils.OSM_FETCH_BRANCH).setAutoCheckout(true).setForce(true).call();
Optional<String> filter = command(ReadOSMFilterFile.class).setEntry(lastEntry).call();
Preconditions.checkState(filter.isPresent(), "Filter file not found");
message = message == null ? "Updated OSM data" : message;
Optional<OSMReport> report = command(OSMImportOp.class).setMessage(message).setFilter(filter.get()).setDataSource(apiUrl).setProgressListener(getProgressListener()).call();
if (!report.isPresent()) {
return report;
}
if (!getProgressListener().isCanceled()) {
command(CheckoutOp.class).setSource(((SymRef) currHead.get()).getTarget()).call();
Optional<Ref> upstreamRef = command(RefParse.class).setName(OSMUtils.OSM_FETCH_BRANCH).call();
Supplier<ObjectId> commitSupplier = Suppliers.ofInstance(upstreamRef.get().getObjectId());
if (rebase) {
getProgressListener().setDescription("Rebasing updated features...");
command(RebaseOp.class).setUpstream(commitSupplier).setProgressListener(getProgressListener()).call();
} else {
getProgressListener().setDescription("Merging updated features...");
command(MergeOp.class).addCommit(commitSupplier).setProgressListener(getProgressListener()).call();
}
}
return report;
}
use of org.locationtech.geogig.osm.internal.log.OSMLogEntry in project GeoGig by boundlessgeo.
the class OSMDownloadOpTest method testDownloadNodes.
@Ignore
@Test
public void testDownloadNodes() throws Exception {
String filename = OSMImportOp.class.getResource("nodes_overpass_filter.txt").getFile();
File filterFile = new File(filename);
OSMDownloadOp download = geogig.command(OSMDownloadOp.class);
download.setFilterFile(filterFile).setOsmAPIUrl(OSMUtils.DEFAULT_API_ENDPOINT).call();
Optional<Node> tree = geogig.getRepository().getRootTreeChild("node");
assertTrue(tree.isPresent());
List<OSMLogEntry> entries = geogig.command(ReadOSMLogEntries.class).call();
assertFalse(entries.isEmpty());
Iterator<RevCommit> log = geogig.command(LogOp.class).call();
assertTrue(log.hasNext());
}
use of org.locationtech.geogig.osm.internal.log.OSMLogEntry in project GeoGig by boundlessgeo.
the class OSMDownloadOpTest method testDowloadNodesWithDestinationFile.
@Ignore
@Test
public void testDowloadNodesWithDestinationFile() throws Exception {
String filename = OSMImportOp.class.getResource("nodes_overpass_filter.txt").getFile();
File filterFile = new File(filename);
File downloadFile = File.createTempFile("osm-geogig", ".xml");
OSMDownloadOp download = geogig.command(OSMDownloadOp.class);
download.setFilterFile(filterFile).setSaveFile(downloadFile).setOsmAPIUrl(OSMUtils.DEFAULT_API_ENDPOINT).call();
Optional<Node> tree = geogig.getRepository().getRootTreeChild("node");
assertTrue(tree.isPresent());
List<OSMLogEntry> entries = geogig.command(ReadOSMLogEntries.class).call();
assertFalse(entries.isEmpty());
Iterator<RevCommit> log = geogig.command(LogOp.class).call();
assertTrue(log.hasNext());
}
use of org.locationtech.geogig.osm.internal.log.OSMLogEntry in project GeoGig by boundlessgeo.
the class OSMDownloadOpTest method testUpdate.
@Ignore
@Test
public void testUpdate() throws Exception {
String filename = OSMImportOp.class.getResource("fire_station_filter.txt").getFile();
File filterFile = new File(filename);
OSMDownloadOp download = geogig.command(OSMDownloadOp.class);
download.setFilterFile(filterFile).setOsmAPIUrl(OSMUtils.DEFAULT_API_ENDPOINT).call();
Optional<Node> tree = geogig.getRepository().getRootTreeChild("node");
assertTrue(tree.isPresent());
tree = geogig.getRepository().getRootTreeChild("way");
assertTrue(tree.isPresent());
List<OSMLogEntry> entries = geogig.command(ReadOSMLogEntries.class).call();
assertFalse(entries.isEmpty());
OSMUpdateOp update = geogig.command(OSMUpdateOp.class);
try {
update.setAPIUrl(OSMUtils.DEFAULT_API_ENDPOINT).call();
} catch (NothingToCommitException e) {
// No new data
}
}
Aggregations