Example usage for com.liferay.portal.kernel.util PortalUtil getSiteGroupId

List of usage examples for com.liferay.portal.kernel.util PortalUtil getSiteGroupId

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util PortalUtil getSiteGroupId.

Prototype

public static long getSiteGroupId(long scopeGroupId) 

Source Link

Usage

From source file:com.liferay.asset.publisher.web.util.AssetPublisherUtil.java

License:Open Source License

protected static long[] getSiteGroupIds(long[] groupIds) {
    Set<Long> siteGroupIds = new LinkedHashSet<>();

    for (long groupId : groupIds) {
        siteGroupIds.add(PortalUtil.getSiteGroupId(groupId));
    }/*from  w w  w  .j  a  va 2s .c om*/

    return ArrayUtil.toLongArray(siteGroupIds);
}

From source file:com.liferay.journal.model.impl.JournalArticleImpl.java

License:Open Source License

@Override
public DDMStructure getDDMStructure() {
    DDMStructure ddmStructure = null;//from www. j ava  2 s  .c  o m

    try {
        ddmStructure = DDMStructureLocalServiceUtil.fetchStructure(PortalUtil.getSiteGroupId(getGroupId()),
                ClassNameLocalServiceUtil.getClassNameId(JournalArticle.class), getDDMStructureKey(), true);
    } catch (PortalException pe) {
        _log.error("Unable to get DDM structure with DDM structure key " + getDDMStructureKey(), pe);
    }

    return ddmStructure;
}

From source file:com.liferay.journal.model.impl.JournalArticleImpl.java

License:Open Source License

@Override
public DDMTemplate getDDMTemplate() {
    DDMTemplate ddmTemplate = null;//from   w w  w .  j a v  a2  s  .c o m

    try {
        ddmTemplate = DDMTemplateLocalServiceUtil.fetchTemplate(PortalUtil.getSiteGroupId(getGroupId()),
                ClassNameLocalServiceUtil.getClassNameId(JournalArticle.class), getDDMTemplateKey(), true);
    } catch (PortalException pe) {
        _log.error("Unable to get DDM template for DDM structure with" + "DDM structure key "
                + getDDMStructureKey(), pe);
    }

    return ddmTemplate;
}

From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

protected JournalArticleDisplay getArticleDisplay(JournalArticle article, String ddmTemplateKey,
        String viewMode, String languageId, int page, PortletRequestModel portletRequestModel,
        ThemeDisplay themeDisplay, boolean propagateException) throws PortalException {

    String content = null;/*from ww w.  j a  v a2 s.  c om*/

    if (page < 1) {
        page = 1;
    }

    int numberOfPages = 1;
    boolean paginate = false;
    boolean pageFlow = false;

    boolean cacheable = true;

    Map<String, String> tokens = JournalUtil.getTokens(article.getGroupId(), portletRequestModel, themeDisplay);

    if ((themeDisplay == null) && (portletRequestModel == null)) {
        tokens.put("company_id", String.valueOf(article.getCompanyId()));

        Group companyGroup = groupLocalService.getCompanyGroup(article.getCompanyId());

        tokens.put("article_group_id", String.valueOf(article.getGroupId()));
        tokens.put("company_group_id", String.valueOf(companyGroup.getGroupId()));

        // Deprecated tokens

        tokens.put("group_id", String.valueOf(article.getGroupId()));
    }

    tokens.put(TemplateConstants.CLASS_NAME_ID,
            String.valueOf(classNameLocalService.getClassNameId(DDMStructure.class)));
    tokens.put("article_resource_pk", String.valueOf(article.getResourcePrimKey()));

    DDMStructure ddmStructure = article.getDDMStructure();

    tokens.put("ddm_structure_key", String.valueOf(ddmStructure.getStructureKey()));
    tokens.put("ddm_structure_id", String.valueOf(ddmStructure.getStructureId()));

    // Deprecated token

    tokens.put("structure_id", article.getDDMStructureKey());

    String defaultDDMTemplateKey = article.getDDMTemplateKey();

    if (Validator.isNull(ddmTemplateKey)) {
        ddmTemplateKey = defaultDDMTemplateKey;
    }

    Document document = article.getDocument();

    document = document.clone();

    Element rootElement = document.getRootElement();

    List<Element> pages = rootElement.elements("page");

    if (!pages.isEmpty()) {
        pageFlow = true;

        String targetPage = null;

        Map<String, String[]> parameters = portletRequestModel.getParameters();

        if (parameters != null) {
            String[] values = parameters.get("targetPage");

            if ((values != null) && (values.length > 0)) {
                targetPage = values[0];
            }
        }

        Element pageElement = null;

        if (Validator.isNotNull(targetPage)) {
            targetPage = HtmlUtil.escapeXPathAttribute(targetPage);

            XPath xPathSelector = SAXReaderUtil.createXPath("/root/page[@id = " + targetPage + "]");

            pageElement = (Element) xPathSelector.selectSingleNode(document);
        }

        if (pageElement != null) {
            document = SAXReaderUtil.createDocument(pageElement);

            rootElement = document.getRootElement();

            numberOfPages = pages.size();
        } else {
            if (page > pages.size()) {
                page = 1;
            }

            pageElement = pages.get(page - 1);

            document = SAXReaderUtil.createDocument(pageElement);

            rootElement = document.getRootElement();

            numberOfPages = pages.size();
            paginate = true;
        }
    }

    JournalUtil.addAllReservedEls(rootElement, tokens, article, languageId, themeDisplay);

    try {
        if (_log.isDebugEnabled()) {
            _log.debug(
                    "Transforming " + article.getArticleId() + " " + article.getVersion() + " " + languageId);
        }

        // Try with specified template first (in the current group and the
        // global group). If a template is not specified, use the default
        // one. If the specified template does not exist, use the default
        // one. If the default one does not exist, throw an exception.

        DDMTemplate ddmTemplate = null;

        try {
            ddmTemplate = ddmTemplateLocalService.getTemplate(PortalUtil.getSiteGroupId(article.getGroupId()),
                    classNameLocalService.getClassNameId(DDMStructure.class), ddmTemplateKey, true);

            Group companyGroup = groupLocalService.getCompanyGroup(article.getCompanyId());

            if (companyGroup.getGroupId() == ddmTemplate.getGroupId()) {
                tokens.put("company_group_id", String.valueOf(companyGroup.getGroupId()));
            }
        } catch (NoSuchTemplateException nste) {
            if (!defaultDDMTemplateKey.equals(ddmTemplateKey)) {
                ddmTemplate = ddmTemplateLocalService.getTemplate(
                        PortalUtil.getSiteGroupId(article.getGroupId()),
                        classNameLocalService.getClassNameId(DDMStructure.class), defaultDDMTemplateKey);
            } else {
                throw nste;
            }
        }

        tokens.put("ddm_template_key", String.valueOf(ddmTemplate.getTemplateKey()));
        tokens.put("ddm_template_id", String.valueOf(ddmTemplate.getTemplateId()));

        // Deprecated token

        tokens.put("template_id", ddmTemplateKey);

        String script = ddmTemplate.getScript();
        String langType = ddmTemplate.getLanguage();
        cacheable = ddmTemplate.isCacheable();

        content = JournalUtil.transform(themeDisplay, tokens, viewMode, languageId, document,
                portletRequestModel, script, langType, propagateException);

        if (!pageFlow) {
            JournalServiceConfiguration journalServiceConfiguration = configurationProvider
                    .getCompanyConfiguration(JournalServiceConfiguration.class, article.getCompanyId());

            String[] pieces = StringUtil.split(content,
                    journalServiceConfiguration.journalArticlePageBreakToken());

            if (pieces.length > 1) {
                if (page > pieces.length) {
                    page = 1;
                }

                content = pieces[page - 1];
                numberOfPages = pieces.length;
                paginate = true;
            }
        }
    } catch (Exception e) {
        throw new SystemException(e);
    }

    return new JournalArticleDisplayImpl(article.getCompanyId(), article.getId(), article.getResourcePrimKey(),
            article.getGroupId(), article.getUserId(), article.getArticleId(), article.getVersion(),
            article.getTitle(languageId), article.getUrlTitle(), article.getDescription(languageId),
            article.getAvailableLanguageIds(), content, article.getDDMStructureKey(), ddmTemplateKey,
            article.isSmallImage(), article.getSmallImageId(), article.getSmallImageURL(), numberOfPages, page,
            paginate, cacheable);
}

From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

protected void updateDDMLinks(long id, long groupId, String ddmStructureKey, String ddmTemplateKey,
        boolean incrementVersion) throws PortalException {

    DDMStructure ddmStructure = ddmStructureLocalService.getStructure(PortalUtil.getSiteGroupId(groupId),
            classNameLocalService.getClassNameId(JournalArticle.class), ddmStructureKey, true);

    DDMTemplate ddmTemplate = ddmTemplateLocalService.getTemplate(PortalUtil.getSiteGroupId(groupId),
            classNameLocalService.getClassNameId(DDMStructure.class), ddmTemplateKey, true);

    if (incrementVersion) {
        ddmStorageLinkLocalService.addStorageLink(ddmStructure.getClassNameId(), id,
                ddmStructure.getStructureId(), new ServiceContext());

        ddmTemplateLinkLocalService.addTemplateLink(classNameLocalService.getClassNameId(JournalArticle.class),
                id, ddmTemplate.getTemplateId());
    } else {//from   www  .ja  v  a  2 s  . c om
        DDMStorageLink ddmStorageLink = ddmStorageLinkLocalService.getClassStorageLink(id);

        ddmStorageLink.setStructureId(ddmStructure.getStructureId());

        ddmStorageLinkLocalService.updateDDMStorageLink(ddmStorageLink);

        ddmTemplateLinkLocalService.updateTemplateLink(
                classNameLocalService.getClassNameId(JournalArticle.class), id, ddmTemplate.getTemplateId());
    }
}

From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

protected void validate(long companyId, long groupId, long classNameId, Map<Locale, String> titleMap,
        String content, String ddmStructureKey, String ddmTemplateKey, Date displayDate, Date expirationDate,
        boolean smallImage, String smallImageURL, File smallImageFile, byte[] smallImageBytes,
        ServiceContext serviceContext) throws PortalException {

    Locale articleDefaultLocale = LocaleUtil.fromLanguageId(LocalizationUtil.getDefaultLanguageId(content));

    if (!ExportImportThreadLocal.isImportInProcess()) {
        if (!LanguageUtil.isAvailableLocale(groupId, articleDefaultLocale)) {

            LocaleException le = new LocaleException(LocaleException.TYPE_CONTENT,
                    "The locale " + articleDefaultLocale + " is not available in site with groupId" + groupId);

            le.setSourceAvailableLocales(Collections.singleton(articleDefaultLocale));
            le.setTargetAvailableLocales(LanguageUtil.getAvailableLocales(groupId));

            throw le;
        }//  w  w w .  java  2 s. c o  m

        if ((expirationDate != null) && (expirationDate.before(new Date())
                || ((displayDate != null) && expirationDate.before(displayDate)))) {

            throw new ArticleExpirationDateException("Expiration date " + expirationDate + " is in the past");
        }
    }

    if ((classNameId == JournalArticleConstants.CLASSNAME_ID_DEFAULT)
            && (titleMap.isEmpty() || Validator.isNull(titleMap.get(articleDefaultLocale)))) {

        throw new ArticleTitleException("Title is null");
    }

    validateContent(content);

    DDMStructure ddmStructure = ddmStructureLocalService.getStructure(PortalUtil.getSiteGroupId(groupId),
            classNameLocalService.getClassNameId(JournalArticle.class), ddmStructureKey, true);

    validateDDMStructureFields(ddmStructure, classNameId, content, articleDefaultLocale);

    if (Validator.isNotNull(ddmTemplateKey)) {
        DDMTemplate ddmTemplate = ddmTemplateLocalService.getTemplate(PortalUtil.getSiteGroupId(groupId),
                classNameLocalService.getClassNameId(DDMStructure.class), ddmTemplateKey, true);

        if (ddmTemplate.getClassPK() != ddmStructure.getStructureId()) {
            throw new NoSuchTemplateException("{templateKey=" + ddmTemplateKey + "}");
        }
    } else if (classNameId == JournalArticleConstants.CLASSNAME_ID_DEFAULT) {
        throw new NoSuchTemplateException("DDM template key is null");
    }

    if (!smallImage || Validator.isNotNull(smallImageURL) || (smallImageFile == null)
            || (smallImageBytes == null)) {

        return;
    }

    String smallImageName = smallImageFile.getName();

    boolean validSmallImageExtension = false;

    for (String imageExtension : _journalFileUploadsConfiguration.imageExtensions()) {

        if (StringPool.STAR.equals(imageExtension) || StringUtil.endsWith(smallImageName, imageExtension)) {

            validSmallImageExtension = true;

            break;
        }
    }

    if (!validSmallImageExtension) {
        throw new ArticleSmallImageNameException(smallImageName);
    }

    long smallImageMaxSize = _journalFileUploadsConfiguration.smallImageMaxSize();

    if ((smallImageMaxSize > 0) && (smallImageBytes.length > smallImageMaxSize)) {

        throw new ArticleSmallImageSizeException(smallImageBytes.length + " exceeds " + smallImageMaxSize);
    }
}

From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

protected void validateDDMStructureId(long groupId, long folderId, String ddmStructureKey)
        throws PortalException {

    int restrictionType = JournalUtil.getRestrictionType(folderId);

    DDMStructure ddmStructure = ddmStructureLocalService.getStructure(PortalUtil.getSiteGroupId(groupId),
            classNameLocalService.getClassNameId(JournalArticle.class), ddmStructureKey, true);

    List<DDMStructure> folderDDMStructures = journalFolderLocalService
            .getDDMStructures(PortalUtil.getCurrentAndAncestorSiteGroupIds(groupId), folderId, restrictionType);

    for (DDMStructure folderDDMStructure : folderDDMStructures) {
        if (folderDDMStructure.getStructureId() == ddmStructure.getStructureId()) {

            return;
        }/*from   ww  w  .j av a  2s . c o  m*/
    }

    throw new InvalidDDMStructureException(
            "Invalid structure " + ddmStructure.getStructureId() + " for folder " + folderId);
}

From source file:com.liferay.journal.web.asset.JournalArticleDDMFormValuesReader.java

License:Open Source License

@Override
public DDMFormValues getDDMFormValues() throws PortalException {
    try {/* ww  w .  j  av  a 2  s  .  c  o  m*/
        DDMStructure ddmStructure = DDMStructureLocalServiceUtil.getStructure(
                PortalUtil.getSiteGroupId(_article.getGroupId()),
                PortalUtil.getClassNameId(JournalArticle.class), _article.getDDMStructureKey(), true);

        Fields fields = _journalConverter.getDDMFields(ddmStructure, _article.getContent());

        return DDMBeanTranslatorUtil.translate(_fieldsToDDMFormValuesConverter.convert(ddmStructure, fields));
    } catch (Exception e) {
        throw new PortalException("Unable to read fields for article " + _article.getId(), e);
    }
}

From source file:com.liferay.mentions.internal.service.MentionsWikiPageServiceWrapper.java

License:Open Source License

@Override
public WikiPage updateStatus(long userId, WikiPage page, int status, ServiceContext serviceContext,
        Map<String, Serializable> workflowContext) throws PortalException {

    int oldStatus = page.getStatus();

    page = super.updateStatus(userId, page, status, serviceContext, workflowContext);

    WikiGroupServiceOverriddenConfiguration wikiGroupServiceOverriddenConfiguration = _configurationProvider
            .getConfiguration(WikiGroupServiceOverriddenConfiguration.class,
                    new GroupServiceSettingsLocator(page.getGroupId(), WikiConstants.SERVICE_NAME));

    // Subscriptions

    if (status == WorkflowConstants.STATUS_APPROVED) {
        if (NotificationThreadLocal.isEnabled()
                && (!page.isMinorEdit() || wikiGroupServiceOverriddenConfiguration.pageMinorEditSendEmail())) {

            notifySubscribers(userId, page, (String) workflowContext.get(WorkflowConstants.CONTEXT_URL),
                    serviceContext);/* ww  w .j ava 2s  . co m*/
        }
    }

    if ((status != WorkflowConstants.STATUS_APPROVED) || (oldStatus == WorkflowConstants.STATUS_IN_TRASH)) {

        return page;
    }

    long siteGroupId = PortalUtil.getSiteGroupId(page.getGroupId());

    if (!MentionsUtil.isMentionsEnabled(siteGroupId)) {
        return page;
    }

    String contentURL = (String) serviceContext.getAttribute("contentURL");

    if (Validator.isNull(contentURL)) {
        serviceContext.setAttribute("contentURL", workflowContext.get("url"));
    }

    String portalURL = serviceContext.getPortalURL();

    String attachmentURLPrefix = WikiUtil.getAttachmentURLPrefix(serviceContext.getPathMain(),
            serviceContext.getPlid(), page.getNodeId(), page.getTitle());

    attachmentURLPrefix = portalURL + attachmentURLPrefix;

    String pageContent = _wikiEngineRenderer.convert(page, null, null, attachmentURLPrefix);

    MentionsGroupServiceConfiguration mentionsGroupServiceConfiguration = _configurationProvider
            .getCompanyConfiguration(MentionsGroupServiceConfiguration.class, page.getCompanyId());

    _mentionsNotifier.notify(page.getUserId(), page.getGroupId(), page.getTitle(), pageContent,
            WikiPage.class.getName(), page.getPageId(),
            mentionsGroupServiceConfiguration.assetEntryMentionEmailSubject(),
            mentionsGroupServiceConfiguration.assetEntryMentionEmailBody(), serviceContext);

    return page;
}