use of com.liferay.knowledgebase.admin.importer.util.KBArticleMarkdownConverter in project liferay-ide by liferay.
the class KBArticleImporter method addKBArticleMarkdown.
protected KBArticle addKBArticleMarkdown(long userId, long groupId, long parentKBFolderId, long parentResourceClassNameId, long parentResourcePrimaryKey, String markdown, String fileEntryName, ZipReader zipReader, Map<String, String> metadata, PrioritizationStrategy prioritizationStrategy, ServiceContext serviceContext) throws KBArticleImportException, SystemException {
if (Validator.isNull(markdown)) {
throw new KBArticleImportException("Markdown is null for file entry " + fileEntryName);
}
KBArticleMarkdownConverter kbArticleMarkdownConverter = new KBArticleMarkdownConverter(markdown, fileEntryName, metadata);
String urlTitle = kbArticleMarkdownConverter.getUrlTitle();
KBArticle kbArticle = KBArticleLocalServiceUtil.fetchKBArticleByUrlTitle(groupId, parentKBFolderId, urlTitle);
boolean newKBArticle = false;
if (kbArticle == null) {
newKBArticle = true;
}
try {
if (kbArticle == null) {
int workflowAction = serviceContext.getWorkflowAction();
serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT);
kbArticle = KBArticleLocalServiceUtil.addKBArticle(userId, parentResourceClassNameId, parentResourcePrimaryKey, kbArticleMarkdownConverter.getTitle(), urlTitle, markdown, null, kbArticleMarkdownConverter.getSourceURL(), null, null, serviceContext);
serviceContext.setWorkflowAction(workflowAction);
}
} catch (Exception e) {
StringBundler sb = new StringBundler(4);
sb.append("Unable to add basic KB article for file entry ");
sb.append(fileEntryName);
sb.append(": ");
sb.append(e.getLocalizedMessage());
throw new KBArticleImportException(sb.toString(), e);
}
try {
String html = kbArticleMarkdownConverter.processAttachmentsReferences(userId, kbArticle, zipReader, new HashMap<String, FileEntry>());
kbArticle = KBArticleLocalServiceUtil.updateKBArticle(userId, kbArticle.getResourcePrimKey(), kbArticleMarkdownConverter.getTitle(), html, kbArticle.getDescription(), kbArticleMarkdownConverter.getSourceURL(), null, null, null, serviceContext);
if (newKBArticle) {
prioritizationStrategy.addKBArticle(kbArticle, fileEntryName);
} else {
prioritizationStrategy.updateKBArticle(kbArticle, fileEntryName);
}
return kbArticle;
} catch (Exception e) {
StringBundler sb = new StringBundler(4);
sb.append("Unable to update KB article for file entry ");
sb.append(fileEntryName);
sb.append(": ");
sb.append(e.getLocalizedMessage());
throw new KBArticleImportException(sb.toString(), e);
}
}
Aggregations