Skip to content

Commit

Permalink
LPS-128194 Prepare JSON to return and empty author when the informati…
Browse files Browse the repository at this point in the history
…on of the author is empty.
  • Loading branch information
cgoncas committed Mar 2, 2021
1 parent 8428a97 commit c92b53f
Showing 1 changed file with 29 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.liferay.analytics.reports.web.internal.model.TimeSpan;
import com.liferay.info.item.InfoItemReference;
import com.liferay.info.item.InfoItemServiceTracker;
import com.liferay.info.type.WebImage;
import com.liferay.layout.display.page.LayoutDisplayPageProviderTracker;
import com.liferay.layout.seo.kernel.LayoutSEOLinkManager;
import com.liferay.portal.kernel.exception.NoSuchModelException;
Expand Down Expand Up @@ -158,24 +157,35 @@ private JSONObject _getAuthorJSONObject(
AnalyticsReportsInfoItem<Object> analyticsReportsInfoItem,
Locale locale, Object object) {

String authorProfileImage = null;

WebImage webImage = analyticsReportsInfoItem.getAuthorWebImage(
object, locale);

long portraitId = GetterUtil.getLong(
_http.getParameter(HtmlUtil.escape(webImage.getUrl()), "img_id"));

if (portraitId > 0) {
authorProfileImage = webImage.getUrl();
}

return JSONUtil.put(
"authorId", analyticsReportsInfoItem.getAuthorUserId(object)
).put(
"name", analyticsReportsInfoItem.getAuthorName(object)
).put(
"url", authorProfileImage
return Optional.ofNullable(
analyticsReportsInfoItem.getAuthorWebImage(object, locale)
).filter(
webImage -> Validator.isNotNull(webImage.getUrl())
).map(
webImage -> {
long portraitId = GetterUtil.getLong(
_http.getParameter(
HtmlUtil.escape(webImage.getUrl()), "img_id"));

if (portraitId > 0) {
return JSONUtil.put(
"authorId",
analyticsReportsInfoItem.getAuthorUserId(object)
).put(
"name", analyticsReportsInfoItem.getAuthorName(object)
).put(
"url", webImage.getUrl()
);
}

return JSONUtil.put(
"authorId", analyticsReportsInfoItem.getAuthorUserId(object)
).put(
"name", analyticsReportsInfoItem.getAuthorName(object)
);
}
).orElse(
null
);
}

Expand Down

0 comments on commit c92b53f

Please sign in to comment.