use of org.locationtech.geogig.api.RevTag in project GeoGig by boundlessgeo.
the class HttpRemoteRepo method fetchMoreData.
/**
* Retrieve objects from the remote repository, and update have/want lists accordingly.
* Specifically, any retrieved commits are removed from the want list and added to the have
* list, and any parents of those commits are removed from the have list (it only represents the
* most recent common commits.) Retrieved objects are added to the local repository, and the
* want/have lists are updated in-place.
*
* @param want a list of ObjectIds that need to be fetched
* @param have a list of ObjectIds that are in common with the remote repository
* @param progress
*/
private void fetchMoreData(final List<ObjectId> want, final Set<ObjectId> have, final ProgressListener progress) {
final JsonObject message = createFetchMessage(want, have);
final URL resourceURL;
try {
resourceURL = new URL(repositoryURL.toString() + "/repo/batchobjects");
} catch (MalformedURLException e) {
throw Throwables.propagate(e);
}
final HttpURLConnection connection;
try {
final Gson gson = new Gson();
OutputStream out;
final Writer writer;
connection = (HttpURLConnection) resourceURL.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.addRequestProperty("Accept-Encoding", "gzip");
out = connection.getOutputStream();
writer = new OutputStreamWriter(out);
gson.toJson(message, writer);
writer.flush();
out.flush();
} catch (IOException e) {
throw Throwables.propagate(e);
}
final HttpUtils.ReportingInputStream in = HttpUtils.getResponseStream(connection);
BinaryPackedObjects unpacker = new BinaryPackedObjects(localRepository.objectDatabase());
BinaryPackedObjects.Callback callback = new BinaryPackedObjects.Callback() {
@Override
public void callback(Supplier<RevObject> supplier) {
RevObject object = supplier.get();
progress.setProgress(progress.getProgress() + 1);
if (object instanceof RevCommit) {
RevCommit commit = (RevCommit) object;
want.remove(commit.getId());
have.removeAll(commit.getParentIds());
have.add(commit.getId());
} else if (object instanceof RevTag) {
RevTag tag = (RevTag) object;
want.remove(tag.getId());
have.remove(tag.getCommitId());
have.add(tag.getId());
}
}
};
Stopwatch sw = Stopwatch.createStarted();
IngestResults ingestResults = unpacker.ingest(in, callback);
sw.stop();
String msg = String.format("Processed %,d objects. Inserted: %,d. Existing: %,d. Time: %s. Compressed size: %,d bytes. Uncompressed size: %,d bytes.", ingestResults.total(), ingestResults.getInserted(), ingestResults.getExisting(), sw, in.compressedSize(), in.unCompressedSize());
LOGGER.info(msg);
progress.setDescription(msg);
}
use of org.locationtech.geogig.api.RevTag in project GeoGig by boundlessgeo.
the class TagCreateOp method _call.
/**
* Executes the tag creation operation.
*
* @return the created tag
*
*/
@Override
protected RevTag _call() throws RuntimeException {
checkState(name != null, "tag name was not provided");
final String tagRefPath = Ref.TAGS_PREFIX + name;
checkArgument(!command(RefParse.class).setName(tagRefPath).call().isPresent(), "A tag named '" + name + "' already exists.");
if (commitId == null) {
final Optional<Ref> currHead = command(RefParse.class).setName(Ref.HEAD).call();
Preconditions.checkState(currHead.isPresent(), "Repository has no HEAD, can't create tag");
commitId = currHead.get().getObjectId();
}
RevPerson tagger = resolveTagger();
message = message == null ? "" : message;
RevTag tag = new RevTagImpl(ObjectId.NULL, name, commitId, message, tagger);
ObjectId id = command(HashObject.class).setObject(tag).call();
tag = new RevTagImpl(id, name, commitId, message, tagger);
objectDatabase().put(tag);
Optional<Ref> branchRef = command(UpdateRef.class).setName(tagRefPath).setNewValue(tag.getId()).call();
checkState(branchRef.isPresent());
return tag;
}
use of org.locationtech.geogig.api.RevTag in project GeoGig by boundlessgeo.
the class CatWebOp method run.
/**
* Runs the command and builds the appropriate response
*
* @param context - the context to use for this command
*
* @throws CommandSpecException
*/
@Override
public void run(CommandContext context) {
Preconditions.checkArgument(object != null && !object.equals(ObjectId.NULL));
final Context geogig = this.getCommandLocator(context);
Preconditions.checkState(geogig.stagingDatabase().exists(object));
final RevObject revObject = geogig.stagingDatabase().get(object);
switch(revObject.getType()) {
case COMMIT:
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeCommit((RevCommit) revObject, "commit", null, null, null);
out.finish();
}
});
break;
case TREE:
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeTree((RevTree) revObject, "tree");
out.finish();
}
});
break;
case FEATURE:
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeFeature((RevFeature) revObject, "feature");
out.finish();
}
});
break;
case FEATURETYPE:
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeFeatureType((RevFeatureType) revObject, "featuretype");
out.finish();
}
});
break;
case TAG:
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeTag((RevTag) revObject, "tag");
out.finish();
}
});
break;
}
}
use of org.locationtech.geogig.api.RevTag in project GeoGig by boundlessgeo.
the class ResponseWriter method writeTagListResponse.
/**
* Writes the response for the {@link TagWebOp} command to the stream.
*
* @param tags the list of {@link RevTag}s of this repository
* @throws XMLStreamException
*/
public void writeTagListResponse(List<RevTag> tags) throws XMLStreamException {
for (RevTag tag : tags) {
out.writeStartElement("Tag");
writeElement("name", tag.getName());
out.writeEndElement();
}
}
use of org.locationtech.geogig.api.RevTag in project GeoGig by boundlessgeo.
the class TagListOp method _call.
@Override
protected ImmutableList<RevTag> _call() {
List<Ref> refs = Lists.newArrayList(command(ForEachRef.class).setPrefixFilter(Ref.TAGS_PREFIX).call());
List<RevTag> list = Lists.newArrayList();
for (Ref ref : refs) {
Optional<RevTag> tag = command(RevObjectParse.class).setObjectId(ref.getObjectId()).call(RevTag.class);
list.add(tag.get());
}
return ImmutableList.copyOf(list);
}
Aggregations