Example usage for com.liferay.portal.kernel.model StagedModel getCompanyId

List of usage examples for com.liferay.portal.kernel.model StagedModel getCompanyId

Introduction

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

Prototype

public long getCompanyId();

Source Link

Usage

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 ww  . j  av a  2  s  .com*/
        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;
}

From source file:com.liferay.exportimport.test.util.lar.BaseStagedModelDataHandlerTestCase.java

License:Open Source License

protected StagedModelAssets updateAssetEntry(StagedModel stagedModel, Group group) throws Exception {

    AssetEntry assetEntry = fetchAssetEntry(stagedModel, group);

    if (assetEntry == null) {
        return null;
    }// w ww.ja va  2s.  com

    AssetVocabulary assetVocabulary = AssetTestUtil.addVocabulary(stagingGroup.getGroupId());

    AssetCategory assetCategory = AssetTestUtil.addCategory(stagingGroup.getGroupId(),
            assetVocabulary.getVocabularyId());

    Company company = CompanyLocalServiceUtil.getCompany(stagedModel.getCompanyId());

    Group companyGroup = company.getGroup();

    AssetVocabulary companyAssetVocabulary = AssetTestUtil.addVocabulary(companyGroup.getGroupId());

    AssetCategory companyAssetCategory = AssetTestUtil.addCategory(companyGroup.getGroupId(),
            companyAssetVocabulary.getVocabularyId());

    AssetTag assetTag = AssetTestUtil.addTag(stagingGroup.getGroupId());

    double assetPriority = assetEntry.getPriority();

    if (isAssetPrioritySupported()) {
        assetPriority = RandomTestUtil.nextDouble();
    }

    assetEntry = AssetEntryLocalServiceUtil.updateEntry(TestPropsValues.getUserId(), stagingGroup.getGroupId(),
            assetEntry.getCreateDate(), assetEntry.getModifiedDate(), assetEntry.getClassName(),
            assetEntry.getClassPK(), assetEntry.getClassUuid(), assetEntry.getClassTypeId(),
            new long[] { assetCategory.getCategoryId(), companyAssetCategory.getCategoryId() },
            new String[] { assetTag.getName() }, assetEntry.isListable(), assetEntry.isVisible(),
            assetEntry.getStartDate(), assetEntry.getEndDate(), assetEntry.getPublishDate(),
            assetEntry.getExpirationDate(), assetEntry.getMimeType(), assetEntry.getTitle(),
            assetEntry.getDescription(), assetEntry.getSummary(), assetEntry.getUrl(),
            assetEntry.getLayoutUuid(), assetEntry.getHeight(), assetEntry.getWidth(), assetPriority);

    return new StagedModelAssets(assetCategory, assetEntry, assetTag, assetVocabulary);
}