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);
}
}
}
Aggregations