Added case management for target review file already existing.

This commit is contained in:
Christian P. MOMON 2018-05-17 09:28:02 +02:00
parent 7a443487f3
commit d5e500ce2d

View File

@ -357,7 +357,13 @@ public class Hebdobot extends PircBot
} }
logger.info("Write review file."); logger.info("Write review file.");
File file = new File(this.reviewDirectory, date + StringUtils.defaultString(this.reviewFileSuffix, DEFAULT_SUFFIX)); File reviewFile = new File(this.reviewDirectory, date + StringUtils.defaultString(this.reviewFileSuffix, DEFAULT_SUFFIX));
if (reviewFile.exists())
{
LocalTime now = LocalTime.now();
String newSuffix = String.format("-%02d'h'%02d.txt", now.getHour(), now.getMinute());
reviewFile = new File(reviewFile.getAbsolutePath().replace(".txt", newSuffix));
}
try try
{ {
if (!this.reviewDirectory.exists()) if (!this.reviewDirectory.exists())
@ -365,8 +371,8 @@ public class Hebdobot extends PircBot
logger.info("Create review directory: " + this.reviewDirectory.getAbsolutePath()); logger.info("Create review directory: " + this.reviewDirectory.getAbsolutePath());
this.reviewDirectory.mkdirs(); this.reviewDirectory.mkdirs();
} }
FileUtils.writeStringToFile(file, textReview, StandardCharsets.UTF_8); FileUtils.writeStringToFile(reviewFile, textReview, StandardCharsets.UTF_8);
logger.info("File review saved in: [{}]", file.getAbsolutePath()); logger.info("File review saved in: [{}]", reviewFile.getAbsolutePath());
} }
catch (final Exception exception) catch (final Exception exception)
{ {
@ -378,7 +384,7 @@ public class Hebdobot extends PircBot
String reminderMessage = String.format( String reminderMessage = String.format(
"%% %s, ne pas oublier d'ajouter le compte-rendu de la revue sur https://agir.april.org/issues/135 en utilisant comme nom de fichier %s", "%% %s, ne pas oublier d'ajouter le compte-rendu de la revue sur https://agir.april.org/issues/135 en utilisant comme nom de fichier %s",
this.review.getOwner(), file.getName()); this.review.getOwner(), reviewFile.getName());
logger.info("reminderMessage=[{}]", reminderMessage); logger.info("reminderMessage=[{}]", reminderMessage);
sendMessage(reminderMessage); sendMessage(reminderMessage);