Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LPS-98836 Support condition field based on organization country and/or region #4132

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,10 @@ protected AssetEntryQuery getAssetEntryQuery(

properties.fastLoad(assetListEntry.getTypeSettings(segmentsEntryId));

_setCategoriesAndTags(
_setCategoriesAndKeywordsAndTags(
assetListEntry, assetEntryQuery, properties,
_getAssetCategoryIds(properties), _getAssetTagNames(properties));
_getAssetCategoryIds(properties), _getKeywords(properties),
_getAssetTagNames(properties));

long[] groupIds = GetterUtil.getLongValues(
StringUtil.split(
Expand Down Expand Up @@ -369,6 +370,35 @@ private static String[] _getAssetTagNames(UnicodeProperties properties) {
return allAssetTagNames;
}

private static String[] _getKeywords(UnicodeProperties properties) {
String[] allKeywords = new String[0];

for (int i = 0; true; i++) {
String[] queryValues = StringUtil.split(
properties.getProperty("queryValues" + i, null));

if (ArrayUtil.isEmpty(queryValues)) {
break;
}

boolean queryContains = GetterUtil.getBoolean(
properties.getProperty("queryContains" + i, StringPool.BLANK));
boolean queryAndOperator = GetterUtil.getBoolean(
properties.getProperty(
"queryAndOperator" + i, StringPool.BLANK));
String queryName = properties.getProperty(
"queryName" + i, StringPool.BLANK);

if (!Objects.equals(queryName, "keywords") && queryContains &&
(queryAndOperator || (queryValues.length == 1))) {

allKeywords = queryValues;
}
}

return allKeywords;
}

private long[] _filterAssetCategoryIds(long[] assetCategoryIds) {
List<Long> assetCategoryIdsList = new ArrayList<>();

Expand Down Expand Up @@ -593,16 +623,21 @@ private List<AssetEntry> _search(
return Collections.emptyList();
}

private void _setCategoriesAndTags(
private void _setCategoriesAndKeywordsAndTags(
AssetListEntry assetListEntry, AssetEntryQuery assetEntryQuery,
UnicodeProperties properties, long[] overrideAllAssetCategoryIds,
String[] overrideAllAssetTagNames) {
String[] overrideAllKeywords, String[] overrideAllAssetTagNames) {

long[] allAssetCategoryIds = new long[0];
long[] anyAssetCategoryIds = new long[0];
long[] notAllAssetCategoryIds = new long[0];
long[] notAnyAssetCategoryIds = new long[0];

String[] allKeywords = new String[0];
String[] anyKeywords = new String[0];
String[] notAllKeywords = new String[0];
String[] notAnyKeywords = new String[0];

String[] allAssetTagNames = new String[0];
String[] anyAssetTagNames = new String[0];
String[] notAllAssetTagNames = new String[0];
Expand Down Expand Up @@ -640,6 +675,20 @@ else if (!queryContains && queryAndOperator) {
notAnyAssetCategoryIds = assetCategoryIds;
}
}
else if (Objects.equals(queryName, "keywords")) {
if (queryContains && queryAndOperator) {
allKeywords = queryValues;
}
else if (queryContains && !queryAndOperator) {
anyKeywords = queryValues;
}
else if (!queryContains && queryAndOperator) {
notAllKeywords = queryValues;
}
else {
notAnyKeywords = queryValues;
}
}
else {
if (queryContains && queryAndOperator) {
allAssetTagNames = queryValues;
Expand All @@ -664,6 +713,12 @@ else if (!queryContains && queryAndOperator) {

assetEntryQuery.setAllCategoryIds(allAssetCategoryIds);

if (overrideAllKeywords != null) {
allKeywords = overrideAllKeywords;
}

assetEntryQuery.setAllKeywords(allKeywords);

if (overrideAllAssetTagNames != null) {
allAssetTagNames = overrideAllAssetTagNames;
}
Expand All @@ -679,13 +734,17 @@ else if (!queryContains && queryAndOperator) {

assetEntryQuery.setAnyCategoryIds(anyAssetCategoryIds);

assetEntryQuery.setAnyKeywords(anyKeywords);

long[] anyAssetTagIds = _assetTagLocalService.getTagIds(
siteGroupId, anyAssetTagNames);

assetEntryQuery.setAnyTagIds(anyAssetTagIds);

assetEntryQuery.setNotAllCategoryIds(notAllAssetCategoryIds);

assetEntryQuery.setNotAllKeywords(notAllKeywords);

for (String assetTagName : notAllAssetTagNames) {
long[] notAllAssetTagIds = _assetTagLocalService.getTagIds(
new long[] {siteGroupId}, assetTagName);
Expand All @@ -695,6 +754,8 @@ else if (!queryContains && queryAndOperator) {

assetEntryQuery.setNotAnyCategoryIds(notAnyAssetCategoryIds);

assetEntryQuery.setNotAnyKeywords(notAnyKeywords);

long[] notAnyAssetTagIds = _assetTagLocalService.getTagIds(
siteGroupId, notAnyAssetTagNames);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,30 @@ public JSONArray getAutoFieldRulesJSONArray() {

ruleJSONObject.put("selectedItems", selectedItems);
}
else if (Objects.equals(queryName, "keywords")) {
queryValues = ParamUtil.getString(
_httpServletRequest, "keywords" + queryLogicIndex,
queryValues);

String[] keywords = StringUtil.split(queryValues, " ");

if (ArrayUtil.isEmpty(keywords)) {
continue;
}

List<HashMap<String, String>> selectedItems = new ArrayList<>();

for (String keyword : keywords) {
HashMap<String, String> selectedCategory = new HashMap<>();

selectedCategory.put("label", keyword);
selectedCategory.put("value", keyword);

selectedItems.add(selectedCategory);
}

ruleJSONObject.put("selectedItems", selectedItems);
}
else {
queryValues = ParamUtil.getString(
_httpServletRequest, "queryCategoryIds" + queryLogicIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ protected AssetQueryRule getQueryRule(
values = ParamUtil.getStringValues(
actionRequest, "queryTagNames" + index);
}
else if (name.equals("keywords")) {
values = ParamUtil.getStringValues(
actionRequest, "keywords" + index);
}
else {
values = ParamUtil.getStringValues(
actionRequest, "queryCategoryIds" + index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
>
<option class="" {if $rule.type == 'assetCategories'}selected="selected"{/if} value="assetCategories">{msg desc=""}categories{/msg}</option>
<option class="" {if $rule.type == 'assetTags'}selected="selected"{/if} value="assetTags">{msg desc=""}tags{/msg}</option>
<option class="" {if $rule.type == 'keywords'}selected="selected"{/if} value="keywords">{msg desc=""}keywords{/msg}</option>
</select>
</div>

Expand All @@ -152,6 +153,19 @@
{param selectedItems: $rule.selectedItems ?: [] /}
{param vocabularyIds: $vocabularyIds /}
{/call}
{elseif $rule.type == 'keywords'}
<div class="form-group">
<label for="{$namespace + 'keywords' + $index}">{msg desc=""}keywords{/msg}</label>

<input
type="text"
class="form-control asset-query-keywords"
data-item-index="{$index}"
id="{$namespace + 'keywords' + $index}"
name="{$namespace + 'keywords' + $index}"
value="{$rule.queryValues ?: ''}"
/>
</div>
{else}
{call com.liferay.asset.taglib.AssetTagsSelector.render}
{param eventName: $namespace + 'selectTag' /}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ public AssetEntryQuery getAssetEntryQuery(
String[] overrideAllAssetTagNames)
throws PortalException;

public AssetEntryQuery getAssetEntryQuery(
PortletPreferences portletPreferences, long groupId, Layout layout,
long[] overrideAllAssetCategoryIds, String[] overrideAllKeywords,
String[] overrideAllAssetTagNames)
throws PortalException;

public List<AssetEntryResult> getAssetEntryResults(
SearchContainer searchContainer, AssetEntryQuery assetEntryQuery,
Layout layout, PortletPreferences portletPreferences,
Expand Down Expand Up @@ -134,6 +140,8 @@ public long[] getGroupIds(
PortletPreferences portletPreferences, long scopeGroupId,
Layout layout);

public String[] getKeywords(PortletPreferences portletPreferences);

public String getScopeId(Group group, long scopeGroupId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,33 @@ public String[] getAllAssetTagNames() {
return _allAssetTagNames;
}

public String[] getAllKeywords() {
if (_allKeywords != null) {
return _allKeywords;
}

_allKeywords = new String[0];

String keyword = ParamUtil.getString(_httpServletRequest, "keyword");

String selectionStyle = getSelectionStyle();

if (selectionStyle.equals("dynamic")) {
_allKeywords = _assetPublisherHelper.getKeywords(
_portletPreferences);
}

if (Validator.isNotNull(keyword) &&
!ArrayUtil.contains(_allKeywords, keyword)) {

_allKeywords = ArrayUtil.append(_allKeywords, keyword);
}

_allKeywords = ArrayUtil.distinct(_allKeywords, new StringComparator());

return _allKeywords;
}

public long getAssetCategoryId() {
if (_assetCategoryId != null) {
return _assetCategoryId;
Expand Down Expand Up @@ -335,7 +362,7 @@ assetListEntry, _getSegmentsEntryIds(),
_assetEntryQuery = _assetPublisherHelper.getAssetEntryQuery(
_portletPreferences, _themeDisplay.getScopeGroupId(),
_themeDisplay.getLayout(), getAllAssetCategoryIds(),
getAllAssetTagNames());
getAllKeywords(), getAllAssetTagNames());
}

_assetEntryQuery.setEnablePermissions(isEnablePermissions());
Expand Down Expand Up @@ -547,6 +574,30 @@ public JSONArray getAutoFieldRulesJSONArray() {

ruleJSONObject.put("selectedItems", selectedItems);
}
else if (Objects.equals(queryName, "keywords")) {
queryValues = ParamUtil.getString(
_httpServletRequest, "keywords" + queryLogicIndex,
queryValues);

String[] keywords = StringUtil.split(queryValues, " ");

if (ArrayUtil.isEmpty(keywords)) {
continue;
}

List<HashMap<String, String>> selectedItems = new ArrayList<>();

for (String keyword : keywords) {
HashMap<String, String> selectedCategory = new HashMap<>();

selectedCategory.put("label", keyword);
selectedCategory.put("value", keyword);

selectedItems.add(selectedCategory);
}

ruleJSONObject.put("selectedItems", selectedItems);
}
else {
queryValues = ParamUtil.getString(
_httpServletRequest, "queryCategoryIds" + queryLogicIndex,
Expand Down Expand Up @@ -1891,6 +1942,7 @@ private long[] _getSegmentsEntryIds() {
private Integer _abstractLength;
private long[] _allAssetCategoryIds;
private String[] _allAssetTagNames;
private String[] _allKeywords;
private Boolean _anyAssetType;
private Long _assetCategoryId;
private final AssetEntryActionRegistry _assetEntryActionRegistry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,10 @@ protected AssetQueryRule getQueryRule(
values = ParamUtil.getStringValues(
actionRequest, "queryTagNames" + index);
}
else if (name.equals("keywords")) {
values = ParamUtil.getStringValues(
actionRequest, "keywords" + index);
}
else {
values = ParamUtil.getStringValues(
actionRequest, "queryCategoryIds" + index);
Expand Down
Loading