All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.adamcin.oakpal.cli.ReportMessage Maven / Gradle / Ivy

There is a newer version: 2.3.0
Show newest version
package net.adamcin.oakpal.cli;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Set;
import java.util.stream.Collectors;
import javax.json.JsonObject;

import net.adamcin.oakpal.core.CheckReport;
import net.adamcin.oakpal.core.Violation;
import org.apache.jackrabbit.vault.packaging.PackageId;

public class ReportMessage implements StructuredMessage {
    private final CheckReport report;

    public ReportMessage(final CheckReport report) {
        this.report = report;
    }

    @Override
    public String toString() {
        StringWriter sw = new StringWriter();
        try (PrintWriter writer = new PrintWriter(sw)) {
            writer.println(String.format("report: %s", String.valueOf(report.getCheckName())));
            for (Violation v : report.getViolations()) {
                final Set packageIds = v.getPackages().stream().map(PackageId::getDownloadName)
                        .collect(Collectors.toSet());
                final String violLog = !packageIds.isEmpty()
                        ? String.format(" +- <%s> %s %s", v.getSeverity(), v.getDescription(), packageIds)
                        : String.format(" +- <%s> %s", v.getSeverity(), v.getDescription());
                writer.println(violLog);
            }
        }
        return sw.toString().trim();
    }

    @Override
    public JsonObject toJson() {
        return report.toJson();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy