001
014
015 package com.liferay.portal.upgrade.v6_0_6;
016
017 import com.liferay.portal.kernel.portlet.PortletPreferencesFactoryUtil;
018 import com.liferay.portal.kernel.upgrade.BaseUpgradePortletPreferences;
019 import com.liferay.portal.kernel.util.GetterUtil;
020 import com.liferay.portal.kernel.util.StringPool;
021
022 import java.sql.PreparedStatement;
023 import java.sql.ResultSet;
024
025 import javax.portlet.PortletPreferences;
026
027
030 public class UpgradeRSS extends BaseUpgradePortletPreferences {
031
032 protected String[] getArticleValues(long resourcePrimKey) {
033 long groupId = 0;
034 String articleId = StringPool.BLANK;
035
036 try (PreparedStatement ps = connection.prepareStatement(
037 "select groupId, articleId from JournalArticle where " +
038 "resourcePrimKey = ?")) {
039
040 ps.setLong(1, resourcePrimKey);
041
042 try (ResultSet rs = ps.executeQuery()) {
043 rs.next();
044
045 groupId = rs.getLong("groupId");
046 articleId = rs.getString("articleId");
047 }
048 }
049 catch (Exception e) {
050 }
051
052 return new String[] {String.valueOf(groupId), articleId};
053 }
054
055 @Override
056 protected String[] getPortletIds() {
057 return new String[] {"39_INSTANCE_%"};
058 }
059
060 protected void updateFooterValues(PortletPreferences portletPreferences)
061 throws Exception {
062
063 String[] footerArticleResouceValues = portletPreferences.getValues(
064 "footer-article-resource-values", new String[] {"0", ""});
065
066 long footerArticleResourcePrimKey = GetterUtil.getLong(
067 footerArticleResouceValues[0]);
068
069 String[] values = getArticleValues(footerArticleResourcePrimKey);
070
071 portletPreferences.setValues("footer-article-values", values);
072 portletPreferences.reset("footer-article-resource-values");
073 }
074
075 protected void updateHeaderValues(PortletPreferences portletPreferences)
076 throws Exception {
077
078 String[] headerArticleResouceValues = portletPreferences.getValues(
079 "header-article-resource-values", new String[] {"0", ""});
080
081 long headerArticleResourcePrimKey = GetterUtil.getLong(
082 headerArticleResouceValues[0]);
083
084 String[] values = getArticleValues(headerArticleResourcePrimKey);
085
086 portletPreferences.setValues("header-article-values", values);
087 portletPreferences.reset("header-article-resource-values");
088 }
089
090 @Override
091 protected String upgradePreferences(
092 long companyId, long ownerId, int ownerType, long plid,
093 String portletId, String xml)
094 throws Exception {
095
096 PortletPreferences portletPreferences =
097 PortletPreferencesFactoryUtil.fromXML(
098 companyId, ownerId, ownerType, plid, portletId, xml);
099
100 updateFooterValues(portletPreferences);
101 updateHeaderValues(portletPreferences);
102
103 return PortletPreferencesFactoryUtil.toXML(portletPreferences);
104 }
105
106 }