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

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

Introduction

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

Prototype

String SKIP

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

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   www .  j av  a  2s. c om
            _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.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;
        }/*from   ww w  .  j  a va  2s.com*/

        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 w w w .  j a  v  a 2s. co  m*/

        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);
    }
}