forked from liferay/liferay-portal
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
15837d7
commit e07a8fb
Showing
62 changed files
with
1,006 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
11 changes: 11 additions & 0 deletions
11
modules/apps/asset/asset-vocabularies-selector-web/bnd.bnd
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,11 @@ | ||
Bundle-Name: Liferay Asset Vocabularies Selector Web | ||
Bundle-SymbolicName: com.liferay.asset.vocabularies.selector.web | ||
Bundle-Version: 3.0.0 | ||
Provide-Capability:\ | ||
soy;\ | ||
type="asset-vocabularies-selector-web";\ | ||
version:Version="${Bundle-Version}" | ||
Require-Capability:\ | ||
osgi.extender;\ | ||
filter:="(&(osgi.extender=jsp.taglib)(uri=http://liferay.com/tld/soy))" | ||
Web-ContextPath: /asset-vocabularies-selector-web |
14 changes: 14 additions & 0 deletions
14
modules/apps/asset/asset-vocabularies-selector-web/build.gradle
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,14 @@ | ||
dependencies { | ||
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.impl", version: "default" | ||
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "default" | ||
compileOnly group: "com.liferay.portal", name: "com.liferay.util.taglib", version: "default" | ||
compileOnly group: "javax.portlet", name: "portlet-api", version: "3.0.1" | ||
compileOnly group: "javax.servlet.jsp", name: "javax.servlet.jsp-api", version: "2.3.1" | ||
compileOnly group: "org.apache.felix", name: "org.apache.felix.http.servlet-api", version: "1.1.2" | ||
compileOnly group: "org.osgi", name: "org.osgi.service.component.annotations", version: "1.3.0" | ||
compileOnly project(":apps:frontend-taglib:frontend-taglib") | ||
compileOnly project(":apps:frontend-taglib:frontend-taglib-soy") | ||
compileOnly project(":apps:portal:portal-upgrade-api") | ||
compileOnly project(":core:petra:petra-lang") | ||
compileOnly project(":core:petra:petra-string") | ||
} |
16 changes: 16 additions & 0 deletions
16
modules/apps/asset/asset-vocabularies-selector-web/package.json
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,16 @@ | ||
{ | ||
"dependencies": { | ||
"frontend-js-web": "*", | ||
"metal": "2.16.8", | ||
"metal-component": "2.16.8", | ||
"metal-soy": "2.16.8", | ||
"metal-state": "2.16.8" | ||
}, | ||
"name": "asset-vocabularies-selector-web", | ||
"scripts": { | ||
"build": "liferay-npm-scripts build", | ||
"checkFormat": "liferay-npm-scripts check", | ||
"format": "liferay-npm-scripts fix" | ||
}, | ||
"version": "3.0.0" | ||
} |
26 changes: 26 additions & 0 deletions
26
...set/vocabularies/selector/web/internal/contants/AssetVocabulariesSelectorPortletKeys.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,26 @@ | ||
/** | ||
* 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.asset.vocabularies.selector.web.internal.contants; | ||
|
||
/** | ||
* @author Raymond Augé | ||
*/ | ||
public class AssetVocabulariesSelectorPortletKeys { | ||
|
||
public static final String ASSET_VOCABULARIES_SELECTOR = | ||
"com_liferay_asset_vocabularies_selector_web_portlet_" + | ||
"AssetVocabulariesSelectorPortlet"; | ||
|
||
} |
183 changes: 183 additions & 0 deletions
183
...laries/selector/web/internal/display/context/AssetVocabulariesSelectorDisplayContext.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,183 @@ | ||
/** | ||
* 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.asset.vocabularies.selector.web.internal.display.context; | ||
|
||
import com.liferay.asset.kernel.model.AssetVocabulary; | ||
import com.liferay.asset.kernel.service.AssetVocabularyLocalService; | ||
import com.liferay.asset.kernel.service.AssetVocabularyService; | ||
import com.liferay.petra.string.StringBundler; | ||
import com.liferay.petra.string.StringPool; | ||
import com.liferay.portal.kernel.exception.PortalException; | ||
import com.liferay.portal.kernel.json.JSONArray; | ||
import com.liferay.portal.kernel.json.JSONFactory; | ||
import com.liferay.portal.kernel.json.JSONObject; | ||
import com.liferay.portal.kernel.language.Language; | ||
import com.liferay.portal.kernel.model.Group; | ||
import com.liferay.portal.kernel.service.GroupLocalService; | ||
import com.liferay.portal.kernel.theme.ThemeDisplay; | ||
import com.liferay.portal.kernel.util.Html; | ||
import com.liferay.portal.kernel.util.ParamUtil; | ||
import com.liferay.portal.kernel.util.Validator; | ||
import com.liferay.portal.kernel.util.WebKeys; | ||
|
||
import java.util.List; | ||
|
||
import javax.portlet.RenderRequest; | ||
import javax.portlet.RenderResponse; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
/** | ||
* @author Raymond Augé | ||
*/ | ||
public class AssetVocabulariesSelectorDisplayContext { | ||
|
||
public AssetVocabulariesSelectorDisplayContext( | ||
RenderRequest renderRequest, RenderResponse renderResponse, | ||
HttpServletRequest httpServletRequest) { | ||
|
||
_renderRequest = renderRequest; | ||
_renderResponse = renderResponse; | ||
_httpServletRequest = httpServletRequest; | ||
_assetVocabularyService = | ||
(AssetVocabularyService)renderRequest.getAttribute( | ||
"assetVocabularyService"); | ||
_assetVocabularyLocalService = | ||
(AssetVocabularyLocalService)renderRequest.getAttribute( | ||
"assetVocabularyLocalService"); | ||
_groupLocalService = (GroupLocalService)renderRequest.getAttribute( | ||
"groupLocalService"); | ||
_html = (Html)renderRequest.getAttribute("html"); | ||
_jsonFactory = (JSONFactory)renderRequest.getAttribute("jsonFactory"); | ||
_language = (Language)renderRequest.getAttribute("language"); | ||
} | ||
|
||
public String getEventName() { | ||
if (Validator.isNotNull(_eventName)) { | ||
return _eventName; | ||
} | ||
|
||
_eventName = ParamUtil.getString( | ||
_httpServletRequest, "eventName", | ||
_renderResponse.getNamespace() + "selectVocabulary"); | ||
|
||
return _eventName; | ||
} | ||
|
||
public String getSelectedVocabularies() { | ||
if (_selectedVocabularies != null) { | ||
return _selectedVocabularies; | ||
} | ||
|
||
_selectedVocabularies = ParamUtil.getString( | ||
_httpServletRequest, "selectedVocabularies"); | ||
|
||
return _selectedVocabularies; | ||
} | ||
|
||
public JSONArray getVocabulariesJSONArray() throws Exception { | ||
JSONArray jsonArray = _jsonFactory.createJSONArray(); | ||
|
||
ThemeDisplay themeDisplay = | ||
(ThemeDisplay)_httpServletRequest.getAttribute( | ||
WebKeys.THEME_DISPLAY); | ||
|
||
long[] groupIds = getGroupIds(themeDisplay); | ||
|
||
List<AssetVocabulary> vocabularies = | ||
_assetVocabularyService.getGroupsVocabularies(groupIds); | ||
|
||
for (AssetVocabulary vocabulary : vocabularies) { | ||
JSONObject jsonObject = _jsonFactory.createJSONObject(); | ||
|
||
jsonObject.put( | ||
"icon", "vocabularies" | ||
).put( | ||
"id", vocabulary.getVocabularyId() | ||
).put( | ||
"key", vocabulary.getName() | ||
).put( | ||
"name", getVocabularyTitle(vocabulary.getVocabularyId()) | ||
); | ||
|
||
if (getSelectedVocabularies().contains( | ||
String.valueOf(vocabulary.getVocabularyId()))) { | ||
|
||
jsonObject.put("selected", true); | ||
} | ||
|
||
jsonArray.put(jsonObject); | ||
} | ||
|
||
return jsonArray; | ||
} | ||
|
||
public String getVocabularyTitle(long vocabularyId) throws PortalException { | ||
ThemeDisplay themeDisplay = (ThemeDisplay)_renderRequest.getAttribute( | ||
WebKeys.THEME_DISPLAY); | ||
|
||
AssetVocabulary assetVocabulary = | ||
_assetVocabularyLocalService.fetchAssetVocabulary(vocabularyId); | ||
|
||
StringBundler sb = new StringBundler(5); | ||
|
||
String title = assetVocabulary.getTitle(themeDisplay.getLocale()); | ||
|
||
sb.append(_html.escape(title)); | ||
|
||
sb.append(StringPool.SPACE); | ||
sb.append(StringPool.OPEN_PARENTHESIS); | ||
|
||
if (assetVocabulary.getGroupId() == themeDisplay.getCompanyGroupId()) { | ||
sb.append(_language.get(_httpServletRequest, "global")); | ||
} | ||
else { | ||
Group group = _groupLocalService.fetchGroup( | ||
assetVocabulary.getGroupId()); | ||
|
||
sb.append(group.getDescriptiveName(themeDisplay.getLocale())); | ||
} | ||
|
||
sb.append(StringPool.CLOSE_PARENTHESIS); | ||
|
||
return sb.toString(); | ||
} | ||
|
||
private long[] getGroupIds(ThemeDisplay themeDisplay) { | ||
if (_groupIds != null) { | ||
return _groupIds; | ||
} | ||
|
||
return _groupIds = ParamUtil.getLongValues( | ||
_httpServletRequest, "groupIds", | ||
new long[] { | ||
themeDisplay.getCompanyGroupId(), themeDisplay.getScopeGroupId() | ||
}); | ||
} | ||
|
||
private final AssetVocabularyLocalService _assetVocabularyLocalService; | ||
private final AssetVocabularyService _assetVocabularyService; | ||
private String _eventName; | ||
private long[] _groupIds; | ||
private final GroupLocalService _groupLocalService; | ||
private final Html _html; | ||
private final HttpServletRequest _httpServletRequest; | ||
private final JSONFactory _jsonFactory; | ||
private final Language _language; | ||
private final RenderRequest _renderRequest; | ||
private final RenderResponse _renderResponse; | ||
private String _selectedVocabularies; | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...laries/selector/web/internal/portlet/AssetVocabulariesSelectorBrowserPortletProvider.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,39 @@ | ||
/** | ||
* 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.asset.vocabularies.selector.web.internal.portlet; | ||
|
||
import com.liferay.asset.vocabularies.selector.web.internal.contants.AssetVocabulariesSelectorPortletKeys; | ||
import com.liferay.portal.kernel.portlet.BasePortletProvider; | ||
import com.liferay.portal.kernel.portlet.BrowsePortletProvider; | ||
|
||
import org.osgi.service.component.annotations.Component; | ||
|
||
/** | ||
* @author Raymond Augé | ||
*/ | ||
@Component( | ||
immediate = true, | ||
property = "model.class.name=com.liferay.asset.kernel.model.AssetVocabulary", | ||
service = BrowsePortletProvider.class | ||
) | ||
public class AssetVocabulariesSelectorBrowserPortletProvider | ||
extends BasePortletProvider implements BrowsePortletProvider { | ||
|
||
@Override | ||
public String getPortletName() { | ||
return AssetVocabulariesSelectorPortletKeys.ASSET_VOCABULARIES_SELECTOR; | ||
} | ||
|
||
} |
Oops, something went wrong.