Apply review suggestions from balazs-szucs

This commit is contained in:
Anthony Stirling
2026-08-24 16:13:08 +01:00
parent a7509aba7c
commit dae17dfc60
6 changed files with 14 additions and 20 deletions
@@ -876,9 +876,12 @@ public class GeneralUtils {
*/
private final Object SETTINGS_WRITE_LOCK = new Object();
/** Dotted-notation separator for settings keys; a literal, so compile it once. */
private final Pattern SETTINGS_KEY_SEPARATOR = Pattern.compile("\\.");
public void saveKeyToSettings(String key, Object newValue) throws IOException {
synchronized (SETTINGS_WRITE_LOCK) {
String[] keyArray = key.split("\\.");
String[] keyArray = SETTINGS_KEY_SEPARATOR.split(key);
Path settingsPath = Path.of(InstallationPathConfig.getSettingsPath());
YamlHelper settingsYaml = new YamlHelper(settingsPath);
settingsYaml.updateValue(Arrays.asList(keyArray), newValue);
@@ -909,7 +912,7 @@ public class GeneralUtils {
for (Map.Entry<String, Object> entry : settingsMap.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
String[] keyArray = key.split("\\.");
String[] keyArray = SETTINGS_KEY_SEPARATOR.split(key);
settingsYaml.updateValue(Arrays.asList(keyArray), value);
}
@@ -35,8 +35,7 @@ public class ModelCatalogService {
@PostConstruct
void load() {
try (InputStream is = new ClassPathResource(CATALOG_RESOURCE).getInputStream()) {
List<ModelCatalogEntry> loaded =
objectMapper.readValue(is, new TypeReference<List<ModelCatalogEntry>>() {});
List<ModelCatalogEntry> loaded = objectMapper.readValue(is, new TypeReference<>() {});
Map<String, ModelCatalogEntry> map = new LinkedHashMap<>();
for (ModelCatalogEntry entry : loaded) {
if (entry.getId() != null && !entry.getId().isBlank()) {
@@ -41,10 +41,6 @@ import stirling.software.proprietary.formdetection.service.FormDetectionModelMan
* Server-side detection endpoint. Gated behind the {@code form-detection} endpoint key, which is
* disabled until a model is installed (so the tool tile is greyed in the UI). Returns the shared
* detection schema, or - when {@code applyToPdf=true} - the AcroForm-applied PDF.
*
* <p>Deliberately under {@code /api/v1/form}, not {@code /api/v1/ai}: anything on the AI prefix is
* classified billable by {@code BillableOperationClassifier} and blocked with 402 when the instance
* is unlinked - which would gate on-device detection that never touches the server.
*/
@Slf4j
@RestController
@@ -26,10 +26,6 @@ import stirling.software.proprietary.formdetection.service.FormDetectionModelMan
* Admin-managed lifecycle for the Auto Form Detection model. Lives under the never-gated {@code
* form-detection-model} endpoint key so install/status stay reachable while the feature itself (the
* {@code form-detection} detect endpoint) is disabled until a model is ready.
*
* <p>Deliberately under {@code /api/v1/form}, not {@code /api/v1/ai}: anything on the AI prefix is
* classified billable by {@code BillableOperationClassifier} and blocked with 402 when the instance
* is unlinked - which would gate on-device detection that never touches the server.
*/
@Slf4j
@RestController
@@ -168,8 +168,8 @@ public class OnnxFormDetector implements FormDetectionEngine {
if (session != null) {
try {
session.close();
} catch (Exception ignored) {
// ignore
} catch (Exception _) {
// already closing
}
session = null;
}
@@ -1,5 +1,7 @@
package stirling.software.proprietary.formdetection.render;
import lombok.experimental.UtilityClass;
import stirling.software.proprietary.formdetection.inference.Yolo;
import stirling.software.proprietary.formdetection.model.DetectedField;
@@ -9,12 +11,10 @@ import stirling.software.proprietary.formdetection.model.DetectedField;
* live in. The bitmap is display space: /Rotate baked in and the crop box anchored at (0,0), so the
* mapping is scale + Y-flip, then the inverse page rotation, then the crop-box translation.
*/
public final class CoordinateMapper {
@UtilityClass
public class CoordinateMapper {
private CoordinateMapper() {}
public static DetectedField.RectPt toPdfPoints(
Yolo.Detection d, PageRasterizer.RasterPage page) {
public DetectedField.RectPt toPdfPoints(Yolo.Detection d, PageRasterizer.RasterPage page) {
float sx = page.scaleX() > 0 ? page.scaleX() : 1f;
float sy = page.scaleY() > 0 ? page.scaleY() : 1f;
@@ -66,7 +66,7 @@ public final class CoordinateMapper {
return new DetectedField.RectPt(x + page.cropLlxPt(), y + page.cropLlyPt(), w, h);
}
private static double clamp(double v, double lo, double hi) {
private double clamp(double v, double lo, double hi) {
return v < lo ? lo : Math.min(v, hi);
}
}