2023-08-26 17:30:49 +01:00
|
|
|
package stirling.software.SPDF.config;
|
2023-09-05 20:58:18 +01:00
|
|
|
|
2023-08-26 17:30:49 +01:00
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
2024-05-03 20:43:48 +01:00
|
|
|
import java.net.URISyntaxException;
|
2024-06-15 10:05:31 +02:00
|
|
|
import java.net.URL;
|
2023-08-26 17:30:49 +01:00
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.nio.file.Paths;
|
2024-06-15 10:05:31 +02:00
|
|
|
import java.nio.file.StandardCopyOption;
|
2025-03-25 17:57:17 +00:00
|
|
|
import java.util.List;
|
2023-08-26 17:30:49 +01:00
|
|
|
|
2024-12-17 10:26:18 +01:00
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
2025-01-31 11:00:03 +00:00
|
|
|
/**
|
|
|
|
* A naive, line-based approach to merging "settings.yml" with "settings.yml.template" while
|
|
|
|
* preserving exact whitespace, blank lines, and inline comments -- but we only rewrite the file if
|
|
|
|
* the merged content actually differs.
|
|
|
|
*/
|
2024-12-17 10:26:18 +01:00
|
|
|
@Slf4j
|
2025-01-06 12:41:30 +00:00
|
|
|
public class ConfigInitializer {
|
2023-12-30 19:11:27 +00:00
|
|
|
|
2024-05-03 20:43:48 +01:00
|
|
|
public void ensureConfigExists() throws IOException, URISyntaxException {
|
2025-01-31 11:00:03 +00:00
|
|
|
// 1) If settings file doesn't exist, create from template
|
2025-01-06 12:41:30 +00:00
|
|
|
Path destPath = Paths.get(InstallationPathConfig.getSettingsPath());
|
2023-09-24 21:09:34 +01:00
|
|
|
if (Files.notExists(destPath)) {
|
|
|
|
Files.createDirectories(destPath.getParent());
|
|
|
|
try (InputStream in =
|
|
|
|
getClass().getClassLoader().getResourceAsStream("settings.yml.template")) {
|
2025-01-31 11:00:03 +00:00
|
|
|
if (in == null) {
|
2023-09-24 21:09:34 +01:00
|
|
|
throw new FileNotFoundException(
|
|
|
|
"Resource file not found: settings.yml.template");
|
|
|
|
}
|
2025-01-31 11:00:03 +00:00
|
|
|
Files.copy(in, destPath);
|
2023-09-24 21:09:34 +01:00
|
|
|
}
|
2025-01-06 12:41:30 +00:00
|
|
|
log.info("Created settings file from template");
|
2023-09-24 21:09:34 +01:00
|
|
|
} else {
|
2025-01-31 11:00:03 +00:00
|
|
|
// 2) Merge existing file with the template
|
|
|
|
URL templateResource = getClass().getClassLoader().getResource("settings.yml.template");
|
|
|
|
if (templateResource == null) {
|
2024-06-15 10:05:31 +02:00
|
|
|
throw new IOException("Resource not found: settings.yml.template");
|
|
|
|
}
|
|
|
|
|
2025-01-31 11:00:03 +00:00
|
|
|
// Copy template to a temp location so we can read lines
|
2024-06-15 10:05:31 +02:00
|
|
|
Path tempTemplatePath = Files.createTempFile("settings.yml", ".template");
|
2025-01-31 11:00:03 +00:00
|
|
|
try (InputStream in = templateResource.openStream()) {
|
2024-06-15 10:05:31 +02:00
|
|
|
Files.copy(in, tempTemplatePath, StandardCopyOption.REPLACE_EXISTING);
|
|
|
|
}
|
|
|
|
|
Improved Configuration and YAML Management (#2966)
# Description of Changes
**What was changed:**
- **Configuration Updates:**
Replaced all calls to `GeneralUtils.saveKeyToConfig` with the new
`GeneralUtils.saveKeyToSettings` method across multiple classes (e.g.,
`LicenseKeyChecker`, `InitialSetup`, `SettingsController`, etc.). This
update ensures consistent management of configuration settings.
- **File Path and Exception Handling:**
Updated file path handling in `SPDFApplication` by creating `Path`
objects from string paths and logging these paths for clarity. Also
refined exception handling by catching more specific exceptions (e.g.,
using `IOException` instead of a generic `Exception`).
- **Analytics Flag and Rate Limiting:**
Changed the analytics flag in the application properties from a `String`
to a `Boolean`, and updated related logic in `AppConfig` and
`PostHogService`. The rate-limiting property retrieval in `AppConfig`
was also refined for clarity.
- **YAML Configuration Management:**
Replaced the previous manual, line-based YAML merging logic in
`ConfigInitializer` with a new `YamlHelper` class. This helper leverages
the SnakeYAML engine to load, update, and save YAML configurations more
robustly while preserving comments and formatting.
**Why the change was made:**
- **Improved Maintainability:**
Consolidating configuration update logic into a single utility method
(`saveKeyToSettings`) reduces code duplication and simplifies future
maintenance.
- **Enhanced Robustness:**
The new `YamlHelper` class ensures that configuration files are merged
accurately and safely, minimizing risks of data loss or format
corruption.
- **Better Type Safety and Exception Handling:**
Switching the analytics flag to a Boolean and refining exception
handling improves code robustness and debugging efficiency.
- **Clarity and Consistency:**
Standardizing file path handling and logging practices enhances code
readability across the project.
**Challenges encountered:**
- **YAML Merging Complexity:**
Integrating the new `YamlHelper` required careful handling to preserve
existing settings, comments, and formatting during merges.
- **Type Conversion and Backward Compatibility:**
Updating the analytics flag from a string to a Boolean required
extensive testing to ensure backward compatibility and proper
functionality.
- **Exception Granularity:**
Refactoring exception handling from a generic to a more specific
approach involved a detailed review to cover all edge cases.
Closes #<issue_number>
---
## Checklist
- [x] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [ ] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md)
(if applicable)
- [ ] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md)
(if applicable)
- [x] I have performed a self-review of my own code
- [x] My changes generate no new warnings
### Documentation
- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)
### UI Changes (if applicable)
- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)
### Testing (if applicable)
- [x] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing)
for more details.
---------
Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2025-02-25 22:52:59 +01:00
|
|
|
// Copy setting.yaml to a temp location so we can read lines
|
|
|
|
Path settingTempPath = Files.createTempFile("settings", ".yaml");
|
|
|
|
try (InputStream in = Files.newInputStream(destPath)) {
|
|
|
|
Files.copy(in, settingTempPath, StandardCopyOption.REPLACE_EXISTING);
|
|
|
|
}
|
2025-01-31 11:00:03 +00:00
|
|
|
|
Improved Configuration and YAML Management (#2966)
# Description of Changes
**What was changed:**
- **Configuration Updates:**
Replaced all calls to `GeneralUtils.saveKeyToConfig` with the new
`GeneralUtils.saveKeyToSettings` method across multiple classes (e.g.,
`LicenseKeyChecker`, `InitialSetup`, `SettingsController`, etc.). This
update ensures consistent management of configuration settings.
- **File Path and Exception Handling:**
Updated file path handling in `SPDFApplication` by creating `Path`
objects from string paths and logging these paths for clarity. Also
refined exception handling by catching more specific exceptions (e.g.,
using `IOException` instead of a generic `Exception`).
- **Analytics Flag and Rate Limiting:**
Changed the analytics flag in the application properties from a `String`
to a `Boolean`, and updated related logic in `AppConfig` and
`PostHogService`. The rate-limiting property retrieval in `AppConfig`
was also refined for clarity.
- **YAML Configuration Management:**
Replaced the previous manual, line-based YAML merging logic in
`ConfigInitializer` with a new `YamlHelper` class. This helper leverages
the SnakeYAML engine to load, update, and save YAML configurations more
robustly while preserving comments and formatting.
**Why the change was made:**
- **Improved Maintainability:**
Consolidating configuration update logic into a single utility method
(`saveKeyToSettings`) reduces code duplication and simplifies future
maintenance.
- **Enhanced Robustness:**
The new `YamlHelper` class ensures that configuration files are merged
accurately and safely, minimizing risks of data loss or format
corruption.
- **Better Type Safety and Exception Handling:**
Switching the analytics flag to a Boolean and refining exception
handling improves code robustness and debugging efficiency.
- **Clarity and Consistency:**
Standardizing file path handling and logging practices enhances code
readability across the project.
**Challenges encountered:**
- **YAML Merging Complexity:**
Integrating the new `YamlHelper` required careful handling to preserve
existing settings, comments, and formatting during merges.
- **Type Conversion and Backward Compatibility:**
Updating the analytics flag from a string to a Boolean required
extensive testing to ensure backward compatibility and proper
functionality.
- **Exception Granularity:**
Refactoring exception handling from a generic to a more specific
approach involved a detailed review to cover all edge cases.
Closes #<issue_number>
---
## Checklist
- [x] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [ ] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md)
(if applicable)
- [ ] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md)
(if applicable)
- [x] I have performed a self-review of my own code
- [x] My changes generate no new warnings
### Documentation
- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)
### UI Changes (if applicable)
- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)
### Testing (if applicable)
- [x] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing)
for more details.
---------
Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2025-02-25 22:52:59 +01:00
|
|
|
YamlHelper settingsTemplateFile = new YamlHelper(tempTemplatePath);
|
|
|
|
YamlHelper settingsFile = new YamlHelper(settingTempPath);
|
2025-01-31 11:00:03 +00:00
|
|
|
|
2025-03-25 17:57:17 +00:00
|
|
|
migrateEnterpriseEditionToPremium(settingsFile, settingsTemplateFile);
|
|
|
|
|
Improved Configuration and YAML Management (#2966)
# Description of Changes
**What was changed:**
- **Configuration Updates:**
Replaced all calls to `GeneralUtils.saveKeyToConfig` with the new
`GeneralUtils.saveKeyToSettings` method across multiple classes (e.g.,
`LicenseKeyChecker`, `InitialSetup`, `SettingsController`, etc.). This
update ensures consistent management of configuration settings.
- **File Path and Exception Handling:**
Updated file path handling in `SPDFApplication` by creating `Path`
objects from string paths and logging these paths for clarity. Also
refined exception handling by catching more specific exceptions (e.g.,
using `IOException` instead of a generic `Exception`).
- **Analytics Flag and Rate Limiting:**
Changed the analytics flag in the application properties from a `String`
to a `Boolean`, and updated related logic in `AppConfig` and
`PostHogService`. The rate-limiting property retrieval in `AppConfig`
was also refined for clarity.
- **YAML Configuration Management:**
Replaced the previous manual, line-based YAML merging logic in
`ConfigInitializer` with a new `YamlHelper` class. This helper leverages
the SnakeYAML engine to load, update, and save YAML configurations more
robustly while preserving comments and formatting.
**Why the change was made:**
- **Improved Maintainability:**
Consolidating configuration update logic into a single utility method
(`saveKeyToSettings`) reduces code duplication and simplifies future
maintenance.
- **Enhanced Robustness:**
The new `YamlHelper` class ensures that configuration files are merged
accurately and safely, minimizing risks of data loss or format
corruption.
- **Better Type Safety and Exception Handling:**
Switching the analytics flag to a Boolean and refining exception
handling improves code robustness and debugging efficiency.
- **Clarity and Consistency:**
Standardizing file path handling and logging practices enhances code
readability across the project.
**Challenges encountered:**
- **YAML Merging Complexity:**
Integrating the new `YamlHelper` required careful handling to preserve
existing settings, comments, and formatting during merges.
- **Type Conversion and Backward Compatibility:**
Updating the analytics flag from a string to a Boolean required
extensive testing to ensure backward compatibility and proper
functionality.
- **Exception Granularity:**
Refactoring exception handling from a generic to a more specific
approach involved a detailed review to cover all edge cases.
Closes #<issue_number>
---
## Checklist
- [x] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [ ] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md)
(if applicable)
- [ ] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md)
(if applicable)
- [x] I have performed a self-review of my own code
- [x] My changes generate no new warnings
### Documentation
- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)
### UI Changes (if applicable)
- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)
### Testing (if applicable)
- [x] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing)
for more details.
---------
Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2025-02-25 22:52:59 +01:00
|
|
|
boolean changesMade =
|
|
|
|
settingsTemplateFile.updateValuesFromYaml(settingsFile, settingsTemplateFile);
|
|
|
|
if (changesMade) {
|
|
|
|
settingsTemplateFile.save(destPath);
|
2025-01-31 11:00:03 +00:00
|
|
|
log.info("Settings file updated based on template changes.");
|
|
|
|
} else {
|
|
|
|
log.info("No changes detected; settings file left as-is.");
|
2024-05-03 20:43:48 +01:00
|
|
|
}
|
2024-06-15 10:05:31 +02:00
|
|
|
|
2025-01-31 11:00:03 +00:00
|
|
|
Files.deleteIfExists(tempTemplatePath);
|
Improved Configuration and YAML Management (#2966)
# Description of Changes
**What was changed:**
- **Configuration Updates:**
Replaced all calls to `GeneralUtils.saveKeyToConfig` with the new
`GeneralUtils.saveKeyToSettings` method across multiple classes (e.g.,
`LicenseKeyChecker`, `InitialSetup`, `SettingsController`, etc.). This
update ensures consistent management of configuration settings.
- **File Path and Exception Handling:**
Updated file path handling in `SPDFApplication` by creating `Path`
objects from string paths and logging these paths for clarity. Also
refined exception handling by catching more specific exceptions (e.g.,
using `IOException` instead of a generic `Exception`).
- **Analytics Flag and Rate Limiting:**
Changed the analytics flag in the application properties from a `String`
to a `Boolean`, and updated related logic in `AppConfig` and
`PostHogService`. The rate-limiting property retrieval in `AppConfig`
was also refined for clarity.
- **YAML Configuration Management:**
Replaced the previous manual, line-based YAML merging logic in
`ConfigInitializer` with a new `YamlHelper` class. This helper leverages
the SnakeYAML engine to load, update, and save YAML configurations more
robustly while preserving comments and formatting.
**Why the change was made:**
- **Improved Maintainability:**
Consolidating configuration update logic into a single utility method
(`saveKeyToSettings`) reduces code duplication and simplifies future
maintenance.
- **Enhanced Robustness:**
The new `YamlHelper` class ensures that configuration files are merged
accurately and safely, minimizing risks of data loss or format
corruption.
- **Better Type Safety and Exception Handling:**
Switching the analytics flag to a Boolean and refining exception
handling improves code robustness and debugging efficiency.
- **Clarity and Consistency:**
Standardizing file path handling and logging practices enhances code
readability across the project.
**Challenges encountered:**
- **YAML Merging Complexity:**
Integrating the new `YamlHelper` required careful handling to preserve
existing settings, comments, and formatting during merges.
- **Type Conversion and Backward Compatibility:**
Updating the analytics flag from a string to a Boolean required
extensive testing to ensure backward compatibility and proper
functionality.
- **Exception Granularity:**
Refactoring exception handling from a generic to a more specific
approach involved a detailed review to cover all edge cases.
Closes #<issue_number>
---
## Checklist
- [x] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [ ] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md)
(if applicable)
- [ ] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md)
(if applicable)
- [x] I have performed a self-review of my own code
- [x] My changes generate no new warnings
### Documentation
- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)
### UI Changes (if applicable)
- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)
### Testing (if applicable)
- [x] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing)
for more details.
---------
Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2025-02-25 22:52:59 +01:00
|
|
|
Files.deleteIfExists(settingTempPath);
|
2023-09-24 21:09:34 +01:00
|
|
|
}
|
2024-06-15 10:05:31 +02:00
|
|
|
|
2025-01-31 11:00:03 +00:00
|
|
|
// 3) Ensure custom settings file exists
|
2025-01-06 12:41:30 +00:00
|
|
|
Path customSettingsPath = Paths.get(InstallationPathConfig.getCustomSettingsPath());
|
Improved Configuration and YAML Management (#2966)
# Description of Changes
**What was changed:**
- **Configuration Updates:**
Replaced all calls to `GeneralUtils.saveKeyToConfig` with the new
`GeneralUtils.saveKeyToSettings` method across multiple classes (e.g.,
`LicenseKeyChecker`, `InitialSetup`, `SettingsController`, etc.). This
update ensures consistent management of configuration settings.
- **File Path and Exception Handling:**
Updated file path handling in `SPDFApplication` by creating `Path`
objects from string paths and logging these paths for clarity. Also
refined exception handling by catching more specific exceptions (e.g.,
using `IOException` instead of a generic `Exception`).
- **Analytics Flag and Rate Limiting:**
Changed the analytics flag in the application properties from a `String`
to a `Boolean`, and updated related logic in `AppConfig` and
`PostHogService`. The rate-limiting property retrieval in `AppConfig`
was also refined for clarity.
- **YAML Configuration Management:**
Replaced the previous manual, line-based YAML merging logic in
`ConfigInitializer` with a new `YamlHelper` class. This helper leverages
the SnakeYAML engine to load, update, and save YAML configurations more
robustly while preserving comments and formatting.
**Why the change was made:**
- **Improved Maintainability:**
Consolidating configuration update logic into a single utility method
(`saveKeyToSettings`) reduces code duplication and simplifies future
maintenance.
- **Enhanced Robustness:**
The new `YamlHelper` class ensures that configuration files are merged
accurately and safely, minimizing risks of data loss or format
corruption.
- **Better Type Safety and Exception Handling:**
Switching the analytics flag to a Boolean and refining exception
handling improves code robustness and debugging efficiency.
- **Clarity and Consistency:**
Standardizing file path handling and logging practices enhances code
readability across the project.
**Challenges encountered:**
- **YAML Merging Complexity:**
Integrating the new `YamlHelper` required careful handling to preserve
existing settings, comments, and formatting during merges.
- **Type Conversion and Backward Compatibility:**
Updating the analytics flag from a string to a Boolean required
extensive testing to ensure backward compatibility and proper
functionality.
- **Exception Granularity:**
Refactoring exception handling from a generic to a more specific
approach involved a detailed review to cover all edge cases.
Closes #<issue_number>
---
## Checklist
- [x] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [ ] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md)
(if applicable)
- [ ] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md)
(if applicable)
- [x] I have performed a self-review of my own code
- [x] My changes generate no new warnings
### Documentation
- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)
### UI Changes (if applicable)
- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)
### Testing (if applicable)
- [x] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing)
for more details.
---------
Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2025-02-25 22:52:59 +01:00
|
|
|
if (Files.notExists(customSettingsPath)) {
|
2024-06-15 10:05:31 +02:00
|
|
|
Files.createFile(customSettingsPath);
|
Improved Configuration and YAML Management (#2966)
# Description of Changes
**What was changed:**
- **Configuration Updates:**
Replaced all calls to `GeneralUtils.saveKeyToConfig` with the new
`GeneralUtils.saveKeyToSettings` method across multiple classes (e.g.,
`LicenseKeyChecker`, `InitialSetup`, `SettingsController`, etc.). This
update ensures consistent management of configuration settings.
- **File Path and Exception Handling:**
Updated file path handling in `SPDFApplication` by creating `Path`
objects from string paths and logging these paths for clarity. Also
refined exception handling by catching more specific exceptions (e.g.,
using `IOException` instead of a generic `Exception`).
- **Analytics Flag and Rate Limiting:**
Changed the analytics flag in the application properties from a `String`
to a `Boolean`, and updated related logic in `AppConfig` and
`PostHogService`. The rate-limiting property retrieval in `AppConfig`
was also refined for clarity.
- **YAML Configuration Management:**
Replaced the previous manual, line-based YAML merging logic in
`ConfigInitializer` with a new `YamlHelper` class. This helper leverages
the SnakeYAML engine to load, update, and save YAML configurations more
robustly while preserving comments and formatting.
**Why the change was made:**
- **Improved Maintainability:**
Consolidating configuration update logic into a single utility method
(`saveKeyToSettings`) reduces code duplication and simplifies future
maintenance.
- **Enhanced Robustness:**
The new `YamlHelper` class ensures that configuration files are merged
accurately and safely, minimizing risks of data loss or format
corruption.
- **Better Type Safety and Exception Handling:**
Switching the analytics flag to a Boolean and refining exception
handling improves code robustness and debugging efficiency.
- **Clarity and Consistency:**
Standardizing file path handling and logging practices enhances code
readability across the project.
**Challenges encountered:**
- **YAML Merging Complexity:**
Integrating the new `YamlHelper` required careful handling to preserve
existing settings, comments, and formatting during merges.
- **Type Conversion and Backward Compatibility:**
Updating the analytics flag from a string to a Boolean required
extensive testing to ensure backward compatibility and proper
functionality.
- **Exception Granularity:**
Refactoring exception handling from a generic to a more specific
approach involved a detailed review to cover all edge cases.
Closes #<issue_number>
---
## Checklist
- [x] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [ ] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md)
(if applicable)
- [ ] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md)
(if applicable)
- [x] I have performed a self-review of my own code
- [x] My changes generate no new warnings
### Documentation
- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)
### UI Changes (if applicable)
- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)
### Testing (if applicable)
- [x] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing)
for more details.
---------
Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2025-02-25 22:52:59 +01:00
|
|
|
log.info("Created custom_settings file: {}", customSettingsPath.toString());
|
2024-05-03 22:23:21 +01:00
|
|
|
}
|
2024-05-25 18:19:03 +02:00
|
|
|
}
|
2025-03-25 17:57:17 +00:00
|
|
|
|
|
|
|
// TODO: Remove post migration
|
|
|
|
private void migrateEnterpriseEditionToPremium(YamlHelper yaml, YamlHelper template) {
|
|
|
|
if (yaml.getValueByExactKeyPath("enterpriseEdition", "enabled") != null) {
|
|
|
|
template.updateValue(
|
|
|
|
List.of("premium", "enabled"),
|
|
|
|
yaml.getValueByExactKeyPath("enterpriseEdition", "enabled"));
|
|
|
|
}
|
|
|
|
if (yaml.getValueByExactKeyPath("enterpriseEdition", "key") != null) {
|
|
|
|
template.updateValue(
|
|
|
|
List.of("premium", "key"),
|
|
|
|
yaml.getValueByExactKeyPath("enterpriseEdition", "key"));
|
|
|
|
}
|
|
|
|
if (yaml.getValueByExactKeyPath("enterpriseEdition", "SSOAutoLogin") != null) {
|
|
|
|
template.updateValue(
|
|
|
|
List.of("premium", "proFeatures", "SSOAutoLogin"),
|
|
|
|
yaml.getValueByExactKeyPath("enterpriseEdition", "SSOAutoLogin"));
|
|
|
|
}
|
|
|
|
if (yaml.getValueByExactKeyPath("enterpriseEdition", "CustomMetadata", "autoUpdateMetadata")
|
|
|
|
!= null) {
|
|
|
|
template.updateValue(
|
|
|
|
List.of("premium", "proFeatures", "CustomMetadata", "autoUpdateMetadata"),
|
|
|
|
yaml.getValueByExactKeyPath(
|
|
|
|
"enterpriseEdition", "CustomMetadata", "autoUpdateMetadata"));
|
|
|
|
}
|
|
|
|
if (yaml.getValueByExactKeyPath("enterpriseEdition", "CustomMetadata", "author") != null) {
|
|
|
|
template.updateValue(
|
|
|
|
List.of("premium", "proFeatures", "CustomMetadata", "author"),
|
|
|
|
yaml.getValueByExactKeyPath("enterpriseEdition", "CustomMetadata", "author"));
|
|
|
|
}
|
|
|
|
if (yaml.getValueByExactKeyPath("enterpriseEdition", "CustomMetadata", "creator") != null) {
|
|
|
|
template.updateValue(
|
|
|
|
List.of("premium", "proFeatures", "CustomMetadata", "creator"),
|
|
|
|
yaml.getValueByExactKeyPath("enterpriseEdition", "CustomMetadata", "creator"));
|
|
|
|
}
|
|
|
|
if (yaml.getValueByExactKeyPath("enterpriseEdition", "CustomMetadata", "producer")
|
|
|
|
!= null) {
|
|
|
|
template.updateValue(
|
|
|
|
List.of("premium", "proFeatures", "CustomMetadata", "producer"),
|
|
|
|
yaml.getValueByExactKeyPath("enterpriseEdition", "CustomMetadata", "producer"));
|
|
|
|
}
|
|
|
|
}
|
2023-09-05 20:58:18 +01:00
|
|
|
}
|