Search in sources :

Example 11 with Group

use of com.liferay.portal.model.Group in project liferay-ide by liferay.

the class ShindigUtil method getOwnerId.

public static String getOwnerId(Layout layout) throws PortalException, SystemException {
    Group group = layout.getGroup();
    long classPK = group.getClassPK();
    String ownerId = "G-" + classPK;
    if (group.isUser()) {
        ownerId = String.valueOf(classPK);
    }
    return ownerId;
}
Also used : Group(com.liferay.portal.model.Group)

Example 12 with Group

use of com.liferay.portal.model.Group in project liferay-ide by liferay.

the class LiferayMediaItemService method doGetMediaItems.

protected RestfulCollection<MediaItem> doGetMediaItems(UserId userId, String appId, String albumId, Set<String> fields, CollectionOptions collectionOptions, SecurityToken securityToken) throws Exception {
    long userIdLong = GetterUtil.getLong(userId.getUserId(securityToken));
    User user = UserLocalServiceUtil.getUserById(userIdLong);
    List<MediaItem> mediaItems = new ArrayList<MediaItem>();
    if (!ShindigUtil.isValidUser(user)) {
        return new RestfulCollection<MediaItem>(mediaItems, collectionOptions.getFirst(), mediaItems.size(), collectionOptions.getMax());
    }
    Group group = user.getGroup();
    long groupIdLong = group.getGroupId();
    long albumIdLong = GetterUtil.getLong(albumId);
    List<FileEntry> fileEntries = DLAppServiceUtil.getFileEntries(groupIdLong, albumIdLong);
    for (FileEntry fileEntry : fileEntries) {
        MediaItem.Type mediaItemType = toMediaItemType(StringPool.PERIOD.concat(fileEntry.getExtension()));
        if (mediaItemType == null) {
            continue;
        }
        MediaItem mediaItem = toMediaItem(fileEntry, fields, securityToken);
        mediaItems.add(mediaItem);
    }
    return new RestfulCollection<MediaItem>(mediaItems, collectionOptions.getFirst(), mediaItems.size(), collectionOptions.getMax());
}
Also used : Group(com.liferay.portal.model.Group) User(com.liferay.portal.model.User) MediaItem(org.apache.shindig.social.opensocial.model.MediaItem) ArrayList(java.util.ArrayList) RestfulCollection(org.apache.shindig.protocol.RestfulCollection) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry) Type(org.apache.shindig.social.opensocial.model.MediaItem.Type)

Example 13 with Group

use of com.liferay.portal.model.Group in project liferay-ide by liferay.

the class LiferayMediaItemService method doGetMediaItems.

protected RestfulCollection<MediaItem> doGetMediaItems(Set<UserId> userIds, GroupId groupId, String appId, Set<String> fields, CollectionOptions collectionOptions, SecurityToken securityToken) throws Exception {
    List<MediaItem> mediaItems = new ArrayList<MediaItem>();
    for (UserId userId : userIds) {
        long userIdLong = GetterUtil.getLong(userId.getUserId(securityToken));
        User user = UserLocalServiceUtil.getUserById(userIdLong);
        if (!ShindigUtil.isValidUser(user)) {
            continue;
        }
        List<FileEntry> fileEntries = new ArrayList<FileEntry>();
        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<FileEntry> friendFileEntries = DLAppServiceUtil.getGroupFileEntries(group.getGroupId(), socialUser.getUserId(), collectionOptions.getFirst(), collectionOptions.getMax());
                fileEntries.addAll(friendFileEntries);
            }
        } else if (groupIdType.equals(GroupId.Type.self)) {
            Group group = user.getGroup();
            fileEntries = DLAppServiceUtil.getGroupFileEntries(group.getGroupId(), user.getUserId(), collectionOptions.getFirst(), collectionOptions.getMax());
        }
        for (FileEntry fileEntry : fileEntries) {
            MediaItem.Type mediaItemType = toMediaItemType(StringPool.PERIOD.concat(fileEntry.getExtension()));
            if (mediaItemType == null) {
                continue;
            }
            MediaItem mediaItem = toMediaItem(fileEntry, fields, securityToken);
            mediaItems.add(mediaItem);
        }
    }
    return new RestfulCollection<MediaItem>(mediaItems, collectionOptions.getFirst(), mediaItems.size(), collectionOptions.getMax());
}
Also used : Group(com.liferay.portal.model.Group) User(com.liferay.portal.model.User) ArrayList(java.util.ArrayList) RestfulCollection(org.apache.shindig.protocol.RestfulCollection) GroupId(org.apache.shindig.social.opensocial.spi.GroupId) Type(org.apache.shindig.social.opensocial.model.MediaItem.Type) MediaItem(org.apache.shindig.social.opensocial.model.MediaItem) UserId(org.apache.shindig.social.opensocial.spi.UserId) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry)

Example 14 with Group

use of com.liferay.portal.model.Group in project liferay-ide by liferay.

the class UserLocalServiceImpl method updateScreenName.

/**
 * Updates the user's screen name.
 *
 * @param  userId the primary key of the user
 * @param  screenName the user's new screen name
 * @return the user
 * @throws PortalException if a user with the primary key could not be found
 *         or if the new screen name was invalid
 * @throws SystemException if a system exception occurred
 */
@Override
public User updateScreenName(long userId, String screenName) throws PortalException, SystemException {
    // User
    User user = userPersistence.findByPrimaryKey(userId);
    screenName = getLogin(screenName);
    validateScreenName(user.getCompanyId(), userId, screenName);
    if (!StringUtil.equalsIgnoreCase(user.getScreenName(), screenName)) {
        user.setDigest(StringPool.BLANK);
    }
    user.setScreenName(screenName);
    userPersistence.update(user);
    // Group
    Group group = groupLocalService.getUserGroup(user.getCompanyId(), userId);
    group.setFriendlyURL(StringPool.SLASH + screenName);
    groupPersistence.update(group);
    return user;
}
Also used : Group(com.liferay.portal.model.Group) UserGroup(com.liferay.portal.model.UserGroup) User(com.liferay.portal.model.User)

Example 15 with Group

use of com.liferay.portal.model.Group in project liferay-ide by liferay.

the class UserLocalServiceImpl method validateScreenName.

protected void validateScreenName(long companyId, long userId, String screenName) throws PortalException, SystemException {
    if (Validator.isNull(screenName)) {
        throw new UserScreenNameException();
    }
    ScreenNameValidator screenNameValidator = ScreenNameValidatorFactory.getInstance();
    if (!screenNameValidator.validate(companyId, screenName)) {
        throw new UserScreenNameException();
    }
    if (Validator.isNumber(screenName)) {
        if (!PropsValues.USERS_SCREEN_NAME_ALLOW_NUMERIC) {
            throw new UserScreenNameException();
        }
        if (!screenName.equals(String.valueOf(userId))) {
            Group group = groupPersistence.fetchByPrimaryKey(GetterUtil.getLong(screenName));
            if (group != null) {
                throw new UserScreenNameException();
            }
        }
    }
    for (char c : screenName.toCharArray()) {
        if (!Validator.isChar(c) && !Validator.isDigit(c) && (c != CharPool.DASH) && (c != CharPool.PERIOD) && (c != CharPool.UNDERLINE)) {
            throw new UserScreenNameException();
        }
    }
    String[] anonymousNames = BaseServiceImpl.ANONYMOUS_NAMES;
    for (String anonymousName : anonymousNames) {
        if (StringUtil.equalsIgnoreCase(screenName, anonymousName)) {
            throw new UserScreenNameException();
        }
    }
    User user = userPersistence.fetchByC_SN(companyId, screenName);
    if ((user != null) && (user.getUserId() != userId)) {
        throw new DuplicateUserScreenNameException("{userId=" + userId + "}");
    }
    String friendlyURL = StringPool.SLASH + screenName;
    Group group = groupPersistence.fetchByC_F(companyId, friendlyURL);
    if ((group != null) && (group.getClassPK() != userId)) {
        throw new GroupFriendlyURLException(GroupFriendlyURLException.DUPLICATE);
    }
    int exceptionType = LayoutImpl.validateFriendlyURL(friendlyURL);
    if (exceptionType != -1) {
        throw new UserScreenNameException(new GroupFriendlyURLException(exceptionType));
    }
    String[] reservedScreenNames = PrefsPropsUtil.getStringArray(companyId, PropsKeys.ADMIN_RESERVED_SCREEN_NAMES, StringPool.NEW_LINE, PropsValues.ADMIN_RESERVED_SCREEN_NAMES);
    for (String reservedScreenName : reservedScreenNames) {
        if (StringUtil.equalsIgnoreCase(screenName, reservedScreenName)) {
            throw new ReservedUserScreenNameException();
        }
    }
}
Also used : Group(com.liferay.portal.model.Group) UserGroup(com.liferay.portal.model.UserGroup) GroupFriendlyURLException(com.liferay.portal.GroupFriendlyURLException) ScreenNameValidator(com.liferay.portal.security.auth.ScreenNameValidator) User(com.liferay.portal.model.User) DuplicateUserScreenNameException(com.liferay.portal.DuplicateUserScreenNameException) ReservedUserScreenNameException(com.liferay.portal.ReservedUserScreenNameException) ReservedUserScreenNameException(com.liferay.portal.ReservedUserScreenNameException) DuplicateUserScreenNameException(com.liferay.portal.DuplicateUserScreenNameException) UserScreenNameException(com.liferay.portal.UserScreenNameException)

Aggregations

Group (com.liferay.portal.model.Group)30 User (com.liferay.portal.model.User)15 UserGroup (com.liferay.portal.model.UserGroup)13 ArrayList (java.util.ArrayList)9 UserGroupRole (com.liferay.portal.model.UserGroupRole)6 Role (com.liferay.portal.model.Role)5 Indexer (com.liferay.portal.kernel.search.Indexer)4 Company (com.liferay.portal.model.Company)4 Contact (com.liferay.portal.model.Contact)3 ServiceContext (com.liferay.portal.service.ServiceContext)3 RestfulCollection (org.apache.shindig.protocol.RestfulCollection)3 KBArticle (com.liferay.knowledgebase.model.KBArticle)2 DuplicateUserScreenNameException (com.liferay.portal.DuplicateUserScreenNameException)2 GroupFriendlyURLException (com.liferay.portal.GroupFriendlyURLException)2 NoSuchImageException (com.liferay.portal.NoSuchImageException)2 RequiredUserException (com.liferay.portal.RequiredUserException)2 ReservedUserScreenNameException (com.liferay.portal.ReservedUserScreenNameException)2 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)2 Folder (com.liferay.portal.kernel.repository.model.Folder)2 Organization (com.liferay.portal.model.Organization)2