use of com.liferay.portal.kernel.model.Group in project liferay-db-setup-core by ableneo.
the class SetupSites method assignMemberGroups.
private static void assignMemberGroups(List<UserGroupAsMember> memberGroups, long companyId, long groupId) {
if (Objects.isNull(memberGroups) || memberGroups.isEmpty()) {
return;
}
for (UserGroupAsMember memberGroup : memberGroups) {
try {
UserGroup liferayUserGroup = UserGroupLocalServiceUtil.getUserGroup(companyId, memberGroup.getUserGroupName());
Group liferayGroup = GroupLocalServiceUtil.getGroup(groupId);
GroupLocalServiceUtil.addUserGroupGroup(liferayUserGroup.getUserGroupId(), liferayGroup);
LOG.info(String.format("UserGroup %1$s was assigned as site member to %2$s", liferayUserGroup.getName(), liferayGroup.getDescriptiveName()));
assignGroupMemberRoles(memberGroup.getRole(), companyId, liferayGroup, liferayUserGroup);
} catch (PortalException e) {
LOG.error(String.format("Cannot find UserGroup with name: %1$s. Group won't be assigned to site.", memberGroup.getUserGroupName()), e);
}
}
}
use of com.liferay.portal.kernel.model.Group in project liferay-db-setup-core by ableneo.
the class SetupSites method assignMemberRoles.
private static void assignMemberRoles(List<Role> membershipRoles, long companyId, long groupId) {
if (Objects.isNull(membershipRoles) || membershipRoles.isEmpty()) {
return;
}
Set<String> roles = new HashSet<String>();
for (Role membershipRole : membershipRoles) {
try {
com.liferay.portal.kernel.model.Role liferayRole = RoleLocalServiceUtil.getRole(companyId, membershipRole.getName());
roles.add(String.valueOf(liferayRole.getRoleId()));
} catch (PortalException e) {
LOG.error(String.format("Can not get role with name%1$s does not exists. Will not be assigned.", membershipRole.getName()));
}
}
if (roles.isEmpty()) {
LOG.info("NO new roles to be assigned to site " + groupId);
return;
}
try {
Group liferayGroup = GroupLocalServiceUtil.getGroup(groupId);
UnicodeProperties siteGroupProps = liferayGroup.getTypeSettingsProperties();
if (siteGroupProps == null) {
siteGroupProps = new UnicodeProperties();
}
String roleIds = siteGroupProps.getProperty(UNIPARAM_DEFAULT_SITE_ROLE_IDS);
if (roleIds != null && roleIds.length() > 1) {
String[] roleIdArr = roleIds.split("[,;]+");
roles.addAll(Arrays.asList(roleIdArr));
}
roleIds = StringUtil.merge(roles, ",");
siteGroupProps.setProperty(UNIPARAM_DEFAULT_SITE_ROLE_IDS, roleIds);
liferayGroup.setTypeSettingsProperties(siteGroupProps);
GroupLocalServiceUtil.updateGroup(liferayGroup);
StringBuilder sb = new StringBuilder("Roles ").append(roleIds).append(" assigned to site-group ").append(liferayGroup.getDescriptiveName());
LOG.info(sb.toString());
} catch (Exception e) {
LOG.error("Can not set roles to site-group (" + roles + ")=>" + groupId, e);
}
}
use of com.liferay.portal.kernel.model.Group in project liferay-db-setup-core by ableneo.
the class SetupSites method assignMemberUsers.
private static void assignMemberUsers(List<UserAsMember> memberUsers, long companyId, long groupId) {
if (Objects.isNull(memberUsers) || memberUsers.isEmpty()) {
return;
}
for (UserAsMember memberUser : memberUsers) {
User user = UserLocalServiceUtil.fetchUserByScreenName(companyId, memberUser.getScreenName());
if (Objects.isNull(user)) {
LOG.error(String.format("User with screenName %1$s does not exists. Won't be assigned as site member.", memberUser.getScreenName()));
continue;
}
try {
Group liferayGroup = GroupLocalServiceUtil.getGroup(groupId);
GroupLocalServiceUtil.addUserGroup(user.getUserId(), liferayGroup.getGroupId());
LOG.info(String.format("User %1$s was assigned as member of site %2$s", user.getScreenName(), liferayGroup.getDescriptiveName()));
assignUserMemberRoles(memberUser.getRole(), companyId, liferayGroup, user);
} catch (PortalException e) {
LOG.error(e);
}
}
}
use of com.liferay.portal.kernel.model.Group in project liferay-db-setup-core by ableneo.
the class SetupPages method setupTheme.
/**
* @param groupId
* @param theme
* @param isPrivate
*
* @throws SystemException
* @throws PortalException
*/
private static void setupTheme(final long groupId, final Theme theme, final boolean isPrivate) throws PortalException {
Group group = GroupLocalServiceUtil.getGroup(groupId);
LayoutSet set;
if (isPrivate) {
set = group.getPrivateLayoutSet();
} else {
set = group.getPublicLayoutSet();
}
set.setThemeId(theme.getName());
set.setSettingsProperties(mergeConvertProperties(set.getSettingsProperties(), theme.getLayoutSetSettings()));
LayoutSetLocalServiceUtil.updateLayoutSet(set);
}
use of com.liferay.portal.kernel.model.Group in project liferay-db-setup-core by ableneo.
the class SetupPages method addAssetPublisherPortletIntoPage.
private static void addAssetPublisherPortletIntoPage(PageType page, Layout layout, AssetPublisherPortletType portlet, long company, long groupId) throws PortalException {
if (isLinkPage(page)) {
return;
}
LOG.info("Adding AssetPublisherPortlet: " + portlet.getColumn() + "@" + portlet.getColumnPosition() + "-" + portlet.getPortletId() + "; ADTgroupIdFrom:" + portlet.getAdtTemplateSiteUrl());
PagePortletType toInsert = null;
toInsert = new PagePortletType();
toInsert.setColumn(portlet.getColumn());
toInsert.setColumnPosition(portlet.getColumnPosition());
toInsert.setPortletId(portlet.getPortletId());
toInsert.getPortletPreference().addAll(portlet.getPortletPreference());
toInsert.setRolePermissions(portlet.getRolePermissions());
// // ADT STYLE is in this groupId: // 35345 == myra portal, now..
// prefMap.put("displayStyleGroupId", "35345");
Group group = GroupLocalServiceUtil.getFriendlyURLGroup(company, portlet.getAdtTemplateSiteUrl());
toInsert.getPortletPreference().add(newPortletPreference("displayStyleGroupId", String.valueOf(group.getPrimaryKey())));
// //-TODO: decode runtime..
// // [ WIKI-FTl, ...
// // prefMap.put("classNameIds", new String[] {"32502", "28501", "20008", "28506", "33222", "34325", "33246", "20009", "34316", "33208"});
List<String> shownArticleClasses = StringUtil.split(portlet.getShownArticleClasses(), CharPool.SEMICOLON);
Set<String> shownClassIds = new HashSet<String>();
for (String cls : shownArticleClasses) {
ClassName shownClass = ClassNameLocalServiceUtil.getClassName(cls);
shownClassIds.add(String.valueOf(shownClass.getPrimaryKey()));
}
toInsert.getPortletPreference().add(newPortletPreference("classNameIds", StringUtil.merge(shownClassIds, StringPool.COMMA)));
// // //TODO: runtime query of all structure templates, where class-type == com.liferay.journal.model.JournalArticle
// // //BASIC-WEB-CONTENT, TEXT-ARRAY-STRUCT, BUTTON-BOTTOM-STRUCT
// //// 28501: INSERT INTO CLASSNAME_ VALUES(0,28501,'com.liferay.journal.model.JournalArticle')
// //// INSERT INTO DDMSTRUCTURE VALUES(0,'55d9d223-9da5-bda0-0c80-88b8d8c97997',34987,20128,20101,20105,NULL,20105,NULL,'2020-11-21 04:57:26.721000','2020-11-21 04:57:26.721000',0,28501,'BASIC-WEB-CONTENT','1.0','<?xml version=''1.0'' encoding=''UTF-8''?><root available-locales="en_US,sv_SE,pt_BR,ja_JP,fr_FR,hu_HU,de_DE,ca_ES,ar_SA,fi_FI,zh_CN,es_ES,nl_NL" default-locale="en_US"><Name language-id="sv_SE">Vanligt inneh\u00e5ll</Name><Name language-id="pt_BR">Conte\u00fado Web b\u00e1sico</Name><Name language-id="ja_JP">\u57fa\u672cWeb\u30b3\u30f3\u30c6\u30f3\u30c4</Name><Name language-id="fr_FR">Contenu web basique</Name><Name language-id="hu_HU">Alapvet\u0151 webtartalom</Name><Name language-id="de_DE">Einfacher Webcontent</Name><Name language-id="ca_ES">Contigut web b\u00e0sic</Name><Name language-id="ar_SA">\u062a\u062d\u0631\u064a\u0631 \u0645\u062d\u062a\u0648\u0649</Name><Name language-id="fi_FI">Tavallinen web-sis\u00e4lt\u00f6</Name><Name language-id="en_US">Basic Web Content</Name><Name language-id="zh_CN">\u57fa\u672c Web \u5185\u5bb9</Name><Name language-id="es_ES">Contenido web b\u00e1sico</Name><Name language-id="nl_NL">Basiswebcontent</Name></root>','<?xml version=''1.0'' encoding=''UTF-8''?><root available-locales="en_US,sv_SE,pt_BR,ja_JP,fr_FR,hu_HU,de_DE,ca_ES,ar_SA,fi_FI,zh_CN,es_ES,nl_NL" default-locale="en_US"><Description language-id="sv_SE">Vanligt inneh\u00e5ll</Description><Description language-id="pt_BR">Conte\u00fado Web b\u00e1sico</Description><Description language-id="ja_JP">\u57fa\u672cWeb\u30b3\u30f3\u30c6\u30f3\u30c4</Description><Description language-id="fr_FR">Contenu web basique</Description><Description language-id="hu_HU">Alapvet\u0151 webtartalom</Description><Description language-id="de_DE">Einfacher Webcontent</Description><Description language-id="ca_ES">Contigut web b\u00e0sic</Description><Description language-id="ar_SA">\u062a\u062d\u0631\u064a\u0631 \u0645\u062d\u062a\u0648\u0649</Description><Description language-id="fi_FI">Tavallinen web-sis\u00e4lt\u00f6</Description><Description language-id="en_US">Basic Web Content</Description><Description language-id="zh_CN">\u57fa\u672c Web \u5185\u5bb9</Description><Description language-id="es_ES">Contenido web b\u00e1sico</Description><Description language-id="nl_NL">Basiswebcontent</Description></root>','{"availableLanguageIds":["en_US"],"successPage":{"body":{},"title":{},"enabled":false},"defaultLanguageId":"en_US","fields":[{"fieldNamespace":"ddm","indexType":"text","dataType":"html","predefinedValue":{},"name":"content","localizable":true,"tip":{},"label":{"en_US":"content"},"type":"ddm-text-html","showLabel":true}]}','json',0,NULL)
// //// INSERT INTO DDMSTRUCTURE VALUES(0,'5dbceeef-b83f-63db-651a-159ce9964d6e',35348,35345,20101,20130,'Test Test',20130,'Test Test','2020-11-25 13:18:47.567000','2020-11-25 13:18:47.567000',0,28501,'TEXT-ARRAY-STRUCT','1.0','<?xml version=''1.0'' encoding=''UTF-8''?><root available-locales="en_US" default-locale="en_US"><Name language-id="en_US">TEXT-ARRAY-STRUCT</Name></root>','','{"availableLanguageIds":["en_US"],"successPage":{"body":{},"title":{},"enabled":false},"defaultLanguageId":"en_US","fields":[{"indexType":"keyword","repeatable":true,"dataType":"string","predefinedValue":{"en_US":""},"name":"textString","localizable":false,"readOnly":false,"tip":{"en_US":""},"label":{"en_US":"Sz\u00f6veg"},"type":"text","required":false,"showLabel":true}]}','json',0,NULL)
// //// INSERT INTO DDMSTRUCTURE VALUES(0,'006c2151-f6cb-c1fe-19f6-5ce259582b28',35352,35345,20101,20130,'Test Test',20130,'Test Test','2020-11-25 13:18:47.648000','2020-11-25 13:18:47.648000',0,28501,'BUTTON-BOTTOM-STRUCT','1.0','<?xml version=''1.0'' encoding=''UTF-8''?><root available-locales="en_US" default-locale="en_US"><Name language-id="en_US">BUTTON-BOTTOM-STRUCT</Name></root>','','{"availableLanguageIds":["en_US"],"successPage":{"body":{},"title":{},"enabled":false},"defaultLanguageId":"en_US","fields":[{"indexType":"keyword","repeatable":false,"dataType":"string","predefinedValue":{"en_US":""},"name":"titletext","localizable":true,"readOnly":false,"tip":{"en_US":""},"label":{"en_US":"Cimsor"},"type":"text","required":false,"showLabel":true},{"indexType":"text","repeatable":true,"dataType":"string","predefinedValue":{"en_US":""},"name":"contenttext","localizable":true,"readOnly":false,"tip":{"en_US":""},"label":{"en_US":"Szoveges tartalom"},"type":"textarea","required":false,"showLabel":true},{"dataType":"boolean","predefinedValue":{"en_US":"false"},"readOnly":false,"label":{"en_US":"van gombja?"},"type":"checkbox","required":false,"showLabel":true,"nestedFields":[{"indexType":"keyword","repeatable":false,"dataType":"string","predefinedValue":{"en_US":""},"name":"buttontitle","localizable":true,"readOnly":false,"tip":{"en_US":""},"label":{"en_US":"szovege"},"type":"text","required":false,"showLabel":true},{"indexType":"keyword","repeatable":false,"dataType":"string","predefinedValue":{"en_US":""},"name":"buttonlink","localizable":true,"readOnly":false,"tip":{"en_US":""},"label":{"en_US":"Url/link"},"type":"text","required":false,"showLabel":true},{"dataType":"string","predefinedValue":{"en_US":"[\"\"]"},"multiple":false,"readOnly":false,"label":{"en_US":"gomb szine/tipusa"},"type":"select","required":false,"showLabel":true,"indexType":"keyword","repeatable":false,"name":"buttontype","options":[{"label":{"en_US":"elsodleges"},"value":"btn-primary"},{"label":{"en_US":"masodlagos"},"value":"btn-secondary"},{"label":{"en_US":"atlatszo"},"value":"btn-info"},{"label":{"en_US":"link-szeru"},"value":"btn-link"}],"localizable":true,"tip":{"en_US":""}},{"indexType":"keyword","repeatable":false,"dataType":"string","predefinedValue":{"en_US":""},"name":"buttonicon","localizable":true,"readOnly":false,"tip":{"en_US":""},"label":{"en_US":"ikon/css class"},"type":"text","required":false,"showLabel":true}],"indexType":"keyword","repeatable":true,"name":"hasbutton","localizable":true,"tip":{"en_US":""}}]}','json',0,NULL)
// // prefMap.put("classTypeIdsJournalArticleAssetRendererFactory", "34987,35348,35352");
// ClassName journalArticleClass = ClassNameLocalServiceUtil.getClassName(portlet.getAssetRendererBaseClass());
// List<DDLRecordSet> journalDescendants = DDLRecordSetLocalServiceUtil.getDDMStructureRecordSets(journalArticleClass.getPrimaryKey());
// Set<String> ddlIds = new HashSet<String>();
// for (DDLRecordSet ddlRecord : journalDescendants) {
// ddlIds.add(String.valueOf(ddlRecord.getPrimaryKey()));
// }
// toInsert.getPortletPreference().add(newPortletPreference("classTypeIdsJournalArticleAssetRendererFactory",StringUtil.merge(ddlIds, StringPool.COMMA)));
insertPortletIntoPage(page, layout, toInsert, company, groupId);
}
Aggregations