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.document.library.internal.exportimport.data.handler.FileShortcutStagedModelDataHandler.java

License:Open Source License

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, FileShortcut fileShortcut)
        throws Exception {

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

    Map<Long, Long> folderIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Folder.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();
    }//from  w  w  w  . java  2s .c  o  m

    Map<Long, Long> fileEntryIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(FileEntry.class);

    long fileEntryId = MapUtil.getLong(fileEntryIds, fileShortcut.getToFileEntryId(),
            fileShortcut.getToFileEntryId());

    FileEntry importedFileEntry = null;

    try {
        importedFileEntry = _dlAppLocalService.getFileEntry(fileEntryId);
    } catch (PortalException pe) {
        if (_log.isWarnEnabled()) {
            _log.warn("Unable to fetch file entry " + fileEntryId, pe);
        }

        return;
    }

    ServiceContext serviceContext = portletDataContext.createServiceContext(fileShortcut);

    FileShortcut importedFileShortcut = null;

    if (portletDataContext.isDataStrategyMirror()) {
        FileShortcut existingFileShortcut = fetchStagedModelByUuidAndGroupId(fileShortcut.getUuid(),
                portletDataContext.getScopeGroupId());

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

            importedFileShortcut = _dlAppLocalService.addFileShortcut(userId, groupId, folderId,
                    importedFileEntry.getFileEntryId(), serviceContext);
        } else {
            importedFileShortcut = _dlAppLocalService.updateFileShortcut(userId,
                    existingFileShortcut.getFileShortcutId(), folderId, importedFileEntry.getFileEntryId(),
                    serviceContext);
        }
    } else {
        importedFileShortcut = _dlAppLocalService.addFileShortcut(userId, groupId, folderId,
                importedFileEntry.getFileEntryId(), serviceContext);
    }

    portletDataContext.importClassedModel(fileShortcut, importedFileShortcut);
}

From source file:com.liferay.document.library.internal.exportimport.data.handler.FolderStagedModelDataHandler.java

License:Open Source License

@Override
protected void doExportStagedModel(PortletDataContext portletDataContext, Folder folder) throws Exception {

    Element folderElement = portletDataContext.getExportDataElement(folder);

    String folderPath = ExportImportPathUtil.getModelPath(folder);

    if (!folder.isDefaultRepository()) {
        Repository repository = _repositoryLocalService.getRepository(folder.getRepositoryId());

        StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, folder, repository,
                PortletDataContext.REFERENCE_TYPE_STRONG);

        portletDataContext.addClassedModel(folderElement, folderPath, folder);

        long portletRepositoryClassNameId = _portal.getClassNameId(PortletRepository.class.getName());

        if (repository.getClassNameId() != portletRepositoryClassNameId) {
            return;
        }/*from  w  ww.  jav  a2 s.  c  o  m*/
    }

    if (folder.getParentFolderId() != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

        StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, folder,
                folder.getParentFolder(), PortletDataContext.REFERENCE_TYPE_PARENT);
    }

    exportFolderFileEntryTypes(portletDataContext, folderElement, folder);

    portletDataContext.addClassedModel(folderElement, folderPath, folder, DLFolder.class);
}

From source file:com.liferay.document.library.internal.repository.capabilities.LiferayTrashCapability.java

License:Open Source License

@Override
public void deleteFolder(Folder folder) throws PortalException {
    List<DLFileEntry> dlFileEntries = _dlFileEntryServiceAdapter.getGroupFileEntries(folder.getGroupId(), 0,
            folder.getRepositoryId(), folder.getFolderId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);

    for (DLFileEntry dlFileEntry : dlFileEntries) {
        FileEntry fileEntry = new LiferayFileEntry(dlFileEntry);

        _dlAppHelperLocalService.deleteFileEntry(fileEntry);

        deleteTrashEntry(fileEntry);/*from   w w w  .  j a  v  a 2 s  .c om*/
    }

    _dlAppHelperLocalService.deleteFolder(folder);

    deleteTrashEntry(folder);

    _dlFolderServiceAdapter.deleteFolder(folder.getFolderId(), false);
}

From source file:com.liferay.document.library.internal.service.ExternalRepositoryDLAppHelperLocalServiceWrapper.java

License:Open Source License

private boolean _isEnabled(Folder folder) {
    if (!DLAppHelperThreadLocal.isEnabled()) {
        return false;
    }/*from  w w w  . j  a  va2  s .  com*/

    if (!folder.isMountPoint() && RepositoryUtil.isExternalRepository(folder.getRepositoryId())) {

        return false;
    }

    return true;
}

From source file:com.liferay.document.library.jaxrs.FolderRepr.java

License:Open Source License

public static FolderRepr fromFolder(Folder folder, List<RepositoryContentObject> repositoryContentObjects,
        UriBuilder uriBuilder) {//  w  w  w  .j av  a  2 s.  c  om

    String url = uriBuilder.build(Long.toString(folder.getFolderId())).toString();

    return new FolderRepr(folder.getRepositoryId(), folder.getFolderId(), folder.getDescription(),
            folder.getCreateDate(), folder.getName(), repositoryContentObjects, url);
}

From source file:com.liferay.document.library.jaxrs.FolderResource.java

License:Open Source License

public FolderResource(DLAppService dlAppService, final Folder folder, UriBuilder folderUriBuilder,
        UriBuilder fileUriBuilder) {/*ww  w  .  j ava2s .  com*/

    _dlAppService = dlAppService;
    _folderUriBuilder = folderUriBuilder;
    _fileUriBuilder = fileUriBuilder;
    _folderId = folder.getFolderId();

    _repositoryId = folder.getRepositoryId();
    _folderReprFunction = contents -> FolderRepr.fromFolder(folder, contents, _folderUriBuilder);
}

From source file:com.liferay.document.library.web.internal.portlet.action.DLFolderFindActionHelper.java

License:Open Source License

@Override
public long getGroupId(long primaryKey) throws Exception {
    Folder folder = _dlAppLocalService.getFolder(primaryKey);

    return folder.getRepositoryId();
}

From source file:com.liferay.document.library.web.internal.portlet.action.DownloadEntriesMVCResourceCommand.java

License:Open Source License

protected void downloadFileEntries(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long folderId = ParamUtil.getLong(resourceRequest, "folderId");

    File file = null;/* w  w  w  . j  a v a2 s .  co  m*/
    InputStream inputStream = null;

    try {
        List<FileEntry> fileEntries = ActionUtil.getFileEntries(resourceRequest);

        List<FileShortcut> fileShortcuts = ActionUtil.getFileShortcuts(resourceRequest);

        List<Folder> folders = ActionUtil.getFolders(resourceRequest);

        if (fileEntries.isEmpty() && fileShortcuts.isEmpty() && folders.isEmpty()) {

            return;
        } else if ((fileEntries.size() == 1) && fileShortcuts.isEmpty() && folders.isEmpty()) {

            FileEntry fileEntry = fileEntries.get(0);

            PortletResponseUtil.sendFile(resourceRequest, resourceResponse, fileEntry.getFileName(),
                    fileEntry.getContentStream(), 0, fileEntry.getMimeType(),
                    HttpHeaders.CONTENT_DISPOSITION_ATTACHMENT);
        } else if ((fileShortcuts.size() == 1) && fileEntries.isEmpty() && folders.isEmpty()) {

            FileShortcut fileShortcut = fileShortcuts.get(0);

            FileEntry fileEntry = _dlAppService.getFileEntry(fileShortcut.getToFileEntryId());

            PortletResponseUtil.sendFile(resourceRequest, resourceResponse, fileEntry.getFileName(),
                    fileEntry.getContentStream(), 0, fileEntry.getMimeType(),
                    HttpHeaders.CONTENT_DISPOSITION_ATTACHMENT);
        } else {
            String zipFileName = getZipFileName(folderId, themeDisplay);

            ZipWriter zipWriter = ZipWriterFactoryUtil.getZipWriter();

            for (FileEntry fileEntry : fileEntries) {
                zipFileEntry(fileEntry, StringPool.SLASH, zipWriter);
            }

            for (FileShortcut fileShortcut : fileShortcuts) {
                FileEntry fileEntry = _dlAppService.getFileEntry(fileShortcut.getToFileEntryId());

                zipFileEntry(fileEntry, StringPool.SLASH, zipWriter);
            }

            for (Folder folder : folders) {
                zipFolder(folder.getRepositoryId(), folder.getFolderId(),
                        StringPool.SLASH.concat(folder.getName()), zipWriter);
            }

            file = zipWriter.getFile();

            inputStream = new FileInputStream(file);

            PortletResponseUtil.sendFile(resourceRequest, resourceResponse, zipFileName, inputStream,
                    ContentTypes.APPLICATION_ZIP);
        }
    } finally {
        StreamUtil.cleanUp(inputStream);

        if (file != null) {
            file.delete();
        }
    }
}

From source file:com.liferay.document.library.web.internal.portlet.action.DownloadEntriesMVCResourceCommand.java

License:Open Source License

protected void zipFolder(long repositoryId, long folderId, String path, ZipWriter zipWriter) throws Exception {

    List<Object> foldersAndFileEntriesAndFileShortcuts = _dlAppService.getFoldersAndFileEntriesAndFileShortcuts(
            repositoryId, folderId, WorkflowConstants.STATUS_APPROVED, false, QueryUtil.ALL_POS,
            QueryUtil.ALL_POS);// w  w  w  .  j  av a2  s  . c  om

    for (Object entry : foldersAndFileEntriesAndFileShortcuts) {
        if (entry instanceof Folder) {
            Folder folder = (Folder) entry;

            zipFolder(folder.getRepositoryId(), folder.getFolderId(),
                    path.concat(StringPool.SLASH).concat(folder.getName()), zipWriter);
        } else if (entry instanceof FileEntry) {
            zipFileEntry((FileEntry) entry, path, zipWriter);
        } else if (entry instanceof FileShortcut) {
            FileShortcut fileShortcut = (FileShortcut) entry;

            FileEntry fileEntry = _dlAppService.getFileEntry(fileShortcut.getToFileEntryId());

            zipFileEntry(fileEntry, path, zipWriter);
        }
    }
}

From source file:com.liferay.document.library.web.internal.portlet.configuration.icon.AccessFromDesktopPortletConfigurationIcon.java

License:Open Source License

@Override
public boolean isShow(PortletRequest portletRequest) {
    try {//from  ww w  .  java2s.com
        ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

        PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

        long folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;

        Folder folder = ActionUtil.getFolder(portletRequest);

        if (folder != null) {
            folderId = folder.getFolderId();
        }

        if (DLFolderPermission.contains(themeDisplay.getPermissionChecker(), themeDisplay.getScopeGroupId(),
                folderId, ActionKeys.VIEW) && portletDisplay.isWebDAVEnabled()
                && ((folder == null) || (folder.getRepositoryId() == themeDisplay.getScopeGroupId()))) {

            return true;
        }
    } catch (Exception e) {
    }

    return false;
}