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;
}
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());
}
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());
}
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;
}
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();
}
}
}
Aggregations