diff --git a/cesium-plus-pod-assembly/src/main/assembly/config/elasticsearch.yml b/cesium-plus-pod-assembly/src/main/assembly/config/elasticsearch.yml index 1744ec2828caebf2ca35cf2fab2ab8ce6daf27e5..b0803719fbbc08e562bd614dd76335ae14610385 100644 --- a/cesium-plus-pod-assembly/src/main/assembly/config/elasticsearch.yml +++ b/cesium-plus-pod-assembly/src/main/assembly/config/elasticsearch.yml @@ -122,6 +122,8 @@ duniter.string.analyzer: french # Enabling blockchain synchronization (default: false) # duniter.blockchain.enable: true +#duniter.blockchain.event.user.enable: true +#duniter.blockchain.event.admin.enable: true # # Force blockchain full synchronization - /!\ WARNING: all user events will be reset to 'unread' # @@ -180,6 +182,10 @@ duniter.p2p.includes.endpoints: [ # # duniter.p2p.includes.pubkeys: [""] # +# Need to full resync using P2P endpoints, at startup. Useful when new pods has been added +# +# duniter.p2p.fullResyncAtStartup: true +# # ---------------------------------- Duniter4j document moderation --------------- # # Filter too old document, if time older that 'maxPastDelta' (in seconds). (default: 7200 =2h) @@ -249,19 +255,25 @@ duniter.subscription.enable: false # # Email subscription: URL to a Cesium site, for links in the email content (default: https://g1.duniter.fr) # -# duniter.subscription.email.cesium.url: 'http://domain.com/cesium' +# duniter.subscription.email.link.url: 'http://domain.com/cesium' # # ---------------------------------- Duniter4j User (profile, message) module ------------------- # # # Share link: `og:site_name` (default: 'Cesium') # -# duniter.user.share.site.name: 'Cesium - Ğ1' +# duniter.share.site.name: 'Cesium - Ğ1' +# +# Share page link : URL to a web site, for links to a page (default: https://g1.duniter.fr/#/app/page/view/{id}/{title} ) +# Usable variables are: {id} and {title} +# +# duniter.share.page.link.url: 'https://domain.com/cesium/#/app/page/view/{id}/{title}' # -# Share link: `og:url` - URL to a Cesium site, for links in the email content (default: https://g1.duniter.fr) +# Share user link : URL to a web site, for links to a user (default: https://g1.duniter.fr/#https://g1.duniter.fr/#/app/wot/{pubkey}/{title} ) +# Usable variables are: {pubkey} and {title} # -# duniter.share.cesium.url: 'https://domain.com/cesium' +# duniter.share.user.link.url: 'https://domain.com/cesium/#/app/wot/{pubkey}/{title}' # -# Share link: Base URL of the ES cluster, to resolve `og:image` URL (default: none => /!\ Will use relative image path) +# Share default image: URL of an image (min size of 200x200px) to use as default image for `og:image` (default: https://g1.duniter.fr/img/logo_200px.png) # -# duniter.share.base.url: 'https://data.domain.com' \ No newline at end of file +# duniter.share.image.default.url: https://g1.duniter.fr/img/logo_200px.png \ No newline at end of file diff --git a/cesium-plus-pod-assembly/src/test/es-home/config/elasticsearch.yml b/cesium-plus-pod-assembly/src/test/es-home/config/elasticsearch.yml index 124f71b8c5443388105ff26fe60d1b987a37dcab..2cfb7083d168e09de6c62416302256a8433c9d3d 100644 --- a/cesium-plus-pod-assembly/src/test/es-home/config/elasticsearch.yml +++ b/cesium-plus-pod-assembly/src/test/es-home/config/elasticsearch.yml @@ -122,6 +122,8 @@ duniter.string.analyzer: french # Enabling blockchain synchronization # duniter.blockchain.enable: true +#duniter.blockchain.event.user.enable: true +#duniter.blockchain.event.admin.enable: true # # Force blockchain full synchronization - /!\ WARNING: all user events will be reset to 'unread' # @@ -191,6 +193,20 @@ duniter.p2p.includes.endpoints: [ #] #duniter.p2p.fullResyncAtStartup: true # +# ---------------------------------- Duniter4j document moderation --------------- +# +# Filter too old document, if time older that 'maxPastDelta' (in seconds). (default: 7200 =2h) +# +# duniter.document.time.maxPastDelta: 7200 +# +# Filter document in the futur, if time greater that 'maxFutureDelta' (in seconds). (default: 600 =10min) +# +# duniter.document.time.maxFutureDelta: 600 +# +# Allow admin (define in duniter.keyring) to delete documents ? (default: true) +# +# duniter.document.allowAdminDeletion: true +# # ---------------------------------- Duniter4j Mail module ----------------------- # # Enable mail module ? @@ -251,19 +267,25 @@ duniter.subscription.enable: true # # Email subscription: URL to a Cesium site, for links in the email content (default: https://g1.duniter.fr) # -#duniter.subscription.email.cesium.url: 'https://domain.com/cesium' +#duniter.subscription.email.link.url: 'https://domain.com/cesium' # -# ---------------------------------- Duniter4j User (profile, message) module ------------------- +# ---------------------------------- Duniter4j Share module ------------------- # # # Share link: og:site_name (default: 'Cesium') # -# duniter.user.share.site.name: 'Cesium - Ğ1' +# duniter.share.site.name: 'Cesium - Ğ1' +# +# Share page link : URL to a web site, for links to a page (default: https://g1.duniter.fr/#/app/page/view/{id}/{title} ) +# Usable variables are: {id} and {title} +# +# duniter.share.page.link.url: 'https://domain.com/cesium/#/app/page/view/{id}/{title}' # -# Share link : URL to a Cesium site, for links in the email content (default: https://g1.duniter.fr) +# Share user link : URL to a web site, for links to a user (default: https://g1.duniter.fr/#https://g1.duniter.fr/#/app/wot/{pubkey}/{title} ) +# Usable variables are: {pubkey} and {title} # -#duniter.share.cesium.url: 'https://domain.com/cesium' +# duniter.share.user.link.url: 'https://domain.com/cesium/#/app/wot/{pubkey}/{title}' # -# Share link : Base URL of cluster, to resolve image (default: none => /!\ Will use relative image path) +# Share default image: URL of an image (min size of 200x200px) to use as default image for `og:image` (default: https://g1.duniter.fr/img/logo_200px.png) # -#duniter.share.base.url: 'http://localhost:9200' \ No newline at end of file +# duniter.share.image.default.url: https://g1.duniter.fr/img/logo_200px.png \ No newline at end of file diff --git a/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/Plugin.java b/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/Plugin.java index 3b96eb6b3f759318324edcf155a8036c7cc330a5..bd86c8296a6ec6e815374586e124a6ad61085999 100644 --- a/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/Plugin.java +++ b/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/Plugin.java @@ -46,7 +46,7 @@ public class Plugin extends org.elasticsearch.plugins.Plugin { private boolean enable; @Inject public Plugin(Settings settings) { - this.enable = settings.getAsBoolean("duniter.enabled", true); + this.enable = settings.getAsBoolean("duniter.enable", true); this.logger = Loggers.getLogger("duniter.core", settings, new String[0]); } diff --git a/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/PluginInit.java b/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/PluginInit.java index 1c279625a528d67c8fc79e6b117e10db50b95d14..21073f65e5c583ffbbc369d4b593057587034952 100644 --- a/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/PluginInit.java +++ b/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/PluginInit.java @@ -103,7 +103,7 @@ public class PluginInit extends AbstractLifecycleComponent<PluginInit> { } } - else if (pluginSettings.enableBlockchainSync() && pluginSettings.reloadBlockchainIndices() && pluginSettings.reloadBlockchainIndicesFrom() <= 0) { + else if (pluginSettings.enableBlockchainIndexation() && pluginSettings.reloadBlockchainIndices() && pluginSettings.reloadBlockchainIndicesFrom() <= 0) { if (logger.isWarnEnabled()) { logger.warn("/!\\ Reloading blockchain indices..."); } @@ -140,7 +140,7 @@ public class PluginInit extends AbstractLifecycleComponent<PluginInit> { protected void doAfterStart() { // Synchronize blockchain - if (pluginSettings.enableBlockchainSync()) { + if (pluginSettings.enableBlockchainIndexation()) { Peer peer = pluginSettings.checkAndGetPeer(); diff --git a/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/PluginSettings.java b/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/PluginSettings.java index 084e47db917049cec53706c5cf7e6a54493ea06c..8018e4ca835ae27b7098138e562bc03518503296 100644 --- a/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/PluginSettings.java +++ b/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/PluginSettings.java @@ -61,6 +61,8 @@ public class PluginSettings extends AbstractLifecycleComponent<PluginSettings> { private List<String> i18nBundleNames = new ArrayList<>(); // Default + private String clusterRemoteUrl; + /** * Delegate application config. */ @@ -154,10 +156,42 @@ public class PluginSettings extends AbstractLifecycleComponent<PluginSettings> { return settings; } + /* -- settings on cluster -- */ + public String getClusterName() { return settings.get("cluster.name", "?"); } + public String getClusterRemoteHost() { + return settings.get("cluster.remote.host"); + } + + public int getClusterRemotePort() { + return settings.getAsInt("cluster.remote.port", 80); + } + + public boolean getClusterRemoteUseSsl() { + return settings.getAsBoolean("cluster.remote.useSsl", getClusterRemotePort() == 443); + } + + public String getClusterRemoteUrlOrNull() { + if (StringUtils.isBlank(getClusterRemoteHost())) return null; + + if (clusterRemoteUrl == null) { + + clusterRemoteUrl = Peer.newBuilder().setHost(getClusterRemoteHost()) + .setPort(getClusterRemotePort()) + .setUseSsl(getClusterRemoteUseSsl()) + .build() + .getUrl(); + } + + return clusterRemoteUrl; + } + + + /* -- Settings on Duniter node (with BMA API) -- */ + public String getNodeBmaHost() { return settings.get("duniter.host", "g1.duniter.org"); } @@ -170,6 +204,8 @@ public class PluginSettings extends AbstractLifecycleComponent<PluginSettings> { return settings.getAsBoolean("duniter.useSsl", getNodeBmaPort() == 443); } + /* -- Other settings -- */ + public boolean isIndexBulkEnable() { return settings.getAsBoolean("duniter.bulk.enable", true); } @@ -190,7 +226,7 @@ public class PluginSettings extends AbstractLifecycleComponent<PluginSettings> { return settings.getAsBoolean("duniter.indices.reload", false); } - public boolean enableBlockchainSync() { + public boolean enableBlockchainIndexation() { return settings.getAsBoolean("duniter.blockchain.enable", false); } diff --git a/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/rest/share/AbstractRestShareLinkAction.java b/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/rest/share/AbstractRestShareLinkAction.java index 6dd3dd5a8d41c80a6aa9b6733b45de31e1c575e9..f11a850dbac68d75c1f73d5cc938d7e55bc763ae 100644 --- a/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/rest/share/AbstractRestShareLinkAction.java +++ b/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/rest/share/AbstractRestShareLinkAction.java @@ -1,9 +1,11 @@ package org.duniter.elasticsearch.rest.share; import org.apache.http.entity.ContentType; +import org.duniter.core.client.model.local.Peer; import org.duniter.core.exception.BusinessException; import org.duniter.core.util.Preconditions; import org.duniter.core.util.StringUtils; +import org.duniter.elasticsearch.PluginSettings; import org.duniter.elasticsearch.exception.DuniterElasticsearchException; import org.duniter.elasticsearch.rest.XContentThrowableRestResponse; import org.duniter.elasticsearch.util.opengraph.OGData; @@ -34,25 +36,36 @@ public abstract class AbstractRestShareLinkAction extends BaseRestHandler { private STGroup templates; private String urlPattern; - public AbstractRestShareLinkAction(Settings settings, RestController controller, Client client, + public AbstractRestShareLinkAction(PluginSettings pluginSettings, + RestController controller, Client client, + String indexName, + String typeName + ) { + this(pluginSettings, controller, client, indexName, typeName,null); + } + + public AbstractRestShareLinkAction(PluginSettings pluginSettings, + RestController controller, Client client, String indexName, String typeName, - String shareBaseUrl, OGDataResolver resolver ) { - super(settings, controller, client); + super(pluginSettings.getSettings(), controller, client); log = Loggers.getLogger("duniter.rest." + indexName, settings, String.format("[%s]", indexName)); + String clusterUrl = pluginSettings.getClusterRemoteUrlOrNull(); + String pathPattern = String.format("/%s/%s/%s/_share", indexName, typeName, "%s"); controller.registerHandler(GET, String.format(pathPattern, "{id}"), this); - this.urlPattern = (shareBaseUrl != null ? shareBaseUrl : "") + pathPattern; - this.resolver = resolver; + + this.urlPattern = (clusterUrl != null ? clusterUrl : "") + pathPattern; // Configure springtemplate engine this.templates = STUtils.newSTGroup("org/duniter/elasticsearch/templates"); Preconditions.checkNotNull(this.templates.getInstanceOf("html_share"), "Unable to load ST template for share page"); + this.resolver = resolver; } @Override @@ -96,4 +109,7 @@ public abstract class AbstractRestShareLinkAction extends BaseRestHandler { } } + public void setResolver(OGDataResolver resolver) { + this.resolver = resolver; + } } diff --git a/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/service/AbstractBlockchainListenerService.java b/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/service/AbstractBlockchainListenerService.java index ec9b0dddc073b0b408d2df5dfd28fc24c2740f11..e122a9d897e78f193224e741100cc6c8cd01d9fa 100644 --- a/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/service/AbstractBlockchainListenerService.java +++ b/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/service/AbstractBlockchainListenerService.java @@ -60,16 +60,18 @@ public abstract class AbstractBlockchainListenerService extends AbstractService protected BulkRequestBuilder bulkRequest; protected boolean flushing; + @Inject public AbstractBlockchainListenerService(String loggerName, Duniter4jClient client, PluginSettings settings, CryptoService cryptoService, ThreadPool threadPool, - TimeValue processingInterval) { + TimeValue processingInterval, + boolean enable) { super(loggerName, client, settings, cryptoService); this.listenerId = loggerName; - this.enable = pluginSettings.enableBlockchainSync(); + this.enable = enable; this.threadPool = threadPool; this.bulkSize = pluginSettings.getIndexBulkSize(); diff --git a/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/service/BlockchainListenerService.java b/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/service/BlockchainListenerService.java index d22758b8e48092a6bbcce16d755ac6eefd2b6c01..b3c74160afa3e5631b9d8a584bd4a1ca5e1a480d 100644 --- a/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/service/BlockchainListenerService.java +++ b/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/service/BlockchainListenerService.java @@ -56,7 +56,8 @@ public class BlockchainListenerService extends AbstractBlockchainListenerService BlockStatDao blockStatDao, MovementDao movementDao) { super("duniter.blockchain.listener", client, settings, cryptoService, threadPool, - new TimeValue(500, TimeUnit.MILLISECONDS)); + new TimeValue(500, TimeUnit.MILLISECONDS), + settings.enableBlockchainIndexation()); this.blockStatDao = blockStatDao; this.movementDao = movementDao; } diff --git a/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/synchro/SynchroService.java b/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/synchro/SynchroService.java index 5ecb5611df1c7c3d11d0e8bef4f25fc13c120a5c..a1794c147c5fd5c36c3345aea7e598db63e5436a 100644 --- a/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/synchro/SynchroService.java +++ b/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/synchro/SynchroService.java @@ -292,7 +292,12 @@ public class SynchroService extends AbstractService { } } catch (IOException e) { - logger.warn(String.format("Unable to parse P2P endpoint [%s]: %s", endpoint, e.getMessage())); + if (logger.isDebugEnabled()) { + logger.warn(String.format("Unable to parse P2P endpoint [%s]: %s", endpoint, e.getMessage()), e); + } + else { + logger.warn(String.format("Unable to parse P2P endpoint [%s]: %s", endpoint, e.getMessage())); + } } } return peers; diff --git a/cesium-plus-pod-core/src/main/resources/org/duniter/elasticsearch/templates/html_share.st b/cesium-plus-pod-core/src/main/resources/org/duniter/elasticsearch/templates/html_share.st index 1b03f96d40bad593c53154292ffc852d5e0c0658..01e9e84e265ada38a7b2109d7436fef7bbf937a9 100644 --- a/cesium-plus-pod-core/src/main/resources/org/duniter/elasticsearch/templates/html_share.st +++ b/cesium-plus-pod-core/src/main/resources/org/duniter/elasticsearch/templates/html_share.st @@ -47,12 +47,9 @@ html_share(type, title, summary, description, image, imageHeight, imageWidth, si $endif$ $if(redirectUrl)$ - <script type="text/javascript"> - window.location.href = "$redirectUrl$" + setTimeout("window.location.href=\"$redirectUrl$\";", 2000); </script> - <!--<META HTTP-EQUIV="Refresh" CONTENT="0; URL=$redirectUrl$"> - --> $endif$ </head> <body> diff --git a/cesium-plus-pod-core/src/test/es-home/config/elasticsearch.yml b/cesium-plus-pod-core/src/test/es-home/config/elasticsearch.yml index 9c61fdd5dcc47ba5e9c7a7efe5f1c3e1ff06ca4d..b39db5e6e021e2dc5f6992e6df2d024b3f3e00da 100644 --- a/cesium-plus-pod-core/src/test/es-home/config/elasticsearch.yml +++ b/cesium-plus-pod-core/src/test/es-home/config/elasticsearch.yml @@ -107,9 +107,9 @@ security.manager.enabled: false # # ---------------------------------- Duniter4j --------------------------------- # -# Disbale duniter4j plugin +# Enable duniter4j plugin (default: true) # -# duniter.enabled: false +# duniter.enable: false # # Reset and reload all Duniter4j data at startup - DO SET to true in production # diff --git a/cesium-plus-pod-subscription/src/main/java/org/duniter/elasticsearch/subscription/PluginSettings.java b/cesium-plus-pod-subscription/src/main/java/org/duniter/elasticsearch/subscription/PluginSettings.java index 4dd8d5d805e4823610c442380554067daf2a52b5..401fb9ca810d2faa80fc2467b96fd26a24d6a667 100644 --- a/cesium-plus-pod-subscription/src/main/java/org/duniter/elasticsearch/subscription/PluginSettings.java +++ b/cesium-plus-pod-subscription/src/main/java/org/duniter/elasticsearch/subscription/PluginSettings.java @@ -78,10 +78,19 @@ public class PluginSettings extends AbstractLifecycleComponent<PluginSettings> { return settings.getAsBoolean("duniter.subscription.enable", Boolean.TRUE); } + /** + * @deprecated use getEmailLinkUrl instead + * @return + */ + @Deprecated public String getCesiumUrl() { return this.settings.get("duniter.subscription.email.cesium.url", "https://g1.duniter.fr"); } + public String getEmailLinkUrl() { + return this.settings.get("duniter.subscription.email.link.url", getCesiumUrl()); + } + /** * Should email subscription be send at startup ? * @return diff --git a/cesium-plus-pod-user/src/main/java/org/duniter/elasticsearch/user/PluginSettings.java b/cesium-plus-pod-user/src/main/java/org/duniter/elasticsearch/user/PluginSettings.java index bfaf15151b99d5ddad942cbad75d3e25057e6339..f3b81354e66e6a0222f1d85076d381491d78fa3c 100644 --- a/cesium-plus-pod-user/src/main/java/org/duniter/elasticsearch/user/PluginSettings.java +++ b/cesium-plus-pod-user/src/main/java/org/duniter/elasticsearch/user/PluginSettings.java @@ -153,6 +153,22 @@ public class PluginSettings extends AbstractLifecycleComponent<PluginSettings> { return delegate.getClusterName(); } + public String getClusterRemoteHost() { + return delegate.getClusterRemoteHost(); + } + + public int getClusterRemotePort() { + return delegate.getClusterRemotePort(); + } + + public boolean getClusterRemoteUseSsl() { + return delegate.getClusterRemoteUseSsl(); + } + + public String getClusterRemoteUrlOrNull() { + return delegate.getClusterRemoteUrlOrNull(); + } + public String getNodeBmaHost() { return delegate.getNodeBmaHost(); } @@ -166,7 +182,7 @@ public class PluginSettings extends AbstractLifecycleComponent<PluginSettings> { } public boolean enableBlockchainSync() { - return delegate.enableBlockchainSync(); + return delegate.enableBlockchainIndexation(); } public String getKeyringSalt() { @@ -212,18 +228,42 @@ public class PluginSettings extends AbstractLifecycleComponent<PluginSettings> { return this.nodePubkey; } + /** + * @deprecated + * @return + */ + @Deprecated public String getCesiumUrl() { return this.settings.get("duniter.share.cesium.url", "https://g1.duniter.fr"); } + public String getSharePageLinkUrl() { + return this.settings.get("duniter.share.page.link.url", getCesiumUrl() + "#/app/page/view/{id}/{title}"); + } + public String getShareUserLinkUrl() { + return this.settings.get("duniter.share.user.link.url", getCesiumUrl() + "#/app/wot/{pubkey}/{title}"); + } + + public String getShareDefaultImageUrl() { + return this.settings.get("duniter.share.image.default.url", getCesiumUrl() + "/img/logo_200px.png"); + } + public String getShareSiteName() { - return this.settings.get("duniter.user.share.site.name", "Cesium"); + return this.settings.get("duniter.share.site.name", "Cesium"); } public String getShareBaseUrl() { return settings.get("duniter.share.base.url"); } + public boolean enableBlockchainUserEventIndexation() { + return delegate.enableBlockchainIndexation() && settings.getAsBoolean("duniter.blockchain.event.user.enable", true); + } + + public boolean enableBlockchainAdminEventIndexation() { + return delegate.enableBlockchainIndexation() && settings.getAsBoolean("duniter.blockchain.event.admin.enable", true); + } + /* -- protected methods -- */ protected String getI18nBundleName() { diff --git a/cesium-plus-pod-user/src/main/java/org/duniter/elasticsearch/user/rest/page/RestPageShareLinkAction.java b/cesium-plus-pod-user/src/main/java/org/duniter/elasticsearch/user/rest/page/RestPageShareLinkAction.java index 49385cf924df5d1aed059bcf799de15f958b0d7c..74366d051b19ace07ad0fb88c8a42f1b2ac45bdc 100644 --- a/cesium-plus-pod-user/src/main/java/org/duniter/elasticsearch/user/rest/page/RestPageShareLinkAction.java +++ b/cesium-plus-pod-user/src/main/java/org/duniter/elasticsearch/user/rest/page/RestPageShareLinkAction.java @@ -15,98 +15,93 @@ import org.duniter.elasticsearch.user.service.PageService; import org.duniter.elasticsearch.util.opengraph.OGData; import org.elasticsearch.client.Client; import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.rest.RestController; import org.nuiton.i18n.I18n; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; -public class RestPageShareLinkAction extends AbstractRestShareLinkAction { +public class RestPageShareLinkAction extends AbstractRestShareLinkAction implements AbstractRestShareLinkAction.OGDataResolver { + + private final PluginSettings pluginSettings; + private final PageService service; + @Inject - public RestPageShareLinkAction(final Settings settings, final RestController controller, final Client client, - final PluginSettings pluginSettings, + public RestPageShareLinkAction(final PluginSettings pluginSettings, final RestController controller, final Client client, final PageService service) { - super(settings, controller, client, PageIndexDao.INDEX, PageRecordDao.TYPE, - pluginSettings.getShareBaseUrl(), - createResolver(pluginSettings, service)); + super(pluginSettings.getDelegate(), controller, client, PageIndexDao.INDEX, PageRecordDao.TYPE); + setResolver(this); + this.pluginSettings = pluginSettings; + this.service = service; } - protected static OGDataResolver createResolver( - final PluginSettings pluginSettings, - final PageService service) throws DuniterElasticsearchException, BusinessException { - - return (id) -> { - try { - RegistryRecord record = service.getPageForSharing(id); - - OGData data = new OGData(); - - if (record != null) { - - // og:title - if (StringUtils.isNotBlank(record.getTitle())) { - data.title = record.getTitle(); - } - else { - data.title = pluginSettings.getShareSiteName(); - } - - // og:description - data.description = HtmlEscapers.htmlEscaper().escape(record.getDescription()); - - // og:image - if (record.getThumbnail() != null && StringUtils.isNotBlank(record.getThumbnail().get("_content_type"))) { - String baseUrl = pluginSettings.getShareBaseUrl(); - data.image = StringUtils.isBlank(baseUrl) ? "" : baseUrl; - data.image += RestImageAttachmentAction.computeImageUrl(PageIndexDao.INDEX, PageRecordDao.TYPE, id, RegistryRecord.PROPERTY_THUMBNAIL, record.getThumbnail().get("_content_type")); - - // FIXME : use a greater image ? at least 200px x 200px for FaceBook - data.imageHeight = 100; - data.imageWidth = 100; - } - - // og:url - data.url = String.format("%s/#/app/page/view/%s/%s", - pluginSettings.getCesiumUrl(), - id, - URLEncoder.encode(record.getTitle(), "UTF-8")); - } - else { + @Override + public OGData resolve(final String id) throws DuniterElasticsearchException, BusinessException { + try { + RegistryRecord record = service.getPageForSharing(id); - // og:title - data.title = pluginSettings.getShareSiteName(); + OGData data = new OGData(); - // og:description - data.description = I18n.t("duniter.user.share.description"); + if (record != null) { - // og:url - data.url = String.format("%s/#/app/page/view/%s/%s", - pluginSettings.getCesiumUrl(), - id, - ""); + // og:title + if (StringUtils.isNotBlank(record.getTitle())) { + data.title = record.getTitle(); + } + else { + data.title = pluginSettings.getShareSiteName(); } - // og:type - data.type = "website"; - - // og:site_name - data.siteName = pluginSettings.getShareSiteName(); + // og:description + data.description = HtmlEscapers.htmlEscaper().escape(record.getDescription()); - // default og:image - if (StringUtils.isBlank(data.image)) { - data.image = pluginSettings.getCesiumUrl() + "/img/logo_200px.png"; - data.imageType = "image/png"; + // og:image + if (record.getThumbnail() != null && StringUtils.isNotBlank(record.getThumbnail().get("_content_type"))) { + String baseUrl = pluginSettings.getClusterRemoteUrlOrNull(); + data.image = StringUtils.isBlank(baseUrl) ? "" : baseUrl; + data.image += RestImageAttachmentAction.computeImageUrl(PageIndexDao.INDEX, PageRecordDao.TYPE, id, RegistryRecord.PROPERTY_THUMBNAIL, record.getThumbnail().get("_content_type")); data.imageHeight = 200; data.imageWidth = 200; } - return data; + // og:url + data.url = pluginSettings.getSharePageLinkUrl() + .replace("{id}", id) + .replace("{title}", URLEncoder.encode(record.getTitle(), "UTF-8")); } - catch(UnsupportedEncodingException e) { - throw new TechnicalException(e); + else { + + // og:title + data.title = pluginSettings.getShareSiteName(); + + // og:description + data.description = I18n.t("duniter.user.share.description"); + + // og:url + data.url = pluginSettings.getSharePageLinkUrl() + .replace("{id}", id) + .replace("{title}", ""); + } + + // og:type + data.type = "website"; + + // og:site_name + data.siteName = pluginSettings.getShareSiteName(); + + // default og:image + if (StringUtils.isBlank(data.image)) { + data.image = pluginSettings.getShareDefaultImageUrl(); + data.imageType = "image/png"; + data.imageHeight = 200; + data.imageWidth = 200; } - }; + + return data; + } + catch(UnsupportedEncodingException e) { + throw new TechnicalException(e); + } } } diff --git a/cesium-plus-pod-user/src/main/java/org/duniter/elasticsearch/user/rest/user/RestUserShareLinkAction.java b/cesium-plus-pod-user/src/main/java/org/duniter/elasticsearch/user/rest/user/RestUserShareLinkAction.java index 7a4775207e80be76f665ed97b3e743c2419a9072..ccee548898b444916d8ddf2cbe91e7cb5fe2604a 100644 --- a/cesium-plus-pod-user/src/main/java/org/duniter/elasticsearch/user/rest/user/RestUserShareLinkAction.java +++ b/cesium-plus-pod-user/src/main/java/org/duniter/elasticsearch/user/rest/user/RestUserShareLinkAction.java @@ -13,7 +13,6 @@ import org.duniter.elasticsearch.user.service.UserService; import org.duniter.elasticsearch.util.opengraph.OGData; import org.elasticsearch.client.Client; import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.rest.RestController; import org.nuiton.i18n.I18n; @@ -21,115 +20,112 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.Locale; -public class RestUserShareLinkAction extends AbstractRestShareLinkAction { +public class RestUserShareLinkAction extends AbstractRestShareLinkAction implements AbstractRestShareLinkAction.OGDataResolver{ + + private PluginSettings pluginSettings; + private UserService userService; @Inject - public RestUserShareLinkAction(final Settings settings, final RestController controller, final Client client, - final PluginSettings pluginSettings, + public RestUserShareLinkAction(final PluginSettings pluginSettings, final RestController controller, final Client client, final UserService userService) { - super(settings, controller, client, UserService.INDEX, UserService.PROFILE_TYPE, - pluginSettings.getShareBaseUrl(), - createResolver(pluginSettings, userService)); + super(pluginSettings.getDelegate(), controller, client, UserService.INDEX, UserService.PROFILE_TYPE); + setResolver(this); - if (StringUtils.isBlank(pluginSettings.getShareBaseUrl())) { - log.warn(I18n.t("duniter4j.es.share.error.noBaseUrl", "duniter.share.base.url")); + if (StringUtils.isBlank(pluginSettings.getClusterRemoteUrlOrNull())) { + log.warn(I18n.t("duniter4j.es.share.error.noRemoteUrl")); } + this.pluginSettings = pluginSettings; + this.userService = userService; } - protected static AbstractRestShareLinkAction.OGDataResolver createResolver( - final PluginSettings pluginSettings, - final UserService userService) throws DuniterElasticsearchException, BusinessException { - - return (id) -> { - try { - UserProfile profile = userService.getUserProfileForSharing(id); - - OGData data = new OGData(); - - if (profile != null) { - - // og:locale - Locale locale; - if (StringUtils.isNotBlank(profile.getLocale())) { - locale = new Locale(profile.getLocale()); - data.locale = profile.getLocale(); - } - else { - locale = I18n.getDefaultLocale(); - } - data.locale = locale.toString(); - - String pubkey = I18n.l(locale, "duniter.user.share.pubkey", id); - - // og:title - if (StringUtils.isNotBlank(profile.getTitle())) { - data.title = profile.getTitle(); - data.description = pubkey; - } - else { - data.title = pubkey; - data.description = ""; - } - - // og:description - if (StringUtils.isNotBlank(data.description)) data.description += " | "; - if (StringUtils.isNotBlank(profile.getDescription())) { - data.description += HtmlEscapers.htmlEscaper().escape(profile.getDescription()); - } - else { - data.description += I18n.l(locale, "duniter.user.share.description"); - } - - // og:image - if (profile.getAvatar() != null && StringUtils.isNotBlank(profile.getAvatar().getContentType())) { - String baseUrl = pluginSettings.getShareBaseUrl(); - data.image = StringUtils.isBlank(baseUrl) ? "" : baseUrl; - data.image += RestImageAttachmentAction.computeImageUrl(UserService.INDEX, UserService.PROFILE_TYPE, id, UserProfile.PROPERTY_AVATAR, profile.getAvatar().getContentType()); - data.imageHeight = 100; - data.imageWidth = 100; - } - - // og:url - data.url = String.format("%s/#/app/wot/%s/%s", - pluginSettings.getCesiumUrl(), - id, - URLEncoder.encode(profile.getTitle(), "UTF-8")); - } - else { + @Override + public OGData resolve(String id) throws DuniterElasticsearchException, BusinessException { + try { + UserProfile profile = userService.getUserProfileForSharing(id); - // og:title - String pubkey = I18n.t("duniter.user.share.pubkey", id); - data.title = pubkey; + OGData data = new OGData(); - // og:description - data.description = I18n.t("duniter.user.share.description"); + if (profile != null) { - // og:url - data.url = String.format("%s/#/app/wot/%s/%s", - pluginSettings.getCesiumUrl(), - id, - ""); + // og:locale + Locale locale; + if (StringUtils.isNotBlank(profile.getLocale())) { + locale = new Locale(profile.getLocale()); + data.locale = profile.getLocale(); } + else { + locale = I18n.getDefaultLocale(); + } + data.locale = locale.toString(); - // og:type - data.type = "website"; + String pubkeyMessage = I18n.l(locale, "duniter.user.share.pubkey", id); - // og:site_name - data.siteName = pluginSettings.getShareSiteName(); + // og:title + if (StringUtils.isNotBlank(profile.getTitle())) { + data.title = profile.getTitle(); + data.description = pubkeyMessage; + } + else { + data.title = pubkeyMessage; + data.description = ""; + } + + // og:description + if (StringUtils.isNotBlank(data.description)) data.description += " | "; + if (StringUtils.isNotBlank(profile.getDescription())) { + data.description += HtmlEscapers.htmlEscaper().escape(profile.getDescription()); + } + else { + data.description += I18n.l(locale, "duniter.user.share.description"); + } - // default og:image - if (StringUtils.isBlank(data.image)) { - data.image = pluginSettings.getCesiumUrl() + "/img/logo_200px.png"; - data.imageType = "image/png"; - data.imageHeight = 200; + // og:image + if (profile.getAvatar() != null && StringUtils.isNotBlank(profile.getAvatar().getContentType())) { + String baseUrl = pluginSettings.getClusterRemoteUrlOrNull(); + data.image = StringUtils.isBlank(baseUrl) ? "" : baseUrl; + data.image += RestImageAttachmentAction.computeImageUrl(UserService.INDEX, UserService.PROFILE_TYPE, pubkeyMessage, UserProfile.PROPERTY_AVATAR, profile.getAvatar().getContentType()); + data.imageHeight = 200; // min size for Facebook data.imageWidth = 200; } - return data; + // og:url + data.url = pluginSettings.getShareUserLinkUrl() + .replace("{pubkey}", id) + .replace("{title}", URLEncoder.encode(profile.getTitle(), "UTF-8")); } - catch(UnsupportedEncodingException e) { - throw new TechnicalException(e); + else { + + // og:title + String pubkeyMessage = I18n.t("duniter.user.share.pubkey", id); + data.title = pubkeyMessage; + + // og:description + data.description = I18n.t("duniter.user.share.description"); + + // og:url + data.url = pluginSettings.getShareUserLinkUrl() + .replace("{pubkey}", id) + .replace("{title}", ""); } - }; + + // og:type + data.type = "website"; + + // og:site_name + data.siteName = pluginSettings.getShareSiteName(); + + // default og:image + if (StringUtils.isBlank(data.image)) { + data.image = pluginSettings.getShareDefaultImageUrl(); + data.imageType = "image/png"; + data.imageHeight = 200; + data.imageWidth = 200; + } + + return data; + } + catch(UnsupportedEncodingException e) { + throw new TechnicalException(e); + } } } diff --git a/cesium-plus-pod-user/src/main/java/org/duniter/elasticsearch/user/service/BlockchainUserEventService.java b/cesium-plus-pod-user/src/main/java/org/duniter/elasticsearch/user/service/BlockchainUserEventService.java index b510b8391bab992cf62b940a21ab5a66bc1d5967..d80732cb115d6babb026721df5379d85bf156c6b 100644 --- a/cesium-plus-pod-user/src/main/java/org/duniter/elasticsearch/user/service/BlockchainUserEventService.java +++ b/cesium-plus-pod-user/src/main/java/org/duniter/elasticsearch/user/service/BlockchainUserEventService.java @@ -58,19 +58,21 @@ public class BlockchainUserEventService extends AbstractBlockchainListenerServic private final AdminService adminService; @Inject - public BlockchainUserEventService(Duniter4jClient client, PluginSettings settings, CryptoService cryptoService, + public BlockchainUserEventService(Duniter4jClient client, PluginSettings pluginSettings, CryptoService cryptoService, ThreadPool threadPool, BlockchainService blockchainService, UserService userService, AdminService adminService, UserEventService userEventService) { - super("duniter.user.event.blockchain", client, settings.getDelegate(), cryptoService, threadPool, - new TimeValue(500, TimeUnit.MILLISECONDS)); + super("duniter.user.event.blockchain", client, pluginSettings.getDelegate(), cryptoService, threadPool, + new TimeValue(500, TimeUnit.MILLISECONDS), + pluginSettings.enableBlockchainUserEventIndexation()); this.userService = userService; this.adminService = adminService; this.userEventService = userEventService; - if (this.enable) { + // Should notify admin when connection to node is DOWN ? + if (pluginSettings.enableBlockchainAdminEventIndexation()) { blockchainService.registerConnectionListener(createConnectionListeners()); } } diff --git a/cesium-plus-pod-user/src/main/resources/i18n/cesium-plus-pod-user_en_GB.properties b/cesium-plus-pod-user/src/main/resources/i18n/cesium-plus-pod-user_en_GB.properties index 3c47a593117794059ed2628a702289ef4d3798b0..83e90ba4c848a6b22e752ca1d8fa96e1cb2de416 100644 --- a/cesium-plus-pod-user/src/main/resources/i18n/cesium-plus-pod-user_en_GB.properties +++ b/cesium-plus-pod-user/src/main/resources/i18n/cesium-plus-pod-user_en_GB.properties @@ -18,4 +18,5 @@ duniter.user.event.TX_SENT=Your payment to %2$s was executed. duniter.user.share.description=Follow your "libre money" wallets easily duniter.user.share.pubkey=Public key\: %1$s duniter4j.es.share.error.noBaseUrl=Image path are relative for share links (og\:image). /\!\\ Set [%s] in the configuration (recommended). +duniter4j.es.share.error.noRemoteUrl= duniter4j.ws.user.open=User [%1$s] connecting with id [%2$s] with locale [%3$s] diff --git a/cesium-plus-pod-user/src/main/resources/i18n/cesium-plus-pod-user_fr_FR.properties b/cesium-plus-pod-user/src/main/resources/i18n/cesium-plus-pod-user_fr_FR.properties index ec9ace345c37859ec4eebeece40f906bd7d5233d..f106b9c2f6aedc988e438db788686d9ee9251dee 100644 --- a/cesium-plus-pod-user/src/main/resources/i18n/cesium-plus-pod-user_fr_FR.properties +++ b/cesium-plus-pod-user/src/main/resources/i18n/cesium-plus-pod-user_fr_FR.properties @@ -17,5 +17,5 @@ duniter.user.event.TX_RECEIVED=Vous avez recu un paiement de %2$s. duniter.user.event.TX_SENT=Votre paiement à %2$s a bien été executé. duniter.user.share.description=Suivez vos comptes de monnaie libre en toute simplicité \! duniter.user.share.pubkey=Clé publique \: %1$s -duniter4j.es.share.error.noBaseUrl=Chemins relatif pour les images, dans les partages (og\:image). /\!\\ Renseignez [%s] dans la configuration (conseillé). +duniter4j.es.share.error.noRemoteUrl=Chemins relatif pour les images, dans les partages (og\:image). /\!\\ Renseignez les options [cluster.remote.xxx] dans la configuration (conseillé). duniter4j.ws.user.open=Utilisateur [%1$s] connecté id\=[%2$s] sur la locale [%3$s] diff --git a/pom.xml b/pom.xml index 64ca0213f3ca767269abb4dfcf8fb5ddede99cb3..004536de84daf4a8677a275d93308f1fb6a16f91 100644 --- a/pom.xml +++ b/pom.xml @@ -149,15 +149,15 @@ </modules> <scm> - <url>https://github.com/duniter/duniter4j.git</url> - <connection>scm:git:https://github.com/duniter/duniter4j.git</connection> - <developerConnection>scm:git:https://github.com/duniter/duniter4j.git</developerConnection> + <url>https://git.duniter.org/clients/cesium-grp/cesium-plus-pod.git</url> + <connection>scm:git:https://git.duniter.org/clients/cesium-grp/cesium-plus-pod.git</connection> + <developerConnection>scm:git:https://git.duniter.org/clients/cesium-grp/cesium-plus-pod.git</developerConnection> <tag>HEAD</tag> </scm> <issueManagement> - <system>GitHub</system> - <url>https://github.com/duniter/duniter4j/issues</url> + <system>Gitlab</system> + <url>https://git.duniter.org/clients/cesium-grp/cesium-plus-pod/issues</url> </issueManagement> <dependencyManagement>