Search in sources :

Example 1 with KBFolder

use of com.liferay.knowledgebase.model.KBFolder in project liferay-ide by liferay.

the class KBArticleStagedModelDataHandler method doExportStagedModel.

@Override
protected void doExportStagedModel(PortletDataContext portletDataContext, KBArticle kbArticle) throws Exception {
    if (kbArticle.getParentResourcePrimKey() != KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
        long kbArticleClassNameId = PortalUtil.getClassNameId(KBArticleConstants.getClassName());
        if (kbArticle.getParentResourceClassNameId() == kbArticleClassNameId) {
            KBArticle parentKBArticle = KBArticleLocalServiceUtil.getLatestKBArticle(kbArticle.getParentResourcePrimKey(), WorkflowConstants.STATUS_APPROVED);
            StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, kbArticle, parentKBArticle, PortletDataContext.REFERENCE_TYPE_PARENT);
        } else {
            KBFolder parentKBFolder = KBFolderLocalServiceUtil.getKBFolder(kbArticle.getParentResourcePrimKey());
            StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, kbArticle, parentKBFolder, PortletDataContext.REFERENCE_TYPE_PARENT);
        }
    }
    Element kbArticleElement = portletDataContext.getExportDataElement(kbArticle);
    exportKBArticleAttachments(portletDataContext, kbArticleElement, kbArticle);
    portletDataContext.addClassedModel(kbArticleElement, ExportImportPathUtil.getModelPath(kbArticle), kbArticle);
}
Also used : KBFolder(com.liferay.knowledgebase.model.KBFolder) KBArticle(com.liferay.knowledgebase.model.KBArticle) Element(com.liferay.portal.kernel.xml.Element)

Example 2 with KBFolder

use of com.liferay.knowledgebase.model.KBFolder in project liferay-ide by liferay.

the class KBFolderStagedModelDataHandler method doImportStagedModel.

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, KBFolder kbFolder) throws Exception {
    long userId = portletDataContext.getUserId(kbFolder.getUserUuid());
    if (kbFolder.getParentKBFolderId() != KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
        StagedModelDataHandlerUtil.importReferenceStagedModels(portletDataContext, kbFolder, KBFolder.class);
    }
    ServiceContext serviceContext = portletDataContext.createServiceContext(kbFolder);
    KBFolder importedKBFolder = null;
    if (portletDataContext.isDataStrategyMirror()) {
        KBFolder existingKBFolder = KBFolderUtil.fetchByUUID_G(kbFolder.getUuid(), portletDataContext.getScopeGroupId());
        if (existingKBFolder == null) {
            importedKBFolder = KBFolderLocalServiceUtil.addKBFolder(userId, portletDataContext.getScopeGroupId(), kbFolder.getClassNameId(), kbFolder.getParentKBFolderId(), kbFolder.getName(), kbFolder.getDescription(), serviceContext);
        } else {
            importedKBFolder = KBFolderLocalServiceUtil.updateKBFolder(kbFolder.getClassNameId(), kbFolder.getParentKBFolderId(), kbFolder.getKbFolderId(), kbFolder.getName(), kbFolder.getDescription());
        }
    } else {
        importedKBFolder = KBFolderLocalServiceUtil.addKBFolder(userId, portletDataContext.getScopeGroupId(), kbFolder.getClassNameId(), kbFolder.getParentKBFolderId(), kbFolder.getName(), kbFolder.getDescription(), serviceContext);
    }
    portletDataContext.importClassedModel(kbFolder, importedKBFolder);
    Map<Long, Long> kbFolderIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(KBFolder.class);
    kbFolderIds.put(kbFolder.getKbFolderId(), importedKBFolder.getKbFolderId());
}
Also used : KBFolder(com.liferay.knowledgebase.model.KBFolder) ServiceContext(com.liferay.portal.service.ServiceContext) Map(java.util.Map)

Example 3 with KBFolder

use of com.liferay.knowledgebase.model.KBFolder in project liferay-ide by liferay.

the class KBFolderPermission method check.

public static void check(PermissionChecker permissionChecker, long kbFolderId, String actionId) throws PortalException, SystemException {
    KBFolder kbFolder = KBFolderLocalServiceUtil.getKBFolder(kbFolderId);
    check(permissionChecker, kbFolder, actionId);
}
Also used : KBFolder(com.liferay.knowledgebase.model.KBFolder)

Example 4 with KBFolder

use of com.liferay.knowledgebase.model.KBFolder in project liferay-ide by liferay.

the class KBFolderPersistenceImpl method fetchByG_P_UT.

/**
 * Returns the k b folder where groupId = &#63; and parentKBFolderId = &#63; and urlTitle = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
 *
 * @param groupId the group ID
 * @param parentKBFolderId the parent k b folder ID
 * @param urlTitle the url title
 * @param retrieveFromCache whether to use the finder cache
 * @return the matching k b folder, or <code>null</code> if a matching k b folder could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public KBFolder fetchByG_P_UT(long groupId, long parentKBFolderId, String urlTitle, boolean retrieveFromCache) throws SystemException {
    Object[] finderArgs = new Object[] { groupId, parentKBFolderId, urlTitle };
    Object result = null;
    if (retrieveFromCache) {
        result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P_UT, finderArgs, this);
    }
    if (result instanceof KBFolder) {
        KBFolder kbFolder = (KBFolder) result;
        if ((groupId != kbFolder.getGroupId()) || (parentKBFolderId != kbFolder.getParentKBFolderId()) || !Validator.equals(urlTitle, kbFolder.getUrlTitle())) {
            result = null;
        }
    }
    if (result == null) {
        StringBundler query = new StringBundler(5);
        query.append(_SQL_SELECT_KBFOLDER_WHERE);
        query.append(_FINDER_COLUMN_G_P_UT_GROUPID_2);
        query.append(_FINDER_COLUMN_G_P_UT_PARENTKBFOLDERID_2);
        boolean bindUrlTitle = false;
        if (urlTitle == null) {
            query.append(_FINDER_COLUMN_G_P_UT_URLTITLE_1);
        } else if (urlTitle.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_G_P_UT_URLTITLE_3);
        } else {
            bindUrlTitle = true;
            query.append(_FINDER_COLUMN_G_P_UT_URLTITLE_2);
        }
        String sql = query.toString();
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            QueryPos qPos = QueryPos.getInstance(q);
            qPos.add(groupId);
            qPos.add(parentKBFolderId);
            if (bindUrlTitle) {
                qPos.add(urlTitle);
            }
            List<KBFolder> list = q.list();
            if (list.isEmpty()) {
                FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_UT, finderArgs, list);
            } else {
                if ((list.size() > 1) && _log.isWarnEnabled()) {
                    _log.warn("KBFolderPersistenceImpl.fetchByG_P_UT(long, long, String, boolean) with parameters (" + StringUtil.merge(finderArgs) + ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
                }
                KBFolder kbFolder = list.get(0);
                result = kbFolder;
                cacheResult(kbFolder);
                if ((kbFolder.getGroupId() != groupId) || (kbFolder.getParentKBFolderId() != parentKBFolderId) || (kbFolder.getUrlTitle() == null) || !kbFolder.getUrlTitle().equals(urlTitle)) {
                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_UT, finderArgs, kbFolder);
                }
            }
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_UT, finderArgs);
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    if (result instanceof List<?>) {
        return null;
    } else {
        return (KBFolder) result;
    }
}
Also used : KBFolder(com.liferay.knowledgebase.model.KBFolder) SQLQuery(com.liferay.portal.kernel.dao.orm.SQLQuery) Query(com.liferay.portal.kernel.dao.orm.Query) ArrayList(java.util.ArrayList) UnmodifiableList(com.liferay.portal.kernel.util.UnmodifiableList) List(java.util.List) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.portal.kernel.util.StringBundler) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchFolderException(com.liferay.knowledgebase.NoSuchFolderException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 5 with KBFolder

use of com.liferay.knowledgebase.model.KBFolder in project liferay-ide by liferay.

the class KBFolderPersistenceImpl method findByUuid_C_Last.

/**
 * Returns the last k b folder in the ordered set where uuid = &#63; and companyId = &#63;.
 *
 * @param uuid the uuid
 * @param companyId the company ID
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the last matching k b folder
 * @throws com.liferay.knowledgebase.NoSuchFolderException if a matching k b folder could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public KBFolder findByUuid_C_Last(String uuid, long companyId, OrderByComparator orderByComparator) throws NoSuchFolderException, SystemException {
    KBFolder kbFolder = fetchByUuid_C_Last(uuid, companyId, orderByComparator);
    if (kbFolder != null) {
        return kbFolder;
    }
    StringBundler msg = new StringBundler(6);
    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
    msg.append("uuid=");
    msg.append(uuid);
    msg.append(", companyId=");
    msg.append(companyId);
    msg.append(StringPool.CLOSE_CURLY_BRACE);
    throw new NoSuchFolderException(msg.toString());
}
Also used : KBFolder(com.liferay.knowledgebase.model.KBFolder) NoSuchFolderException(com.liferay.knowledgebase.NoSuchFolderException) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Aggregations

KBFolder (com.liferay.knowledgebase.model.KBFolder)59 NoSuchFolderException (com.liferay.knowledgebase.NoSuchFolderException)24 StringBundler (com.liferay.portal.kernel.util.StringBundler)21 Session (com.liferay.portal.kernel.dao.orm.Session)14 SystemException (com.liferay.portal.kernel.exception.SystemException)14 SQLQuery (com.liferay.portal.kernel.dao.orm.SQLQuery)12 QueryPos (com.liferay.portal.kernel.dao.orm.QueryPos)11 Query (com.liferay.portal.kernel.dao.orm.Query)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 UnmodifiableList (com.liferay.portal.kernel.util.UnmodifiableList)8 KBArticle (com.liferay.knowledgebase.model.KBArticle)7 KBFolderImpl (com.liferay.knowledgebase.model.impl.KBFolderImpl)7 FinderPath (com.liferay.portal.kernel.dao.orm.FinderPath)4 PortletURL (javax.portlet.PortletURL)4 Element (com.liferay.portal.kernel.xml.Element)2 ThemeDisplay (com.liferay.portal.theme.ThemeDisplay)2 PortalPreferences (com.liferay.portlet.PortalPreferences)2 Date (java.util.Date)2 Map (java.util.Map)2