@Test public void testDeleteAttachmentsWhenDeletingWikiPage() throws Exception { int initialFileEntriesCount = DLFileEntryLocalServiceUtil.getFileEntriesCount(); addWikiPageAttachment(); Assert.assertEquals( initialFileEntriesCount + 1, DLFileEntryLocalServiceUtil.getFileEntriesCount()); WikiPageLocalServiceUtil.deletePage(_page.getNodeId(), _page.getTitle()); Assert.assertEquals(initialFileEntriesCount, DLFileEntryLocalServiceUtil.getFileEntriesCount()); }
@Override public List<FileEntry> getPortletFileEntries( long groupId, long folderId, int status, int start, int end, OrderByComparator obc) throws SystemException { return toFileEntries( DLFileEntryLocalServiceUtil.getFileEntries(groupId, folderId, status, start, end, obc)); }
public DLFileEntryActionableDynamicQuery() { setBaseLocalService(DLFileEntryLocalServiceUtil.getService()); setClass(DLFileEntry.class); setClassLoader(PortalClassLoaderUtil.getClassLoader()); setPrimaryKeyPropertyName("fileEntryId"); }
@Override public boolean isEnabled() { try { return DLFileEntryLocalServiceUtil.hasExtraSettings(); } catch (Exception e) { _log.error(e, e); return false; } }
@Override public void deletePortletFileEntries(long groupId, long folderId) throws PortalException, SystemException { List<DLFileEntry> dlFileEntries = DLFileEntryLocalServiceUtil.getFileEntries(groupId, folderId); for (DLFileEntry dlFileEntry : dlFileEntries) { deletePortletFileEntry(dlFileEntry.getFileEntryId()); } }
public PortalDocumentLibrary(User currentUser) { try { this.currentUser = currentUser; processBaseGroup = GroupLocalServiceUtil.getGroup(currentUser.getCompanyId(), Constants.DL_GROUP); folderService = DLFolderLocalServiceUtil.getService(); fileService = DLFileEntryLocalServiceUtil.getService(); } catch (Exception ex) { ex.printStackTrace(); } }
@Override protected void doReindexDDMStructures(List<Long> ddmStructureIds) throws Exception { List<DLFileEntry> dlFileEntries = DLFileEntryLocalServiceUtil.getDDMStructureFileEntries( ArrayUtil.toLongArray(ddmStructureIds)); for (DLFileEntry dlFileEntry : dlFileEntries) { doReindex(dlFileEntry); } }
@Override public void addRelatedEntryFields(Document document, Object obj) throws Exception { MBMessage message = (MBMessage) obj; DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.getDLFileEntry(message.getClassPK()); document.addKeyword(Field.FOLDER_ID, dlFileEntry.getFolderId()); document.addKeyword(Field.HIDDEN, dlFileEntry.isInHiddenFolder()); document.addKeyword(Field.RELATED_ENTRY, true); }
@Override public void deleteRow(Object primaryKey) throws IOException { long fileEntryId = (Long) primaryKey; try { DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.getFileEntry(fileEntryId); DLFileEntryServiceUtil.deleteFileEntry( dlFolder.getGroupId(), dlFolder.getFolderId(), dlFileEntry.getName()); } catch (Exception e) { logger.error(e.getMessage(), e); throw new IOException(e.getMessage()); } }
protected void migrateDL() throws Exception { int count = DLFileEntryLocalServiceUtil.getDLFileEntriesCount(); int pages = count / Indexer.DEFAULT_INTERVAL; MaintenanceUtil.appendStatus("Migrating " + count + " document library files"); for (int i = 0; i <= pages; i++) { int start = (i * Indexer.DEFAULT_INTERVAL); int end = start + Indexer.DEFAULT_INTERVAL; List<DLFileEntry> dlFileEntries = DLFileEntryLocalServiceUtil.getDLFileEntries(start, end); String portletId = PortletKeys.DOCUMENT_LIBRARY; for (DLFileEntry dlFileEntry : dlFileEntries) { long companyId = dlFileEntry.getCompanyId(); long groupId = dlFileEntry.getGroupId(); long repositoryId = dlFileEntry.getRepositoryId(); migrateDLFileEntry(companyId, portletId, groupId, repositoryId, dlFileEntry); } } }
protected void reindexFileEntries(long companyId, final long groupId, final long dataRepositoryId) throws PortalException { final ActionableDynamicQuery actionableDynamicQuery = DLFileEntryLocalServiceUtil.getActionableDynamicQuery(); actionableDynamicQuery.setAddCriteriaMethod( new ActionableDynamicQuery.AddCriteriaMethod() { @Override public void addCriteria(DynamicQuery dynamicQuery) { Property property = PropertyFactoryUtil.forName("folderId"); long folderId = DLFolderConstants.getFolderId(groupId, dataRepositoryId); dynamicQuery.add(property.eq(folderId)); } }); actionableDynamicQuery.setCompanyId(companyId); actionableDynamicQuery.setGroupId(groupId); actionableDynamicQuery.setPerformActionMethod( new ActionableDynamicQuery.PerformActionMethod() { @Override public void performAction(Object object) { DLFileEntry dlFileEntry = (DLFileEntry) object; try { Document document = getDocument(dlFileEntry); if (document != null) { actionableDynamicQuery.addDocument(document); } } catch (PortalException pe) { if (_log.isWarnEnabled()) { _log.warn( "Unable to index document library file entry " + dlFileEntry.getFileEntryId(), pe); } } } }); actionableDynamicQuery.setSearchEngineId(getSearchEngineId()); actionableDynamicQuery.performActions(); }
@Override public void reindexDDMStructures(List<Long> ddmStructureIds) throws SearchException { if (SearchEngineUtil.isIndexReadOnly() || !isIndexerEnabled()) { return; } try { List<DLFileEntry> dlFileEntries = DLFileEntryLocalServiceUtil.getDDMStructureFileEntries( ArrayUtil.toLongArray(ddmStructureIds)); for (DLFileEntry dlFileEntry : dlFileEntries) { doReindex(dlFileEntry); } } catch (Exception e) { throw new SearchException(e); } }
@Override public List<FileEntry> fetchStagedModelsByUuidAndCompanyId(String uuid, long companyId) { List<DLFileEntry> dlFileEntries = DLFileEntryLocalServiceUtil.getDLFileEntriesByUuidAndCompanyId( uuid, companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, new StagedModelModifiedDateComparator<DLFileEntry>()); List<FileEntry> fileEntries = new ArrayList<>(); for (DLFileEntry dlFileEntry : dlFileEntries) { fileEntries.add(new LiferayFileEntry(dlFileEntry)); } return fileEntries; }
@Override public void reindexDDMStructures(List<Long> ddmStructureIds) throws SearchException { if (IndexWriterHelperUtil.isIndexReadOnly() || !isIndexerEnabled()) { return; } try { Indexer<DLFileEntry> indexer = IndexerRegistryUtil.nullSafeGetIndexer(DLFileEntry.class); List<DLFileEntry> dlFileEntries = DLFileEntryLocalServiceUtil.getDDMStructureFileEntries( ArrayUtil.toLongArray(ddmStructureIds)); for (DLFileEntry dlFileEntry : dlFileEntries) { indexer.reindex(dlFileEntry); } } catch (Exception e) { throw new SearchException(e); } }
@Override protected void doImportStagedModel(PortletDataContext portletDataContext, FileEntry fileEntry) throws Exception { long userId = portletDataContext.getUserId(fileEntry.getUserUuid()); if (!fileEntry.isDefaultRepository()) { // References has been automatically imported, nothing to do here return; } Map<Long, Long> folderIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Folder.class); long folderId = MapUtil.getLong(folderIds, fileEntry.getFolderId(), fileEntry.getFolderId()); long[] assetCategoryIds = portletDataContext.getAssetCategoryIds(DLFileEntry.class, fileEntry.getFileEntryId()); String[] assetTagNames = portletDataContext.getAssetTagNames(DLFileEntry.class, fileEntry.getFileEntryId()); ServiceContext serviceContext = portletDataContext.createServiceContext(fileEntry, DLFileEntry.class); serviceContext.setAttribute("sourceFileName", "A." + fileEntry.getExtension()); serviceContext.setUserId(userId); Element fileEntryElement = portletDataContext.getImportDataElement(fileEntry); String binPath = fileEntryElement.attributeValue("bin-path"); InputStream is = null; if (Validator.isNull(binPath) && portletDataContext.isPerformDirectBinaryImport()) { try { is = FileEntryUtil.getContentStream(fileEntry); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Unable to retrieve content for file entry " + fileEntry.getFileEntryId(), e); } return; } } else { is = portletDataContext.getZipEntryAsInputStream(binPath); } if (is == null) { if (_log.isWarnEnabled()) { _log.warn("No file found for file entry " + fileEntry.getFileEntryId()); } return; } importMetaData(portletDataContext, fileEntryElement, fileEntry, serviceContext); FileEntry importedFileEntry = null; if (portletDataContext.isDataStrategyMirror()) { FileEntry existingFileEntry = fetchStagedModelByUuidAndGroupId( fileEntry.getUuid(), portletDataContext.getScopeGroupId()); FileVersion fileVersion = fileEntry.getFileVersion(); if (existingFileEntry == null) { if (portletDataContext.isDataStrategyMirrorWithOverwriting()) { FileEntry existingTitleFileEntry = FileEntryUtil.fetchByR_F_T( portletDataContext.getScopeGroupId(), folderId, fileEntry.getTitle()); if (existingTitleFileEntry == null) { existingTitleFileEntry = FileEntryUtil.fetchByR_F_FN( portletDataContext.getScopeGroupId(), folderId, fileEntry.getFileName()); } if (existingTitleFileEntry != null) { DLAppLocalServiceUtil.deleteFileEntry(existingTitleFileEntry.getFileEntryId()); } } serviceContext.setAttribute("fileVersionUuid", fileVersion.getUuid()); serviceContext.setUuid(fileEntry.getUuid()); String fileEntryTitle = DLFileEntryLocalServiceUtil.getUniqueTitle( portletDataContext.getScopeGroupId(), folderId, 0, fileEntry.getTitle(), fileEntry.getExtension()); importedFileEntry = DLAppLocalServiceUtil.addFileEntry( userId, portletDataContext.getScopeGroupId(), folderId, fileEntry.getFileName(), fileEntry.getMimeType(), fileEntryTitle, fileEntry.getDescription(), null, is, fileEntry.getSize(), serviceContext); if (fileEntry.isInTrash()) { importedFileEntry = DLAppServiceUtil.moveFileEntryToTrash(importedFileEntry.getFileEntryId()); } } else { FileVersion latestExistingFileVersion = existingFileEntry.getLatestFileVersion(true); boolean indexEnabled = serviceContext.isIndexingEnabled(); boolean deleteFileEntry = false; boolean updateFileEntry = false; if (!Validator.equals(fileVersion.getUuid(), latestExistingFileVersion.getUuid())) { deleteFileEntry = true; updateFileEntry = true; } else { InputStream existingFileVersionInputStream = null; try { existingFileVersionInputStream = latestExistingFileVersion.getContentStream(false); } catch (Exception e) { if (_log.isDebugEnabled()) { _log.debug(e, e); } } finally { if (existingFileVersionInputStream != null) { existingFileVersionInputStream.close(); } } if (existingFileVersionInputStream == null) { updateFileEntry = true; } } try { serviceContext.setIndexingEnabled(false); if (updateFileEntry) { DLFileVersion alreadyExistingFileVersion = DLFileVersionLocalServiceUtil.getFileVersionByUuidAndGroupId( fileVersion.getUuid(), existingFileEntry.getGroupId()); if (alreadyExistingFileVersion != null) { serviceContext.setAttribute( "existingDLFileVersionId", alreadyExistingFileVersion.getFileVersionId()); } serviceContext.setUuid(fileVersion.getUuid()); String fileEntryTitle = DLFileEntryLocalServiceUtil.getUniqueTitle( portletDataContext.getScopeGroupId(), existingFileEntry.getFolderId(), existingFileEntry.getFileEntryId(), fileEntry.getTitle(), fileEntry.getExtension()); importedFileEntry = DLAppLocalServiceUtil.updateFileEntry( userId, existingFileEntry.getFileEntryId(), fileEntry.getFileName(), fileEntry.getMimeType(), fileEntryTitle, fileEntry.getDescription(), null, false, is, fileEntry.getSize(), serviceContext); } else { DLAppLocalServiceUtil.updateAsset( userId, existingFileEntry, latestExistingFileVersion, assetCategoryIds, assetTagNames, null); importedFileEntry = existingFileEntry; } if (importedFileEntry.getFolderId() != folderId) { importedFileEntry = DLAppLocalServiceUtil.moveFileEntry( userId, importedFileEntry.getFileEntryId(), folderId, serviceContext); } if (importedFileEntry instanceof LiferayFileEntry) { LiferayFileEntry liferayFileEntry = (LiferayFileEntry) importedFileEntry; Indexer<DLFileEntry> indexer = IndexerRegistryUtil.nullSafeGetIndexer(DLFileEntry.class); indexer.reindex((DLFileEntry) liferayFileEntry.getModel()); } if (deleteFileEntry && ExportImportThreadLocal.isStagingInProcess()) { DLAppServiceUtil.deleteFileVersion( latestExistingFileVersion.getFileEntryId(), latestExistingFileVersion.getVersion()); } } finally { serviceContext.setIndexingEnabled(indexEnabled); } } } else { String fileEntryTitle = DLFileEntryLocalServiceUtil.getUniqueTitle( portletDataContext.getScopeGroupId(), folderId, 0, fileEntry.getTitle(), fileEntry.getExtension()); importedFileEntry = DLAppLocalServiceUtil.addFileEntry( userId, portletDataContext.getScopeGroupId(), folderId, fileEntry.getFileName(), fileEntry.getMimeType(), fileEntryTitle, fileEntry.getDescription(), null, is, fileEntry.getSize(), serviceContext); } if (portletDataContext.getBooleanParameter("document_library", "previews-and-thumbnails")) { DLProcessorRegistryUtil.importGeneratedFiles( portletDataContext, fileEntry, importedFileEntry, fileEntryElement); } portletDataContext.importClassedModel(fileEntry, importedFileEntry, DLFileEntry.class); Map<Long, Long> fileEntryIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(FileEntry.class); fileEntryIds.put(fileEntry.getFileEntryId(), importedFileEntry.getFileEntryId()); }
private String formatJournalArticleURL() { /* This checks if the object is viewable by the current user and, if so, works out * the original url for the search results. The "visible" flag variable is set for each one. */ Long lGroupId; Long lArticleId; Long lUserId; String strJournalURL = Global.strNoURLReturned; JournalContentSearchLocalServiceUtil jcslu = new JournalContentSearchLocalServiceUtil(); LayoutLocalServiceUtil llsu = new LayoutLocalServiceUtil(); List<Long> listLayouts = new ArrayList<Long>(); Layout layLayout; User user; int iCount = 0; this.isVisible = false; try { this.context = FacesContext.getCurrentInstance(); this.portletRequest = (PortletRequest) context.getExternalContext().getRequest(); this.themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); } catch (Exception e) { System.out.println(e); } try { lGroupId = Long.decode(this.getGroupId()); } catch (NumberFormatException n) { lGroupId = 0l; // zero long, not letter O } try { lArticleId = Long.decode(this.getArticleId()); } catch (NumberFormatException n) { lArticleId = 0l; // zero long, not letter O } try { lUserId = Long.decode(this.getUserId()); } catch (NumberFormatException n) { lUserId = 0l; // zero long, not letter O } if ((lGroupId != 0) && (lArticleId != 0)) { try { try { permissionChecker = themeDisplay.getPermissionChecker(); this.setIsVisible( permissionChecker.hasPermission( lGroupId, this.entryClassName, this.rootEntryClassPK, ActionKeys.VIEW)); if (this.isIsVisible()) { if (getEntryClassName().equalsIgnoreCase(JournalArticle.class.getName())) { iCount = jcslu.getLayoutIdsCount(lGroupId, false, articleId); listLayouts = jcslu.getLayoutIds(lGroupId, false, articleId); if (iCount > 0) { layLayout = llsu.getLayout(lGroupId, false, listLayouts.get(0)); layoutFriendlyURL = PortalUtil.getLayoutFriendlyURL(layLayout, themeDisplay); layoutFullURL = PortalUtil.getLayoutActualURL(layLayout, themeDisplay.getPathMain()); strHost = portletRequest.getServerName(); iServerPort = portletRequest.getServerPort(); strScheme = portletRequest.getScheme(); if (layoutFullURL.startsWith("http://")) { strJournalURL = layoutFullURL; } else { if (strHost.equalsIgnoreCase("localhost")) { strJournalURL = strScheme + "://" + strHost + ":" + iServerPort + layoutFriendlyURL; } else { strJournalURL = layoutFriendlyURL; } } } } else if (getEntryClassName().equalsIgnoreCase(BlogsEntry.class.getName())) { BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(lArticleId); Group trgtGroup = GroupLocalServiceUtil.getGroup(lGroupId); String strFrUrl = trgtGroup.getFriendlyURL(); String strUrlPath; user = UserLocalServiceUtil.getUser(lUserId); if (strFrUrl.equalsIgnoreCase("/fishnet")) { strUrlPath = "/home/-/blogs/"; } else if (strFrUrl.equalsIgnoreCase("/fishlink")) { strUrlPath = "/home/-/blogs/"; } else if (strFrUrl.equalsIgnoreCase("/freshwater-biological-association")) { strUrlPath = "/home/-/blogs/"; } else { strUrlPath = "/blog/-/blogs/"; } layoutFriendlyURL = "/web" + strFrUrl + strUrlPath + entry.getUrlTitle(); strHost = portletRequest.getServerName(); iServerPort = portletRequest.getServerPort(); strScheme = portletRequest.getScheme(); strJournalURL = strScheme + "://" + strHost + ":" + iServerPort + layoutFriendlyURL; } else if (getEntryClassName().equalsIgnoreCase(WikiPage.class.getName())) { WikiPageResource pageResource = WikiPageResourceLocalServiceUtil.getPageResource(lArticleId); WikiPage wikiPage = WikiPageLocalServiceUtil.getPage( pageResource.getNodeId(), pageResource.getTitle()); WikiNode wikiNode = WikiNodeLocalServiceUtil.getNode(pageResource.getNodeId()); String strWikiNodeName = wikiNode.getName(); String strWikiTitle = wikiPage.getTitle(); Long lPageGroupId = wikiPage.getGroupId(); Group trgtGroup = GroupLocalServiceUtil.getGroup(lPageGroupId); String strFrUrl = trgtGroup.getFriendlyURL(); strHost = portletRequest.getServerName(); iServerPort = portletRequest.getServerPort(); strScheme = portletRequest.getScheme(); // Extremely nasty hack! if (strFrUrl.equalsIgnoreCase("/tera")) { String strReplacedTitle = strWikiTitle.replaceAll("\\s", "\\+"); layoutFriendlyURL = "/web" + strFrUrl + "/home?p_p_id=54_INSTANCE_rU18&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=1&_54_INSTANCE_rU18_struts_action=%2Fwiki_display%2Fview&_54_INSTANCE_rU18_nodeName=" + strWikiNodeName + "&_54_INSTANCE_rU18_title=" + strReplacedTitle; } else if (strFrUrl.equalsIgnoreCase("/fwl")) { layoutFriendlyURL = "/web" + strFrUrl + "/wiki/-/wiki/" + strWikiNodeName + "/" + strWikiTitle; } else if (strFrUrl.equalsIgnoreCase("/fishlink")) { layoutFriendlyURL = "/web" + strFrUrl + strFrUrl + "-wiki/-/wiki/" + strWikiNodeName + "/" + strWikiTitle; } else { layoutFriendlyURL = "/freshwater-wiki/-/wiki/" + strWikiNodeName + "/" + strWikiTitle; } // </hack> strJournalURL = strScheme + "://" + strHost + ":" + iServerPort + layoutFriendlyURL; } else if (getEntryClassName().equalsIgnoreCase(DLFileEntry.class.getName())) { DLFileEntry fileEntry = DLFileEntryLocalServiceUtil.getFileEntry(lArticleId); lGroupId = fileEntry.getGroupId(); AssetEntry assetEntry = AssetEntryLocalServiceUtil.getEntry(getEntryClassName(), lArticleId); Long lEntryId = assetEntry.getEntryId(); strHost = portletRequest.getServerName(); iServerPort = portletRequest.getServerPort(); strScheme = portletRequest.getScheme(); // Another hack layoutFriendlyURL = "/fwl/documents/-/asset_publisher/8Ztl/document/id/" + lEntryId; strJournalURL = strScheme + "://" + strHost + ":" + iServerPort + "/web" + layoutFriendlyURL; if (fileEntry.getTitle().isEmpty()) { this.setTitle("From Document Library"); } else { this.setTitle(fileEntry.getTitle()); } // } else if (getEntryClassName().equalsIgnoreCase(IGImage.class.getName())) { IGImage image = IGImageLocalServiceUtil.getImage(lArticleId); strHost = portletRequest.getServerName(); iServerPort = portletRequest.getServerPort(); strScheme = portletRequest.getScheme(); layoutFriendlyURL = "igimage.fba.org.uk"; // if (layoutFullURL.startsWith("http://")) { // strJournalURL = layoutFullURL; // } else { strJournalURL = strScheme + "://" + strHost + ":" + iServerPort + layoutFriendlyURL; // } // PortletURL viewImageURL = new PortletURLImpl(request, PortletKeys.IMAGE_GALLERY, // plid, PortletRequest.RENDER_PHASE); // viewImageURL.setWindowState(WindowState.MAXIMIZED); // viewImageURL.setParameter("struts_action", "/image_gallery/view"); // viewImageURL.setParameter("folderId", String.valueOf(image.getFolderId())); } else if (getEntryClassName().equalsIgnoreCase(MBMessage.class.getName())) { MBMessage message = MBMessageLocalServiceUtil.getMessage(lArticleId); String aHref = "<a href=" + themeDisplay.getPathMain() + "/message_boards/find_message?messageId=" + message.getMessageId() + ">"; strHost = portletRequest.getServerName(); iServerPort = portletRequest.getServerPort(); strScheme = portletRequest.getScheme(); layoutFriendlyURL = "mbmessage.fba.org.uk"; // if (layoutFullURL.startsWith("http://")) { // strJournalURL = layoutFullURL; // } else { strJournalURL = strScheme + "://" + strHost + ":" + iServerPort + layoutFriendlyURL; // } } else if (getEntryClassName().equalsIgnoreCase(BookmarksEntry.class.getName())) { BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(lArticleId); String entryURL = themeDisplay.getPathMain() + "/bookmarks/open_entry?entryId=" + entry.getEntryId(); strHost = portletRequest.getServerName(); iServerPort = portletRequest.getServerPort(); strScheme = portletRequest.getScheme(); layoutFriendlyURL = "bookmarks.fba.org.uk"; // if (layoutFullURL.startsWith("http://")) { // strJournalURL = layoutFullURL; // } else { strJournalURL = strScheme + "://" + strHost + ":" + iServerPort + layoutFriendlyURL; // } } } } catch (PortalException ex) { Logger.getLogger(Liferay.class.getName()).log(Level.SEVERE, null, ex); } } catch (SystemException ex) { Logger.getLogger(Liferay.class.getName()).log(Level.SEVERE, null, ex); } } return strJournalURL; }
public DLFileEntry getFileEntry() throws PortalException, SystemException { return DLFileEntryLocalServiceUtil.getFileEntry(getFileEntryId()); }
@Override public List<FileEntry> getPortletFileEntries(long groupId, long folderId) throws SystemException { return toFileEntries(DLFileEntryLocalServiceUtil.getFileEntries(groupId, folderId)); }
protected SocialActivityFeedEntry doInterpret(SocialActivity activity, ThemeDisplay themeDisplay) throws Exception { PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); DLFileEntry fileEntry = DLFileEntryLocalServiceUtil.getDLFileEntry(activity.getClassPK()); if (!DLFileEntryPermission.contains(permissionChecker, fileEntry, ActionKeys.VIEW)) { return null; } String groupName = StringPool.BLANK; if (activity.getGroupId() != themeDisplay.getScopeGroupId()) { groupName = getGroupName(activity.getGroupId(), themeDisplay); } String creatorUserName = getUserName(activity.getUserId(), themeDisplay); int activityType = activity.getType(); // Link String link = themeDisplay.getPortalURL() + themeDisplay.getPathMain() + "/document_library/get_file?groupId=" + fileEntry.getGroupId() + "&folderId=" + fileEntry.getFolderId() + "&name=" + fileEntry.getName(); // Title String titlePattern = null; if (activityType == DLActivityKeys.ADD_FILE_ENTRY) { titlePattern = "activity-document-library-add-file"; } else if (activityType == DLActivityKeys.UPDATE_FILE_ENTRY) { titlePattern = "activity-document-library-update-file"; } if (Validator.isNotNull(groupName)) { titlePattern += "-in"; } String fileTitle = wrapLink(link, HtmlUtil.escape(cleanContent(fileEntry.getTitle()))); Object[] titleArguments = new Object[] {groupName, creatorUserName, fileTitle}; String title = themeDisplay.translate(titlePattern, titleArguments); // Body StringBundler sb = new StringBundler(3); String fileEntryLink = themeDisplay.getPortalURL() + themeDisplay.getPathMain() + "/document_library/find_file_entry?fileEntryId=" + fileEntry.getFileEntryId(); sb.append(wrapLink(fileEntryLink, "view-document", themeDisplay)); sb.append(StringPool.SPACE); String folderLink = themeDisplay.getPortalURL() + themeDisplay.getPathMain() + "/document_library/find_folder?groupId=" + fileEntry.getGroupId() + "&folderId=" + fileEntry.getFolderId(); sb.append(wrapLink(folderLink, "go-to-folder", themeDisplay)); String body = sb.toString(); return new SocialActivityFeedEntry(link, title, body); }
public File getFile(boolean incrementCounter) throws PortalException { return DLFileEntryLocalServiceUtil.getFile( _dlFileVersion.getFileEntryId(), _dlFileVersion.getVersion(), incrementCounter); }
protected static String exportDLFileEntries( PortletDataContext portletDataContext, Element dlFileEntryTypesElement, Element dlFoldersElement, Element dlFileEntriesElement, Element dlFileRanksElement, Element dlRepositoriesElement, Element dlRepositoryEntriesElement, Element entityElement, String content, boolean checkDateRange) throws Exception { Group group = GroupLocalServiceUtil.getGroup(portletDataContext.getGroupId()); if (group.isStagingGroup()) { group = group.getLiveGroup(); } if (group.isStaged() && !group.isStagedRemotely() && !group.isStagedPortlet(PortletKeys.DOCUMENT_LIBRARY)) { return content; } StringBuilder sb = new StringBuilder(content); int beginPos = content.length(); int currentLocation = -1; boolean legacyURL = true; while (true) { String contextPath = PortalUtil.getPathContext(); currentLocation = content.lastIndexOf(contextPath.concat("/c/document_library/get_file?"), beginPos); if (currentLocation == -1) { currentLocation = content.lastIndexOf(contextPath.concat("/image/image_gallery?"), beginPos); } if (currentLocation == -1) { currentLocation = content.lastIndexOf(contextPath.concat("/documents/"), beginPos); legacyURL = false; } if (currentLocation == -1) { return sb.toString(); } beginPos = currentLocation + contextPath.length(); int endPos1 = content.indexOf(CharPool.APOSTROPHE, beginPos); int endPos2 = content.indexOf(CharPool.CLOSE_BRACKET, beginPos); int endPos3 = content.indexOf(CharPool.CLOSE_CURLY_BRACE, beginPos); int endPos4 = content.indexOf(CharPool.CLOSE_PARENTHESIS, beginPos); int endPos5 = content.indexOf(CharPool.LESS_THAN, beginPos); int endPos6 = content.indexOf(CharPool.QUESTION, beginPos); int endPos7 = content.indexOf(CharPool.QUOTE, beginPos); int endPos8 = content.indexOf(CharPool.SPACE, beginPos); int endPos = endPos1; if ((endPos == -1) || ((endPos2 != -1) && (endPos2 < endPos))) { endPos = endPos2; } if ((endPos == -1) || ((endPos3 != -1) && (endPos3 < endPos))) { endPos = endPos3; } if ((endPos == -1) || ((endPos4 != -1) && (endPos4 < endPos))) { endPos = endPos4; } if ((endPos == -1) || ((endPos5 != -1) && (endPos5 < endPos))) { endPos = endPos5; } if ((endPos == -1) || ((endPos6 != -1) && (endPos6 < endPos) && !legacyURL)) { endPos = endPos6; } if ((endPos == -1) || ((endPos7 != -1) && (endPos7 < endPos))) { endPos = endPos7; } if ((endPos == -1) || ((endPos8 != -1) && (endPos8 < endPos))) { endPos = endPos8; } if ((beginPos == -1) || (endPos == -1)) { break; } try { String oldParameters = content.substring(beginPos, endPos); while (oldParameters.contains(StringPool.AMPERSAND_ENCODED)) { oldParameters = oldParameters.replace(StringPool.AMPERSAND_ENCODED, StringPool.AMPERSAND); } Map<String, String[]> map = new HashMap<String, String[]>(); if (oldParameters.startsWith("/documents/")) { String[] pathArray = oldParameters.split(StringPool.SLASH); map.put("groupId", new String[] {pathArray[2]}); if (pathArray.length == 4) { map.put("uuid", new String[] {pathArray[3]}); } else if (pathArray.length == 5) { map.put("folderId", new String[] {pathArray[3]}); String title = HttpUtil.decodeURL(pathArray[4]); int pos = title.indexOf(StringPool.QUESTION); if (pos != -1) { title = title.substring(0, pos); } map.put("title", new String[] {title}); } else if (pathArray.length > 5) { String uuid = pathArray[5]; int pos = uuid.indexOf(StringPool.QUESTION); if (pos != -1) { uuid = uuid.substring(0, pos); } map.put("uuid", new String[] {uuid}); } } else { oldParameters = oldParameters.substring(oldParameters.indexOf(CharPool.QUESTION) + 1); map = HttpUtil.parameterMapFromString(oldParameters); } FileEntry fileEntry = null; String uuid = MapUtil.getString(map, "uuid"); if (Validator.isNotNull(uuid)) { String groupIdString = MapUtil.getString(map, "groupId"); long groupId = GetterUtil.getLong(groupIdString); if (groupIdString.equals("@group_id@")) { groupId = portletDataContext.getScopeGroupId(); } fileEntry = DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId); } else { String folderIdString = MapUtil.getString(map, "folderId"); if (Validator.isNotNull(folderIdString)) { long folderId = GetterUtil.getLong(folderIdString); String name = MapUtil.getString(map, "name"); String title = MapUtil.getString(map, "title"); String groupIdString = MapUtil.getString(map, "groupId"); long groupId = GetterUtil.getLong(groupIdString); if (groupIdString.equals("@group_id@")) { groupId = portletDataContext.getScopeGroupId(); } if (Validator.isNotNull(title)) { fileEntry = DLAppLocalServiceUtil.getFileEntry(groupId, folderId, title); } else { DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.getFileEntryByName(groupId, folderId, name); fileEntry = new LiferayFileEntry(dlFileEntry); } } else if (map.containsKey("image_id") || map.containsKey("img_id") || map.containsKey("i_id")) { long imageId = MapUtil.getLong(map, "image_id"); if (imageId <= 0) { imageId = MapUtil.getLong(map, "img_id"); if (imageId <= 0) { imageId = MapUtil.getLong(map, "i_id"); } } DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.fetchFileEntryByAnyImageId(imageId); if (dlFileEntry != null) { fileEntry = new LiferayFileEntry(dlFileEntry); } } } if (fileEntry == null) { beginPos--; continue; } beginPos = currentLocation; DLPortletDataHandler.exportFileEntry( portletDataContext, dlFileEntryTypesElement, dlFoldersElement, dlFileEntriesElement, dlFileRanksElement, dlRepositoriesElement, dlRepositoryEntriesElement, fileEntry, checkDateRange); Element dlReferenceElement = entityElement.addElement("dl-reference"); dlReferenceElement.addAttribute( "default-repository", String.valueOf(fileEntry.isDefaultRepository())); String path = null; if (fileEntry.isDefaultRepository()) { path = DLPortletDataHandler.getFileEntryPath(portletDataContext, fileEntry); } else { path = DLPortletDataHandler.getRepositoryEntryPath( portletDataContext, fileEntry.getFileEntryId()); } dlReferenceElement.addAttribute("path", path); String dlReference = "[$dl-reference=" + path + "$]"; sb.replace(beginPos, endPos, dlReference); } catch (Exception e) { if (_log.isDebugEnabled()) { _log.debug(e, e); } else if (_log.isWarnEnabled()) { _log.warn(e.getMessage()); } } beginPos--; } return sb.toString(); }
@Before public void setUp() throws Exception { FinderCacheUtil.clearCache(); _liveGroup = GroupTestUtil.addGroup(); _stagingGroup = GroupTestUtil.addGroup(); _fileEntry = DLAppTestUtil.addFileEntry( _stagingGroup.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, ServiceTestUtil.randomString() + ".txt", ServiceTestUtil.randomString(), true); LiferayFileEntry liferayFileEntry = (LiferayFileEntry) _fileEntry; DLFileEntry dlFileEntry = liferayFileEntry.getDLFileEntry(); dlFileEntry.setLargeImageId(dlFileEntry.getFileEntryId()); DLFileEntryLocalServiceUtil.updateDLFileEntry(dlFileEntry); TestReaderWriter testReaderWriter = new TestReaderWriter(); _portletDataContextExport = PortletDataContextFactoryUtil.createExportPortletDataContext( _stagingGroup.getCompanyId(), _stagingGroup.getGroupId(), new HashMap<String, String[]>(), new Date(System.currentTimeMillis() - Time.HOUR), new Date(), testReaderWriter); Element rootElement = SAXReaderUtil.createElement("root"); _portletDataContextExport.setExportDataRootElement(rootElement); _stagingPrivateLayout = LayoutTestUtil.addLayout(_stagingGroup.getGroupId(), ServiceTestUtil.randomString(), true); _stagingPublicLayout = LayoutTestUtil.addLayout(_stagingGroup.getGroupId(), ServiceTestUtil.randomString(), false); _portletDataContextExport.setPlid(_stagingPublicLayout.getPlid()); _portletDataContextImport = PortletDataContextFactoryUtil.createImportPortletDataContext( _stagingGroup.getCompanyId(), _stagingGroup.getGroupId(), new HashMap<String, String[]>(), new CurrentUserIdStrategy(TestPropsValues.getUser()), testReaderWriter); _portletDataContextImport.setImportDataRootElement(rootElement); _livePublicLayout = LayoutTestUtil.addLayout(_liveGroup.getGroupId(), ServiceTestUtil.randomString(), false); _portletDataContextImport.setPlid(_livePublicLayout.getPlid()); _portletDataContextImport.setSourceGroupId(_stagingGroup.getGroupId()); rootElement.addElement("entry"); _referrerStagedModel = JournalTestUtil.addArticle( _stagingGroup.getGroupId(), ServiceTestUtil.randomString(), ServiceTestUtil.randomString()); }
@Override protected void doReindex(String className, long classPK) throws Exception { DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.getFileEntry(classPK); doReindex(dlFileEntry); }
@Override public int getPortletFileEntriesCount(long groupId, long folderId, int status) throws SystemException { return DLFileEntryLocalServiceUtil.getFileEntriesCount(groupId, folderId, status); }
public static List<Object> getEntries(Hits hits) { List<Object> entries = new ArrayList<Object>(); for (Document document : hits.getDocs()) { long categoryId = GetterUtil.getLong(document.get(Field.CATEGORY_ID)); try { MBCategoryLocalServiceUtil.getCategory(categoryId); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn( "Message boards search index is stale and contains " + "category " + categoryId); } continue; } long threadId = GetterUtil.getLong(document.get("threadId")); try { MBThreadLocalServiceUtil.getThread(threadId); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Message boards search index is stale and contains " + "thread " + threadId); } continue; } String entryClassName = document.get(Field.ENTRY_CLASS_NAME); long entryClassPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK)); Object obj = null; try { if (entryClassName.equals(DLFileEntry.class.getName())) { long classPK = GetterUtil.getLong(document.get(Field.CLASS_PK)); MBMessageLocalServiceUtil.getMessage(classPK); obj = DLFileEntryLocalServiceUtil.getDLFileEntry(entryClassPK); } else if (entryClassName.equals(MBMessage.class.getName())) { obj = MBMessageLocalServiceUtil.getMessage(entryClassPK); } entries.add(obj); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn( "Message boards search index is stale and contains " + "entry {className=" + entryClassName + ", " + "classPK=" + entryClassPK + "}"); } continue; } } return entries; }
protected void getFile( long fileEntryId, long folderId, String name, String title, String version, long fileShortcutId, String uuid, long groupId, String targetExtension, HttpServletRequest request, HttpServletResponse response) throws Exception { if (name.startsWith("DLFE-")) { name = name.substring(5); } name = FileUtil.stripExtension(name); FileEntry fileEntry = null; if (Validator.isNotNull(uuid) && (groupId > 0)) { fileEntry = DLAppServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId); folderId = fileEntry.getFolderId(); } if (fileEntryId > 0) { fileEntry = DLAppServiceUtil.getFileEntry(fileEntryId); } else if (fileShortcutId <= 0) { if (Validator.isNotNull(title)) { fileEntry = DLAppServiceUtil.getFileEntry(groupId, folderId, title); } else if (Validator.isNotNull(name)) { DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.fetchFileEntryByName(groupId, folderId, name); if (dlFileEntry == null) { // LPS-30374 List<DLFileEntry> dlFileEntries = DLFileEntryLocalServiceUtil.getFileEntries(folderId, name); if (!dlFileEntries.isEmpty()) { dlFileEntry = dlFileEntries.get(0); } } if (dlFileEntry != null) { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); DLFileEntryPermission.check(permissionChecker, dlFileEntry, ActionKeys.VIEW); fileEntry = new LiferayFileEntry(dlFileEntry); } } } else { DLFileShortcut fileShortcut = DLAppServiceUtil.getFileShortcut(fileShortcutId); fileEntryId = fileShortcut.getToFileEntryId(); fileEntry = DLAppServiceUtil.getFileEntry(fileEntryId); } if (Validator.isNull(version)) { if ((fileEntry != null) && Validator.isNotNull(fileEntry.getVersion())) { version = fileEntry.getVersion(); } else { throw new NoSuchFileEntryException(); } } FileVersion fileVersion = fileEntry.getFileVersion(version); InputStream is = fileVersion.getContentStream(true); String fileName = fileVersion.getTitle(); long contentLength = fileVersion.getSize(); String contentType = fileVersion.getMimeType(); if (Validator.isNotNull(targetExtension)) { String id = DLUtil.getTempFileId(fileEntry.getFileEntryId(), version); String sourceExtension = fileVersion.getExtension(); if (!fileName.endsWith(StringPool.PERIOD + sourceExtension)) { fileName += StringPool.PERIOD + sourceExtension; } File convertedFile = DocumentConversionUtil.convert(id, is, sourceExtension, targetExtension); if (convertedFile != null) { fileName = FileUtil.stripExtension(fileName).concat(StringPool.PERIOD).concat(targetExtension); is = new FileInputStream(convertedFile); contentLength = convertedFile.length(); contentType = MimeTypesUtil.getContentType(fileName); } } ServletResponseUtil.sendFile(request, response, fileName, is, contentLength, contentType); }