public KBFolderActionableDynamicQuery() {
    setBaseLocalService(KBFolderLocalServiceUtil.getService());
    setClass(KBFolder.class);

    setClassLoader(com.liferay.knowledgebase.service.ClpSerializer.class.getClassLoader());

    setPrimaryKeyPropertyName("kbFolderId");
  }
  protected boolean isParentFolder(long resourcePrimKey, long kbFolderId)
      throws PortalException, SystemException {

    while (kbFolderId != KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
      if (resourcePrimKey == kbFolderId) {
        return true;
      }

      KBFolder kbFolder = KBFolderLocalServiceUtil.getKBFolder(kbFolderId);

      kbFolderId = kbFolder.getParentKBFolderId();
    }

    return false;
  }
  protected PortletURL getKBArticleURL(
      long plid, String portletId, KBArticle kbArticle, HttpServletRequest request)
      throws Exception {

    long resourcePrimKey = ParamUtil.getLong(request, "resourcePrimKey");

    String mvcPath = null;

    String rootPortletId = PortletConstants.getRootPortletId(portletId);

    if (rootPortletId.equals(PortletKeys.KNOWLEDGE_BASE_ARTICLE)) {
      mvcPath = "/article/view_article.jsp";
    } else if (rootPortletId.equals(PortletKeys.KNOWLEDGE_BASE_SECTION)) {
      mvcPath = "/section/view_article.jsp";
    }

    PortletURL portletURL =
        PortletURLFactoryUtil.create(request, portletId, plid, PortletRequest.RENDER_PHASE);

    if (mvcPath != null) {
      portletURL.setParameter("mvcPath", mvcPath);
    }

    if ((kbArticle == null) || Validator.isNull(kbArticle.getUrlTitle())) {
      portletURL.setParameter("resourcePrimKey", String.valueOf(resourcePrimKey));
    } else {
      portletURL.setParameter("urlTitle", kbArticle.getUrlTitle());

      if (kbArticle.getKbFolderId() != KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

        KBFolder kbFolder = KBFolderLocalServiceUtil.getKBFolder(kbArticle.getKbFolderId());

        portletURL.setParameter("kbFolderUrlTitle", String.valueOf(kbFolder.getUrlTitle()));
      }
    }

    portletURL.setPortletMode(PortletMode.VIEW);

    portletURL.setWindowState(LiferayWindowState.NORMAL);

    if (rootPortletId.equals(PortletKeys.KNOWLEDGE_BASE_SECTION)) {
      portletURL.setWindowState(LiferayWindowState.MAXIMIZED);
    }

    return portletURL;
  }
  @Override
  protected void doExportStagedModel(PortletDataContext portletDataContext, KBArticle kbArticle)
      throws Exception {

    if (kbArticle.getParentResourcePrimKey() != KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

      long kbArticleClassNameId = PortalUtil.getClassNameId(KBArticleConstants.getClassName());

      if (kbArticle.getParentResourceClassNameId() == kbArticleClassNameId) {

        KBArticle parentKBArticle =
            KBArticleLocalServiceUtil.getLatestKBArticle(
                kbArticle.getParentResourcePrimKey(), WorkflowConstants.STATUS_APPROVED);

        StagedModelDataHandlerUtil.exportReferenceStagedModel(
            portletDataContext,
            kbArticle,
            parentKBArticle,
            PortletDataContext.REFERENCE_TYPE_PARENT);
      } else {
        KBFolder parentKBFolder =
            KBFolderLocalServiceUtil.getKBFolder(kbArticle.getParentResourcePrimKey());

        StagedModelDataHandlerUtil.exportReferenceStagedModel(
            portletDataContext,
            kbArticle,
            parentKBFolder,
            PortletDataContext.REFERENCE_TYPE_PARENT);
      }
    }

    Element kbArticleElement = portletDataContext.getExportDataElement(kbArticle);

    exportKBArticleAttachments(portletDataContext, kbArticleElement, kbArticle);

    portletDataContext.addClassedModel(
        kbArticleElement, ExportImportPathUtil.getModelPath(kbArticle), kbArticle);
  }
  public Object invokeMethod(String name, String[] parameterTypes, Object[] arguments)
      throws Throwable {
    if (_methodName0.equals(name) && Arrays.deepEquals(_methodParameterTypes0, parameterTypes)) {
      return KBFolderLocalServiceUtil.addKBFolder(
          (com.liferay.knowledgebase.model.KBFolder) arguments[0]);
    }

    if (_methodName1.equals(name) && Arrays.deepEquals(_methodParameterTypes1, parameterTypes)) {
      return KBFolderLocalServiceUtil.createKBFolder(((Long) arguments[0]).longValue());
    }

    if (_methodName2.equals(name) && Arrays.deepEquals(_methodParameterTypes2, parameterTypes)) {
      return KBFolderLocalServiceUtil.deleteKBFolder(((Long) arguments[0]).longValue());
    }

    if (_methodName3.equals(name) && Arrays.deepEquals(_methodParameterTypes3, parameterTypes)) {
      return KBFolderLocalServiceUtil.deleteKBFolder(
          (com.liferay.knowledgebase.model.KBFolder) arguments[0]);
    }

    if (_methodName4.equals(name) && Arrays.deepEquals(_methodParameterTypes4, parameterTypes)) {
      return KBFolderLocalServiceUtil.dynamicQuery();
    }

    if (_methodName5.equals(name) && Arrays.deepEquals(_methodParameterTypes5, parameterTypes)) {
      return KBFolderLocalServiceUtil.dynamicQuery(
          (com.liferay.portal.kernel.dao.orm.DynamicQuery) arguments[0]);
    }

    if (_methodName6.equals(name) && Arrays.deepEquals(_methodParameterTypes6, parameterTypes)) {
      return KBFolderLocalServiceUtil.dynamicQuery(
          (com.liferay.portal.kernel.dao.orm.DynamicQuery) arguments[0],
          ((Integer) arguments[1]).intValue(),
          ((Integer) arguments[2]).intValue());
    }

    if (_methodName7.equals(name) && Arrays.deepEquals(_methodParameterTypes7, parameterTypes)) {
      return KBFolderLocalServiceUtil.dynamicQuery(
          (com.liferay.portal.kernel.dao.orm.DynamicQuery) arguments[0],
          ((Integer) arguments[1]).intValue(),
          ((Integer) arguments[2]).intValue(),
          (com.liferay.portal.kernel.util.OrderByComparator) arguments[3]);
    }

    if (_methodName8.equals(name) && Arrays.deepEquals(_methodParameterTypes8, parameterTypes)) {
      return KBFolderLocalServiceUtil.dynamicQueryCount(
          (com.liferay.portal.kernel.dao.orm.DynamicQuery) arguments[0]);
    }

    if (_methodName9.equals(name) && Arrays.deepEquals(_methodParameterTypes9, parameterTypes)) {
      return KBFolderLocalServiceUtil.dynamicQueryCount(
          (com.liferay.portal.kernel.dao.orm.DynamicQuery) arguments[0],
          (com.liferay.portal.kernel.dao.orm.Projection) arguments[1]);
    }

    if (_methodName10.equals(name) && Arrays.deepEquals(_methodParameterTypes10, parameterTypes)) {
      return KBFolderLocalServiceUtil.fetchKBFolder(((Long) arguments[0]).longValue());
    }

    if (_methodName11.equals(name) && Arrays.deepEquals(_methodParameterTypes11, parameterTypes)) {
      return KBFolderLocalServiceUtil.fetchKBFolderByUuidAndCompanyId(
          (java.lang.String) arguments[0], ((Long) arguments[1]).longValue());
    }

    if (_methodName12.equals(name) && Arrays.deepEquals(_methodParameterTypes12, parameterTypes)) {
      return KBFolderLocalServiceUtil.fetchKBFolderByUuidAndGroupId(
          (java.lang.String) arguments[0], ((Long) arguments[1]).longValue());
    }

    if (_methodName13.equals(name) && Arrays.deepEquals(_methodParameterTypes13, parameterTypes)) {
      return KBFolderLocalServiceUtil.getKBFolder(((Long) arguments[0]).longValue());
    }

    if (_methodName14.equals(name) && Arrays.deepEquals(_methodParameterTypes14, parameterTypes)) {
      return KBFolderLocalServiceUtil.getPersistedModel((java.io.Serializable) arguments[0]);
    }

    if (_methodName15.equals(name) && Arrays.deepEquals(_methodParameterTypes15, parameterTypes)) {
      return KBFolderLocalServiceUtil.getKBFolderByUuidAndCompanyId(
          (java.lang.String) arguments[0], ((Long) arguments[1]).longValue());
    }

    if (_methodName16.equals(name) && Arrays.deepEquals(_methodParameterTypes16, parameterTypes)) {
      return KBFolderLocalServiceUtil.getKBFolderByUuidAndGroupId(
          (java.lang.String) arguments[0], ((Long) arguments[1]).longValue());
    }

    if (_methodName17.equals(name) && Arrays.deepEquals(_methodParameterTypes17, parameterTypes)) {
      return KBFolderLocalServiceUtil.getKBFolders(
          ((Integer) arguments[0]).intValue(), ((Integer) arguments[1]).intValue());
    }

    if (_methodName18.equals(name) && Arrays.deepEquals(_methodParameterTypes18, parameterTypes)) {
      return KBFolderLocalServiceUtil.getKBFoldersCount();
    }

    if (_methodName19.equals(name) && Arrays.deepEquals(_methodParameterTypes19, parameterTypes)) {
      return KBFolderLocalServiceUtil.updateKBFolder(
          (com.liferay.knowledgebase.model.KBFolder) arguments[0]);
    }

    if (_methodName64.equals(name) && Arrays.deepEquals(_methodParameterTypes64, parameterTypes)) {
      return KBFolderLocalServiceUtil.getBeanIdentifier();
    }

    if (_methodName65.equals(name) && Arrays.deepEquals(_methodParameterTypes65, parameterTypes)) {
      KBFolderLocalServiceUtil.setBeanIdentifier((java.lang.String) arguments[0]);

      return null;
    }

    if (_methodName70.equals(name) && Arrays.deepEquals(_methodParameterTypes70, parameterTypes)) {
      return KBFolderLocalServiceUtil.addKBFolder(
          ((Long) arguments[0]).longValue(),
          ((Long) arguments[1]).longValue(),
          ((Long) arguments[2]).longValue(),
          ((Long) arguments[3]).longValue(),
          (java.lang.String) arguments[4],
          (java.lang.String) arguments[5],
          (com.liferay.portal.service.ServiceContext) arguments[6]);
    }

    if (_methodName71.equals(name) && Arrays.deepEquals(_methodParameterTypes71, parameterTypes)) {
      return KBFolderLocalServiceUtil.deleteKBFolder(((Long) arguments[0]).longValue());
    }

    if (_methodName72.equals(name) && Arrays.deepEquals(_methodParameterTypes72, parameterTypes)) {
      return KBFolderLocalServiceUtil.fetchFirstChildKBFolder(
          ((Long) arguments[0]).longValue(), ((Long) arguments[1]).longValue());
    }

    if (_methodName73.equals(name) && Arrays.deepEquals(_methodParameterTypes73, parameterTypes)) {
      return KBFolderLocalServiceUtil.fetchKBFolder(((Long) arguments[0]).longValue());
    }

    if (_methodName74.equals(name) && Arrays.deepEquals(_methodParameterTypes74, parameterTypes)) {
      return KBFolderLocalServiceUtil.fetchKBFolderByUrlTitle(
          ((Long) arguments[0]).longValue(),
          ((Long) arguments[1]).longValue(),
          (java.lang.String) arguments[2]);
    }

    if (_methodName75.equals(name) && Arrays.deepEquals(_methodParameterTypes75, parameterTypes)) {
      return KBFolderLocalServiceUtil.getKBFolderByUrlTitle(
          ((Long) arguments[0]).longValue(),
          ((Long) arguments[1]).longValue(),
          (java.lang.String) arguments[2]);
    }

    if (_methodName76.equals(name) && Arrays.deepEquals(_methodParameterTypes76, parameterTypes)) {
      return KBFolderLocalServiceUtil.getKBFolders(
          ((Long) arguments[0]).longValue(),
          ((Long) arguments[1]).longValue(),
          ((Integer) arguments[2]).intValue(),
          ((Integer) arguments[3]).intValue());
    }

    if (_methodName77.equals(name) && Arrays.deepEquals(_methodParameterTypes77, parameterTypes)) {
      return KBFolderLocalServiceUtil.getKBFoldersCount(
          ((Long) arguments[0]).longValue(), ((Long) arguments[1]).longValue());
    }

    if (_methodName78.equals(name) && Arrays.deepEquals(_methodParameterTypes78, parameterTypes)) {
      KBFolderLocalServiceUtil.moveKBFolder(
          ((Long) arguments[0]).longValue(), ((Long) arguments[1]).longValue());

      return null;
    }

    if (_methodName79.equals(name) && Arrays.deepEquals(_methodParameterTypes79, parameterTypes)) {
      return KBFolderLocalServiceUtil.updateKBFolder(
          ((Long) arguments[0]).longValue(),
          ((Long) arguments[1]).longValue(),
          ((Long) arguments[2]).longValue(),
          (java.lang.String) arguments[3],
          (java.lang.String) arguments[4]);
    }

    throw new UnsupportedOperationException();
  }
  protected Tuple getResourceTuple(RenderRequest renderRequest) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

    String urlTitle = ParamUtil.getString(renderRequest, "urlTitle");

    if (Validator.isNotNull(urlTitle)) {
      String kbFolderUrlTitle = ParamUtil.getString(renderRequest, "kbFolderUrlTitle");

      KBArticle kbArticle = null;

      if (Validator.isNotNull(kbFolderUrlTitle)) {
        kbArticle =
            KBArticleLocalServiceUtil.fetchKBArticleByUrlTitle(
                themeDisplay.getScopeGroupId(), kbFolderUrlTitle, urlTitle);
      } else {
        kbArticle =
            KBArticleLocalServiceUtil.fetchKBArticleByUrlTitle(
                themeDisplay.getScopeGroupId(),
                KBFolderConstants.DEFAULT_PARENT_FOLDER_ID,
                urlTitle);
      }

      if ((kbArticle != null)
          && KBArticlePermission.contains(
              themeDisplay.getPermissionChecker(), kbArticle, ActionKeys.VIEW)) {

        return new Tuple(kbArticle.getClassNameId(), kbArticle.getResourcePrimKey());
      }
    }

    PortletPreferences portletPreferences = renderRequest.getPreferences();

    long defaultResourcePrimKey =
        GetterUtil.getLong(portletPreferences.getValue("resourcePrimKey", null));

    String mvcPath = ParamUtil.getString(renderRequest, "mvcPath");

    if (((defaultResourcePrimKey == 0) && mvcPath.equals(viewTemplate))
        || mvcPath.equals("/display/select_configuration_article.jsp")) {

      return new Tuple(
          PortalUtil.getClassNameId(KBFolderConstants.getClassName()),
          KBFolderConstants.DEFAULT_PARENT_FOLDER_ID);
    }

    long defaultResourceClassNameId =
        GetterUtil.getLong(portletPreferences.getValue("resourceClassNameId", null));

    long resourceClassNameId =
        ParamUtil.getLong(renderRequest, "resourceClassNameId", defaultResourceClassNameId);

    long resourcePrimKey =
        ParamUtil.getLong(renderRequest, "resourcePrimKey", defaultResourcePrimKey);

    if ((resourcePrimKey == 0) || (resourcePrimKey != defaultResourcePrimKey)) {

      return new Tuple(resourceClassNameId, resourcePrimKey);
    }

    long kbFolderClassNameId = PortalUtil.getClassNameId(KBFolderConstants.getClassName());

    if (resourceClassNameId == kbFolderClassNameId) {
      KBFolder kbFolder = KBFolderLocalServiceUtil.fetchKBFolder(resourcePrimKey);

      if ((kbFolder != null)
          && !KBFolderPermission.contains(
              themeDisplay.getPermissionChecker(),
              themeDisplay.getScopeGroupId(),
              defaultResourcePrimKey,
              ActionKeys.VIEW)) {

        return new Tuple(
            PortalUtil.getClassNameId(KBFolderConstants.getClassName()),
            KBFolderConstants.DEFAULT_PARENT_FOLDER_ID);
      }
    } else {
      KBArticle kbArticle =
          KBArticleLocalServiceUtil.fetchLatestKBArticle(
              defaultResourcePrimKey, WorkflowConstants.STATUS_ANY);

      if ((kbArticle != null)
          && !KBArticlePermission.contains(
              themeDisplay.getPermissionChecker(), defaultResourcePrimKey, ActionKeys.VIEW)) {

        return new Tuple(
            PortalUtil.getClassNameId(KBFolderConstants.getClassName()),
            KBFolderConstants.DEFAULT_PARENT_FOLDER_ID);
      }
    }

    return new Tuple(defaultResourceClassNameId, defaultResourcePrimKey);
  }