Search in sources :

Example 1 with ServiceContext

use of com.liferay.portal.service.ServiceContext 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)

Example 2 with ServiceContext

use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.

the class KBCommentStagedModelDataHandler method doImportStagedModel.

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, KBComment kbComment) throws Exception {
    long userId = portletDataContext.getUserId(kbComment.getUserUuid());
    Map<Long, Long> relatedClassPKs = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(kbComment.getClassName());
    long newClassPK = MapUtil.getLong(relatedClassPKs, kbComment.getClassPK(), kbComment.getClassPK());
    ServiceContext serviceContext = portletDataContext.createServiceContext(kbComment);
    KBComment importedKBComment = null;
    if (portletDataContext.isDataStrategyMirror()) {
        KBComment existingKBComment = KBCommentUtil.fetchByUUID_G(kbComment.getUuid(), portletDataContext.getScopeGroupId());
        if (existingKBComment == null) {
            serviceContext.setUuid(kbComment.getUuid());
            importedKBComment = KBCommentLocalServiceUtil.addKBComment(userId, kbComment.getClassNameId(), newClassPK, kbComment.getContent(), kbComment.getUserRating(), serviceContext);
        } else {
            importedKBComment = KBCommentLocalServiceUtil.updateKBComment(existingKBComment.getKbCommentId(), kbComment.getClassNameId(), newClassPK, kbComment.getContent(), kbComment.getUserRating(), kbComment.getStatus(), serviceContext);
        }
    } else {
        importedKBComment = KBCommentLocalServiceUtil.addKBComment(userId, kbComment.getClassNameId(), newClassPK, kbComment.getContent(), kbComment.getUserRating(), serviceContext);
    }
    portletDataContext.importClassedModel(kbComment, importedKBComment);
}
Also used : KBComment(com.liferay.knowledgebase.model.KBComment) ServiceContext(com.liferay.portal.service.ServiceContext) Map(java.util.Map)

Example 3 with ServiceContext

use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.

the class KBFolderStagedModelDataHandler method doImportStagedModel.

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, KBFolder kbFolder) throws Exception {
    long userId = portletDataContext.getUserId(kbFolder.getUserUuid());
    if (kbFolder.getParentKBFolderId() != KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
        StagedModelDataHandlerUtil.importReferenceStagedModels(portletDataContext, kbFolder, KBFolder.class);
    }
    ServiceContext serviceContext = portletDataContext.createServiceContext(kbFolder);
    KBFolder importedKBFolder = null;
    if (portletDataContext.isDataStrategyMirror()) {
        KBFolder existingKBFolder = KBFolderUtil.fetchByUUID_G(kbFolder.getUuid(), portletDataContext.getScopeGroupId());
        if (existingKBFolder == null) {
            importedKBFolder = KBFolderLocalServiceUtil.addKBFolder(userId, portletDataContext.getScopeGroupId(), kbFolder.getClassNameId(), kbFolder.getParentKBFolderId(), kbFolder.getName(), kbFolder.getDescription(), serviceContext);
        } else {
            importedKBFolder = KBFolderLocalServiceUtil.updateKBFolder(kbFolder.getClassNameId(), kbFolder.getParentKBFolderId(), kbFolder.getKbFolderId(), kbFolder.getName(), kbFolder.getDescription());
        }
    } else {
        importedKBFolder = KBFolderLocalServiceUtil.addKBFolder(userId, portletDataContext.getScopeGroupId(), kbFolder.getClassNameId(), kbFolder.getParentKBFolderId(), kbFolder.getName(), kbFolder.getDescription(), serviceContext);
    }
    portletDataContext.importClassedModel(kbFolder, importedKBFolder);
    Map<Long, Long> kbFolderIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(KBFolder.class);
    kbFolderIds.put(kbFolder.getKbFolderId(), importedKBFolder.getKbFolderId());
}
Also used : KBFolder(com.liferay.knowledgebase.model.KBFolder) ServiceContext(com.liferay.portal.service.ServiceContext) Map(java.util.Map)

Example 4 with ServiceContext

use of com.liferay.portal.service.ServiceContext 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 5 with ServiceContext

use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.

the class AdminPortlet method importFile.

public void importFile(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
    InputStream inputStream = null;
    try {
        ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
        UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);
        long parentKBFolderId = ParamUtil.getLong(uploadPortletRequest, "parentKBFolderId", KBFolderConstants.DEFAULT_PARENT_FOLDER_ID);
        String fileName = uploadPortletRequest.getFileName("file");
        if (Validator.isNull(fileName)) {
            throw new KBArticleImportException("File name is null");
        }
        boolean prioritizeByNumericalPrefix = ParamUtil.getBoolean(uploadPortletRequest, "prioritizeByNumericalPrefix");
        inputStream = uploadPortletRequest.getFileAsStream("file");
        ServiceContext serviceContext = ServiceContextFactory.getInstance(AdminPortlet.class.getName(), actionRequest);
        serviceContext.setGuestPermissions(new String[] { ActionKeys.VIEW });
        int kbArticleCount = KBArticleServiceUtil.addKBArticlesMarkdown(themeDisplay.getScopeGroupId(), parentKBFolderId, fileName, prioritizeByNumericalPrefix, inputStream, serviceContext);
        SessionMessages.add(actionRequest, "importedKBArticlesCount", kbArticleCount);
    } catch (KBArticleImportException kbaie) {
        SessionErrors.add(actionRequest, kbaie.getClass(), kbaie);
    } finally {
        StreamUtil.cleanUp(inputStream);
    }
}
Also used : InputStream(java.io.InputStream) ServiceContext(com.liferay.portal.service.ServiceContext) KBArticleImportException(com.liferay.knowledgebase.KBArticleImportException) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay) UploadPortletRequest(com.liferay.portal.kernel.upload.UploadPortletRequest)

Aggregations

ServiceContext (com.liferay.portal.service.ServiceContext)57 User (com.liferay.portal.model.User)11 PrincipalException (com.liferay.portal.security.auth.PrincipalException)11 InputStream (java.io.InputStream)11 AlbumNameException (org.liferay.jukebox.AlbumNameException)9 ArtistNameException (org.liferay.jukebox.ArtistNameException)9 DuplicatedSongException (org.liferay.jukebox.DuplicatedSongException)9 SongNameException (org.liferay.jukebox.SongNameException)9 UploadPortletRequest (com.liferay.portal.kernel.upload.UploadPortletRequest)8 Song (org.liferay.jukebox.model.Song)8 ThemeDisplay (com.liferay.portal.theme.ThemeDisplay)7 Date (java.util.Date)7 SystemException (com.liferay.portal.kernel.exception.SystemException)6 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)6 PortalException (com.liferay.portal.kernel.exception.PortalException)5 JSONObject (com.liferay.portal.kernel.json.JSONObject)5 Artist (org.liferay.jukebox.model.Artist)5 Gadget (com.liferay.opensocial.model.Gadget)4 Folder (com.liferay.portal.kernel.repository.model.Folder)4 Element (com.liferay.portal.kernel.xml.Element)4