use of com.ableneo.liferay.portal.setup.domain.Site in project liferay-db-setup-core by ableneo.
the class SetupSites method deleteSite.
public static void deleteSite(final List<com.ableneo.liferay.portal.setup.domain.Site> sites, final String deleteMethod) {
switch(deleteMethod) {
case "excludeListed":
Map<String, Site> toBeDeletedOrganisations = convertSiteListToHashMap(sites);
try {
for (com.liferay.portal.kernel.model.Group siteGroup : GroupLocalServiceUtil.getGroups(QueryUtil.ALL_POS, QueryUtil.ALL_POS)) {
if (!toBeDeletedOrganisations.containsKey(siteGroup.getName())) {
deleteLiferayGroup(siteGroup);
}
}
} catch (SystemException e) {
LOG.error("Error by retrieving sites!", e);
}
break;
case "onlyListed":
for (com.ableneo.liferay.portal.setup.domain.Site site : sites) {
String name = site.getName();
try {
com.liferay.portal.kernel.model.Group o = GroupLocalServiceUtil.getGroup(SetupConfigurationThreadLocal.getRunInGroupId(), name);
GroupLocalServiceUtil.deleteGroup(o);
} catch (Exception e) {
LOG.error("Error by deleting Site !", e);
}
LOG.info(String.format("Deleting Site %1$s", name));
}
break;
default:
LOG.error(String.format("Unknown delete method : %1$s", deleteMethod));
break;
}
}
use of com.ableneo.liferay.portal.setup.domain.Site in project liferay-db-setup-core by ableneo.
the class SetupSites method setupSites.
public static void setupSites(final List<com.ableneo.liferay.portal.setup.domain.Site> siteList, final Group parentGroup) throws PortalException {
long companyId = SetupConfigurationThreadLocal.getRunInCompanyId();
for (com.ableneo.liferay.portal.setup.domain.Site site : siteList) {
Group liferayGroup = setupSite(parentGroup, companyId, site);
List<com.ableneo.liferay.portal.setup.domain.Site> sites = site.getSite();
setupSites(sites, liferayGroup);
}
}
use of com.ableneo.liferay.portal.setup.domain.Site in project liferay-db-setup-core by ableneo.
the class SetupOrganizations method setupOrganizations.
public static void setupOrganizations(final Iterable<com.ableneo.liferay.portal.setup.domain.Organization> organizations, final Organization parentOrg, final Group parentGroup) {
for (com.ableneo.liferay.portal.setup.domain.Organization organization : organizations) {
try {
Organization liferayOrg = null;
Group liferayGroup = null;
long groupId = -1;
long companyId = SetupConfigurationThreadLocal.getRunInCompanyId();
try {
Organization org = OrganizationLocalServiceUtil.getOrganization(companyId, organization.getName());
liferayGroup = org.getGroup();
groupId = org.getGroupId();
liferayOrg = org;
LOG.info(String.format("Setup: Organization %1$s already exist in system, not creating...", organization.getName()));
} catch (PortalException | SystemException e) {
LOG.debug("Organization does not exist.", e);
}
if (groupId == -1) {
LOG.info(String.format("Setup: Organization %1$s does not exist in system, creating...", organization.getName()));
Organization newOrganization = OrganizationLocalServiceUtil.addOrganization(SetupConfigurationThreadLocal.getRunAsUserId(), OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID, organization.getName(), "organization", 0, 0, ListTypeConstants.ORGANIZATION_STATUS_DEFAULT, "Created by setup module.", false, new ServiceContext());
addOrganizationUser(newOrganization, UserLocalServiceUtil.getUser(SetupConfigurationThreadLocal.getRunAsUserId()));
liferayOrg = newOrganization;
liferayGroup = liferayOrg.getGroup();
groupId = newOrganization.getGroupId();
LOG.info(String.format("New Organization created. Group ID: %1$s", groupId));
}
if (parentOrg != null && liferayOrg != null && organization.isMaintainOrganizationHierarchy()) {
liferayOrg.setParentOrganizationId(parentOrg.getOrganizationId());
OrganizationLocalServiceUtil.updateOrganization(liferayOrg);
} else if (liferayOrg != null && organization.isMaintainOrganizationHierarchy()) {
liferayOrg.setParentOrganizationId(0);
OrganizationLocalServiceUtil.updateOrganization(liferayOrg);
}
setCustomFields(groupId, organization, liferayOrg);
LOG.info("Organization custom fields set up.");
Site orgSite = organization.getSite();
if (orgSite == null) {
LOG.info("Organization has no site defined. All is set.");
} else if (orgSite.isDefault() || orgSite.getName() == null || orgSite.getName().isEmpty()) {
LOG.error("It is not possible to set global or default within organization. Skipping site setup.");
} else {
LOG.info("Setting up site for organization.");
liferayGroup.setSite(true);
liferayGroup.setName(orgSite.getName());
GroupLocalServiceUtil.updateGroup(liferayGroup);
liferayGroup = liferayOrg.getGroup();
if (liferayGroup != null && orgSite.getSiteFriendlyUrl() != null && !orgSite.getSiteFriendlyUrl().isEmpty()) {
liferayGroup.setFriendlyURL(orgSite.getSiteFriendlyUrl());
GroupLocalServiceUtil.updateGroup(liferayGroup);
liferayGroup = liferayOrg.getGroup();
}
if (parentGroup != null && liferayGroup != null && orgSite.isMaintainSiteHierarchy()) {
liferayGroup.setParentGroupId(parentGroup.getGroupId());
GroupLocalServiceUtil.updateGroup(liferayGroup);
} else if (liferayGroup != null && orgSite.isMaintainSiteHierarchy()) {
liferayGroup.setParentGroupId(0);
GroupLocalServiceUtil.updateGroup(liferayGroup);
}
SetupConfigurationThreadLocal.configureGroupExecutionContext(liferayGroup);
LOG.info("Setting organization site content...");
SetupDocumentFolders.setupDocumentFolders(orgSite, groupId);
LOG.info("Document Folders setting finished.");
SetupDocuments.setupSiteDocuments(orgSite, groupId);
LOG.info("Documents setting finished.");
SetupPages.setupSitePages(orgSite, groupId);
LOG.info("Organization Pages setting finished.");
SetupWebFolders.setupWebFolders(orgSite, groupId);
LOG.info("Web folders setting finished.");
SetupCategorization.setupVocabularies(orgSite.getVocabulary(), groupId);
LOG.info("Organization Categories setting finished.");
SetupArticles.setupSiteArticles(orgSite.getArticle(), orgSite.getAdt(), orgSite.getDdlRecordset(), groupId);
LOG.info("Organization Articles setting finished.");
SetupSites.setCustomFields(groupId, orgSite.getCustomFieldSetting());
LOG.info("Organization site custom fields set up.");
}
List<com.ableneo.liferay.portal.setup.domain.Organization> orgs = organization.getOrganization();
setupOrganizations(orgs, liferayOrg, liferayGroup);
} catch (Exception e) {
LOG.error(String.format("Error by setting up organization %1$s", organization.getName()), e);
}
}
}
use of com.ableneo.liferay.portal.setup.domain.Site in project liferay-db-setup-core by ableneo.
the class LiferaySetup method deleteObjects.
private static void deleteObjects(final List<ObjectsToBeDeleted> objectsToBeDeleted) {
for (ObjectsToBeDeleted otbd : objectsToBeDeleted) {
if (otbd.getRoles() != null) {
List<com.ableneo.liferay.portal.setup.domain.Role> roles = otbd.getRoles().getRole();
SetupRoles.deleteRoles(roles, otbd.getDeleteMethod());
}
if (otbd.getUsers() != null) {
List<com.ableneo.liferay.portal.setup.domain.User> users = otbd.getUsers().getUser();
SetupUsers.deleteUsers(users, otbd.getDeleteMethod());
}
if (otbd.getOrganizations() != null) {
List<Organization> organizations = otbd.getOrganizations().getOrganization();
SetupOrganizations.deleteOrganization(organizations, otbd.getDeleteMethod());
}
if (otbd.getCustomFields() != null) {
List<CustomFields.Field> customFields = otbd.getCustomFields().getField();
SetupCustomFields.deleteCustomFields(customFields, otbd.getDeleteMethod());
}
if (otbd.getSites() != null) {
final List<Site> siteList = otbd.getSites().getSite();
SetupSites.deleteSite(siteList, otbd.getDeleteMethod());
}
}
}
Aggregations