protected void mergeLayoutSetPrototypeLayouts( Method method, Object[] arguments, Group group, LayoutSet layoutSet, boolean privateLayout, boolean workflowEnabled) { try { if (!SitesUtil.isLayoutSetMergeable(group, layoutSet)) { return; } MergeLayoutPrototypesThreadLocal.setInProgress(true); WorkflowThreadLocal.setEnabled(false); SitesUtil.mergeLayoutSetPrototypeLayouts(group, layoutSet); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Unable to merge layouts for site template", e); } } finally { MergeLayoutPrototypesThreadLocal.setMergeComplete(method, arguments); WorkflowThreadLocal.setEnabled(workflowEnabled); } }
protected boolean isMergeComplete(Method method, Object[] arguments, Group group) { if (MergeLayoutPrototypesThreadLocal.isMergeComplete(method, arguments) && (!group.isUser() || PropsValues.USER_GROUPS_COPY_LAYOUTS_TO_USER_PERSONAL_SITE)) { return true; } else { return false; } }
protected void doTestPortletPreferencesPropagation(boolean linkEnabled, boolean globalScope) throws Exception { setLinkEnabled(linkEnabled); PortletPreferences layoutSetPrototypePortletPreferences = LayoutTestUtil.getPortletPreferences(prototypeLayout, journalContentPortletId); MergeLayoutPrototypesThreadLocal.clearMergeComplete(); layoutSetPrototypePortletPreferences.setValue("articleId", StringPool.BLANK); layoutSetPrototypePortletPreferences.setValue("showAvailableLocales", Boolean.FALSE.toString()); if (globalScope) { layoutSetPrototypePortletPreferences.setValue("groupId", String.valueOf(globalGroupId)); layoutSetPrototypePortletPreferences.setValue("lfrScopeType", "company"); } layoutSetPrototypePortletPreferences.store(); layout = propagateChanges(layout); PortletPreferences portletPreferences = LayoutTestUtil.getPortletPreferences(layout, journalContentPortletId); if (linkEnabled) { if (globalScope) { Assert.assertEquals( StringPool.BLANK, portletPreferences.getValue("articleId", StringPool.BLANK)); } else { // Changes in preferences of local ids are not propagated Assert.assertEquals( journalArticle.getArticleId(), portletPreferences.getValue("articleId", StringPool.BLANK)); } Assert.assertEquals( Boolean.FALSE.toString(), portletPreferences.getValue("showAvailableLocales", StringPool.BLANK)); } else { Assert.assertEquals( journalArticle.getArticleId(), portletPreferences.getValue("articleId", StringPool.BLANK)); } }
protected Layout propagateChanges(Layout layout) throws Exception { MergeLayoutPrototypesThreadLocal.clearMergeComplete(); return LayoutLocalServiceUtil.getLayout(layout.getPlid()); }
private LayoutRevision _getLayoutRevision(Layout layout, LayoutRevision layoutRevision) throws PortalException, SystemException { if (layoutRevision != null) { return layoutRevision; } ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext(); if (!serviceContext.isSignedIn()) { LayoutRevision lastLayoutRevision = null; lastLayoutRevision = LayoutRevisionLocalServiceUtil.fetchLastLayoutRevision(layout.getPlid(), true); if (lastLayoutRevision == null) { lastLayoutRevision = LayoutRevisionLocalServiceUtil.fetchLastLayoutRevision(layout.getPlid(), false); } return lastLayoutRevision; } User user = UserLocalServiceUtil.getUser(serviceContext.getUserId()); long layoutSetBranchId = ParamUtil.getLong(serviceContext, "layoutSetBranchId"); LayoutSet layoutSet = layout.getLayoutSet(); LayoutSetBranch layoutSetBranch = LayoutSetBranchLocalServiceUtil.getUserLayoutSetBranch( serviceContext.getUserId(), layout.getGroupId(), layout.isPrivateLayout(), layoutSet.getLayoutSetId(), layoutSetBranchId); layoutSetBranchId = layoutSetBranch.getLayoutSetBranchId(); long layoutRevisionId = ParamUtil.getLong(serviceContext, "layoutRevisionId"); if (layoutRevisionId <= 0) { layoutRevisionId = StagingUtil.getRecentLayoutRevisionId(user, layoutSetBranchId, layout.getPlid()); } if (layoutRevisionId > 0) { layoutRevision = LayoutRevisionLocalServiceUtil.fetchLayoutRevision(layoutRevisionId); if (layoutRevision.getStatus() != WorkflowConstants.STATUS_INACTIVE) { return layoutRevision; } layoutRevision = null; } List<LayoutRevision> layoutRevisions = LayoutRevisionLocalServiceUtil.getLayoutRevisions( layoutSetBranchId, layout.getPlid(), QueryUtil.ALL_POS, QueryUtil.ALL_POS, new LayoutRevisionCreateDateComparator(true)); if (!layoutRevisions.isEmpty()) { layoutRevision = layoutRevisions.get(0); for (LayoutRevision curLayoutRevision : layoutRevisions) { if (curLayoutRevision.isHead()) { layoutRevision = curLayoutRevision; break; } } } if (layoutRevision != null) { StagingUtil.setRecentLayoutRevisionId( user, layoutSetBranchId, layout.getPlid(), layoutRevision.getLayoutRevisionId()); return layoutRevision; } LayoutBranch layoutBranch = LayoutBranchLocalServiceUtil.getMasterLayoutBranch( layoutSetBranchId, layout.getPlid(), serviceContext); if (!MergeLayoutPrototypesThreadLocal.isInProgress()) { serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT); } return LayoutRevisionLocalServiceUtil.addLayoutRevision( serviceContext.getUserId(), layoutSetBranchId, layoutBranch.getLayoutBranchId(), LayoutRevisionConstants.DEFAULT_PARENT_LAYOUT_REVISION_ID, false, layout.getPlid(), LayoutConstants.DEFAULT_PLID, layout.isPrivateLayout(), layout.getName(), layout.getTitle(), layout.getDescription(), layout.getKeywords(), layout.getRobots(), layout.getTypeSettings(), layout.getIconImage(), layout.getIconImageId(), layout.getThemeId(), layout.getColorSchemeId(), layout.getWapThemeId(), layout.getWapColorSchemeId(), layout.getCss(), serviceContext); }
@Override public Object invoke(MethodInvocation methodInvocation) throws Throwable { if (MergeLayoutPrototypesThreadLocal.isInProgress()) { return methodInvocation.proceed(); } Method method = methodInvocation.getMethod(); String methodName = method.getName(); Class<?>[] parameterTypes = method.getParameterTypes(); Object[] arguments = methodInvocation.getArguments(); boolean workflowEnabled = WorkflowThreadLocal.isEnabled(); if (methodName.equals("getLayout") && (Arrays.equals(parameterTypes, _TYPES_L) || Arrays.equals(parameterTypes, _TYPES_L_B_L))) { Layout layout = (Layout) methodInvocation.proceed(); Group group = layout.getGroup(); if (isMergeComplete(method, arguments, group)) { return layout; } if (Validator.isNull(layout.getLayoutPrototypeUuid()) && Validator.isNull(layout.getSourcePrototypeLayoutUuid())) { return layout; } LayoutSet layoutSet = layout.getLayoutSet(); try { MergeLayoutPrototypesThreadLocal.setInProgress(true); WorkflowThreadLocal.setEnabled(false); SitesUtil.mergeLayoutPrototypeLayout(group, layout); if (Validator.isNotNull(layout.getSourcePrototypeLayoutUuid())) { SitesUtil.mergeLayoutSetPrototypeLayouts(group, layoutSet); } } finally { MergeLayoutPrototypesThreadLocal.setMergeComplete(method, arguments); WorkflowThreadLocal.setEnabled(workflowEnabled); } } else if (methodName.equals("getLayouts") && (Arrays.equals(parameterTypes, _TYPES_L_B_L) || Arrays.equals(parameterTypes, _TYPES_L_B_L_B_I_I))) { long groupId = (Long) arguments[0]; Group group = GroupLocalServiceUtil.getGroup(groupId); if (isMergeComplete(method, arguments, group)) { return methodInvocation.proceed(); } boolean privateLayout = (Boolean) arguments[1]; long parentLayoutId = (Long) arguments[2]; try { LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(groupId, privateLayout); mergeLayoutSetPrototypeLayouts( method, arguments, group, layoutSet, privateLayout, workflowEnabled); List<Layout> layouts = (List<Layout>) methodInvocation.proceed(); if (PropsValues.USER_GROUPS_COPY_LAYOUTS_TO_USER_PERSONAL_SITE) { return layouts; } if (group.isUser()) { _virtualLayoutTargetGroupId.set(group.getGroupId()); if (parentLayoutId == LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) { return addUserGroupLayouts(group, layoutSet, layouts, parentLayoutId); } else { return addChildUserGroupLayouts(group, layouts); } } else if (group.isUserGroup() && (parentLayoutId != LayoutConstants.DEFAULT_PARENT_LAYOUT_ID)) { long targetGroupId = _virtualLayoutTargetGroupId.get(); if (targetGroupId != GroupConstants.DEFAULT_LIVE_GROUP_ID) { Group targetGroup = GroupLocalServiceUtil.getGroup(targetGroupId); return addChildUserGroupLayouts(targetGroup, layouts); } } return layouts; } catch (Exception e) { _log.error(e, e); throw e; } } return methodInvocation.proceed(); }