Example usage for com.liferay.portal.kernel.repository.model Folder getRepositoryId

List of usage examples for com.liferay.portal.kernel.repository.model Folder getRepositoryId

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.repository.model Folder getRepositoryId.

Prototype

public long getRepositoryId();

Source Link

Usage

From source file:com.liferay.portlet.documentlibrary.atom.FileEntryAtomCollectionAdapter.java

License:Open Source License

@Override
protected FileEntry doPostMedia(String mimeType, String slug, InputStream inputStream,
        AtomRequestContext atomRequestContext) throws Exception {

    long folderId = atomRequestContext.getLongParameter("folderId");

    long repositoryId = 0;

    if (folderId != 0) {
        Folder folder = DLAppServiceUtil.getFolder(folderId);

        repositoryId = folder.getRepositoryId();
    } else {/*ww w  .j a  v a 2 s.c  om*/
        repositoryId = atomRequestContext.getLongParameter("repositoryId");
    }

    String title = atomRequestContext.getHeader("Title");
    String description = atomRequestContext.getHeader("Summary");

    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

    StreamUtil.transfer(inputStream, byteArrayOutputStream);

    byte[] content = byteArrayOutputStream.toByteArray();

    ByteArrayInputStream contentInputStream = new ByteArrayInputStream(content);

    ServiceContext serviceContext = new ServiceContext();

    FileEntry fileEntry = DLAppServiceUtil.addFileEntry(repositoryId, folderId, title, mimeType, title,
            description, null, contentInputStream, content.length, serviceContext);

    return fileEntry;
}

From source file:com.liferay.portlet.documentlibrary.atom.FolderAtomCollectionAdapter.java

License:Open Source License

@Override
protected Iterable<Folder> doGetFeedEntries(AtomRequestContext atomRequestContext) throws Exception {

    long repositoryId = 0;

    long parentFolderId = atomRequestContext.getLongParameter("parentFolderId");

    if (parentFolderId != 0) {
        Folder parentFolder = DLAppServiceUtil.getFolder(parentFolderId);

        repositoryId = parentFolder.getRepositoryId();
    } else {//from   ww w.j ava 2 s  .  c  o m
        repositoryId = atomRequestContext.getLongParameter("repositoryId");
    }

    int count = DLAppServiceUtil.getFoldersCount(repositoryId, parentFolderId);

    AtomPager atomPager = new AtomPager(atomRequestContext, count);

    AtomUtil.saveAtomPagerInRequest(atomRequestContext, atomPager);

    return DLAppServiceUtil.getFolders(repositoryId, parentFolderId, atomPager.getStart(),
            atomPager.getEnd() + 1, new EntryNameComparator());
}

From source file:com.liferay.portlet.documentlibrary.atom.FolderAtomCollectionAdapter.java

License:Open Source License

@Override
protected Folder doPostEntry(String title, String summary, String content, Date date,
        AtomRequestContext atomRequestContext) throws Exception {

    long repositoryId = 0;

    long parentFolderId = atomRequestContext.getLongParameter("parentFolderId");

    if (parentFolderId != 0) {
        Folder parentFolder = DLAppServiceUtil.getFolder(parentFolderId);

        repositoryId = parentFolder.getRepositoryId();
    } else {/*from w  w w .  j ava2 s  .co m*/
        repositoryId = atomRequestContext.getLongParameter("repositoryId");
    }

    ServiceContext serviceContext = new ServiceContext();

    Folder folder = DLAppServiceUtil.addFolder(repositoryId, parentFolderId, title, summary, serviceContext);

    return folder;
}

From source file:com.liferay.portlet.documentlibrary.lar.DLPortletDataHandlerImpl.java

License:Open Source License

protected static void exportFolder(PortletDataContext portletDataContext, Element fileEntryTypesElement,
        Element foldersElement, Element fileEntriesElement, Element fileShortcutsElement,
        Element fileRanksElement, Element repositoriesElement, Element repositoryEntriesElement, Folder folder,
        boolean recurse) throws Exception {

    if (!portletDataContext.isWithinDateRange(folder.getModifiedDate())) {
        return;//from w  w w.ja  va2s. c  o m
    }

    if (folder.isMountPoint()) {
        Repository repository = RepositoryUtil.findByPrimaryKey(folder.getRepositoryId());

        exportRepository(portletDataContext, repositoriesElement, repositoryEntriesElement, repository);

        return;
    } else if (!folder.isDefaultRepository()) {

        // No need to export non-Liferay repository items since they would
        // be exported as part of repository export

        return;
    }

    exportParentFolder(portletDataContext, fileEntryTypesElement, foldersElement, repositoriesElement,
            repositoryEntriesElement, folder.getParentFolderId());

    String path = getFolderPath(portletDataContext, folder);

    if (!portletDataContext.isPathNotProcessed(path)) {
        return;
    }

    Element folderElement = foldersElement.addElement("folder");

    exportFolderFileEntryTypes(portletDataContext, folder, fileEntryTypesElement, folderElement);

    portletDataContext.addClassedModel(folderElement, path, folder, _NAMESPACE);

    if (recurse) {
        List<Folder> folders = FolderUtil.findByR_P(folder.getRepositoryId(), folder.getFolderId());

        for (Folder curFolder : folders) {
            exportFolder(portletDataContext, fileEntryTypesElement, foldersElement, fileEntriesElement,
                    fileShortcutsElement, fileRanksElement, repositoriesElement, repositoryEntriesElement,
                    curFolder, recurse);
        }
    }

    List<FileEntry> fileEntries = FileEntryUtil.findByR_F(folder.getRepositoryId(), folder.getFolderId());

    for (FileEntry fileEntry : fileEntries) {
        exportFileEntry(portletDataContext, fileEntryTypesElement, foldersElement, fileEntriesElement,
                fileRanksElement, repositoriesElement, repositoryEntriesElement, fileEntry, true);
    }

    if (portletDataContext.getBooleanParameter(_NAMESPACE, "shortcuts")) {
        List<DLFileShortcut> fileShortcuts = DLFileShortcutUtil.findByG_F(folder.getRepositoryId(),
                folder.getFolderId());

        for (DLFileShortcut fileShortcut : fileShortcuts) {
            exportFileShortcut(portletDataContext, fileEntryTypesElement, foldersElement, fileShortcutsElement,
                    repositoriesElement, repositoryEntriesElement, fileShortcut);
        }
    }
}

From source file:com.liferay.portlet.documentlibrary.lar.DLPortletDataHandlerImpl.java

License:Open Source License

protected static void exportParentFolder(PortletDataContext portletDataContext, Element fileEntryTypesElement,
        Element foldersElement, Element repositoriesElement, Element repositoryEntriesElement, long folderId)
        throws Exception {

    if (folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
        return;//from   ww  w  .j av  a  2  s .  c om
    }

    Folder folder = DLAppLocalServiceUtil.getFolder(folderId);

    if (folder.isMountPoint()) {
        Repository repository = RepositoryUtil.findByPrimaryKey(folder.getRepositoryId());

        exportRepository(portletDataContext, repositoriesElement, repositoryEntriesElement, repository);

        return;
    } else if (!folder.isDefaultRepository()) {
        //no need to export non-Liferay Repository items since they would
        //be exported as part of repository export
        return;
    }

    exportParentFolder(portletDataContext, fileEntryTypesElement, foldersElement, repositoriesElement,
            repositoryEntriesElement, folder.getParentFolderId());

    String path = getFolderPath(portletDataContext, folder);

    if (portletDataContext.isPathNotProcessed(path)) {
        Element folderElement = foldersElement.addElement("folder");

        exportFolderFileEntryTypes(portletDataContext, folder, fileEntryTypesElement, folderElement);

        portletDataContext.addClassedModel(folderElement, path, folder, _NAMESPACE);
    }
}

From source file:com.liferay.portlet.documentlibrary.lar.DLPortletDataHandlerImpl.java

License:Open Source License

protected static void importFileShortcut(PortletDataContext portletDataContext, Element fileShortcutElement,
        DLFileShortcut fileShortcut) throws Exception {

    long userId = portletDataContext.getUserId(fileShortcut.getUserUuid());

    Map<Long, Long> folderIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(DLFolder.class);

    long folderId = MapUtil.getLong(folderIds, fileShortcut.getFolderId(), fileShortcut.getFolderId());

    long groupId = portletDataContext.getScopeGroupId();

    if (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
        Folder folder = FolderUtil.findByPrimaryKey(folderId);

        groupId = folder.getRepositoryId();
    }/*w  ww .ja  va  2s  .c om*/

    String fileEntryUuid = fileShortcutElement.attributeValue("file-entry-uuid");

    FileEntry fileEntry = FileEntryUtil.fetchByUUID_R(fileEntryUuid, groupId);

    if (fileEntry == null) {
        if (_log.isWarnEnabled()) {
            _log.warn("Unable to fetch file entry {uuid=" + fileEntryUuid + ", groupId=" + groupId + "}");
        }

        return;
    }

    long fileEntryId = fileEntry.getFileEntryId();

    ServiceContext serviceContext = portletDataContext.createServiceContext(fileShortcutElement, fileShortcut,
            _NAMESPACE);

    DLFileShortcut importedFileShortcut = null;

    if (portletDataContext.isDataStrategyMirror()) {
        DLFileShortcut existingFileShortcut = DLFileShortcutUtil.fetchByUUID_G(fileShortcut.getUuid(),
                portletDataContext.getScopeGroupId());

        if (existingFileShortcut == null) {
            serviceContext.setUuid(fileShortcut.getUuid());

            importedFileShortcut = DLAppLocalServiceUtil.addFileShortcut(userId, groupId, folderId, fileEntryId,
                    serviceContext);
        } else {
            importedFileShortcut = DLAppLocalServiceUtil.updateFileShortcut(userId,
                    existingFileShortcut.getFileShortcutId(), folderId, fileEntryId, serviceContext);
        }
    } else {
        importedFileShortcut = DLAppLocalServiceUtil.addFileShortcut(userId, groupId, folderId, fileEntryId,
                serviceContext);
    }

    portletDataContext.importClassedModel(fileShortcut, importedFileShortcut, _NAMESPACE);
}

From source file:com.liferay.portlet.documentlibrary.service.impl.DLAppHelperLocalServiceImpl.java

License:Open Source License

public void addFolder(Folder folder, ServiceContext serviceContext) throws SystemException {

    if (!isStagingGroup(folder.getGroupId())) {
        dlSyncLocalService.addSync(folder.getFolderId(), folder.getUuid(), folder.getCompanyId(),
                folder.getRepositoryId(), folder.getParentFolderId(), folder.getName(),
                DLSyncConstants.TYPE_FOLDER, "-1");
    }//from  w  w w.  j a v  a 2  s.  c o m
}

From source file:com.liferay.portlet.documentlibrary.webdav.DLWebDAVStorageImpl.java

License:Open Source License

public Resource getResource(WebDAVRequest webDavRequest) throws WebDAVException {

    try {//w  w  w.j  ava2 s .c  om
        String[] pathArray = webDavRequest.getPathArray();

        long companyId = webDavRequest.getCompanyId();
        long parentFolderId = getParentFolderId(companyId, pathArray);
        String name = WebDAVUtil.getResourceName(pathArray);

        if (Validator.isNull(name)) {
            String path = getRootPath() + webDavRequest.getPath();

            return new BaseResourceImpl(path, StringPool.BLANK, getToken());
        }

        try {
            Folder folder = DLAppServiceUtil.getFolder(webDavRequest.getGroupId(), parentFolderId, name);

            if ((folder.getParentFolderId() != parentFolderId)
                    || (webDavRequest.getGroupId() != folder.getRepositoryId())) {

                throw new NoSuchFolderException();
            }

            return toResource(webDavRequest, folder, false);
        } catch (NoSuchFolderException nsfe) {
            try {
                String titleWithExtension = name;

                FileEntry fileEntry = DLAppServiceUtil.getFileEntry(webDavRequest.getGroupId(), parentFolderId,
                        titleWithExtension);

                return toResource(webDavRequest, fileEntry, false);
            } catch (NoSuchFileEntryException nsfee) {
                return null;
            }
        }
    } catch (Exception e) {
        throw new WebDAVException(e);
    }
}

From source file:com.liferay.portlet.documentlibrary.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 ww w  . j a  v a  2s.c  o  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 = WebDAVUtil.getResourceName(pathArray);

            String contentType = GetterUtil.get(request.getHeader(HttpHeaders.CONTENT_TYPE),
                    ContentTypes.APPLICATION_OCTET_STREAM);

            if (contentType.equals(ContentTypes.APPLICATION_OCTET_STREAM)) {
                contentType = MimeTypesUtil.getContentType(request.getInputStream(), title);
            }

            String description = StringPool.BLANK;
            String changeLog = StringPool.BLANK;

            File file = FileUtil.createTempFile(FileUtil.getExtension(title));

            file.createNewFile();

            ServiceContext serviceContext = new ServiceContext();

            serviceContext.setAddGroupPermissions(isAddGroupPermissions(groupId));
            serviceContext.setAddGuestPermissions(true);

            FileEntry fileEntry = DLAppServiceUtil.addFileEntry(groupId, parentFolderId, title, contentType,
                    title, description, changeLog, file, serviceContext);

            resource = toResource(webDavRequest, fileEntry, false);
        }

        if (resource instanceof DLFileEntryResourceImpl) {
            FileEntry fileEntry = (FileEntry) resource.getModel();

            lock = DLAppServiceUtil.lockFileEntry(fileEntry.getFileEntryId(), owner, timeout);
        } else {
            boolean inheritable = false;

            long depth = WebDAVUtil.getDepth(webDavRequest.getHttpServletRequest());

            if (depth != 0) {
                inheritable = true;
            }

            Folder folder = (Folder) resource.getModel();

            lock = DLAppServiceUtil.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.portlet.documentlibrary.webdav.DLWebDAVStorageImpl.java

License:Open Source License

@Override
public boolean unlockResource(WebDAVRequest webDavRequest, String token) throws WebDAVException {

    Resource resource = getResource(webDavRequest);

    try {//from   w  ww . j a va2 s .c  om
        if (resource instanceof DLFileEntryResourceImpl) {
            FileEntry fileEntry = (FileEntry) resource.getModel();

            DLAppServiceUtil.unlockFileEntry(fileEntry.getFileEntryId(), token);

            if (webDavRequest.isAppleDoubleRequest()) {
                DLAppServiceUtil.deleteFileEntry(fileEntry.getFileEntryId());
            }
        } else {
            Folder folder = (Folder) resource.getModel();

            DLAppServiceUtil.unlockFolder(folder.getRepositoryId(), folder.getParentFolderId(),
                    folder.getName(), token);
        }

        return true;
    } catch (Exception e) {
        if (e instanceof InvalidLockException) {
            if (_log.isWarnEnabled()) {
                _log.warn(e.getMessage());
            }
        } else {
            if (_log.isWarnEnabled()) {
                _log.warn("Unable to unlock file entry", e);
            }
        }
    }

    return false;
}