Search in sources :

Example 16 with KBTemplate

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

the class KBTemplateLocalServiceImpl method updateKBTemplate.

@Override
public KBTemplate updateKBTemplate(long kbTemplateId, String title, String content, ServiceContext serviceContext) throws PortalException, SystemException {
    // KB template
    validate(title, content);
    KBTemplate kbTemplate = kbTemplatePersistence.findByPrimaryKey(kbTemplateId);
    kbTemplate.setModifiedDate(serviceContext.getModifiedDate(null));
    kbTemplate.setTitle(title);
    kbTemplate.setContent(content);
    kbTemplatePersistence.update(kbTemplate);
    if ((serviceContext.getGroupPermissions() != null) || (serviceContext.getGuestPermissions() != null)) {
        updateKBTemplateResources(kbTemplate, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
    }
    // Social
    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();
    extraDataJSONObject.put("title", kbTemplate.getTitle());
    socialActivityLocalService.addActivity(kbTemplate.getUserId(), kbTemplate.getGroupId(), KBTemplate.class.getName(), kbTemplateId, AdminActivityKeys.UPDATE_KB_TEMPLATE, extraDataJSONObject.toString(), 0);
    return kbTemplate;
}
Also used : JSONObject(com.liferay.portal.kernel.json.JSONObject) KBTemplate(com.liferay.knowledgebase.model.KBTemplate)

Example 17 with KBTemplate

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

the class KBTemplateModelImpl method equals.

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (!(obj instanceof KBTemplate)) {
        return false;
    }
    KBTemplate kbTemplate = (KBTemplate) obj;
    long primaryKey = kbTemplate.getPrimaryKey();
    if (getPrimaryKey() == primaryKey) {
        return true;
    } else {
        return false;
    }
}
Also used : KBTemplate(com.liferay.knowledgebase.model.KBTemplate)

Example 18 with KBTemplate

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

the class KBCommentLocalServiceImpl method putTitle.

protected void putTitle(JSONObject jsonObject, KBComment kbComment) {
    KBArticle kbArticle = null;
    KBTemplate kbTemplate = null;
    String className = kbComment.getClassName();
    try {
        if (className.equals(KBArticle.class.getName())) {
            kbArticle = KBArticleLocalServiceUtil.getLatestKBArticle(kbComment.getClassPK(), WorkflowConstants.STATUS_APPROVED);
            jsonObject.put("title", kbArticle.getTitle());
        } else if (className.equals(KBTemplate.class.getName())) {
            kbTemplate = KBTemplateLocalServiceUtil.getKBTemplate(kbComment.getClassPK());
            jsonObject.put("title", kbTemplate.getTitle());
        }
    } catch (Exception e) {
        _log.error(e);
    }
}
Also used : KBArticle(com.liferay.knowledgebase.model.KBArticle) KBTemplate(com.liferay.knowledgebase.model.KBTemplate) KBCommentContentException(com.liferay.knowledgebase.KBCommentContentException) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException)

Example 19 with KBTemplate

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

the class KBTemplateLocalServiceImpl method deleteKBTemplates.

@Override
public void deleteKBTemplates(long[] kbTemplateIds) throws PortalException, SystemException {
    for (long kbTemplateId : kbTemplateIds) {
        KBTemplate kbTemplate = null;
        try {
            kbTemplate = kbTemplatePersistence.findByPrimaryKey(kbTemplateId);
        } catch (NoSuchTemplateException nste) {
            continue;
        }
        kbTemplateLocalService.deleteKBTemplate(kbTemplate);
    }
}
Also used : NoSuchTemplateException(com.liferay.knowledgebase.NoSuchTemplateException) KBTemplate(com.liferay.knowledgebase.model.KBTemplate)

Example 20 with KBTemplate

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

the class KBTemplateServiceImpl method getKBTemplateSearchDisplay.

@Override
public KBTemplateSearchDisplay getKBTemplateSearchDisplay(long groupId, String title, String content, Date startDate, Date endDate, boolean andOperator, int[] curStartValues, int cur, int delta, OrderByComparator orderByComparator) throws PortalException, SystemException {
    // See LPS-9546
    int start = 0;
    if (curStartValues.length > (cur - SearchContainer.DEFAULT_CUR)) {
        start = curStartValues[cur - SearchContainer.DEFAULT_CUR];
        curStartValues = ArrayUtil.subset(curStartValues, 0, cur - SearchContainer.DEFAULT_CUR + 1);
    } else {
        cur = SearchContainer.DEFAULT_CUR;
        curStartValues = new int[] { 0 };
    }
    int end = start + _INTERVAL;
    List<KBTemplate> kbTemplates = new ArrayList<KBTemplate>();
    int curStartValue = 0;
    while (curStartValue == 0) {
        List<KBTemplate> curKBTemplates = kbTemplateLocalService.search(groupId, title, content, startDate, endDate, andOperator, start, end, orderByComparator);
        if (curKBTemplates.isEmpty()) {
            break;
        }
        for (int i = 0; i < curKBTemplates.size(); i++) {
            KBTemplate curKBTemplate = curKBTemplates.get(i);
            if (!KBTemplatePermission.contains(getPermissionChecker(), curKBTemplate, ActionKeys.VIEW)) {
                continue;
            }
            if (kbTemplates.size() == delta) {
                curStartValue = start + i;
                break;
            }
            kbTemplates.add(curKBTemplate);
        }
        start = start + _INTERVAL;
        end = start + _INTERVAL;
    }
    int total = ((cur - 1) * delta) + kbTemplates.size();
    if (curStartValue > 0) {
        curStartValues = ArrayUtil.append(curStartValues, curStartValue);
        total = total + 1;
    }
    return new KBTemplateSearchDisplayImpl(kbTemplates, total, curStartValues);
}
Also used : KBTemplateSearchDisplayImpl(com.liferay.knowledgebase.model.impl.KBTemplateSearchDisplayImpl) ArrayList(java.util.ArrayList) 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