protected PortletURL getKBArticleURL( long plid, boolean privateLayout, KBArticle kbArticle, HttpServletRequest request) throws Exception { PortletURL firstMatchPortletURL = null; List<Layout> layouts = getCandidateLayouts(plid, privateLayout, kbArticle); for (Layout layout : layouts) { LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType(); List<Portlet> portlets = layoutTypePortlet.getAllPortlets(); for (Portlet portlet : portlets) { String rootPortletId = PortletConstants.getRootPortletId(portlet.getPortletId()); if (rootPortletId.equals(PortletKeys.KNOWLEDGE_BASE_DISPLAY)) { PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getPortletSetup( layout, portlet.getPortletId(), StringPool.BLANK); long kbFolderClassNameId = PortalUtil.getClassNameId(KBFolderConstants.getClassName()); long resourceClassNameId = GetterUtil.getLong( portletPreferences.getValue("resourceClassNameId", null), kbFolderClassNameId); long resourcePrimKey = GetterUtil.getLong( portletPreferences.getValue("resourcePrimKey", null), KBFolderConstants.DEFAULT_PARENT_FOLDER_ID); if (resourceClassNameId == kbFolderClassNameId) { if (isParentFolder(resourcePrimKey, kbArticle.getKbFolderId())) { return getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request); } } else if (resourcePrimKey == kbArticle.getResourcePrimKey()) { return getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request); } if (firstMatchPortletURL == null) { firstMatchPortletURL = getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request); } } if (rootPortletId.equals(PortletKeys.KNOWLEDGE_BASE_SECTION)) { PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getPortletSetup( layout, portlet.getPortletId(), StringPool.BLANK); String[] kbArticlesSections = portletPreferences.getValues("kbArticlesSections", new String[0]); KBArticle rootKBArticle = KBArticleLocalServiceUtil.fetchLatestKBArticle( kbArticle.getRootResourcePrimKey(), WorkflowConstants.STATUS_APPROVED); if (rootKBArticle == null) { continue; } String[] sections = AdminUtil.unescapeSections(rootKBArticle.getSections()); for (String section : sections) { if (!ArrayUtil.contains(kbArticlesSections, section)) { continue; } return getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request); } } if (rootPortletId.equals(PortletKeys.KNOWLEDGE_BASE_ARTICLE)) { PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getPortletSetup( layout, portlet.getPortletId(), StringPool.BLANK); long resourcePrimKey = GetterUtil.getLong(portletPreferences.getValue("resourcePrimKey", null)); KBArticle selKBArticle = KBArticleLocalServiceUtil.fetchLatestKBArticle( resourcePrimKey, WorkflowConstants.STATUS_APPROVED); if (selKBArticle == null) { continue; } long rootResourcePrimKey = kbArticle.getRootResourcePrimKey(); long selRootResourcePrimKey = selKBArticle.getRootResourcePrimKey(); if (rootResourcePrimKey == selRootResourcePrimKey) { return getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request); } if (firstMatchPortletURL == null) { firstMatchPortletURL = getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request); } } } } return firstMatchPortletURL; }
@Override protected void doImportStagedModel(PortletDataContext portletDataContext, KBArticle kbArticle) throws Exception { long userId = portletDataContext.getUserId(kbArticle.getUserUuid()); if (kbArticle.getParentResourcePrimKey() != KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) { if (kbArticle.getClassNameId() == kbArticle.getParentResourceClassNameId()) { StagedModelDataHandlerUtil.importReferenceStagedModels( portletDataContext, kbArticle, KBArticle.class); } else { StagedModelDataHandlerUtil.importReferenceStagedModels( portletDataContext, kbArticle, KBFolder.class); } } Map<Long, Long> kbArticleResourcePrimKeys = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(KBArticle.class); long parentResourcePrimKey = MapUtil.getLong( kbArticleResourcePrimKeys, kbArticle.getParentResourcePrimKey(), KBFolderConstants.DEFAULT_PARENT_FOLDER_ID); long resourcePrimaryKey = MapUtil.getLong(kbArticleResourcePrimKeys, kbArticle.getResourcePrimKey(), 0); if (parentResourcePrimKey == KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) { Map<Long, Long> kbFolderResourcePrimKeys = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(KBFolder.class); parentResourcePrimKey = MapUtil.getLong( kbFolderResourcePrimKeys, kbArticle.getParentResourcePrimKey(), KBFolderConstants.DEFAULT_PARENT_FOLDER_ID); } String[] sections = AdminUtil.unescapeSections(kbArticle.getSections()); ServiceContext serviceContext = portletDataContext.createServiceContext(kbArticle); KBArticle importedKBArticle = null; if (portletDataContext.isDataStrategyMirror()) { KBArticle existingKBArticle = KBArticleUtil.fetchByR_V(resourcePrimaryKey, kbArticle.getVersion()); if (existingKBArticle == null) { existingKBArticle = fetchStagedModelByUuidAndGroupId( kbArticle.getUuid(), portletDataContext.getScopeGroupId()); } if (existingKBArticle == null) { serviceContext.setUuid(kbArticle.getUuid()); existingKBArticle = KBArticleLocalServiceUtil.fetchLatestKBArticle( resourcePrimaryKey, WorkflowConstants.STATUS_ANY); if (existingKBArticle == null) { importedKBArticle = KBArticleLocalServiceUtil.addKBArticle( userId, kbArticle.getParentResourceClassNameId(), parentResourcePrimKey, kbArticle.getTitle(), kbArticle.getUrlTitle(), kbArticle.getContent(), kbArticle.getDescription(), kbArticle.getSourceURL(), sections, null, serviceContext); KBArticleLocalServiceUtil.updatePriority( importedKBArticle.getResourcePrimKey(), kbArticle.getPriority()); } else { KBArticleLocalServiceUtil.updateKBArticle( userId, existingKBArticle.getResourcePrimKey(), kbArticle.getTitle(), kbArticle.getContent(), kbArticle.getDescription(), kbArticle.getSourceURL(), sections, null, null, serviceContext); KBArticleLocalServiceUtil.moveKBArticle( userId, existingKBArticle.getResourcePrimKey(), existingKBArticle.getParentResourceClassNameId(), parentResourcePrimKey, kbArticle.getPriority()); importedKBArticle = KBArticleLocalServiceUtil.getLatestKBArticle( existingKBArticle.getResourcePrimKey(), WorkflowConstants.STATUS_APPROVED); } } else { importedKBArticle = existingKBArticle; } } else { importedKBArticle = KBArticleLocalServiceUtil.addKBArticle( userId, kbArticle.getParentResourceClassNameId(), parentResourcePrimKey, kbArticle.getTitle(), kbArticle.getUrlTitle(), kbArticle.getContent(), kbArticle.getDescription(), kbArticle.getSourceURL(), sections, null, serviceContext); KBArticleLocalServiceUtil.updatePriority( importedKBArticle.getResourcePrimKey(), kbArticle.getPriority()); } importKBArticleAttachments(portletDataContext, kbArticle, importedKBArticle); portletDataContext.importClassedModel(kbArticle, importedKBArticle); if (!kbArticle.isMain()) { kbArticleResourcePrimKeys.put( kbArticle.getResourcePrimKey(), importedKBArticle.getResourcePrimKey()); } }