Search in sources :

Example 1 with ValueAndCommit

use of org.locationtech.geogig.api.porcelain.ValueAndCommit in project GeoGig by boundlessgeo.

the class ResponseWriter method writeBlameReport.

/**
     * Writes the response for the blame operation.
     * 
     * @param report - the result of the blame operation
     * @throws XMLStreamException
     */
public void writeBlameReport(BlameReport report) throws XMLStreamException {
    out.writeStartElement("Blame");
    Map<String, ValueAndCommit> changes = report.getChanges();
    Iterator<String> iter = changes.keySet().iterator();
    while (iter.hasNext()) {
        String attrib = iter.next();
        ValueAndCommit valueAndCommit = changes.get(attrib);
        RevCommit commit = valueAndCommit.commit;
        Optional<?> value = valueAndCommit.value;
        out.writeStartElement("Attribute");
        writeElement("name", attrib);
        writeElement("value", TextValueSerializer.asString(Optional.fromNullable((Object) value.orNull())));
        writeCommit(commit, "commit", null, null, null);
        out.writeEndElement();
    }
    out.writeEndElement();
}
Also used : ValueAndCommit(org.locationtech.geogig.api.porcelain.ValueAndCommit) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 2 with ValueAndCommit

use of org.locationtech.geogig.api.porcelain.ValueAndCommit in project GeoGig by boundlessgeo.

the class BlameOpTest method testBlameChangedByLastCommit.

@Test
public void testBlameChangedByLastCommit() throws Exception {
    insertAndAdd(points1);
    geogig.command(CommitOp.class).call();
    insertAndAdd(points1_modified);
    RevCommit secondCommit = geogig.command(CommitOp.class).call();
    String path = NodeRef.appendChild(pointsName, idP1);
    BlameReport report = geogig.command(BlameOp.class).setPath(path).call();
    Map<String, ValueAndCommit> changes = report.getChanges();
    assertEquals(3, changes.size());
    Collection<ValueAndCommit> commits = changes.values();
    for (ValueAndCommit valueAndCommit : commits) {
        assertEquals(secondCommit, valueAndCommit.commit);
    }
}
Also used : ValueAndCommit(org.locationtech.geogig.api.porcelain.ValueAndCommit) BlameReport(org.locationtech.geogig.api.porcelain.BlameReport) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 3 with ValueAndCommit

use of org.locationtech.geogig.api.porcelain.ValueAndCommit in project GeoGig by boundlessgeo.

the class BlameOpTest method testBlameChangedByASingleCommit.

@Test
public void testBlameChangedByASingleCommit() throws Exception {
    insertAndAdd(points1);
    RevCommit firstCommit = geogig.command(CommitOp.class).call();
    String path = NodeRef.appendChild(pointsName, idP1);
    BlameReport report = geogig.command(BlameOp.class).setPath(path).call();
    Map<String, ValueAndCommit> changes = report.getChanges();
    assertEquals(3, changes.size());
    Collection<ValueAndCommit> commits = changes.values();
    for (ValueAndCommit valueAndCommit : commits) {
        assertEquals(firstCommit, valueAndCommit.commit);
    }
}
Also used : ValueAndCommit(org.locationtech.geogig.api.porcelain.ValueAndCommit) BlameReport(org.locationtech.geogig.api.porcelain.BlameReport) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 4 with ValueAndCommit

use of org.locationtech.geogig.api.porcelain.ValueAndCommit in project GeoGig by boundlessgeo.

the class Blame method runInternal.

@Override
public void runInternal(GeogigCLI cli) throws IOException {
    checkParameter(paths.size() < 2, "Only one path allowed");
    checkParameter(!paths.isEmpty(), "A path must be specified");
    ConsoleReader console = cli.getConsole();
    GeoGIG geogig = cli.getGeogig();
    String path = paths.get(0);
    try {
        BlameReport report = geogig.command(BlameOp.class).setPath(path).call();
        Map<String, ValueAndCommit> changes = report.getChanges();
        Iterator<String> iter = changes.keySet().iterator();
        while (iter.hasNext()) {
            String attrib = iter.next();
            ValueAndCommit valueAndCommit = changes.get(attrib);
            RevCommit commit = valueAndCommit.commit;
            Optional<?> value = valueAndCommit.value;
            if (porcelain) {
                StringBuilder sb = new StringBuilder();
                sb.append(attrib).append(' ');
                sb.append(commit.getId().toString()).append(' ');
                sb.append(commit.getAuthor().getName().or("")).append(' ');
                sb.append(commit.getAuthor().getEmail().or("")).append(' ');
                sb.append(Long.toString(commit.getAuthor().getTimestamp())).append(' ');
                sb.append(Integer.toString(commit.getAuthor().getTimeZoneOffset()));
                if (!noValues) {
                    sb.append(" ").append(TextValueSerializer.asString(Optional.of((Object) value.orNull())));
                }
                console.println(sb.toString());
            } else {
                Ansi ansi = newAnsi(console.getTerminal());
                ansi.fg(GREEN).a(attrib + ": ").reset();
                if (!noValues) {
                    String s = value.isPresent() ? value.get().toString() : "NULL";
                    ansi.fg(YELLOW).a(s).a(" ").reset();
                }
                ansi.a(commit.getId().toString().substring(0, 7)).a(" ");
                ansi.a(commit.getAuthor().getName().or("")).a(" ");
                ansi.a(commit.getAuthor().getEmail().or("")).a(" ");
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
                String date = formatter.format(new Date(commit.getAuthor().getTimestamp() + commit.getAuthor().getTimeZoneOffset()));
                ansi.a(date);
                console.println(ansi.toString());
            }
        }
    } catch (BlameException e) {
        switch(e.statusCode) {
            case FEATURE_NOT_FOUND:
                throw new InvalidParameterException("The supplied path does not exist", e);
            case PATH_NOT_FEATURE:
                throw new InvalidParameterException("The supplied path does not resolve to a feature", e);
        }
    }
}
Also used : BlameException(org.locationtech.geogig.api.porcelain.BlameException) ConsoleReader(jline.console.ConsoleReader) BlameReport(org.locationtech.geogig.api.porcelain.BlameReport) Date(java.util.Date) ValueAndCommit(org.locationtech.geogig.api.porcelain.ValueAndCommit) InvalidParameterException(org.locationtech.geogig.cli.InvalidParameterException) Ansi(org.fusesource.jansi.Ansi) SimpleDateFormat(java.text.SimpleDateFormat) GeoGIG(org.locationtech.geogig.api.GeoGIG) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 5 with ValueAndCommit

use of org.locationtech.geogig.api.porcelain.ValueAndCommit in project GeoGig by boundlessgeo.

the class BlameOpTest method testBlameRemovedAndAdded.

@Test
public void testBlameRemovedAndAdded() throws Exception {
    insertAndAdd(points1);
    RevCommit firstCommit = geogig.command(CommitOp.class).call();
    deleteAndAdd(points1);
    RevCommit secondCommit = geogig.command(CommitOp.class).call();
    insertAndAdd(points1);
    RevCommit thirdCommit = geogig.command(CommitOp.class).call();
    String path = NodeRef.appendChild(pointsName, idP1);
    BlameReport report = geogig.command(BlameOp.class).setPath(path).call();
    Map<String, ValueAndCommit> changes = report.getChanges();
    assertEquals(3, changes.size());
    Collection<ValueAndCommit> commits = changes.values();
    for (ValueAndCommit valueAndCommit : commits) {
        assertEquals(thirdCommit, valueAndCommit.commit);
    }
    try {
        report = geogig.command(BlameOp.class).setPath(path).setCommit(secondCommit.getId()).call();
        fail();
    } catch (BlameException e) {
        assertTrue(e.statusCode == StatusCode.FEATURE_NOT_FOUND);
    }
    report = geogig.command(BlameOp.class).setPath(path).setCommit(firstCommit.getId()).call();
    changes = report.getChanges();
    assertEquals(3, changes.size());
    commits = changes.values();
    for (ValueAndCommit valueAndCommit : commits) {
        assertEquals(firstCommit, valueAndCommit.commit);
    }
}
Also used : BlameException(org.locationtech.geogig.api.porcelain.BlameException) ValueAndCommit(org.locationtech.geogig.api.porcelain.ValueAndCommit) BlameReport(org.locationtech.geogig.api.porcelain.BlameReport) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Aggregations

RevCommit (org.locationtech.geogig.api.RevCommit)6 ValueAndCommit (org.locationtech.geogig.api.porcelain.ValueAndCommit)6 BlameReport (org.locationtech.geogig.api.porcelain.BlameReport)5 Test (org.junit.Test)4 CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)4 BlameException (org.locationtech.geogig.api.porcelain.BlameException)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 ConsoleReader (jline.console.ConsoleReader)1 Ansi (org.fusesource.jansi.Ansi)1 GeoGIG (org.locationtech.geogig.api.GeoGIG)1 InvalidParameterException (org.locationtech.geogig.cli.InvalidParameterException)1 Feature (org.opengis.feature.Feature)1