Exemple #1
0
  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);
    }
  }
Exemple #2
0
  @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();
  }