import com.liferay.portlet.documentlibrary.model.DLFolder; //导入方法依赖的package包/类
private long createIGFolders(PortletRequest request,long userId,long repositoryId) throws PortalException, SystemException{
//Variables for folder ids
Long igMainFolderId = 0L;
Long igPortletFolderId = 0L;
Long igRecordFolderId = 0L;
//Search for folders
boolean igMainFolderFound = false;
boolean igPortletFolderFound = false;
try {
//Get the main folder
Folder igMainFolder = DLAppLocalServiceUtil.getFolder(repositoryId,DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,IMAGEGALLERY_MAINFOLDER);
igMainFolderId = igMainFolder.getFolderId();
igMainFolderFound = true;
//Get the portlet folder
DLFolder igPortletFolder = DLFolderLocalServiceUtil.getFolder(repositoryId,igMainFolderId,IMAGEGALLERY_PORTLETFOLDER);
igPortletFolderId = igPortletFolder.getFolderId();
igPortletFolderFound = true;
} catch (Exception ex) {
}
ServiceContext serviceContext= ServiceContextFactory.getInstance( DLFolder.class.getName(), request);
//Damos permisos al archivo para usuarios de comunidad.
serviceContext.setAddGroupPermissions(true);
serviceContext.setAddGuestPermissions(true);
//Create main folder if not exist
if(!igMainFolderFound) {
Folder newImageMainFolder=DLAppLocalServiceUtil.addFolder(userId, repositoryId, 0, IMAGEGALLERY_MAINFOLDER, IMAGEGALLERY_MAINFOLDER_DESCRIPTION, serviceContext);
igMainFolderId = newImageMainFolder.getFolderId();
igMainFolderFound = true;
}
//Create portlet folder if not exist
if(igMainFolderFound && !igPortletFolderFound){
Folder newImagePortletFolder = DLAppLocalServiceUtil.addFolder(userId, repositoryId, igMainFolderId, IMAGEGALLERY_PORTLETFOLDER, IMAGEGALLERY_PORTLETFOLDER_DESCRIPTION, serviceContext);
igPortletFolderFound = true;
igPortletFolderId = newImagePortletFolder.getFolderId();
}
//Create this record folder
if(igPortletFolderFound){
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
Date date = new Date();
String igRecordFolderName=dateFormat.format(date)+StringPool.UNDERLINE+userId;
Folder newImageRecordFolder = DLAppLocalServiceUtil.addFolder(userId,repositoryId, igPortletFolderId,igRecordFolderName, igRecordFolderName, serviceContext);
igRecordFolderId = newImageRecordFolder.getFolderId();
}
return igRecordFolderId;
}