001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.messageboards.util;
016    
017    import com.liferay.message.boards.kernel.model.MBMessage;
018    import com.liferay.message.boards.kernel.service.MBMessageLocalServiceUtil;
019    import com.liferay.portal.kernel.exception.PortalException;
020    import com.liferay.portal.kernel.portletfilerepository.PortletFileRepositoryUtil;
021    import com.liferay.portal.kernel.repository.model.FileEntry;
022    import com.liferay.portal.kernel.repository.model.Folder;
023    import com.liferay.portal.kernel.util.GetterUtil;
024    
025    /**
026     * @author Eudaldo Alonso
027     */
028    public class MBMessageAttachmentsUtil {
029    
030            public static MBMessage fetchMessage(long fileEntryId)
031                    throws PortalException {
032    
033                    return MBMessageLocalServiceUtil.fetchMBMessage(
034                            getMessageId(fileEntryId));
035            }
036    
037            public static MBMessage getMessage(long fileEntryId)
038                    throws PortalException {
039    
040                    return MBMessageLocalServiceUtil.getMBMessage(
041                            getMessageId(fileEntryId));
042            }
043    
044            protected static long getMessageId(long fileEntryId)
045                    throws PortalException {
046    
047                    FileEntry fileEntry = PortletFileRepositoryUtil.getPortletFileEntry(
048                            fileEntryId);
049    
050                    Folder folder = PortletFileRepositoryUtil.getPortletFolder(
051                            fileEntry.getFolderId());
052    
053                    return GetterUtil.getLong(folder.getName());
054            }
055    
056    }