List of usage examples for com.liferay.portal.kernel.repository.model Folder getRepositoryId
public long getRepositoryId();
From source file:com.liferay.document.library.web.internal.webdav.DLWebDAVStorageImpl.java
License:Open Source License
@Override public Status lockResource(WebDAVRequest webDAVRequest, String owner, long timeout) throws WebDAVException { Resource resource = getResource(webDAVRequest); Lock lock = null;/*from w w w. j a v a 2 s . co m*/ int status = HttpServletResponse.SC_OK; try { if (resource == null) { status = HttpServletResponse.SC_CREATED; HttpServletRequest request = webDAVRequest.getHttpServletRequest(); String[] pathArray = webDAVRequest.getPathArray(); long companyId = webDAVRequest.getCompanyId(); long groupId = webDAVRequest.getGroupId(); long parentFolderId = getParentFolderId(companyId, pathArray); String title = getTitle(pathArray); String extension = FileUtil.getExtension(title); String contentType = getContentType(request, null, title, extension); String description = StringPool.BLANK; String changeLog = StringPool.BLANK; File file = FileUtil.createTempFile(extension); file.createNewFile(); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(isAddGroupPermissions(groupId)); serviceContext.setAddGuestPermissions(true); FileEntry fileEntry = _dlAppService.addFileEntry(groupId, parentFolderId, title, contentType, title, description, changeLog, file, serviceContext); resource = toResource(webDAVRequest, fileEntry, false); } if (resource instanceof DLFileEntryResourceImpl) { FileEntry fileEntry = (FileEntry) resource.getModel(); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAttribute(DL.MANUAL_CHECK_IN_REQUIRED, webDAVRequest.isManualCheckInRequired()); populateServiceContext(serviceContext, fileEntry); _dlAppService.checkOutFileEntry(fileEntry.getFileEntryId(), owner, timeout, serviceContext); lock = fileEntry.getLock(); } else { boolean inheritable = false; long depth = WebDAVUtil.getDepth(webDAVRequest.getHttpServletRequest()); if (depth != 0) { inheritable = true; } Folder folder = (Folder) resource.getModel(); lock = _dlAppService.lockFolder(folder.getRepositoryId(), folder.getFolderId(), owner, inheritable, timeout); } } catch (Exception e) { // DuplicateLock is 423 not 501 if (!(e instanceof DuplicateLockException)) { throw new WebDAVException(e); } status = WebDAVUtil.SC_LOCKED; } return new Status(lock, status); }
From source file:com.liferay.document.library.web.internal.webdav.DLWebDAVStorageImpl.java
License:Open Source License
@Override public boolean unlockResource(WebDAVRequest webDAVRequest, String token) throws WebDAVException { Resource resource = getResource(webDAVRequest); try {/* ww w .ja va 2s. c o m*/ if (resource instanceof DLFileEntryResourceImpl) { FileEntry fileEntry = (FileEntry) resource.getModel(); // Do not allow WebDAV to check in a file entry if it requires a // manual check in if (fileEntry.isManualCheckInRequired()) { return false; } ServiceContext serviceContext = new ServiceContext(); serviceContext.setAttribute(DL.WEBDAV_CHECK_IN_MODE, Boolean.TRUE); _dlAppService.checkInFileEntry(fileEntry.getFileEntryId(), token, serviceContext); if (webDAVRequest.isAppleDoubleRequest()) { _dlAppService.deleteFileEntry(fileEntry.getFileEntryId()); } } else { Folder folder = (Folder) resource.getModel(); _dlAppService.unlockFolder(folder.getRepositoryId(), folder.getParentFolderId(), folder.getName(), token); } return true; } catch (InvalidLockException ile) { if (_log.isWarnEnabled()) { _log.warn(ile.getMessage()); } } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Unable to unlock file entry", e); } } return false; }
From source file:com.liferay.document.library.web.internal.webdav.DLWebDAVStorageImpl.java
License:Open Source License
protected long getFolderId(long companyId, String[] pathArray, boolean parent) throws Exception { long folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID; if (pathArray.length <= 1) { return folderId; }/* w w w .j a v a 2s.c om*/ long groupId = WebDAVUtil.getGroupId(companyId, pathArray); int x = pathArray.length; if (parent) { x--; } for (int i = 2; i < x; i++) { String name = pathArray[i]; Folder folder = _dlAppService.getFolder(groupId, folderId, name); if (groupId == folder.getRepositoryId()) { folderId = folder.getFolderId(); } } return folderId; }
From source file:com.liferay.document.library.web.webdav.DLWebDAVStorageImpl.java
License:Open Source License
@Override public int deleteResource(WebDAVRequest webDAVRequest) throws WebDAVException { try {/*from w ww . ja v a2 s . co m*/ Resource resource = getResource(webDAVRequest); if (resource == null) { if (webDAVRequest.isAppleDoubleRequest()) { return HttpServletResponse.SC_NO_CONTENT; } else { return HttpServletResponse.SC_NOT_FOUND; } } Object model = resource.getModel(); if (model instanceof Folder) { Folder folder = (Folder) model; long folderId = folder.getFolderId(); if ((folder.getModel() instanceof DLFolder) && DLTrashUtil.isTrashEnabled(folder.getGroupId(), folder.getRepositoryId())) { _dlTrashService.moveFolderToTrash(folderId); } else { _dlAppService.deleteFolder(folderId); } } else { FileEntry fileEntry = (FileEntry) model; if (!hasLock(fileEntry, webDAVRequest.getLockUuid()) && (fileEntry.getLock() != null)) { return WebDAVUtil.SC_LOCKED; } long fileEntryId = fileEntry.getFileEntryId(); if ((fileEntry.getModel() instanceof DLFileEntry) && DLTrashUtil.isTrashEnabled(fileEntry.getGroupId(), fileEntry.getRepositoryId())) { _dlTrashService.moveFileEntryToTrash(fileEntryId); } else { _dlAppService.deleteFileEntry(fileEntryId); } } return HttpServletResponse.SC_NO_CONTENT; } catch (PrincipalException pe) { if (_log.isDebugEnabled()) { _log.debug(pe, pe); } return HttpServletResponse.SC_FORBIDDEN; } catch (Exception e) { throw new WebDAVException(e); } }
From source file:com.liferay.document.library.web.webdav.DLWebDAVStorageImpl.java
License:Open Source License
@Override public Status lockResource(WebDAVRequest webDAVRequest, String owner, long timeout) throws WebDAVException { Resource resource = getResource(webDAVRequest); Lock lock = null;//w w w.j av a2 s . com int status = HttpServletResponse.SC_OK; try { if (resource == null) { status = HttpServletResponse.SC_CREATED; HttpServletRequest request = webDAVRequest.getHttpServletRequest(); String[] pathArray = webDAVRequest.getPathArray(); long companyId = webDAVRequest.getCompanyId(); long groupId = webDAVRequest.getGroupId(); long parentFolderId = getParentFolderId(companyId, pathArray); String title = getTitle(pathArray); String extension = FileUtil.getExtension(title); String contentType = getContentType(request, null, title, extension); String description = StringPool.BLANK; String changeLog = StringPool.BLANK; File file = FileUtil.createTempFile(extension); file.createNewFile(); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(isAddGroupPermissions(groupId)); serviceContext.setAddGuestPermissions(true); FileEntry fileEntry = _dlAppService.addFileEntry(groupId, parentFolderId, title, contentType, title, description, changeLog, file, serviceContext); resource = toResource(webDAVRequest, fileEntry, false); } if (resource instanceof DLFileEntryResourceImpl) { FileEntry fileEntry = (FileEntry) resource.getModel(); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAttribute(DL.MANUAL_CHECK_IN_REQUIRED, webDAVRequest.isManualCheckInRequired()); _dlAppService.checkOutFileEntry(fileEntry.getFileEntryId(), owner, timeout, serviceContext); lock = fileEntry.getLock(); } else { boolean inheritable = false; long depth = WebDAVUtil.getDepth(webDAVRequest.getHttpServletRequest()); if (depth != 0) { inheritable = true; } Folder folder = (Folder) resource.getModel(); lock = _dlAppService.lockFolder(folder.getRepositoryId(), folder.getFolderId(), owner, inheritable, timeout); } } catch (Exception e) { // DuplicateLock is 423 not 501 if (!(e instanceof DuplicateLockException)) { throw new WebDAVException(e); } status = WebDAVUtil.SC_LOCKED; } return new Status(lock, status); }
From source file:com.liferay.opensocial.editor.portlet.EditorPortlet.java
License:Open Source License
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);/*from ww w.j av a2s. com*/ 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); }
From source file:com.liferay.opensocial.editor.portlet.EditorPortlet.java
License:Open Source License
protected void serveAddFolder(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception { long parentFolderId = ParamUtil.getLong(resourceRequest, "parentFolderId"); Folder parentFolder = DLAppServiceUtil.getFolder(parentFolderId); String folderName = ParamUtil.getString(resourceRequest, "folderName"); ServiceContext serviceContext = ServiceContextFactory.getInstance(resourceRequest); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); serviceContext.setScopeGroupId(parentFolder.getGroupId()); Folder folder = DLAppServiceUtil.addFolder(parentFolder.getRepositoryId(), parentFolderId, folderName, StringPool.BLANK, serviceContext); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); jsonObject.put("folderId", folder.getFolderId()); writeJSON(resourceRequest, resourceResponse, jsonObject); }
From source file:com.liferay.portlet.documentlibrary.action.FindFolderAction.java
License:Open Source License
@Override protected long getGroupId(long primaryKey) throws Exception { Folder folder = DLAppLocalServiceUtil.getFolder(primaryKey); return folder.getRepositoryId(); }
From source file:com.liferay.portlet.documentlibrary.atom.FileEntryAtomCollectionAdapter.java
License:Open Source License
@Override protected Iterable<FileEntry> doGetFeedEntries(AtomRequestContext atomRequestContext) throws Exception { long folderId = atomRequestContext.getLongParameter("folderId"); long repositoryId = 0; if (folderId != 0) { Folder folder = DLAppServiceUtil.getFolder(folderId); repositoryId = folder.getRepositoryId(); } else {/*from w w w .j ava 2 s . co m*/ repositoryId = atomRequestContext.getLongParameter("repositoryId"); } int count = DLAppServiceUtil.getFileEntriesCount(repositoryId, folderId); AtomPager atomPager = new AtomPager(atomRequestContext, count); AtomUtil.saveAtomPagerInRequest(atomRequestContext, atomPager); return DLAppServiceUtil.getFileEntries(repositoryId, folderId, atomPager.getStart(), atomPager.getEnd() + 1, new EntryNameComparator()); }
From source file:com.liferay.portlet.documentlibrary.atom.FileEntryAtomCollectionAdapter.java
License:Open Source License
@Override protected FileEntry doPostEntry(String title, String summary, String content, Date date, AtomRequestContext atomRequestContext) throws Exception { long folderId = atomRequestContext.getLongParameter("folderId"); long repositoryId = 0; if (folderId != 0) { Folder folder = DLAppServiceUtil.getFolder(folderId); repositoryId = folder.getRepositoryId(); } else {/*w ww. j a va 2 s .c om*/ repositoryId = atomRequestContext.getLongParameter("repositoryId"); } String mimeType = atomRequestContext.getHeader("Media-Content-Type"); if (mimeType == null) { mimeType = MimeTypesUtil.getContentType(title); } byte[] contentDecoded = Base64.decode(content); ByteArrayInputStream contentInputStream = new ByteArrayInputStream(contentDecoded); ServiceContext serviceContext = new ServiceContext(); FileEntry fileEntry = DLAppServiceUtil.addFileEntry(repositoryId, folderId, title, mimeType, title, summary, null, contentInputStream, contentDecoded.length, serviceContext); return fileEntry; }