Skip to content

Commit

Permalink
Better handling of setting local properties
Browse files Browse the repository at this point in the history
  • Loading branch information
herrtunante committed Dec 13, 2024
1 parent d1b23b7 commit 1eea442
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 21 deletions.
3 changes: 3 additions & 0 deletions collect-earth/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Updated versions of libraries for Chrome/Firefox
- Connection to Planet daily imagery service has been fixed

### Added
- Export Sampling Error Excel file inside the GHGi LULUCF package


## [1.20.7] - 2023-07-06

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ public static String getMd5FromFolder(File folder) throws IOException {
}

public static String getMd5FromFile(String filePath) throws IOException {
return DigestUtils.md5Hex(new FileInputStream(new File(filePath)));
try (FileInputStream fis = new FileInputStream(new File(filePath))) {
return DigestUtils.md5Hex(fis);
} catch (Exception e) {
logger.error("Error getting MD5 from file", e);
return null;
}
}

public static void setFontDependingOnLanguaue(UI_LANGUAGE uiLanguage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,28 +466,44 @@ public void generateLoaderKmlFile() throws IOException, TemplateException {

private boolean isKmlUpToDate() throws IOException {

final String csvFile = getLocalProperties().getCsvFile();
final String balloon = getLocalProperties().getBalloonFile();
final String template = getLocalProperties().getTemplateFile();

boolean upToDate = true;
if (!getLocalProperties().getBalloonFileChecksum().trim().equals(CollectEarthUtils.getMd5FromFile(balloon))
|| !getLocalProperties().getTemplateFileChecksum().trim()
.equals(CollectEarthUtils.getMd5FromFile(template))
|| !getLocalProperties().getCsvFileChecksum().trim()
.equals(CollectEarthUtils.getMd5FromFile(csvFile))) {
upToDate = false;
}

final File kmzFile = new File(KmlGeneratorService.KMZ_FILE_PATH);
if (!kmzFile.exists()) {
upToDate = false;
}

return upToDate;

// Retrieve file paths and checksums, handling potential null values
final String csvFile = getLocalProperties().getCsvFile();
final String balloon = getLocalProperties().getBalloonFile();
final String template = getLocalProperties().getTemplateFile();
final String balloonChecksum = getLocalProperties().getBalloonFileChecksum();
final String templateChecksum = getLocalProperties().getTemplateFileChecksum();
final String csvChecksum = getLocalProperties().getCsvFileChecksum();

// Check if any essential property is null
if (csvFile == null || balloon == null || template == null ||
balloonChecksum == null || templateChecksum == null || csvChecksum == null) {
return false; // Return false if any required property is null
}

boolean upToDate = true;

// Get MD5 checksums, ensuring null values are handled
final String balloonMd5 = CollectEarthUtils.getMd5FromFile(balloon);
final String templateMd5 = CollectEarthUtils.getMd5FromFile(template);
final String csvMd5 = CollectEarthUtils.getMd5FromFile(csvFile);

// Check if the computed MD5 values are null or do not match the expected checksums
if (balloonMd5 == null || !balloonChecksum.trim().equals(balloonMd5) ||
templateMd5 == null || !templateChecksum.trim().equals(templateMd5) ||
csvMd5 == null || !csvChecksum.trim().equals(csvMd5)) {
upToDate = false;
}

// Check if the KMZ file exists
final File kmzFile = new File(KmlGeneratorService.KMZ_FILE_PATH);
if (!kmzFile.exists()) {
upToDate = false;
}

return upToDate;
}


public void generatePlacemarksKmzFile() throws IOException, KmlGenerationException, CsvValidationException {
generatePlacemarksKmzFile(false);
}
Expand Down

0 comments on commit 1eea442

Please sign in to comment.