Search in sources :

Example 1 with ChangeType

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());
}
Also used : ChangeType(org.locationtech.geogig.api.plumbing.diff.DiffEntry.ChangeType) Ansi(org.fusesource.jansi.Ansi) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 2 with ChangeType

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");
    }
}
Also used : FeatureBuilder(org.locationtech.geogig.api.FeatureBuilder) RevFeatureBuilder(org.locationtech.geogig.api.RevFeatureBuilder) Optional(com.google.common.base.Optional) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) FactoryException(org.opengis.referencing.FactoryException) PropertyType(org.opengis.feature.type.PropertyType) Geometry(com.vividsolutions.jts.geom.Geometry) GeometryType(org.opengis.feature.type.GeometryType) ChangeType(org.locationtech.geogig.api.plumbing.diff.DiffEntry.ChangeType) RevFeature(org.locationtech.geogig.api.RevFeature) Collection(java.util.Collection) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) RevObject(org.locationtech.geogig.api.RevObject) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeogigSimpleFeature(org.locationtech.geogig.api.GeogigSimpleFeature) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 3 with ChangeType

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) {
        }
    }
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) IOException(java.io.IOException) ResetOp(org.locationtech.geogig.api.porcelain.ResetOp) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) ChangeType(org.locationtech.geogig.api.plumbing.diff.DiffEntry.ChangeType) ResetMode(org.locationtech.geogig.api.porcelain.ResetOp.ResetMode) GeoGIG(org.locationtech.geogig.api.GeoGIG) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Aggregations

DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)3 ChangeType (org.locationtech.geogig.api.plumbing.diff.DiffEntry.ChangeType)3 Optional (com.google.common.base.Optional)1 Geometry (com.vividsolutions.jts.geom.Geometry)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 Ansi (org.fusesource.jansi.Ansi)1 FeatureBuilder (org.locationtech.geogig.api.FeatureBuilder)1 GeoGIG (org.locationtech.geogig.api.GeoGIG)1 GeogigSimpleFeature (org.locationtech.geogig.api.GeogigSimpleFeature)1 ObjectId (org.locationtech.geogig.api.ObjectId)1 RevFeature (org.locationtech.geogig.api.RevFeature)1 RevFeatureBuilder (org.locationtech.geogig.api.RevFeatureBuilder)1 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)1 RevObject (org.locationtech.geogig.api.RevObject)1 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)1 ResetOp (org.locationtech.geogig.api.porcelain.ResetOp)1 ResetMode (org.locationtech.geogig.api.porcelain.ResetOp.ResetMode)1 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)1 GeometryType (org.opengis.feature.type.GeometryType)1