Search in sources :

Example 1 with DuplicateFileException

use of com.liferay.portlet.documentlibrary.DuplicateFileException in project liferay-ide by liferay.

the class KBArticleStagedModelDataHandler method importKBArticleAttachments.

protected void importKBArticleAttachments(PortletDataContext portletDataContext, KBArticle kbArticle, KBArticle importedKBArticle) throws Exception {
    List<Element> dlFileEntryElements = portletDataContext.getReferenceDataElements(kbArticle, DLFileEntry.class);
    ServiceContext serviceContext = new ServiceContext();
    serviceContext.setCompanyId(portletDataContext.getCompanyId());
    serviceContext.setScopeGroupId(portletDataContext.getScopeGroupId());
    InputStream inputStream = null;
    for (Element dlFileEntryElement : dlFileEntryElements) {
        try {
            byte[] bytes = portletDataContext.getZipEntryAsByteArray(dlFileEntryElement.attributeValue("path"));
            inputStream = new UnsyncByteArrayInputStream(bytes);
            String fileName = dlFileEntryElement.attributeValue("file-name");
            String mimeType = KnowledgeBaseUtil.getMimeType(bytes, fileName);
            PortletFileRepositoryUtil.addPortletFileEntry(portletDataContext.getScopeGroupId(), portletDataContext.getUserId(importedKBArticle.getUserUuid()), KBArticle.class.getName(), importedKBArticle.getClassPK(), PortletKeys.KNOWLEDGE_BASE_ADMIN, importedKBArticle.getAttachmentsFolderId(), inputStream, fileName, mimeType, true);
        } catch (DuplicateFileException dfe) {
            continue;
        } finally {
            StreamUtil.cleanUp(inputStream);
        }
    }
}
Also used : KBArticle(com.liferay.knowledgebase.model.KBArticle) DuplicateFileException(com.liferay.portlet.documentlibrary.DuplicateFileException) ServiceContext(com.liferay.portal.service.ServiceContext) UnsyncByteArrayInputStream(com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream) InputStream(java.io.InputStream) Element(com.liferay.portal.kernel.xml.Element) UnsyncByteArrayInputStream(com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream)

Aggregations

KBArticle (com.liferay.knowledgebase.model.KBArticle)1 UnsyncByteArrayInputStream (com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream)1 Element (com.liferay.portal.kernel.xml.Element)1 ServiceContext (com.liferay.portal.service.ServiceContext)1 DuplicateFileException (com.liferay.portlet.documentlibrary.DuplicateFileException)1 InputStream (java.io.InputStream)1