留言板

Facing problem in migrating liferay webcontent articles into custom table

Harsha Vardhan Mummanedi,修改在8 年前。

Facing problem in migrating liferay webcontent articles into custom table

New Member 发布: 1 加入日期: 12-9-15 最近的帖子
Hello every one,
we are initially created web contents and storing data into journal article table, later we created custom table what ever we want that data we moved into custom table by using liferay upgrade processor, but the problem in custom table some date is missing discription field,
Example: This product's belongs to Hundai, but here its saving upto This product
After apostrophe the data is not saving in DB, This problem is only migrated records but newly created records in custom table working fine.. apostrophe also
Jouranalarticle descripton filed data::
<dynamic-element instance-id="1Pf0dHHa" name="description" type="text_area" index-type="">
<dynamic-content>
<![CDATA[<span style="font-size: 16px; line-height: normal;">Order Status tool integrates data from kP's order management systems, enabling a real-time view of order-status, shipping, and reporting information</span>]]>
</dynamic-content>
</dynamic-element>

After migrating by table data:
<?xml version="1.0" ?>
<root available-locales="en_US,in_ID,ja_JP,ko_KR,zh_CN,zh_TW," default-locale="en_US">
<Description language-id="zh_CN">订单状态 (OS) 工具提供了几乎实时的订单状态、发运、发票等信息,同时还能够生成定制报告。</Description>
<Description language-id="zh_TW">訂單狀態 (OS) 工具可提供有關訂單狀態、運送、發票等的接近即時的資訊,並能產生自訂報告。</Description>
<Description language-id="en_US">Order Status tool integrates data from HP</Description>
<Description language-id="in_ID">Tool Order Status (OS) memberikan informasi hampir realtime mengenai status order, pengiriman, faktur, dll dengan kemampuan menyusun laporan yang dapat diatur sesuai keinginan</Description>
<Description language-id="ja_JP">注文状況(OS)ツールでは、注文状況、配送、請求書などのほぼリアルタイムの情報を提供しており、専用レポートを作成できます。</Description>
<Description language-id="ko_KR">오더 상태 (OS, Order Status) 도구는 오더상태, 선적, 인보이스 등에 대한 실시간에 가까운 정보를 사용자정의 리포트 기능과 함께 제공합니다.</Description>
</root>

upgrade processor we used migration purpose::
public class CategoryUpgradeProcessor implements UpgradeProcessor {

xmlResult = XmlParserUtil.getJournalArticleContent(latestArticle.getContent());
if(xmlResult != null) {
Set<String> keySet = xmlResult.keySet();
Iterator<String> it = keySet.iterator();
while(it.hasNext()){
String el = it.next();
if(el.equalsIgnoreCase(DashboardWidgetConstants.DESCRIPTION)){
discriptionValue = xmlResult.get(el);
}else if(el.equalsIgnoreCase(DashboardWidgetConstants.SERVICEID)){
serviceIDValue = xmlResult.get(el);
}else if(el.equalsIgnoreCase(DashboardWidgetConstants.ENAME)){
eNameValue = xmlResult.get(el);
}
saveWidget(widgetType, titleValue, iconValue, discriptionValue, serviceIDValue, eNameValue, status, articleId,groupId,userID,companyID,latestArticle, serviceContext);
}


private void saveWidget(String widgetType, String titleValue, String iconValue, String discriptionValue, String serviceIDValue, String eNameValue,
int status, String articleId, long groupId, long userID, long companyID, JournalArticle latestArticle, ServiceContext serviceContext) {

}

long widgetId = Long.parseLong(articleId);
String size = DashboardWidgetConstants.FIXED;
String xmldefinition = StringPool.BLANK;
String widgetTypes = DashboardWidgetConstants.GO_BUTTON_WIDGET;
long categoryId = 0;
if( widgetType.equalsIgnoreCase(DashboardWidgetConstants.ESM_WIDGET)){


Widget widget = new WidgetImpl();
widget.setWidgetId(widgetId);

for(String locales : latestArticle.getAvailableLocales()){
String content = latestArticle.getContentByLocale();

titleValue= XmlParserUtil.getAvailableLocalesForTitle(content);
discriptionValue= XmlParserUtil.getAvaillocalesableLocalesForDiscrption(content);
eNameValue= XmlParserUtil.getAvailableLocalesForButtonLabel(content);

widget.setTitle(titleValue, LocaleUtil.fromLanguageId(locales));
widget.setDescription(discriptionValue, LocaleUtil.fromLanguageId(locales));
widget.setButtonLabel(eNameValue, LocaleUtil.fromLanguageId(locales));
}

widget.setStatus(status);
widget.setSize(size);
xmldefinition = getXmlDefinitionForWidget(iconValue,serviceIDValue);
widget.setXmlDefinition(xmldefinition);
widget.setUserId(userID);
widget.setCreateDate(new Date());
widget.setModifiedDate(new Date());
widget.setLastModifierUserId(userID);
widget.setWidgetType(widgetTypes);
widget.setGroupId(groupId);
widget.setCompanyId(companyID);


DynamicQuery queryCategoryName = DynamicQueryFactoryUtil.forClass(AssetCategory.class);
List<PortletPreferences> portletPreferences = getPortletItems();

for(PortletPreferences portletPref: portletPreferences){

Map<String, Preference> portletPreferencesHashMap = preferencesToMap(portletPref.getPreferences());

if(portletPreferencesHashMap != null && !portletPreferencesHashMap.isEmpty()){
long prefArticleId=0;

if(portletPreferencesHashMap.get("articleId")!=null){
if(portletPreferencesHashMap.get("articleId").getValues() !=null){
String[] id = portletPreferencesHashMap.get("articleId").getValues();
prefArticleId = Long.parseLong(id[0]);
LOG.info("Widget Migration: Article Id of preference is: "+prefArticleId);
}
}
if(prefArticleId == widgetId){
PortletItem portletItem = PortletItemLocalServiceUtil.getPortletItem(portletPref.getOwnerId());
String categoryString = portletItem.getName();
String[] name = categoryString.split("@@");
String categoryKey = name[0];
String categoryName = LanguageUtil.get(Locale.US, categoryKey);

long globalGroupId = GroupLocalServiceUtil.getCompanyGroup(companyID).getGroupId();
AssetVocabulary voc = AssetVocabularyLocalServiceUtil.getGroupVocabulary(globalGroupId, "dashboard-widgets");

Criterion criterionCategory = null;
criterionCategory = RestrictionsFactoryUtil.eq("name", categoryName);
criterionCategory = RestrictionsFactoryUtil.and(criterionCategory, RestrictionsFactoryUtil.eq("vocabularyId", voc.getVocabularyId()));
queryCategoryName.add(criterionCategory);


List<AssetCategory> assetCategory = AssetCategoryLocalServiceUtil.dynamicQuery(queryCategoryName);

for(AssetCategory assetCat : assetCategory){
categoryId= assetCat.getCategoryId();
widget.setCategoryId(categoryId);
try{
WidgetLocalServiceUtil.addWidget(widget);
LOG.info("Widget Id inserted for this Record -- Success" + articleId);

/* Adding in AssetEntry */
AssetEntry assetEntry = WidgetLocalServiceUtil.addDashboardWigetgAssetEntry(userID, groupId, Widget.class.getName(), widget.getWidgetId(), serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames());

/* Adding in AssetEntries_AssetCategories */
AssetEntryLocalServiceUtil.addAssetCategoryAssetEntry(categoryId, assetEntry.getEntryId());
} catch (SystemException e) {
LOG.info("Widget Id inserted for this Record, Not allowed duplicate record to update==" + articleId);
e.printStackTrace();
}

}

}
}
}

}else{

if (LOG.isDebugEnabled()) {
LOG.debug("Widget with same title already exists.");
}
}

}catch (Exception e) {
e.printStackTrace();
}


}