Example usage for com.liferay.portal.kernel.model Group getParentGroup

List of usage examples for com.liferay.portal.kernel.model Group getParentGroup

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.model Group getParentGroup.

Prototype

public Group getParentGroup();

Source Link

Usage

From source file:com.liferay.asset.categories.admin.web.internal.exportimport.staged.model.repository.StagedAssetLinkStagedModelRepository.java

License:Open Source License

protected AssetEntry fetchAssetEntry(long groupId, String uuid) throws PortalException {

    DynamicQuery dynamicQuery = _assetEntryLocalService.dynamicQuery();

    Property classUuidProperty = PropertyFactoryUtil.forName("classUuid");

    dynamicQuery.add(classUuidProperty.eq(uuid));

    List<AssetEntry> assetEntries = _assetEntryLocalService.dynamicQuery(dynamicQuery);

    if (ListUtil.isEmpty(assetEntries)) {
        return null;
    }/*from  w  w  w .ja  v a2s. co  m*/

    Map<Long, AssetEntry> assetEntryMap = new HashMap<>();

    for (AssetEntry assetEntry : assetEntries) {
        assetEntryMap.put(assetEntry.getGroupId(), assetEntry);
    }

    // Try to fetch the existing staged model from the importing group

    if (assetEntryMap.containsKey(groupId)) {
        return assetEntryMap.get(groupId);
    }

    // Try to fetch the existing staged model from parent sites

    Group group = _groupLocalService.getGroup(groupId);

    Group parentGroup = group.getParentGroup();

    while (parentGroup != null) {
        if (assetEntryMap.containsKey(parentGroup.getGroupId())) {
            AssetEntry assetEntry = assetEntryMap.get(parentGroup.getGroupId());

            if (isAssetEntryApplicable(assetEntry)) {
                return assetEntry;
            }
        }

        parentGroup = parentGroup.getParentGroup();
    }

    // Try to fetch the existing staged model from the global site

    Group companyGroup = _groupLocalService.fetchCompanyGroup(group.getCompanyId());

    if (assetEntryMap.containsKey(companyGroup.getGroupId())) {
        return assetEntryMap.get(companyGroup.getGroupId());
    }

    // Try to fetch the existing staged model from the company

    Stream<AssetEntry> assetEntryStream = assetEntries.stream();

    List<AssetEntry> companyAssetEntries = assetEntryStream
            .filter(entry -> entry.getCompanyId() == group.getCompanyId()).collect(Collectors.toList());

    if (ListUtil.isEmpty(companyAssetEntries)) {
        return null;
    }

    for (AssetEntry assetEntry : companyAssetEntries) {
        try {
            if (isAssetEntryApplicable(assetEntry)) {
                return assetEntry;
            }
        } catch (PortalException pe) {
            if (_log.isDebugEnabled()) {
                _log.debug(pe, pe);
            }
        }
    }

    return null;
}

From source file:com.liferay.exportimport.internal.staged.model.repository.StagedModelRepositoryHelperImpl.java

License:Open Source License

@Override
public StagedModel fetchMissingReference(String uuid, long groupId,
        StagedModelRepository<?> stagedModelRepository) {

    // Try to fetch the existing staged model from the importing group

    StagedModel existingStagedModel = stagedModelRepository.fetchStagedModelByUuidAndGroupId(uuid, groupId);

    if ((existingStagedModel != null) && !isStagedModelInTrash(existingStagedModel)) {

        return existingStagedModel;
    }//from  w w w. j  a  v a  2 s . c o  m

    try {

        // Try to fetch the existing staged model from parent sites

        Group originalGroup = _groupLocalService.getGroup(groupId);

        Group group = originalGroup.getParentGroup();

        while (group != null) {
            existingStagedModel = stagedModelRepository.fetchStagedModelByUuidAndGroupId(uuid,
                    group.getGroupId());

            if (existingStagedModel != null) {
                break;
            }

            group = group.getParentGroup();
        }

        if ((existingStagedModel != null) && !isStagedModelInTrash(existingStagedModel)) {

            return existingStagedModel;
        }

        List<StagedModel> existingStagedModels = (List<StagedModel>) stagedModelRepository
                .fetchStagedModelsByUuidAndCompanyId(uuid, originalGroup.getCompanyId());

        for (StagedModel stagedModel : existingStagedModels) {
            try {
                if (stagedModel instanceof StagedGroupedModel) {
                    StagedGroupedModel stagedGroupedModel = (StagedGroupedModel) stagedModel;

                    group = _groupLocalService.getGroup(stagedGroupedModel.getGroupId());

                    if (!group.isStagingGroup() && !isStagedModelInTrash(stagedModel)) {

                        return stagedModel;
                    }
                } else if (!isStagedModelInTrash(stagedModel)) {
                    return stagedModel;
                }
            } catch (PortalException pe) {
                if (_log.isDebugEnabled()) {
                    _log.debug(pe, pe);
                }
            }
        }
    } catch (Exception e) {
        if (_log.isDebugEnabled()) {
            _log.debug(e, e);
        } else if (_log.isWarnEnabled()) {
            _log.warn("Unable to fetch missing reference staged model from " + "group " + groupId);
        }
    }

    return null;
}

From source file:com.liferay.exportimport.staged.model.repository.base.BaseStagedModelRepository.java

License:Open Source License

@Override
public T fetchMissingReference(String uuid, long groupId) {

    // Try to fetch the existing staged model from the importing group

    T existingStagedModel = fetchStagedModelByUuidAndGroupId(uuid, groupId);

    if ((existingStagedModel != null) && !isStagedModelInTrash(existingStagedModel)) {

        return existingStagedModel;
    }/*  ww w.j  a  v  a  2s  .  co  m*/

    try {

        // Try to fetch the existing staged model from parent sites

        Group originalGroup = GroupLocalServiceUtil.getGroup(groupId);

        Group group = originalGroup.getParentGroup();

        while (group != null) {
            existingStagedModel = fetchStagedModelByUuidAndGroupId(uuid, group.getGroupId());

            if (existingStagedModel != null) {
                break;
            }

            group = group.getParentGroup();
        }

        if ((existingStagedModel != null) && !isStagedModelInTrash(existingStagedModel)) {

            return existingStagedModel;
        }

        List<T> existingStagedModels = fetchStagedModelsByUuidAndCompanyId(uuid, originalGroup.getCompanyId());

        for (T stagedModel : existingStagedModels) {
            try {
                if (stagedModel instanceof StagedGroupedModel) {
                    StagedGroupedModel stagedGroupedModel = (StagedGroupedModel) stagedModel;

                    group = GroupLocalServiceUtil.getGroup(stagedGroupedModel.getGroupId());

                    if (!group.isStagingGroup() && !isStagedModelInTrash(stagedModel)) {

                        return stagedModel;
                    }
                } else if (!isStagedModelInTrash(stagedModel)) {
                    return stagedModel;
                }
            } catch (PortalException pe) {
                if (_log.isDebugEnabled()) {
                    _log.debug(pe, pe);
                }
            }
        }
    } catch (Exception e) {
        if (_log.isDebugEnabled()) {
            _log.debug(e, e);
        } else if (_log.isWarnEnabled()) {
            _log.warn("Unable to fetch missing reference staged model from " + "group " + groupId);
        }
    }

    return null;
}

From source file:com.liferay.layout.admin.web.internal.exportimport.data.handler.LayoutStagedModelDataHandler.java

License:Open Source License

protected Layout fetchMissingReference(String uuid, long groupId, boolean privateLayout) {

    // Try to fetch the existing layout from the importing group

    Layout layout = _layoutLocalService.fetchLayoutByUuidAndGroupId(uuid, groupId, privateLayout);

    if (layout != null) {
        return layout;
    }/*from  w  w w  . j a v  a 2  s  .com*/

    try {

        // Try to fetch the existing layout from the parent sites

        Group originalGroup = _groupLocalService.getGroup(groupId);

        Group group = originalGroup.getParentGroup();

        while (group != null) {
            layout = _layoutLocalService.fetchLayoutByUuidAndGroupId(uuid, group.getGroupId(), privateLayout);

            if (layout != null) {
                break;
            }

            group = group.getParentGroup();
        }

        if (layout == null) {
            List<Layout> layouts = fetchStagedModelsByUuidAndCompanyId(uuid, originalGroup.getCompanyId());

            if (ListUtil.isEmpty(layouts)) {
                return null;
            }

            layout = layouts.get(0);
        }

        return layout;
    } catch (Exception e) {
        if (_log.isDebugEnabled()) {
            _log.debug(e, e);
        } else if (_log.isWarnEnabled()) {
            _log.warn("Unable to fetch missing reference layout from group " + groupId);
        }

        return null;
    }
}

From source file:com.liferay.portlet.display.template.internal.PortletDisplayTemplateImpl.java

License:Open Source License

@Override
public long getDDMTemplateGroupId(long groupId) {
    Group group = _groupLocalService.fetchGroup(groupId);

    if (group == null) {
        return groupId;
    }//from w  ww.ja v  a  2s . com

    try {
        if (group.isLayout()) {
            group = group.getParentGroup();
        }

        if (group.isStagingGroup()) {
            Group liveGroup = group.getLiveGroup();

            if (!liveGroup.isStagedPortlet(PortletKeys.PORTLET_DISPLAY_TEMPLATE)) {

                return liveGroup.getGroupId();
            }
        }

        return group.getGroupId();
    } catch (Exception e) {
        if (_log.isWarnEnabled()) {
            _log.warn(e, e);
        }
    }

    return groupId;
}