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:au.com.permeance.liferay.portlet.documentlibrary.service.impl.DLFolderExportZipHelper.java

License:Open Source License

/**
 * Export folder to ZIP writer./*from  w w w .  j  a  v a2s .  co  m*/
 * 
 * @param groupId group id
 * @param repositoryId source repository containing folder to export
 * @param folder source folder to export
 * @param folderPath source folder path to export
 * @param serviceContext service context
 * @param zipWriter destination ZIP writer
 * 
 * @throws PortalException
 * @throws SystemException
 * @throws RemoteException
 */
public static void exportFolderToZipWriter(long groupId, long repositoryId, Folder folder, String folderPath,
        ServiceContext serviceContext, ZipWriter zipWriter) throws PortalException, SystemException {

    // Export file entries in folder to ZIP writer

    List<FileEntry> fileEntryList = DLAppServiceUtil.getFileEntries(folder.getRepositoryId(),
            folder.getFolderId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);

    for (FileEntry fileEntry : fileEntryList) {
        try {
            exportFileEntryToZipWriter(fileEntry, folderPath, zipWriter);
        } catch (Exception e) {
            String msg = "Error exporting file entry to ZIP file : " + e.getMessage();
            s_log.error(msg, e);
            throw new PortalException(msg, e);
        }
    }

    // Export sub-folders in folder to ZIP writer

    List<Folder> subFolderList = DLAppServiceUtil.getFolders(folder.getRepositoryId(), folder.getFolderId(),
            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);

    for (Folder subFolder : subFolderList) {
        String subFolderName = subFolder.getName();
        String subFolderPath = folderPath + subFolderName + StringPool.FORWARD_SLASH;
        exportFolderToZipWriter(groupId, repositoryId, subFolder, subFolderPath, serviceContext, zipWriter);
    }
}

From source file:au.com.permeance.liferay.portlet.documentlibrary.service.impl.DLFolderUsageHelper.java

License:Open Source License

/**
 * Visit Folder.// w  w w  .  j ava2 s .  c  o  m
 * 
 * @param repositoryId repository containing folder
 * @param folderId folder ID
 * @param serviceContext service context
 * @param folderUsageCollector folder usage collector
 * 
 * @throws PortalException
 * @throws SystemException
 */
public static void calculateFolderUsage(long repositoryId, long folderId, ServiceContext serviceContext,
        DLFolderUsageCollector folderUsageCollector) throws PortalException, SystemException {

    try {

        Folder folder = DLAppServiceUtil.getFolder(folderId);

        if (s_log.isDebugEnabled()) {
            s_log.debug("calculating usage for folder " + folder.getFolderId() + "/" + folder.getName());
        }

        calculateFolderUsage(repositoryId, folder, StringPool.BLANK, serviceContext, folderUsageCollector);

    } catch (Exception e) {

        String msg = "Error calculating usage for folder " + folderId + " in repository " + repositoryId + " : "
                + e.getMessage();

        s_log.error(msg, e);

        if (e instanceof PortalException) {
            throw (PortalException) e;

        } else if (e instanceof SystemException) {
            throw (SystemException) e;
        }
    }
}

From source file:au.com.permeance.liferay.portlet.documentlibrary.service.impl.DLFolderUsageHelper.java

License:Open Source License

/**
 * Visit Folder./*from  w  ww  .j  av  a2 s. c  om*/
 * 
 * @param repositoryId repository containing folder
 * @param folder folder
 * @param folderPath folder path
 * @param serviceContext service context
 * @param folderUsageCollector folder usage collector
 * 
 * @throws PortalException 
 * @throws SystemException
 */
public static void calculateFolderUsage(long repositoryId, Folder folder, String folderPath,
        ServiceContext serviceContext, DLFolderUsageCollector folderUsageCollector)
        throws PortalException, SystemException {

    // Visit file entries in folder

    if (s_log.isDebugEnabled()) {
        s_log.debug("calculating usage for folder " + folder.getFolderId() + "/" + folder.getName());
    }

    List<FileEntry> fileEntryList = DLAppServiceUtil.getFileEntries(folder.getRepositoryId(),
            folder.getFolderId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);

    for (FileEntry fileEntry : fileEntryList) {
        try {
            calculateFileEntryUsage(fileEntry, folderPath, folderUsageCollector);
            folderUsageCollector.incrementFileCount();
        } catch (Exception e) {
            String msg = "Error visiting file entry " + fileEntry.getFileEntryId() + " : " + e.getMessage();
            s_log.error(msg, e);
            throw new PortalException(msg, e);
        }
    }

    // Visit sub-folders

    List<Folder> subFolderList = DLAppServiceUtil.getFolders(folder.getRepositoryId(), folder.getFolderId(),
            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);

    for (Folder subFolder : subFolderList) {
        String subFolderName = subFolder.getName();
        String subFolderPath = folderPath + subFolderName + StringPool.FORWARD_SLASH;
        calculateFolderUsage(repositoryId, subFolder, subFolderPath, serviceContext, folderUsageCollector);
        folderUsageCollector.incrementFolderCount();
    }
}

From source file:com.bemis.portal.report.model.impl.ReportRequestImpl.java

License:Open Source License

@Override
public Folder addAttachmentsFolder() throws PortalException {
    if (_attachmentsFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

        return PortletFileRepositoryUtil.getPortletFolder(_attachmentsFolderId);
    }/*from w w  w. j a v a  2  s  .c om*/

    ServiceContext serviceContext = new ServiceContext();

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

    Repository repository = PortletFileRepositoryUtil.addPortletRepository(getGroupId(),
            ReportPortletKeys.REPORT_GENERATION_REQUEST, serviceContext);

    Folder folder = PortletFileRepositoryUtil.addPortletFolder(getUserId(), repository.getRepositoryId(),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, String.valueOf(getReportRequestId()), serviceContext);

    _attachmentsFolderId = folder.getFolderId();

    return folder;
}

From source file:com.bemis.portal.report.model.impl.ReportRequestImpl.java

License:Open Source License

@Override
public long getAttachmentsFolderId() {
    if (_attachmentsFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

        return _attachmentsFolderId;
    }// w  w  w.  ja v a  2s .com

    ServiceContext serviceContext = new ServiceContext();

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

    Repository repository = PortletFileRepositoryUtil.fetchPortletRepository(getGroupId(),
            ReportPortletKeys.REPORT_GENERATION_REQUEST);

    if (repository == null) {
        return DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
    }

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

        _attachmentsFolderId = folder.getFolderId();
    } catch (Exception e) {
        if (_log.isDebugEnabled()) {
            _log.debug("No portlet repository for ReportRequest" + getReportRequestId(), e);
        }
    }

    return _attachmentsFolderId;
}

From source file:com.bemis.portal.report.service.impl.ReportRequestLocalServiceImpl.java

License:Open Source License

@Override
public void addReportResponse(long userId, long reportRequestId, String fileName, String mimeType, File file)
        throws PortalException {

    ReportRequest reportRequest = getReportRequest(reportRequestId);

    Folder folder = reportRequest.addAttachmentsFolder();

    portletFileRepository.addPortletFileEntry(reportRequest.getGroupId(), userId, ReportRequest.class.getName(),
            reportRequest.getPrimaryKey(), ReportPortletKeys.REPORT_GENERATION_REQUEST, folder.getFolderId(),
            file, fileName, mimeType, false);
}

From source file:com.bemis.portal.report.service.impl.ReportRequestLocalServiceImpl.java

License:Open Source License

@Override
public void addReportResponse(long userId, long reportRequestId, String fileName, String mimeType,
        InputStream inputStream) throws PortalException {

    ReportRequest reportRequest = getReportRequest(reportRequestId);

    Folder folder = reportRequest.addAttachmentsFolder();

    portletFileRepository.addPortletFileEntry(reportRequest.getGroupId(), userId, ReportRequest.class.getName(),
            reportRequest.getPrimaryKey(), ReportPortletKeys.REPORT_GENERATION_REQUEST, folder.getFolderId(),
            inputStream, fileName, mimeType, false);
}

From source file:com.custom.portal.verify.CustomVerifyDynamicDataMapping.java

License:Open Source License

protected Folder addFolder(long userId, long groupId, long primaryKey, String fieldName) throws Exception {

    Folder ddmFolder = addFolder(userId, groupId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, "DDM",
            StringPool.BLANK);/*from  w w w  .jav a  2  s . c  o m*/

    Folder primaryKeyFolder = addFolder(userId, groupId, ddmFolder.getFolderId(), String.valueOf(primaryKey),
            StringPool.BLANK);

    return addFolder(userId, groupId, primaryKeyFolder.getFolderId(), fieldName, StringPool.BLANK);
}

From source file:com.custom.portal.verify.CustomVerifyDynamicDataMapping.java

License:Open Source License

protected void updateFileUploadReferences(long companyId, long storageId, long userId, long groupId,
        BaseModel<?> baseModel, int status) throws Exception {

    Map<String, String> fieldValues = new HashMap<String, String>();

    Fields fields = StorageEngineUtil.getFields(storageId);

    for (Field field : fields) {
        String dataType = field.getDataType();

        if (!dataType.equals("file-upload") || Validator.isNull(field.getValue())) {

            continue;
        }/*from   www.  j ava 2  s .  c  o  m*/

        long primaryKey = GetterUtil.getLong(baseModel.getPrimaryKeyObj());

        Folder folder = addFolder(userId, groupId, primaryKey, field.getName());

        String valueString = String.valueOf(field.getValue());

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject(valueString);

        String filePath = getFileUploadPath(baseModel) + StringPool.SLASH + field.getName();

        FileEntry fileEntry = addFileEntry(companyId, userId, groupId, folder.getFolderId(),
                jsonObject.getString("name"), filePath, status);

        if (fileEntry != null) {
            fieldValues.put(field.getName(), getJSON(fileEntry));
        }
    }

    updateFieldValues(storageId, fieldValues);
}

From source file:com.liferay.adaptive.media.demo.internal.AdaptiveMediaImageDemo.java

License:Open Source License

@Override
public void portalInstanceRegistered(Company company) throws Exception {
    User user = _omniAdminUserDemoDataCreator.create(company.getCompanyId(), "alejandro.hernandez@liferay.com");

    Group guestGroup = _groupLocalService.getGroup(company.getCompanyId(), "Guest");

    Folder nonAdaptiveMediaFolder = _rootFolderDemoDataCreator.create(user.getUserId(), guestGroup.getGroupId(),
            "Non Adaptive Media");

    for (int i = 0; i < 5; i++) {
        FileEntry fileEntry = _fileEntryDemoDataCreator.create(user.getUserId(),
                nonAdaptiveMediaFolder.getFolderId());

        if (_log.isInfoEnabled()) {
            _log.info("Non Adaptive Media Image created with file entry id " + fileEntry.getFileEntryId());
        }/*from   ww  w  .  j  a v  a 2 s . c  om*/
    }

    _adaptiveMediaImageConfigurationDemoDataCreator.create(company.getCompanyId());

    Folder adaptiveMediaFolder = _rootFolderDemoDataCreator.create(user.getUserId(), guestGroup.getGroupId(),
            "Adaptive Media");

    for (int i = 0; i < 5; i++) {
        FileEntry fileEntry = _fileEntryDemoDataCreator.create(user.getUserId(),
                adaptiveMediaFolder.getFolderId());

        if (_log.isInfoEnabled()) {
            _log.info("Adaptive Media Image created with file entry id " + fileEntry.getFileEntryId());
        }
    }
}