use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.
the class ResponseWriter method writeDiffEntries.
/**
* Writes a set of {@link DiffEntry}s to the stream.
*
* @param name the element name
* @param start the change number to start writing from
* @param length the number of changes to write
* @param entries an iterator for the DiffEntries to write
* @throws XMLStreamException
*/
public void writeDiffEntries(String name, int start, int length, Iterator<DiffEntry> entries) throws XMLStreamException {
Iterators.advance(entries, start);
if (length < 0) {
length = Integer.MAX_VALUE;
}
int counter = 0;
while (entries.hasNext() && counter < length) {
DiffEntry entry = entries.next();
out.writeStartElement(name);
writeElement("changeType", entry.changeType().toString());
NodeRef oldObject = entry.getOldObject();
NodeRef newObject = entry.getNewObject();
if (oldObject == null) {
writeElement("newPath", newObject.path());
writeElement("newObjectId", newObject.objectId().toString());
writeElement("path", "");
writeElement("oldObjectId", ObjectId.NULL.toString());
} else if (newObject == null) {
writeElement("newPath", "");
writeElement("newObjectId", ObjectId.NULL.toString());
writeElement("path", oldObject.path());
writeElement("oldObjectId", oldObject.objectId().toString());
} else {
writeElement("newPath", newObject.path());
writeElement("newObjectId", newObject.objectId().toString());
writeElement("path", oldObject.path());
writeElement("oldObjectId", oldObject.objectId().toString());
}
out.writeEndElement();
counter++;
}
if (entries.hasNext()) {
writeElement("nextPage", "true");
}
}
use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.
the class ResponseWriter method writeCommitResponse.
/**
* Writes the response for the {@link Commit} command to the stream.
*
* @param commit the commit
* @param diff the changes returned from the command
* @throws XMLStreamException
*/
public void writeCommitResponse(RevCommit commit, Iterator<DiffEntry> diff) throws XMLStreamException {
int adds = 0, deletes = 0, changes = 0;
DiffEntry diffEntry;
while (diff.hasNext()) {
diffEntry = diff.next();
switch(diffEntry.changeType()) {
case ADDED:
++adds;
break;
case REMOVED:
++deletes;
break;
case MODIFIED:
++changes;
break;
}
}
writeElement("commitId", commit.getId().toString());
writeElement("added", Integer.toString(adds));
writeElement("changed", Integer.toString(changes));
writeElement("deleted", Integer.toString(deletes));
}
use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.
the class ResponseWriter method writePullResponse.
public void writePullResponse(PullResult result, Iterator<DiffEntry> iter, Context geogig) throws XMLStreamException {
out.writeStartElement("Pull");
writeFetchResponse(result.getFetchResult());
if (iter != null) {
writeElement("Remote", result.getRemoteName());
writeElement("Ref", result.getNewRef().localName());
int added = 0;
int removed = 0;
int modified = 0;
while (iter.hasNext()) {
DiffEntry entry = iter.next();
if (entry.changeType() == ChangeType.ADDED) {
added++;
} else if (entry.changeType() == ChangeType.MODIFIED) {
modified++;
} else if (entry.changeType() == ChangeType.REMOVED) {
removed++;
}
}
writeElement("Added", Integer.toString(added));
writeElement("Modified", Integer.toString(modified));
writeElement("Removed", Integer.toString(removed));
}
if (result.getMergeReport().isPresent() && result.getMergeReport().get().getReport().isPresent()) {
MergeReport report = result.getMergeReport().get();
writeMergeResponse(Optional.fromNullable(report.getMergeCommit()), report.getReport().get(), geogig, report.getOurs(), report.getPairs().get(0).getTheirs(), report.getPairs().get(0).getAncestor());
}
out.writeEndElement();
}
use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.
the class Commit 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) {
if (this.getTransactionId() == null) {
throw new CommandSpecException("No transaction was specified, commit requires a transaction to preserve the stability of the repository.");
}
final Context geogig = this.getCommandLocator(context);
RevCommit commit;
try {
commit = geogig.command(CommitOp.class).setAuthor(authorName.orNull(), authorEmail.orNull()).setMessage(message).setAllowEmpty(true).setAll(all).call();
assert commit != null;
} catch (NothingToCommitException noChanges) {
context.setResponseContent(CommandResponse.warning("Nothing to commit"));
commit = null;
} catch (IllegalStateException e) {
context.setResponseContent(CommandResponse.warning(e.getMessage()));
commit = null;
}
if (commit != null) {
final RevCommit commitToWrite = commit;
final ObjectId parentId = commit.parentN(0).or(ObjectId.NULL);
final Iterator<DiffEntry> diff = geogig.command(DiffOp.class).setOldVersion(parentId).setNewVersion(commit.getId()).call();
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeCommitResponse(commitToWrite, diff);
out.finish();
}
});
}
}
use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.
the class ResponseWriter method writeGeometryChanges.
/**
* Writes the response for a set of diffs while also supplying the geometry.
*
* @param geogig - a CommandLocator to call commands from
* @param diff - a DiffEntry iterator to build the response from
* @throws XMLStreamException
*/
public void writeGeometryChanges(final Context geogig, Iterator<DiffEntry> diff, int page, int elementsPerPage) throws XMLStreamException {
Iterators.advance(diff, page * elementsPerPage);
int counter = 0;
Iterator<GeometryChange> changeIterator = Iterators.transform(diff, new Function<DiffEntry, GeometryChange>() {
@Override
public GeometryChange apply(DiffEntry input) {
Optional<RevObject> feature = Optional.absent();
Optional<RevObject> type = Optional.absent();
String path = null;
String crsCode = null;
GeometryChange change = null;
if (input.changeType() == ChangeType.ADDED || input.changeType() == ChangeType.MODIFIED) {
feature = geogig.command(RevObjectParse.class).setObjectId(input.newObjectId()).call();
type = geogig.command(RevObjectParse.class).setObjectId(input.getNewObject().getMetadataId()).call();
path = input.getNewObject().path();
} else if (input.changeType() == ChangeType.REMOVED) {
feature = geogig.command(RevObjectParse.class).setObjectId(input.oldObjectId()).call();
type = geogig.command(RevObjectParse.class).setObjectId(input.getOldObject().getMetadataId()).call();
path = input.getOldObject().path();
}
if (feature.isPresent() && feature.get() instanceof RevFeature && type.isPresent() && type.get() instanceof RevFeatureType) {
RevFeatureType featureType = (RevFeatureType) type.get();
Collection<PropertyDescriptor> attribs = featureType.type().getDescriptors();
for (PropertyDescriptor attrib : attribs) {
PropertyType attrType = attrib.getType();
if (attrType instanceof GeometryType) {
GeometryType gt = (GeometryType) attrType;
CoordinateReferenceSystem crs = gt.getCoordinateReferenceSystem();
if (crs != null) {
try {
crsCode = CRS.lookupIdentifier(Citations.EPSG, crs, false);
} catch (FactoryException e) {
crsCode = null;
}
if (crsCode != null) {
crsCode = "EPSG:" + crsCode;
}
}
break;
}
}
RevFeature revFeature = (RevFeature) feature.get();
FeatureBuilder builder = new FeatureBuilder(featureType);
GeogigSimpleFeature simpleFeature = (GeogigSimpleFeature) builder.build(revFeature.getId().toString(), revFeature);
change = new GeometryChange(simpleFeature, input.changeType(), path, crsCode);
}
return change;
}
});
while (changeIterator.hasNext() && (elementsPerPage == 0 || counter < elementsPerPage)) {
GeometryChange next = changeIterator.next();
if (next != null) {
GeogigSimpleFeature feature = next.getFeature();
ChangeType change = next.getChangeType();
out.writeStartElement("Feature");
writeElement("change", change.toString());
writeElement("id", next.getPath());
List<Object> attributes = feature.getAttributes();
for (Object attribute : attributes) {
if (attribute instanceof Geometry) {
writeElement("geometry", ((Geometry) attribute).toText());
break;
}
}
if (next.getCRS() != null) {
writeElement("crs", next.getCRS());
}
out.writeEndElement();
counter++;
}
}
if (changeIterator.hasNext()) {
writeElement("nextPage", "true");
}
}
Aggregations