private boolean isInvalid(User... users) { if (users.length <= 0) return true; if (users.length > 1) { long companyId = users[0].getCompanyId(); for (User user : users) { if (user.getCompanyId() != companyId) { LOGGER.error("Users are from different Liferay instances (they have different companyId)"); return true; } } } return false; }
private boolean isInvalid(User... users) { if (users.length <= 0) { return true; } if (users.length > 1) { long companyId = users[0].getCompanyId(); for (User user : users) { if (user.getCompanyId() != companyId) { LOGGER.error("Users are from different Liferay instances (they have different companyId)"); return true; } } } return false; }
@Override public <T> T get(String columnName, User user) { try { return get(columnName, user.getCompanyId(), user.getUserId()); } catch (Exception ex) { return null; } }
@Override public <T> void set(String columnName, T value, User user) { set(columnName, value, user.getCompanyId(), user.getUserId()); }
@Override public void removeUser(String userGroupName, User... users) { if (isInvalid(users)) return; UserGroup userGroup = findByName(userGroupName, users[0].getCompanyId()); removeUser(userGroup, users); }
@Override public boolean isFollowingThread(final long threadId) { boolean result = false; if (isLoggedInUser()) { try { final com.liferay.portal.model.User user = UserLocalServiceUtil .getUser(currentUserId); result = SubscriptionLocalServiceUtil.isSubscribed( user.getCompanyId(), user.getUserId(), MBThread.class.getName(), threadId); } catch (final NestableException e) { LOG.error(String .format("Cannot check if user is following thread %d", threadId), e); } } return result; }
public static boolean usesScreennameOnTori( final com.liferay.portal.model.User liferayUser) { boolean result = false; try { if (liferayUser != null) { result = ExpandoValueLocalServiceUtil.getData( liferayUser.getCompanyId(), com.liferay.portal.model.User.class.getName(), "CUSTOM_FIELDS", SCREENNAME_EXPANDO_COLUMN_NAME, liferayUser.getUserId(), false); } } catch (PortalException e) { e.printStackTrace(); } catch (SystemException e) { e.printStackTrace(); } return result; }
@Override public void createIfNeeded(String userGroupName, long companyId) { try { if (findByName(userGroupName, companyId) != null) return; User systemUser = liferayAutomation.lookupSysadmin(companyId); String description = liferayAutomation.autoCreateDescription(); userGroupLocalService.addUserGroup(systemUser.getUserId(), systemUser.getCompanyId(), userGroupName, description); } catch (Exception e) { String msg = String.format("Failed to create UserGroup [%s]", userGroupName); log(msg, e); throw new RuntimeException(msg, e); } }
private boolean certificationIsPublicInfoFor(final User user) { final com.liferay.portal.model.User liferayUser = liferayUser(user); boolean badgeShown = true; getLogger().debug("Defaulting 'show badge' to " + badgeShown); try { getLogger() .debug("Looking up user Custom Field " + BADGE_EXPANDO_COLUMN_NAME); badgeShown = ExpandoValueLocalServiceUtil.getData( liferayUser.getCompanyId(), com.liferay.portal.model.User.class.getName(), "CUSTOM_FIELDS", BADGE_EXPANDO_COLUMN_NAME, liferayUser.getUserId(), true); getLogger().debug("Liferay said " + badgeShown); } catch (final NestableException e) { getLogger().error(e); } catch (final Exception e) { getLogger().error(e); } getLogger().debug("Showing badge: " + badgeShown); return badgeShown; }
@Override public void addUser(String organizationName, User... users) { if (isInvalid(users)) { return; } try { Organization organization = findByName(organizationName, users[0].getCompanyId()); if (organization == null) { // create and try again createIfNeeded(organizationName, users[0].getCompanyId()); addUser(organizationName, users); } else { addUser(organization, users); } } catch (Exception e) { String msg = String.format("Failed to add users [%s] to Organization [%s]", toScreenNames(users), organizationName); log(msg, e); } }
@Override public void removeUser(String organizationName, User... users) { if (isInvalid(users)) { return; } try { Organization organization = findByName(organizationName, users[0].getCompanyId()); removeUser(organization, users); } catch (Exception e) { String msg = String.format("Failed to add user [%s] to organization [%s]", toScreenNames(users), organizationName); log(msg, e); } }
/** * Adds {@link User}s to a {@link UserGroup} with a given name. If the {@link UserGroup} does not exist an attempt * to create it is made. * * @param userGroupName the userGroupName * @param users the {@link User}s */ @Override public void addUser(String userGroupName, User... users) { if (isInvalid(users)) return; try { UserGroup userGroup = findByName(userGroupName, users[0].getCompanyId()); if (userGroup == null) { // create and try again createIfNeeded(userGroupName, users[0].getCompanyId()); addUser(userGroupName, users); } else { addUser(userGroup, users); } } catch (Exception e) { String msg = String.format("Failed to add users [%s] to UserGroup [%s]", toScreenNames(users), userGroupName); log(msg, e); } }
public static UserData convertLiferayUser(User user) throws SystemException { if (user == null) { return null; } UserDataBean ud = new UserDataBean(); ud.setEmail(user.getEmailAddress()); ud.setLogin(user.getScreenName()); ud.setFirstName(user.getFirstName()); ud.setLastName(user.getLastName()); ud.setJobTitle(user.getJobTitle()); ud.setCompanyId(user.getCompanyId()); for (Role role : user.getRoles()) { ud.addRole(role.getName()); } setGroupRoles(ud, user); Map<String, Serializable> customAttributes = user.getExpandoBridge().getAttributes(false); Map<String, Object> attributes = new HashMap<String, Object>(); for(Map.Entry<String, Serializable> entry: customAttributes.entrySet()) { String attributeKey = entry.getKey(); Serializable value = entry.getValue(); if(attributeKey.contains(APERTE_PREFIX_ATTRIBUTE)) attributes.put(attributeKey, value); } ud.setAttributes(attributes); return ud; }
public static UserData convertLiferayUser(User user) throws SystemException { if (user == null) { return null; } UserData ud = new UserData(); ud.setEmail(user.getEmailAddress()); ud.setLogin(user.getScreenName()); ud.setFirstName(user.getFirstName()); ud.setLastName(user.getLastName()); ud.setJobTitle(user.getJobTitle()); ud.setCompanyId(user.getCompanyId()); ud.setLiferayUserId(user.getUserId()); for (Role role : user.getRoles()) { ud.addRoleName(role.getName(), role.getDescription()); } setGroupRoles(ud, user); return ud; }