
package info.freelibrary.jiiify.util;

import java.awt.Dimension;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import info.freelibrary.jiiify.iiif.IIIFException;
import info.freelibrary.jiiify.iiif.ImageRequest;
import info.freelibrary.util.PairtreeRoot;

import au.com.bytecode.opencsv.CSVReader;
import au.com.bytecode.opencsv.CSVWriter;

public class ReportUtils {

    private static final File CSV_FILE = new File("input.csv");

    private static final File CSV_OUT = new File("output.csv");

    private static final Logger LOGGER = LoggerFactory.getLogger(ReportUtils.class);

    private static int myFoundCount;

    private static int myNotFoundCount;

    public static final void main(final String[] args) throws IOException {
        final CSVReader csvReader = new CSVReader(new FileReader(CSV_FILE));
        final PairtreeRoot ptRoot = new PairtreeRoot(new File(args[0]));
        final CSVWriter csvWriter = new CSVWriter(new FileWriter(CSV_OUT));

        csvReader.readAll().forEach(image -> {
            try {
                final File imageFile = new File(image[1]);
                final Dimension dim = ImageUtils.getImageDimension(imageFile);

                myFoundCount = 0;
                myNotFoundCount = 0;

                ImageUtils.getTilePaths("/iiif", image[0], 1024, dim.width, dim.height).forEach(path -> {
                    try {
                        final ImageRequest request = new ImageRequest(path);

                        if (request.hasCachedFile(ptRoot)) {
                            myFoundCount++;
                        } else {
                            myNotFoundCount++;
                        }
                    } catch (final IIIFException | IOException details) {
                        try {
                            csvWriter.close();
                            csvReader.close();
                        } catch (final IOException ignorable) {
                            LOGGER.error(ignorable.getMessage(), ignorable);
                        }

                        throw new RuntimeException(details);
                    }
                });

                csvWriter.writeNext(new String[] { imageFile.getAbsolutePath(), Integer.toString(myFoundCount),
                    Integer.toString(myNotFoundCount) });
            } catch (final IOException details) {
                try {
                    csvWriter.close();
                    csvReader.close();
                } catch (final IOException ignorable) {
                    LOGGER.error(ignorable.getMessage(), ignorable);
                }

                throw new RuntimeException(details);
            }
        });

        csvReader.close();
        csvWriter.close();
    }
}

@@ -851,16 +851,377 @@
 ption %7B%0A
+        if (args.length %3E 1 && args%5B0%5D.equals(%22ptcheck%22)) %7B%0A            checkPairtree(args%5B1%5D);%0A        %7D else %7B%0A            System.err.println(%22Usage: java -cp path/to/my.jar %22 + ReportUtils.class.getName() +%0A                    %22 ptcheck /my/pt/path%22);%0A        %7D%0A    %7D%0A%0A    private static final void checkPairtree(final String aFilePath) throws IOException %7B%0A
         
@@ -1352,22 +1352,24 @@
 w File(a
-rgs%5B0%5D
+FilePath
 ));%0A    

Update ReportUtils script so other reports can be added