Search in sources :

Example 1 with LayoutSet

use of com.liferay.portal.kernel.model.LayoutSet 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);
}
Also used : Group(com.liferay.portal.kernel.model.Group) LayoutSet(com.liferay.portal.kernel.model.LayoutSet)

Example 2 with LayoutSet

use of com.liferay.portal.kernel.model.LayoutSet in project liferay-imex by jpdacunha.

the class VirtualhostExporter method doExport.

@Override
public void doExport(User user, Properties config, File virtualhostDir, long companyId, Locale locale, List<ExporterRawContent> rawContentToExport, boolean debug) {
    reportService.getStartMessage(_log, "Virtualhost export process");
    boolean enabled = GetterUtil.getBoolean(config.get(ImExVirtualhostExporterPropsKeys.EXPORT_VIRTUALHOST_ENABLED));
    if (enabled) {
        try {
            Company company = companyLocalService.getCompany(companyId);
            List<VirtualHost> hosts = virtualHostCommonService.getCompanyVirtualHost(companyId);
            for (VirtualHost virtualHost : hosts) {
                String hostname = virtualHost.getHostname();
                try {
                    LayoutSet layoutSet = null;
                    Group group = null;
                    boolean publicVirtualHost = true;
                    long layoutSetId = virtualHost.getLayoutSetId();
                    boolean defaultVirtualHost = virtualHost.getDefaultVirtualHost();
                    String groupFriendlyURL = StringPool.BLANK;
                    String languageId = StringPool.BLANK;
                    boolean isCompanyLayoutSet = layoutSetId == VirtualhostCommonService.DEFAULT_LAYOUTSET_ID;
                    if (!isCompanyLayoutSet) {
                        layoutSet = layoutSetLocalService.getLayoutSet(layoutSetId);
                        publicVirtualHost = !layoutSet.isPrivateLayout();
                        group = groupLocalService.getGroup(layoutSet.getGroupId());
                        groupFriendlyURL = group.getFriendlyURL();
                        languageId = virtualHost.getLanguageId();
                    }
                    String companyWebId = company.getWebId();
                    ImexVirtualhost imexVirtualhost = new ImexVirtualhost(companyWebId, groupFriendlyURL, publicVirtualHost, isCompanyLayoutSet, hostname, defaultVirtualHost, languageId);
                    processor.write(imexVirtualhost, virtualhostDir, FileNames.getVirtualhostFileName(virtualHost, company, group, layoutSet, processor.getFileExtension()));
                    reportService.getOK(_log, "Virtualhost : " + hostname + " for group : " + groupFriendlyURL);
                } catch (Exception e) {
                    reportService.getError(_log, "Virtualhost : " + hostname, e);
                    if (debug) {
                        _log.error(e, e);
                    }
                }
            }
        } catch (Exception e) {
            _log.error(e, e);
            reportService.getError(_log, e);
        }
    } else {
        reportService.getDisabled(_log, DESCRIPTION);
    }
    reportService.getEndMessage(_log, "Virtualhost export process");
}
Also used : Group(com.liferay.portal.kernel.model.Group) Company(com.liferay.portal.kernel.model.Company) ImexVirtualhost(com.liferay.imex.virtualhost.model.ImexVirtualhost) VirtualHost(com.liferay.portal.kernel.model.VirtualHost) LayoutSet(com.liferay.portal.kernel.model.LayoutSet)

Example 3 with LayoutSet

use of com.liferay.portal.kernel.model.LayoutSet in project liferay-imex by jpdacunha.

the class VirtualhostImporter method updateVirtualHosts.

private void updateVirtualHosts(long companyId, Locale locale, Map<Long, TreeMap<String, String>> layoutSetHostnames) throws PortalException {
    // Updating bunch of virtualhosts for each layoutSet - The Liferay method destriy all existing virtualhosts first
    for (Entry<Long, TreeMap<String, String>> entry : layoutSetHostnames.entrySet()) {
        long layoutSetId = entry.getKey();
        TreeMap<String, String> currentLayoutSetHostnames = entry.getValue();
        virtualHostLocalService.updateVirtualHosts(companyId, layoutSetId, currentLayoutSetHostnames);
        Company company = companyLocalService.getCompanyById(companyId);
        String name = "Company : " + company.getName();
        if (layoutSetId != VirtualhostCommonService.DEFAULT_LAYOUTSET_ID) {
            LayoutSet layoutSet = layoutSetLocalService.getLayoutSet(layoutSetId);
            Group group = layoutSet.getGroup();
            name = "Site : " + GroupUtil.getGroupName(group, locale);
        }
        // To avoid diplaying null in logs
        Map<String, String> toDisplay = new HashMap<String, String>();
        toDisplay.putAll(currentLayoutSetHostnames);
        toDisplay = CollectionUtil.replaceNullValues(toDisplay, DEFAULT_LANGUAGE_MESSAGE);
        reportService.getOK(_log, name, "Virtual Hosts : " + toDisplay);
    }
}
Also used : Group(com.liferay.portal.kernel.model.Group) Company(com.liferay.portal.kernel.model.Company) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) LayoutSet(com.liferay.portal.kernel.model.LayoutSet)

Example 4 with LayoutSet

use of com.liferay.portal.kernel.model.LayoutSet in project liferay-imex by jpdacunha.

the class VirtualhostImporter method converToUpdatableMap.

private Map<Long, TreeMap<String, String>> converToUpdatableMap(long companyId, List<ExtendedImexVirtualhost> virtualHosts) throws PortalException {
    // Constructing structured map to update
    Map<Long, TreeMap<String, String>> layoutSetHostnames = new HashMap<Long, TreeMap<String, String>>();
    for (ExtendedImexVirtualhost extendedVirtualHostObj : virtualHosts) {
        ImexVirtualhost virtualHostObj = extendedVirtualHostObj.getVirtualhost();
        String companyWebId = virtualHostObj.getCompanyWebId();
        String groupFriendlyURL = virtualHostObj.getGroupFriendlyURL();
        boolean isPublicVirtualHost = virtualHostObj.isPublicVirtualHost();
        long layoutSetId = VirtualhostCommonService.DEFAULT_LAYOUTSET_ID;
        boolean isCompanyVirtualHost = virtualHostObj.isCompanyVirtualHost();
        File virtualHostFile = extendedVirtualHostObj.getSourceFile();
        String originFileName = virtualHostFile.getName();
        String languageId = virtualHostObj.getLanguageId();
        try {
            // Verify if company exists
            companyLocalService.getCompanyByWebId(companyWebId);
            if (!isCompanyVirtualHost) {
                // Verify if group exists
                Group group = groupLocalService.getFriendlyURLGroup(companyId, groupFriendlyURL);
                LayoutSet layoutSet = layoutSetLocalService.getLayoutSet(group.getGroupId(), !isPublicVirtualHost);
                layoutSetId = layoutSet.getLayoutSetId();
            }
            String hostname = virtualHostObj.getHostname();
            TreeMap<String, String> currentLayoutSetHostnames = null;
            if (Validator.isNotNull(hostname)) {
                TreeMap<String, String> treeMap = layoutSetHostnames.get(layoutSetId);
                if (treeMap == null) {
                    layoutSetHostnames.put(layoutSetId, new TreeMap<String, String>());
                } else {
                    _log.debug("Updating existing TreeMap");
                }
                currentLayoutSetHostnames = layoutSetHostnames.get(layoutSetId);
                if (!currentLayoutSetHostnames.containsKey(hostname)) {
                    currentLayoutSetHostnames.put(hostname, languageId);
                } else {
                    _log.debug("Current TreeMap already contains [" + hostname + "]");
                }
            } else {
                reportService.getError(_log, originFileName, "missing required information hostname");
            }
        } catch (NoSuchCompanyException e) {
            reportService.getDNE(_log, "company identified by [" + companyWebId + "]");
            reportService.getSkipped(_log, originFileName);
        } catch (NoSuchGroupException e) {
            reportService.getDNE(_log, "group identified by [" + groupFriendlyURL + "]");
            reportService.getSkipped(_log, originFileName);
        }
    }
    return layoutSetHostnames;
}
Also used : Group(com.liferay.portal.kernel.model.Group) HashMap(java.util.HashMap) NoSuchCompanyException(com.liferay.portal.kernel.exception.NoSuchCompanyException) TreeMap(java.util.TreeMap) NoSuchGroupException(com.liferay.portal.kernel.exception.NoSuchGroupException) ImexVirtualhost(com.liferay.imex.virtualhost.model.ImexVirtualhost) ExtendedImexVirtualhost(com.liferay.imex.virtualhost.importer.model.ExtendedImexVirtualhost) ExtendedImexVirtualhost(com.liferay.imex.virtualhost.importer.model.ExtendedImexVirtualhost) File(java.io.File) LayoutSet(com.liferay.portal.kernel.model.LayoutSet)

Aggregations

Group (com.liferay.portal.kernel.model.Group)4 LayoutSet (com.liferay.portal.kernel.model.LayoutSet)4 ImexVirtualhost (com.liferay.imex.virtualhost.model.ImexVirtualhost)2 Company (com.liferay.portal.kernel.model.Company)2 HashMap (java.util.HashMap)2 TreeMap (java.util.TreeMap)2 ExtendedImexVirtualhost (com.liferay.imex.virtualhost.importer.model.ExtendedImexVirtualhost)1 NoSuchCompanyException (com.liferay.portal.kernel.exception.NoSuchCompanyException)1 NoSuchGroupException (com.liferay.portal.kernel.exception.NoSuchGroupException)1 VirtualHost (com.liferay.portal.kernel.model.VirtualHost)1 File (java.io.File)1