@Override
  public void init(PortletConfig portletConfig) throws PortletException {
    if (portletConfig instanceof PortletConfigImpl) {
      PortletConfigurationPortletPortletConfig portletConfigurationPortletPortletConfig =
          new PortletConfigurationPortletPortletConfig((PortletConfigImpl) portletConfig);

      super.init(portletConfigurationPortletPortletConfig);
    } else {
      super.init(portletConfig);
    }
  }
  @Override
  protected void doDispatch(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    try {
      String mvcPath = renderRequest.getParameter("mvcPath");

      if (mvcPath.equals("/edit_permissions.jsp")) {
        checkEditPermissionsJSP(renderRequest);

        super.doDispatch(renderRequest, renderResponse);

        return;
      }

      Portlet portlet = ActionUtil.getPortlet(renderRequest);

      if (mvcPath.endsWith("edit_configuration.jsp")) {
        ThemeDisplay themeDisplay =
            (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

        String settingsScope = renderRequest.getParameter("settingsScope");

        PortletPreferences portletPreferences =
            getPortletPreferences(themeDisplay, portlet.getPortletId(), settingsScope);

        renderRequest = ActionUtil.getWrappedRenderRequest(renderRequest, portletPreferences);

        renderEditConfiguration(renderRequest, portlet);
      } else {
        PortletPreferences portletPreferences =
            ActionUtil.getLayoutPortletSetup(renderRequest, portlet);

        renderRequest = ActionUtil.getWrappedRenderRequest(renderRequest, portletPreferences);

        if (mvcPath.endsWith("edit_public_render_parameters.jsp")) {
          renderEditPublicParameters(renderRequest, portlet);
        }
      }

      renderResponse.setTitle(ActionUtil.getTitle(portlet, renderRequest));

      super.doDispatch(renderRequest, renderResponse);
    } catch (Exception e) {
      _log.error(e.getMessage());

      SessionErrors.add(renderRequest, e.getClass());

      include("/error.jsp", renderRequest, renderResponse);
    }
  }
  @Override
  protected void doDispatch(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    try {
      getGroup(renderRequest);
    } catch (Exception e) {
      if (e instanceof NoSuchGroupException || e instanceof PrincipalException) {

        SessionErrors.add(renderRequest, e.getClass());
      } else {
        throw new PortletException(e);
      }
    }

    if (SessionErrors.contains(renderRequest, NoSuchGroupException.class.getName())
        || SessionErrors.contains(renderRequest, PrincipalException.getNestedClasses())) {

      include("/error.jsp", renderRequest, renderResponse);
    } else {
      try {
        ServiceContext serviceContext = ServiceContextFactory.getInstance(renderRequest);

        ServiceContextThreadLocal.pushServiceContext(serviceContext);
      } catch (Exception e) {
        if (_log.isWarnEnabled()) {
          _log.warn(e, e);
        }
      }

      renderRequest.setAttribute(ApplicationListWebKeys.GROUP_PROVIDER, groupProvider);

      super.doDispatch(renderRequest, renderResponse);
    }
  }
  @Override
  public void render(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    try {
      HttpServletRequest httpServletRequest = PortalUtil.getHttpServletRequest(renderRequest);

      httpServletRequest = PortalUtil.getOriginalServletRequest(httpServletRequest);

      String oAuthVerifier = httpServletRequest.getParameter(OAuthConstants.VERIFIER);

      if (oAuthVerifier != null) {
        updateAccessToken(renderRequest, oAuthVerifier);
      }

      String remoteMVCPath = renderRequest.getParameter("remoteMVCPath");

      if (remoteMVCPath != null) {
        remoteRender(renderRequest, renderResponse);

        return;
      }
    } catch (IOException ioe) {
      throw ioe;
    } catch (Exception e) {
      throw new PortletException(e);
    }

    super.render(renderRequest, renderResponse);
  }
  @Override
  protected void doDispatch(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    setAttributes(renderRequest);

    long roleId = ParamUtil.getLong(renderRequest, "roleId");

    if (SessionErrors.contains(renderRequest, RequiredRoleException.class.getName())
        && (roleId < 1)) {

      include("/view.jsp", renderRequest, renderResponse);
    } else if (SessionErrors.contains(renderRequest, DuplicateRoleException.class.getName())
        || SessionErrors.contains(renderRequest, RequiredRoleException.class.getName())
        || SessionErrors.contains(renderRequest, RoleNameException.class.getName())) {

      include("/edit_role.jsp", renderRequest, renderResponse);
    } else if (SessionErrors.contains(renderRequest, NoSuchRoleException.class.getName())
        || SessionErrors.contains(renderRequest, PrincipalException.getNestedClasses())
        || SessionErrors.contains(renderRequest, RoleAssignmentException.class.getName())
        || SessionErrors.contains(renderRequest, RolePermissionsException.class.getName())) {

      include("/error.jsp", renderRequest, renderResponse);
    } else {
      super.doDispatch(renderRequest, renderResponse);
    }
  }
  @Override
  public void render(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    renderRequest.setAttribute(JournalWebKeys.JOURNAL_CONTENT, _journalContent);

    super.render(renderRequest, renderResponse);
  }
  @Override
  public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
      throws IOException, PortletException {

    setAttributes(resourceRequest);

    super.serveResource(resourceRequest, resourceResponse);
  }
  @Override
  public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
      throws IOException, PortletException {

    super.processAction(actionRequest, actionResponse);

    MultiSessionMessages.add(
        actionRequest, PortalUtil.getPortletId(actionRequest) + "requestProcessed");
  }
  @Override
  public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
      throws IOException, PortletException {

    _portletRequestThreadLocal.set(actionRequest);

    actionRequest.setAttribute(JavaConstants.JAVAX_PORTLET_CONFIG, getPortletConfig());

    super.processAction(actionRequest, actionResponse);
  }
  @Override
  public void processEvent(EventRequest eventRequest, EventResponse eventResponse)
      throws IOException, PortletException {

    _portletRequestThreadLocal.set(eventRequest);

    eventRequest.setAttribute(JavaConstants.JAVAX_PORTLET_CONFIG, getPortletConfig());

    super.processEvent(eventRequest, eventResponse);
  }
  @Override
  public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
      throws IOException, PortletException {

    _portletRequestThreadLocal.set(resourceRequest);

    resourceRequest.setAttribute(JavaConstants.JAVAX_PORTLET_CONFIG, getPortletConfig());

    super.serveResource(resourceRequest, resourceResponse);
  }
  @Override
  protected void doDispatch(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    renderRequest.setAttribute(ApplicationListWebKeys.GROUP_PROVIDER, _groupProvider);
    renderRequest.setAttribute(ApplicationListWebKeys.PANEL_APP_REGISTRY, _panelAppRegistry);
    renderRequest.setAttribute(
        ApplicationListWebKeys.PANEL_CATEGORY_REGISTRY, _panelCategoryRegistry);

    super.doDispatch(renderRequest, renderResponse);
  }
  @Override
  public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
      throws IOException, PortletException {

    super.processAction(actionRequest, actionResponse);

    String actionName = ParamUtil.getString(actionRequest, ActionRequest.ACTION_NAME);

    if (StringUtil.equalsIgnoreCase(actionName, "invokeTaglibDiscussion")) {
      hideDefaultSuccessMessage(actionRequest);
    }
  }
  @Override
  public void render(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    String path = getPath(renderRequest);

    if (Validator.equals(path, "/edit_article.jsp")) {
      renderRequest.setAttribute(JournalWebKeys.ITEM_SELECTOR, _itemSelector);
    }

    super.render(renderRequest, renderResponse);
  }
  @Override
  public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
      throws IOException, PortletException {

    String resourceID = GetterUtil.getString(resourceRequest.getResourceID());

    if (resourceID.equals("exportArticle")) {
      _exportArticleUtil.sendFile(resourceRequest, resourceResponse);
    } else {
      resourceRequest.setAttribute(JournalWebKeys.JOURNAL_CONTENT, _journalContent);

      super.serveResource(resourceRequest, resourceResponse);
    }
  }
  @Override
  protected void doDispatch(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    if (SessionErrors.contains(renderRequest, PrincipalException.getNestedClasses())
        || SessionErrors.contains(renderRequest, WorkflowException.class.getName())) {

      hideDefaultErrorMessage(renderRequest);

      include("/error.jsp", renderRequest, renderResponse);
    } else {
      super.doDispatch(renderRequest, renderResponse);
    }
  }
  @Override
  public void render(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    ItemSelectorRendering itemSelectorRendering =
        _itemSelector.getItemSelectorRendering(renderRequest, renderResponse);

    LocalizedItemSelectorRendering localizedItemSelectorRendering =
        new LocalizedItemSelectorRendering(renderRequest.getLocale(), itemSelectorRendering);

    localizedItemSelectorRendering.store(renderRequest);

    super.render(renderRequest, renderResponse);
  }
  @Override
  protected void doDispatch(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    if (SessionErrors.contains(renderRequest, NoSuchArticleException.class.getName())
        || SessionErrors.contains(renderRequest, NoSuchFeedException.class.getName())
        || SessionErrors.contains(renderRequest, NoSuchFolderException.class.getName())
        || SessionErrors.contains(renderRequest, NoSuchStructureException.class.getName())
        || SessionErrors.contains(renderRequest, NoSuchTemplateException.class.getName())
        || SessionErrors.contains(renderRequest, PrincipalException.getNestedClasses())) {

      include("/portlet/journal/html/error.jsp", renderRequest, renderResponse);
    } else {
      super.doDispatch(renderRequest, renderResponse);
    }
  }
  @Override
  public void render(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

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

    if (mvcPath.equals("/edit_entry.jsp")) {
      JSONArray serviceClassNamesToContextNamesJSONArray =
          getServiceClassNamesToContextNamesJSONArray();

      renderRequest.setAttribute(
          SAPWebKeys.SERVICE_CLASS_NAMES_TO_CONTEXT_NAMES,
          serviceClassNamesToContextNamesJSONArray);
    }

    super.render(renderRequest, renderResponse);
  }
  @Override
  public void init() throws PortletException {

    if (FirebaseApp.getApps().size() < 1) {
      FirebaseOptions options =
          new FirebaseOptions.Builder()
              .setDatabaseUrl("https://lfvo-test.firebaseio.com/")
              .setServiceAccount(
                  AppManagerPortlet.class
                      .getClassLoader()
                      .getResourceAsStream("firebase-service-account.json"))
              .build();
      FirebaseApp.initializeApp(options);
    }

    super.init();
  }
  @Override
  public void render(RenderRequest request, RenderResponse response)
      throws IOException, PortletException {

    try {
      setWorkflowTaskRenderRequestAttribute(request);
    } catch (Exception e) {
      if (isSessionErrorException(e)) {
        hideDefaultErrorMessage(request);

        SessionErrors.add(request, e.getClass());
      } else {
        throw new PortletException(e);
      }
    }

    super.render(request, response);
  }
  @Override
  protected void doDispatch(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    if (SessionErrors.contains(renderRequest, NoSuchUserGroupException.class.getName())
        || SessionErrors.contains(renderRequest, PrincipalException.getNestedClasses())) {

      include("/error.jsp", renderRequest, renderResponse);
    } else if (SessionErrors.contains(renderRequest, RequiredUserGroupException.class.getName())) {

      include("/view.jsp", renderRequest, renderResponse);
    } else if (SessionErrors.contains(renderRequest, DuplicateUserGroupException.class.getName())
        || SessionErrors.contains(renderRequest, UserGroupNameException.class.getName())) {

      include("/edit_user_group.jsp", renderRequest, renderResponse);
    } else {
      super.doDispatch(renderRequest, renderResponse);
    }
  }
Esempio n. 23
0
  @Override
  public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
      throws IOException, PortletException {

    try {
      String actionName = ParamUtil.getString(actionRequest, ActionRequest.ACTION_NAME);

      getActionMethod(actionName);

      super.processAction(actionRequest, actionResponse);

      return;
    } catch (NoSuchMethodException nsme) {
    }

    try {
      remoteProcessAction(actionRequest, actionResponse);
    } catch (IOException ioe) {
      throw ioe;
    } catch (Exception e) {
      throw new PortletException(e);
    }
  }
  public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
    HashMap<Date, ArrayList<HashMap<String, Object>>> resultado =
        new HashMap<Date, ArrayList<HashMap<String, Object>>>();
    List<TimeLinePopUp> listaPopUps = new ArrayList<TimeLinePopUp>();

    PortletPreferences prefs = renderRequest.getPreferences();
    String showInMain = prefs.getValue("showInMain", "true");
    String showItems = prefs.getValue("showItems", "true");
    String showAlerts = prefs.getValue("showAlerts", "true");

    // *********************
    // 1) Sites de LIFERAY
    // *********************
    List<Group> offices = new ArrayList<Group>();

    // Si el portlet se muestra en la pagina ppal, recorremos todas las oficianas a partir de un
    // sitio padre leido desde properties
    if (showInMain.equals("true")) {
      String mainSiteGroupId = com.liferay.util.portlet.PortletProps.get("lfvo.main.site.group.id");
      if (mainSiteGroupId != null && !"".equals(mainSiteGroupId)) {
        try {
          offices =
              GroupLocalServiceUtil.getGroups(
                  themeDisplay.getCompanyId(), Long.parseLong(mainSiteGroupId), true);

        } catch (NumberFormatException e) {
          e.printStackTrace();
          offices = GroupLocalServiceUtil.getGroups(themeDisplay.getCompanyId(), 0, true);
        }
      } else {
        offices = GroupLocalServiceUtil.getGroups(themeDisplay.getCompanyId(), 0, true);
      }
      // Si el portlet no se muestra en la pagina ppal, cogemos la oficina del sitio
    } else {
      offices.add(themeDisplay.getScopeGroup());
    }

    // *********************
    // 2) Sites de FIREBASE
    // *********************
    HashMap<String, Object> officesMap = new HashMap<String, Object>();
    try {
      DatabaseReference ref = FirebaseDatabase.getInstance().getReference("/offices/");
      Firebase firebase = new Firebase(ref.toString());
      FirebaseResponse response = firebase.get();
      officesMap = (HashMap<String, Object>) response.getBody();

    } catch (FirebaseException e2) {
      e2.printStackTrace();
    }

    if (officesMap != null) {
      for (Group office : offices) {

        HashMap<String, Object> officeBD =
            (HashMap<String, Object>)
                officesMap.get(
                    String.valueOf(office.getGroupId())); // Site Firebase <> Site Liferay
        if (officeBD != null) {

          try {
            List<Item> items = ItemLocalServiceUtil.getItems(office.getGroupId(), -1, -1);
            for (Item item : items) {

              // Si s�lo mostramos ITEMS y no ALERTS...
              if (showItems.equals("true") & showAlerts.equals("false")) {
                if (!"".equals(item.getType())
                    & !item.getType()
                        .equals("office")) { // Si tiene tipo, pero no es 'office' descartamos
                  continue;
                }
              }

              // Si s�lo mostramos ALERTS y no ITEMS...
              if (showItems.equals("false") & showAlerts.equals("true")) {
                if ("".equals(item.getType())
                    || item.getType()
                        .equals("office")) { // Si es vacio o es 'office' descartamos							
                  continue;
                }
              }

              // Si no mostramos nada...
              if (showItems.equals("false") & showAlerts.equals("false")) {
                continue;
              }

              HashMap<String, Object> miItem = new HashMap<String, Object>();

              // Creamos una fecha con formato simple
              Date createDate = item.getCreateDate();
              String fechaFormat = "";
              String fechaFormatEus = "";
              SimpleDateFormat dt1 = new SimpleDateFormat("dd/MM/yyyy");
              SimpleDateFormat dt2 = new SimpleDateFormat("yyyy/MM/dd");
              if (createDate != null) {
                fechaFormat = dt1.format(item.getCreateDate());
                fechaFormatEus = dt2.format(item.getCreateDate());
              } else {
                fechaFormat = dt1.format(item.getModifiedDate());
                fechaFormatEus = dt2.format(item.getModifiedDate());
              }

              // Quitamos la hora y minutos de la fecha original
              SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
              Date b = new Date();
              try {
                b = formatter.parse(fechaFormat);
              } catch (ParseException e) {

              }

              // PopUp - Mapa Street
              TimeLinePopUp miPopUp = new TimeLinePopUp();
              miPopUp.setDate_es(fechaFormat);
              miPopUp.setDate_eu(fechaFormatEus);
              miPopUp.setName(item.getName());
              miPopUp.setImage(this.obtenerImagenItem(item.getItemId()));
              miPopUp.setLat(String.valueOf(item.getLat()));
              miPopUp.setLng(String.valueOf(item.getLng()));

              listaPopUps.add(miPopUp);

              // HashMaps - Timeline
              miItem.put("image", this.obtenerImagenItem(item.getItemId()));
              miItem.put("name", item.getName());
              miItem.put("desc", item.getDescription());
              miItem.put("lat", item.getLat());
              miItem.put("lng", item.getLng());
              miItem.put("type", item.getType());

              if (resultado.get(b) == null) {
                resultado.put(b, new ArrayList<HashMap<String, Object>>());
              }
              resultado.get(b).add(miItem);
            }
          } catch (PortalException e) {
            e.printStackTrace();
          }
        }
      }
    }

    // Lista de PopUps
    Type listType = new TypeToken<List<TimeLinePopUp>>() {}.getType();
    Gson gson = new Gson();
    String json = gson.toJson(listaPopUps, listType);

    renderRequest.setAttribute("popUps", json);

    // En vez de ordenar el hashmap, ordenamos las keys
    ArrayList<Date> miArray = new ArrayList<Date>();
    for (Date date : resultado.keySet()) {
      miArray.add(date);
    }
    Collections.sort(miArray);

    renderRequest.setAttribute("resultado", resultado);
    renderRequest.setAttribute("orderedKeys", miArray);

    super.doView(renderRequest, renderResponse);
  }
  @Override
  public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
      throws IOException, PortletException {

    String resourceID = GetterUtil.getString(resourceRequest.getResourceID());

    HttpServletRequest request = PortalUtil.getHttpServletRequest(resourceRequest);

    HttpServletResponse response = PortalUtil.getHttpServletResponse(resourceResponse);

    if (resourceID.equals("compareVersions")) {
      ThemeDisplay themeDisplay =
          (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);

      long groupId = ParamUtil.getLong(resourceRequest, "groupId");
      String articleId = ParamUtil.getString(resourceRequest, "articleId");
      double sourceVersion = ParamUtil.getDouble(resourceRequest, "filterSourceVersion");
      double targetVersion = ParamUtil.getDouble(resourceRequest, "filterTargetVersion");
      String languageId = ParamUtil.getString(resourceRequest, "languageId");

      String diffHtmlResults = null;

      try {
        diffHtmlResults =
            JournalUtil.diffHtml(
                groupId,
                articleId,
                sourceVersion,
                targetVersion,
                languageId,
                new PortletRequestModel(resourceRequest, resourceResponse),
                themeDisplay);
      } catch (CompareVersionsException cve) {
        resourceRequest.setAttribute(WebKeys.DIFF_VERSION, cve.getVersion());
      } catch (Exception e) {
        try {
          PortalUtil.sendError(e, request, response);
        } catch (ServletException se) {
        }
      }

      resourceRequest.setAttribute(WebKeys.DIFF_HTML_RESULTS, diffHtmlResults);

      PortletSession portletSession = resourceRequest.getPortletSession();

      PortletContext portletContext = portletSession.getPortletContext();

      PortletRequestDispatcher portletRequestDispatcher =
          portletContext.getRequestDispatcher(
              "/html/taglib/ui/diff_version_comparator/diff_html.jsp");

      portletRequestDispatcher.include(resourceRequest, resourceResponse);
    } else if (resourceID.equals("rss")) {
      try {
        byte[] xml = JournalRSSUtil.getRSS(resourceRequest, resourceResponse);

        ServletResponseUtil.sendFile(request, response, null, xml, ContentTypes.TEXT_XML_UTF8);
      } catch (Exception e) {
        try {
          PortalUtil.sendError(e, request, response);
        } catch (ServletException se) {
        }
      }
    } else {
      super.serveResource(resourceRequest, resourceResponse);
    }
  }
  @Override
  public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    PortletPreferences portletPreferences = renderRequest.getPreferences();

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

    long articleGroupId =
        PrefsParamUtil.getLong(
            portletPreferences, renderRequest, "groupId", themeDisplay.getScopeGroupId());

    String articleId = PrefsParamUtil.getString(portletPreferences, renderRequest, "articleId");
    String ddmTemplateKey =
        PrefsParamUtil.getString(portletPreferences, renderRequest, "ddmTemplateKey");

    JournalArticle article = null;
    JournalArticleDisplay articleDisplay = null;

    if ((articleGroupId > 0) && Validator.isNotNull(articleId)) {
      String viewMode = ParamUtil.getString(renderRequest, "viewMode");
      String languageId = LanguageUtil.getLanguageId(renderRequest);
      int page = ParamUtil.getInteger(renderRequest, "page", 1);

      article =
          _journalArticleLocalService.fetchLatestArticle(
              articleGroupId, articleId, WorkflowConstants.STATUS_APPROVED);

      try {
        if (article == null) {
          article =
              _journalArticleLocalService.getLatestArticle(
                  articleGroupId, articleId, WorkflowConstants.STATUS_ANY);
        }

        double version = article.getVersion();

        if (Validator.isNull(ddmTemplateKey)) {
          ddmTemplateKey = article.getDDMTemplateKey();
        }

        articleDisplay =
            _journalContent.getDisplay(
                articleGroupId,
                articleId,
                version,
                ddmTemplateKey,
                viewMode,
                languageId,
                page,
                new PortletRequestModel(renderRequest, renderResponse),
                themeDisplay);
      } catch (Exception e) {
        renderRequest.removeAttribute(WebKeys.JOURNAL_ARTICLE);

        articleDisplay =
            _journalContent.getDisplay(
                articleGroupId,
                articleId,
                ddmTemplateKey,
                viewMode,
                languageId,
                page,
                new PortletRequestModel(renderRequest, renderResponse),
                themeDisplay);
      }
    }

    if (article != null) {
      renderRequest.setAttribute(WebKeys.JOURNAL_ARTICLE, article);
    }

    if (articleDisplay != null) {
      renderRequest.setAttribute(WebKeys.JOURNAL_ARTICLE_DISPLAY, articleDisplay);
    } else {
      renderRequest.removeAttribute(WebKeys.JOURNAL_ARTICLE_DISPLAY);
    }

    super.doView(renderRequest, renderResponse);
  }
  public void markNotSpamWikiPages(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    long[] wikiPageIds = ParamUtil.getLongValues(actionRequest, "notSpamWikiPageIds");

    List<String> wikiPageLinks = new ArrayList<>();

    for (long wikiPageId : wikiPageIds) {
      WikiPage wikiPage = WikiPageLocalServiceUtil.getPageByPageId(wikiPageId);

      WikiPage latestVersionWikiPage =
          AkismetUtil.getWikiPage(
              wikiPage.getNodeId(), wikiPage.getTitle(), wikiPage.getVersion(), false);

      String latestContent = null;

      if (latestVersionWikiPage != null) {
        latestContent = latestVersionWikiPage.getContent();
      }

      WikiPage previousVersionWikiPage =
          AkismetUtil.getWikiPage(
              wikiPage.getNodeId(), wikiPage.getTitle(), wikiPage.getVersion(), true);

      String previousContent = null;

      if (previousVersionWikiPage != null) {
        previousContent = previousVersionWikiPage.getContent();
      }

      // Selected version

      wikiPage.setStatus(WorkflowConstants.STATUS_APPROVED);
      wikiPage.setSummary(StringPool.BLANK);

      wikiPage = WikiPageLocalServiceUtil.updateWikiPage(wikiPage);

      // Latest version

      if ((latestContent != null)
          && ((previousContent == null) || latestContent.equals(previousContent))) {

        ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

        WikiPageLocalServiceUtil.revertPage(
            themeDisplay.getUserId(),
            wikiPage.getNodeId(),
            wikiPage.getTitle(),
            wikiPage.getVersion(),
            serviceContext);
      } else {
        StringBundler sb = new StringBundler(5);

        sb.append("<a href=\"");

        long plid = PortalUtil.getPlidFromPortletId(wikiPage.getGroupId(), WikiPortletKeys.WIKI);

        LiferayPortletURL liferayPortletURL =
            PortletURLFactoryUtil.create(
                actionRequest, WikiPortletKeys.WIKI, plid, PortletRequest.RENDER_PHASE);

        WikiNode wikiNode = wikiPage.getNode();

        liferayPortletURL.setParameter("struts_action", "/wiki/view");
        liferayPortletURL.setParameter("nodeName", wikiNode.getName());
        liferayPortletURL.setParameter("title", wikiPage.getTitle());
        liferayPortletURL.setParameter("version", String.valueOf(wikiPage.getVersion()));

        sb.append(liferayPortletURL.toString());
        sb.append("\" target=\"_blank\">");
        sb.append(HtmlUtil.escape(wikiPage.getTitle()));
        sb.append("</a>");

        wikiPageLinks.add(sb.toString());
      }

      // Akismet

      if (AkismetUtil.isWikiEnabled(wikiPage.getCompanyId())) {
        AkismetUtil.submitHam(wikiPage);
      }
    }

    if (!wikiPageLinks.isEmpty()) {
      SessionMessages.add(
          actionRequest,
          "anotherUserHasMadeChangesToThesePages",
          StringUtil.merge(wikiPageLinks, "<br />"));

      addSuccessMessage(actionRequest, actionResponse);

      super.sendRedirect(actionRequest, actionResponse);
    }
  }