Search in sources :

Example 26 with FileEntry

use of com.liferay.portal.kernel.repository.model.FileEntry in project liferay-ide by liferay.

the class LiferayMediaItemService method doUpdateMediaItem.

protected void doUpdateMediaItem(UserId userId, String appId, String albumId, String mediaItemId, MediaItem mediaItem, SecurityToken securityToken) throws Exception {
    long userIdLong = GetterUtil.getLong(userId.getUserId(securityToken));
    User user = UserLocalServiceUtil.getUserById(userIdLong);
    if (!ShindigUtil.isValidUser(user)) {
        return;
    }
    Group group = user.getGroup();
    long groupIdLong = group.getGroupId();
    Http.Options options = new Http.Options();
    options.setLocation(mediaItem.getUrl());
    byte[] byteArray = HttpUtil.URLtoByteArray(options);
    String fileName = getFileName(mediaItem, options);
    String contentType = MimeTypesUtil.getContentType(fileName);
    ServiceContext serviceContext = new ServiceContext();
    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);
    serviceContext.setAttribute("sourceFileName", fileName);
    serviceContext.setExpandoBridgeAttributes(SerializerUtil.toExpandoAttributes(mediaItem, _MEDIA_ITEM_FIELDS, user.getCompanyId(), DLFileEntry.class.getName()));
    serviceContext.setScopeGroupId(groupIdLong);
    if (mediaItemId == null) {
        long albumIdLong = GetterUtil.getLong(albumId);
        DLAppServiceUtil.addFileEntry(groupIdLong, albumIdLong, fileName, contentType, mediaItem.getTitle(), mediaItem.getDescription(), StringPool.BLANK, byteArray, serviceContext);
    } else {
        long mediaItemIdLong = GetterUtil.getLong(mediaItemId);
        FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(mediaItemIdLong);
        serviceContext.setCreateDate(fileEntry.getCreateDate());
        serviceContext.setModifiedDate(fileEntry.getModifiedDate());
        DLAppServiceUtil.updateFileEntry(fileEntry.getFileEntryId(), fileName, contentType, mediaItem.getTitle(), mediaItem.getDescription(), StringPool.BLANK, false, byteArray, serviceContext);
    }
}
Also used : Group(com.liferay.portal.model.Group) CollectionOptions(org.apache.shindig.social.opensocial.spi.CollectionOptions) User(com.liferay.portal.model.User) ServiceContext(com.liferay.portal.service.ServiceContext) Http(com.liferay.portal.kernel.util.Http) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry)

Example 27 with FileEntry

use of com.liferay.portal.kernel.repository.model.FileEntry in project liferay-ide by liferay.

the class EditorPortlet method serveGetFileEntryContent.

protected void serveGetFileEntryContent(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception {
    long fileEntryId = ParamUtil.getLong(resourceRequest, "fileEntryId");
    FileEntry fileEntry = DLAppServiceUtil.getFileEntry(fileEntryId);
    String content = StringUtil.read(fileEntry.getContentStream());
    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
    jsonObject.put("content", content);
    writeJSON(resourceRequest, resourceResponse, jsonObject);
}
Also used : JSONObject(com.liferay.portal.kernel.json.JSONObject) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry)

Example 28 with FileEntry

use of com.liferay.portal.kernel.repository.model.FileEntry in project liferay-ide by liferay.

the class EditorPortlet method serveAddFileEntry.

protected void serveAddFileEntry(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);
    long folderId = ParamUtil.getLong(resourceRequest, "folderId");
    Folder folder = DLAppServiceUtil.getFolder(folderId);
    String fileEntryTitle = ParamUtil.getString(resourceRequest, "fileEntryTitle");
    String content = ParamUtil.getString(resourceRequest, "content");
    byte[] bytes = content.getBytes(StringPool.UTF8);
    ServiceContext serviceContext = ServiceContextFactory.getInstance(resourceRequest);
    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);
    serviceContext.setAttribute("sourceFileName", fileEntryTitle);
    serviceContext.setScopeGroupId(folder.getGroupId());
    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
    FileEntry fileEntry = DLAppServiceUtil.addFileEntry(folder.getRepositoryId(), folderId, fileEntryTitle, resourceRequest.getContentType(), fileEntryTitle, StringPool.BLANK, StringPool.BLANK, bytes, serviceContext);
    jsonObject.put("fileEntryId", fileEntry.getFileEntryId());
    String portalURL = PortalUtil.getPortalURL(themeDisplay);
    String fileEntryURL = ShindigUtil.getFileEntryURL(portalURL, fileEntry.getFileEntryId());
    jsonObject.put("fileEntryURL", fileEntryURL);
    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) Folder(com.liferay.portal.kernel.repository.model.Folder) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay)

Example 29 with FileEntry

use of com.liferay.portal.kernel.repository.model.FileEntry in project liferay-ide by liferay.

the class EditorPortlet method serveUpdateFileEntryTitle.

protected void serveUpdateFileEntryTitle(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception {
    long fileEntryId = ParamUtil.getLong(resourceRequest, "fileEntryId");
    FileEntry fileEntry = DLAppServiceUtil.getFileEntry(fileEntryId);
    String fileEntryTitle = ParamUtil.getString(resourceRequest, "fileEntryTitle");
    byte[] bytes = null;
    ServiceContext serviceContext = ServiceContextFactory.getInstance(resourceRequest);
    DLAppServiceUtil.updateFileEntry(fileEntryId, fileEntryTitle, resourceRequest.getContentType(), fileEntryTitle, 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 30 with FileEntry

use of com.liferay.portal.kernel.repository.model.FileEntry 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)

Aggregations

FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)34 DLFileEntry (com.liferay.portlet.documentlibrary.model.DLFileEntry)15 PortalException (com.liferay.portal.kernel.exception.PortalException)8 Folder (com.liferay.portal.kernel.repository.model.Folder)7 ServiceContext (com.liferay.portal.service.ServiceContext)6 IOException (java.io.IOException)6 SystemException (com.liferay.portal.kernel.exception.SystemException)5 JSONObject (com.liferay.portal.kernel.json.JSONObject)5 Element (com.liferay.portal.kernel.xml.Element)5 User (com.liferay.portal.model.User)5 NoSuchFileEntryException (com.liferay.portlet.documentlibrary.NoSuchFileEntryException)5 InputStream (java.io.InputStream)5 StringBundler (com.liferay.portal.kernel.util.StringBundler)4 ArrayList (java.util.ArrayList)4 NoSuchGroupException (com.liferay.portal.NoSuchGroupException)3 RepositoryException (com.liferay.portal.kernel.repository.RepositoryException)3 FileVersion (com.liferay.portal.kernel.repository.model.FileVersion)3 Group (com.liferay.portal.model.Group)3 Repository (com.liferay.portal.model.Repository)3 PrincipalException (com.liferay.portal.security.auth.PrincipalException)3