Skip to content

Commit

Permalink
Add try catch for importing pages so that the initializer does not fa…
Browse files Browse the repository at this point in the history
…il due to a page import error.
  • Loading branch information
ethib137 committed Mar 15, 2021
1 parent 4aefe1c commit abbabfb
Showing 1 changed file with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.liferay.layout.util.structure.LayoutStructure;
import com.liferay.petra.string.StringBundler;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.json.JSONArray;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONObject;
Expand Down Expand Up @@ -488,9 +489,14 @@ private void _addLayoutPageTemplateEntries() throws Exception {
File file = _generateZipFile(
pathKeyValuePairs, numberValuesMap, stringValuesMap);

_layoutPageTemplatesImporter.importFile(
_serviceContext.getUserId(), _serviceContext.getScopeGroupId(),
file, false);
try {
_layoutPageTemplatesImporter.importFile(
_serviceContext.getUserId(), _serviceContext.getScopeGroupId(),
file, false);
}
catch (Exception e) {
_log.error(e);
}
}

private void _addLayouts() throws Exception {
Expand Down Expand Up @@ -930,8 +936,7 @@ private String _getTokenFromName(String name) {
}

private void _importPageDefinition(
Layout draftLayout, JSONObject pageDefinitionJSONObject)
throws Exception {
Layout draftLayout, JSONObject pageDefinitionJSONObject) {

if (!pageDefinitionJSONObject.has("pageElement")) {
return;
Expand All @@ -946,10 +951,19 @@ private void _importPageDefinition(
return;
}

LayoutPageTemplateStructure layoutPageTemplateStructure =
_layoutPageTemplateStructureLocalService.
fetchLayoutPageTemplateStructure(
draftLayout.getGroupId(), draftLayout.getPlid(), true);
LayoutPageTemplateStructure layoutPageTemplateStructure;

try {
layoutPageTemplateStructure =
_layoutPageTemplateStructureLocalService.
fetchLayoutPageTemplateStructure(
draftLayout.getGroupId(), draftLayout.getPlid(), true);
}
catch (PortalException pe) {
_log.error(pe);

return;
}

LayoutStructure layoutStructure = LayoutStructure.of(
layoutPageTemplateStructure.getData(
Expand All @@ -959,9 +973,15 @@ private void _importPageDefinition(
"pageElements");

for (int j = 0; j < pageElementsJSONArray.length(); j++) {
_layoutPageTemplatesImporter.importPageElement(
draftLayout, layoutStructure, layoutStructure.getMainItemId(),
pageElementsJSONArray.getString(j), j);
try {
_layoutPageTemplatesImporter.importPageElement(
draftLayout, layoutStructure,
layoutStructure.getMainItemId(),
pageElementsJSONArray.getString(j), j);
}
catch (Exception e) {
_log.error(e);
}
}
}

Expand Down

0 comments on commit abbabfb

Please sign in to comment.