Search in sources :

Example 6 with IRemoteRepo

use of org.locationtech.geogig.remote.IRemoteRepo in project GeoGig by boundlessgeo.

the class RemoteWebOp method remotePing.

private void remotePing(CommandContext context, final Context geogig) {
    Optional<Remote> remote = geogig.command(RemoteResolve.class).setName(remoteName).call();
    final boolean remotePingResponse;
    if (remote.isPresent()) {
        Optional<IRemoteRepo> remoteRepo = RemoteUtils.newRemote(GlobalContextBuilder.builder.build(), remote.get(), null, null);
        Ref ref = null;
        if (remoteRepo.isPresent()) {
            try {
                remoteRepo.get().open();
                ref = remoteRepo.get().headRef();
                remoteRepo.get().close();
            } catch (IOException e) {
            // Do nothing, we will write the response later.
            }
        }
        remotePingResponse = ref != null;
    } else {
        remotePingResponse = false;
    }
    context.setResponseContent(new CommandResponse() {

        @Override
        public void write(ResponseWriter out) throws Exception {
            out.start();
            out.writeRemotePingResponse(remotePingResponse);
            out.finish();
        }
    });
}
Also used : Ref(org.locationtech.geogig.api.Ref) ResponseWriter(org.locationtech.geogig.web.api.ResponseWriter) IRemoteRepo(org.locationtech.geogig.remote.IRemoteRepo) Remote(org.locationtech.geogig.api.Remote) IOException(java.io.IOException) CommandResponse(org.locationtech.geogig.web.api.CommandResponse) IOException(java.io.IOException) RemoteException(org.locationtech.geogig.api.porcelain.RemoteException) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException)

Aggregations

IOException (java.io.IOException)6 IRemoteRepo (org.locationtech.geogig.remote.IRemoteRepo)6 Ref (org.locationtech.geogig.api.Ref)4 Remote (org.locationtech.geogig.api.Remote)4 ProgressListener (org.locationtech.geogig.api.ProgressListener)2 SymRef (org.locationtech.geogig.api.SymRef)2 LsRemote (org.locationtech.geogig.api.plumbing.LsRemote)2 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)2 ArrayList (java.util.ArrayList)1 UpdateSymRef (org.locationtech.geogig.api.plumbing.UpdateSymRef)1 RemoteException (org.locationtech.geogig.api.porcelain.RemoteException)1 TransferSummary (org.locationtech.geogig.api.porcelain.TransferSummary)1 ChangedRef (org.locationtech.geogig.api.porcelain.TransferSummary.ChangedRef)1 Repository (org.locationtech.geogig.repository.Repository)1 CommandResponse (org.locationtech.geogig.web.api.CommandResponse)1 CommandSpecException (org.locationtech.geogig.web.api.CommandSpecException)1 ResponseWriter (org.locationtech.geogig.web.api.ResponseWriter)1