From 666e9223eafb62515a5c4d80ab66e5b7a1511866 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Thu, 16 May 2019 00:34:47 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A2=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D1=8C=20=D0=B4=D0=B5=D1=84=D0=BE=D0=BB=D1=82=D0=BD?= =?UTF-8?q?=D1=8B=D0=B9=20=D0=BE=D1=82=D0=B2=D0=B5=D1=82,=20=D0=B5=D1=81?= =?UTF-8?q?=D0=BB=D0=B8=20=D0=BD=D0=B8=20=D0=BE=D0=B4=D0=B8=D0=BD=20=D0=B8?= =?UTF-8?q?=D0=B7=20=D1=8E=D0=BD=D0=B8=D1=82=D0=BE=D0=B2=20=D0=BD=D0=B5=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=B4=D0=BE=D1=88=D0=B5=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sadtech/autoresponder/Autoresponder.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/sadtech/autoresponder/Autoresponder.java b/src/main/java/org/sadtech/autoresponder/Autoresponder.java index 69e2edb..6c081cf 100644 --- a/src/main/java/org/sadtech/autoresponder/Autoresponder.java +++ b/src/main/java/org/sadtech/autoresponder/Autoresponder.java @@ -24,6 +24,7 @@ public class Autoresponder { private static final UnitPriorityComparator UNIT_PRIORITY_COMPARATOR = new UnitPriorityComparator(); private final Set startUnits; + private Unit defaultUnit; private final UnitPointerService unitPointerService; public Autoresponder(UnitPointerService unitPointerService, Set startUnits) { @@ -35,18 +36,26 @@ public class Autoresponder { return unitPointerService; } + public void setDefaultUnit(Unit defaultUnit) { + this.defaultUnit = defaultUnit; + } + /* - Возвращает unit на основании сообщения пользователя - */ + Возвращает unit на основании сообщения пользователя + */ public Unit answer(Integer personId, String message) { UnitPointer unitPointer = checkAndAddPerson(personId); Unit unit; - if (unitPointer.getUnit() == null || unitPointer.getUnit().getNextUnits() == null) { - unit = nextUnit(startUnits, message); // выбирает unit из startUnits, если пользователь обращается впервые - } else { - unit = nextUnit(unitPointer.getUnit().getNextUnits(), message); + try { + if (unitPointer.getUnit() == null || unitPointer.getUnit().getNextUnits() == null) { + unit = nextUnit(startUnits, message); // выбирает unit из startUnits, если пользователь обращается впервые + } else { + unit = nextUnit(unitPointer.getUnit().getNextUnits(), message); + } + unitPointerService.edit(personId, unit); + } catch (NotFoundUnitException e) { + unit = defaultUnit; } - unitPointerService.edit(personId, unit); return unit; }