use of org.locationtech.geogig.api.plumbing.diff.DiffEntry.ChangeType in project GeoGig by boundlessgeo.
the class Status method print.
/**
* Prints the list of changes using the specified options
*
* @param console the output console
* @param changes an iterator of differences to print
* @param color the color to use for the changes if color use is enabled
* @param total the total number of changes
* @throws IOException
* @see DiffEntry
*/
private void print(final ConsoleReader console, final Iterator<DiffEntry> changes, final Color color, final long total) throws IOException {
final int limit = all || this.limit == null ? Integer.MAX_VALUE : this.limit.intValue();
StringBuilder sb = new StringBuilder();
Ansi ansi = newAnsi(console.getTerminal(), sb);
DiffEntry entry;
ChangeType type;
String path;
int cnt = 0;
if (limit > 0) {
Iterator<DiffEntry> changesIterator = changes;
while (changesIterator.hasNext() && cnt < limit) {
++cnt;
entry = changesIterator.next();
type = entry.changeType();
path = formatPath(entry);
sb.setLength(0);
ansi.a("# ").fg(color).a(type.toString().toLowerCase()).a(" ").a(path).reset();
console.println(ansi.toString());
}
}
sb.setLength(0);
ansi.a("# ").a(String.format("%,d", total)).a(" total.");
console.println(ansi.toString());
}
use of org.locationtech.geogig.api.plumbing.diff.DiffEntry.ChangeType 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");
}
}
use of org.locationtech.geogig.api.plumbing.diff.DiffEntry.ChangeType in project GeoGig by boundlessgeo.
the class Reset method runInternal.
/**
* Executes the reset command using the provided options.
*
* @param cli
* @see org.locationtech.geogig.cli.AbstractCommand#runInternal(org.locationtech.geogig.cli.GeogigCLI)
*/
@Override
public void runInternal(GeogigCLI cli) {
final GeoGIG geogig = cli.getGeogig();
ResetMode mode = resolveResetMode();
ResetOp reset = cli.getGeogig().command(ResetOp.class);
try {
for (int i = 0; args != null && i < args.size(); i++) {
reset.addPattern(args.get(i));
}
if (commit != null && commit.size() > 0) {
Optional<ObjectId> commitId = geogig.command(RevParse.class).setRefSpec(commit.get(0)).call();
checkParameter(commitId.isPresent(), "Commit could not be resolved.");
reset.setCommit(Suppliers.ofInstance(commitId.get()));
}
reset.setMode(mode);
reset.call();
} catch (IllegalArgumentException iae) {
throw new CommandFailedException(iae.getMessage(), iae);
} catch (IllegalStateException ise) {
throw new CommandFailedException(ise.getMessage(), ise);
}
if (!geogig.getRepository().workingTree().isClean()) {
try {
Iterator<DiffEntry> unstaged = geogig.command(DiffWorkTree.class).setFilter(null).call();
cli.getConsole().println("Unstaged changes after reset:");
while (unstaged.hasNext()) {
DiffEntry entry = unstaged.next();
ChangeType type = entry.changeType();
switch(type) {
case ADDED:
cli.getConsole().println("A\t" + entry.newPath());
break;
case MODIFIED:
cli.getConsole().println("M\t" + entry.newPath());
break;
case REMOVED:
cli.getConsole().println("D\t" + entry.oldPath());
break;
}
}
} catch (IOException e) {
}
}
}
Aggregations