Example usage for com.liferay.portal.kernel.util Constants ACTION

List of usage examples for com.liferay.portal.kernel.util Constants ACTION

Introduction

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

Prototype

String ACTION

To view the source code for com.liferay.portal.kernel.util Constants ACTION.

Click Source Link

Usage

From source file:com.liferay.exportimport.controller.LayoutImportController.java

License:Open Source License

protected void validateLayoutPrototypes(long companyId, Element headerElement, Element layoutsElement)
        throws Exception {

    List<Tuple> missingLayoutPrototypes = new ArrayList<>();

    String layoutSetPrototypeUuid = headerElement.attributeValue("layout-set-prototype-uuid");

    if (Validator.isNotNull(layoutSetPrototypeUuid)) {
        try {//from  w  w w .  j a  v  a2s .com
            _layoutSetPrototypeLocalService.getLayoutSetPrototypeByUuidAndCompanyId(layoutSetPrototypeUuid,
                    companyId);
        } catch (NoSuchLayoutSetPrototypeException nslspe) {

            // LPS-52675

            if (_log.isDebugEnabled()) {
                _log.debug(nslspe, nslspe);
            }

            String layoutSetPrototypeName = headerElement.attributeValue("layout-set-prototype-name");

            missingLayoutPrototypes.add(new Tuple(LayoutSetPrototype.class.getName(), layoutSetPrototypeUuid,
                    layoutSetPrototypeName));
        }
    }

    List<Element> layoutElements = layoutsElement.elements();

    for (Element layoutElement : layoutElements) {
        String action = layoutElement.attributeValue(Constants.ACTION);

        if (action.equals(Constants.SKIP)) {
            continue;
        }

        String layoutPrototypeUuid = GetterUtil
                .getString(layoutElement.attributeValue("layout-prototype-uuid"));

        if (Validator.isNotNull(layoutPrototypeUuid)) {
            try {
                _layoutPrototypeLocalService.getLayoutPrototypeByUuidAndCompanyId(layoutPrototypeUuid,
                        companyId);
            } catch (NoSuchLayoutPrototypeException nslpe) {

                // LPS-52675

                if (_log.isDebugEnabled()) {
                    _log.debug(nslpe, nslpe);
                }

                String layoutPrototypeName = GetterUtil
                        .getString(layoutElement.attributeValue("layout-prototype-name"));

                missingLayoutPrototypes.add(
                        new Tuple(LayoutPrototype.class.getName(), layoutPrototypeUuid, layoutPrototypeName));
            }
        }
    }

    if (!missingLayoutPrototypes.isEmpty()) {
        throw new LayoutPrototypeException(missingLayoutPrototypes);
    }
}

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

License:Open Source License

@Override
protected void doExportStagedModel(PortletDataContext portletDataContext, Layout layout) throws Exception {

    Element layoutElement = portletDataContext.getExportDataElement(layout);

    populateElementLayoutMetadata(layoutElement, layout);

    layoutElement.addAttribute(Constants.ACTION, Constants.ADD);

    portletDataContext.setPlid(layout.getPlid());

    long parentLayoutId = layout.getParentLayoutId();

    if (parentLayoutId != LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
        Layout parentLayout = _layoutLocalService.fetchLayout(layout.getGroupId(), layout.isPrivateLayout(),
                parentLayoutId);// w  w  w .  jav  a 2 s . co m

        if (parentLayout != null) {
            StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, layout, parentLayout,
                    PortletDataContext.REFERENCE_TYPE_PARENT);

            layoutElement.addAttribute("parent-layout-uuid", parentLayout.getUuid());
        }
    }

    List<LayoutFriendlyURL> layoutFriendlyURLs = _layoutFriendlyURLLocalService
            .getLayoutFriendlyURLs(layout.getPlid());

    for (LayoutFriendlyURL layoutFriendlyURL : layoutFriendlyURLs) {
        StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, layout, layoutFriendlyURL,
                PortletDataContext.REFERENCE_TYPE_DEPENDENCY);
    }

    if (layout.isIconImage()) {
        exportLayoutIconImage(portletDataContext, layout, layoutElement);
    }

    if (Objects.equals(layout.getType(), LayoutConstants.TYPE_LINK_TO_LAYOUT)) {

        exportLinkedLayout(portletDataContext, layout, layoutElement);
    } else if (Objects.equals(layout.getType(), LayoutConstants.TYPE_PORTLET)) {

        exportLayoutPortlets(portletDataContext, layout, layoutElement);
    }

    fixExportTypeSettings(layout);

    exportTheme(portletDataContext, layout);

    portletDataContext.addClassedModel(layoutElement, ExportImportPathUtil.getModelPath(layout),
            LayoutStagingUtil.mergeLayoutRevisionIntoLayout(layout));
}

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

License:Open Source License

protected void exportLayouts(PortletDataContext portletDataContext, StagedLayoutSet stagedLayoutSet) {

    // Force to always export layout deletions

    portletDataContext.addDeletionSystemEventStagedModelTypes(new StagedModelType(Layout.class));

    // Force to always have a layout group element

    portletDataContext.getExportDataGroupElement(Layout.class);

    long[] layoutIds = portletDataContext.getLayoutIds();
    List<StagedModel> stagedModels = _stagedLayoutSetStagedModelRepository
            .fetchChildrenStagedModels(portletDataContext, stagedLayoutSet);

    for (StagedModel stagedModel : stagedModels) {
        Layout layout = (Layout) stagedModel;

        if (!ArrayUtil.contains(layoutIds, layout.getLayoutId())) {
            Element layoutElement = portletDataContext.getExportDataElement(layout);

            layoutElement.addAttribute(Constants.ACTION, Constants.SKIP);

            continue;
        }//w w  w . java 2  s.c o  m

        try {
            if (!LayoutStagingUtil.prepareLayoutStagingHandler(portletDataContext, layout)) {

                continue;
            }

            StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, stagedLayoutSet, layout,
                    PortletDataContext.REFERENCE_TYPE_CHILD);
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn("Unable to export layout " + layout.getName(), e);
            }
        }
    }
}

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

License:Open Source License

protected void updateLayoutPriorities(PortletDataContext portletDataContext, List<Element> layoutElements,
        boolean privateLayout) {

    Map<Long, Layout> layouts = (Map<Long, Layout>) portletDataContext
            .getNewPrimaryKeysMap(Layout.class + ".layout");

    Map<Long, Integer> layoutPriorities = new HashMap<>();

    int maxPriority = Integer.MIN_VALUE;

    for (Element layoutElement : layoutElements) {
        String action = layoutElement.attributeValue(Constants.ACTION);

        if (action.equals(Constants.SKIP)) {

            // We only want to update priorites if there are no elements
            // with the SKIP action

            return;
        }//from   www.j a va2s.  com

        if (action.equals(Constants.ADD)) {
            long layoutId = GetterUtil.getLong(layoutElement.attributeValue("layout-id"));

            Layout layout = layouts.get(layoutId);

            // Layout might not have been imported due to a controlled
            // error. See SitesImpl#addMergeFailFriendlyURLLayout.

            if (layout == null) {
                continue;
            }

            int layoutPriority = GetterUtil.getInteger(layoutElement.attributeValue("layout-priority"));

            layoutPriorities.put(layout.getPlid(), layoutPriority);

            if (maxPriority < layoutPriority) {
                maxPriority = layoutPriority;
            }
        }
    }

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

    for (Layout layout : layoutSetLayouts) {
        if (layoutPriorities.containsKey(layout.getPlid())) {
            layout.setPriority(layoutPriorities.get(layout.getPlid()));
        } else {
            layout.setPriority(++maxPriority);
        }

        _layoutLocalService.updateLayout(layout);
    }
}