From 3ee8766d9d6989997b091e4fe75ff3762e980dfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kruszewski?= Date: Fri, 28 Jul 2017 16:13:25 +0200 Subject: [PATCH] Add company support (#9) * * support for multiple company/group configuration, compiles, tested with custom fields, not yet finished * added more documentation to xsd https://github.com/mimacom/liferay-db-setup-core/issues/2 * added hook scaffold to test most of the configuration https://github.com/mimacom/liferay-db-setup-core/issues/3 * * fixed wrong dependency * * fixed distributionManagement * * fixed documentation * fixed setup / reset of permission checker in thread local when setup is run with logged in user * fixed log information for portlet / resource permission setup * release commit --- README.md | 4 +- db-setup-core/pom.xml | 93 +++++++- .../liferay/portal/setup/LiferaySetup.java | 208 ++++++++++-------- ...rocess.java => LiferaySetupException.java} | 26 +-- .../portal/setup/core/SetupArticles.java | 81 +++---- .../setup/core/SetupCategorization.java | 26 +-- .../portal/setup/core/SetupCustomFields.java | 95 ++++---- .../setup/core/SetupDocumentFolders.java | 22 +- .../portal/setup/core/SetupDocuments.java | 11 +- .../portal/setup/core/SetupOrganizations.java | 18 +- .../liferay/portal/setup/core/SetupPages.java | 44 ++-- .../portal/setup/core/SetupPermissions.java | 77 +++---- .../liferay/portal/setup/core/SetupRoles.java | 19 +- .../portal/setup/core/SetupWebFolders.java | 22 +- .../core/util/CustomFieldSettingUtil.java | 2 +- .../portal/setup/core/util/FilePathUtil.java | 2 +- .../util/FileUtil.java} | 57 +---- .../setup/{ => core/util}/MarshallUtil.java | 6 +- .../portal/setup/core/util/ResolverUtil.java | 6 - .../liferay/portal/setup/package-info.java | 4 - ...ition-1.0.xsd => setup_definition-1.1.xsd} | 85 ++++++- db-setup-sample-hook/pom.xml | 99 +++++++++ .../src/main/resources/setup.xml | 47 ++++ .../src/main/webapp/WEB-INF/liferay-hook.xml | 6 + .../webapp/WEB-INF/liferay-plugin-package.xml | 42 ++++ .../src/main/webapp/WEB-INF/web.xml | 5 + pom.xml | 22 +- 27 files changed, 702 insertions(+), 427 deletions(-) rename db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/{SetupUpgradeProcess.java => LiferaySetupException.java} (73%) rename db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/{BasicSetupUpgradeProcess.java => core/util/FileUtil.java} (63%) rename db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/{ => core/util}/MarshallUtil.java (95%) delete mode 100644 db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/package-info.java rename db-setup-core/src/main/resources/{setup_definition-1.0.xsd => setup_definition-1.1.xsd} (85%) create mode 100644 db-setup-sample-hook/pom.xml create mode 100644 db-setup-sample-hook/src/main/resources/setup.xml create mode 100644 db-setup-sample-hook/src/main/webapp/WEB-INF/liferay-hook.xml create mode 100644 db-setup-sample-hook/src/main/webapp/WEB-INF/liferay-plugin-package.xml create mode 100644 db-setup-sample-hook/src/main/webapp/WEB-INF/web.xml diff --git a/README.md b/README.md index a09751f..4570db8 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ We didn't publish binary yet so you'll need to build the jar yourself. Here are com.mimacom.liferay db-setup-core - 1.0.0 + 1.1.0 ``` @@ -22,7 +22,7 @@ We didn't publish binary yet so you'll need to build the jar yourself. Here are Run com.mimacom.liferay.portal.setup.LiferaySetup#setup(java.io.File) with following xml configuration: ```xml - + test@liferay.com diff --git a/db-setup-core/pom.xml b/db-setup-core/pom.xml index e6327de..ff08609 100644 --- a/db-setup-core/pom.xml +++ b/db-setup-core/pom.xml @@ -3,8 +3,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + + com.mimacom.liferay + build-parent + 1.1.0 + com.mimacom.liferay - 1.0.1 + 1.1.0 db-setup-core Liferay Portal DB Setup core Library that allows to declare a set of Liferay data to be created and create them using the API. @@ -18,7 +23,6 @@ 1.7 1.13 3.0.2 - 6.2.5 3.0.1 2.10.4 @@ -39,13 +43,12 @@ ${project.build.directory}/generated-sources/sources - ${basedir}/src/main/resources/setup_definition-1.0.xsd + ${basedir}/src/main/resources/setup_definition-1.1.xsd com.mimacom.liferay.portal.setup.domain false - maven-compiler-plugin 2.5 @@ -55,7 +58,6 @@ ${java.version} - org.codehaus.mojo license-maven-plugin @@ -82,7 +84,6 @@ - org.apache.maven.plugins maven-resources-plugin @@ -156,11 +157,13 @@ test + scm:git:git://github.com/mimacom/liferay-db-setup-core.git scm:git:ssh://github.com:mimacom/liferay-db-setup-core.git https://github.com/mimacom/liferay-db-setup-core/tree/1.x + mimacom ag http://www.mimacom.com @@ -174,12 +177,88 @@ A business-friendly OSS license + + + Silvio Meier + silvio.meier@empa.ch + Empa + http://www.empa.ch + + + Ivan Greguric Ortolan + ivan.g.ortolan@mimacom.com + mimacom ag + http://www.mimacom.com + + + Gustav Novotny + gustav.novotny@mimacom.com + mimacom ag + http://www.mimacom.com + + + Ludovit Hajzer + ludovit.hajzer@mimacom.com + mimacom ag + http://www.mimacom.com + + + Marek Palenik + marek.palenik@mimacom.com + mimacom ag + http://www.mimacom.com + Pawel Kruszewski pawel.kruszewski@mimacom.com - mimacom + mimacom ag http://www.mimacom.com + + + + ossrh-distribution + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + ossrh + https://oss.sonatype.org/ + true + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.5 + + + sign-artifacts + verify + + sign + + + + + + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + diff --git a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/LiferaySetup.java b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/LiferaySetup.java index 9dc570b..1bccc89 100644 --- a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/LiferaySetup.java +++ b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/LiferaySetup.java @@ -12,10 +12,10 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -26,36 +26,28 @@ * #L% */ -import java.io.File; -import java.util.List; - -import com.mimacom.liferay.portal.setup.core.SetupOrganizations; -import com.mimacom.liferay.portal.setup.core.SetupPages; -import com.mimacom.liferay.portal.setup.core.SetupRoles; -import com.mimacom.liferay.portal.setup.core.SetupUsers; -import com.mimacom.liferay.portal.setup.domain.*; -import com.mimacom.liferay.portal.setup.core.SetupCustomFields; -import com.mimacom.liferay.portal.setup.core.SetupPermissions; -import com.mimacom.liferay.portal.setup.domain.Configuration; -import com.mimacom.liferay.portal.setup.domain.CustomFields; -import com.mimacom.liferay.portal.setup.domain.ObjectsToBeDeleted; -import com.mimacom.liferay.portal.setup.domain.Setup; - import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.exception.SystemException; import com.liferay.portal.kernel.log.Log; import com.liferay.portal.kernel.log.LogFactoryUtil; -import com.liferay.portal.model.Group; +import com.liferay.portal.model.GroupConstants; import com.liferay.portal.model.Role; import com.liferay.portal.model.User; import com.liferay.portal.security.auth.PrincipalThreadLocal; import com.liferay.portal.security.permission.PermissionChecker; import com.liferay.portal.security.permission.PermissionCheckerFactoryUtil; import com.liferay.portal.security.permission.PermissionThreadLocal; +import com.liferay.portal.service.CompanyLocalServiceUtil; import com.liferay.portal.service.GroupLocalServiceUtil; import com.liferay.portal.service.RoleLocalServiceUtil; import com.liferay.portal.service.UserLocalServiceUtil; import com.liferay.portal.util.PortalUtil; +import com.mimacom.liferay.portal.setup.core.*; +import com.mimacom.liferay.portal.setup.core.util.MarshallUtil; +import com.mimacom.liferay.portal.setup.domain.*; + +import java.io.File; +import java.util.List; public final class LiferaySetup { @@ -63,7 +55,6 @@ public final class LiferaySetup { private static final Log LOG = LogFactoryUtil.getLog(LiferaySetup.class); private static final String ADMIN_ROLE_NAME = "Administrator"; - private static long runAsUserId; private LiferaySetup() { } @@ -75,108 +66,138 @@ public static boolean setup(final File file) { public static boolean setup(final Setup setup) { - try { - Configuration configuration = setup.getConfiguration(); + Configuration configuration = setup.getConfiguration(); + String runAsUserEmail = configuration.getRunasuser(); + final String principalName = PrincipalThreadLocal.getName(); + final PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker(); - String runAsUser = configuration.getRunasuser(); - if (runAsUser == null || runAsUser.isEmpty()) { - setAdminPermissionCheckerForThread(PortalUtil.getDefaultCompanyId()); - LOG.info("Using default administrator."); + try { + // iterate over companies or choose default + if (!configuration.getCompany().isEmpty()) { + for (Company company : configuration.getCompany()) { + Long companyId = company.getCompanyid(); + String companyWebId = company.getCompanywebid(); + if (companyId == null) { + try { + companyId = CompanyLocalServiceUtil.getCompanyByWebId(companyWebId).getCompanyId(); + } catch (PortalException | SystemException e) { + LOG.error("Couldn't find company with webId: " + companyWebId); + continue; + } + } + long runAsUserId = configureThreadPermission(runAsUserEmail, companyId); + + setupPortalInstance(setup, companyId, runAsUserId); + + // iterate over group names or choose GUEST group for the company + if (!company.getGroupName().isEmpty()) { + for (String groupName : company.getGroupName()) { + long groupId = GroupLocalServiceUtil.getGroup(companyId, groupName).getGroupId(); + setupPortalGroup(setup, companyId, groupId, runAsUserId); + } + } else { + long groupId = GroupLocalServiceUtil.getGroup(companyId, GroupConstants.GUEST).getGroupId(); + setupPortalGroup(setup, companyId, groupId, runAsUserId); + } + } } else { - User user = UserLocalServiceUtil - .getUserByEmailAddress(PortalUtil.getDefaultCompanyId(), runAsUser); - runAsUserId = user.getUserId(); - PrincipalThreadLocal.setName(runAsUserId); - PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user, - true); - PermissionThreadLocal.setPermissionChecker(permissionChecker); - - LOG.info("Execute setup module as user " + setup.getConfiguration().getRunasuser()); - } - - setupPortal(setup); - return true; + long companyId = PortalUtil.getDefaultCompanyId(); + long runAsUserId = configureThreadPermission(runAsUserEmail, companyId); + setupPortalInstance(setup, companyId, runAsUserId); - } catch (Exception e) { - LOG.error("An error occured while executing the portal setup ", e); + long groupId = GroupLocalServiceUtil.getGroup(companyId, GroupConstants.GUEST).getGroupId(); + setupPortalGroup(setup, companyId, groupId, runAsUserId); + } + } catch (PortalException | SystemException | LiferaySetupException e) { + LOG.error("An error occured while executing the portal setup"); return false; - } finally { - PrincipalThreadLocal.setName(null); - PermissionThreadLocal.setPermissionChecker(null); + PrincipalThreadLocal.setName(principalName); + PermissionThreadLocal.setPermissionChecker(permissionChecker); } + return true; } - public static void setupPortal(final Setup setup) { - long defaultUserId = 0; - long companyId = PortalUtil.getDefaultCompanyId(); - try { - defaultUserId = UserLocalServiceUtil.getDefaultUserId(companyId); - } catch (PortalException e1) { - LOG.error("default user not found", e1); - } catch (SystemException e1) { - LOG.error("default user not found", e1); + private static long configureThreadPermission(String runAsUserEmail, long companyId) throws SystemException, PortalException, LiferaySetupException { + long runAsUserId; + if (runAsUserEmail == null || runAsUserEmail.isEmpty()) { + runAsUserId = UserLocalServiceUtil.getDefaultUserId(companyId); + setAdminPermissionCheckerForThread(companyId); + LOG.info("Using default administrator."); + } else { + User user = UserLocalServiceUtil + .getUserByEmailAddress(PortalUtil.getDefaultCompanyId(), runAsUserEmail); + runAsUserId = user.getUserId(); + PrincipalThreadLocal.setName(runAsUserId); + PermissionChecker permissionChecker; + try { + permissionChecker = PermissionCheckerFactoryUtil.create(user); + } catch (Exception e) { + throw new LiferaySetupException("An error occured while trying to create permissionchecker for user: " + runAsUserEmail, e); + } + PermissionThreadLocal.setPermissionChecker(permissionChecker); + + LOG.info("Execute setup module as user " + runAsUserEmail); } - long groupId = 0; - Group g; - try { - g = GroupLocalServiceUtil.getGroup(companyId, "Guest"); - groupId = g.getGroupId(); - } catch (PortalException e) { - LOG.error("Default site not found", e); - } catch (SystemException e) { - LOG.error("Default site not found", e); + return runAsUserId; + } + + private static void setupPortalGroup(Setup setup, long companyId, long groupId, long runAsUserId) { + if (setup.getUsers() != null) { + LOG.info("Setting up " + setup.getUsers().getUser().size() + " users"); + SetupUsers.setupUsers(setup.getUsers().getUser(), runAsUserId, groupId); + } + + if (setup.getPageTemplates() != null) { + SetupPages.setupPageTemplates(setup.getPageTemplates(), groupId, companyId, + runAsUserId, runAsUserId); } + LOG.info("Setup of portal groups finished"); + } + + private static void setupPortalInstance(final Setup setup, long companyId, long runAsUserId) { + if (setup.getDeleteLiferayObjects() != null) { LOG.info("Deleting : " + setup.getDeleteLiferayObjects().getObjectsToBeDeleted().size() + " objects"); - deleteObjects(setup.getDeleteLiferayObjects().getObjectsToBeDeleted()); + deleteObjects(setup.getDeleteLiferayObjects().getObjectsToBeDeleted(), companyId); } if (setup.getCustomFields() != null) { LOG.info("Setting up " + setup.getCustomFields().getField().size() + " custom fields"); - SetupCustomFields.setupExpandoFields(setup.getCustomFields().getField()); + SetupCustomFields.setupExpandoFields(setup.getCustomFields().getField(), companyId); } if (setup.getRoles() != null) { LOG.info("Setting up " + setup.getRoles().getRole().size() + " roles"); - SetupRoles.setupRoles(setup.getRoles().getRole()); + SetupRoles.setupRoles(setup.getRoles().getRole(), companyId); } if (setup.getPortletPermissions() != null) { - LOG.info("Setting up " + setup.getPortletPermissions().getPortlet().size() + " roles"); - SetupPermissions.setupPortletPermissions(setup.getPortletPermissions()); + LOG.info("Setting up " + setup.getPortletPermissions().getPortlet().size() + " portlet/model resource"); + SetupPermissions.setupPortletPermissions(setup.getPortletPermissions(), companyId); } if (setup.getOrganizations() != null) { LOG.info("Setting up " + setup.getOrganizations().getOrganization().size() + " " + "organizations"); SetupOrganizations.setupOrganizations(setup.getOrganizations().getOrganization(), null, - null); - } - - if (setup.getUsers() != null) { - LOG.info("Setting up " + setup.getUsers().getUser().size() + " users"); - SetupUsers.setupUsers(setup.getUsers().getUser(), defaultUserId, groupId); + null, runAsUserId); } - if (setup.getPageTemplates() != null) { - SetupPages.setupPageTemplates(setup.getPageTemplates(), groupId, companyId, - defaultUserId); - } - LOG.info("Setup finished"); + LOG.info("Setup of portal instances finished"); } - private static void deleteObjects(final List objectsToBeDeleted) { + private static void deleteObjects(final List objectsToBeDeleted, long companyId) { for (ObjectsToBeDeleted otbd : objectsToBeDeleted) { if (otbd.getRoles() != null) { List roles = otbd.getRoles() .getRole(); - SetupRoles.deleteRoles(roles, otbd.getDeleteMethod()); + SetupRoles.deleteRoles(roles, otbd.getDeleteMethod(), companyId); } if (otbd.getUsers() != null) { @@ -193,7 +214,7 @@ private static void deleteObjects(final List objectsToBeDele if (otbd.getCustomFields() != null) { List customFields = otbd.getCustomFields().getField(); - SetupCustomFields.deleteCustomFields(customFields, otbd.getDeleteMethod()); + SetupCustomFields.deleteCustomFields(customFields, otbd.getDeleteMethod(), companyId); } } } @@ -201,26 +222,24 @@ private static void deleteObjects(final List objectsToBeDele /** * Returns Liferay user, that has Administrator role assigned. * - * @param companyId - * company ID + * @param companyId company ID * @return Liferay {@link com.mimacom.liferay.portal.setup.domain.User} - * instance, if no user is found, returns null - * @throws Exception - * if cannot obtain permission checker + * instance, throws exception if no user is found + * @throws LiferaySetupException if cannot obtain permission checker or find any user with administration role */ - private static User getAdminUser(final long companyId) throws Exception { + private static User getAdminUser(final long companyId) throws LiferaySetupException { try { Role adminRole = RoleLocalServiceUtil.getRole(companyId, ADMIN_ROLE_NAME); List adminUsers = UserLocalServiceUtil.getRoleUsers(adminRole.getRoleId()); if (adminUsers == null || adminUsers.isEmpty()) { - return null; + throw new LiferaySetupException("Cannot find any admin with default administration role: " + ADMIN_ROLE_NAME + " in liferay instance with companyId: " + companyId); } return adminUsers.get(0); } catch (PortalException | SystemException e) { - throw new Exception("Cannot obtain Liferay role for role name: " + ADMIN_ROLE_NAME, e); + throw new LiferaySetupException("Cannot obtain Liferay role for role name: " + ADMIN_ROLE_NAME + " in liferay instance with companyId: " + companyId, e); } } @@ -228,12 +247,10 @@ private static User getAdminUser(final long companyId) throws Exception { * Initializes permission checker for Liferay Admin. Used to grant access to * custom fields. * - * @param companyId - * company ID - * @throws Exception - * if cannot set permission checker + * @param companyId company ID + * @throws LiferaySetupException if cannot set permission checker */ - private static void setAdminPermissionCheckerForThread(final long companyId) throws Exception { + private static void setAdminPermissionCheckerForThread(final long companyId) throws LiferaySetupException { User adminUser = getAdminUser(companyId); PrincipalThreadLocal.setName(adminUser.getUserId()); @@ -241,13 +258,10 @@ private static void setAdminPermissionCheckerForThread(final long companyId) thr try { permissionChecker = PermissionCheckerFactoryUtil.create(adminUser); } catch (Exception e) { - throw new Exception("Cannot obtain permission checker for Liferay Administrator user", + throw new LiferaySetupException("Cannot obtain permission checker for Liferay Administrator user", e); } PermissionThreadLocal.setPermissionChecker(permissionChecker); } - public static long getRunAsUserId() { - return runAsUserId; - } } diff --git a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/SetupUpgradeProcess.java b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/LiferaySetupException.java similarity index 73% rename from db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/SetupUpgradeProcess.java rename to db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/LiferaySetupException.java index ffe9007..f652bfe 100644 --- a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/SetupUpgradeProcess.java +++ b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/LiferaySetupException.java @@ -1,6 +1,6 @@ package com.mimacom.liferay.portal.setup; -/* +/*- * #%L * Liferay Portal DB Setup core * %% @@ -25,24 +25,12 @@ * THE SOFTWARE. * #L% */ - - -/** - * Basic class for upgrade process. - */ -public abstract class SetupUpgradeProcess extends BasicSetupUpgradeProcess { - - /** - * @return paths to setup xml files. - */ - protected final String[] getSetupFileNames() { - String[] retVal = new String[1]; - retVal[0] = getSetupFileName(); - return retVal; +public class LiferaySetupException extends Exception { + public LiferaySetupException(String message) { + super(message); } - /** - * @return path to setup xml file. - */ - protected abstract String getSetupFileName(); + public LiferaySetupException(String message, Throwable cause) { + super(message, cause); + } } diff --git a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupArticles.java b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupArticles.java index d915547..1d9f945 100644 --- a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupArticles.java +++ b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupArticles.java @@ -27,31 +27,6 @@ */ -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -import com.mimacom.liferay.portal.setup.LiferaySetup; -import com.mimacom.liferay.portal.setup.core.util.ResolverUtil; -import com.mimacom.liferay.portal.setup.core.util.TitleMapUtil; -import org.jboss.vfs.VirtualFile; -import com.mimacom.liferay.portal.setup.core.util.WebFolderUtil; -import com.mimacom.liferay.portal.setup.domain.Adt; -import com.mimacom.liferay.portal.setup.domain.Article; -import com.mimacom.liferay.portal.setup.domain.ArticleTemplate; -import com.mimacom.liferay.portal.setup.domain.DdlRecordset; -import com.mimacom.liferay.portal.setup.domain.Organization; -import com.mimacom.liferay.portal.setup.domain.RelatedAsset; -import com.mimacom.liferay.portal.setup.domain.RelatedAssets; -import com.mimacom.liferay.portal.setup.domain.Structure; - import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.exception.SystemException; import com.liferay.portal.kernel.log.Log; @@ -83,6 +58,18 @@ import com.liferay.portlet.journal.model.JournalArticleConstants; import com.liferay.portlet.journal.model.JournalFolder; import com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil; +import com.mimacom.liferay.portal.setup.core.util.ResolverUtil; +import com.mimacom.liferay.portal.setup.core.util.TitleMapUtil; +import com.mimacom.liferay.portal.setup.core.util.WebFolderUtil; +import com.mimacom.liferay.portal.setup.domain.*; +import org.jboss.vfs.VirtualFile; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.*; /** * Created by mapa, guno.. @@ -123,14 +110,14 @@ private SetupArticles() { } public static void setupOrganizationArticles(final Organization organization, - final long groupId, final long companyId) throws PortalException, SystemException { + final long groupId, final long companyId, long runAsUserId) throws PortalException, SystemException { List articleStructures = organization.getArticleStructure(); if (articleStructures != null) { long classNameId = ClassNameLocalServiceUtil.getClassNameId(JournalArticle.class); for (Structure structure : articleStructures) { try { - addDDMStructure(structure, groupId, classNameId); + addDDMStructure(structure, groupId, classNameId, runAsUserId); } catch (StructureDuplicateStructureKeyException | IOException | URISyntaxException e) { LOG.error(e); @@ -145,7 +132,7 @@ public static void setupOrganizationArticles(final Organization organization, for (Structure structure : ddlStructures) { LOG.info("Adding DDL structure " + structure.getName()); try { - addDDMStructure(structure, groupId, classNameId); + addDDMStructure(structure, groupId, classNameId, runAsUserId); } catch (StructureDuplicateStructureKeyException | IOException | URISyntaxException e) { LOG.error(e); @@ -157,7 +144,7 @@ public static void setupOrganizationArticles(final Organization organization, if (articleTemplates != null) { for (ArticleTemplate template : articleTemplates) { try { - addDDMTemplate(template, groupId); + addDDMTemplate(template, groupId, runAsUserId); } catch (TemplateDuplicateTemplateKeyException | IOException | URISyntaxException e) { LOG.error(e); @@ -167,14 +154,14 @@ public static void setupOrganizationArticles(final Organization organization, List
articles = organization.getArticle(); if (articles != null) { for (Article article : articles) { - addJournalArticle(article, groupId, companyId); + addJournalArticle(article, groupId, companyId, runAsUserId); } } List adts = organization.getAdt(); if (adts != null) { for (Adt template : adts) { try { - addDDMTemplate(template, groupId); + addDDMTemplate(template, groupId, runAsUserId); } catch (TemplateDuplicateTemplateKeyException | URISyntaxException | IOException e) { LOG.error("Error in adding ADT: " + template.getName(), e); @@ -185,7 +172,7 @@ public static void setupOrganizationArticles(final Organization organization, if (recordSets != null) { for (DdlRecordset recordSet : recordSets) { try { - addDDLRecordSet(recordSet, groupId); + addDDLRecordSet(recordSet, groupId, runAsUserId); } catch (TemplateDuplicateTemplateKeyException e) { LOG.error("Error in adding DDLRecordSet: " + recordSet.getName(), e); } @@ -194,8 +181,8 @@ public static void setupOrganizationArticles(final Organization organization, } public static void addDDMStructure(final Structure structure, final long groupId, - final long classNameId) - throws SystemException, PortalException, IOException, URISyntaxException { + final long classNameId, long runAsUserId) + throws SystemException, PortalException, IOException, URISyntaxException { LOG.info("Adding Article structure " + structure.getName()); Map nameMap = new HashMap<>(); @@ -240,7 +227,7 @@ public static void addDDMStructure(final Structure structure, final long groupId } DDMStructure newStructure = DDMStructureLocalServiceUtil.addStructure( - LiferaySetup.getRunAsUserId(), groupId, structure.getParent(), classNameId, + runAsUserId, groupId, structure.getParent(), classNameId, structure.getKey(), nameMap, descMap, xsd, "xml", 0, new ServiceContext()); LOG.info("Added Article structure: " + newStructure.getName()); } @@ -252,7 +239,7 @@ private static String getStructureNameOrKey(final Structure structure) { return structure.getKey(); } - public static void addDDMTemplate(final ArticleTemplate template, final long groupId) + public static void addDDMTemplate(final ArticleTemplate template, final long groupId, long runAsUserId) throws SystemException, PortalException, IOException, URISyntaxException { LOG.info("Adding Article template " + template.getName()); @@ -301,13 +288,13 @@ public static void addDDMTemplate(final ArticleTemplate template, final long gro } DDMTemplate newTemplate = DDMTemplateLocalServiceUtil.addTemplate( - LiferaySetup.getRunAsUserId(), groupId, classNameId, classPK, template.getKey(), + runAsUserId, groupId, classNameId, classPK, template.getKey(), nameMap, descMap, "display", null, template.getLanguage(), script, true, false, null, null, new ServiceContext()); LOG.info("Added Article template: " + newTemplate.getName()); } - public static void addDDMTemplate(final Adt template, final long groupId) + public static void addDDMTemplate(final Adt template, final long groupId, long runAsUserId) throws SystemException, PortalException, IOException, URISyntaxException { LOG.info("Adding ADT " + template.getName()); @@ -355,7 +342,7 @@ public static void addDDMTemplate(final Adt template, final long groupId) String script = getFileContent(template.getPath()); DDMTemplate newTemplate = DDMTemplateLocalServiceUtil.addTemplate( - LiferaySetup.getRunAsUserId(), groupId, classNameId, 0, template.getTemplateKey(), + runAsUserId, groupId, classNameId, 0, template.getTemplateKey(), nameMap, descriptionMap, DDMTemplateConstants.TEMPLATE_TYPE_DISPLAY, null, template.getLanguage(), script, template.isCacheable(), false, null, null, new ServiceContext()); @@ -363,14 +350,14 @@ public static void addDDMTemplate(final Adt template, final long groupId) } public static void addJournalArticle(final Article article, final long groupId, - final long companyId) { + final long companyId, long runAsUserId) { LOG.info("Adding Journal Article " + article.getTitle()); String content = null; long folderId = 0L; if (article.getArticleFolderPath() != null && !article.getArticleFolderPath().equals("")) { JournalFolder jf = WebFolderUtil.findWebFolder(companyId, groupId, - LiferaySetup.getRunAsUserId(), article.getArticleFolderPath(), "", true); + runAsUserId, article.getArticleFolderPath(), "", true); if (jf == null) { LOG.warn("Specified webfolder " + article.getArticleFolderPath() + " of article " + article.getTitle() @@ -381,7 +368,7 @@ public static void addJournalArticle(final Article article, final long groupId, } try { content = getFileContent(article.getPath()); - content = ResolverUtil.lookupAll(LiferaySetup.getRunAsUserId(), groupId, companyId, + content = ResolverUtil.lookupAll(runAsUserId, groupId, companyId, content, article.getPath()); } catch (IOException | URISyntaxException e) { LOG.error( @@ -411,7 +398,7 @@ public static void addJournalArticle(final Article article, final long groupId, try { if (journalArticle == null) { journalArticle = JournalArticleLocalServiceUtil.addArticle( - LiferaySetup.getRunAsUserId(), groupId, folderId, 0, 0, + runAsUserId, groupId, folderId, 0, 0, article.getArticleId(), generatedId, JournalArticleConstants.VERSION_DEFAULT, titleMap, null, content, "general", article.getArticleStructureKey(), article.getArticleTemplateKey(), @@ -440,7 +427,7 @@ public static void addJournalArticle(final Article article, final long groupId, } LOG.info("Updated JournalArticle: " + journalArticle.getTitle()); } - processRelatedAssets(article, journalArticle, LiferaySetup.getRunAsUserId(), groupId, + processRelatedAssets(article, journalArticle, runAsUserId, groupId, companyId); SetupPermissions.updatePermission("Article " + journalArticle.getArticleId(), groupId, companyId, journalArticle.getResourcePrimKey(), JournalArticle.class, @@ -451,7 +438,7 @@ public static void addJournalArticle(final Article article, final long groupId, } } - private static void addDDLRecordSet(final DdlRecordset recordSet, final long groupId) + private static void addDDLRecordSet(final DdlRecordset recordSet, final long groupId, long runAsUserId) throws SystemException, PortalException { LOG.info("Adding DDLRecordSet " + recordSet.getName()); Map nameMap = new HashMap<>(); @@ -478,7 +465,7 @@ private static void addDDLRecordSet(final DdlRecordset recordSet, final long gro } DDLRecordSet newDDLRecordSet = DDLRecordSetLocalServiceUtil.addRecordSet( - LiferaySetup.getRunAsUserId(), groupId, + runAsUserId, groupId, ResolverUtil.getStructureId(recordSet.getDdlStructureKey(), groupId, DDLRecordSet.class), recordSet.getDdlStructureKey(), nameMap, descMap, MIN_DISPLAY_ROWS, 0, @@ -487,7 +474,7 @@ private static void addDDLRecordSet(final DdlRecordset recordSet, final long gro } public static void processRelatedAssets(final Article article, final JournalArticle ja, - final long runAsUserId, final long groupId, final long companyId) { + final long runAsUserId, final long groupId, final long companyId) { if (article.getRelatedAssets() != null) { RelatedAssets ras = article.getRelatedAssets(); AssetEntry ae = null; diff --git a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupCategorization.java b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupCategorization.java index 51a014d..65514cb 100644 --- a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupCategorization.java +++ b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupCategorization.java @@ -31,7 +31,6 @@ import java.util.Map; import com.mimacom.liferay.portal.setup.domain.Category; -import com.mimacom.liferay.portal.setup.LiferaySetup; import com.mimacom.liferay.portal.setup.domain.Organization; import com.mimacom.liferay.portal.setup.domain.Vocabulary; @@ -60,7 +59,7 @@ private SetupCategorization() { } - public static void setupVocabularies(final Organization organization, final long groupId) + public static void setupVocabularies(final Organization organization, final long groupId, long runAsUserId) throws SystemException, PortalException { List vocabularies = organization.getVocabulary(); @@ -69,12 +68,11 @@ public static void setupVocabularies(final Organization organization, final long LOG.info("Setting up vocabularies"); for (Vocabulary vocabulary : vocabularies) { - setupVocabulary(vocabulary, organization, groupId, siteDefaultLocale); + setupVocabulary(vocabulary, groupId, siteDefaultLocale, runAsUserId); } } - private static void setupVocabulary(final Vocabulary vocabulary, - final Organization organization, final long groupId, final Locale defaultLocale) { + private static void setupVocabulary(final Vocabulary vocabulary, final long groupId, final Locale defaultLocale, long runAsUserId) { LOG.info("Setting up vocabulary with title: " + vocabulary.getTitle()); @@ -107,7 +105,7 @@ private static void setupVocabulary(final Vocabulary vocabulary, } setupCategories(assetVocabulary.getVocabularyId(), groupId, 0L, - vocabulary.getCategory(), defaultLocale); + vocabulary.getCategory(), defaultLocale, runAsUserId); return; } @@ -116,11 +114,11 @@ private static void setupVocabulary(final Vocabulary vocabulary, serviceContext.setCompanyId(PortalUtil.getDefaultCompanyId()); serviceContext.setScopeGroupId(groupId); assetVocabulary = AssetVocabularyLocalServiceUtil.addVocabulary( - LiferaySetup.getRunAsUserId(), null, titleMap, descMap, null, serviceContext); + runAsUserId, null, titleMap, descMap, null, serviceContext); LOG.info("AssetVocabulary successfuly added. ID:" + assetVocabulary.getVocabularyId() + ", group:" + assetVocabulary.getGroupId()); setupCategories(assetVocabulary.getVocabularyId(), groupId, 0L, - vocabulary.getCategory(), defaultLocale); + vocabulary.getCategory(), defaultLocale, runAsUserId); } catch (PortalException | SystemException | NullPointerException e) { LOG.error("Error while trying to create vocabulary with title: " + assetVocabulary.getTitle(), e); @@ -128,18 +126,18 @@ private static void setupVocabulary(final Vocabulary vocabulary, } private static void setupCategories(final long vocabularyId, final long groupId, - final long parentId, final List categories, final Locale defaultLocale) { + final long parentId, final List categories, final Locale defaultLocale, long runAsUserId) { LOG.info("Setting up categories for parentId:" + parentId); if (categories != null && !categories.isEmpty()) { for (Category category : categories) { - setupCategory(category, vocabularyId, groupId, defaultLocale, parentId); + setupCategory(category, vocabularyId, groupId, defaultLocale, parentId, runAsUserId); } } } private static void setupCategory(final Category category, final long vocabularyId, - final long groupId, final Locale defaultLocale, final long parentCategoryId) { + final long groupId, final Locale defaultLocale, final long parentCategoryId, long runAsUserId) { LOG.info("Setting up category with title:" + category.getTitle()); @@ -185,17 +183,17 @@ private static void setupCategory(final Category category, final long vocabulary } setupCategories(vocabularyId, groupId, assetCategory.getCategoryId(), - category.getCategory(), defaultLocale); + category.getCategory(), defaultLocale, runAsUserId); return; } try { - assetCategory = AssetCategoryLocalServiceUtil.addCategory(LiferaySetup.getRunAsUserId(), + assetCategory = AssetCategoryLocalServiceUtil.addCategory(runAsUserId, parentCategoryId, titleMap, descMap, vocabularyId, null, serviceContext); LOG.info("Category successfully added with title: " + assetCategory.getTitle()); setupCategories(vocabularyId, groupId, assetCategory.getCategoryId(), - category.getCategory(), defaultLocale); + category.getCategory(), defaultLocale, runAsUserId); } catch (PortalException | SystemException e) { LOG.error("Error in creating category with title: " + category.getTitle(), e); diff --git a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupCustomFields.java b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupCustomFields.java index e6d2191..ffb4b0c 100644 --- a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupCustomFields.java +++ b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupCustomFields.java @@ -26,19 +26,6 @@ * #L% */ -import java.io.Serializable; -import java.text.DateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.SortedSet; -import java.util.TreeSet; - -import com.mimacom.liferay.portal.setup.domain.CustomFields; -import com.mimacom.liferay.portal.setup.domain.RolePermission; - import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.exception.SystemException; import com.liferay.portal.kernel.log.Log; @@ -47,54 +34,54 @@ import com.liferay.portal.kernel.util.GetterUtil; import com.liferay.portal.kernel.util.StringUtil; import com.liferay.portal.kernel.util.UnicodeProperties; -import com.liferay.portal.util.PortalUtil; -import com.liferay.portlet.expando.model.ExpandoBridge; -import com.liferay.portlet.expando.model.ExpandoColumn; -import com.liferay.portlet.expando.model.ExpandoColumnConstants; -import com.liferay.portlet.expando.model.ExpandoTable; -import com.liferay.portlet.expando.model.ExpandoTableConstants; +import com.liferay.portlet.expando.model.*; import com.liferay.portlet.expando.service.ExpandoColumnLocalServiceUtil; import com.liferay.portlet.expando.service.ExpandoTableLocalServiceUtil; import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil; +import com.mimacom.liferay.portal.setup.domain.CustomFields; +import com.mimacom.liferay.portal.setup.domain.RolePermission; + +import java.io.Serializable; +import java.text.DateFormat; +import java.util.*; public final class SetupCustomFields { private static final Log LOG = LogFactoryUtil.getLog(SetupCustomFields.class); - private static final long COMPANY_ID = PortalUtil.getDefaultCompanyId(); private SetupCustomFields() { } - public static void setupExpandoFields(final List fields) { + public static void setupExpandoFields(final List fields, long companyId) { for (CustomFields.Field field : fields) { String className = field.getClassName(); LOG.info("Add field " + field.getName() + "(" + className + ") to expando bridge"); - ExpandoBridge bridge = ExpandoBridgeFactoryUtil.getExpandoBridge(COMPANY_ID, className); - addAttributeToExpandoBridge(bridge, field); + ExpandoBridge bridge = ExpandoBridgeFactoryUtil.getExpandoBridge(companyId, className); + addAttributeToExpandoBridge(bridge, field, companyId); } } /** * @return all expandos with types specified in the "excludeListed" List to - * avoid deleting all expandos in the portal! + * avoid deleting all expandos in the portal! */ private static List getAllExpandoColumns( - final List customFields) { + final List customFields, long companyId) { List all = new ArrayList<>(); SortedSet tables = new TreeSet<>(); for (CustomFields.Field field : customFields) { ExpandoTable table; try { - table = ExpandoTableLocalServiceUtil.getDefaultTable(COMPANY_ID, + table = ExpandoTableLocalServiceUtil.getDefaultTable(companyId, field.getClassName()); if (table != null && !tables.contains(table.getName())) { tables.add(table.getName()); List columns = ExpandoColumnLocalServiceUtil - .getColumns(COMPANY_ID, field.getClassName(), table.getName()); + .getColumns(companyId, field.getClassName(), table.getName()); all.addAll(columns); } } catch (PortalException | SystemException e) { @@ -105,13 +92,13 @@ private static List getAllExpandoColumns( } private static void addAttributeToExpandoBridge(final ExpandoBridge bridge, - final CustomFields.Field field) { + final CustomFields.Field field, long companyId) { String name = field.getName(); try { int fieldTypeKey = getFieldTypeKey(field.getType()); if (bridge.hasAttribute(name)) { - ExpandoColumn column = ExpandoColumnLocalServiceUtil.getColumn(COMPANY_ID, + ExpandoColumn column = ExpandoColumnLocalServiceUtil.getColumn(companyId, bridge.getClassName(), ExpandoTableConstants.DEFAULT_TABLE_NAME, name); ExpandoColumnLocalServiceUtil.updateColumn(column.getColumnId(), name, fieldTypeKey, getAttributeFromString(fieldTypeKey, field.getDefaultData())); @@ -125,40 +112,40 @@ private static void addAttributeToExpandoBridge(final ExpandoBridge bridge, properties.setProperty(ExpandoColumnConstants.PROPERTY_DISPLAY_TYPE, getDisplayType(field.getDisplayType())); bridge.setAttributeProperties(name, properties); - setCustomFieldPermission(field.getRolePermission(), bridge, name); + setCustomFieldPermission(field.getRolePermission(), bridge, name, companyId); } catch (PortalException | SystemException e) { LOG.error("Could not set custom attribute: " + name, e); } } private static void setCustomFieldPermission(final List rolePermissions, - final ExpandoBridge bridge, final String fieldName) throws SystemException { + final ExpandoBridge bridge, final String fieldName, long companyId) throws SystemException { LOG.info("Set read permissions on field " + fieldName + " for " + rolePermissions.size() + " rolePermissions"); - ExpandoColumn column = ExpandoColumnLocalServiceUtil.getColumn(COMPANY_ID, + ExpandoColumn column = ExpandoColumnLocalServiceUtil.getColumn(companyId, bridge.getClassName(), ExpandoTableConstants.DEFAULT_TABLE_NAME, fieldName); for (RolePermission rolePermission : rolePermissions) { String roleName = rolePermission.getRoleName(); String permission = rolePermission.getPermission(); try { switch (permission) { - case "update": - SetupPermissions.addReadWrightRight(roleName, ExpandoColumn.class.getName(), - String.valueOf(column.getColumnId())); - LOG.info("Added update permission on field " + fieldName + " for role " - + roleName); - break; - case "view": - SetupPermissions.addReadRight(roleName, ExpandoColumn.class.getName(), - String.valueOf(column.getColumnId())); - LOG.info("Added read permission on field " + fieldName + " for role " - + roleName); - break; - default: - LOG.info("Unknown permission:" + permission + ". No permission added on " - + "field " + fieldName + " for role " + roleName); - break; + case "update": + SetupPermissions.addReadWrightRight(roleName, ExpandoColumn.class.getName(), + String.valueOf(column.getColumnId()), companyId); + LOG.info("Added update permission on field " + fieldName + " for role " + + roleName); + break; + case "view": + SetupPermissions.addReadRight(roleName, ExpandoColumn.class.getName(), + String.valueOf(column.getColumnId()), companyId); + LOG.info("Added read permission on field " + fieldName + " for role " + + roleName); + break; + default: + LOG.info("Unknown permission:" + permission + ". No permission added on " + + "field " + fieldName + " for role " + roleName); + break; } } catch (PortalException e) { @@ -168,17 +155,17 @@ private static void setCustomFieldPermission(final List rolePerm } public static void deleteCustomField(final CustomFields.Field customField, - final String deleteMethod) { - deleteCustomFields(Arrays.asList(customField), deleteMethod); + final String deleteMethod, long companyId) { + deleteCustomFields(Arrays.asList(customField), deleteMethod, companyId); } public static void deleteCustomFields(final List customFields, - final String deleteMethod) { + final String deleteMethod, long companyId) { if ("excludeListed".equals(deleteMethod)) { // delete all (from types in the list) but listed List skipFields = attributeNamesList(customFields); - List expandoColumns = getAllExpandoColumns(customFields); + List expandoColumns = getAllExpandoColumns(customFields, companyId); if (expandoColumns != null) { for (ExpandoColumn expandoColumn : expandoColumns) { if (!skipFields.contains(expandoColumn.getName())) { @@ -193,9 +180,9 @@ public static void deleteCustomFields(final List customField } else if (deleteMethod.equals("onlyListed")) { for (CustomFields.Field field : customFields) { try { - ExpandoTable table = ExpandoTableLocalServiceUtil.getDefaultTable(COMPANY_ID, + ExpandoTable table = ExpandoTableLocalServiceUtil.getDefaultTable(companyId, field.getClassName()); - ExpandoColumnLocalServiceUtil.deleteColumn(COMPANY_ID, field.getClassName(), + ExpandoColumnLocalServiceUtil.deleteColumn(companyId, field.getClassName(), table.getName(), field.getName()); } catch (PortalException | SystemException e) { LOG.error("Could not delete Custom Field " + field.getName(), e); diff --git a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupDocumentFolders.java b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupDocumentFolders.java index d5dc29b..52c86a2 100644 --- a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupDocumentFolders.java +++ b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupDocumentFolders.java @@ -27,19 +27,17 @@ */ -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import com.mimacom.liferay.portal.setup.LiferaySetup; -import com.mimacom.liferay.portal.setup.core.util.FolderUtil; -import com.mimacom.liferay.portal.setup.domain.DocumentFolder; -import com.mimacom.liferay.portal.setup.domain.Organization; - import com.liferay.portal.kernel.repository.model.Folder; import com.liferay.portal.model.RoleConstants; import com.liferay.portal.security.permission.ActionKeys; import com.liferay.portlet.documentlibrary.model.DLFolder; +import com.mimacom.liferay.portal.setup.core.util.FolderUtil; +import com.mimacom.liferay.portal.setup.domain.DocumentFolder; +import com.mimacom.liferay.portal.setup.domain.Organization; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; public final class SetupDocumentFolders { public static final HashMap> DEFAULT_PERMISSIONS; @@ -73,14 +71,14 @@ private SetupDocumentFolders() { } public static void setupDocumentFolders( - final Organization org, final long groupId, - final long companyId) { + final Organization org, final long groupId, + final long companyId, long runAsUserId) { for (DocumentFolder df : org.getDocumentFolder()) { boolean create = df.isCreateIfNotExists(); String folderName = df.getFolderName(); Folder folder = FolderUtil.findFolder(companyId, groupId, groupId, - LiferaySetup.getRunAsUserId(), folderName, create); + runAsUserId, folderName, create); SetupPermissions.updatePermission("Document folder " + folderName, groupId, companyId, folder.getFolderId(), DLFolder.class, df.getRolePermissions(), DEFAULT_PERMISSIONS); diff --git a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupDocuments.java b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupDocuments.java index a9baa12..fe6b849 100644 --- a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupDocuments.java +++ b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupDocuments.java @@ -83,7 +83,7 @@ private SetupDocuments() { } public static void setupOrganizationDocuments(final Organization organization, - final long groupId, final long company) { + final long groupId, final long company, long runAsUserId) { for (Document doc : organization.getDocument()) { String folderPath = doc.getDocumentFolderName(); String documentName = doc.getDocumentFilename(); @@ -91,23 +91,22 @@ public static void setupOrganizationDocuments(final Organization organization, String extension = doc.getExtension(); String filenameInFilesystem = doc.getFileSystemName(); long repoId = groupId; - long userId = LiferaySetup.getRunAsUserId(); Long folderId = 0L; Folder f = null; if (folderPath != null && !folderPath.equals("")) { - f = FolderUtil.findFolder(company, groupId, repoId, userId, folderPath, true); + f = FolderUtil.findFolder(company, groupId, repoId, runAsUserId, folderPath, true); folderId = f.getFolderId(); } FileEntry fe = DocumentUtil.findDocument(documentName, folderPath, groupId, company, - groupId, userId); + groupId, runAsUserId); if (fe == null) { fe = DocumentUtil.createDocument(company, groupId, folderId, documentName, - documentTitle, userId, repoId, getDocumentContent(filenameInFilesystem)); + documentTitle, runAsUserId, repoId, getDocumentContent(filenameInFilesystem)); LOG.info(documentName + " is not found! It will be created! "); } else { LOG.info(documentName + " is found! Content will be updated! "); - DocumentUtil.updateFile(fe, getDocumentContent(filenameInFilesystem), userId, + DocumentUtil.updateFile(fe, getDocumentContent(filenameInFilesystem), runAsUserId, documentName); } SetupPermissions.updatePermission("Document " + folderPath + "/" + documentName, diff --git a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupOrganizations.java b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupOrganizations.java index 2615aef..a2bfc6c 100644 --- a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupOrganizations.java +++ b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupOrganizations.java @@ -60,7 +60,7 @@ private SetupOrganizations() { public static void setupOrganizations( final List organizations, - final Organization parentOrg, final Group parentGroup) { + final Organization parentOrg, final Group parentGroup, long runAsUserId) { for (com.mimacom.liferay.portal.setup.domain.Organization organization : organizations) { try { @@ -141,32 +141,32 @@ public static void setupOrganizations( LOG.info("Setting organization content..."); - SetupDocumentFolders.setupDocumentFolders(organization, groupId, COMPANY_ID); + SetupDocumentFolders.setupDocumentFolders(organization, groupId, COMPANY_ID, runAsUserId); LOG.info("Document Folders setting finished."); - SetupDocuments.setupOrganizationDocuments(organization, groupId, COMPANY_ID); + SetupDocuments.setupOrganizationDocuments(organization, groupId, COMPANY_ID, runAsUserId); LOG.info("Documents setting finished."); SetupPages.setupOrganizationPages(organization, groupId, COMPANY_ID, - LiferaySetup.getRunAsUserId()); + runAsUserId, runAsUserId); LOG.info("Organization Pages setting finished."); - SetupWebFolders.setupWebFolders(organization, groupId, COMPANY_ID); + SetupWebFolders.setupWebFolders(organization, groupId, COMPANY_ID, runAsUserId); LOG.info("Web folders setting finished."); - SetupCategorization.setupVocabularies(organization, groupId); + SetupCategorization.setupVocabularies(organization, groupId, runAsUserId); LOG.info("Organization Categories setting finished."); - SetupArticles.setupOrganizationArticles(organization, groupId, COMPANY_ID); + SetupArticles.setupOrganizationArticles(organization, groupId, COMPANY_ID, runAsUserId); LOG.info("Organization Articles setting finished."); - setCustomFields(LiferaySetup.getRunAsUserId(), groupId, COMPANY_ID, organization, + setCustomFields(runAsUserId, groupId, COMPANY_ID, organization, liferayOrg); LOG.info("Organization custom fields set up."); List orgs = organization .getOrganization(); - setupOrganizations(orgs, liferayOrg, liferayGroup); + setupOrganizations(orgs, liferayOrg, liferayGroup, runAsUserId); } catch (Exception e) { LOG.error("Error by setting up organization " + organization.getName(), e); diff --git a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupPages.java b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupPages.java index c4ce9af..09061bd 100644 --- a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupPages.java +++ b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupPages.java @@ -133,11 +133,12 @@ private SetupPages() { * @param groupId liferay site scope * @param company liferay instance scope * @param userid run as user + * @param runAsUserId * @throws SystemException * @throws PortalException */ public static void setupOrganizationPages(final Organization organization, final long groupId, - final long company, final long userid) throws SystemException, PortalException { + final long company, final long userid, long runAsUserId) throws SystemException, PortalException { PublicPages publicPages = organization.getPublicPages(); if (publicPages != null) { @@ -148,7 +149,7 @@ public static void setupOrganizationPages(final Organization organization, final LOG.info("Setup: Deleting pages from organization " + organization.getName()); deletePages(groupId); } - addPages(publicPages.getPage(), groupId, false, 0, company, userid); + addPages(publicPages.getPage(), groupId, false, 0, company, userid, runAsUserId); } PrivatePages privatePages = organization.getPrivatePages(); @@ -161,24 +162,23 @@ public static void setupOrganizationPages(final Organization organization, final deletePages(groupId); } - addPages(privatePages.getPage(), groupId, true, 0, company, userid); + addPages(privatePages.getPage(), groupId, true, 0, company, userid, runAsUserId); } } /** * Set the page templates up. As this is heavily based on page (layout). - * - * @param pageTemplates + * @param pageTemplates * The page template definitions that are imported. * @param groupId * The group id of the site where to import the * @param company - * The id of the company to which the templates are imported. + * The id of the company to which the templates are imported. * @param userid - * The user id of the importing user. + * @param runAsUserId */ public static void setupPageTemplates(final PageTemplates pageTemplates, final long groupId, - final long company, final long userid) { + final long company, final long userid, long runAsUserId) { try { for (PageTemplate pageTemplate : pageTemplates.getPageTemplate()) { String name = pageTemplate.getName(); @@ -207,7 +207,7 @@ public static void setupPageTemplates(final PageTemplates pageTemplates, final l LOG.error("The page of page template " + name + " may not have a " + "friendly URL! Will ignore it!"); } - setupLiferayPage(layout, page, groupId, false, company, userid, name); + setupLiferayPage(layout, page, groupId, false, company, userid, name, runAsUserId); } } else { LOG.error("Could not create or find the page template " + name); @@ -247,12 +247,13 @@ private static void setupTheme(final long groupId, final Theme theme, final bool * @param parentLayoutId layout id of parent page * @param company Liferay instance scope * @param userId run as user + * @param runAsUserId * @throws SystemException * @throws PortalException */ private static void addPages(final List pages, final long groupId, - final boolean isPrivate, final long parentLayoutId, final long company, - final long userId) throws SystemException, PortalException { + final boolean isPrivate, final long parentLayoutId, final long company, + final long userId, long runAsUserId) throws SystemException, PortalException { for (Page page : pages) { @@ -264,7 +265,7 @@ private static void addPages(final List pages, final long groupId, if (layout != null && page.isDeleteExistingPages()) { LayoutLocalServiceUtil.deleteLayout(layout); if (page.getLinkToURL() == null || page.getLinkToURL().equals("")) { - layout = createPage(groupId, page, parentLayoutId, isPrivate); + layout = createPage(groupId, page, parentLayoutId, isPrivate, runAsUserId); } else { layout = createLinkPage(page, groupId, parentLayoutId, userId); } @@ -274,7 +275,7 @@ private static void addPages(final List pages, final long groupId, } } catch (NoSuchLayoutException e) { if (page.getLinkToURL() == null || page.getLinkToURL().equals("")) { - layout = createPage(groupId, page, parentLayoutId, isPrivate); + layout = createPage(groupId, page, parentLayoutId, isPrivate, runAsUserId); } else { layout = createLinkPage(page, groupId, parentLayoutId, userId); } @@ -282,13 +283,13 @@ private static void addPages(final List pages, final long groupId, } catch (Exception ex) { LOG.error(ex); } - setupLiferayPage(layout, page, groupId, isPrivate, company, userId, null); + setupLiferayPage(layout, page, groupId, isPrivate, company, userId, null, runAsUserId); } } private static void setupLiferayPage(final Layout layout, final Page page, final long groupId, - final boolean isPrivate, final long company, final long userId, - final String pageTemplateName) throws SystemException, PortalException { + final boolean isPrivate, final long company, final long userId, + final String pageTemplateName, long runAsUserId) throws SystemException, PortalException { if (page.getTheme() != null) { setPageTheme(layout, page); } @@ -300,7 +301,7 @@ private static void setupLiferayPage(final Layout layout, final Page page, final if (portlets != null && !portlets.isEmpty()) { for (Pageportlet portlet : portlets) { try { - addPortletIntoPage(page, layout, portlet, company, groupId); + addPortletIntoPage(page, layout, portlet, company, groupId, runAsUserId); } catch (ValidatorException | IOException e) { LOG.error(e); @@ -314,7 +315,7 @@ private static void setupLiferayPage(final Layout layout, final Page page, final LOG.error("Page template " + pageTemplateName + " may not have any sub-pages! " + "Will ignore them!"); } else { - addPages(subPages, groupId, isPrivate, layout.getLayoutId(), company, userId); + addPages(subPages, groupId, isPrivate, layout.getLayoutId(), company, userId, runAsUserId); } } @@ -427,7 +428,7 @@ private static void setPageTheme(final Layout layout, final Page page) throws Sy } private static void addPortletIntoPage(final Page page, final Layout layout, - final Pageportlet portlet, final long company, final long groupId) + final Pageportlet portlet, final long company, final long groupId, long runAsUserId) throws SystemException, ValidatorException, IOException, PortalException { if (page.getLinkToURL() != null && !page.getLinkToURL().equals("")) { LOG.error("This is a link page! It cannot be cleared. If you intend to use this page " @@ -436,7 +437,6 @@ private static void addPortletIntoPage(final Page page, final Layout layout, } else { long plid = layout.getPlid(); int ownerType = PortletKeys.PREFS_OWNER_TYPE_LAYOUT; - long runAsUserId = LiferaySetup.getRunAsUserId(); LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType(); @@ -629,10 +629,10 @@ private static void deletePages(final long groupId) { } private static Layout createPage(final long groupId, final Page currentPage, - final long parentLayoutId, final boolean isPrivate) + final long parentLayoutId, final boolean isPrivate, long runAsUserId) throws SystemException, PortalException { - return LayoutLocalServiceUtil.addLayout(LiferaySetup.getRunAsUserId(), groupId, isPrivate, + return LayoutLocalServiceUtil.addLayout(runAsUserId, groupId, isPrivate, parentLayoutId, currentPage.getName(), currentPage.getName(), LiferaySetup.DESCRIPTION, currentPage.getType(), currentPage.isHidden(), currentPage.getFriendlyURL(), new ServiceContext()); diff --git a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupPermissions.java b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupPermissions.java index 610cf15..0098fde 100644 --- a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupPermissions.java +++ b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupPermissions.java @@ -26,17 +26,6 @@ * #L% */ -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Set; - -import com.mimacom.liferay.portal.setup.domain.PermissionAction; -import com.mimacom.liferay.portal.setup.domain.PortletPermissions; -import com.mimacom.liferay.portal.setup.domain.RolePermission; -import com.mimacom.liferay.portal.setup.domain.RolePermissions; -import com.mimacom.liferay.portal.setup.domain.Role; - import com.liferay.portal.kernel.exception.NestableException; import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.exception.SystemException; @@ -48,32 +37,36 @@ import com.liferay.portal.security.permission.ActionKeys; import com.liferay.portal.service.ResourcePermissionLocalServiceUtil; import com.liferay.portal.service.RoleLocalServiceUtil; -import com.liferay.portal.util.PortalUtil; +import com.mimacom.liferay.portal.setup.domain.*; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Set; public final class SetupPermissions { public static final String[] PERMISSION_RO = {ActionKeys.VIEW}; public static final String[] PERMISSION_RW = {ActionKeys.VIEW, ActionKeys.UPDATE}; private static final Log LOG = LogFactoryUtil.getLog(SetupPermissions.class); - private static final long COMPANY_ID = PortalUtil.getDefaultCompanyId(); private SetupPermissions() { } - public static void setupPortletPermissions(final PortletPermissions portletPermissions) { + public static void setupPortletPermissions(final PortletPermissions portletPermissions, long companyId) { for (PortletPermissions.Portlet portlet : portletPermissions.getPortlet()) { - deleteAllPortletPermissions(portlet); + deleteAllPortletPermissions(portlet, companyId); for (PortletPermissions.Portlet.ActionId actionId : portlet.getActionId()) { for (Role role : actionId.getRole()) { try { String name = role.getName(); - long roleId = RoleLocalServiceUtil.getRole(COMPANY_ID, name).getRoleId(); - ResourcePermissionLocalServiceUtil.setResourcePermissions(COMPANY_ID, + long roleId = RoleLocalServiceUtil.getRole(companyId, name).getRoleId(); + ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId, portlet.getPortletId(), ResourceConstants.SCOPE_COMPANY, - String.valueOf(COMPANY_ID), roleId, - new String[] {actionId.getName()}); + String.valueOf(companyId), roleId, + new String[]{actionId.getName()}); LOG.info("Set permission for action id " + actionId.getName() + " and role " + role.getName()); @@ -87,29 +80,29 @@ public static void setupPortletPermissions(final PortletPermissions portletPermi } public static void addReadRight(final String roleName, final String className, - final String primaryKey) throws SystemException, PortalException { + final String primaryKey, long companyId) throws SystemException, PortalException { - addPermission(roleName, className, primaryKey, PERMISSION_RO); + addPermission(roleName, className, primaryKey, PERMISSION_RO, companyId); } public static void addReadWrightRight(final String roleName, final String className, - final String primaryKey) throws SystemException, PortalException { + final String primaryKey, long companyId) throws SystemException, PortalException { - addPermission(roleName, className, primaryKey, PERMISSION_RW); + addPermission(roleName, className, primaryKey, PERMISSION_RW, companyId); } public static void removePermission(final long companyId, final String name, - final String primKey) throws PortalException, SystemException { + final String primKey) throws PortalException, SystemException { ResourcePermissionLocalServiceUtil.deleteResourcePermissions(companyId, name, ResourceConstants.SCOPE_INDIVIDUAL, primKey); } public static void addPermission(final String roleName, final String className, - final String primaryKey, final String[] permission) - throws SystemException, PortalException { + final String primaryKey, final String[] permission, long companyId) + throws SystemException, PortalException { try { - long roleId = RoleLocalServiceUtil.getRole(COMPANY_ID, roleName).getRoleId(); - ResourcePermissionLocalServiceUtil.setResourcePermissions(COMPANY_ID, className, + long roleId = RoleLocalServiceUtil.getRole(companyId, roleName).getRoleId(); + ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId, className, ResourceConstants.SCOPE_INDIVIDUAL, primaryKey, roleId, permission); } catch (Exception ex) { LOG.error(ex); @@ -117,21 +110,21 @@ public static void addPermission(final String roleName, final String className, } public static void addPermissionToPage(final Role role, - final String primaryKey, final String[] actionKeys) - throws PortalException, SystemException { + final String primaryKey, final String[] actionKeys, long companyId) + throws PortalException, SystemException { - long roleId = RoleLocalServiceUtil.getRole(COMPANY_ID, role.getName()).getRoleId(); - ResourcePermissionLocalServiceUtil.setResourcePermissions(COMPANY_ID, + long roleId = RoleLocalServiceUtil.getRole(companyId, role.getName()).getRoleId(); + ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId, Layout.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(primaryKey), roleId, actionKeys); } - private static void deleteAllPortletPermissions(final PortletPermissions.Portlet portlet) { + private static void deleteAllPortletPermissions(final PortletPermissions.Portlet portlet, long companyId) { try { List resourcePermissions = ResourcePermissionLocalServiceUtil - .getResourcePermissions(COMPANY_ID, portlet.getPortletId(), - ResourceConstants.SCOPE_COMPANY, String.valueOf(COMPANY_ID)); + .getResourcePermissions(companyId, portlet.getPortletId(), + ResourceConstants.SCOPE_COMPANY, String.valueOf(companyId)); for (ResourcePermission resourcePermission : resourcePermissions) { ResourcePermissionLocalServiceUtil.deleteResourcePermission(resourcePermission); } @@ -140,18 +133,18 @@ private static void deleteAllPortletPermissions(final PortletPermissions.Portlet } } - public static void clearPagePermissions(final String primaryKey) + public static void clearPagePermissions(final String primaryKey, long companyId) throws PortalException, SystemException { - ResourcePermissionLocalServiceUtil.deleteResourcePermissions(COMPANY_ID, + ResourcePermissionLocalServiceUtil.deleteResourcePermissions(companyId, Layout.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(primaryKey)); } public static void updatePermission(final String locationHint, final long groupId, - final long companyId, final long elementId, final Class clazz, - final RolePermissions rolePermissions, - final HashMap> defaultPermissions) { + final long companyId, final long elementId, final Class clazz, + final RolePermissions rolePermissions, + final HashMap> defaultPermissions) { boolean useDefaultPermissions = false; if (rolePermissions != null) { if (rolePermissions.isClearPermissions()) { @@ -178,7 +171,7 @@ public static void updatePermission(final String locationHint, final long groupI try { SetupPermissions.addPermission(roleName, clazz.getName(), Long.toString(elementId), - actions.toArray(new String[actions.size()])); + actions.toArray(new String[actions.size()]), companyId); } catch (SystemException e) { LOG.error("Permissions for " + roleName + " for " + locationHint + " " + "could not be set. ", e); @@ -203,7 +196,7 @@ public static void updatePermission(final String locationHint, final long groupI actions = defaultPermissions.get(r); try { SetupPermissions.addPermission(r, clazz.getName(), Long.toString(elementId), - actions.toArray(new String[actions.size()])); + actions.toArray(new String[actions.size()]), companyId); } catch (SystemException e) { LOG.error("Permissions for " + r + " for " + locationHint + " could not be " + "set. ", e); diff --git a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupRoles.java b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupRoles.java index a7ca84c..4f0c231 100644 --- a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupRoles.java +++ b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/SetupRoles.java @@ -46,20 +46,19 @@ public final class SetupRoles { private static final Log LOG = LogFactoryUtil.getLog(SetupRoles.class); - private static final long COMPANY_ID = PortalUtil.getDefaultCompanyId(); private SetupRoles() { } - public static void setupRoles(final List roles) { + public static void setupRoles(final List roles, long companyId) { for (com.mimacom.liferay.portal.setup.domain.Role role : roles) { try { - RoleLocalServiceUtil.getRole(COMPANY_ID, role.getName()); + RoleLocalServiceUtil.getRole(companyId, role.getName()); LOG.info("Setup: Role " + role.getName() + " already exist, not creating..."); } catch (NoSuchRoleException | ObjectNotFoundException e) { - addRole(role); + addRole(role, companyId); } catch (SystemException | PortalException e) { LOG.error("error while setting up roles", e); @@ -67,7 +66,7 @@ public static void setupRoles(final List localeTitleMap = new HashMap<>(); localeTitleMap.put(Locale.ENGLISH, role.getName()); @@ -82,8 +81,8 @@ private static void addRole(final com.mimacom.liferay.portal.setup.domain.Role r } } - long defaultUserId = UserLocalServiceUtil.getDefaultUserId(COMPANY_ID); - RoleLocalServiceUtil.addRole(defaultUserId, COMPANY_ID, role.getName(), localeTitleMap, + long defaultUserId = UserLocalServiceUtil.getDefaultUserId(companyId); + RoleLocalServiceUtil.addRole(defaultUserId, companyId, role.getName(), localeTitleMap, null, roleType); LOG.info("Setup: Role " + role.getName() + " does not exist, adding..."); @@ -95,7 +94,7 @@ private static void addRole(final com.mimacom.liferay.portal.setup.domain.Role r } public static void deleteRoles(final List roles, - final String deleteMethod) { + final String deleteMethod, final long companyId) { switch (deleteMethod) { case "excludeListed": @@ -107,7 +106,7 @@ public static void deleteRoles(final List> DEFAULT_PERMISSIONS; @@ -71,13 +69,13 @@ private SetupWebFolders() { } public static void setupWebFolders( - final Organization org, final long groupId, - final long companyId) { + final Organization org, final long groupId, + final long companyId, long runAsUserId) { for (ArticleFolder af : org.getArticleFolder()) { String webFolderPath = af.getFolderPath(); String description = af.getDescription(); JournalFolder jf = WebFolderUtil.findWebFolder(companyId, groupId, - LiferaySetup.getRunAsUserId(), webFolderPath, description, true); + runAsUserId, webFolderPath, description, true); SetupPermissions.updatePermission("Folder " + af.getFolderPath(), groupId, companyId, jf.getFolderId(), JournalFolder.class, af.getRolePermissions(), DEFAULT_PERMISSIONS); diff --git a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/util/CustomFieldSettingUtil.java b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/util/CustomFieldSettingUtil.java index c2db610..0f8d4bd 100644 --- a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/util/CustomFieldSettingUtil.java +++ b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/util/CustomFieldSettingUtil.java @@ -46,7 +46,7 @@ public final class CustomFieldSettingUtil { private static final Log LOG = LogFactoryUtil.getLog(CustomFieldSettingUtil.class); private CustomFieldSettingUtil() { - + // hide default constructor } /** diff --git a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/util/FilePathUtil.java b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/util/FilePathUtil.java index 10102f5..0bb49d4 100644 --- a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/util/FilePathUtil.java +++ b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/util/FilePathUtil.java @@ -32,7 +32,7 @@ public final class FilePathUtil { private FilePathUtil() { - + // hide default constructor } public static String getExtension(final String fname) { diff --git a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/BasicSetupUpgradeProcess.java b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/util/FileUtil.java similarity index 63% rename from db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/BasicSetupUpgradeProcess.java rename to db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/util/FileUtil.java index 2be4c40..9541dfd 100644 --- a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/BasicSetupUpgradeProcess.java +++ b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/util/FileUtil.java @@ -1,6 +1,6 @@ -package com.mimacom.liferay.portal.setup; +package com.mimacom.liferay.portal.setup.core.util; -/* +/*- * #%L * Liferay Portal DB Setup core * %% @@ -25,7 +25,9 @@ * THE SOFTWARE. * #L% */ - +import com.liferay.portal.kernel.log.Log; +import com.liferay.portal.kernel.log.LogFactoryUtil; +import org.jboss.vfs.VirtualFile; import java.io.File; import java.io.IOException; @@ -33,54 +35,22 @@ import java.net.URISyntaxException; import java.net.URL; -import org.jboss.vfs.VirtualFile; +public class FileUtil { -import com.liferay.portal.kernel.log.Log; -import com.liferay.portal.kernel.log.LogFactoryUtil; -import com.liferay.portal.kernel.upgrade.UpgradeException; -import com.liferay.portal.kernel.upgrade.UpgradeProcess; - -/** - * Created by mapa on 13.3.2015. - */ -public abstract class BasicSetupUpgradeProcess extends UpgradeProcess { - /** - * Logger. - */ - private static final Log LOG = LogFactoryUtil.getLog(BasicSetupUpgradeProcess.class); + private static final Log LOG = LogFactoryUtil.getLog(FileUtil.class); - /** - * Does upgrade. - * - * @throws com.liferay.portal.kernel.upgrade.UpgradeException - * wrapped exception - */ - @Override - public final void upgrade() throws UpgradeException { - - String[] fileNames = getSetupFileNames(); - for (String fileName : fileNames) { - LOG.info("Starting upgrade process. Filename: " + fileName); - - File file = getSetupFile(fileName); - if (file == null) { - throw new UpgradeException("XML configuration not found"); - } - LiferaySetup.setup(file); - LOG.info("Finished upgrade process. Filename: " + fileName); - } + private FileUtil() { + // hide default constructor } /** * checks and returns file used for setup. * - * @param fileName - * name of resource + * @param fileName name of resource * @return setup xml file */ - public final File getSetupFile(final String fileName) { + public static final File getSetupFileFromClassloader(ClassLoader cl, final String fileName) { - ClassLoader cl = this.getClass().getClassLoader(); URL url = cl.getResource(fileName); if (url == null) { LOG.error("XML configuration not found"); @@ -113,9 +83,4 @@ public final File getSetupFile(final String fileName) { return file; } - /** - * @return paths to setup xml files. - */ - protected abstract String[] getSetupFileNames(); - } diff --git a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/MarshallUtil.java b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/util/MarshallUtil.java similarity index 95% rename from db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/MarshallUtil.java rename to db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/util/MarshallUtil.java index c021eb5..a1751ba 100644 --- a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/MarshallUtil.java +++ b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/util/MarshallUtil.java @@ -1,4 +1,4 @@ -package com.mimacom.liferay.portal.setup; +package com.mimacom.liferay.portal.setup.core.util; /* * #%L @@ -73,13 +73,13 @@ public static Setup unmarshall(final InputStream stream) { } private static Unmarshaller getUnmarshaller() throws JAXBException { - JAXBContext jc = JAXBContext.newInstance("org.mimacom.liferay.portal.setup.domain"); + JAXBContext jc = JAXBContext.newInstance("com.mimacom.liferay.portal.setup.domain"); return jc.createUnmarshaller(); } public static boolean validateAgainstXSD(final InputStream xml) throws IOException { ClassLoader cl = MarshallUtil.class.getClassLoader(); - URL url = cl.getResource("setup_definition-1.0.xsd"); + URL url = cl.getResource("setup_definition-2.0.xsd"); if (url == null) { throw new IOException("XSD configuration not found"); } diff --git a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/util/ResolverUtil.java b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/util/ResolverUtil.java index 6f2dd32..032af7b 100644 --- a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/util/ResolverUtil.java +++ b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/core/util/ResolverUtil.java @@ -60,7 +60,6 @@ public final class ResolverUtil { - // CHECKSTYLE:OFF public static final int ID_TYPE_ID = 0; public static final int ID_TYPE_UUID = 1; public static final int ID_TYPE_RESOURCE = 2; @@ -82,8 +81,6 @@ public final class ResolverUtil { private static final String ID_OF_ORG_USER_GROUP_WITH_NAME_KEY = "{{$%%IDTYPE%%_OF_%%LOOKUPTYPE%%_WITH_NAME="; - // CHECKSTYLE:ON - private ResolverUtil() { } @@ -643,7 +640,6 @@ public static String lookupDDLRecordSetId(final String content, final String loc return contentCopy; } - // CHECKSTYLE:OFF public static String lookupStructureOrTemplateIdWithKey(final String content, final String locationHint, final long groupId, final long company, final boolean uuid, final String commandPrefix, final boolean isTemplate, final Class referredClass) { @@ -714,8 +710,6 @@ public static String lookupStructureOrTemplateIdWithKey(final String content, return retVal; } - // CHECKSTYLE:ON - public static JournalArticle getArticleByArticleID(final String articleId, final long groupId) throws SystemException { JournalArticle article = null; diff --git a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/package-info.java b/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/package-info.java deleted file mode 100644 index 0378651..0000000 --- a/db-setup-core/src/main/java/com/mimacom/liferay/portal/setup/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Created by luha on 4.8.2015. - */ -package com.mimacom.liferay.portal.setup; diff --git a/db-setup-core/src/main/resources/setup_definition-1.0.xsd b/db-setup-core/src/main/resources/setup_definition-1.1.xsd similarity index 85% rename from db-setup-core/src/main/resources/setup_definition-1.0.xsd rename to db-setup-core/src/main/resources/setup_definition-1.1.xsd index 470efc9..e0355cd 100644 --- a/db-setup-core/src/main/resources/setup_definition-1.0.xsd +++ b/db-setup-core/src/main/resources/setup_definition-1.1.xsd @@ -1,18 +1,23 @@ + elementFormDefault="qualified" targetNamespace="https://raw.githubusercontent.com/mimacom/liferay-db-setup-core/1.x/db-setup-core/src/main/resources/setup_definition-1.1.xsd" + xmlns="https://raw.githubusercontent.com/mimacom/liferay-db-setup-core/1.x/db-setup-core/src/main/resources/setup_definition-1.1.xsd"> + + Liferay Setup Configuration + + This configuration is used to setup Liferay DB with desired entities. It can be applied to: default, one, many Liferay instances at once. Additionally one can specify the groups on which the setup will take place. + + - + @@ -23,7 +28,9 @@ - + + + @@ -66,6 +73,14 @@ + + + + + + + + @@ -95,6 +110,66 @@ + + + Specify the email address of user, which will be used for performing all operations within setup hook or specific company. When empty: random user that has Administrator role within a company will be used. + + + + + + + + Used to define companies and groups on whose below defined setup configuration will run. When not specified setup will only take place on default company and "Guest" group within. + + + + + + + + + + + + + Setup configuration will be executed on every provided group or only on "Guest" group if none is provided. If you need separate setups for different groups create different configuration file per group and execute all of them. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/db-setup-sample-hook/pom.xml b/db-setup-sample-hook/pom.xml new file mode 100644 index 0000000..b9bc2ab --- /dev/null +++ b/db-setup-sample-hook/pom.xml @@ -0,0 +1,99 @@ + + + + com.mimacom.liferay + build-parent + 1.1.0 + + + 4.0.0 + com.mimacom + db-setup-sample-hook + war + DB Setup Sample Hook + + Liferay DB Setup Sample Hook plugin - uses all available configurations to setup sample portal from scratch + + 1.0.0-SNAPSHOT + + + + ${} + ${liferay.home}/tomcat-7.0.62 + ${liferay.home}/deploy + ${liferay.app.server.tomcat.dir}/webapps + ${liferay.app.server.tomcat.dir}/lib/ext + ${liferay.app.server.tomcat.dir}/webapps/ROOT + + + + + com.liferay.maven.plugins + liferay-maven-plugin + ${liferay.maven.plugin.version} + + ${liferay.auto.deploy.dir} + ${liferay.app.server.deploy.dir} + ${liferay.app.server.lib.global.dir} + ${liferay.app.server.portal.dir} + ${liferay.ce.version} + hook + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + 1.7 + 1.7 + UTF-8 + + + + org.apache.maven.plugins + maven-resources-plugin + 3.0.2 + + UTF-8 + + + + + + + com.mimacom.liferay + db-setup-core + 1.1.0-SNAPSHOT + + + com.liferay.portal + portal-service + ${liferay.ce.version} + + + com.liferay.portal + util-java + ${liferay.ce.version} + + + javax.portlet + portlet-api + 2.0 + provided + + + javax.servlet + javax.servlet-api + 3.0.1 + provided + + + javax.servlet.jsp + jsp-api + 2.2 + provided + + + diff --git a/db-setup-sample-hook/src/main/resources/setup.xml b/db-setup-sample-hook/src/main/resources/setup.xml new file mode 100644 index 0000000..deb2d37 --- /dev/null +++ b/db-setup-sample-hook/src/main/resources/setup.xml @@ -0,0 +1,47 @@ + + + + + test@liferay.com + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/db-setup-sample-hook/src/main/webapp/WEB-INF/liferay-hook.xml b/db-setup-sample-hook/src/main/webapp/WEB-INF/liferay-hook.xml new file mode 100644 index 0000000..45fbacd --- /dev/null +++ b/db-setup-sample-hook/src/main/webapp/WEB-INF/liferay-hook.xml @@ -0,0 +1,6 @@ + + + + + portal.properties + diff --git a/db-setup-sample-hook/src/main/webapp/WEB-INF/liferay-plugin-package.xml b/db-setup-sample-hook/src/main/webapp/WEB-INF/liferay-plugin-package.xml new file mode 100644 index 0000000..48961e9 --- /dev/null +++ b/db-setup-sample-hook/src/main/webapp/WEB-INF/liferay-plugin-package.xml @@ -0,0 +1,42 @@ + + + + ${project.name} + ${project.groupId}/${project.artifactId}/${project.version}/${project.packaging} + + hooks + + + Liferay DB Setup Sample Hook plugin - uses all available configurations to setup sample portal from scratch + + Features: + +

Creating new objects:

+
    +
  1. Roles
  2. +
+ +

Configuring relationships:

+
    +
  1. +
+ +

Deleting existing objects:

+
    +
  1. +
+ ]]>
+ + Use all available configurations to setup sample portal from scratch + + https://github.com/mimacom/liferay-db-setup-core + mimacom ag + + MIT + + + 6.2.0+ + +
diff --git a/db-setup-sample-hook/src/main/webapp/WEB-INF/web.xml b/db-setup-sample-hook/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..49c4180 --- /dev/null +++ b/db-setup-sample-hook/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,5 @@ + + + + diff --git a/pom.xml b/pom.xml index 6972269..5e5df47 100644 --- a/pom.xml +++ b/pom.xml @@ -2,14 +2,20 @@ - 4.0.0 + 4.0.0 - com.mimacom.liferay - build-parent - 1.0.0 - pom + com.mimacom.liferay + build-parent + 1.1.0 + pom - - db-setup-core - + + 6.2.5 + ${liferay.ce.version} + + + + db-setup-core + db-setup-sample-hook +