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

[DE-Migration] LPS-125369 convert title json object into map #89

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -37,6 +37,8 @@
import com.liferay.layout.service.LayoutClassedModelUsageLocalService;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.json.JSONFactory;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.model.Layout;
Expand All @@ -53,6 +55,7 @@
import com.liferay.portal.kernel.upload.UploadException;
import com.liferay.portal.kernel.upload.UploadPortletRequest;
import com.liferay.portal.kernel.util.Http;
import com.liferay.portal.kernel.util.LocaleUtil;
import com.liferay.portal.kernel.util.LocalizationUtil;
import com.liferay.portal.kernel.util.MapUtil;
import com.liferay.portal.kernel.util.ParamUtil;
Expand All @@ -66,9 +69,11 @@
import java.io.File;

import java.util.Calendar;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
Expand Down Expand Up @@ -135,8 +140,18 @@ protected void doProcessAction(
String articleId = ParamUtil.getString(
uploadPortletRequest, "articleId");
double version = ParamUtil.getDouble(uploadPortletRequest, "version");
Map<Locale, String> titleMap = LocalizationUtil.getLocalizationMap(
actionRequest, "titleMapAsXML");

Map<Locale, String> titleMap = new HashMap<>();

JSONObject titleValueJSONObject = _jsonFactory.createJSONObject(
ParamUtil.getString(uploadPortletRequest, "titleValue"));

Set<String> keySet = titleValueJSONObject.keySet();

keySet.forEach(
key -> titleMap.put(
LocaleUtil.fromLanguageId(key),
titleValueJSONObject.getString(key)));

String ddmStructureKey = ParamUtil.getString(
uploadPortletRequest, "ddmStructureKey");
Expand Down Expand Up @@ -582,6 +597,9 @@ private void _updateLayoutClassedModelUsage(
@Reference
private JournalHelper _journalHelper;

@Reference
private JSONFactory _jsonFactory;

@Reference
private LayoutClassedModelUsageLocalService
_layoutClassedModelUsageLocalService;
Expand Down
Expand Up @@ -64,6 +64,7 @@ JournalEditArticleDisplayContext journalEditArticleDisplayContext = new JournalE
<ul class="tbar-nav">
<li class="tbar-item tbar-item-expand">
<aui:input autoFocus="<%= (article == null) || article.isNew() %>" cssClass="form-control-inline" defaultLanguageId="<%= journalEditArticleDisplayContext.getDefaultArticleLanguageId() %>" label="" localized="<%= true %>" name="titleMapAsXML" placeholder='<%= LanguageUtil.format(request, "untitled-x", HtmlUtil.escape(ddmStructure.getName(locale))) %>' required="<%= journalEditArticleDisplayContext.getClassNameId() == JournalArticleConstants.CLASS_NAME_ID_DEFAULT %>" selectedLanguageId="<%= journalEditArticleDisplayContext.getSelectedLanguageId() %>" type="text" wrapperCssClass="article-content-title mb-0" />
<aui:input name="titleValue" type="hidden" />
</li>
<li class="tbar-item">
<div class="journal-article-button-row tbar-section text-right">
Expand Down
Expand Up @@ -153,6 +153,25 @@ class JournalPortlet extends PortletBase {
return document.getElementById(this.ns(name));
}

_getInputLocalizedValues(field) {
const inputLocalized = Liferay.component(this.ns(field));
const localizedValues = {};

if (inputLocalized) {
const translatedLanguages = inputLocalized
.get('translatedLanguages')
.values();

translatedLanguages.forEach((languageId) => {
localizedValues[languageId] = inputLocalized.getValue(
languageId
);
});
}

return JSON.stringify(localizedValues);
}

/**
* @private
*/
Expand Down Expand Up @@ -247,6 +266,10 @@ class JournalPortlet extends PortletBase {
articleIdInput.value = newArticleIdInput.value;
}

const titleValueInput = this._getInputByName(this.ns('titleValue'));

titleValueInput.value = this._getInputLocalizedValues('titleMapAsXML');

const form = this._getInputByName(this.ns('fm1'));

this._cleanInputIfNeeded('titleMapAsXML');
Expand Down