Skip to content

Commit

Permalink
LPD-44292 Extract logic into an util class
Browse files Browse the repository at this point in the history
  • Loading branch information
ealonso authored and brianchandotcom committed Dec 17, 2024
1 parent c21c697 commit 6181859
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* SPDX-FileCopyrightText: (c) 2024 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/

package com.liferay.headless.admin.site.internal.resource.util.layout.structure;

import com.liferay.headless.admin.site.dto.v1_0.PageElement;
import com.liferay.layout.util.structure.LayoutStructure;
import com.liferay.portal.kernel.util.Validator;

/**
* @author Eudaldo Alonso
*/
public class LayoutStructureUtil {

public static String getParentExternalReferenceCode(
PageElement pageElement, LayoutStructure layoutStructure) {

String parentExternalReferenceCode =
pageElement.getParentExternalReferenceCode();

if (Validator.isNotNull(parentExternalReferenceCode)) {
return parentExternalReferenceCode;
}

return layoutStructure.getMainItemId();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.liferay.fragment.service.FragmentEntryLocalService;
import com.liferay.headless.admin.site.dto.v1_0.PageElement;
import com.liferay.headless.admin.site.internal.resource.util.GroupUtil;
import com.liferay.headless.admin.site.internal.resource.util.layout.structure.LayoutStructureUtil;
import com.liferay.headless.admin.site.internal.resource.util.layout.structure.item.importer.CollectionItemLayoutStructureItemImporter;
import com.liferay.headless.admin.site.internal.resource.util.layout.structure.item.importer.CollectionLayoutStructureItemImporter;
import com.liferay.headless.admin.site.internal.resource.util.layout.structure.item.importer.ColumnLayoutStructureItemImporter;
Expand All @@ -33,7 +34,6 @@
import com.liferay.portal.kernel.feature.flag.FeatureFlagManagerUtil;
import com.liferay.portal.kernel.model.Layout;
import com.liferay.portal.kernel.service.LayoutLocalService;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.vulcan.dto.converter.DTOConverter;
import com.liferay.portal.vulcan.dto.converter.DTOConverterContext;
import com.liferay.portal.vulcan.dto.converter.DefaultDTOConverterContext;
Expand Down Expand Up @@ -383,7 +383,8 @@ public PageElement putSiteSiteByExternalReferenceCodePageElement(

layoutStructure.moveLayoutStructureItem(
layoutStructureItem.getItemId(),
_getParentExternalReferenceCode(pageElement, layoutStructure),
LayoutStructureUtil.getParentExternalReferenceCode(
pageElement, layoutStructure),
pageElement.getPosition());

_layoutPageTemplateStructureLocalService.
Expand Down Expand Up @@ -488,19 +489,6 @@ private DTOConverterContext _getDTOConverterContext(
return dtoConverterContext;
}

private String _getParentExternalReferenceCode(
PageElement pageElement, LayoutStructure layoutStructure) {

String parentExternalReferenceCode =
pageElement.getParentExternalReferenceCode();

if (Validator.isNotNull(parentExternalReferenceCode)) {
return parentExternalReferenceCode;
}

return layoutStructure.getMainItemId();
}

@Reference
private FragmentCollectionContributorRegistry
_fragmentCollectionContributorRegistry;
Expand Down

0 comments on commit 6181859

Please sign in to comment.