Created
October 11, 2017 06:27
-
-
Save CorneAussems/f3f7613c3a64c8d1df1c3a57877478ea to your computer and use it in GitHub Desktop.
Liferay Remove and add UserGroup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.liferay.portal.service.*; | |
import com.liferay.portal.kernel.util.GetterUtil; | |
import com.liferay.portal.util.*; | |
try{ | |
serviceContext = new com.liferay.portal.service.ServiceContext() | |
long companyId = PortalUtil.getDefaultCompanyId() | |
employee = com.liferay.portal.service.UserGroupLocalServiceUtil.getUserGroup(companyId,"EMPLOYEE"); | |
fired = com.liferay.portal.service.UserGroupLocalServiceUtil.getUserGroup(companyId,"FIRED_EMPLOYEE"); | |
out.println(employee); | |
out.println(fired); | |
screenNames = "999,8888".split(",") | |
for( i=0; i<screenNames.length;i++){ | |
screenName = screenNames[i]; | |
user = UserLocalServiceUtil.getUserByScreenName(companyId,screenName) | |
out.println(user.getUserId()); | |
try{ | |
UserGroupLocalServiceUtil.deleteUserUserGroup(user.getUserId(),employee); | |
}catch(e){out.println('DELETE:'+e)} | |
try{ | |
UserGroupLocalServiceUtil.addUserUserGroup(user.getUserId(),fired); | |
}catch(e){out.println('ADD:'+e)} | |
} | |
}catch(e){ | |
out.println(e); | |
} | |
out.println('done'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment