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

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

Introduction

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

Prototype

public long getRepositoryId();

Source Link

Usage

From source file:com.liferay.adaptive.media.image.item.selector.internal.FileEntryAMImageFileEntryItemSelectorReturnTypeResolver.java

License:Open Source License

@Override
public String getValue(FileEntry fileEntry, ThemeDisplay themeDisplay) throws Exception {

    JSONObject fileEntryJSONObject = JSONFactoryUtil.createJSONObject();

    fileEntryJSONObject.put("fileEntryId", fileEntry.getFileEntryId());

    String previewURL = null;//from  w  ww. j  av a  2s.c  om

    if (fileEntry.getGroupId() == fileEntry.getRepositoryId()) {
        previewURL = DLUtil.getPreviewURL(fileEntry, fileEntry.getFileVersion(), themeDisplay, StringPool.BLANK,
                false, false);
    } else {
        previewURL = PortletFileRepositoryUtil.getPortletFileEntryURL(themeDisplay, fileEntry, StringPool.BLANK,
                false);
    }

    fileEntryJSONObject.put("url", previewURL);

    return fileEntryJSONObject.toString();
}

From source file:com.liferay.adaptive.media.image.item.selector.internal.FileEntryAMImageURLItemSelectorReturnTypeResolver.java

License:Open Source License

@Override
public String getValue(FileEntry fileEntry, ThemeDisplay themeDisplay) throws Exception {

    JSONObject fileEntryJSONObject = JSONFactoryUtil.createJSONObject();

    String previewURL = null;//from   www  .  j  a  va 2  s . c  o  m

    if (fileEntry.getGroupId() == fileEntry.getRepositoryId()) {
        previewURL = DLUtil.getPreviewURL(fileEntry, fileEntry.getFileVersion(), themeDisplay, StringPool.BLANK,
                false, false);
    } else {
        previewURL = PortletFileRepositoryUtil.getPortletFileEntryURL(themeDisplay, fileEntry, StringPool.BLANK,
                false);
    }

    fileEntryJSONObject.put("defaultSource", previewURL);

    fileEntryJSONObject.put("fileEntryId", fileEntry.getFileEntryId());

    JSONArray sourcesArray = JSONFactoryUtil.createJSONArray();

    List<MediaQuery> mediaQueries = _mediaQueryProvider.getMediaQueries(fileEntry);

    Stream<MediaQuery> mediaQueryStream = mediaQueries.stream();

    mediaQueryStream.map(this::_getSourceJSONObject).forEach(sourcesArray::put);

    fileEntryJSONObject.put("sources", sourcesArray);

    return fileEntryJSONObject.toString();
}

From source file:com.liferay.adaptive.media.image.item.selector.internal.resolver.FileEntryAMImageFileEntryItemSelectorReturnTypeResolver.java

License:Open Source License

@Override
public String getValue(FileEntry fileEntry, ThemeDisplay themeDisplay) throws Exception {

    JSONObject fileEntryJSONObject = JSONFactoryUtil.createJSONObject();

    String previewURL = null;/*from w  ww .  j a v  a  2  s.  co  m*/

    if (fileEntry.getGroupId() == fileEntry.getRepositoryId()) {
        previewURL = DLUtil.getPreviewURL(fileEntry, fileEntry.getFileVersion(), themeDisplay, StringPool.BLANK,
                false, false);
    } else {
        previewURL = PortletFileRepositoryUtil.getPortletFileEntryURL(themeDisplay, fileEntry, StringPool.BLANK,
                false);
    }

    fileEntryJSONObject.put("fileEntryId", fileEntry.getFileEntryId());
    fileEntryJSONObject.put("url", previewURL);

    return fileEntryJSONObject.toString();
}

From source file:com.liferay.adaptive.media.image.item.selector.internal.resolver.FileEntryAMImageURLItemSelectorReturnTypeResolver.java

License:Open Source License

@Override
public String getValue(FileEntry fileEntry, ThemeDisplay themeDisplay) throws Exception {

    JSONObject fileEntryJSONObject = JSONFactoryUtil.createJSONObject();

    fileEntryJSONObject.put("fileEntryId", fileEntry.getFileEntryId());

    String previewURL = null;//from w  w w .j  a  va 2  s . c o  m

    if (fileEntry.getGroupId() == fileEntry.getRepositoryId()) {
        previewURL = DLUtil.getPreviewURL(fileEntry, fileEntry.getFileVersion(), themeDisplay, StringPool.BLANK,
                false, false);
    } else {
        previewURL = PortletFileRepositoryUtil.getPortletFileEntryURL(themeDisplay, fileEntry, StringPool.BLANK,
                false);
    }

    fileEntryJSONObject.put("defaultSource", previewURL);

    JSONArray sourcesArray = JSONFactoryUtil.createJSONArray();

    List<MediaQuery> mediaQueries = _mediaQueryProvider.getMediaQueries(fileEntry);

    Stream<MediaQuery> mediaQueryStream = mediaQueries.stream();

    mediaQueryStream.map(this::_getSourceJSONObject).forEach(sourcesArray::put);

    fileEntryJSONObject.put("sources", sourcesArray);

    return fileEntryJSONObject.toString();
}

From source file:com.liferay.blogs.attachments.test.BaseBlogsEntryImageTestCase.java

License:Open Source License

@Test
public void testImageStoredInBlogsRepository() throws Exception {
    BlogsEntry blogsEntry = addBlogsEntry("image1.jpg");

    FileEntry imageFileEntry = PortletFileRepositoryUtil.getPortletFileEntry(getImageFileEntryId(blogsEntry));

    Repository repository = RepositoryLocalServiceUtil.getRepository(imageFileEntry.getRepositoryId());

    Assert.assertEquals(BlogsConstants.SERVICE_NAME, repository.getName());
}

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

License:Open Source License

@Override
protected void doExportStagedModel(PortletDataContext portletDataContext, FileEntry fileEntry)
        throws Exception {

    Element fileEntryElement = portletDataContext.getExportDataElement(fileEntry);

    String fileEntryPath = ExportImportPathUtil.getModelPath(fileEntry);

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

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

        portletDataContext.addClassedModel(fileEntryElement, fileEntryPath, fileEntry);

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

        if (repository.getClassNameId() != portletRepositoryClassNameId) {
            return;
        }//from ww  w .  ja v a  2 s.  c o m
    }

    if (fileEntry.getFolderId() != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

        StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, fileEntry,
                fileEntry.getFolder(), PortletDataContext.REFERENCE_TYPE_PARENT);
    }

    LiferayFileEntry liferayFileEntry = (LiferayFileEntry) fileEntry;

    liferayFileEntry.setCachedFileVersion(fileEntry.getFileVersion());

    if (!portletDataContext.isPerformDirectBinaryImport()) {
        InputStream is = null;

        try {
            is = FileEntryUtil.getContentStream(fileEntry);
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn("Unable to retrieve content for file entry " + fileEntry.getFileEntryId(), e);
            }
        }

        if (is == null) {
            fileEntryElement.detach();

            return;
        }

        try {
            String binPath = ExportImportPathUtil.getModelPath(fileEntry, fileEntry.getVersion());

            portletDataContext.addZipEntry(binPath, is);

            fileEntryElement.addAttribute("bin-path", binPath);
        } finally {
            try {
                is.close();
            } catch (IOException ioe) {
                _log.error(ioe, ioe);
            }
        }
    }

    for (DLPluggableContentDataHandler dlPluggableContentDataHandler : _serviceTrackerList) {

        dlPluggableContentDataHandler.exportContent(portletDataContext, fileEntryElement, fileEntry);
    }

    exportMetaData(portletDataContext, fileEntryElement, fileEntry);

    portletDataContext.addClassedModel(fileEntryElement, fileEntryPath, liferayFileEntry, DLFileEntry.class);
}

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

License:Open Source License

private boolean _isEnabled(FileEntry fileEntry) {
    if (!DLAppHelperThreadLocal.isEnabled()) {
        return false;
    }/*from w w  w. ja  v  a2s . c o  m*/

    if (RepositoryUtil.isExternalRepository(fileEntry.getRepositoryId())) {
        return false;
    }

    return true;
}

From source file:com.liferay.document.library.service.test.DLAppServiceTest.java

License:Open Source License

protected static void search(FileEntry fileEntry, String keywords, boolean expected) throws Exception {

    SearchContext searchContext = new SearchContext();

    searchContext.setAttribute("paginationType", "regular");
    searchContext.setCompanyId(fileEntry.getCompanyId());
    searchContext.setFolderIds(new long[] { fileEntry.getFolderId() });
    searchContext.setGroupIds(new long[] { fileEntry.getRepositoryId() });
    searchContext.setKeywords(keywords);

    QueryConfig queryConfig = searchContext.getQueryConfig();

    queryConfig.setHighlightEnabled(false);
    queryConfig.setScoreEnabled(false);//from www . j  a va  2  s .c om

    Indexer<DLFileEntry> indexer = IndexerRegistryUtil.getIndexer(DLFileEntryConstants.getClassName());

    Hits hits = indexer.search(searchContext);

    boolean found = false;

    for (Document document : hits.getDocs()) {
        long fileEntryId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

        if (fileEntryId == fileEntry.getFileEntryId()) {
            found = true;

            break;
        }
    }

    Assert.assertEquals(hits.toString(), expected, found);
}

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

License:Open Source License

@Override
public String getMessage(PortletRequest portletRequest) {
    String key = "delete";

    try {//from  w  w w.  j  av  a 2 s .c o m
        ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

        FileEntry fileEntry = ActionUtil.getFileEntry(portletRequest);

        if (isTrashEnabled(themeDisplay.getScopeGroupId(), fileEntry.getRepositoryId())) {

            key = "move-to-the-recycle-bin";
        }

        return LanguageUtil.get(getResourceBundle(getLocale(portletRequest)), key);
    } catch (PortalException pe) {
        throw new RuntimeException(pe);
    }
}

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

License:Open Source License

@Override
public String getURL(PortletRequest portletRequest, PortletResponse portletResponse) {

    PortletURL portletURL = _portal.getControlPanelPortletURL(portletRequest,
            DLPortletKeys.DOCUMENT_LIBRARY_ADMIN, PortletRequest.ACTION_PHASE);

    portletURL.setParameter(ActionRequest.ACTION_NAME, "/document_library/edit_file_entry");

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

    FileEntry fileEntry = null;

    try {/*from  w  ww .j  a  va  2s  .  co  m*/
        fileEntry = ActionUtil.getFileEntry(portletRequest);
    } catch (PortalException pe) {
        throw new RuntimeException(pe);
    }

    if (isTrashEnabled(themeDisplay.getScopeGroupId(), fileEntry.getRepositoryId())) {

        portletURL.setParameter(Constants.CMD, Constants.MOVE_TO_TRASH);
    } else {
        portletURL.setParameter(Constants.CMD, Constants.DELETE);
    }

    PortletURL redirectURL = _portal.getControlPanelPortletURL(portletRequest,
            DLPortletKeys.DOCUMENT_LIBRARY_ADMIN, PortletRequest.RENDER_PHASE);

    long folderId = fileEntry.getFolderId();

    if (folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
        redirectURL.setParameter("mvcRenderCommandName", "/document_library/view");
    } else {
        redirectURL.setParameter("mvcRenderCommandName", "/document_library/view_folder");
    }

    redirectURL.setParameter("folderId", String.valueOf(folderId));

    portletURL.setParameter("redirect", redirectURL.toString());

    portletURL.setParameter("fileEntryId", String.valueOf(fileEntry.getFileEntryId()));

    return portletURL.toString();
}