/**
* OpenCPS is the open source Core Public Services software
* Copyright (C) 2016-present OpenCPS community

* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/

package org.opencps.util;

import java.io.InputStream;

import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.repository.model.FileEntry;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portlet.documentlibrary.model.DLFolder;
import com.liferay.portlet.documentlibrary.service.DLAppLocalServiceUtil;
import com.liferay.portlet.documentlibrary.service.DLAppServiceUtil;

/**
 * @author trungnt
 */
public class DLFileEntryUtil {

	public static FileEntry addFileEntry(
	    long repositoryId, long folderId, String sourceFileName,
	    String contentType, String title, String description, String changeLog,
	    InputStream inputStream, long size, ServiceContext serviceContext) {

		FileEntry fileEntry = null;

		try {
			fileEntry = DLAppServiceUtil
			    .addFileEntry(
			        repositoryId, folderId, sourceFileName, contentType, title,
			        description, changeLog, inputStream, size, serviceContext);
		}
		catch (Exception e) {
			_log
			    .error(e);
		}

		return fileEntry;
	}

	public static FileEntry addFileEntryToTargetFolder(
	    long userId, long groupId, boolean mountPoint, long parentFolderId,
	    boolean hidden, String destination, long repositoryId,
	    String sourceFileName, String contentType, String title,
	    String description, String changeLog, InputStream inputStream,
	    long size, ServiceContext serviceContext) {

		FileEntry fileEntry = null;

		try {
			DLFolder dlFolder = DLFolderUtil
			    .getTargetFolder(
			        userId, groupId, repositoryId, mountPoint, parentFolderId,
			        destination, description, hidden, serviceContext);
			fileEntry = DLAppServiceUtil
			    .addFileEntry(repositoryId, dlFolder
			        .getFolderId(), sourceFileName, contentType, title,
			        description, changeLog, inputStream, size, serviceContext);
		}
		catch (Exception e) {
			_log
			    .error(e);
		}

		return fileEntry;
	}

	public static FileEntry getFileEntry(long fileEntryId) {

		FileEntry fileEntry = null;
		try {
			fileEntry = DLAppLocalServiceUtil
			    .getFileEntry(fileEntryId);
		}
		catch (Exception e) {
			_log
			    .error(e);
		}
		return fileEntry;
	}

	private static Log _log = LogFactoryUtil
	    .getLog(DLFileEntryUtil.class
	        .getName());
}

@@ -796,16 +796,133 @@
 tream;%0A%0A
+import org.opencps.dossiermgt.model.DossierFile;%0Aimport org.opencps.dossiermgt.service.DossierFileLocalServiceUtil;%0A%0A
 import c
@@ -955,16 +955,16 @@
 og.Log;%0A
-
 import c
@@ -1069,16 +1069,66 @@
 eEntry;%0A
+import com.liferay.portal.kernel.util.StringPool;%0A
 import c
@@ -1169,16 +1169,62 @@
 ontext;%0A
+import com.liferay.portal.theme.ThemeDisplay;%0A
 import c
@@ -1344,24 +1344,24 @@
 erviceUtil;%0A
-
 import com.l
@@ -1416,16 +1416,72 @@
 iceUtil;
+%0Aimport com.liferay.portlet.documentlibrary.util.DLUtil;
 %0A%0A/**%0A *
@@ -3240,24 +3240,653 @@
 ileEntry;%0A%09%7D
+%0A%09%0A%09public static String getDossierFileAttachmentURL(%0A%09%09long dossierFileId, ThemeDisplay themeDisplay) %7B%0A%0A%09%09String url = StringPool.BLANK;%0A%09%09try %7B%0A%09%09%09DossierFile dossierFile = DossierFileLocalServiceUtil%0A%09%09%09%09.getDossierFile(dossierFileId);%0A%09%09%09long fileEntryId = dossierFile%0A%09%09%09%09.getFileEntryId();%0A%09%09%09if (fileEntryId %3E 0) %7B%0A%09%09%09%09FileEntry fileEntry = DLFileEntryUtil%0A%09%09%09%09%09.getFileEntry(fileEntryId);%0A%09%09%09%09if (fileEntry != null) %7B%0A%09%09%09%09%09url = DLUtil%0A%09%09%09%09%09%09.getPreviewURL(fileEntry, fileEntry%0A%09%09%09%09%09%09%09.getFileVersion(), themeDisplay, StringPool.BLANK);%0A%09%09%09%09%7D%0A%0A%09%09%09%7D%0A%09%09%7D%0A%09%09catch (Exception e) %7B%0A%09%09%09_log%0A%09%09%09%09.error(e);%0A%09%09%7D%0A%09%09return url;%0A%09%7D
 %0A%0A%09private s

Add method get dossier file url