Example usage for com.liferay.portal.kernel.repository.model Folder getFolderId

List of usage examples for com.liferay.portal.kernel.repository.model Folder getFolderId

Introduction

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

Prototype

public long getFolderId();

Source Link

Usage

From source file:edu.jhu.cvrg.filestore.main.Liferay61FileStorer.java

License:Apache License

@Override
public synchronized FSFolder addFolder(long parentFolderId, String folderName) throws FSException {
    Folder newFolder = null;
    Semaphore s = Semaphore.getCreateFolderSemaphore();
    folderName = Liferay61FileStorer.convertToLiferayFolderName(folderName);

    try {/*from  w w  w.j a v  a 2  s. c  om*/
        s.take();

        FSFolder parentFolder = this.getFolder(parentFolderId);
        if (parentFolder == null) {
            throw new FSException("Folder ID [" + parentFolderId + "] does not exists.");
        }

        List<FSFolder> subFolders = this.getFolders(parentFolderId);
        if (subFolders != null) {
            for (FSFolder subFolder : subFolders) {
                if (folderName.equals(subFolder.getName())) {
                    return subFolder;
                }
            }
        }

        ServiceContext service = LiferayFacesContext.getInstance().getServiceContext();
        try {
            newFolder = DLAppLocalServiceUtil.addFolder(userId, groupId, parentFolderId, folderName, "",
                    service);
        } catch (Exception e) {
            Thread.sleep(2000);
            int tries = 5;

            for (int i = 0; i < tries && newFolder == null; i++) {
                try {
                    newFolder = DLAppLocalServiceUtil.getFolder(groupId, parentFolderId, folderName);
                } catch (Exception e2) {
                    Thread.sleep(2000);
                    log.warn("Sleep and Try Again. #" + (i));
                }
            }
        }

        if (newFolder != null) {
            StringBuilder treePath = new StringBuilder();
            extractFolderHierachic(newFolder, treePath);

            Role userRole = RoleLocalServiceUtil.getRole(companyId, FileStoreConstants.AXIS_USER_ROLE_NAME);
            ResourcePermission resourcePermission = null;

            resourcePermission = ResourcePermissionLocalServiceUtil
                    .createResourcePermission(CounterLocalServiceUtil.increment());
            resourcePermission.setCompanyId(companyId);
            resourcePermission.setName(DLFolder.class.getName());
            resourcePermission.setScope(ResourceConstants.SCOPE_INDIVIDUAL);
            resourcePermission.setPrimKey(String.valueOf(newFolder.getPrimaryKey()));
            resourcePermission.setRoleId(userRole.getRoleId());

            ResourceAction resourceActionDelete = ResourceActionLocalServiceUtil
                    .getResourceAction(DLFolder.class.getName(), ActionKeys.DELETE);
            ResourceAction resourceActionView = ResourceActionLocalServiceUtil
                    .getResourceAction(DLFolder.class.getName(), ActionKeys.VIEW);
            ResourceAction resourceActionAccess = ResourceActionLocalServiceUtil
                    .getResourceAction(DLFolder.class.getName(), ActionKeys.ACCESS);
            ResourceAction resourceActionAddDoc = ResourceActionLocalServiceUtil
                    .getResourceAction(DLFolder.class.getName(), ActionKeys.ADD_DOCUMENT);
            resourcePermission
                    .setActionIds(resourceActionDelete.getBitwiseValue() + resourceActionView.getBitwiseValue()
                            + resourceActionAccess.getBitwiseValue() + resourceActionAddDoc.getBitwiseValue());
            ResourcePermissionLocalServiceUtil.addResourcePermission(resourcePermission);

            return new FSFolder(newFolder.getFolderId(), newFolder.getName(), newFolder.getParentFolderId());
        } else {
            throw new FSException("Please select a folder");
        }

    } catch (Exception e) {
        log.error(e.getMessage());
        throw new FSException("Error on record name folder's creation.", e);
    } finally {
        try {
            s.release();
        } catch (InterruptedException e) {
            log.error(e.getMessage());
        }
    }
}

From source file:gr.open.loglevelsmanager.loglevel.LogLevelUpload.java

License:Open Source License

/**
 * Create folders for upload documents from our portlet to DocumentLibrary portlet
 * /*w w  w.  ja v a  2  s .c  o m*/
 * @param request
 * @param userId
 * @param groupId
 * @param portletName
 * @return
 * @throws PortalException
 * @throws SystemException
 */
private long createFolders(ActionRequest request, Long userId, Long groupId, String portletName)
        throws PortalException, SystemException {

    // Search for folder in Document Library
    if (dlFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

        return dlFolderId;
    }

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);

    Repository repository = PortletFileRepositoryUtil.addPortletRepository(groupId, portletName,
            serviceContext);

    Folder folder = PortletFileRepositoryUtil.addPortletFolder(userId, repository.getRepositoryId(),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, DOCUMENTLIBRARY_PORTLETFOLDER, serviceContext);

    dlFolderId = folder.getFolderId();

    return dlFolderId;
}

From source file:org.liferay.jukebox.model.impl.SongImpl.java

License:Open Source License

protected FileEntry getFileEntry(ThemeDisplay themeDisplay, String folderName) throws SystemException {

    Repository repository = PortletFileRepositoryUtil.fetchPortletRepository(getGroupId(),
            Constants.JUKEBOX_PORTLET_REPOSITORY);

    if (repository == null) {
        return null;
    }//from   ww w  .ja v a2 s  .com

    try {
        Folder folder = PortletFileRepositoryUtil.getPortletFolder(0, repository.getRepositoryId(),
                DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, String.valueOf(getSongId()), null);

        Folder songFolder = PortletFileRepositoryUtil.getPortletFolder(0, repository.getRepositoryId(),
                folder.getFolderId(), folderName, null);

        List<FileEntry> fileEntries = PortletFileRepositoryUtil
                .getPortletFileEntries(themeDisplay.getScopeGroupId(), songFolder.getFolderId());

        if (fileEntries.isEmpty()) {
            return null;
        }

        return fileEntries.get(0);
    } catch (Exception e) {
        return null;
    }
}

From source file:org.liferay.jukebox.service.impl.SongLocalServiceImpl.java

License:Open Source License

@Indexable(type = IndexableType.REINDEX)
public Song addSong(long userId, long albumId, String name, String songFileName, InputStream songInputStream,
        String lyricsFileName, InputStream lyricsInputStream, ServiceContext serviceContext)
        throws PortalException, SystemException {

    long groupId = serviceContext.getScopeGroupId();

    User user = userPersistence.findByPrimaryKey(userId);

    Date now = new Date();

    long songId = counterLocalService.increment();
    Album album = albumPersistence.findByPrimaryKey(albumId);

    validate(songId, groupId, album.getArtistId(), albumId, name);

    Song song = songPersistence.create(songId);

    song.setUuid(serviceContext.getUuid());
    song.setGroupId(groupId);/*from  w  ww. jav  a  2 s .co m*/
    song.setCompanyId(user.getCompanyId());
    song.setUserId(user.getUserId());
    song.setUserName(user.getFullName());
    song.setCreateDate(serviceContext.getCreateDate(now));
    song.setModifiedDate(serviceContext.getModifiedDate(now));

    song.setArtistId(album.getArtistId());
    song.setAlbumId(albumId);
    song.setName(name);
    song.setExpandoBridgeAttributes(serviceContext);

    songPersistence.update(song);

    if ((songInputStream != null) || (lyricsInputStream != null)) {
        Repository repository = PortletFileRepositoryUtil.addPortletRepository(groupId,
                Constants.JUKEBOX_PORTLET_REPOSITORY, serviceContext);

        Folder folder = PortletFileRepositoryUtil.addPortletFolder(userId, repository.getRepositoryId(),
                DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, String.valueOf(song.getSongId()), serviceContext);

        if (songInputStream != null) {
            Folder songFolder = PortletFileRepositoryUtil.addPortletFolder(userId, repository.getRepositoryId(),
                    folder.getFolderId(), Constants.SONGS_FOLDER_NAME, serviceContext);

            FileEntry fileEntry = PortletFileRepositoryUtil.addPortletFileEntry(groupId, userId,
                    Song.class.getName(), song.getSongId(), Constants.JUKEBOX_PORTLET_REPOSITORY,
                    songFolder.getFolderId(), songInputStream, songFileName, StringPool.BLANK, true);

            DLProcessorRegistryUtil.trigger(fileEntry, null, true);
        }

        if (lyricsInputStream != null) {
            Folder lyricsFolder = PortletFileRepositoryUtil.addPortletFolder(userId,
                    repository.getRepositoryId(), folder.getFolderId(), Constants.LYRICS_FOLDER_NAME,
                    serviceContext);

            FileEntry fileEntry = PortletFileRepositoryUtil.addPortletFileEntry(groupId, userId,
                    Song.class.getName(), song.getSongId(), Constants.JUKEBOX_PORTLET_REPOSITORY,
                    lyricsFolder.getFolderId(), lyricsInputStream, lyricsFileName, StringPool.BLANK, true);

            DLProcessorRegistryUtil.trigger(fileEntry, null, true);
        }
    }

    // Resources

    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {

        addEntryResources(song, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions());
    } else {
        addEntryResources(song, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
    }

    // Message boards

    mbMessageLocalService.addDiscussionMessage(userId, album.getUserName(), groupId, Song.class.getName(),
            songId, WorkflowConstants.ACTION_PUBLISH);

    // Asset

    updateAsset(userId, song, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(),
            serviceContext.getAssetLinkEntryIds());

    return song;
}

From source file:org.liferay.jukebox.service.impl.SongLocalServiceImpl.java

License:Open Source License

@Indexable(type = IndexableType.DELETE)
public Song deleteSong(long songId) throws PortalException, SystemException {

    Song song = songPersistence.findByPrimaryKey(songId);

    Repository repository = PortletFileRepositoryUtil.fetchPortletRepository(song.getGroupId(),
            Constants.JUKEBOX_PORTLET_REPOSITORY);

    if (repository != null) {
        try {//from  w w  w.j  a v  a  2 s  . c  om
            Folder folder = PortletFileRepositoryUtil.getPortletFolder(0, repository.getRepositoryId(),
                    DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, String.valueOf(songId), null);

            PortletFileRepositoryUtil.deleteFolder(folder.getFolderId());
        } catch (Exception e) {
        }
    }

    return songPersistence.remove(songId);
}

From source file:org.liferay.jukebox.service.impl.SongLocalServiceImpl.java

License:Open Source License

@Indexable(type = IndexableType.REINDEX)
public Song updateSong(long userId, long songId, long albumId, String name, String songFileName,
        InputStream songInputStream, String lyricsFileName, InputStream lyricsInputStream,
        ServiceContext serviceContext) throws PortalException, SystemException {

    // Event/*from   w w  w .j av a 2 s .  c  om*/

    User user = userPersistence.findByPrimaryKey(userId);

    Song song = songPersistence.findByPrimaryKey(songId);
    Album album = albumPersistence.findByPrimaryKey(albumId);

    validate(songId, song.getGroupId(), album.getArtistId(), albumId, name);

    song.setModifiedDate(serviceContext.getModifiedDate(null));

    song.setArtistId(album.getArtistId());
    song.setAlbumId(albumId);

    song.setName(name);
    song.setExpandoBridgeAttributes(serviceContext);

    songPersistence.update(song);

    if ((songInputStream != null) || (lyricsInputStream != null)) {
        Repository repository = PortletFileRepositoryUtil.addPortletRepository(serviceContext.getScopeGroupId(),
                Constants.JUKEBOX_PORTLET_REPOSITORY, serviceContext);

        Folder folder = PortletFileRepositoryUtil.addPortletFolder(userId, repository.getRepositoryId(),
                DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, String.valueOf(song.getSongId()), serviceContext);

        if (songInputStream != null) {
            Folder songFolder = PortletFileRepositoryUtil.addPortletFolder(userId, repository.getRepositoryId(),
                    folder.getFolderId(), Constants.SONGS_FOLDER_NAME, serviceContext);

            List<FileEntry> fileEntries = PortletFileRepositoryUtil
                    .getPortletFileEntries(serviceContext.getScopeGroupId(), songFolder.getFolderId());

            for (FileEntry fileEntry : fileEntries) {
                PortletFileRepositoryUtil.deletePortletFileEntry(fileEntry.getFileEntryId());

                DLProcessorRegistryUtil.cleanUp(fileEntry);
            }

            FileEntry fileEntry = PortletFileRepositoryUtil.addPortletFileEntry(
                    serviceContext.getScopeGroupId(), userId, Song.class.getName(), song.getSongId(),
                    Constants.JUKEBOX_PORTLET_REPOSITORY, songFolder.getFolderId(), songInputStream,
                    songFileName, StringPool.BLANK, true);

            triggerDLProcessors(fileEntry);
        }

        if (lyricsInputStream != null) {
            Folder lyricsFolder = PortletFileRepositoryUtil.addPortletFolder(userId,
                    repository.getRepositoryId(), folder.getFolderId(), Constants.LYRICS_FOLDER_NAME,
                    serviceContext);

            List<FileEntry> fileEntries = PortletFileRepositoryUtil
                    .getPortletFileEntries(serviceContext.getScopeGroupId(), lyricsFolder.getFolderId());

            for (FileEntry fileEntry : fileEntries) {
                PortletFileRepositoryUtil.deletePortletFileEntry(fileEntry.getFileEntryId());

                DLProcessorRegistryUtil.cleanUp(fileEntry);
            }

            FileEntry fileEntry = PortletFileRepositoryUtil.addPortletFileEntry(
                    serviceContext.getScopeGroupId(), userId, Song.class.getName(), song.getSongId(),
                    Constants.JUKEBOX_PORTLET_REPOSITORY, lyricsFolder.getFolderId(), lyricsInputStream,
                    lyricsFileName, StringPool.BLANK, true);

            triggerDLProcessors(fileEntry);
        }
    }

    // Asset

    updateAsset(userId, song, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(),
            serviceContext.getAssetLinkEntryIds());

    return song;
}

From source file:org.opencps.paymentmgt.portlet.PaymentMgtFrontOfficePortlet.java

License:Open Source License

/**
 * Upload file//w w  w  .ja v  a 2  s .com
 * 
 * @param actionRequest
 * @param actionResponse
 * @return
 * @throws Exception
 */
protected FileEntry updateFileEntry(ActionRequest actionRequest, ActionResponse actionResponse)
        throws Exception {

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

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

    String cmd = ParamUtil.getString(uploadPortletRequest, Constants.CMD);

    long repositoryId = themeDisplay.getScopeGroupId();

    long folderId = 0;

    Folder folderFile = initFolderService(actionRequest, themeDisplay);

    if (Validator.isNotNull(folderFile)) {
        folderId = folderFile.getFolderId();
    }

    Date now = new Date();
    String sourceFileName = now.getTime() + "_" + uploadPortletRequest.getFileName("uploadedFile");
    String title = ParamUtil.getString(uploadPortletRequest, "fileName");

    String description = ParamUtil.getString(uploadPortletRequest, "description");
    String changeLog = ParamUtil.getString(uploadPortletRequest, "changeLog");
    System.out.println("----FILE NAME----" + sourceFileName);
    if (folderId > 0) {
        Folder folder = DLAppServiceUtil.getFolder(folderId);

        if (folder.getGroupId() != themeDisplay.getScopeGroupId()) {
            throw new NoSuchFolderException("{folderId=" + folderId + "}");
        }
    }

    InputStream inputStream = null;

    try {
        String contentType = uploadPortletRequest.getContentType("uploadedFile");

        long size = uploadPortletRequest.getSize("uploadedFile");

        if ((cmd.equals(Constants.ADD) || cmd.equals(Constants.ADD_DYNAMIC)) && (size == 0)) {

            contentType = MimeTypesUtil.getContentType(title);
        }

        inputStream = uploadPortletRequest.getFileAsStream("uploadedFile");

        ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFileEntry.class.getName(),
                uploadPortletRequest);
        serviceContext.setAddGroupPermissions(true);
        serviceContext.setAddGuestPermissions(true);

        FileEntry fileEntry = null;

        // Add file entry

        fileEntry = DLAppServiceUtil.addFileEntry(repositoryId, folderId, sourceFileName, contentType,
                sourceFileName, description, changeLog, inputStream, size, serviceContext);
        System.out.println("----FILE ENTRY ID----" + fileEntry.getFileEntryId());
        AssetPublisherUtil.addAndStoreSelection(actionRequest, DLFileEntry.class.getName(),
                fileEntry.getFileEntryId(), -1);

        AssetPublisherUtil.addRecentFolderId(actionRequest, DLFileEntry.class.getName(), folderId);

        return fileEntry;
    } catch (Exception e) {
        e.printStackTrace();
        UploadException uploadException = (UploadException) actionRequest
                .getAttribute(WebKeys.UPLOAD_EXCEPTION);

        if (uploadException != null) {
            if (uploadException.isExceededLiferayFileItemSizeLimit()) {
                throw new LiferayFileItemException();
            } else if (uploadException.isExceededSizeLimit()) {
                throw new FileSizeException(uploadException.getCause());
            }
        }

        throw e;
    } finally {
        StreamUtil.cleanUp(inputStream);
    }
}

From source file:org.opencps.paymentmgt.portlet.PaymentMgtFrontOfficePortlet.java

License:Open Source License

/**
 * Create tree folder. Return folder contains confirm payments files
 * /*from ww  w  .j  av a2 s  . c  o  m*/
 * @param actionRequest
 * @param themeDisplay
 * @return
 */
public Folder initFolderService(ActionRequest actionRequest, ThemeDisplay themeDisplay) {

    // Folder contains template service files

    String dateFolderName = DateTimeUtil.getStringDate();

    Folder folder = null;

    try {
        // Check ROOT folder exist

        long rootFolderId = 0;

        long parentFolderId = 0;

        boolean isRootFolderExist = isFolderExist(themeDisplay.getScopeGroupId(), 0, ROOT_FOLDER_NAME);

        ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

        if (isRootFolderExist) {
            Folder rootFolder = null;

            rootFolder = DLAppServiceUtil.getFolder(themeDisplay.getScopeGroupId(), 0, ROOT_FOLDER_NAME);

            rootFolderId = rootFolder.getFolderId();

        } else {
            Folder rootFolder = DLAppServiceUtil.addFolder(themeDisplay.getScopeGroupId(), 0, ROOT_FOLDER_NAME,
                    "All documents of OpenCPS", serviceContext);

            rootFolderId = rootFolder.getFolderId();
        }

        // Check parent folder exist

        boolean isParentFolderExist = isFolderExist(themeDisplay.getScopeGroupId(), rootFolderId,
                PARENT_FOLDER_NAME);

        if (isParentFolderExist) {

            Folder parentFolder = DLAppServiceUtil.getFolder(themeDisplay.getScopeGroupId(), rootFolderId,
                    PARENT_FOLDER_NAME);

            parentFolderId = parentFolder.getFolderId();

        } else {
            Folder parentFolder = DLAppServiceUtil.addFolder(themeDisplay.getScopeGroupId(), rootFolderId,
                    PARENT_FOLDER_NAME, "All payment documents", serviceContext);

            parentFolderId = parentFolder.getFolderId();
        }

        // Check DateFolder exist
        boolean isDateFolderExist = isFolderExist(themeDisplay.getScopeGroupId(), parentFolderId,
                dateFolderName);

        Folder dateFolder = null;

        if (isDateFolderExist) {

            dateFolder = DLAppServiceUtil.getFolder(themeDisplay.getScopeGroupId(), parentFolderId,
                    dateFolderName);

        } else {
            dateFolder = DLAppServiceUtil.addFolder(themeDisplay.getScopeGroupId(), parentFolderId,
                    dateFolderName, "All confirm payment documents upload in a day", serviceContext);
        }

        folder = dateFolder;

    } catch (Exception e) {
        _log.error(e);
    }

    return folder;
}

From source file:org.opencps.servicemgt.service.impl.TemplateFileLocalServiceImpl.java

License:Open Source License

protected FileEntry updateFileEntry(ActionRequest actionRequest, ActionResponse actionResponse)
        throws Exception {

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

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

    String cmd = ParamUtil.getString(uploadPortletRequest, Constants.CMD);

    long repositoryId = themeDisplay.getScopeGroupId();

    long folderId = 0;

    Folder folderFile = initFolderService(actionRequest, themeDisplay);

    if (Validator.isNotNull(folderFile)) {
        folderId = folderFile.getFolderId();
    }// w w w .  j  av a2  s . co  m

    String sourceFileName = uploadPortletRequest.getFileName("uploadedFile");
    String title = ParamUtil.getString(uploadPortletRequest, "fileName");

    String description = ParamUtil.getString(uploadPortletRequest, "description");
    String changeLog = ParamUtil.getString(uploadPortletRequest, "changeLog");

    if (folderId > 0) {
        Folder folder = DLAppServiceUtil.getFolder(folderId);

        if (folder.getGroupId() != themeDisplay.getScopeGroupId()) {
            throw new NoSuchFolderException("{folderId=" + folderId + "}");
        }
    }

    InputStream inputStream = null;

    try {
        String contentType = uploadPortletRequest.getContentType("uploadedFile");

        long size = uploadPortletRequest.getSize("uploadedFile");

        if ((cmd.equals(Constants.ADD) || cmd.equals(Constants.ADD_DYNAMIC)) && (size == 0)) {

            contentType = MimeTypesUtil.getContentType(title);
        }

        inputStream = uploadPortletRequest.getFileAsStream("uploadedFile");

        ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFileEntry.class.getName(),
                uploadPortletRequest);

        serviceContext.setAddGroupPermissions(true);
        serviceContext.setAddGuestPermissions(true);

        FileEntry fileEntry = null;

        // Add file entry

        fileEntry = DLAppServiceUtil.addFileEntry(repositoryId, folderId, sourceFileName, contentType,
                sourceFileName, description, changeLog, inputStream, size, serviceContext);

        AssetPublisherUtil.addAndStoreSelection(actionRequest, DLFileEntry.class.getName(),
                fileEntry.getFileEntryId(), -1);

        AssetPublisherUtil.addRecentFolderId(actionRequest, DLFileEntry.class.getName(), folderId);

        return fileEntry;
    } catch (Exception e) {
        UploadException uploadException = (UploadException) actionRequest
                .getAttribute(WebKeys.UPLOAD_EXCEPTION);

        if (uploadException != null) {
            if (uploadException.isExceededLiferayFileItemSizeLimit()) {
                throw new LiferayFileItemException();
            } else if (uploadException.isExceededSizeLimit()) {
                throw new FileSizeException(uploadException.getCause());
            }
        }

        throw e;
    } finally {
        StreamUtil.cleanUp(inputStream);
    }
}

From source file:org.opencps.servicemgt.service.impl.TemplateFileLocalServiceImpl.java

License:Open Source License

/**
 * Create tree folder. Return folder contains template files
 * /*  w  w w  .j a  v a  2  s . c o m*/
 * @param actionRequest
 * @param themeDisplay
 * @return
 */
public Folder initFolderService(ActionRequest actionRequest, ThemeDisplay themeDisplay) {

    // Folder contains template service files

    String dateFolderName = DateTimeUtil.getStringDate();

    Folder folder = null;

    try {
        // Check ROOT folder exist

        long rootFolderId = 0;

        long parentFolderId = 0;

        boolean isRootFolderExist = isFolderExist(themeDisplay.getScopeGroupId(), 0, ROOT_FOLDER_NAME);

        ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

        serviceContext.setAddGroupPermissions(true);
        serviceContext.setAddGuestPermissions(true);

        if (isRootFolderExist) {
            Folder rootFolder = null;

            rootFolder = DLAppServiceUtil.getFolder(themeDisplay.getScopeGroupId(), 0, ROOT_FOLDER_NAME);

            rootFolderId = rootFolder.getFolderId();

        } else {
            Folder rootFolder = DLAppServiceUtil.addFolder(themeDisplay.getScopeGroupId(), 0, ROOT_FOLDER_NAME,
                    "All documents of OpenCPS", serviceContext);

            rootFolderId = rootFolder.getFolderId();
        }

        // Check parent folder exist

        boolean isParentFolderExist = isFolderExist(themeDisplay.getScopeGroupId(), rootFolderId,
                PARENT_FOLDER_NAME);

        if (isParentFolderExist) {
            Folder parentFolder = DLAppServiceUtil.getFolder(themeDisplay.getScopeGroupId(), rootFolderId,
                    PARENT_FOLDER_NAME);

            parentFolderId = parentFolder.getFolderId();

        } else {
            Folder parentFolder = DLAppServiceUtil.addFolder(themeDisplay.getScopeGroupId(), rootFolderId,
                    PARENT_FOLDER_NAME, "All documents of Service Template File", serviceContext);

            parentFolderId = parentFolder.getFolderId();
        }

        // Check DateFolder exist
        boolean isDateFolderExist = isFolderExist(themeDisplay.getScopeGroupId(), parentFolderId,
                dateFolderName);

        Folder dateFolder = null;

        if (isDateFolderExist) {

            dateFolder = DLAppServiceUtil.getFolder(themeDisplay.getScopeGroupId(), parentFolderId,
                    dateFolderName);

        } else {
            dateFolder = DLAppServiceUtil.addFolder(themeDisplay.getScopeGroupId(), parentFolderId,
                    dateFolderName, "All documents of Service Template File upload in a day", serviceContext);
        }

        folder = dateFolder;

    } catch (Exception e) {

    }

    return folder;
}