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

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

Introduction

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

Prototype

public long getRemoteLiveGroupId();

Source Link

Usage

From source file:com.liferay.asset.publisher.web.internal.exportimport.portlet.preferences.processor.AssetPublisherExportImportPortletPreferencesProcessor.java

License:Open Source License

protected void updateExportScopeIds(PortletDataContext portletDataContext,
        PortletPreferences portletPreferences, String key, long plid) throws Exception {

    String[] oldValues = portletPreferences.getValues(key, null);

    if (oldValues == null) {
        return;//from w w  w  .j  av  a 2s  .com
    }

    Layout layout = _layoutLocalService.getLayout(plid);

    String companyGroupScopeId = AssetPublisherUtil.SCOPE_ID_GROUP_PREFIX
            + portletDataContext.getCompanyGroupId();

    String[] newValues = new String[oldValues.length];

    Element rootElement = portletDataContext.getExportDataRootElement();

    Element groupIdMappingsElement = rootElement.addElement("group-id-mappings");

    for (int i = 0; i < oldValues.length; i++) {
        String oldValue = oldValues[i];

        if (oldValue.startsWith(AssetPublisherUtil.SCOPE_ID_GROUP_PREFIX)) {
            newValues[i] = StringUtil.replace(oldValue, companyGroupScopeId, "[$COMPANY_GROUP_SCOPE_ID$]");

            if (newValues[i].contains("[$COMPANY_GROUP_SCOPE_ID$]")) {
                continue;
            }
        } else if (oldValue.startsWith(AssetPublisherUtil.SCOPE_ID_LAYOUT_PREFIX)) {

            // Legacy preferences

            String scopeIdSuffix = oldValue.substring(AssetPublisherUtil.SCOPE_ID_LAYOUT_PREFIX.length());

            long scopeIdLayoutId = GetterUtil.getLong(scopeIdSuffix);

            Layout scopeIdLayout = _layoutLocalService.getLayout(layout.getGroupId(), layout.isPrivateLayout(),
                    scopeIdLayoutId);

            if (plid != scopeIdLayout.getPlid()) {
                StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext,
                        portletDataContext.getPortletId(), scopeIdLayout);
            }

            newValues[i] = AssetPublisherUtil.SCOPE_ID_LAYOUT_UUID_PREFIX + scopeIdLayout.getUuid();
        } else if (oldValue.startsWith(AssetPublisherUtil.SCOPE_ID_LAYOUT_UUID_PREFIX)) {

            String scopeLayoutUuid = oldValue
                    .substring(AssetPublisherUtil.SCOPE_ID_LAYOUT_UUID_PREFIX.length());

            Layout scopeUuidLayout = _layoutLocalService.getLayoutByUuidAndGroupId(scopeLayoutUuid,
                    portletDataContext.getGroupId(), portletDataContext.isPrivateLayout());

            if (plid != scopeUuidLayout.getPlid()) {
                StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext,
                        portletDataContext.getPortletId(), scopeUuidLayout);
            }

            newValues[i] = oldValue;
        } else {
            newValues[i] = oldValue;
        }

        long groupId = AssetPublisherUtil.getGroupIdFromScopeId(newValues[i], portletDataContext.getGroupId(),
                portletDataContext.isPrivateLayout());

        Group group = _groupLocalService.fetchGroup(groupId);

        long liveGroupId = 0;

        if (group != null) {
            liveGroupId = group.getLiveGroupId();

            if (group.isStagedRemotely()) {
                liveGroupId = group.getRemoteLiveGroupId();
            }
        }

        if ((groupId == 0) || (liveGroupId == 0)) {
            continue;
        }

        newValues[i] = String.valueOf(groupId);

        Element groupIdMappingElement = groupIdMappingsElement.addElement("group-id-mapping");

        groupIdMappingElement.addAttribute("group-id", String.valueOf(groupId));
        groupIdMappingElement.addAttribute("live-group-id", String.valueOf(liveGroupId));
    }

    portletPreferences.setValues(key, newValues);
}

From source file:com.liferay.exportimport.changeset.web.internal.portlet.action.ExportImportEntityMVCActionCommand.java

License:Open Source License

private void _processExportAndPublishAction(ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortalException {

    String[] exportingEntities;//from w  ww.j a  va 2  s  .  co  m

    if (Validator.isNotNull(actionRequest.getParameter("exportingEntities"))) {

        exportingEntities = ParamUtil.getStringValues(actionRequest, "exportingEntities");
    } else if (Validator.isNotNull(actionRequest.getParameter("classNameId"))
            && Validator.isNotNull(actionRequest.getParameter("uuid"))) {

        long classNameId = ParamUtil.getLong(actionRequest, "classNameId");
        long groupId = ParamUtil.getLong(actionRequest, "groupId");
        String uuid = ParamUtil.getString(actionRequest, "uuid");

        StringBundler sb = new StringBundler(5);

        sb.append(classNameId);
        sb.append(StringPool.POUND);
        sb.append(groupId);
        sb.append(StringPool.POUND);
        sb.append(uuid);

        exportingEntities = new String[] { sb.toString() };
    } else {
        SessionErrors.add(actionRequest, ExportImportEntityException.class,
                new ExportImportEntityException(ExportImportEntityException.TYPE_NO_DATA_FOUND));

        return;
    }

    Map<String, String[]> parameterMap = ExportImportConfigurationParameterMapFactory.buildParameterMap();

    parameterMap.put("exportingEntities", exportingEntities);

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    String cmd = ParamUtil.getString(actionRequest, "cmd");

    String portletId = MapUtil.getString(actionRequest.getParameterMap(), "portletId");

    Portlet portlet = _portletLocalService.getPortletById(portletId);

    long backgroundTaskId = 0;

    if (cmd.equals(Constants.EXPORT)) {
        Map<String, Serializable> settingsMap = ExportImportConfigurationSettingsMapFactory
                .buildExportPortletSettingsMap(themeDisplay.getUser(), themeDisplay.getPlid(),
                        themeDisplay.getScopeGroupId(), ChangesetPortletKeys.CHANGESET, parameterMap,
                        _exportImportHelper.getPortletExportFileName(portlet));

        ExportImportConfiguration exportImportConfiguration = _exportImportConfigurationLocalService
                .addDraftExportImportConfiguration(themeDisplay.getUserId(), portletId,
                        ExportImportConfigurationConstants.TYPE_EXPORT_PORTLET, settingsMap);

        backgroundTaskId = _exportImportLocalService
                .exportPortletInfoAsFileInBackground(themeDisplay.getUserId(), exportImportConfiguration);
    } else if (cmd.equals(Constants.PUBLISH)) {
        Group scopeGroup = themeDisplay.getScopeGroup();

        if (!scopeGroup.isStagingGroup() && !scopeGroup.isStagedRemotely()) {

            SessionErrors.add(actionRequest, ExportImportEntityException.class,
                    new ExportImportEntityException(ExportImportEntityException.TYPE_GROUP_NOT_STAGED));

            return;
        }

        if (!scopeGroup.isStagedPortlet(portletId)) {
            SessionErrors.add(actionRequest, ExportImportEntityException.class,
                    new ExportImportEntityException(ExportImportEntityException.TYPE_PORTLET_NOT_STAGED));

            return;
        }

        long liveGroupId = 0;

        if (scopeGroup.isStagingGroup()) {
            liveGroupId = scopeGroup.getLiveGroupId();
        } else if (scopeGroup.isStagedRemotely()) {
            liveGroupId = scopeGroup.getRemoteLiveGroupId();
        }

        Map<String, Serializable> settingsMap = ExportImportConfigurationSettingsMapFactory
                .buildPublishPortletSettingsMap(themeDisplay.getUser(), themeDisplay.getScopeGroupId(),
                        themeDisplay.getPlid(), liveGroupId, themeDisplay.getPlid(),
                        ChangesetPortletKeys.CHANGESET, parameterMap);

        ExportImportConfiguration exportImportConfiguration = _exportImportConfigurationLocalService
                .addDraftExportImportConfiguration(themeDisplay.getUserId(), portletId,
                        ExportImportConfigurationConstants.TYPE_PUBLISH_PORTLET, settingsMap);

        backgroundTaskId = _staging.publishPortlet(themeDisplay.getUserId(), exportImportConfiguration);
    }

    sendRedirect(actionRequest, actionResponse, backgroundTaskId);
}

From source file:com.liferay.exportimport.lar.PortletDataContextImpl.java

License:Open Source License

protected Element doAddReferenceElement(ClassedModel referrerClassedModel, Element element,
        ClassedModel classedModel, String className, String binPath, String referenceType, boolean missing) {

    Element referenceElement = null;

    if (missing) {
        Element referencesElement = _missingReferencesElement;

        referenceElement = referencesElement.addElement("missing-reference");
    } else {/*w w  w. ja  v  a2s.  c om*/
        Element referencesElement = element.element("references");

        if (referencesElement == null) {
            referencesElement = element.addElement("references");
        }

        referenceElement = referencesElement.addElement("reference");
    }

    referenceElement.addAttribute("class-name", className);

    referenceElement.addAttribute("class-pk", String.valueOf(classedModel.getPrimaryKeyObj()));

    populateClassNameAttribute(classedModel, referenceElement);

    if (missing) {
        if (classedModel instanceof StagedModel) {
            referenceElement.addAttribute("display-name",
                    StagedModelDataHandlerUtil.getDisplayName((StagedModel) classedModel));
        } else {
            referenceElement.addAttribute("display-name", String.valueOf(classedModel.getPrimaryKeyObj()));
        }
    }

    if (classedModel instanceof StagedGroupedModel) {
        StagedGroupedModel stagedGroupedModel = (StagedGroupedModel) classedModel;

        referenceElement.addAttribute("group-id", String.valueOf(stagedGroupedModel.getGroupId()));

        try {
            Group group = GroupLocalServiceUtil.getGroup(stagedGroupedModel.getGroupId());

            long liveGroupId = group.getLiveGroupId();

            if (group.isStagedRemotely()) {
                liveGroupId = group.getRemoteLiveGroupId();
            }

            if (liveGroupId == GroupConstants.DEFAULT_LIVE_GROUP_ID) {
                liveGroupId = group.getGroupId();
            }

            referenceElement.addAttribute("live-group-id", String.valueOf(liveGroupId));

            if (group.isLayout()) {
                try {
                    Layout scopeLayout = LayoutLocalServiceUtil.getLayout(group.getClassPK());

                    referenceElement.addAttribute("scope-layout-uuid", scopeLayout.getUuid());
                } catch (NoSuchLayoutException nsle) {
                    if (_log.isWarnEnabled()) {
                        _log.warn("Unable to find layout " + group.getClassPK(), nsle);
                    }
                }
            }
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn("Unable to find group " + stagedGroupedModel.getGroupId());
            }
        }
    }

    if (Validator.isNotNull(binPath)) {
        referenceElement.addAttribute("path", binPath);
    }

    referenceElement.addAttribute("type", referenceType);

    if (missing) {
        referenceElement.addAttribute("referrer-class-name",
                ExportImportClassedModelUtil.getClassName(referrerClassedModel));

        if (referrerClassedModel instanceof PortletModel) {
            Portlet portlet = (Portlet) referrerClassedModel;

            referenceElement.addAttribute("referrer-display-name", portlet.getRootPortletId());
        } else if (referrerClassedModel instanceof StagedModel) {
            StagedModel referrerStagedModel = (StagedModel) referrerClassedModel;

            referenceElement.addAttribute("referrer-display-name",
                    StagedModelDataHandlerUtil.getDisplayName(referrerStagedModel));
        }
    }

    if (classedModel instanceof StagedModel) {
        StagedModel stagedModel = (StagedModel) classedModel;

        referenceElement.addAttribute("uuid", stagedModel.getUuid());
        referenceElement.addAttribute("company-id", String.valueOf(stagedModel.getCompanyId()));

        Map<String, String> referenceAttributes = StagedModelDataHandlerUtil.getReferenceAttributes(this,
                stagedModel);

        for (Map.Entry<String, String> referenceAttribute : referenceAttributes.entrySet()) {

            referenceElement.addAttribute(referenceAttribute.getKey(), referenceAttribute.getValue());
        }
    }

    return referenceElement;
}