/** @author Jonathan Lee */ public class UpgradeUser extends UpgradeProcess { @Override protected void doUpgrade() throws Exception { List<User> users = UserLocalServiceUtil.getUsers(QueryUtil.ALL_POS, QueryUtil.ALL_POS); for (User user : users) { try { if (user.isDefaultUser()) { continue; } Group group = user.getGroup(); LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(group.getGroupId(), false); String themeId = layoutSet.getThemeId(); if (!themeId.equals("so_WAR_sotheme")) { return; } Role role = RoleLocalServiceUtil.getRole(user.getCompanyId(), RoleConstants.SOCIAL_OFFICE_USER); UserLocalServiceUtil.addRoleUsers(role.getRoleId(), new long[] {user.getUserId()}); updateUserGroup(group); updateSocialRelations(user); } catch (Exception e) { } } } protected void updateSocialRelations(User user) throws Exception { List<User> socialUsers = UserLocalServiceUtil.getSocialUsers( user.getUserId(), SocialRelationConstants.TYPE_BI_FRIEND, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); for (User socialUser : socialUsers) { SocialRelationLocalServiceUtil.addRelation( user.getUserId(), socialUser.getUserId(), SocialRelationConstants.TYPE_BI_CONNECTION); } } protected void updateUserGroup(Group group) throws Exception { LayoutLocalServiceUtil.deleteLayouts(group.getGroupId(), false, new ServiceContext()); LayoutSetPrototypeUtil.updateLayoutSetPrototype( group, false, SocialOfficeConstants.LAYOUT_SET_PROTOTYPE_KEY_USER_PUBLIC); LayoutSet publicLayoutSet = LayoutSetLocalServiceUtil.getLayoutSet(group.getGroupId(), false); PortalClassInvoker.invoke( true, _mergeLayoutSetPrototypeLayoutsMethodKey, group, publicLayoutSet); LayoutLocalServiceUtil.deleteLayouts(group.getGroupId(), true, new ServiceContext()); LayoutSetPrototypeUtil.updateLayoutSetPrototype( group, true, SocialOfficeConstants.LAYOUT_SET_PROTOTYPE_KEY_USER_PRIVATE); LayoutSet privateLayoutSet = LayoutSetLocalServiceUtil.getLayoutSet(group.getGroupId(), true); PortalClassInvoker.invoke( true, _mergeLayoutSetPrototypeLayoutsMethodKey, group, privateLayoutSet); SocialOfficeUtil.enableSocialOffice(group); } private static MethodKey _mergeLayoutSetPrototypeLayoutsMethodKey = new MethodKey( ClassResolverUtil.resolveByPortalClassLoader("com.liferay.portlet.sites.util.SitesUtil"), "mergeLayoutSetPrototypeLayouts", Group.class, LayoutSet.class); }
/** @author Alexander Chow */ public class CMISRepositoryUtil { public static void checkRepository( long repositoryId, Map<String, String> parameters, UnicodeProperties typeSettingsProperties, String typeSettingsKey) { try { PortalClassInvoker.invoke( false, _checkRepositoryMethodKey, repositoryId, parameters, typeSettingsProperties, typeSettingsKey); } catch (Exception e) { _log.error(e, e); } } public static Session createSession(Map<String, String> parameters) throws RepositoryException { Session session = null; try { Object returnObj = PortalClassInvoker.invoke(false, _createSessionMethodKey, parameters); if (returnObj != null) { session = (Session) returnObj; } } catch (RepositoryException re) { throw re; } catch (Exception e) { _log.error(e, e); } return session; } public static String getTypeSettingsValue( UnicodeProperties typeSettingsProperties, String typeSettingsKey) { String value = null; try { Object returnObj = PortalClassInvoker.invoke( false, _getTypeSettingsValueMethodKey, typeSettingsProperties, typeSettingsKey); if (returnObj != null) { value = (String) returnObj; } } catch (Exception e) { _log.error(e, e); } return value; } private static final String _CLASS_NAME = "com.liferay.portal.repository.cmis.CMISRepositoryUtil"; private static Log _log = LogFactoryUtil.getLog(CMISRepositoryUtil.class); private static MethodKey _checkRepositoryMethodKey = new MethodKey( ClassResolverUtil.resolveByPortalClassLoader(_CLASS_NAME), "checkRepository", long.class, Map.class, UnicodeProperties.class, String.class); private static MethodKey _createSessionMethodKey = new MethodKey( ClassResolverUtil.resolveByPortalClassLoader(_CLASS_NAME), "createSession", Map.class); private static MethodKey _getTypeSettingsValueMethodKey = new MethodKey( ClassResolverUtil.resolveByPortalClassLoader(_CLASS_NAME), "getTypeSettingsValue", UnicodeProperties.class, String.class); }