Esempio n. 1
0
  /**
   * Valide tout les site web de caroline et liste les erreurs s'il y en a.
   *
   * @return La liste des erreur qui rendent le site instable. Retourne une liste vide si le site
   *     est correct.
   * @throws IOException
   * @throws FtpManagerException
   */
  public List<ValidationError> validate() throws IOException, FtpManagerException {
    List<ValidationError> errors = new ArrayList<ValidationError>();

    // Construit le dossier qui servira à récupérer les fichiers pour la validation.
    LOGGER.info(workingFolder.getAbsolutePath());
    FileUtils.deleteDirectory(workingFolder);
    workingFolder.mkdir();

    // Lecture du fichier gallery.hyml
    File galleryHtmlFile = ftpManager.getCopyGalleryHtmlFile();
    String blocs = extractAlbumsBloc(galleryHtmlFile);

    // Validation du fichier gallery.html et récupération des noms de fichiers.
    Pattern albumBlocPattern = Pattern.compile("grid_4(.*?)</div></div></div>");
    Matcher albumMBlocMatcher = albumBlocPattern.matcher(blocs.replace(" ", ""));
    Set<String> phpFileNames = new TreeSet<>();
    Set<String> jpgFileNames = new TreeSet<>();
    while (albumMBlocMatcher.find()) {
      validateBlocAndExtract(albumMBlocMatcher.group(), phpFileNames, jpgFileNames, errors);
    }

    checkGalleryPictures(errors, jpgFileNames);
    checkPhpFiles(errors, phpFileNames);

    // Valide les album photos.
    Set<String> albumToTest = checkAlbumExistance(errors, phpFileNames, jpgFileNames);
    for (String album : albumToTest) {
      checkAlbumContent(errors, album);
    }

    return errors;
  }
Esempio n. 2
0
 private void checkPhpFiles(List<ValidationError> errors, Set<String> phpFileNames)
     throws FtpManagerException {
   Set<String> filesNotFound = ftpManager.checkFilesExists(phpFileNames);
   for (String phpFile : filesNotFound) {
     errors.add(
         new ValidationError(
             SeverityErrorEnum.ERREUR, "Le fichier php " + phpFile + " n'existe pas."));
   }
 }
Esempio n. 3
0
 private void checkGalleryPictures(List<ValidationError> errors, Set<String> jpgFileNames)
     throws FtpManagerException {
   Set<String> filesNotFound = ftpManager.checkFilesExists(jpgFileNames);
   for (String picture : filesNotFound) {
     errors.add(
         new ValidationError(
             SeverityErrorEnum.ERREUR, "La photo de couverture " + picture + " n'existe pas."));
   }
 }
Esempio n. 4
0
  private void checkAlbumContent(List<ValidationError> errors, String album)
      throws FtpManagerException {
    List<FTPFile> pictures = ftpManager.listFilesFromAlbum(album);

    Set<String> smallNames = new TreeSet<>();
    Set<String> normalNames = new TreeSet<>();
    for (FTPFile ftpFile : pictures) {
      String ftpFileName = FilenameUtils.getBaseName(ftpFile.getName());
      if (ftpFileName.contains(AlbumNamesHelper.PREFIX_SMALL_IMAGE)) {
        smallNames.add(
            StringUtils.remove(ftpFileName, AlbumNamesHelper.PREFIX_SMALL_IMAGE).toLowerCase());
      } else {
        normalNames.add(ftpFileName.toLowerCase());
      }
    }

    // Teste si tuous les normal names sont présents.
    if (smallNames.isEmpty() && normalNames.isEmpty()) {
      errors.add(
          new ValidationError(SeverityErrorEnum.WARNNING, "L'album " + album + " est vide."));
    } else {
      Set<String> differenceNormalNames = Sets.difference(smallNames, normalNames);
      for (String pictureName : differenceNormalNames) {
        errors.add(
            new ValidationError(
                SeverityErrorEnum.ERREUR,
                "La photo " + pictureName + " de l'album " + album + " n'a pas sa mignature."));
      }
      Set<String> differenceSmallNames = Sets.difference(normalNames, smallNames);
      for (String pictureName : differenceSmallNames) {
        errors.add(
            new ValidationError(
                SeverityErrorEnum.ERREUR,
                "La photo small"
                    + pictureName
                    + " de l'album "
                    + album
                    + " n'a pas sa photo taille réelle."));
      }
    }
  }
Esempio n. 5
0
  private Set<String> checkAlbumExistance(
      List<ValidationError> errors, Set<String> phpFileNames, Set<String> jpgFileNames)
      throws FtpManagerException {
    Set<String> albumNames = new TreeSet<>();
    for (String jpgFile : jpgFileNames) {
      albumNames.add(FilenameUtils.getBaseName(jpgFile));
    }
    for (String phpFile : phpFileNames) {
      albumNames.add(FilenameUtils.getBaseName(phpFile));
    }
    Set<String> directoriesNotFounds = ftpManager.checkDirectoriesExists(albumNames);
    for (String directory : directoriesNotFounds) {
      errors.add(
          new ValidationError(
              SeverityErrorEnum.ERREUR, "Le dossier " + directory + " n'existe pas."));
    }

    // Valide le contenu photo des albums.
    Set<String> albumToTest = Sets.difference(albumNames, directoriesNotFounds);
    return albumToTest;
  }