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