Search in sources :

Example 6 with Layout

use of com.liferay.portal.kernel.model.Layout in project sw360 by eclipse.

the class ChangeLogsPortletUtils method getModerationPortletUrl.

private LiferayPortletURL getModerationPortletUrl(PortletRequest request) {
    Portlet portlet = PortletLocalServiceUtil.getPortletById(PortalConstants.MODERATION_PORTLET_NAME);
    Optional<Layout> layout = LayoutLocalServiceUtil.getLayouts(portlet.getCompanyId()).stream().filter(l -> ("/moderation").equals(l.getFriendlyURL())).findFirst();
    if (layout.isPresent()) {
        long plId = layout.get().getPlid();
        LiferayPortletURL modUrl = PortletURLFactoryUtil.create(request, PortalConstants.MODERATION_PORTLET_NAME, plId, PortletRequest.RENDER_PHASE);
        modUrl.setParameter(PortalConstants.PAGENAME, PortalConstants.PAGENAME_EDIT);
        return modUrl;
    }
    return null;
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) PortletLocalServiceUtil(com.liferay.portal.kernel.service.PortletLocalServiceUtil) PaginationParameters(org.eclipse.sw360.portal.common.datatables.data.PaginationParameters) JSONFactoryUtil.createJSONObject(com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONObject) ResourceResponse(javax.portlet.ResourceResponse) DATATABLE_RECORDS_TOTAL(org.eclipse.sw360.portal.common.PortalConstants.DATATABLE_RECORDS_TOTAL) DATATABLE_RECORDS_FILTERED(org.eclipse.sw360.portal.common.PortalConstants.DATATABLE_RECORDS_FILTERED) ReferenceDocDataMixin(org.eclipse.sw360.datahandler.couchdb.DatabaseMixInForChangeLog.ReferenceDocDataMixin) DATATABLE_DISPLAY_DATA(org.eclipse.sw360.portal.common.PortalConstants.DATATABLE_DISPLAY_DATA) PortalUtil(com.liferay.portal.kernel.util.PortalUtil) Portlet(com.liferay.portal.kernel.model.Portlet) ChangeLogsMixin(org.eclipse.sw360.datahandler.couchdb.DatabaseMixInForChangeLog.ChangeLogsMixin) PaginationParser(org.eclipse.sw360.portal.common.datatables.PaginationParser) List(java.util.List) Logger(org.apache.logging.log4j.Logger) CommonUtils.nullToEmptyString(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString) Iface(org.eclipse.sw360.datahandler.thrift.changelogs.ChangeLogsService.Iface) Optional(java.util.Optional) PortletUtils(org.eclipse.sw360.portal.common.PortletUtils) LiferayPortletURL(com.liferay.portal.kernel.portlet.LiferayPortletURL) ChangeLogsService(org.eclipse.sw360.datahandler.thrift.changelogs.ChangeLogsService) ChangeLogs(org.eclipse.sw360.datahandler.thrift.changelogs.ChangeLogs) JSONException(com.liferay.portal.kernel.json.JSONException) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) ThriftClients(org.eclipse.sw360.datahandler.thrift.ThriftClients) ResourceRequest(javax.portlet.ResourceRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) Lists(com.google.common.collect.Lists) ChangedFields(org.eclipse.sw360.datahandler.thrift.changelogs.ChangedFields) ImmutableList(com.google.common.collect.ImmutableList) ChangedFieldsMixin(org.eclipse.sw360.datahandler.couchdb.DatabaseMixInForChangeLog.ChangedFieldsMixin) PortletRequest(javax.portlet.PortletRequest) ReferenceDocData(org.eclipse.sw360.datahandler.thrift.changelogs.ReferenceDocData) JSONFactoryUtil.createJSONArray(com.liferay.portal.kernel.json.JSONFactoryUtil.createJSONArray) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TException(org.apache.thrift.TException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JSONFactoryUtil(com.liferay.portal.kernel.json.JSONFactoryUtil) JSONObject(com.liferay.portal.kernel.json.JSONObject) Layout(com.liferay.portal.kernel.model.Layout) UserCacheHolder(org.eclipse.sw360.portal.users.UserCacheHolder) LayoutLocalServiceUtil(com.liferay.portal.kernel.service.LayoutLocalServiceUtil) PortalConstants(org.eclipse.sw360.portal.common.PortalConstants) JSONArray(com.liferay.portal.kernel.json.JSONArray) Comparator(java.util.Comparator) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) PortletURLFactoryUtil(com.liferay.portal.kernel.portlet.PortletURLFactoryUtil) Portlet(com.liferay.portal.kernel.model.Portlet) Layout(com.liferay.portal.kernel.model.Layout) LiferayPortletURL(com.liferay.portal.kernel.portlet.LiferayPortletURL)

Example 7 with Layout

use of com.liferay.portal.kernel.model.Layout in project liferay-blade-samples by liferay.

the class HelloSoyViewMVCRenderCommand method render.

@Override
public String render(RenderRequest renderRequest, RenderResponse renderResponse) {
    Template template = (Template) renderRequest.getAttribute(WebKeys.TEMPLATE);
    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
    List<Layout> layouts = themeDisplay.getLayouts();
    Stream<Layout> layoutsStream = layouts.stream();
    template.put("layouts", layoutsStream.map(layout -> new HashMap<String, String>() {

        {
            put("friendlyURL", layout.getFriendlyURL());
            put("nameCurrentValue", layout.getNameCurrentValue());
        }
    }).collect(Collectors.toList()));
    PortletURL navigationURL = renderResponse.createRenderURL();
    navigationURL.setParameter("mvcRenderCommandName", "Navigation");
    template.put("navigationURL", navigationURL.toString());
    template.put("releaseInfo", ReleaseInfo.getReleaseInfo());
    return "View";
}
Also used : Layout(com.liferay.portal.kernel.model.Layout) ThemeDisplay(com.liferay.portal.kernel.theme.ThemeDisplay) PortletURL(javax.portlet.PortletURL) Template(com.liferay.portal.kernel.template.Template)

Example 8 with Layout

use of com.liferay.portal.kernel.model.Layout in project liferay-db-setup-core by ableneo.

the class ResolverUtil method lookupPageIdWithFriendlyUrl.

public static String lookupPageIdWithFriendlyUrl(final String content, final String locationHint, final long groupId, final long company, final boolean isPrivate, final IdMode mode) {
    String contentCopy = content;
    String lookUp = PAGE_ID_BY_FRIENDLY_URL;
    if (isPrivate) {
        lookUp = lookUp.replace("%%PTYPE%%", "PRIV");
    } else {
        lookUp = lookUp.replace("%%PTYPE%%", "PUB");
    }
    switch(mode) {
        case ID:
            lookUp = lookUp.replace(LAYOUTID, "PLID");
            break;
        case PLID:
            lookUp = lookUp.replace(LAYOUTID, "ID");
            break;
        case UUID:
            lookUp = lookUp.replace(LAYOUTID, "UUID");
            break;
    }
    int pos = contentCopy.indexOf(lookUp);
    while (pos > -1) {
        int pos2 = contentCopy.indexOf(CLOSING_TAG, pos);
        if (pos2 < 0) {
            LOG.error(String.format("No closing Tag, pos %1$s for %2$s", pos, locationHint));
            break;
        } else {
            // by default the referred file is looked up in current site.
            long siteGroupId = groupId;
            String fUrl = contentCopy.substring(pos + lookUp.length(), pos2).trim();
            // check for the reference to another site
            String[] refSegs = ResolverUtil.separateSiteRef(fUrl);
            if (!refSegs[0].equals("")) {
                siteGroupId = ResolverUtil.getSiteGroupIdByName(refSegs[0], company, locationHint);
                fUrl = refSegs[1];
            }
            String pageId = "NOT FOUND";
            Layout l = null;
            try {
                l = LayoutLocalServiceUtil.getFriendlyURLLayout(siteGroupId, isPrivate, fUrl);
            } catch (PortalException | SystemException e) {
                LOG.error(e);
            }
            if (l == null) {
                LOG.error(String.format("Referred page %1$s is not found .", fUrl));
                contentCopy = contentCopy.substring(0, pos) + " PAGE NOT FOUND!! " + contentCopy.substring(pos2 + CLOSING_TAG.length(), contentCopy.length());
            } else {
                switch(mode) {
                    case ID:
                        pageId = Long.toString(l.getLayoutId());
                        break;
                    case PLID:
                        pageId = Long.toString(l.getPlid());
                        break;
                    case UUID:
                        pageId = l.getUuid();
                        break;
                }
                contentCopy = contentCopy.substring(0, pos) + pageId + contentCopy.substring(pos2 + CLOSING_TAG.length(), contentCopy.length());
            }
        }
        pos = contentCopy.indexOf(lookUp, pos + 1);
    }
    // 
    return contentCopy;
}
Also used : SystemException(com.liferay.portal.kernel.exception.SystemException) Layout(com.liferay.portal.kernel.model.Layout) PortalException(com.liferay.portal.kernel.exception.PortalException)

Example 9 with Layout

use of com.liferay.portal.kernel.model.Layout in project liferay-db-setup-core by ableneo.

the class SetupPages method updateLinkPage.

private static void updateLinkPage(final PageType page, final long groupId) {
    try {
        Layout layout = LayoutLocalServiceUtil.getFriendlyURLLayout(groupId, false, page.getFriendlyUrl());
        if (layout.getLayoutType().getTypeSettingsProperties().get("url") == null) {
            LOG.error("Could not update link page " + page.getFriendlyUrl() + " with link to url" + " " + page.getLinkToUrl() + " because page is not a link type page! " + " Maybe it has been imported before as non link type page. Please " + "delete it and rerun!");
        } else {
            UnicodeProperties props = layout.getTypeSettingsProperties();
            props.put("url", page.getLinkToUrl());
            layout.setTypeSettingsProperties(props);
            layout.setHidden(page.isHidden());
            LayoutLocalServiceUtil.updateLayout(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings());
        }
    } catch (PortalException | SystemException e) {
        LOG.error(String.format("Could not update link page %1$s with link to url %2$s", page.getFriendlyUrl(), page.getLinkToUrl()), e);
    }
}
Also used : SystemException(com.liferay.portal.kernel.exception.SystemException) Layout(com.liferay.portal.kernel.model.Layout) UnicodeProperties(com.liferay.portal.kernel.util.UnicodeProperties) PortalException(com.liferay.portal.kernel.exception.PortalException)

Example 10 with Layout

use of com.liferay.portal.kernel.model.Layout in project liferay-db-setup-core by ableneo.

the class SetupPages method setupPageTemplates.

/**
 * Set the page templates up. As this is heavily based on page (layout).
 *
 * @param pageTemplates The page template definitions that are imported.
 */
public static void setupPageTemplates(final PageTemplates pageTemplates) {
    try {
        for (PageTemplate pageTemplate : pageTemplates.getPageTemplate()) {
            String name = pageTemplate.getName();
            if (name != null) {
                LayoutPrototype lp;
                DynamicQuery dq = LayoutPrototypeLocalServiceUtil.dynamicQuery().add(PropertyFactoryUtil.forName("name").like("%" + name + "%"));
                List<LayoutPrototype> listLayoutPrototype = LayoutPrototypeLocalServiceUtil.dynamicQuery(dq);
                long groupId = SetupConfigurationThreadLocal.getRunInGroupId();
                long userid = SetupConfigurationThreadLocal.getRunAsUserId();
                long company = SetupConfigurationThreadLocal.getRunInCompanyId();
                if (listLayoutPrototype != null && !listLayoutPrototype.isEmpty()) {
                    lp = listLayoutPrototype.get(0);
                } else {
                    Map<Locale, String> titleMap = TranslationMapUtil.getTranslationMap(pageTemplate.getTitleTranslation(), groupId, name, String.format(" Page template  %1$s", name));
                    Map<Locale, String> nameMap = TranslationMapUtil.getTranslationMap(pageTemplate.getTitleTranslation(), groupId, name, String.format(" Page template  %1$s", name));
                    lp = LayoutPrototypeLocalServiceUtil.addLayoutPrototype(userid, company, titleMap, nameMap, true, new ServiceContext());
                }
                if (lp != null) {
                    Layout layout = lp.getLayout();
                    if (pageTemplate.getPage() != null) {
                        PageType page = pageTemplate.getPage();
                        if (page.getFriendlyUrl() != null && !page.getFriendlyUrl().equals("")) {
                            LOG.error(String.format("The page of page template %1$s may not have a friendly URL! Will ignore it!", name));
                        }
                        setupLiferayPage(layout, page, null, null, groupId, false, company, userid, name);
                    }
                } else {
                    LOG.error(String.format("Could not create or find the page template %1$s", name));
                }
            }
        }
    } catch (PortalException | SystemException e) {
        LOG.error("Problem during creating page templates ", e);
    }
}
Also used : Locale(java.util.Locale) PageTemplate(com.ableneo.liferay.portal.setup.domain.PageTemplate) DynamicQuery(com.liferay.portal.kernel.dao.orm.DynamicQuery) ServiceContext(com.liferay.portal.kernel.service.ServiceContext) SystemException(com.liferay.portal.kernel.exception.SystemException) Layout(com.liferay.portal.kernel.model.Layout) LayoutPrototype(com.liferay.portal.kernel.model.LayoutPrototype) PortalException(com.liferay.portal.kernel.exception.PortalException) PageType(com.ableneo.liferay.portal.setup.domain.PageType)

Aggregations

Layout (com.liferay.portal.kernel.model.Layout)11 PortalException (com.liferay.portal.kernel.exception.PortalException)4 SystemException (com.liferay.portal.kernel.exception.SystemException)4 Portlet (com.liferay.portal.kernel.model.Portlet)4 LiferayPortletURL (com.liferay.portal.kernel.portlet.LiferayPortletURL)4 PortletURLFactoryUtil (com.liferay.portal.kernel.portlet.PortletURLFactoryUtil)4 LayoutLocalServiceUtil (com.liferay.portal.kernel.service.LayoutLocalServiceUtil)4 PortletLocalServiceUtil (com.liferay.portal.kernel.service.PortletLocalServiceUtil)4 PortletRequest (javax.portlet.PortletRequest)4 LogManager (org.apache.logging.log4j.LogManager)4 Logger (org.apache.logging.log4j.Logger)4 User (org.eclipse.sw360.datahandler.thrift.users.User)4 PortalConstants (org.eclipse.sw360.portal.common.PortalConstants)4 UserCacheHolder (org.eclipse.sw360.portal.users.UserCacheHolder)4 ResourceRequest (javax.portlet.ResourceRequest)3 CommonUtils (org.eclipse.sw360.datahandler.common.CommonUtils)3 SW360Utils (org.eclipse.sw360.datahandler.common.SW360Utils)3 CustomFieldHelper (org.eclipse.sw360.portal.common.CustomFieldHelper)3 PortletUtils (org.eclipse.sw360.portal.common.PortletUtils)3 com.google.common.collect (com.google.common.collect)2