package org.cat.eye.test.bundle.simple;

import org.cat.eye.engine.model.annotation.Compute;
import org.cat.eye.engine.model.annotation.Id;
import org.cat.eye.engine.model.annotation.IsComputable;
import org.cat.eye.engine.model.annotation.Update;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by Kotov on 30.09.2017.
 */
@IsComputable
public class FileCounterComputer {

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

    @Id
    private final String path;

    private int numberLocalFiles;

    private long numberSubdirectoryFiles;

    private long numberFiles;

    private List<FileCounterComputer> computers = new ArrayList<>();

    public FileCounterComputer(String path) {
        this.path = path;
    }

    public String getPath() {
        return path;
    }

    @Compute(step = 1)
    public List<FileCounterComputer> getDirectoriesAndFileCounte() {

        int fileCount = 0;

        File directory = new File(path);

        if (directory.exists() && directory.isDirectory()) {
            File[] files = directory.listFiles();
            if (files != null) {
                for (File file : files) {
                    if (file.isDirectory()) {
                        computers.add(new FileCounterComputer(file.getAbsolutePath()));
                    } else {
                        fileCount++;
                    }
                }
            }
        }

        // write result
        numberLocalFiles = fileCount;

        return computers;
    }

    @Compute(step = 2)
    @Update(fieldNames = {"computers", "numberSubdirectoryFiles"})
    public List countFilesInSubdirectories() {

        long counter = 0;

        if (!this.computers.isEmpty()) {
            for (FileCounterComputer computer : computers) {
                counter =+ computer.getNumberLocalFiles();
            }
        }

        numberSubdirectoryFiles = counter;

        return Collections.EMPTY_LIST;
    }

    @Compute(step = 3)
    public List countFiles() {

        long counter = 0;
        counter = numberLocalFiles + numberSubdirectoryFiles;
        numberFiles = counter;

        return Collections.EMPTY_LIST;
    }

    public int getNumberLocalFiles() {
        return numberLocalFiles;
    }

    public long getNumberFiles() {
        return numberFiles;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof FileCounterComputer)) return false;

        FileCounterComputer that = (FileCounterComputer) o;

        return path.equals(that.path);
    }

    @Override
    public int hashCode() {
        return path.hashCode();
    }
}

@@ -1032,16 +1032,17 @@
 leCounte
+r
 () %7B%0A%0A  
@@ -1429,16 +1429,208 @@
 th()));%0A
+                        LOGGER.info(%22FileCounterComputer.getDirectoriesAndFileCounter - %22 +%0A                                %22Computation with path %5B%7B%7D%7D was created.%22, file.getAbsolutePath());%0A
         
@@ -2178,74 +2178,437 @@
 ();%0A
-            %7D%0A        %7D%0A%0A        numberSubdirectoryFiles = counter
+%0A                LOGGER.info(%22FileCounterComputer.countFilesInSubdirectories - %22 +%0A                        %22Directory %5B%7B0%7D%5D contains %5B%7B1%7D%5D files.%22, computer.getPath(), computer.getNumberLocalFiles());%0A            %7D%0A        %7D%0A%0A        numberSubdirectoryFiles = counter;%0A%0A        LOGGER.info(%22FileCounterComputer.countFilesInSubdirectories - %22 +%0A                %22There are %5B%7B%7D%5D in subdirectories of directory %5B%7B%7D%5D.%22, counter, path)
 ;%0A%0A 
@@ -2819,32 +2819,153 @@
 les = counter;%0A%0A
+        LOGGER.info(%22FileCounterComputer.countFiles - Full quantity files in directory %5B%7B0%7D%5D is %5B%7B1%7D%5D%22, path, counter);%0A%0A
         return C

Create test environment