Search in sources :

Example 51 with ServiceContext

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

the class EditorPortlet method serveUpdateFileEntryContent.

protected void serveUpdateFileEntryContent(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception {
    long fileEntryId = ParamUtil.getLong(resourceRequest, "fileEntryId");
    FileEntry fileEntry = DLAppServiceUtil.getFileEntry(fileEntryId);
    String content = ParamUtil.getString(resourceRequest, "content");
    byte[] bytes = content.getBytes(StringPool.UTF8);
    ServiceContext serviceContext = ServiceContextFactory.getInstance(resourceRequest);
    DLAppServiceUtil.updateFileEntry(fileEntryId, fileEntry.getTitle(), resourceRequest.getContentType(), fileEntry.getTitle(), fileEntry.getDescription(), StringPool.BLANK, false, bytes, serviceContext);
    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
    writeJSON(resourceRequest, resourceResponse, jsonObject);
}
Also used : JSONObject(com.liferay.portal.kernel.json.JSONObject) ServiceContext(com.liferay.portal.service.ServiceContext) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry)

Example 52 with ServiceContext

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

the class ShindigUtil method getGadgetEditorRootFolder.

public static Folder getGadgetEditorRootFolder(long repositoryId) throws Exception {
    Folder folder = null;
    try {
        folder = DLAppServiceUtil.getFolder(repositoryId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, _GADGET_EDITOR_ROOT_FOLDER_NAME);
    } catch (Exception e) {
    }
    if (folder == null) {
        ServiceContext serviceContext = new ServiceContext();
        serviceContext.setGroupPermissions(new String[] { ActionKeys.ADD_DOCUMENT, ActionKeys.DELETE, ActionKeys.UPDATE, ActionKeys.VIEW });
        serviceContext.setGuestPermissions(new String[] { ActionKeys.VIEW });
        serviceContext.setScopeGroupId(repositoryId);
        folder = DLAppServiceUtil.addFolder(repositoryId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, _GADGET_EDITOR_ROOT_FOLDER_NAME, StringPool.BLANK, serviceContext);
    }
    return folder;
}
Also used : ServiceContext(com.liferay.portal.service.ServiceContext) Folder(com.liferay.portal.kernel.repository.model.Folder) ProcessingException(org.apache.shindig.gadgets.process.ProcessingException) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) GadgetURLException(com.liferay.opensocial.GadgetURLException)

Example 53 with ServiceContext

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

the class KBArticleStagedModelDataHandler method doImportStagedModel.

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, KBArticle kbArticle) throws Exception {
    long userId = portletDataContext.getUserId(kbArticle.getUserUuid());
    if (kbArticle.getParentResourcePrimKey() != KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
        if (kbArticle.getClassNameId() == kbArticle.getParentResourceClassNameId()) {
            StagedModelDataHandlerUtil.importReferenceStagedModels(portletDataContext, kbArticle, KBArticle.class);
        } else {
            StagedModelDataHandlerUtil.importReferenceStagedModels(portletDataContext, kbArticle, KBFolder.class);
        }
    }
    Map<Long, Long> kbArticleResourcePrimKeys = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(KBArticle.class);
    long parentResourcePrimKey = MapUtil.getLong(kbArticleResourcePrimKeys, kbArticle.getParentResourcePrimKey(), KBFolderConstants.DEFAULT_PARENT_FOLDER_ID);
    long resourcePrimaryKey = MapUtil.getLong(kbArticleResourcePrimKeys, kbArticle.getResourcePrimKey(), 0);
    if (parentResourcePrimKey == KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
        Map<Long, Long> kbFolderResourcePrimKeys = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(KBFolder.class);
        parentResourcePrimKey = MapUtil.getLong(kbFolderResourcePrimKeys, kbArticle.getParentResourcePrimKey(), KBFolderConstants.DEFAULT_PARENT_FOLDER_ID);
    }
    String[] sections = AdminUtil.unescapeSections(kbArticle.getSections());
    ServiceContext serviceContext = portletDataContext.createServiceContext(kbArticle);
    KBArticle importedKBArticle = null;
    if (portletDataContext.isDataStrategyMirror()) {
        KBArticle existingKBArticle = KBArticleUtil.fetchByR_V(resourcePrimaryKey, kbArticle.getVersion());
        if (existingKBArticle == null) {
            existingKBArticle = KBArticleUtil.fetchByUUID_G(kbArticle.getUuid(), portletDataContext.getScopeGroupId());
        }
        if (existingKBArticle == null) {
            serviceContext.setUuid(kbArticle.getUuid());
            existingKBArticle = KBArticleLocalServiceUtil.fetchLatestKBArticle(resourcePrimaryKey, WorkflowConstants.STATUS_ANY);
            if (existingKBArticle == null) {
                importedKBArticle = KBArticleLocalServiceUtil.addKBArticle(userId, kbArticle.getParentResourceClassNameId(), parentResourcePrimKey, kbArticle.getTitle(), kbArticle.getUrlTitle(), kbArticle.getContent(), kbArticle.getDescription(), kbArticle.getSourceURL(), sections, null, serviceContext);
                KBArticleLocalServiceUtil.updatePriority(importedKBArticle.getResourcePrimKey(), kbArticle.getPriority());
            } else {
                KBArticleLocalServiceUtil.updateKBArticle(userId, existingKBArticle.getResourcePrimKey(), kbArticle.getTitle(), kbArticle.getContent(), kbArticle.getDescription(), kbArticle.getSourceURL(), sections, null, null, serviceContext);
                KBArticleLocalServiceUtil.moveKBArticle(userId, existingKBArticle.getResourcePrimKey(), existingKBArticle.getParentResourceClassNameId(), parentResourcePrimKey, kbArticle.getPriority());
                importedKBArticle = KBArticleLocalServiceUtil.getLatestKBArticle(existingKBArticle.getResourcePrimKey(), WorkflowConstants.STATUS_APPROVED);
            }
        } else {
            importedKBArticle = existingKBArticle;
        }
    } else {
        importedKBArticle = KBArticleLocalServiceUtil.addKBArticle(userId, kbArticle.getParentResourceClassNameId(), parentResourcePrimKey, kbArticle.getTitle(), kbArticle.getUrlTitle(), kbArticle.getContent(), kbArticle.getDescription(), kbArticle.getSourceURL(), sections, null, serviceContext);
        KBArticleLocalServiceUtil.updatePriority(importedKBArticle.getResourcePrimKey(), kbArticle.getPriority());
    }
    importKBArticleAttachments(portletDataContext, kbArticle, importedKBArticle);
    portletDataContext.importClassedModel(kbArticle, importedKBArticle);
    if (!kbArticle.isMain()) {
        kbArticleResourcePrimKeys.put(kbArticle.getResourcePrimKey(), importedKBArticle.getResourcePrimKey());
    }
}
Also used : KBFolder(com.liferay.knowledgebase.model.KBFolder) KBArticle(com.liferay.knowledgebase.model.KBArticle) ServiceContext(com.liferay.portal.service.ServiceContext) Map(java.util.Map)

Example 54 with ServiceContext

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

the class KBArticleWorkflowHandler method updateStatus.

@Override
public KBArticle updateStatus(int status, Map<String, Serializable> workflowContext) throws PortalException, SystemException {
    long userId = GetterUtil.getLong((String) workflowContext.get(WorkflowConstants.CONTEXT_USER_ID));
    long resourcePrimKey = GetterUtil.getLong((String) workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_PK));
    ServiceContext serviceContext = (ServiceContext) workflowContext.get("serviceContext");
    return KBArticleLocalServiceUtil.updateStatus(userId, resourcePrimKey, status, serviceContext);
}
Also used : ServiceContext(com.liferay.portal.service.ServiceContext)

Example 55 with ServiceContext

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

the class AddGoogleDocsFileEntryTypeAction method addGoogleDocsFileEntryType.

protected void addGoogleDocsFileEntryType(long userId, long groupId) throws PortalException, SystemException {
    Map<Locale, String> nameMap = new HashMap<Locale, String>();
    Locale locale = LocaleUtil.getDefault();
    nameMap.put(locale, GoogleDocsConstants.GOOGLE_DOCS_FILE_ENTRY_TYPE_NAME);
    Map<Locale, String> descriptionMap = new HashMap<Locale, String>();
    descriptionMap.put(locale, GoogleDocsConstants.GOOGLE_DOCS_FILE_ENTRY_TYPE_NAME);
    ServiceContext serviceContext = new ServiceContext();
    Class<?> clazz = getClass();
    String xsd = ContentUtil.get(clazz.getClassLoader(), "com/liferay/google/docs/hook/event/dependencies" + "/google-docs-file-entry-type-xsd.xml");
    serviceContext.setAttribute("xsd", xsd);
    DLFileEntryTypeLocalServiceUtil.addFileEntryType(userId, groupId, GoogleDocsConstants.GOOGLE_DOCS_FILE_ENTRY_TYPE_KEY, nameMap, descriptionMap, new long[0], serviceContext);
}
Also used : Locale(java.util.Locale) HashMap(java.util.HashMap) ServiceContext(com.liferay.portal.service.ServiceContext)

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