package dk.statsbiblioteket.doms.transformers.common;

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

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

/**
 * Run through list of UUIDs, call object handler, and report status in logging and files.
 */
public class FileRecordingObjectListHandler implements ObjectListHandler {
    private final Logger log = LoggerFactory.getLogger(getClass());
    private final BufferedWriter successFileWriter;
    private final BufferedWriter failureFileWriter;
    private ObjectHandler objectHandler;

    /**
     * Initialise handler. Will open files for reporting successes and failures.
     *
     * @param config Configuration. Will read file names from here.
     * @param objectHandler The object handler that should handle each uuid.
     * @throws IOException On trouble opening the files.
     */
    public FileRecordingObjectListHandler(Config config, ObjectHandler objectHandler) throws IOException {
        this.objectHandler = objectHandler;
        successFileWriter = new BufferedWriter(new FileWriter(new File(config.getSuccessFile())));
        failureFileWriter = new BufferedWriter(new FileWriter(new File(config.getFailureFile())));
    }

    @Override
    public void transform(List<String> uuids) {
        for (String uuid : uuids) {
            try {
                System.out.println("trying to transform... " + uuid);
                objectHandler.transform(uuid);
                System.out.println("transformed... " + uuid);
                recordSuccess(uuid);
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println(e.getMessage());
                log.error("Error processing uuid '{}'", uuid, e);
                recordFailure(uuid);
            }
        }
    }

    private void recordSuccess(String uuid) {
        try {
            successFileWriter.write(uuid);
            successFileWriter.newLine();
            successFileWriter.flush();
        } catch (IOException e) {
            log.error("Unable to record success of '{}'", uuid, e);
        }
        log.info("Successfully processed '{}'", uuid);
    }

    private void recordFailure(String uuid) {
        try {
            failureFileWriter.write(uuid);
            failureFileWriter.newLine();
            failureFileWriter.flush();
        } catch (IOException e) {
            log.error("Unable to record failure of '{}'", uuid, e);
        }
        log.info("Failure processing '{}'", uuid);
    }
}

@@ -419,24 +419,31 @@
     private 
+static 
 final Logger
@@ -477,18 +477,40 @@
 ger(
-getClass()
+%22FileRecordingObjectListHandler%22
 );%0A 
@@ -512,37 +512,38 @@
 %22);%0A    private 
-final
+static
  BufferedWriter 
@@ -573,21 +573,22 @@
 private 
-final
+static
  Buffere
@@ -1906,38 +1906,44 @@
   %7D%0A    %7D%0A%0A    p
-rivate
+ublic static
  void recordSucc
@@ -2277,22 +2277,28 @@
 %7D%0A%0A    p
-rivate
+ublic static
  void re

Make logging functions static.