use of com.ableneo.liferay.portal.setup.domain.UserGroup in project liferay-db-setup-core by ableneo.
the class SetupUserGroups method setCustomFields.
private static void setCustomFields(final com.liferay.portal.kernel.model.UserGroup liferayUserGroup, final List<CustomFieldSetting> customFieldSettings, final UserGroup userGroup) {
if (liferayUserGroup == null) {
return;
}
Class clazz = com.liferay.portal.kernel.model.UserGroup.class;
for (CustomFieldSetting cfs : customFieldSettings) {
String resolverHint = "Custom value for userGroup " + userGroup.getName() + ", " + " Key " + cfs.getKey() + ", value " + cfs.getValue();
long company = SetupConfigurationThreadLocal.getRunInCompanyId();
CustomFieldSettingUtil.setExpandoValue(resolverHint, liferayUserGroup.getUserGroupId(), company, clazz, liferayUserGroup.getUserGroupId(), cfs.getKey(), cfs.getValue());
}
}
use of com.ableneo.liferay.portal.setup.domain.UserGroup in project liferay-db-setup-core by ableneo.
the class SetupUserGroups method setupUserGroups.
public static void setupUserGroups(final List<UserGroup> userGroups) {
final long userId = SetupConfigurationThreadLocal.getRunAsUserId();
for (UserGroup userGroup : userGroups) {
com.liferay.portal.kernel.model.UserGroup liferayUserGroup = null;
long liferayUserGroupId = -1;
long companyId = SetupConfigurationThreadLocal.getRunInCompanyId();
try {
liferayUserGroup = UserGroupLocalServiceUtil.getUserGroup(companyId, userGroup.getName());
liferayUserGroupId = liferayUserGroup.getUserGroupId();
} catch (PortalException e) {
LOG.info(String.format("UserGroup does not exists, creating new one for name: %1$s", userGroup.getName()));
}
if (liferayUserGroupId == -1) {
try {
liferayUserGroup = UserGroupLocalServiceUtil.addUserGroup(userId, companyId, userGroup.getName(), userGroup.getDescription(), new ServiceContext());
} catch (PortalException e) {
LOG.error(String.format("Can not create UserGroup with name: %1$s", userGroup.getName()), e);
continue;
}
}
if (userGroup.getCustomFieldSetting() != null && !userGroup.getCustomFieldSetting().isEmpty()) {
setCustomFields(liferayUserGroup, userGroup.getCustomFieldSetting(), userGroup);
}
if (!userGroup.getRole().isEmpty() && liferayUserGroup != null) {
LOG.info("Setting Roles for UserGroup.");
addRolesToUserGroup(userGroup, liferayUserGroup);
}
if (!userGroup.getUserAsMember().isEmpty() && liferayUserGroup != null) {
LOG.info("Setting User Members.");
addUsersToUserGroup(userGroup.getUserAsMember(), liferayUserGroup);
}
}
}
Aggregations