From 2022595b11de5551c0bb1fa414f4b3076e15a39e Mon Sep 17 00:00:00 2001 From: Barney Boisvert Date: Sun, 28 Jul 2024 10:03:53 -0700 Subject: [PATCH] plan items whose names start with a bang are excluded from ingredient recognition. --- .../brennaswitzer/cookbook/services/ItemService.java | 7 ++++++- .../brennaswitzer/cookbook/services/PlanService.java | 12 ++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/brennaswitzer/cookbook/services/ItemService.java b/src/main/java/com/brennaswitzer/cookbook/services/ItemService.java index cb9435c2..b3b8df12 100644 --- a/src/main/java/com/brennaswitzer/cookbook/services/ItemService.java +++ b/src/main/java/com/brennaswitzer/cookbook/services/ItemService.java @@ -176,11 +176,16 @@ public List getSuggestions(RecognizedItem item, .collect(Collectors.toList()); } - public void updateAutoRecognition(MutableItem it) { + public void clearAutoRecognition(MutableItem it) { if (it == null) return; it.setIngredient(null); it.setQuantity(null); it.setPreparation(null); + } + + public void updateAutoRecognition(MutableItem it) { + if (it == null) return; + clearAutoRecognition(it); autoRecognize(it); } diff --git a/src/main/java/com/brennaswitzer/cookbook/services/PlanService.java b/src/main/java/com/brennaswitzer/cookbook/services/PlanService.java index 333bf4d0..b31fed4f 100644 --- a/src/main/java/com/brennaswitzer/cookbook/services/PlanService.java +++ b/src/main/java/com/brennaswitzer/cookbook/services/PlanService.java @@ -289,7 +289,9 @@ public PlanItem createItem(Long parentId, Long afterId, String name) { PlanItem parent = getPlanItemById(parentId, AccessLevel.CHANGE); PlanItem after = afterId == null ? null : getPlanItemById(afterId, AccessLevel.VIEW); PlanItem item = itemRepo.save(new PlanItem(name).of(parent, after)); - itemService.autoRecognize(item); + if (!isRecognitionDisallowed(item)) { + itemService.autoRecognize(item); + } if (item.getId() == null) itemRepo.flush(); return item; } @@ -369,12 +371,18 @@ public PlanMessage deleteBucketForMessage(Long planId, Long id) { public PlanItem renameItem(Long id, String name) { PlanItem item = getPlanItemById(id, AccessLevel.CHANGE); item.setName(name); - if (!item.hasIngredient() || !(Hibernate.unproxy(item.getIngredient()) instanceof Recipe)) { + if (isRecognitionDisallowed(item)) { + itemService.clearAutoRecognition(item); + } else if (!item.hasIngredient() || !(Hibernate.unproxy(item.getIngredient()) instanceof Recipe)) { itemService.updateAutoRecognition(item); } return item; } + private boolean isRecognitionDisallowed(PlanItem item) { + return item.getName().startsWith("!"); + } + public PlanMessage renameItemForMessage(Long id, String name) { return buildUpdateMessage(renameItem(id, name)); }