diff --git a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/AbstractRestPostIndexAction.java b/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/AbstractRestPostIndexAction.java deleted file mode 100644 index 5f715ec31a9529a99e1c1133148b9e2068673de0..0000000000000000000000000000000000000000 --- a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/AbstractRestPostIndexAction.java +++ /dev/null @@ -1,84 +0,0 @@ -package org.duniter.elasticsearch.action; - -/* - * #%L - * duniter4j-elasticsearch-plugin - * %% - * Copyright (C) 2014 - 2016 EIS - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import org.duniter.core.exception.BusinessException; -import org.duniter.elasticsearch.rest.XContentThrowableRestResponse; -import org.duniter.elasticsearch.rest.security.RestSecurityController; -import org.duniter.elasticsearch.exception.DuniterElasticsearchException; -import org.elasticsearch.client.Client; -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.ESLoggerFactory; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.rest.*; - -import static org.elasticsearch.rest.RestRequest.Method.GET; -import static org.elasticsearch.rest.RestRequest.Method.POST; -import static org.elasticsearch.rest.RestStatus.OK; - -public abstract class AbstractRestPostIndexAction extends BaseRestHandler { - - private static ESLogger log = null; - - private final JsonIndexer indexer; - - - public AbstractRestPostIndexAction(Settings settings, RestController controller, Client client, - RestSecurityController securityController, - String indexName, - String typeName, - JsonIndexer indexer) { - super(settings, controller, client); - controller.registerHandler(POST, - String.format("/%s/%s", indexName, typeName), - this); - securityController.allowIndexType(POST, indexName, typeName); - securityController.allowIndexType(GET, indexName, typeName); - log = ESLoggerFactory.getLogger(String.format("[%s]", indexName)); - this.indexer = indexer; - } - - @Override - protected void handleRequest(final RestRequest request, RestChannel restChannel, Client client) throws Exception { - - try { - String id = indexer.handleJson(request.content().toUtf8()); - restChannel.sendResponse(new BytesRestResponse(OK, id)); - } - catch(DuniterElasticsearchException | BusinessException e) { - log.error(e.getMessage(), e); - restChannel.sendResponse(new XContentThrowableRestResponse(request, e)); - } - catch(Exception e) { - log.error(e.getMessage(), e); - } - } - - - public interface JsonIndexer { - String handleJson(String json) throws DuniterElasticsearchException, BusinessException; - } - - - -} \ No newline at end of file diff --git a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/AbstractRestPostUpdateAction.java b/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/AbstractRestPostUpdateAction.java deleted file mode 100644 index c56a0a23aef039d0b2fffcaeee94a93e1143c378..0000000000000000000000000000000000000000 --- a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/AbstractRestPostUpdateAction.java +++ /dev/null @@ -1,83 +0,0 @@ -package org.duniter.elasticsearch.action; - -/* - * #%L - * duniter4j-elasticsearch-plugin - * %% - * Copyright (C) 2014 - 2016 EIS - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import org.duniter.core.exception.BusinessException; -import org.duniter.elasticsearch.rest.XContentThrowableRestResponse; -import org.duniter.elasticsearch.rest.security.RestSecurityController; -import org.duniter.elasticsearch.exception.DuniterElasticsearchException; -import org.elasticsearch.client.Client; -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.ESLoggerFactory; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.rest.*; - -import static org.elasticsearch.rest.RestRequest.Method.POST; -import static org.elasticsearch.rest.RestStatus.OK; - -public abstract class AbstractRestPostUpdateAction extends BaseRestHandler { - - private static ESLogger log = null; - - private final JsonUpdater updater; - - - public AbstractRestPostUpdateAction(Settings settings, RestController controller, Client client, - RestSecurityController securityController, - String indexName, - String typeName, - JsonUpdater updater) { - super(settings, controller, client); - controller.registerHandler(POST, - String.format("/%s/%s/{id}/_update", indexName, typeName), - this); - securityController.allowIndexType(POST, indexName, typeName); - log = ESLoggerFactory.getLogger(String.format("[%s]", indexName)); - this.updater = updater; - } - - @Override - protected void handleRequest(final RestRequest request, RestChannel restChannel, Client client) throws Exception { - String id = request.param("id"); - - try { - updater.handleJson(request.content().toUtf8(), id); - restChannel.sendResponse(new BytesRestResponse(OK, id)); - } - catch(DuniterElasticsearchException | BusinessException e) { - log.error(e.getMessage(), e); - restChannel.sendResponse(new XContentThrowableRestResponse(request, e)); - } - catch(Exception e) { - log.error(e.getMessage(), e); - } - } - - - public interface JsonUpdater { - void handleJson(String json, String id) throws DuniterElasticsearchException, BusinessException; - } - - - -} \ No newline at end of file diff --git a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/RestModule.java b/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/RestModule.java deleted file mode 100644 index a67d6f2a078292396379f7f74c30149b763b50b8..0000000000000000000000000000000000000000 --- a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/RestModule.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.duniter.elasticsearch.action; - -/* - * #%L - * duniter4j-elasticsearch-plugin - * %% - * Copyright (C) 2014 - 2016 EIS - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import org.duniter.elasticsearch.rest.currency.RestCurrencyIndexAction; -import org.duniter.elasticsearch.rest.history.RestHistoryDeleteIndexAction; -import org.duniter.elasticsearch.action.market.*; -import org.duniter.elasticsearch.action.message.RestMessageInboxIndexAction; -import org.duniter.elasticsearch.action.message.RestMessageOutboxIndexAction; -import org.duniter.elasticsearch.action.registry.*; -import org.duniter.elasticsearch.rest.security.RestSecurityAuthAction; -import org.duniter.elasticsearch.rest.security.RestSecurityController; -import org.duniter.elasticsearch.rest.security.RestSecurityFilter; -import org.duniter.elasticsearch.rest.security.RestSecurityGetChallengeAction; -import org.duniter.elasticsearch.action.user.RestUserProfileIndexAction; -import org.duniter.elasticsearch.action.user.RestUserProfileUpdateAction; -import org.duniter.elasticsearch.action.user.RestUserSettingsIndexAction; -import org.duniter.elasticsearch.action.user.RestUserSettingsUpdateAction; -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.inject.Module; - -public class RestModule extends AbstractModule implements Module { - - @Override protected void configure() { - - // Currency - bind(RestCurrencyIndexAction.class).asEagerSingleton(); - - // Market - bind(RestMarketRecordIndexAction.class).asEagerSingleton(); - bind(RestMarketRecordUpdateAction.class).asEagerSingleton(); - bind(RestMarketCommentIndexAction.class).asEagerSingleton(); - bind(RestMarketCommentUpdateAction.class).asEagerSingleton(); - bind(RestMarketCategoryAction.class).asEagerSingleton(); - - // Registry - bind(RestRegistryRecordIndexAction.class).asEagerSingleton(); - bind(RestRegistryRecordUpdateAction.class).asEagerSingleton(); - bind(RestRegistryCommentIndexAction.class).asEagerSingleton(); - bind(RestregistryCommentUpdateAction.class).asEagerSingleton(); - bind(RestRegistryCategoryAction.class).asEagerSingleton(); - - // User - bind(RestUserProfileIndexAction.class).asEagerSingleton(); - bind(RestUserProfileUpdateAction.class).asEagerSingleton(); - bind(RestUserSettingsIndexAction.class).asEagerSingleton(); - bind(RestUserSettingsUpdateAction.class).asEagerSingleton(); - - // Authentication & Security - bind(RestSecurityGetChallengeAction.class).asEagerSingleton(); - bind(RestSecurityAuthAction.class).asEagerSingleton(); - bind(RestSecurityFilter.class).asEagerSingleton(); - bind(RestSecurityController.class).asEagerSingleton(); - - // History - bind(RestHistoryDeleteIndexAction.class).asEagerSingleton(); - - // Message - bind(RestMessageInboxIndexAction.class).asEagerSingleton(); - bind(RestMessageOutboxIndexAction.class).asEagerSingleton(); - } -} \ No newline at end of file diff --git a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/history/RestHistoryDeleteIndexAction.java b/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/history/RestHistoryDeleteIndexAction.java deleted file mode 100644 index 0778b8d60ee0938c7320562848deec35c58e9ea9..0000000000000000000000000000000000000000 --- a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/history/RestHistoryDeleteIndexAction.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.duniter.elasticsearch.action.history; - -/* - * #%L - * duniter4j-elasticsearch-plugin - * %% - * Copyright (C) 2014 - 2016 EIS - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import org.duniter.elasticsearch.rest.AbstractRestPostIndexAction; -import org.duniter.elasticsearch.rest.security.RestSecurityController; -import org.duniter.elasticsearch.service.HistoryService; -import org.elasticsearch.client.Client; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.ESLoggerFactory; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.rest.RestController; - -public class RestHistoryDeleteIndexAction extends AbstractRestPostIndexAction { - - private static final ESLogger log = ESLoggerFactory.getLogger(org.duniter.elasticsearch.rest.history.RestHistoryDeleteIndexAction.class.getName()); - - @Inject - public RestHistoryDeleteIndexAction(Settings settings, RestController controller, Client client, - RestSecurityController securityController, HistoryService service) { - super(settings, controller, client, securityController, - HistoryService.INDEX, - HistoryService.DELETE_TYPE, - json -> service.indexDeleteFromJson(json)); - } -} \ No newline at end of file diff --git a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/market/RestMarketCommentIndexAction.java b/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/market/RestMarketCommentIndexAction.java deleted file mode 100644 index 37b278a0ac678b036d88d19db4eaacd5ab5112bd..0000000000000000000000000000000000000000 --- a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/market/RestMarketCommentIndexAction.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.duniter.elasticsearch.action.market; - -/* - * #%L - * duniter4j-elasticsearch-plugin - * %% - * Copyright (C) 2014 - 2016 EIS - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import org.duniter.elasticsearch.rest.AbstractRestPostIndexAction; -import org.duniter.elasticsearch.rest.security.RestSecurityController; -import org.duniter.elasticsearch.service.MarketService; -import org.elasticsearch.client.Client; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.rest.RestController; - -public class RestMarketCommentIndexAction extends AbstractRestPostIndexAction { - - @Inject - public RestMarketCommentIndexAction(Settings settings, RestController controller, Client client, RestSecurityController securityController, - MarketService service) { - super(settings, controller, client, securityController, - MarketService.INDEX, MarketService.RECORD_COMMENT_TYPE, - json -> service.indexCommentFromJson(json)); - } - -} \ No newline at end of file diff --git a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/market/RestMarketCommentUpdateAction.java b/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/market/RestMarketCommentUpdateAction.java deleted file mode 100644 index a11d15ab94ece445162e8af7aa31b99ea28df8e6..0000000000000000000000000000000000000000 --- a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/market/RestMarketCommentUpdateAction.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.duniter.elasticsearch.action.market; - -/* - * #%L - * duniter4j-elasticsearch-plugin - * %% - * Copyright (C) 2014 - 2016 EIS - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import org.duniter.elasticsearch.rest.AbstractRestPostUpdateAction; -import org.duniter.elasticsearch.rest.security.RestSecurityController; -import org.duniter.elasticsearch.service.MarketService; -import org.elasticsearch.client.Client; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.rest.RestController; - -public class RestMarketCommentUpdateAction extends AbstractRestPostUpdateAction { - - @Inject - public RestMarketCommentUpdateAction(Settings settings, RestController controller, Client client, RestSecurityController securityController, - MarketService service) { - super(settings, controller, client, securityController, - MarketService.INDEX, MarketService.RECORD_COMMENT_TYPE, - (json, id) -> service.updateCommentFromJson(json, id)); - } - -} \ No newline at end of file diff --git a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/market/RestMarketRecordIndexAction.java b/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/market/RestMarketRecordIndexAction.java deleted file mode 100644 index 1f7cfc68dd69eb97c7453cfeac80af4bceee66b2..0000000000000000000000000000000000000000 --- a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/market/RestMarketRecordIndexAction.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.duniter.elasticsearch.action.market; - -/* - * #%L - * duniter4j-elasticsearch-plugin - * %% - * Copyright (C) 2014 - 2016 EIS - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import org.duniter.elasticsearch.rest.AbstractRestPostIndexAction; -import org.duniter.elasticsearch.rest.security.RestSecurityController; -import org.duniter.elasticsearch.service.MarketService; -import org.elasticsearch.client.Client; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.rest.RestController; - -public class RestMarketRecordIndexAction extends AbstractRestPostIndexAction { - - @Inject - public RestMarketRecordIndexAction(Settings settings, RestController controller, Client client, RestSecurityController securityController, - MarketService service) { - super(settings, controller, client, securityController, - MarketService.INDEX, MarketService.RECORD_TYPE, - json -> service.indexRecordFromJson(json)); - } - -} \ No newline at end of file diff --git a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/market/RestMarketRecordUpdateAction.java b/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/market/RestMarketRecordUpdateAction.java deleted file mode 100644 index 7b1cd758b089c8a287e32ac233c6b3b3ae760dbf..0000000000000000000000000000000000000000 --- a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/market/RestMarketRecordUpdateAction.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.duniter.elasticsearch.action.market; - -/* - * #%L - * duniter4j-elasticsearch-plugin - * %% - * Copyright (C) 2014 - 2016 EIS - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import org.duniter.elasticsearch.rest.AbstractRestPostUpdateAction; -import org.duniter.elasticsearch.rest.security.RestSecurityController; -import org.duniter.elasticsearch.service.MarketService; -import org.elasticsearch.client.Client; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.rest.RestController; - -public class RestMarketRecordUpdateAction extends AbstractRestPostUpdateAction { - - @Inject - public RestMarketRecordUpdateAction(Settings settings, RestController controller, Client client, RestSecurityController securityController, - MarketService service) { - super(settings, controller, client, securityController, - MarketService.INDEX, MarketService.RECORD_TYPE, - (json, id) -> service.updateRecordFromJson(json, id)); - } - -} \ No newline at end of file diff --git a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/message/RestMessageInboxIndexAction.java b/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/message/RestMessageInboxIndexAction.java deleted file mode 100644 index 1ab8b7d53c57ae106d5812a918cbc5c710b9eadf..0000000000000000000000000000000000000000 --- a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/message/RestMessageInboxIndexAction.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.duniter.elasticsearch.action.message; - -/* - * #%L - * duniter4j-elasticsearch-plugin - * %% - * Copyright (C) 2014 - 2016 EIS - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import org.duniter.elasticsearch.rest.AbstractRestPostIndexAction; -import org.duniter.elasticsearch.rest.security.RestSecurityController; -import org.duniter.elasticsearch.service.MessageService; -import org.elasticsearch.client.Client; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.rest.RestController; - -public class RestMessageInboxIndexAction extends AbstractRestPostIndexAction { - - @Inject - public RestMessageInboxIndexAction(Settings settings, RestController controller, Client client, - RestSecurityController securityController, - final MessageService service) { - super(settings, controller, client, securityController, - MessageService.INDEX, - MessageService.RECORD_TYPE, - json -> service.indexRecordFromJson(json)); - } -} \ No newline at end of file diff --git a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/message/RestMessageOutboxIndexAction.java b/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/message/RestMessageOutboxIndexAction.java deleted file mode 100644 index 5fc0c8ba24eb47502266301c9eb9fe3056b32fea..0000000000000000000000000000000000000000 --- a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/message/RestMessageOutboxIndexAction.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.duniter.elasticsearch.action.message; - -/* - * #%L - * duniter4j-elasticsearch-plugin - * %% - * Copyright (C) 2014 - 2016 EIS - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import org.duniter.elasticsearch.rest.AbstractRestPostIndexAction; -import org.duniter.elasticsearch.rest.security.RestSecurityController; -import org.duniter.elasticsearch.service.MessageService; -import org.elasticsearch.client.Client; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.rest.RestController; - -public class RestMessageOutboxIndexAction extends AbstractRestPostIndexAction { - - @Inject - public RestMessageOutboxIndexAction(Settings settings, RestController controller, Client client, - RestSecurityController securityController, - final MessageService service) { - super(settings, controller, client, securityController, - MessageService.INDEX, - MessageService.OUTBOX_TYPE, - json -> service.indexRecordFromJson(json)); - } -} \ No newline at end of file diff --git a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/registry/RestRegistryCategoryAction.java b/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/registry/RestRegistryCategoryAction.java deleted file mode 100644 index db635061101d389b439931bb9fba650d3f95d5a3..0000000000000000000000000000000000000000 --- a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/registry/RestRegistryCategoryAction.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.duniter.elasticsearch.action.registry; - -/* - * #%L - * duniter4j-elasticsearch-plugin - * %% - * Copyright (C) 2014 - 2016 EIS - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import org.duniter.elasticsearch.rest.security.RestSecurityController; -import org.duniter.elasticsearch.service.RegistryService; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.rest.RestRequest; - -public class RestRegistryCategoryAction { - - @Inject - public RestRegistryCategoryAction(RestSecurityController securityController) { - // Add security rule for category - securityController.allowIndexType(RestRequest.Method.GET, RegistryService.INDEX, RegistryService.RECORD_CATEGORY_TYPE); - } - -} \ No newline at end of file diff --git a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/registry/RestRegistryCommentIndexAction.java b/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/registry/RestRegistryCommentIndexAction.java deleted file mode 100644 index b1fb59693d0355602abec4487eaf7298d9c8c096..0000000000000000000000000000000000000000 --- a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/registry/RestRegistryCommentIndexAction.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.duniter.elasticsearch.action.registry; - -/* - * #%L - * duniter4j-elasticsearch-plugin - * %% - * Copyright (C) 2014 - 2016 EIS - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import org.duniter.elasticsearch.rest.AbstractRestPostIndexAction; -import org.duniter.elasticsearch.rest.security.RestSecurityController; -import org.duniter.elasticsearch.service.RegistryService; -import org.elasticsearch.client.Client; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.rest.RestController; - -public class RestRegistryCommentIndexAction extends AbstractRestPostIndexAction { - - @Inject - public RestRegistryCommentIndexAction(Settings settings, RestController controller, Client client, RestSecurityController securityController, - RegistryService service) { - super(settings, controller, client, securityController, - RegistryService.INDEX, RegistryService.RECORD_COMMENT_TYPE, - json -> service.indexCommentFromJson(json)); - } - -} \ No newline at end of file diff --git a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/registry/RestRegistryRecordIndexAction.java b/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/registry/RestRegistryRecordIndexAction.java deleted file mode 100644 index 98d4fce014f567781d28a86a5276d5712af7c7d7..0000000000000000000000000000000000000000 --- a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/registry/RestRegistryRecordIndexAction.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.duniter.elasticsearch.action.registry; - -/* - * #%L - * duniter4j-elasticsearch-plugin - * %% - * Copyright (C) 2014 - 2016 EIS - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import org.duniter.elasticsearch.rest.AbstractRestPostIndexAction; -import org.duniter.elasticsearch.rest.security.RestSecurityController; -import org.duniter.elasticsearch.service.RegistryService; -import org.elasticsearch.client.Client; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.rest.RestController; - -public class RestRegistryRecordIndexAction extends AbstractRestPostIndexAction { - - - @Inject - public RestRegistryRecordIndexAction(Settings settings, RestController controller, Client client, RestSecurityController securityController, - RegistryService service) { - super(settings, controller, client, securityController, - RegistryService.INDEX, RegistryService.RECORD_TYPE, - json -> service.indexRecordFromJson(json)); - } -} \ No newline at end of file diff --git a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/registry/RestRegistryRecordUpdateAction.java b/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/registry/RestRegistryRecordUpdateAction.java deleted file mode 100644 index 3ea0b8a01ce461d0945eec000f96d1168872ebd7..0000000000000000000000000000000000000000 --- a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/registry/RestRegistryRecordUpdateAction.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.duniter.elasticsearch.action.registry; - -/* - * #%L - * duniter4j-elasticsearch-plugin - * %% - * Copyright (C) 2014 - 2016 EIS - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import org.duniter.elasticsearch.rest.AbstractRestPostUpdateAction; -import org.duniter.elasticsearch.rest.security.RestSecurityController; -import org.duniter.elasticsearch.service.RegistryService; -import org.elasticsearch.client.Client; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.rest.RestController; - -public class RestRegistryRecordUpdateAction extends AbstractRestPostUpdateAction { - - @Inject - public RestRegistryRecordUpdateAction(Settings settings, RestController controller, Client client, RestSecurityController securityController, - RegistryService service) { - super(settings, controller, client, securityController, - RegistryService.INDEX, RegistryService.RECORD_TYPE, - (json, id) -> service.updateRecordFromJson(json, id)); - } - -} \ No newline at end of file diff --git a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/registry/RestregistryCommentUpdateAction.java b/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/registry/RestregistryCommentUpdateAction.java deleted file mode 100644 index 329a5ae700849ad89611b93517b8a6f9f24cfd29..0000000000000000000000000000000000000000 --- a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/registry/RestregistryCommentUpdateAction.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.duniter.elasticsearch.action.registry; - -/* - * #%L - * duniter4j-elasticsearch-plugin - * %% - * Copyright (C) 2014 - 2016 EIS - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import org.duniter.elasticsearch.rest.AbstractRestPostUpdateAction; -import org.duniter.elasticsearch.rest.security.RestSecurityController; -import org.duniter.elasticsearch.service.RegistryService; -import org.elasticsearch.client.Client; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.rest.RestController; - -public class RestregistryCommentUpdateAction extends AbstractRestPostUpdateAction { - - @Inject - public RestregistryCommentUpdateAction(Settings settings, RestController controller, Client client, RestSecurityController securityController, - RegistryService service) { - super(settings, controller, client, securityController, - RegistryService.INDEX, RegistryService.RECORD_COMMENT_TYPE, - (json, id) -> service.updateCommentFromJson(json, id)); - } - -} \ No newline at end of file diff --git a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/user/RestUserProfileIndexAction.java b/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/user/RestUserProfileIndexAction.java deleted file mode 100644 index 535fb070daf65705a69e5f5cb3e4ed612ac1bd84..0000000000000000000000000000000000000000 --- a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/user/RestUserProfileIndexAction.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.duniter.elasticsearch.action.user; - -/* - * #%L - * duniter4j-elasticsearch-plugin - * %% - * Copyright (C) 2014 - 2016 EIS - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import org.duniter.elasticsearch.rest.AbstractRestPostIndexAction; -import org.duniter.elasticsearch.rest.security.RestSecurityController; -import org.duniter.elasticsearch.service.UserService; -import org.elasticsearch.client.Client; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.rest.RestController; - -public class RestUserProfileIndexAction extends AbstractRestPostIndexAction { - - @Inject - public RestUserProfileIndexAction(Settings settings, RestController controller, Client client, - RestSecurityController securityController, - UserService service) { - super(settings, controller, client, securityController, - UserService.INDEX, - UserService.PROFILE_TYPE, - json -> service.indexProfileFromJson(json)); - } -} \ No newline at end of file diff --git a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/user/RestUserProfileUpdateAction.java b/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/user/RestUserProfileUpdateAction.java deleted file mode 100644 index c287a82eea4b60477088c3069e9b8738839178af..0000000000000000000000000000000000000000 --- a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/user/RestUserProfileUpdateAction.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.duniter.elasticsearch.action.user; - -/* - * #%L - * duniter4j-elasticsearch-plugin - * %% - * Copyright (C) 2014 - 2016 EIS - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import org.duniter.elasticsearch.rest.AbstractRestPostUpdateAction; -import org.duniter.elasticsearch.rest.security.RestSecurityController; -import org.duniter.elasticsearch.service.UserService; -import org.elasticsearch.client.Client; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.rest.RestController; - -public class RestUserProfileUpdateAction extends AbstractRestPostUpdateAction { - - @Inject - public RestUserProfileUpdateAction(Settings settings, RestController controller, Client client, - RestSecurityController securityController, - UserService service) { - super(settings, controller, client, securityController, - UserService.INDEX, - UserService.PROFILE_TYPE, - (json, id) -> service.updateProfileFromJson(json, id)); - } - -} \ No newline at end of file diff --git a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/user/RestUserSettingsIndexAction.java b/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/user/RestUserSettingsIndexAction.java deleted file mode 100644 index 1948f583fe07f125725e9d2ef80b7343cf10958d..0000000000000000000000000000000000000000 --- a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/user/RestUserSettingsIndexAction.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.duniter.elasticsearch.action.user; - -/* - * #%L - * duniter4j-elasticsearch-plugin - * %% - * Copyright (C) 2014 - 2016 EIS - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import org.duniter.elasticsearch.rest.AbstractRestPostIndexAction; -import org.duniter.elasticsearch.rest.security.RestSecurityController; -import org.duniter.elasticsearch.service.UserService; -import org.elasticsearch.client.Client; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.rest.RestController; - -public class RestUserSettingsIndexAction extends AbstractRestPostIndexAction { - - @Inject - public RestUserSettingsIndexAction(Settings settings, RestController controller, Client client, - RestSecurityController securityController, - final UserService service) { - super(settings, controller, client, securityController, - UserService.INDEX, - UserService.SETTINGS_TYPE, - json -> service.indexSettingsFromJson(json)); - } - -} \ No newline at end of file diff --git a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/user/RestUserSettingsUpdateAction.java b/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/user/RestUserSettingsUpdateAction.java deleted file mode 100644 index b7b3bd717f67ef8cb2517f7824ceafa7a060c889..0000000000000000000000000000000000000000 --- a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/user/RestUserSettingsUpdateAction.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.duniter.elasticsearch.action.user; - -/* - * #%L - * duniter4j-elasticsearch-plugin - * %% - * Copyright (C) 2014 - 2016 EIS - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import org.duniter.elasticsearch.rest.AbstractRestPostUpdateAction; -import org.duniter.elasticsearch.rest.security.RestSecurityController; -import org.duniter.elasticsearch.service.UserService; -import org.elasticsearch.client.Client; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.rest.RestController; - -public class RestUserSettingsUpdateAction extends AbstractRestPostUpdateAction { - - @Inject - public RestUserSettingsUpdateAction(Settings settings, RestController controller, Client client, - RestSecurityController securityController, - final UserService service) { - super(settings, controller, client, securityController, - UserService.INDEX, - UserService.SETTINGS_TYPE, - (json, id) -> service.updateSettingsFromJson(json, id)); - } - -} \ No newline at end of file diff --git a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/Plugin.java b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/Plugin.java index a64334b6cd4159657b5110c034b7aabae3f3e75b..2998ff19a5d01088b06eae754935d3b9ae543147 100644 --- a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/Plugin.java +++ b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/Plugin.java @@ -49,7 +49,7 @@ public class Plugin extends org.elasticsearch.plugins.Plugin { @Override public String name() { - return "duniter"; + return "duniter4j-es-core"; } @Override diff --git a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/PluginSettings.java b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/PluginSettings.java index e1401e60e822ba0eec5136ea2865930233510117..70e2f12bdb6402986ac52a9c60a81721801ee414 100644 --- a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/PluginSettings.java +++ b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/PluginSettings.java @@ -284,6 +284,7 @@ public class PluginSettings extends AbstractLifecycleComponent<PluginSettings> { /* protected methods */ protected void initI18n() throws IOException { + if (I18n.getDefaultLocale() != null) return; // already init // --------------------------------------------------------------------// // init i18n @@ -307,6 +308,7 @@ public class PluginSettings extends AbstractLifecycleComponent<PluginSettings> { logger.info(String.format("Starts i18n with locale [%s] at [%s]", i18nLocale, i18nDirectory)); } + I18n.init(new UserI18nInitializer( i18nDirectory, new DefaultI18nInitializer(getI18nBundleName())), i18nLocale); diff --git a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/service/AbstractService.java b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/service/AbstractService.java index 8e4f408f305bb8b6b9af5f64379bdc4b65ad8193..f9486338ed64386fd830374ce604f373495af823 100644 --- a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/service/AbstractService.java +++ b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/service/AbstractService.java @@ -25,6 +25,7 @@ package org.duniter.elasticsearch.service; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Joiner; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; import com.google.gson.JsonSyntaxException; @@ -45,6 +46,10 @@ import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRespon import org.elasticsearch.action.bulk.BulkRequest; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.index.IndexResponse; +import org.elasticsearch.action.search.SearchPhaseExecutionException; +import org.elasticsearch.action.search.SearchRequestBuilder; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.action.search.SearchType; import org.elasticsearch.client.Client; import org.elasticsearch.client.Requests; import org.elasticsearch.common.bytes.BytesArray; @@ -52,9 +57,13 @@ import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.search.SearchHit; import org.nuiton.i18n.I18n; import java.io.*; +import java.util.HashMap; +import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.regex.Pattern; @@ -226,6 +235,54 @@ public abstract class AbstractService implements Bean { return value; } + /** + * Retrieve some field from a document id + * @param docId + * @return + */ + protected Map<String, Object> getFieldsById(String index, String type, String docId, String... fieldNames) { + // Prepare request + SearchRequestBuilder searchRequest = client + .prepareSearch(index) + .setTypes(type) + .setSearchType(SearchType.DFS_QUERY_THEN_FETCH); + + searchRequest.setQuery(QueryBuilders.matchQuery("_id", docId)); + searchRequest.addFields(fieldNames); + + // Execute query + try { + SearchResponse response = searchRequest.execute().actionGet(); + + Map<String, Object> result = new HashMap<>(); + // Read query result + SearchHit[] searchHits = response.getHits().getHits(); + for (SearchHit searchHit : searchHits) { + if (searchHit.source() != null) { + JsonNode source = objectMapper.readTree(searchHit.source()); + for(String fieldName: fieldNames) { + result.put(fieldName, getMandatoryField(source, fieldName)); + } + + } + else { + for(String fieldName: fieldNames) { + result.put(fieldName, searchHit.getFields().get(fieldName).getValue()); + } + } + break; + } + return result; + } + catch(SearchPhaseExecutionException | JsonSyntaxException | IOException e) { + // Failed or no item on index + throw new TechnicalException(String.format("[%s/%s] Unable to retrieve fields [%s] for document [%s]", + index, type, + Joiner.on(',').join(fieldNames).toString(), + docId), e); + } + } + protected void bulkFromClasspathFile(String classpathFile, String indexName, String indexType) { bulkFromClasspathFile(classpathFile, indexName, indexType, null); } diff --git a/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/model/MarketRecord.java b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/model/MarketRecord.java new file mode 100644 index 0000000000000000000000000000000000000000..52a48d5d01f16b8b7a65c0f8ed95cdc97a21c752 --- /dev/null +++ b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/model/MarketRecord.java @@ -0,0 +1,31 @@ +package org.duniter.elasticsearch.gchange.model; + +import org.duniter.core.client.model.elasticsearch.Record; + +/** + * Created by blavenie on 01/12/16. + */ +public class MarketRecord extends Record{ + + public static final String PROPERTY_TITLE="title"; + public static final String PROPERTY_DESCRIPTION="description"; + + private String title; + private String description; + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/model/event/GchangeEventCodes.java b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/model/event/GchangeEventCodes.java new file mode 100644 index 0000000000000000000000000000000000000000..37bbd68db892a64c22df5d4bdbaee087d49728ae --- /dev/null +++ b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/model/event/GchangeEventCodes.java @@ -0,0 +1,9 @@ +package org.duniter.elasticsearch.gchange.model.event; + +/** + * Created by blavenie on 01/12/16. + */ +public enum GchangeEventCodes { + + NEW_COMMENT +} diff --git a/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/service/MarketService.java b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/service/MarketService.java index 238d0b99d30adb2d0617a376d00eddc573e6c087..0ff97ce969d666e7ac3756df7549f4c959c7e930 100644 --- a/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/service/MarketService.java +++ b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/service/MarketService.java @@ -25,19 +25,19 @@ package org.duniter.elasticsearch.gchange.service; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; +import com.google.common.base.Joiner; import com.google.gson.JsonSyntaxException; -import org.duniter.core.client.model.elasticsearch.Currency; import org.duniter.core.client.model.elasticsearch.Record; import org.duniter.core.client.model.elasticsearch.RecordComment; import org.duniter.core.client.service.bma.WotRemoteService; import org.duniter.core.exception.TechnicalException; import org.duniter.core.service.CryptoService; -import org.duniter.core.util.StringUtils; -import org.duniter.elasticsearch.exception.InvalidFormatException; import org.duniter.elasticsearch.gchange.PluginSettings; +import org.duniter.elasticsearch.gchange.model.MarketRecord; +import org.duniter.elasticsearch.gchange.model.event.GchangeEventCodes; import org.duniter.elasticsearch.service.AbstractService; import org.duniter.elasticsearch.user.service.event.UserEvent; -import org.duniter.elasticsearch.user.service.event.UserEventCodes; +import org.duniter.elasticsearch.user.service.event.UserEventLink; import org.duniter.elasticsearch.user.service.event.UserEventService; import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; import org.elasticsearch.action.index.IndexRequestBuilder; @@ -54,9 +54,10 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHitField; +import org.nuiton.i18n.I18n; import java.io.IOException; -import java.io.UnsupportedEncodingException; +import java.util.Map; /** * Created by Benoit on 30/03/2015. @@ -171,19 +172,32 @@ public class MarketService extends AbstractService { public String indexCommentFromJson(String json) { JsonNode actualObj = readAndVerifyIssuerSignature(json); String issuer = getMandatoryField(actualObj, RecordComment.PROPERTY_ISSUER).asText(); - String recordId = getMandatoryField(actualObj, RecordComment.PROPERTY_RECORD).asText(); - String recordIssuer = getRecordIssuerById(recordId); if (logger.isDebugEnabled()) { logger.debug(String.format("Indexing a %s from issuer [%s]", RECORD_COMMENT_TYPE, issuer.substring(0, 8))); } String commentId = indexDocumentFromJson(INDEX, RECORD_COMMENT_TYPE, json); - // Notify record issuer - if (!issuer.equals(recordIssuer)) { - userEventService.notifyUser(recordIssuer, - new UserEvent(UserEvent.EventType.INFO, /*TODO*/ "NEW_COMMENT")); + // Notification + { + // Notify issuer of record (is not same as comment writer) + String recordId = getMandatoryField(actualObj, RecordComment.PROPERTY_RECORD).asText(); + Map<String, Object> recordFields = getRecordFieldsById(recordId, MarketRecord.PROPERTY_TITLE, MarketRecord.PROPERTY_ISSUER); + String recordIssuer = recordFields.get(MarketRecord.PROPERTY_ISSUER).toString(); + String recordTitle = recordFields.get(MarketRecord.PROPERTY_TITLE).toString(); + if (!issuer.equals(recordIssuer)) { + userEventService.notifyUser(recordIssuer, + new UserEvent(UserEvent.EventType.INFO, + GchangeEventCodes.NEW_COMMENT.name(), + new UserEventLink(INDEX, RECORD_TYPE, recordId), + I18n.n("duniter.market.event.newComment"), + issuer, recordTitle + ) + ); + } } + + return commentId; } public void updateCommentFromJson(String json, String id) { @@ -410,44 +424,15 @@ public class MarketService extends AbstractService { } /** - * Retrieve a blockchain from its name + * Retrieve record field's values * @param recordId + * @param fieldNames * @return */ - protected String getRecordIssuerById(String recordId) { - // Prepare request - SearchRequestBuilder searchRequest = client - .prepareSearch(INDEX) - .setTypes(RECORD_TYPE) - .setSearchType(SearchType.DFS_QUERY_THEN_FETCH); + protected Map<String, Object> getRecordFieldsById(String recordId, String... fieldNames) { - searchRequest.setQuery(QueryBuilders.matchQuery("_id", recordId)); - searchRequest.addFields(Record.PROPERTY_ISSUER); + return getFieldsById(INDEX, RECORD_TYPE, recordId, fieldNames); + } - // Execute query - try { - SearchResponse response = searchRequest.execute().actionGet(); - - // Read query result - SearchHit[] searchHits = response.getHits().getHits(); - for (SearchHit searchHit : searchHits) { - if (searchHit.source() != null) { - JsonNode source = objectMapper.readTree(searchHit.source()); - return source.get(Record.PROPERTY_ISSUER).asText(); - } - else { - SearchHitField field = searchHit.getFields().get(Record.PROPERTY_ISSUER); - return field.getValue().toString(); - } - } - } - catch(SearchPhaseExecutionException | JsonSyntaxException | IOException | UnsupportedEncodingException e) { - // Failed or no item on index - if (logger.isDebugEnabled()) { - logger.error(String.format("Unable to retrieve issuer of record [%s]", recordId), e); - } - } - return null; - } } diff --git a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/Plugin.java b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/Plugin.java index f1bde795a5cf87a32a28e936046038343f51fb35..0736535c3b7bd4d2e31d1e30e39e6d5604c841b8 100644 --- a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/Plugin.java +++ b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/Plugin.java @@ -23,9 +23,8 @@ package org.duniter.elasticsearch.user; */ import com.google.common.collect.Lists; -import org.duniter.elasticsearch.PluginInit; -import org.duniter.elasticsearch.user.service.ServiceModule; import org.duniter.elasticsearch.user.rest.RestModule; +import org.duniter.elasticsearch.user.service.ServiceModule; import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Module; @@ -47,7 +46,7 @@ public class Plugin extends org.elasticsearch.plugins.Plugin { @Override public String name() { - return "duniter.user"; + return "duniter4j-es-user"; } @Override diff --git a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/PluginInit.java b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/PluginInit.java index 15bbda2511094cfd73dc20bc7159dba693cea169..c0e597f17c485745f559be039da07857a4daf3cb 100644 --- a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/PluginInit.java +++ b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/PluginInit.java @@ -38,6 +38,7 @@ import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; +import org.nuiton.i18n.I18n; /** * Created by blavenie on 17/06/16. @@ -77,7 +78,8 @@ public class PluginInit extends AbstractLifecycleComponent<org.duniter.elasticse .notifyAdmin(new UserEvent( UserEvent.EventType.INFO, UserEventCodes.NODE_STARTED.name(), - new String[]{clusterName})); + I18n.n("duniter.event.NODE_STARTED"), + clusterName)); }); } diff --git a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/service/event/UserEvent.java b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/service/event/UserEvent.java index 9046f3c145480f2199dc86d54659e938f2179921..f54954a64385e4dcc1247e43ffe89d0d96d84eb5 100644 --- a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/service/event/UserEvent.java +++ b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/service/event/UserEvent.java @@ -31,27 +31,32 @@ import java.util.Locale; */ public class UserEvent { - private EventType type; + private final EventType type; - private String code; + private final String code; - private long time; + private final long time; - private String message; + private final String message; + private final String[] params; - private String[] params; + private final UserEventLink link; public UserEvent(EventType type, String code) { - this(type, code, null); + this(type, code, null, "duniter.event." + code, null); } - public UserEvent(EventType type, String code, String[] params) { + public UserEvent(EventType type, String code, String message, String... params) { + this(type, code, null, message, params); + } + + public UserEvent(EventType type, String code, UserEventLink link, String message, String... params) { this.type = type; this.code = code; this.params = params; - // default - this.message = I18n.t("duniter4j.event." + code, params); + this.link = link; + this.message = message; this.time = Math.round(1d * System.currentTimeMillis() / 1000); } @@ -59,38 +64,22 @@ public class UserEvent { return type; } - public void setType(EventType type) { - this.type = type; - } - public String getCode() { return code; } - public void setCode(String code) { - this.code = code; - } - public String getMessage() { return message; } public String getLocalizedMessage(Locale locale) { - return I18n.l(locale, "duniter4j.event." + code, params); - } - - public void setMessage(String message) { - this.message = message; + return I18n.l(locale, message, params); } public String[] getParams() { return params; } - public void setParams(String[] params) { - this.params = params; - } - public long getTime() { return time; } diff --git a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/service/event/UserEventCodes.java b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/service/event/UserEventCodes.java index 368e025de692bf7e1ee3540ca8549f6fa6851d7a..6c334ef98ca1b222df18768fd88a834da63c26be 100644 --- a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/service/event/UserEventCodes.java +++ b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/service/event/UserEventCodes.java @@ -28,7 +28,6 @@ package org.duniter.elasticsearch.user.service.event; public enum UserEventCodes { NODE_STARTED, - CREATE_DOC, - UPDATE_DOC, - COMMENT_DOC + CREATE_DOC + } diff --git a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/market/RestMarketCategoryAction.java b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/service/event/UserEventLink.java similarity index 54% rename from duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/market/RestMarketCategoryAction.java rename to duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/service/event/UserEventLink.java index 7bf4f6ae423b0a3896c0900ab1914ff6a6e12a19..23e1c87b74b93c6987ff96f8bae2504b06b5c28c 100644 --- a/duniter4j-es-assembly/src/main/java/org/duniter/elasticsearch/action/market/RestMarketCategoryAction.java +++ b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/service/event/UserEventLink.java @@ -1,8 +1,8 @@ -package org.duniter.elasticsearch.action.market; +package org.duniter.elasticsearch.user.service.event; /* * #%L - * duniter4j-elasticsearch-plugin + * Duniter4j :: ElasticSearch Plugin * %% * Copyright (C) 2014 - 2016 EIS * %% @@ -22,17 +22,36 @@ package org.duniter.elasticsearch.action.market; * #L% */ -import org.duniter.elasticsearch.rest.security.RestSecurityController; -import org.duniter.elasticsearch.service.MarketService; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.rest.RestRequest; +import org.nuiton.i18n.I18n; -public class RestMarketCategoryAction { +import java.util.Locale; - @Inject - public RestMarketCategoryAction(RestSecurityController securityController) { - // Add security rule for category - securityController.allowIndexType(RestRequest.Method.GET, MarketService.INDEX, MarketService.RECORD_CATEGORY_TYPE); +/** + * Created by blavenie on 29/11/16. + */ +public class UserEventLink { + + private final String index; + + private final String type; + + private final String id; + + public UserEventLink(String index, String type, String id) { + this.index = index; + this.type = type; + this.id = id; } -} \ No newline at end of file + public String getIndex() { + return index; + } + + public String getType() { + return type; + } + + public String getId() { + return id; + } +} diff --git a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/service/event/UserEventService.java b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/service/event/UserEventService.java index 8daf4e68f68ef87e04a7e2cb9aee3eb9989e9758..e3cfda044265163c853c26f6271e2ca7130913c8 100644 --- a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/service/event/UserEventService.java +++ b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/service/event/UserEventService.java @@ -89,7 +89,7 @@ public class UserEventService extends AbstractService implements ChangeListener if (!this.mailEnable && logger.isTraceEnabled()) { logger.trace("Mail disable"); } - ChangeService.registerListener(this); + //ChangeService.registerListener(this); } /** @@ -118,17 +118,6 @@ public class UserEventService extends AbstractService implements ChangeListener } } - /** - * Notify a new document - */ - public void notifyNewDocument(String index, String type, String id, String issuer) { - - String docId = String.format("%s/%s/%s", index, type, id); - logger.info(String.format("Detected new document at: %s", docId)); - - notifyUser(issuer, new UserEvent(UserEvent.EventType.INFO, UserEventCodes.CREATE_DOC.name(), new String[]{docId})); - } - /** * Notify a user */ @@ -142,7 +131,7 @@ public class UserEventService extends AbstractService implements ChangeListener @Override public void onChanges(String json) { // TODO get doc issuer - String issuer = nodePubkey; + /* String issuer = nodePubkey; ChangeEvent event = ChangeUtils.fromJson(objectMapper, json); @@ -153,7 +142,7 @@ public class UserEventService extends AbstractService implements ChangeListener if (event.getOperation() == ChangeEvent.Operation.CREATE) { notifyNewDocument(event.getIndex(), event.getType(), event.getId(), issuer); - } + }*/ } @@ -291,15 +280,34 @@ public class UserEventService extends AbstractService implements ChangeListener .field("index", "not_analyzed") .endObject() - // params - .startObject("params") - .field("type", "string") + // link + .startObject("link") + .field("type", "nested") + .field("dynamic", "false") + .startObject("properties") + .startObject("index") + .field("type", "string") + .field("index", "not_analyzed") + .endObject() + .startObject("type") + .field("type", "string") + .field("index", "not_analyzed") + .endObject() + .startObject("id") + .field("type", "string") + .field("index", "not_analyzed") + .endObject() + .endObject() .endObject() // message .startObject("message") .field("type", "string") - .field("index", "not_analyzed") + .endObject() + + // params + .startObject("params") + .field("type", "string") .endObject() .endObject() diff --git a/duniter4j-es-user/src/main/resources/i18n/duniter4j-es-user_en_GB.properties b/duniter4j-es-user/src/main/resources/i18n/duniter4j-es-user_en_GB.properties index 452f86030f449dec66b1856c42eb67c701f51138..7c2d2a95ba12d23aa03f5f289a2672561c9ee450 100644 --- a/duniter4j-es-user/src/main/resources/i18n/duniter4j-es-user_en_GB.properties +++ b/duniter4j-es-user/src/main/resources/i18n/duniter4j-es-user_en_GB.properties @@ -1,3 +1,4 @@ +duniter.event.NODE_STARTED= duniter4j.event.NODE_STARTED=Node started on cluster Duniter4j ES [%s] duniter4j.event.subject.ERROR=[%s] Error message duniter4j.event.subject.INFO=[%s] Information message diff --git a/duniter4j-es-user/src/main/resources/i18n/duniter4j-es-user_fr_FR.properties b/duniter4j-es-user/src/main/resources/i18n/duniter4j-es-user_fr_FR.properties index 4ae1466a52f86484a597b4f91319ec1262e49b0b..3ae4dd7f9b020c5836702fd8a2e4d7c0f0196572 100644 --- a/duniter4j-es-user/src/main/resources/i18n/duniter4j-es-user_fr_FR.properties +++ b/duniter4j-es-user/src/main/resources/i18n/duniter4j-es-user_fr_FR.properties @@ -1,3 +1,4 @@ +duniter.event.NODE_STARTED= duniter4j.event.NODE_STARTED=Noeud démarré sur le cluster Duniter4j ES [%s] duniter4j.event.subject.ERROR=%s Message d'erreur duniter4j.event.subject.INFO=%s Message d'information