Search in sources :

Example 1 with Repository

use of com.liferay.portal.kernel.model.Repository in project index-checker by jorgediaz-lr.

the class OutputUtils method servePortletFileEntry.

public static void servePortletFileEntry(String portletId, String title, ResourceRequest request, ResourceResponse response) throws IOException {
    try {
        Repository repository = getPortletRepository(portletId);
        FileEntry fileEntry = getPortletFileEntry(repository, title);
        InputStream inputStream = fileEntry.getContentStream();
        PortletResponseUtil.sendFile(request, response, title, inputStream, -1, fileEntry.getMimeType(), "attachment");
    } catch (NoSuchFileEntryException nsfe) {
        if (_log.isWarnEnabled()) {
            _log.warn(nsfe.getMessage());
        }
        response.setProperty(ResourceResponse.HTTP_STATUS_CODE, String.valueOf(HttpServletResponse.SC_NOT_FOUND));
    } catch (Exception e) {
        _log.error(e, e);
        response.setProperty(ResourceResponse.HTTP_STATUS_CODE, String.valueOf(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
    }
}
Also used : Repository(com.liferay.portal.kernel.model.Repository) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NoSuchFileEntryException(com.liferay.document.library.kernel.exception.NoSuchFileEntryException) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) PortalException(com.liferay.portal.kernel.exception.PortalException) IOException(java.io.IOException) NoSuchFileEntryException(com.liferay.document.library.kernel.exception.NoSuchFileEntryException)

Example 2 with Repository

use of com.liferay.portal.kernel.model.Repository in project index-checker by jorgediaz-lr.

the class OutputUtils method addPortletOutputFileEntry.

public static FileEntry addPortletOutputFileEntry(String portletId, long userId, String outputContent) {
    if (Validator.isNull(outputContent)) {
        return null;
    }
    try {
        InputStream inputStream = new ByteArrayInputStream(outputContent.getBytes(StringPool.UTF8));
        Repository repository = getPortletRepository(portletId);
        cleanupPortletFileEntries(repository, 8 * 60);
        String fileName = portletId + "_output_" + userId + "_" + System.currentTimeMillis() + ".csv";
        return addPortletFileEntry(repository, inputStream, userId, fileName, "text/plain");
    } catch (Exception e) {
        _log.error(e, e);
        return null;
    }
}
Also used : Repository(com.liferay.portal.kernel.model.Repository) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PortalException(com.liferay.portal.kernel.exception.PortalException) IOException(java.io.IOException) NoSuchFileEntryException(com.liferay.document.library.kernel.exception.NoSuchFileEntryException)

Example 3 with Repository

use of com.liferay.portal.kernel.model.Repository in project index-checker by jorgediaz-lr.

the class DLFileEntryPermissionsHelper method _isHiddenFolder.

private boolean _isHiddenFolder(long groupId, long repositoryId) {
    try {
        if (groupId == repositoryId) {
            return false;
        }
        Repository repository = RepositoryLocalServiceUtil.fetchRepository(repositoryId);
        if (repository == null) {
            return false;
        }
        DLFolder dlFolder = DLFolderLocalServiceUtil.fetchDLFolder(repository.getDlFolderId());
        if (dlFolder == null) {
            return false;
        }
        return dlFolder.isHidden();
    } catch (SystemException se) {
        _log.error(se);
        return false;
    }
}
Also used : Repository(com.liferay.portal.kernel.model.Repository) SystemException(com.liferay.portal.kernel.exception.SystemException) DLFolder(com.liferay.document.library.kernel.model.DLFolder)

Example 4 with Repository

use of com.liferay.portal.kernel.model.Repository in project index-checker by jorgediaz-lr.

the class OutputUtils method getPortletRepository.

public static Repository getPortletRepository(String portletId) throws PortalException {
    List<Company> companies = CompanyLocalServiceUtil.getCompanies(false);
    Company company = companies.get(0);
    Group group = GroupServiceUtil.getCompanyGroup(company.getCompanyId());
    Repository repository = PortletFileRepositoryUtil.fetchPortletRepository(group.getGroupId(), portletId);
    if (repository == null) {
        repository = PortletFileRepositoryUtil.addPortletRepository(group.getGroupId(), portletId, new ServiceContext());
    }
    return repository;
}
Also used : Group(com.liferay.portal.kernel.model.Group) Company(com.liferay.portal.kernel.model.Company) Repository(com.liferay.portal.kernel.model.Repository) ServiceContext(com.liferay.portal.kernel.service.ServiceContext)

Aggregations

Repository (com.liferay.portal.kernel.model.Repository)4 NoSuchFileEntryException (com.liferay.document.library.kernel.exception.NoSuchFileEntryException)2 PortalException (com.liferay.portal.kernel.exception.PortalException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 DLFolder (com.liferay.document.library.kernel.model.DLFolder)1 SystemException (com.liferay.portal.kernel.exception.SystemException)1 Company (com.liferay.portal.kernel.model.Company)1 Group (com.liferay.portal.kernel.model.Group)1 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)1 ServiceContext (com.liferay.portal.kernel.service.ServiceContext)1