-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GROW-1236 implementation of the basic functionality of the contributo…
…rs portlet Co-authored-by: bakayattila <[email protected]>
- Loading branch information
Showing
5 changed files
with
244 additions
and
6 deletions.
There are no files selected for viewing
162 changes: 162 additions & 0 deletions
162
...ain/java/com/liferay/grow/journal/contributors/web/JournalContributorsDisplayContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
...ributors-web/src/main/java/com/liferay/grow/journal/contributors/web/dto/Contributor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters