Example usage for com.liferay.portal.kernel.model LayoutSetPrototype getGroupId

List of usage examples for com.liferay.portal.kernel.model LayoutSetPrototype getGroupId

Introduction

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

Prototype

public long getGroupId() throws com.liferay.portal.kernel.exception.PortalException;

Source Link

Usage

From source file:com.liferay.layout.internal.exportimport.data.handler.StagedLayoutSetStagedModelDataHandler.java

License:Open Source License

protected void checkLayoutSetPrototypeLayouts(PortletDataContext portletDataContext,
        Set<Layout> modifiedLayouts) throws PortalException {

    boolean layoutSetPrototypeLinkEnabled = MapUtil.getBoolean(portletDataContext.getParameterMap(),
            PortletDataHandlerKeys.LAYOUT_SET_PROTOTYPE_LINK_ENABLED);

    if (!layoutSetPrototypeLinkEnabled || Validator.isNull(portletDataContext.getLayoutSetPrototypeUuid())) {

        return;/*from w w  w .j  a  v  a  2  s .  com*/
    }

    LayoutSetPrototype layoutSetPrototype = _layoutSetPrototypeLocalService
            .getLayoutSetPrototypeByUuidAndCompanyId(portletDataContext.getLayoutSetPrototypeUuid(),
                    portletDataContext.getCompanyId());

    List<Layout> layoutSetLayouts = _layoutLocalService.getLayouts(portletDataContext.getGroupId(),
            portletDataContext.isPrivateLayout());

    for (Layout layout : layoutSetLayouts) {
        String sourcePrototypeLayoutUuid = layout.getSourcePrototypeLayoutUuid();

        if (Validator.isNull(sourcePrototypeLayoutUuid)) {
            continue;
        }

        if (SitesUtil.isLayoutModifiedSinceLastMerge(layout)) {
            modifiedLayouts.add(layout);

            continue;
        }

        Layout sourcePrototypeLayout = _layoutLocalService.fetchLayout(layout.getSourcePrototypeLayoutUuid(),
                layoutSetPrototype.getGroupId(), true);

        if (sourcePrototypeLayout == null) {
            _layoutLocalService.deleteLayout(layout, false, ServiceContextThreadLocal.getServiceContext());
        }
    }
}

From source file:com.liferay.layout.set.prototype.exportimport.data.handler.test.LayoutSetPrototypeStagedModelDataHandlerTest.java

License:Open Source License

protected void validateLayouts(LayoutSetPrototype importedLayoutSetPrototype,
        LayoutPrototype importedLayoutPrototype, Layout layoutSetPrototypeLayout) throws Exception {

    validatePrototypedLayouts(LayoutSetPrototype.class, importedLayoutSetPrototype.getGroupId());
    validatePrototypedLayouts(LayoutPrototype.class, importedLayoutPrototype.getGroupId());

    Assert.assertNotNull(layoutSetPrototypeLayout.getLayoutPrototypeUuid());

    Layout importedLayout = LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(
            layoutSetPrototypeLayout.getUuid(), importedLayoutSetPrototype.getGroupId(), true);

    Assert.assertNotNull(importedLayout);
    Assert.assertEquals(importedLayoutSetPrototype.getGroupId(), importedLayout.getGroupId());
    Assert.assertEquals(importedLayoutPrototype.getUuid(), importedLayout.getLayoutPrototypeUuid());
}

From source file:com.liferay.layout.set.prototype.internal.exportimport.data.handler.LayoutSetPrototypeStagedModelDataHandler.java

License:Open Source License

protected void exportLayoutPrototypes(PortletDataContext portletDataContext,
        LayoutSetPrototype layoutSetPrototype, Element layoutSetPrototypeElement) throws Exception {

    DynamicQuery dynamicQuery = _layoutLocalService.dynamicQuery();

    Property groupIdProperty = PropertyFactoryUtil.forName("groupId");

    dynamicQuery.add(groupIdProperty.eq(layoutSetPrototype.getGroupId()));

    Conjunction conjunction = RestrictionsFactoryUtil.conjunction();

    Property layoutPrototypeUuidProperty = PropertyFactoryUtil.forName("layoutPrototypeUuid");

    conjunction.add(layoutPrototypeUuidProperty.isNotNull());
    conjunction.add(layoutPrototypeUuidProperty.ne(StringPool.BLANK));

    dynamicQuery.add(conjunction);/* ww w .  j  a  va  2 s  . c o  m*/

    List<Layout> layouts = _layoutLocalService.dynamicQuery(dynamicQuery);

    boolean exportLayoutPrototypes = portletDataContext.getBooleanParameter("layout_set_prototypes",
            "page-templates");

    for (Layout layout : layouts) {
        String layoutPrototypeUuid = layout.getLayoutPrototypeUuid();

        LayoutPrototype layoutPrototype = _layoutPrototypeLocalService
                .getLayoutPrototypeByUuidAndCompanyId(layoutPrototypeUuid, portletDataContext.getCompanyId());

        portletDataContext.addReferenceElement(layout, layoutSetPrototypeElement, layoutPrototype,
                PortletDataContext.REFERENCE_TYPE_DEPENDENCY, !exportLayoutPrototypes);

        if (exportLayoutPrototypes) {
            StagedModelDataHandlerUtil.exportStagedModel(portletDataContext, layoutPrototype);
        }
    }
}

From source file:com.liferay.layout.set.prototype.internal.exportimport.data.handler.LayoutSetPrototypeStagedModelDataHandler.java

License:Open Source License

protected void exportLayouts(LayoutSetPrototype layoutSetPrototype, PortletDataContext portletDataContext)
        throws Exception {

    File file = null;//from   w  w w.  java  2 s . c o  m

    try {
        file = SitesUtil.exportLayoutSetPrototype(layoutSetPrototype, new ServiceContext());

        try (InputStream inputStream = new FileInputStream(file)) {
            String layoutSetPrototypeLARPath = ExportImportPathUtil.getModelPath(layoutSetPrototype,
                    getLayoutSetPrototypeLARFileName(layoutSetPrototype));

            portletDataContext.addZipEntry(layoutSetPrototypeLARPath, inputStream);
        }

        List<Layout> layoutSetPrototypeLayouts = _layoutLocalService.getLayouts(layoutSetPrototype.getGroupId(),
                true);

        Element layoutSetPrototypeElement = portletDataContext.getExportDataElement(layoutSetPrototype);

        for (Layout layoutSetPrototypeLayout : layoutSetPrototypeLayouts) {
            portletDataContext.addReferenceElement(layoutSetPrototype, layoutSetPrototypeElement,
                    layoutSetPrototypeLayout, PortletDataContext.REFERENCE_TYPE_EMBEDDED, false);
        }
    } finally {
        if (file != null) {
            file.delete();
        }
    }
}