diff --git a/duniter4j-es-core/src/license/THIRD-PARTY.properties b/duniter4j-es-core/src/license/THIRD-PARTY.properties new file mode 100644 index 0000000000000000000000000000000000000000..10a89e2bcaf4082c40f141057fa9e10147c47390 --- /dev/null +++ b/duniter4j-es-core/src/license/THIRD-PARTY.properties @@ -0,0 +1,35 @@ +# Generated by org.codehaus.mojo.license.AddThirdPartyMojo +#------------------------------------------------------------------------------- +# Already used licenses in project : +# - ASL, version 2 +# - Apache 2.0 +# - Apache License 2.0 +# - Apache License Version 2.0 +# - BSD License +# - BSD licence +# - CC0 1.0 Universal +# - CDDL +# - CDDL+GPL +# - COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 +# - Common Development and Distribution License (CDDL) v1.0 +# - Dual license consisting of the CDDL v1.1 and GPL v2 +# - Eclipse Public License 1.0 +# - GPLv2+CE +# - General Public License (GPL) v3 +# - Indiana University Extreme! Lab Software License, vesion 1.1.1 +# - LGPL, version 2.1 +# - Lesser General Public License (LGPL) v 3.0 +# - Lesser General Public License (LPGL) +# - Lesser General Public License (LPGL) v 2.1 +# - Lesser General Public License (LPGL) version 3.0 +# - MIT License +# - New BSD License +# - Public Domain, per Creative Commons CC0 +# - The Apache Software License, Version 2.0 +#------------------------------------------------------------------------------- +# Please fill the missing licenses for dependencies : +# +# +#Fri May 18 18:26:32 CEST 2018 +commons-primitives--commons-primitives--1.0=The Apache Software License, Version 2.0 +org.antlr--antlr-runtime--3.3=BSD License 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 a0f394a8d60a34a59338e623d34d450dfec462da..1ba958a01aa2cb149ad08837ee8801e63e0ef893 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 @@ -261,6 +261,10 @@ public class PluginSettings extends AbstractLifecycleComponent { return settings.getAsInt("duniter.retry.waitDuration", 5000); } + public String getShareBaseUrl() { + return settings.get("duniter.share.base.url"); + } + public Peer checkAndGetPeer() { if (StringUtils.isBlank(getNodeBmaHost())) { logger.error("ERROR: node host is required"); diff --git a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/rest/share/AbstractRestShareLinkAction.java b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/rest/share/AbstractRestShareLinkAction.java index ff97fada10df8a93d416f847e86196295e3c881b..6dd3dd5a8d41c80a6aa9b6733b45de31e1c575e9 100644 --- a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/rest/share/AbstractRestShareLinkAction.java +++ b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/rest/share/AbstractRestShareLinkAction.java @@ -14,7 +14,8 @@ import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.rest.*; import org.nuiton.i18n.I18n; -import org.stringtemplate.v4.*; +import org.stringtemplate.v4.ST; +import org.stringtemplate.v4.STGroup; import java.util.Locale; @@ -31,23 +32,27 @@ public abstract class AbstractRestShareLinkAction extends BaseRestHandler { private OGDataResolver resolver; private STGroup templates; + private String urlPattern; public AbstractRestShareLinkAction(Settings settings, RestController controller, Client client, String indexName, String typeName, + String shareBaseUrl, OGDataResolver resolver ) { super(settings, controller, client); log = Loggers.getLogger("duniter.rest." + indexName, settings, String.format("[%s]", indexName)); + + String pathPattern = String.format("/%s/%s/%s/_share", indexName, typeName, "%s"); controller.registerHandler(GET, - String.format("/%s/%s/{id}/_share", indexName, typeName), + String.format(pathPattern, "{id}"), this); + this.urlPattern = (shareBaseUrl != null ? shareBaseUrl : "") + pathPattern; this.resolver = resolver; // 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"); - } @Override @@ -68,8 +73,11 @@ public abstract class AbstractRestShareLinkAction extends BaseRestHandler { template.add("description", data.description); template.add("siteName", data.siteName); template.add("image", data.image); - template.add("url", data.url); + template.add("url", String.format(urlPattern, id)); + template.add("redirectUrl", data.url); template.add("locale", data.locale); + template.add("imageHeight", data.imageHeight); + template.add("imageWidth", data.imageWidth); if (StringUtils.isNotBlank(data.url)) { Locale locale = data.locale != null ? new Locale(data.locale) : I18n.getDefaultLocale(); template.add("redirectMessage", I18n.l(locale, "duniter4j.share.redirection.help")); diff --git a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/util/opengraph/OGData.java b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/util/opengraph/OGData.java index 0530ead6288cd913cacb01fc7fc11883688e864b..655e14603d4fc75452a72fbbe9cde1cb10b5a4a5 100644 --- a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/util/opengraph/OGData.java +++ b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/util/opengraph/OGData.java @@ -10,4 +10,7 @@ public class OGData { public String imageType; public String siteName; + public Integer imageHeight; + public Integer imageWidth; + } diff --git a/duniter4j-es-core/src/main/resources/org/duniter/elasticsearch/templates/html_share.st b/duniter4j-es-core/src/main/resources/org/duniter/elasticsearch/templates/html_share.st index 664245e3511d95a8b6d5d74c8825c691e38b178d..1b03f96d40bad593c53154292ffc852d5e0c0658 100644 --- a/duniter4j-es-core/src/main/resources/org/duniter/elasticsearch/templates/html_share.st +++ b/duniter4j-es-core/src/main/resources/org/duniter/elasticsearch/templates/html_share.st @@ -1,4 +1,5 @@ -html_share(type, title, summary, description, image, siteName, locale, url, redirectMessage) ::= << +html_share(type, title, summary, description, image, imageHeight, imageWidth, siteName, locale, url, redirectUrl, redirectMessage) ::= << + @@ -30,17 +31,28 @@ html_share(type, title, summary, description, image, siteName, locale, url, redi $if(image)$ $endif$ + $if(imageHeight)$ + + $endif$ + $if(imageWidth)$ + + $endif$ $if(locale)$ $endif$ $if(url)$ - + + $endif$ + + $if(redirectUrl)$ + - + $endif$ @@ -54,9 +66,9 @@ html_share(type, title, summary, description, image, siteName, locale, url, redi

$description$

- $if(url)$ + $if(redirectUrl)$

- $redirectMessage$ $title$. + $redirectMessage$ $title$.

$endif$ diff --git a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/PluginSettings.java b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/PluginSettings.java index e640a389057facdda36a00115d2cbe8fbc794f7a..152034a27f4b0a98fd702e965ca11eca076f152a 100644 --- a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/PluginSettings.java +++ b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/PluginSettings.java @@ -220,7 +220,7 @@ public class PluginSettings extends AbstractLifecycleComponent { return this.settings.get("duniter.user.share.site.name", "Cesium"); } - public String getBaseUrl() { + public String getShareBaseUrl() { return settings.get("duniter.share.base.url"); } diff --git a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/rest/page/RestPageShareLinkAction.java b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/rest/page/RestPageShareLinkAction.java index ecd1c817499ab22f60f370ff4ba7e231ba7da755..49385cf924df5d1aed059bcf799de15f958b0d7c 100644 --- a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/rest/page/RestPageShareLinkAction.java +++ b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/rest/page/RestPageShareLinkAction.java @@ -10,10 +10,8 @@ import org.duniter.elasticsearch.rest.share.AbstractRestShareLinkAction; import org.duniter.elasticsearch.user.PluginSettings; import org.duniter.elasticsearch.user.dao.page.PageIndexDao; import org.duniter.elasticsearch.user.dao.page.PageRecordDao; -import org.duniter.elasticsearch.user.model.UserProfile; import org.duniter.elasticsearch.user.model.page.RegistryRecord; import org.duniter.elasticsearch.user.service.PageService; -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; @@ -23,7 +21,6 @@ import org.nuiton.i18n.I18n; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; -import java.util.Locale; public class RestPageShareLinkAction extends AbstractRestShareLinkAction { @@ -32,6 +29,7 @@ public class RestPageShareLinkAction extends AbstractRestShareLinkAction { final PluginSettings pluginSettings, final PageService service) { super(settings, controller, client, PageIndexDao.INDEX, PageRecordDao.TYPE, + pluginSettings.getShareBaseUrl(), createResolver(pluginSettings, service)); } @@ -60,9 +58,13 @@ public class RestPageShareLinkAction extends AbstractRestShareLinkAction { // og:image if (record.getThumbnail() != null && StringUtils.isNotBlank(record.getThumbnail().get("_content_type"))) { - String baseUrl = pluginSettings.getBaseUrl(); + 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 @@ -94,8 +96,10 @@ public class RestPageShareLinkAction extends AbstractRestShareLinkAction { // default og:image if (StringUtils.isBlank(data.image)) { - data.image = pluginSettings.getCesiumUrl() + "/img/logo_128px.png"; + data.image = pluginSettings.getCesiumUrl() + "/img/logo_200px.png"; data.imageType = "image/png"; + data.imageHeight = 200; + data.imageWidth = 200; } return data; diff --git a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/rest/user/RestUserShareLinkAction.java b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/rest/user/RestUserShareLinkAction.java index 540e6e4e0fcdf07c324b0b6a248d078763e7b2c2..7a4775207e80be76f665ed97b3e743c2419a9072 100644 --- a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/rest/user/RestUserShareLinkAction.java +++ b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/rest/user/RestUserShareLinkAction.java @@ -1,6 +1,5 @@ package org.duniter.elasticsearch.user.rest.user; -import com.google.common.collect.Maps; import com.google.common.html.HtmlEscapers; import org.duniter.core.exception.BusinessException; import org.duniter.core.exception.TechnicalException; @@ -29,9 +28,10 @@ public class RestUserShareLinkAction extends AbstractRestShareLinkAction { final PluginSettings pluginSettings, final UserService userService) { super(settings, controller, client, UserService.INDEX, UserService.PROFILE_TYPE, + pluginSettings.getShareBaseUrl(), createResolver(pluginSettings, userService)); - if (StringUtils.isBlank(pluginSettings.getBaseUrl())) { + if (StringUtils.isBlank(pluginSettings.getShareBaseUrl())) { log.warn(I18n.t("duniter4j.es.share.error.noBaseUrl", "duniter.share.base.url")); } } @@ -57,6 +57,7 @@ public class RestUserShareLinkAction extends AbstractRestShareLinkAction { else { locale = I18n.getDefaultLocale(); } + data.locale = locale.toString(); String pubkey = I18n.l(locale, "duniter.user.share.pubkey", id); @@ -81,9 +82,11 @@ public class RestUserShareLinkAction extends AbstractRestShareLinkAction { // og:image if (profile.getAvatar() != null && StringUtils.isNotBlank(profile.getAvatar().getContentType())) { - String baseUrl = pluginSettings.getBaseUrl(); + 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 @@ -116,8 +119,10 @@ public class RestUserShareLinkAction extends AbstractRestShareLinkAction { // default og:image if (StringUtils.isBlank(data.image)) { - data.image = pluginSettings.getCesiumUrl() + "/img/logo_128px.png"; + data.image = pluginSettings.getCesiumUrl() + "/img/logo_200px.png"; data.imageType = "image/png"; + data.imageHeight = 200; + data.imageWidth = 200; } return data;