Search in sources :

Example 1 with Change

use of org.javers.core.diff.Change in project jag-pcss-civil by bcgov.

the class TestService method printDiff.

private void printDiff(Diff diff) {
    int diffSize = diff.getChanges().size();
    if (diffSize == 0) {
        return;
    }
    String[] header = new String[] { "Property", "API Response", "WM Response" };
    String[][] table = new String[diffSize + 1][3];
    table[0] = header;
    for (int i = 0; i < diffSize; ++i) {
        Change ch = diff.getChanges().get(i);
        if (ch instanceof ListChange) {
            String apiVal = ((ListChange) ch).getLeft() == null ? "null" : ((ListChange) ch).getLeft().toString();
            String wmVal = ((ListChange) ch).getRight() == null ? "null" : ((ListChange) ch).getRight().toString();
            table[i + 1][0] = ((ListChange) ch).getPropertyNameWithPath();
            table[i + 1][1] = apiVal;
            table[i + 1][2] = wmVal;
        } else if (ch instanceof ValueChange) {
            String apiVal = ((ValueChange) ch).getLeft() == null ? "null" : ((ValueChange) ch).getLeft().toString();
            String wmVal = ((ValueChange) ch).getRight() == null ? "null" : ((ValueChange) ch).getRight().toString();
            table[i + 1][0] = ((ValueChange) ch).getPropertyNameWithPath();
            table[i + 1][1] = apiVal;
            table[i + 1][2] = wmVal;
        }
    }
    boolean leftJustifiedRows = false;
    int totalColumnLength = 10;
    /*
         * Calculate appropriate Length of each column by looking at width of data in
         * each column.
         *
         * Map columnLengths is <column_number, column_length>
         */
    Map<Integer, Integer> columnLengths = new HashMap<>();
    Arrays.stream(table).forEach(a -> Stream.iterate(0, (i -> i < a.length), (i -> ++i)).forEach(i -> {
        if (columnLengths.get(i) == null) {
            columnLengths.put(i, 0);
        }
        if (columnLengths.get(i) < a[i].length()) {
            columnLengths.put(i, a[i].length());
        }
    }));
    for (Map.Entry<Integer, Integer> e : columnLengths.entrySet()) {
        totalColumnLength += e.getValue();
    }
    fileOutput.println("=".repeat(totalColumnLength));
    System.out.println("=".repeat(totalColumnLength));
    final StringBuilder formatString = new StringBuilder("");
    String flag = leftJustifiedRows ? "-" : "";
    columnLengths.entrySet().stream().forEach(e -> formatString.append("| %" + flag + e.getValue() + "s "));
    formatString.append("|\n");
    Stream.iterate(0, (i -> i < table.length), (i -> ++i)).forEach(a -> {
        fileOutput.printf(formatString.toString(), table[a]);
        System.out.printf(formatString.toString(), table[a]);
    });
    fileOutput.println("=".repeat(totalColumnLength));
    System.out.println("=".repeat(totalColumnLength));
}
Also used : ValueChange(org.javers.core.diff.changetype.ValueChange) Diff(org.javers.core.diff.Diff) java.util(java.util) Jaxb2Marshaller(org.springframework.oxm.jaxb.Jaxb2Marshaller) Javers(org.javers.core.Javers) JaversBuilder(org.javers.core.JaversBuilder) Autowired(org.springframework.beans.factory.annotation.Autowired) Instant(java.time.Instant) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) Value(org.springframework.beans.factory.annotation.Value) ValueChange(org.javers.core.diff.changetype.ValueChange) Stream(java.util.stream.Stream) java.io(java.io) WebServiceTemplate(org.springframework.ws.client.core.WebServiceTemplate) Service(org.springframework.stereotype.Service) ListChange(org.javers.core.diff.changetype.container.ListChange) DualProtocolSaajSoapMessageFactory(ca.bc.gov.open.pcss.civil.comparison.config.DualProtocolSaajSoapMessageFactory) YesNoType(ca.bc.gov.open.pcss.two.YesNoType) Change(org.javers.core.diff.Change) WebServiceSenderWithAuth(ca.bc.gov.open.pcss.civil.comparison.config.WebServiceSenderWithAuth) ca.bc.gov.open.pcss.three(ca.bc.gov.open.pcss.three) HttpComponentsMessageSender(org.springframework.ws.transport.http.HttpComponentsMessageSender) SoapVersion(org.springframework.ws.soap.SoapVersion) ValueChange(org.javers.core.diff.changetype.ValueChange) ListChange(org.javers.core.diff.changetype.container.ListChange) Change(org.javers.core.diff.Change) ListChange(org.javers.core.diff.changetype.container.ListChange)

Aggregations

DualProtocolSaajSoapMessageFactory (ca.bc.gov.open.pcss.civil.comparison.config.DualProtocolSaajSoapMessageFactory)1 WebServiceSenderWithAuth (ca.bc.gov.open.pcss.civil.comparison.config.WebServiceSenderWithAuth)1 ca.bc.gov.open.pcss.three (ca.bc.gov.open.pcss.three)1 YesNoType (ca.bc.gov.open.pcss.two.YesNoType)1 java.io (java.io)1 Instant (java.time.Instant)1 java.util (java.util)1 Stream (java.util.stream.Stream)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 Javers (org.javers.core.Javers)1 JaversBuilder (org.javers.core.JaversBuilder)1 Change (org.javers.core.diff.Change)1 Diff (org.javers.core.diff.Diff)1 ValueChange (org.javers.core.diff.changetype.ValueChange)1 ListChange (org.javers.core.diff.changetype.container.ListChange)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Value (org.springframework.beans.factory.annotation.Value)1 Jaxb2Marshaller (org.springframework.oxm.jaxb.Jaxb2Marshaller)1 Service (org.springframework.stereotype.Service)1 WebServiceTemplate (org.springframework.ws.client.core.WebServiceTemplate)1