diff --git a/src/main/java/org/orienteer/telegram/component/widget/OTelegramBotWidget.java b/src/main/java/org/orienteer/telegram/component/widget/OTelegramBotWidget.java index 53ef8cb..c72d168 100644 --- a/src/main/java/org/orienteer/telegram/component/widget/OTelegramBotWidget.java +++ b/src/main/java/org/orienteer/telegram/component/widget/OTelegramBotWidget.java @@ -33,7 +33,6 @@ import java.util.List; - /** * @author Vitaliy Gonchar */ @@ -42,22 +41,21 @@ public class OTelegramBotWidget extends AbstractModeAwareWidget { private static final long serialVersionUID = 1L; private static final Logger LOG = LoggerFactory.getLogger(OTelegramBotWidget.class); - private OrienteerStructureTable structureTable; + private OrienteerStructureTable structureTable; - private List propertiesList = new ArrayList<>(); + private List propertiesList = new ArrayList<>(); public OTelegramBotWidget(String id, IModel model, IModel widgetDocumentModel) { super(id, model, widgetDocumentModel); Form form = new TransactionlessForm("form"); - propertiesList.add(OTelegramModule.TELEGRAM_SEARCH.getName()); - propertiesList.add(OTelegramModule.TELEGRAM_DOCUMENTS_LIST.getName()); - propertiesList.add(OTelegramModule.TELEGRAM_CLASS_DESCRIPTION.getName()); - propertiesList.add(OTelegramModule.TELEGRAM_SEARCH_QUERY.getName()); - structureTable = new OrienteerStructureTable("attributes", model, propertiesList) { - + propertiesList.add(OTelegramModule.TELEGRAM_SEARCH); + propertiesList.add(OTelegramModule.TELEGRAM_DOCUMENTS_LIST); + propertiesList.add(OTelegramModule.TELEGRAM_CLASS_DESCRIPTION); + propertiesList.add(OTelegramModule.TELEGRAM_SEARCH_QUERY); + structureTable = new OrienteerStructureTable("attributes", model, propertiesList) { @Override - protected Component getValueComponent(String id, IModel rowModel) { - return new OClassMetaPanel(id, getModeModel(), getModel(), rowModel) { + protected Component getValueComponent(String id, IModel rowModel) { + return new OClassMetaPanel(id, getModeModel(), getModel(), Model.of(rowModel.getObject().getName())) { @Override protected Object getValue(OClass entity, String critery) { CustomAttribute customAttribute = CustomAttribute.get(critery); @@ -92,7 +90,6 @@ protected void setValue(OClass entity, String critery, Object value) { }; } }; - structureTable.addCommand(new EditSchemaCommand(structureTable, getModeModel())); structureTable.addCommand(new SaveSchemaCommand(structureTable, getModeModel())); form.add(structureTable); diff --git a/src/main/java/org/orienteer/telegram/module/OTelegramModule.java b/src/main/java/org/orienteer/telegram/module/OTelegramModule.java index eb368c0..9c60bde 100644 --- a/src/main/java/org/orienteer/telegram/module/OTelegramModule.java +++ b/src/main/java/org/orienteer/telegram/module/OTelegramModule.java @@ -10,6 +10,7 @@ import org.orienteer.core.util.OSchemaHelper; import org.orienteer.telegram.bot.OTelegramBot; import org.orienteer.telegram.bot.handler.LongPolligHandlerConfig; +import org.orienteer.telegram.bot.handler.OTelegramLongPollingHandler; import org.orienteer.telegram.bot.handler.WebHookHandlerConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,25 +24,25 @@ public class OTelegramModule extends AbstractOrienteerModule { private static final Logger LOG = LoggerFactory.getLogger(OTelegramModule.class); - public static final String NAME = "telegram"; - public static final String OCLASS_NAME = "OTelegramBotTest"; - public static final String OPROPERTY_USERNAME = "username"; - public static final String OPROPERTY_TOKEN = "token"; - public static final String OPROPERTY_USER_SESSION = "user_session"; - public static final String OPROPERTY_WEB_HOOK_ENABLE = "web_hook_enable"; - public static final String OPROPERTY_WEB_HOOK_HOST = "web_hook_host"; - public static final String OPROPERTY_WEB_HOOK_PORT = "web_hook_port"; - public static final String OPROPERTY_WEB_HOOK_PATH_TO_CERTIFICATE_KEY = "path_to_certificate_public_key"; - public static final String OPROPERTY_WEB_HOOK_PATH_TO_CERTIFICATE_STORE = "path_to_certificate_store"; - public static final String OPROPERTY_WEB_HOOK_CERTIFICATE_PASSWORD = "certificate_password"; - - - public static final CustomAttribute TELEGRAM_SEARCH = CustomAttribute.create("orienteer.telegramSearch", OType.BOOLEAN, false, false, false); - public static final CustomAttribute TELEGRAM_DOCUMENTS_LIST = CustomAttribute.create("orienteer.telegramDocumentsList", OType.BOOLEAN, false, false, false); - public static final CustomAttribute TELEGRAM_SEARCH_QUERY = CustomAttribute.create("orienteer.telegramSearchQuery", OType.STRING, null, true, false); - public static final CustomAttribute TELEGRAM_CLASS_DESCRIPTION = CustomAttribute.create("orienteer.telegramClassDescription", OType.BOOLEAN, false, false, false); - - private BotSession botSession; + + private static final String NAME = "telegram"; + private static final String OCLASS_NAME = "OTelegramBotTest"; + private static final String OPROPERTY_USERNAME = "username"; + private static final String OPROPERTY_TOKEN = "token"; + private static final String OPROPERTY_USER_SESSION = "user_session"; + private static final String OPROPERTY_WEB_HOOK_ENABLE = "web_hook_enable"; + private static final String OPROPERTY_WEB_HOOK_HOST = "web_hook_host"; + private static final String OPROPERTY_WEB_HOOK_PORT = "web_hook_port"; + private static final String OPROPERTY_WEB_HOOK_PATH_TO_CERTIFICATE_KEY = "path_to_certificate_public_key"; + private static final String OPROPERTY_WEB_HOOK_PATH_TO_CERTIFICATE_STORE = "path_to_certificate_store"; + private static final String OPROPERTY_WEB_HOOK_CERTIFICATE_PASSWORD = "certificate_password"; + + public static final CustomAttribute TELEGRAM_SEARCH = CustomAttribute.getOrCreate("orienteer.telegramSearch", OType.BOOLEAN, false, false, false); + public static final CustomAttribute TELEGRAM_DOCUMENTS_LIST = CustomAttribute.getOrCreate("orienteer.telegramDocumentsList", OType.BOOLEAN, false, false, false); + public static final CustomAttribute TELEGRAM_SEARCH_QUERY = CustomAttribute.getOrCreate("orienteer.telegramSearchQuery", OType.STRING, null, true, false); + public static final CustomAttribute TELEGRAM_CLASS_DESCRIPTION = CustomAttribute.getOrCreate("orienteer.telegramClassDescription", OType.BOOLEAN, false, false, false); + + private BotSession botSession; protected OTelegramModule() { super(NAME, 1); @@ -85,7 +86,8 @@ public void onInitialize(OrienteerWebApplication app, ODatabaseDocument db, ODoc } else { telegramBotsApi = new TelegramBotsApi(); LongPolligHandlerConfig longPolligHandlerConfig = readLongPollingBotConfig(moduleDoc); - botSession = telegramBotsApi.registerBot(OTelegramBot.getLongPollingBot(longPolligHandlerConfig)); + OTelegramLongPollingHandler longPollingBot = OTelegramBot.getLongPollingBot(longPolligHandlerConfig); + botSession = telegramBotsApi.registerBot(longPollingBot); } } @@ -130,7 +132,9 @@ private WebHookHandlerConfig readWebHookBotConfig(ODocument doc) { @Override public void onDestroy(OrienteerWebApplication app, ODatabaseDocument db, ODocument moduleDoc) { - if (botSession != null) botSession.close(); + if (botSession != null) { + botSession.close(); + } } }