Search in sources :

Example 1 with KBTemplate

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

the class KBTemplateStagedModelDataHandler method doImportStagedModel.

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, KBTemplate kbTemplate) throws Exception {
    long userId = portletDataContext.getUserId(kbTemplate.getUserUuid());
    ServiceContext serviceContext = portletDataContext.createServiceContext(kbTemplate);
    KBTemplate importedKBTemplate = null;
    if (portletDataContext.isDataStrategyMirror()) {
        KBTemplate existingKBTemplate = KBTemplateUtil.fetchByUUID_G(kbTemplate.getUuid(), portletDataContext.getScopeGroupId());
        if (existingKBTemplate == null) {
            serviceContext.setUuid(kbTemplate.getUuid());
            importedKBTemplate = KBTemplateLocalServiceUtil.addKBTemplate(userId, kbTemplate.getTitle(), kbTemplate.getContent(), serviceContext);
        } else {
            importedKBTemplate = KBTemplateLocalServiceUtil.updateKBTemplate(existingKBTemplate.getKbTemplateId(), kbTemplate.getTitle(), kbTemplate.getContent(), serviceContext);
        }
    } else {
        importedKBTemplate = KBTemplateLocalServiceUtil.addKBTemplate(userId, kbTemplate.getTitle(), kbTemplate.getContent(), serviceContext);
    }
    portletDataContext.importClassedModel(kbTemplate, importedKBTemplate);
}
Also used : ServiceContext(com.liferay.portal.service.ServiceContext) KBTemplate(com.liferay.knowledgebase.model.KBTemplate)

Example 2 with KBTemplate

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

the class AdminPortlet method render.

@Override
public void render(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException {
    try {
        int status = WorkflowConstants.STATUS_ANY;
        renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_STATUS, status);
        KBArticle kbArticle = null;
        long kbArticleClassNameId = PortalUtil.getClassNameId(KBArticleConstants.getClassName());
        long resourceClassNameId = ParamUtil.getLong(renderRequest, "resourceClassNameId", kbArticleClassNameId);
        long resourcePrimKey = ParamUtil.getLong(renderRequest, "resourcePrimKey");
        if ((resourcePrimKey > 0) && (resourceClassNameId == kbArticleClassNameId)) {
            kbArticle = KBArticleServiceUtil.getLatestKBArticle(resourcePrimKey, status);
        }
        renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_KB_ARTICLE, kbArticle);
        KBTemplate kbTemplate = null;
        long kbTemplateId = ParamUtil.getLong(renderRequest, "kbTemplateId");
        if (kbTemplateId > 0) {
            kbTemplate = KBTemplateServiceUtil.getKBTemplate(kbTemplateId);
        }
        renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_KB_TEMPLATE, kbTemplate);
    } catch (Exception e) {
        if (e instanceof NoSuchArticleException || e instanceof NoSuchTemplateException || e instanceof PrincipalException) {
            SessionErrors.add(renderRequest, e.getClass());
        } else {
            throw new PortletException(e);
        }
    }
    super.render(renderRequest, renderResponse);
}
Also used : NoSuchTemplateException(com.liferay.knowledgebase.NoSuchTemplateException) KBArticle(com.liferay.knowledgebase.model.KBArticle) PortletException(javax.portlet.PortletException) PrincipalException(com.liferay.portal.security.auth.PrincipalException) NoSuchArticleException(com.liferay.knowledgebase.NoSuchArticleException) KBTemplate(com.liferay.knowledgebase.model.KBTemplate) NoSuchTemplateException(com.liferay.knowledgebase.NoSuchTemplateException) KBTemplateContentException(com.liferay.knowledgebase.KBTemplateContentException) NoSuchArticleException(com.liferay.knowledgebase.NoSuchArticleException) NoSuchSubscriptionException(com.liferay.portal.NoSuchSubscriptionException) PrincipalException(com.liferay.portal.security.auth.PrincipalException) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) IOException(java.io.IOException) WindowStateException(javax.portlet.WindowStateException) NoSuchCommentException(com.liferay.knowledgebase.NoSuchCommentException) KBTemplateTitleException(com.liferay.knowledgebase.KBTemplateTitleException) KBArticleImportException(com.liferay.knowledgebase.KBArticleImportException) PortletException(javax.portlet.PortletException)

Example 3 with KBTemplate

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

the class AdminActivityInterpreter method getEntryTitle.

@Override
protected String getEntryTitle(SocialActivity activity, ServiceContext serviceContext) throws Exception {
    String title = StringPool.BLANK;
    String className = activity.getClassName();
    if (className.equals(KBArticle.class.getName())) {
        KBArticle kbArticle = KBArticleLocalServiceUtil.getLatestKBArticle(activity.getClassPK(), WorkflowConstants.STATUS_APPROVED);
        title = kbArticle.getTitle();
    } else if (className.equals(KBComment.class.getName())) {
        KBComment kbComment = KBCommentLocalServiceUtil.getKBComment(activity.getClassPK());
        String kbCommentClassName = kbComment.getClassName();
        if (kbCommentClassName.equals(KBArticle.class.getName())) {
            KBArticle kbArticle = KBArticleLocalServiceUtil.getLatestKBArticle(kbComment.getClassPK(), WorkflowConstants.STATUS_APPROVED);
            title = kbArticle.getTitle();
        } else if (kbCommentClassName.equals(KBTemplate.class.getName())) {
            KBTemplate kbTemplate = KBTemplateLocalServiceUtil.getKBTemplate(kbComment.getClassPK());
            title = kbTemplate.getTitle();
        }
    } else if (className.equals(KBTemplate.class.getName())) {
        KBTemplate kbTemplate = KBTemplateLocalServiceUtil.getKBTemplate(activity.getClassPK());
        title = kbTemplate.getTitle();
    }
    return getJSONValue(activity.getExtraData(), "title", title);
}
Also used : KBComment(com.liferay.knowledgebase.model.KBComment) KBArticle(com.liferay.knowledgebase.model.KBArticle) KBTemplate(com.liferay.knowledgebase.model.KBTemplate)

Example 4 with KBTemplate

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

the class KBTemplateCreateDateComparator method compare.

@Override
public int compare(Object obj1, Object obj2) {
    KBTemplate kbTemplate1 = (KBTemplate) obj1;
    KBTemplate kbTemplate2 = (KBTemplate) obj2;
    int value = DateUtil.compareTo(kbTemplate1.getCreateDate(), kbTemplate2.getCreateDate());
    if (_ascending) {
        return value;
    } else {
        return -value;
    }
}
Also used : KBTemplate(com.liferay.knowledgebase.model.KBTemplate)

Example 5 with KBTemplate

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

the class KBTemplateTitleComparator method compare.

@Override
public int compare(Object obj1, Object obj2) {
    KBTemplate kbTemplate1 = (KBTemplate) obj1;
    KBTemplate kbTemplate2 = (KBTemplate) obj2;
    int value = StringUtil.toLowerCase(kbTemplate1.getTitle()).compareTo(StringUtil.toLowerCase(kbTemplate2.getTitle()));
    if (_ascending) {
        return value;
    } else {
        return -value;
    }
}
Also used : KBTemplate(com.liferay.knowledgebase.model.KBTemplate)

Aggregations

KBTemplate (com.liferay.knowledgebase.model.KBTemplate)40 NoSuchTemplateException (com.liferay.knowledgebase.NoSuchTemplateException)21 StringBundler (com.liferay.portal.kernel.util.StringBundler)17 SystemException (com.liferay.portal.kernel.exception.SystemException)14 Session (com.liferay.portal.kernel.dao.orm.Session)12 SQLQuery (com.liferay.portal.kernel.dao.orm.SQLQuery)10 QueryPos (com.liferay.portal.kernel.dao.orm.QueryPos)9 Query (com.liferay.portal.kernel.dao.orm.Query)8 KBTemplateImpl (com.liferay.knowledgebase.model.impl.KBTemplateImpl)7 ArrayList (java.util.ArrayList)7 UnmodifiableList (com.liferay.portal.kernel.util.UnmodifiableList)6 List (java.util.List)6 FinderPath (com.liferay.portal.kernel.dao.orm.FinderPath)4 KBArticle (com.liferay.knowledgebase.model.KBArticle)3 PortalException (com.liferay.portal.kernel.exception.PortalException)2 JSONObject (com.liferay.portal.kernel.json.JSONObject)2 KBArticleImportException (com.liferay.knowledgebase.KBArticleImportException)1 KBCommentContentException (com.liferay.knowledgebase.KBCommentContentException)1 KBTemplateContentException (com.liferay.knowledgebase.KBTemplateContentException)1 KBTemplateTitleException (com.liferay.knowledgebase.KBTemplateTitleException)1