Skip to content

Commit

Permalink
GROW-1236 implementation of the basic functionality of the contributo…
Browse files Browse the repository at this point in the history
…rs portlet

Co-authored-by: bakayattila <[email protected]>
  • Loading branch information
2 people authored and hudakl committed Jul 10, 2020
1 parent 28de3f5 commit 08bd335
Show file tree
Hide file tree
Showing 5 changed files with 244 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library 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 Lesser General Public License for more
* details.
*/

package com.liferay.grow.journal.contributors.web;

import com.liferay.asset.display.page.constants.AssetDisplayPageWebKeys;
import com.liferay.asset.kernel.model.AssetEntry;
import com.liferay.asset.kernel.service.AssetEntryLocalServiceUtil;
import com.liferay.grow.journal.contributors.web.dto.Contributor;
import com.liferay.info.display.contributor.InfoDisplayObjectProvider;
import com.liferay.journal.constants.JournalPortletKeys;
import com.liferay.journal.model.JournalArticle;
import com.liferay.journal.service.JournalArticleLocalServiceUtil;
import com.liferay.petra.string.StringBundler;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.model.Group;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.service.GroupLocalServiceUtil;
import com.liferay.portal.kernel.service.UserLocalServiceUtil;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.MapUtil;
import com.liferay.portal.kernel.util.PortalUtil;
import com.liferay.portal.kernel.util.PrefsPropsUtil;
import com.liferay.portal.kernel.util.WebKeys;

import java.text.DateFormat;
import java.text.SimpleDateFormat;

import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.portlet.PortletRequest;
import javax.portlet.PortletURL;

import javax.servlet.http.HttpServletRequest;

/**
* @author Balázs Sáfrány-Kovalik
*/
public class JournalContributorsDisplayContext {

public JournalContributorsDisplayContext(
HttpServletRequest httpServletRequest) {

_httpServletRequest = httpServletRequest;

InfoDisplayObjectProvider infoDisplayObjectProvider =
(InfoDisplayObjectProvider)httpServletRequest.getAttribute(
AssetDisplayPageWebKeys.INFO_DISPLAY_OBJECT_PROVIDER);

if (infoDisplayObjectProvider != null) {
_journalArticle =
(JournalArticle)infoDisplayObjectProvider.getDisplayObject();

_assetEntry = AssetEntryLocalServiceUtil.fetchEntry(
JournalArticle.class.getName(),
_journalArticle.getResourcePrimKey());
}

_initContributors();
}

public String getCreateDate() {
DateFormat dateFormat = new SimpleDateFormat("MMM d, yyyy");

if (_journalArticle == null) {
return dateFormat.format(new Date());
}

return dateFormat.format(_journalArticle.getCreateDate());
}

public Contributor getCreator() {
if (_journalArticle == null) {
return _contributors.get(0L);
}

return _contributors.get(_journalArticle.getUserId());
}

public String getModifiedDate() {
DateFormat dateFormat = new SimpleDateFormat("MMM d, yyyy");

if (_journalArticle == null) {
return dateFormat.format(new Date());
}

return dateFormat.format(_journalArticle.getModifiedDate());
}

public Contributor getModifier() {
if (_journalArticle == null) {
return _contributors.get(1L);
}

return _contributors.get(_journalArticle.getStatusByUserId());
}

private Contributor _createContributor(long userId) {
User user = UserLocalServiceUtil.fetchUser(userId);
String fullName = "Missing User";

if (user != null) {
fullName = user.getFullName();
}

return new Contributor(fullName);
}

private void _initContributors() {
_contributors = new HashMap<>();

if (_journalArticle == null) {
_contributors.put(
0L,
new Contributor(
"Creator Place Holder"));
_contributors.put(
1L,
new Contributor(
"Modifier Place Holder"));

} else {
List<JournalArticle> journalArticles =
JournalArticleLocalServiceUtil.getArticlesByResourcePrimKey(
_journalArticle.getResourcePrimKey());

for (JournalArticle version : journalArticles) {
long userId = version.getStatusByUserId();

Contributor contributor = _contributors.get(userId);

if (contributor == null) {
contributor = _createContributor(userId);

_contributors.put(userId, contributor);
}
}
}
}

private AssetEntry _assetEntry;
private String _baseUrl;
private Map<Long, Contributor> _contributors;
private HttpServletRequest _httpServletRequest;
private JournalArticle _journalArticle;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library 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 Lesser General Public License for more
* details.
*/

package com.liferay.grow.journal.contributors.web.dto;

/**
* @author Balázs Sáfrány-Kovalik
*/
public class Contributor {

public Contributor(String name) {
_name = name;
}

public String getName() {
return _name;
}

private String _name;


}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@
immediate = true,
property = {
"com.liferay.portlet.display-category=category.sample",
"com.liferay.portlet.header-portlet-css=/css/main.css",
"com.liferay.portlet.instanceable=true",
"javax.portlet.display-name=JournalContributors",
"javax.portlet.init-param.template-path=/",
"javax.portlet.init-param.view-template=/view.jsp",
"javax.portlet.name=" + JournalContributorsPortletKeys.JOURNAL_CONTRIBUTORS,
"javax.portlet.resource-bundle=content.Language",
"javax.portlet.security-role-ref=power-user,user"
},
service = Portlet.class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %><%@
taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %><%@
taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>

<%@ page import="com.liferay.grow.journal.contributors.web.JournalContributorsDisplayContext" %><%@
page import="com.liferay.grow.journal.contributors.web.dto.Contributor" %>
<liferay-theme:defineObjects />
<portlet:defineObjects />
<portlet:defineObjects />
<%
JournalContributorsDisplayContext journalContributorsDisplayContext = new JournalContributorsDisplayContext(request);
Contributor creatorContributor = journalContributorsDisplayContext.getCreator();
Contributor modifierContributor = journalContributorsDisplayContext.getModifier();
%> >
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,43 @@

<%@ include file="/init.jsp" %>

<p>
<b><liferay-ui:message key="journalcontributors.caption"/></b>
</p>
<nav class="a-items">
<input class="activate hidden" id="contributors" name="contributors" type="checkbox" />

<label class="accordion-label" for="contributors">Contributors</label>

<div class="a-content sbox">
<ul class="list-unstyled">

<li>
<table class="contributors-table">
<c:if test="<%= modifierContributor != null %>">
<tr>
<td>
<span class="glyphicon glyphicon-user"></span>
Updated by <%= modifierContributor.getName() %>
</td>
<td class="last-td">
<span class="glyphicon glyphicon-calendar"></span>
<%= journalContributorsDisplayContext.getModifiedDate() %>
</td>
</tr>
</c:if>

<c:if test="<%= creatorContributor != null %>">
<tr>
<td>
<span class="glyphicon glyphicon-user"></span>
Creator: <%= creatorContributor.getName() %>
</td>
<td class="last-td">
<span class="glyphicon glyphicon-calendar"> </span>
<%= journalContributorsDisplayContext.getCreateDate() %>
</td>
</tr>
</c:if>
</table>
</li>
</ul>
</div>
</nav>

0 comments on commit 08bd335

Please sign in to comment.