List of usage examples for com.liferay.portal.kernel.webdav WebDAVUtil getGroupId
public static long getGroupId(long companyId, String[] pathArray) throws WebDAVException
From source file:com.liferay.document.library.web.internal.webdav.DLWebDAVStorageImpl.java
License:Open Source License
@Override public int copyCollectionResource(WebDAVRequest webDAVRequest, Resource resource, String destination, boolean overwrite, long depth) throws WebDAVException { try {/* w w w . j av a 2 s . co m*/ String[] destinationArray = WebDAVUtil.getPathArray(destination, true); long companyId = webDAVRequest.getCompanyId(); long parentFolderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID; try { parentFolderId = getParentFolderId(companyId, destinationArray); } catch (NoSuchFolderException nsfe) { if (_log.isDebugEnabled()) { _log.debug(nsfe, nsfe); } return HttpServletResponse.SC_CONFLICT; } Folder folder = (Folder) resource.getModel(); long groupId = WebDAVUtil.getGroupId(companyId, destination); String name = WebDAVUtil.getResourceName(destinationArray); String description = folder.getDescription(); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(isAddGroupPermissions(groupId)); serviceContext.setAddGuestPermissions(true); int status = HttpServletResponse.SC_CREATED; if (overwrite) { if (deleteResource(groupId, parentFolderId, name, webDAVRequest.getLockUuid())) { status = HttpServletResponse.SC_NO_CONTENT; } } if (depth == 0) { _dlAppService.addFolder(groupId, parentFolderId, name, description, serviceContext); } else { _dlAppService.copyFolder(groupId, folder.getFolderId(), parentFolderId, name, description, serviceContext); } return status; } catch (DuplicateFolderNameException dfne) { if (_log.isDebugEnabled()) { _log.debug(dfne, dfne); } return HttpServletResponse.SC_PRECONDITION_FAILED; } 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.internal.webdav.DLWebDAVStorageImpl.java
License:Open Source License
@Override public int copySimpleResource(WebDAVRequest webDAVRequest, Resource resource, String destination, boolean overwrite) throws WebDAVException { File file = null;/* w w w . j a va2 s .c om*/ try { String[] destinationArray = WebDAVUtil.getPathArray(destination, true); long companyId = webDAVRequest.getCompanyId(); long parentFolderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID; try { parentFolderId = getParentFolderId(companyId, destinationArray); } catch (NoSuchFolderException nsfe) { if (_log.isDebugEnabled()) { _log.debug(nsfe, nsfe); } return HttpServletResponse.SC_CONFLICT; } FileEntry fileEntry = (FileEntry) resource.getModel(); long groupId = WebDAVUtil.getGroupId(companyId, destination); String mimeType = fileEntry.getMimeType(); String title = getTitle(destinationArray); String description = fileEntry.getDescription(); String changeLog = StringPool.BLANK; InputStream is = fileEntry.getContentStream(); file = FileUtil.createTempFile(is); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(isAddGroupPermissions(groupId)); serviceContext.setAddGuestPermissions(true); int status = HttpServletResponse.SC_CREATED; if (overwrite) { if (deleteResource(groupId, parentFolderId, title, webDAVRequest.getLockUuid())) { status = HttpServletResponse.SC_NO_CONTENT; } } _dlAppService.addFileEntry(groupId, parentFolderId, title, mimeType, title, description, changeLog, file, serviceContext); return status; } catch (DuplicateFileEntryException dfee) { if (_log.isDebugEnabled()) { _log.debug(dfee, dfee); } return HttpServletResponse.SC_PRECONDITION_FAILED; } catch (DuplicateFolderNameException dfne) { if (_log.isDebugEnabled()) { _log.debug(dfne, dfne); } return HttpServletResponse.SC_PRECONDITION_FAILED; } catch (LockException le) { if (_log.isDebugEnabled()) { _log.debug(le, le); } return WebDAVUtil.SC_LOCKED; } catch (PrincipalException pe) { if (_log.isDebugEnabled()) { _log.debug(pe, pe); } return HttpServletResponse.SC_FORBIDDEN; } catch (Exception e) { throw new WebDAVException(e); } finally { FileUtil.delete(file); } }
From source file:com.liferay.document.library.web.internal.webdav.DLWebDAVStorageImpl.java
License:Open Source License
@Override public int moveCollectionResource(WebDAVRequest webDAVRequest, Resource resource, String destination, boolean overwrite) throws WebDAVException { try {/* w ww . j a va 2 s.c o m*/ String[] destinationArray = WebDAVUtil.getPathArray(destination, true); Folder folder = (Folder) resource.getModel(); long companyId = webDAVRequest.getCompanyId(); long groupId = WebDAVUtil.getGroupId(companyId, destinationArray); long folderId = folder.getFolderId(); long parentFolderId = getParentFolderId(companyId, destinationArray); String name = WebDAVUtil.getResourceName(destinationArray); String description = folder.getDescription(); ServiceContext serviceContext = new ServiceContext(); serviceContext.setUserId(webDAVRequest.getUserId()); int status = HttpServletResponse.SC_CREATED; if (overwrite) { if (deleteResource(groupId, parentFolderId, name, webDAVRequest.getLockUuid())) { status = HttpServletResponse.SC_NO_CONTENT; } } if (parentFolderId != folder.getParentFolderId()) { _dlAppService.moveFolder(folderId, parentFolderId, serviceContext); } if (!name.equals(folder.getName())) { _dlAppService.updateFolder(folderId, name, description, serviceContext); } return status; } catch (PrincipalException pe) { if (_log.isDebugEnabled()) { _log.debug(pe, pe); } return HttpServletResponse.SC_FORBIDDEN; } catch (DuplicateFolderNameException dfne) { if (_log.isDebugEnabled()) { _log.debug(dfne, dfne); } return HttpServletResponse.SC_PRECONDITION_FAILED; } catch (Exception e) { throw new WebDAVException(e); } }
From source file:com.liferay.document.library.web.internal.webdav.DLWebDAVStorageImpl.java
License:Open Source License
@Override public int moveSimpleResource(WebDAVRequest webDAVRequest, Resource resource, String destination, boolean overwrite) throws WebDAVException { File file = null;/*from w w w . j a va2s. c o m*/ try { String[] destinationArray = WebDAVUtil.getPathArray(destination, true); FileEntry fileEntry = (FileEntry) resource.getModel(); if (!hasLock(fileEntry, webDAVRequest.getLockUuid()) && (fileEntry.getLock() != null)) { return WebDAVUtil.SC_LOCKED; } long companyId = webDAVRequest.getCompanyId(); long groupId = WebDAVUtil.getGroupId(companyId, destinationArray); long newParentFolderId = getParentFolderId(companyId, destinationArray); String title = getTitle(destinationArray); String description = fileEntry.getDescription(); String changeLog = StringPool.BLANK; ServiceContext serviceContext = new ServiceContext(); populateServiceContext(serviceContext, fileEntry); int status = HttpServletResponse.SC_CREATED; if (overwrite) { if (deleteResource(groupId, newParentFolderId, title, webDAVRequest.getLockUuid())) { status = HttpServletResponse.SC_NO_CONTENT; } } // LPS-5415 if (webDAVRequest.isMac()) { try { FileEntry destFileEntry = _dlAppService.getFileEntry(groupId, newParentFolderId, title); InputStream is = fileEntry.getContentStream(); file = FileUtil.createTempFile(is); populateServiceContext(serviceContext, destFileEntry); _dlAppService.updateFileEntry(destFileEntry.getFileEntryId(), destFileEntry.getTitle(), destFileEntry.getMimeType(), destFileEntry.getTitle(), destFileEntry.getDescription(), changeLog, false, file, serviceContext); _dlAppService.deleteFileEntry(fileEntry.getFileEntryId()); return status; } catch (NoSuchFileEntryException nsfee) { if (_log.isDebugEnabled()) { _log.debug(nsfee, nsfee); } } } populateServiceContext(serviceContext, fileEntry); _dlAppService.updateFileEntry(fileEntry.getFileEntryId(), title, fileEntry.getMimeType(), title, description, changeLog, false, file, serviceContext); if (fileEntry.getFolderId() != newParentFolderId) { fileEntry = _dlAppService.moveFileEntry(fileEntry.getFileEntryId(), newParentFolderId, serviceContext); } return status; } catch (PrincipalException pe) { if (_log.isDebugEnabled()) { _log.debug(pe, pe); } return HttpServletResponse.SC_FORBIDDEN; } catch (DuplicateFileEntryException dfee) { if (_log.isDebugEnabled()) { _log.debug(dfee, dfee); } return HttpServletResponse.SC_PRECONDITION_FAILED; } catch (DuplicateFolderNameException dfne) { if (_log.isDebugEnabled()) { _log.debug(dfne, dfne); } return HttpServletResponse.SC_PRECONDITION_FAILED; } catch (LockException le) { if (_log.isDebugEnabled()) { _log.debug(le, le); } return WebDAVUtil.SC_LOCKED; } catch (Exception e) { throw new WebDAVException(e); } finally { FileUtil.delete(file); } }
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; }/*from ww w .j ava 2s. c o m*/ 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 moveSimpleResource(WebDAVRequest webDAVRequest, Resource resource, String destination, boolean overwrite) throws WebDAVException { File file = null;//from w w w . j a v a 2s .c o m try { String[] destinationArray = WebDAVUtil.getPathArray(destination, true); FileEntry fileEntry = (FileEntry) resource.getModel(); if (!hasLock(fileEntry, webDAVRequest.getLockUuid()) && (fileEntry.getLock() != null)) { return WebDAVUtil.SC_LOCKED; } long companyId = webDAVRequest.getCompanyId(); long groupId = WebDAVUtil.getGroupId(companyId, destinationArray); long newParentFolderId = getParentFolderId(companyId, destinationArray); String title = getTitle(destinationArray); String description = fileEntry.getDescription(); String changeLog = StringPool.BLANK; ServiceContext serviceContext = new ServiceContext(); populateServiceContext(serviceContext, fileEntry); int status = HttpServletResponse.SC_CREATED; if (overwrite) { if (deleteResource(groupId, newParentFolderId, title, webDAVRequest.getLockUuid())) { status = HttpServletResponse.SC_NO_CONTENT; } } // LPS-5415 if (webDAVRequest.isMac()) { try { FileEntry destFileEntry = _dlAppService.getFileEntry(groupId, newParentFolderId, title); InputStream is = fileEntry.getContentStream(); file = FileUtil.createTempFile(is); _dlAppService.updateFileEntry(destFileEntry.getFileEntryId(), destFileEntry.getTitle(), destFileEntry.getMimeType(), destFileEntry.getTitle(), destFileEntry.getDescription(), changeLog, false, file, serviceContext); _dlAppService.deleteFileEntry(fileEntry.getFileEntryId()); return status; } catch (NoSuchFileEntryException nsfee) { if (_log.isDebugEnabled()) { _log.debug(nsfee, nsfee); } } } _dlAppService.updateFileEntry(fileEntry.getFileEntryId(), title, fileEntry.getMimeType(), title, description, changeLog, false, file, serviceContext); if (fileEntry.getFolderId() != newParentFolderId) { fileEntry = _dlAppService.moveFileEntry(fileEntry.getFileEntryId(), newParentFolderId, serviceContext); } return status; } catch (PrincipalException pe) { if (_log.isDebugEnabled()) { _log.debug(pe, pe); } return HttpServletResponse.SC_FORBIDDEN; } catch (DuplicateFileEntryException dfee) { if (_log.isDebugEnabled()) { _log.debug(dfee, dfee); } return HttpServletResponse.SC_PRECONDITION_FAILED; } catch (DuplicateFolderNameException dfne) { if (_log.isDebugEnabled()) { _log.debug(dfne, dfne); } return HttpServletResponse.SC_PRECONDITION_FAILED; } catch (LockException le) { if (_log.isDebugEnabled()) { _log.debug(le, le); } return WebDAVUtil.SC_LOCKED; } catch (Exception e) { throw new WebDAVException(e); } finally { FileUtil.delete(file); } }
From source file:com.liferay.portlet.documentlibrary.webdav.DLWebDAVStorageImpl.java
License:Open Source License
@Override public int copyCollectionResource(WebDAVRequest webDavRequest, Resource resource, String destination, boolean overwrite, long depth) throws WebDAVException { try {/*w ww .j a v a2s. c om*/ String[] destinationArray = WebDAVUtil.getPathArray(destination, true); long companyId = webDavRequest.getCompanyId(); long parentFolderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID; try { parentFolderId = getParentFolderId(companyId, destinationArray); } catch (NoSuchFolderException nsfe) { return HttpServletResponse.SC_CONFLICT; } Folder folder = (Folder) resource.getModel(); long groupId = WebDAVUtil.getGroupId(companyId, destination); String name = WebDAVUtil.getResourceName(destinationArray); String description = folder.getDescription(); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(isAddGroupPermissions(groupId)); serviceContext.setAddGuestPermissions(true); int status = HttpServletResponse.SC_CREATED; if (overwrite) { if (deleteResource(groupId, parentFolderId, name, webDavRequest.getLockUuid())) { status = HttpServletResponse.SC_NO_CONTENT; } } if (depth == 0) { DLAppServiceUtil.addFolder(groupId, parentFolderId, name, description, serviceContext); } else { DLAppServiceUtil.copyFolder(groupId, folder.getFolderId(), parentFolderId, name, description, serviceContext); } return status; } catch (DuplicateFolderNameException dfne) { return HttpServletResponse.SC_PRECONDITION_FAILED; } catch (PrincipalException pe) { return HttpServletResponse.SC_FORBIDDEN; } catch (Exception e) { throw new WebDAVException(e); } }
From source file:com.liferay.portlet.documentlibrary.webdav.DLWebDAVStorageImpl.java
License:Open Source License
@Override public int copySimpleResource(WebDAVRequest webDavRequest, Resource resource, String destination, boolean overwrite) throws WebDAVException { File file = null;//w w w .j a v a 2 s . co m try { String[] destinationArray = WebDAVUtil.getPathArray(destination, true); long companyId = webDavRequest.getCompanyId(); long parentFolderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID; try { parentFolderId = getParentFolderId(companyId, destinationArray); } catch (NoSuchFolderException nsfe) { return HttpServletResponse.SC_CONFLICT; } FileEntry fileEntry = (FileEntry) resource.getModel(); long groupId = WebDAVUtil.getGroupId(companyId, destination); String mimeType = fileEntry.getMimeType(); String title = WebDAVUtil.getResourceName(destinationArray); String description = fileEntry.getDescription(); String changeLog = StringPool.BLANK; InputStream is = fileEntry.getContentStream(); file = FileUtil.createTempFile(is); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(isAddGroupPermissions(groupId)); serviceContext.setAddGuestPermissions(true); int status = HttpServletResponse.SC_CREATED; if (overwrite) { if (deleteResource(groupId, parentFolderId, title, webDavRequest.getLockUuid())) { status = HttpServletResponse.SC_NO_CONTENT; } } DLAppServiceUtil.addFileEntry(groupId, parentFolderId, title, mimeType, title, description, changeLog, file, serviceContext); return status; } catch (DuplicateFileException dfe) { return HttpServletResponse.SC_PRECONDITION_FAILED; } catch (DuplicateFolderNameException dfne) { return HttpServletResponse.SC_PRECONDITION_FAILED; } catch (LockException le) { return WebDAVUtil.SC_LOCKED; } catch (PrincipalException pe) { return HttpServletResponse.SC_FORBIDDEN; } catch (Exception e) { throw new WebDAVException(e); } finally { FileUtil.delete(file); } }
From source file:com.liferay.portlet.documentlibrary.webdav.DLWebDAVStorageImpl.java
License:Open Source License
@Override public int moveCollectionResource(WebDAVRequest webDavRequest, Resource resource, String destination, boolean overwrite) throws WebDAVException { try {//from ww w .j a va2 s .c o m String[] destinationArray = WebDAVUtil.getPathArray(destination, true); Folder folder = (Folder) resource.getModel(); long companyId = webDavRequest.getCompanyId(); long groupId = WebDAVUtil.getGroupId(companyId, destinationArray); long folderId = folder.getFolderId(); long parentFolderId = getParentFolderId(companyId, destinationArray); String name = WebDAVUtil.getResourceName(destinationArray); String description = folder.getDescription(); ServiceContext serviceContext = new ServiceContext(); int status = HttpServletResponse.SC_CREATED; if (overwrite) { if (deleteResource(groupId, parentFolderId, name, webDavRequest.getLockUuid())) { status = HttpServletResponse.SC_NO_CONTENT; } } if (parentFolderId != folder.getParentFolderId()) { DLAppServiceUtil.moveFolder(folderId, parentFolderId, serviceContext); } if (!name.equals(folder.getName())) { DLAppServiceUtil.updateFolder(folderId, name, description, serviceContext); } return status; } catch (PrincipalException pe) { return HttpServletResponse.SC_FORBIDDEN; } catch (DuplicateFolderNameException dfne) { return HttpServletResponse.SC_PRECONDITION_FAILED; } catch (Exception e) { throw new WebDAVException(e); } }
From source file:com.liferay.portlet.documentlibrary.webdav.DLWebDAVStorageImpl.java
License:Open Source License
@Override public int moveSimpleResource(WebDAVRequest webDavRequest, Resource resource, String destination, boolean overwrite) throws WebDAVException { File file = null;/*from w ww .ja v a2 s . c o m*/ try { String[] destinationArray = WebDAVUtil.getPathArray(destination, true); FileEntry fileEntry = (FileEntry) resource.getModel(); if (!hasLock(fileEntry, webDavRequest.getLockUuid()) && (fileEntry.getLock() != null)) { return WebDAVUtil.SC_LOCKED; } long companyId = webDavRequest.getCompanyId(); long groupId = WebDAVUtil.getGroupId(companyId, destinationArray); long newParentFolderId = getParentFolderId(companyId, destinationArray); String sourceFileName = WebDAVUtil.getResourceName(destinationArray); String title = WebDAVUtil.getResourceName(destinationArray); String description = fileEntry.getDescription(); String changeLog = StringPool.BLANK; String[] assetTagNames = AssetTagLocalServiceUtil.getTagNames(FileEntry.class.getName(), fileEntry.getFileEntryId()); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAssetTagNames(assetTagNames); int status = HttpServletResponse.SC_CREATED; if (overwrite) { if (deleteResource(groupId, newParentFolderId, title, webDavRequest.getLockUuid())) { status = HttpServletResponse.SC_NO_CONTENT; } } // LPS-5415 if (webDavRequest.isMac()) { try { FileEntry destFileEntry = DLAppServiceUtil.getFileEntry(groupId, newParentFolderId, title); InputStream is = fileEntry.getContentStream(); file = FileUtil.createTempFile(is); DLAppServiceUtil.updateFileEntry(destFileEntry.getFileEntryId(), destFileEntry.getTitle(), destFileEntry.getMimeType(), destFileEntry.getTitle(), destFileEntry.getDescription(), changeLog, false, file, serviceContext); DLAppServiceUtil.deleteFileEntry(fileEntry.getFileEntryId()); return status; } catch (NoSuchFileEntryException nsfee) { } } DLAppServiceUtil.updateFileEntry(fileEntry.getFileEntryId(), sourceFileName, fileEntry.getMimeType(), title, description, changeLog, false, file, serviceContext); if (fileEntry.getFolderId() != newParentFolderId) { fileEntry = DLAppServiceUtil.moveFileEntry(fileEntry.getFileEntryId(), newParentFolderId, serviceContext); } return status; } catch (PrincipalException pe) { return HttpServletResponse.SC_FORBIDDEN; } catch (DuplicateFileException dfe) { return HttpServletResponse.SC_PRECONDITION_FAILED; } catch (DuplicateFolderNameException dfne) { return HttpServletResponse.SC_PRECONDITION_FAILED; } catch (LockException le) { return WebDAVUtil.SC_LOCKED; } catch (Exception e) { throw new WebDAVException(e); } finally { FileUtil.delete(file); } }