Search in sources :

Example 1 with Folder

use of com.liferay.portal.kernel.repository.model.Folder in project liferay-ide by liferay.

the class WebServerServlet method sendDocumentLibrary.

protected void sendDocumentLibrary(HttpServletRequest request, HttpServletResponse response, User user, String path, String[] pathArray) throws Exception {
    if (!PropsValues.WEB_SERVER_SERVLET_DIRECTORY_INDEXING_ENABLED) {
        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return;
    }
    long groupId = _getGroupId(user.getCompanyId(), pathArray[0]);
    long folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
    for (int i = 1; i < pathArray.length; i++) {
        String name = pathArray[i];
        try {
            Folder folder = DLAppServiceUtil.getFolder(groupId, folderId, name);
            folderId = folder.getFolderId();
        } catch (NoSuchFolderException nsfe) {
            if (i != pathArray.length - 1) {
                throw nsfe;
            }
            String title = name;
            sendFile(response, user, groupId, folderId, title);
            return;
        }
    }
    try {
        sendFile(response, user, groupId, folderId, "index.html");
        return;
    } catch (Exception e) {
        if ((e instanceof NoSuchFileEntryException) || (e instanceof PrincipalException)) {
            try {
                sendFile(response, user, groupId, folderId, "index.htm");
                return;
            } catch (NoSuchFileEntryException nsfee) {
            } catch (PrincipalException pe) {
            }
        } else {
            throw e;
        }
    }
    List<WebServerEntry> webServerEntries = new ArrayList<WebServerEntry>();
    webServerEntries.add(new WebServerEntry(path, "../"));
    List<Folder> folders = DLAppServiceUtil.getFolders(groupId, folderId);
    for (Folder folder : folders) {
        WebServerEntry webServerEntry = new WebServerEntry(path, folder.getName() + StringPool.SLASH, folder.getCreateDate(), folder.getModifiedDate(), folder.getDescription(), 0);
        webServerEntries.add(webServerEntry);
    }
    List<FileEntry> fileEntries = DLAppServiceUtil.getFileEntries(groupId, folderId);
    for (FileEntry fileEntry : fileEntries) {
        WebServerEntry webServerEntry = new WebServerEntry(path, fileEntry.getTitle(), fileEntry.getCreateDate(), fileEntry.getModifiedDate(), fileEntry.getDescription(), fileEntry.getSize());
        webServerEntries.add(webServerEntry);
    }
    sendHTML(response, path, webServerEntries);
}
Also used : ArrayList(java.util.ArrayList) Folder(com.liferay.portal.kernel.repository.model.Folder) ServletException(javax.servlet.ServletException) RepositoryException(com.liferay.portal.kernel.repository.RepositoryException) NoSuchFileEntryException(com.liferay.portlet.documentlibrary.NoSuchFileEntryException) NoSuchFolderException(com.liferay.portlet.documentlibrary.NoSuchFolderException) PrincipalException(com.liferay.portal.security.auth.PrincipalException) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) IOException(java.io.IOException) NoSuchGroupException(com.liferay.portal.NoSuchGroupException) NoSuchFolderException(com.liferay.portlet.documentlibrary.NoSuchFolderException) PrincipalException(com.liferay.portal.security.auth.PrincipalException) NoSuchFileEntryException(com.liferay.portlet.documentlibrary.NoSuchFileEntryException) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry)

Example 2 with Folder

use of com.liferay.portal.kernel.repository.model.Folder in project liferay-ide by liferay.

the class WebServerServlet method hasFiles.

/**
 * @see com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter
 */
public static boolean hasFiles(HttpServletRequest request) {
    try {
        // Do not use permission checking since this may be called from
        // other contexts that are also managing the principal
        User user = _getUser(request);
        String path = HttpUtil.fixPath(request.getPathInfo());
        String[] pathArray = StringUtil.split(path, CharPool.SLASH);
        if (pathArray.length == 0) {
            return true;
        } else if (_PATH_DDL.equals(pathArray[0])) {
            _checkDDLRecord(pathArray);
        } else if (Validator.isNumber(pathArray[0])) {
            _checkFileEntry(pathArray);
        } else {
            long groupId = _getGroupId(user.getCompanyId(), pathArray[0]);
            long folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
            for (int i = 1; i < pathArray.length; i++) {
                try {
                    Folder folder = DLAppLocalServiceUtil.getFolder(groupId, folderId, pathArray[i]);
                    folderId = folder.getFolderId();
                } catch (NoSuchFolderException nsfe) {
                    if (i != pathArray.length - 1) {
                        return false;
                    }
                    pathArray = new String[] { String.valueOf(groupId), String.valueOf(folderId), pathArray[i] };
                    _checkFileEntry(pathArray);
                }
            }
        }
    } catch (Exception e) {
        return false;
    }
    return true;
}
Also used : NoSuchFolderException(com.liferay.portlet.documentlibrary.NoSuchFolderException) User(com.liferay.portal.model.User) Folder(com.liferay.portal.kernel.repository.model.Folder) ServletException(javax.servlet.ServletException) RepositoryException(com.liferay.portal.kernel.repository.RepositoryException) NoSuchFileEntryException(com.liferay.portlet.documentlibrary.NoSuchFileEntryException) NoSuchFolderException(com.liferay.portlet.documentlibrary.NoSuchFolderException) PrincipalException(com.liferay.portal.security.auth.PrincipalException) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) IOException(java.io.IOException) NoSuchGroupException(com.liferay.portal.NoSuchGroupException)

Example 3 with Folder

use of com.liferay.portal.kernel.repository.model.Folder in project liferay-ide by liferay.

the class LiferayAlbumService method doGetAlbums.

protected RestfulCollection<Album> doGetAlbums(UserId userId, String appId, Set<String> fields, CollectionOptions collectionOptions, Set<String> albumIds, SecurityToken securityToken) throws Exception {
    List<Album> albums = new ArrayList<Album>();
    for (String albumId : albumIds) {
        Folder folder = DLAppServiceUtil.getFolder(GetterUtil.getLong(albumId));
        Album album = toAlbum(folder, fields, securityToken);
        albums.add(album);
    }
    return new RestfulCollection<Album>(albums, collectionOptions.getFirst(), albums.size(), collectionOptions.getMax());
}
Also used : ArrayList(java.util.ArrayList) Album(org.apache.shindig.social.opensocial.model.Album) RestfulCollection(org.apache.shindig.protocol.RestfulCollection) Folder(com.liferay.portal.kernel.repository.model.Folder) DLFolder(com.liferay.portlet.documentlibrary.model.DLFolder)

Example 4 with Folder

use of com.liferay.portal.kernel.repository.model.Folder in project liferay-ide by liferay.

the class LiferayAlbumService method doGetAlbums.

protected RestfulCollection<Album> doGetAlbums(Set<UserId> userIds, GroupId groupId, String appId, Set<String> fields, CollectionOptions collectionOptions, SecurityToken securityToken) throws Exception {
    List<Album> albums = new ArrayList<Album>();
    for (UserId userId : userIds) {
        String userIdString = userId.getUserId(securityToken);
        long userIdLong = GetterUtil.getLong(userIdString);
        User user = UserLocalServiceUtil.getUserById(userIdLong);
        if (!ShindigUtil.isValidUser(user)) {
            continue;
        }
        List<Folder> folders = new ArrayList<Folder>();
        GroupId.Type groupIdType = groupId.getType();
        if (groupIdType.equals(GroupId.Type.all) || groupIdType.equals(GroupId.Type.friends) || groupIdType.equals(GroupId.Type.groupId)) {
            List<User> socialUsers = UserLocalServiceUtil.getSocialUsers(user.getUserId(), SocialRelationConstants.TYPE_BI_FRIEND, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
            for (User socialUser : socialUsers) {
                Group group = socialUser.getGroup();
                List<Folder> friendFolders = DLAppServiceUtil.getFolders(group.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);
                folders.addAll(friendFolders);
            }
        } else if (groupIdType.equals(GroupId.Type.self)) {
            Group group = user.getGroup();
            folders = DLAppServiceUtil.getFolders(group.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);
        }
        for (Folder folder : folders) {
            Album album = toAlbum(folder, fields, securityToken);
            albums.add(album);
        }
    }
    return new RestfulCollection<Album>(albums, collectionOptions.getFirst(), albums.size(), collectionOptions.getMax());
}
Also used : Group(com.liferay.portal.model.Group) User(com.liferay.portal.model.User) ArrayList(java.util.ArrayList) Album(org.apache.shindig.social.opensocial.model.Album) RestfulCollection(org.apache.shindig.protocol.RestfulCollection) Folder(com.liferay.portal.kernel.repository.model.Folder) DLFolder(com.liferay.portlet.documentlibrary.model.DLFolder) GroupId(org.apache.shindig.social.opensocial.spi.GroupId) UserId(org.apache.shindig.social.opensocial.spi.UserId)

Example 5 with Folder

use of com.liferay.portal.kernel.repository.model.Folder in project liferay-ide by liferay.

the class LiferayAlbumService method doUpdateAlbum.

protected void doUpdateAlbum(UserId userId, String appId, Album album, String albumId, SecurityToken securityToken) throws Exception {
    long userIdLong = GetterUtil.getLong(userId.getUserId(securityToken));
    User user = UserLocalServiceUtil.getUserById(userIdLong);
    if (!ShindigUtil.isValidUser(user)) {
        return;
    }
    Group group = user.getGroup();
    long groupIdLong = group.getGroupId();
    ServiceContext serviceContext = new ServiceContext();
    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);
    serviceContext.setExpandoBridgeAttributes(SerializerUtil.toExpandoAttributes(album, _ALBUM_FIELDS, user.getCompanyId(), DLFolder.class.getName()));
    serviceContext.setScopeGroupId(groupIdLong);
    if (albumId == null) {
        DLAppServiceUtil.addFolder(groupIdLong, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, album.getTitle(), album.getDescription(), serviceContext);
    } else {
        Folder folder = DLAppLocalServiceUtil.getFolder(GetterUtil.getLong(albumId));
        DLAppServiceUtil.updateFolder(folder.getFolderId(), album.getTitle(), album.getDescription(), serviceContext);
    }
}
Also used : Group(com.liferay.portal.model.Group) User(com.liferay.portal.model.User) ServiceContext(com.liferay.portal.service.ServiceContext) Folder(com.liferay.portal.kernel.repository.model.Folder) DLFolder(com.liferay.portlet.documentlibrary.model.DLFolder)

Aggregations

Folder (com.liferay.portal.kernel.repository.model.Folder)19 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)7 ServiceContext (com.liferay.portal.service.ServiceContext)6 PortalException (com.liferay.portal.kernel.exception.PortalException)5 SystemException (com.liferay.portal.kernel.exception.SystemException)5 Repository (com.liferay.portal.model.Repository)5 User (com.liferay.portal.model.User)5 JSONObject (com.liferay.portal.kernel.json.JSONObject)4 DLFolder (com.liferay.portlet.documentlibrary.model.DLFolder)4 Indexable (com.liferay.portal.kernel.search.Indexable)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Song (org.liferay.jukebox.model.Song)3 NoSuchGroupException (com.liferay.portal.NoSuchGroupException)2 RepositoryException (com.liferay.portal.kernel.repository.RepositoryException)2 ServiceContext (com.liferay.portal.kernel.service.ServiceContext)2 Group (com.liferay.portal.model.Group)2 PrincipalException (com.liferay.portal.security.auth.PrincipalException)2 ThemeDisplay (com.liferay.portal.theme.ThemeDisplay)2 NoSuchFileEntryException (com.liferay.portlet.documentlibrary.NoSuchFileEntryException)2