audittool/test-lib/src/main/java/io/bdrc/audit/audittests/FileSequence.java
private void sequenceImageGroupParent(final int sequenceLength,  final Path imageGroupParent) throws IOException
        {
            // asset-manager #29 don't count json files in image groups
            DirectoryStream.Filter<Path> dirFilter =
                    entry -> !entry.toFile().isHidden() && entry.toFile().isDirectory();

            // asset-manager #23 don't count directories in image groups
            // asset-manager #29 don't count json files in image groups
            DirectoryStream.Filter<Path> filesInImageGroupFilter =
                    entry ->    !entry.toFile().isHidden()
                            &&  !entry.toFile().isDirectory()
                            &&  !entry.toString().endsWith("json");

            for (Path anImageGroup : Files.newDirectoryStream(imageGroupParent, dirFilter)) {
                boolean firstFolderFailure = false;
                if (failFile(imageGroupParent, anImageGroup)) {
                    continue;
                }
                sysLogger.debug("ImageGroup {}", anImageGroup.toString());

                TreeMap<Integer, String> filenames = new TreeMap<>();

                for (Path imageGroupFile : Files.newDirectoryStream(anImageGroup, filesInImageGroupFilter)) {

                    String thisFileName = FilenameUtils.getBaseName(imageGroupFile.getFileName().toString());

                    // BUG: Dont parse by sequence length. Requirements call for parsing backward from last .
                    // to first non int, up to field length.
                    String fileSequence = trailingDigits(thisFileName,sequenceLength);

                    int thisFileIndex = 0;
                    try {
                        thisFileIndex = Integer.parseInt(fileSequence);
                    } catch (NumberFormatException nfe) {
                        String errorText = String.format("File %s does not end in an integer: ends with %s",
                                thisFileName, fileSequence);
                        sysLogger.error(errorText);
                        if (!firstFolderFailure) {
                            firstFolderFailure = true;
                            FailTest(LibOutcome.DIR_FAILS_SEQUENCE, anImageGroup.toString());
                        }
                        FailTest(LibOutcome.FILE_SEQUENCE, errorText);
                    }

                    // fail if duplicate number
                    if (filenames.containsKey(thisFileIndex)) {
                        if (!firstFolderFailure) {
                            firstFolderFailure = true;
                            FailTest(LibOutcome.DIR_FAILS_SEQUENCE, anImageGroup.toString());
                        }
                        FailTest(LibOutcome.DUP_SEQUENCE, filenames.get(thisFileIndex), thisFileName);
                    }
                    filenames.put(thisFileIndex, thisFileName);

                }
                // If filenames contains entries for every number of files, the test passes.
                // The last element must be the same as the size, or there are files missing
                Integer lastKey, size;
                size = filenames.size();

                // No files at all is not a fail
                if (size > 0) {
                    lastKey = filenames.lastKey();
                    if (lastKey > size) {
                        FailTest(LibOutcome.FILE_COUNT, anImageGroup.toString(), lastKey.toString(), size.toString());
                        GenerateFileMissingMessages(filenames);
                    }
                }

            }

            // Because we have a "non-set" state
            if (!IsTestFailed()) {
                PassTest();
            }
        }
/**
         * Special handling for a parent of a series of image groups
         *
         * @param sequenceLength   How many characters before the file extension make up the number
         * @param imageGroupParent the directory we're testing
         * @throws IOException on system failures
         */
Special handling for a parent of a series of image groups
@param sequenceLength   How many characters before the file extension make up the number
@param imageGroupParent the directory we're testing
@throws IOException on system failures
Special handling for a parent of a series of image groups @param sequenceLength How many characters before the file extension make up the number @param imageGroupParent the directory we ' re testing @throws IOException on system failures
private void sequenceImageGroupParent(final int sequenceLength,  final Path imageGroupParent) throws IOException
        {
            DirectoryStream.Filter<Path> dirFilter =
                    entry -> !entry.toFile().isHidden() && entry.toFile().isDirectory();
            DirectoryStream.Filter<Path> filesInImageGroupFilter =
                    entry ->    !entry.toFile().isHidden()
                            &&  !entry.toFile().isDirectory()
                            &&  !entry.toString().endsWith("json");
            for (Path anImageGroup : Files.newDirectoryStream(imageGroupParent, dirFilter)) {
                boolean firstFolderFailure = false;
                if (failFile(imageGroupParent, anImageGroup)) {
                    continue;
                }
                sysLogger.debug("ImageGroup {}", anImageGroup.toString());
                TreeMap<Integer, String> filenames = new TreeMap<>();
                for (Path imageGroupFile : Files.newDirectoryStream(anImageGroup, filesInImageGroupFilter)) {
                    String thisFileName = FilenameUtils.getBaseName(imageGroupFile.getFileName().toString());
                    String fileSequence = trailingDigits(thisFileName,sequenceLength);
                    int thisFileIndex = 0;
                    try {
                        thisFileIndex = Integer.parseInt(fileSequence);
                    } catch (NumberFormatException nfe) {
                        String errorText = String.format("File %s does not end in an integer: ends with %s",
                                thisFileName, fileSequence);
                        sysLogger.error(errorText);
                        if (!firstFolderFailure) {
                            firstFolderFailure = true;
                            FailTest(LibOutcome.DIR_FAILS_SEQUENCE, anImageGroup.toString());
                        }
                        FailTest(LibOutcome.FILE_SEQUENCE, errorText);
                    }
                    if (filenames.containsKey(thisFileIndex)) {
                        if (!firstFolderFailure) {
                            firstFolderFailure = true;
                            FailTest(LibOutcome.DIR_FAILS_SEQUENCE, anImageGroup.toString());
                        }
                        FailTest(LibOutcome.DUP_SEQUENCE, filenames.get(thisFileIndex), thisFileName);
                    }
                    filenames.put(thisFileIndex, thisFileName);
                }
                Integer lastKey, size;
                size = filenames.size();
                if (size > 0) {
                    lastKey = filenames.lastKey();
                    if (lastKey > size) {
                        FailTest(LibOutcome.FILE_COUNT, anImageGroup.toString(), lastKey.toString(), size.toString());
                        GenerateFileMissingMessages(filenames);
                    }
                }
            }
            if (!IsTestFailed()) {
                PassTest();
            }
        }
private void sequenceImageGroupParent ( final int sequenceLength , final Path imageGroupParent ) throws IOException { DirectoryStream . Filter < Path > dirFilter = entry -> ! entry . toFile ( ) . isHidden ( ) && entry . toFile ( ) . isDirectory ( ) ; DirectoryStream . Filter < Path > filesInImageGroupFilter = entry -> ! entry . toFile ( ) . isHidden ( ) && ! entry . toFile ( ) . isDirectory ( ) && ! entry . toString ( ) . endsWith ( "json" ) ; for ( Path anImageGroup : Files . newDirectoryStream ( imageGroupParent , dirFilter ) ) { boolean firstFolderFailure = false ; if ( failFile ( imageGroupParent , anImageGroup ) ) { continue ; } sysLogger . debug ( "ImageGroup {}" , anImageGroup . toString ( ) ) ; TreeMap < Integer , String > filenames = new TreeMap < > ( ) ; for ( Path imageGroupFile : Files . newDirectoryStream ( anImageGroup , filesInImageGroupFilter ) ) { String thisFileName = FilenameUtils . getBaseName ( imageGroupFile . getFileName ( ) . toString ( ) ) ; String fileSequence = trailingDigits ( thisFileName , sequenceLength ) ; int thisFileIndex = 0 ; try { thisFileIndex = Integer . parseInt ( fileSequence ) ; } catch ( NumberFormatException nfe ) { String errorText = String . format ( "File %s does not end in an integer: ends with %s" , thisFileName , fileSequence ) ; sysLogger . error ( errorText ) ; if ( ! firstFolderFailure ) { firstFolderFailure = true ; FailTest ( LibOutcome . DIR_FAILS_SEQUENCE , anImageGroup . toString ( ) ) ; } FailTest ( LibOutcome . FILE_SEQUENCE , errorText ) ; } if ( filenames . containsKey ( thisFileIndex ) ) { if ( ! firstFolderFailure ) { firstFolderFailure = true ; FailTest ( LibOutcome . DIR_FAILS_SEQUENCE , anImageGroup . toString ( ) ) ; } FailTest ( LibOutcome . DUP_SEQUENCE , filenames . get ( thisFileIndex ) , thisFileName ) ; } filenames . put ( thisFileIndex , thisFileName ) ; } Integer lastKey , size ; size = filenames . size ( ) ; if ( size > 0 ) { lastKey = filenames . lastKey ( ) ; if ( lastKey > size ) { FailTest ( LibOutcome . FILE_COUNT , anImageGroup . toString ( ) , lastKey . toString ( ) , size . toString ( ) ) ; GenerateFileMissingMessages ( filenames ) ; } } } if ( ! IsTestFailed ( ) ) { PassTest ( ) ; } }
Special handling for a parent of a series of image groups
 @param sequenceLength   How many characters before the file extension make up the number
 @param imageGroupParent the directory we're testing
 @throws IOException on system failures
Special handling for a parent of a series of image groups @param sequenceLength How many characters before the file extension make up the number @param imageGroupParent the directory we ' re testing @throws IOException on system failures
// asset-manager #29 don't count json files in image groups // asset-manager #23 don't count directories in image groups // asset-manager #29 don't count json files in image groups // BUG: Dont parse by sequence length. Requirements call for parsing backward from last . // to first non int, up to field length. // fail if duplicate number // If filenames contains entries for every number of files, the test passes. // The last element must be the same as the size, or there are files missing // No files at all is not a fail // Because we have a "non-set" state