Ejemplo n.º 1
0
  protected void reindexArticles(long companyId, long startId, long endId) throws Exception {

    List<JournalArticle> articles = new ArrayList<JournalArticle>();

    articles.addAll(getReindexApprovedArticles(companyId, startId, endId));
    articles.addAll(getReindexDraftArticles(companyId, startId, endId));

    if (articles.isEmpty()) {
      return;
    }

    Collection<Document> documents = new ArrayList<Document>(articles.size());

    for (JournalArticle article : articles) {
      if (!article.isIndexable()) {
        continue;
      }

      if (article.isApproved()) {
        JournalArticle latestArticle =
            JournalArticleLocalServiceUtil.getLatestArticle(
                article.getResourcePrimKey(), WorkflowConstants.STATUS_APPROVED);

        if (!latestArticle.isIndexable()) {
          continue;
        }
      }

      Document document = getDocument(article);

      documents.add(document);
    }

    SearchEngineUtil.updateDocuments(getSearchEngineId(), companyId, documents);
  }
Ejemplo n.º 2
0
  @Override
  protected void doReindex(String className, long classPK) throws Exception {
    JournalArticle article =
        JournalArticleLocalServiceUtil.getLatestArticle(classPK, WorkflowConstants.STATUS_APPROVED);

    doReindex(article);
  }
Ejemplo n.º 3
0
  protected void exportJournalArticle(
      PortletDataContext portletDataContext, Layout layout, Element layoutElement)
      throws Exception {

    UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();

    String articleId = typeSettingsProperties.getProperty("article-id", StringPool.BLANK);

    long articleGroupId = layout.getGroupId();

    if (Validator.isNull(articleId)) {
      if (_log.isWarnEnabled()) {
        _log.warn("No article id found in typeSettings of layout " + layout.getPlid());
      }
    }

    JournalArticle article = null;

    try {
      article =
          JournalArticleLocalServiceUtil.getLatestArticle(
              articleGroupId, articleId, WorkflowConstants.STATUS_APPROVED);
    } catch (NoSuchArticleException nsae) {
      if (_log.isWarnEnabled()) {
        _log.warn(
            "No approved article found with group id "
                + articleGroupId
                + " and article id "
                + articleId);
      }
    }

    if (article == null) {
      return;
    }

    String path = JournalPortletDataHandlerImpl.getArticlePath(portletDataContext, article);

    Element articleElement = layoutElement.addElement("article");

    articleElement.addAttribute("path", path);

    Element dlFileEntryTypesElement = layoutElement.addElement("dl-file-entry-types");
    Element dlFoldersElement = layoutElement.addElement("dl-folders");
    Element dlFilesElement = layoutElement.addElement("dl-file-entries");
    Element dlFileRanksElement = layoutElement.addElement("dl-file-ranks");

    JournalPortletDataHandlerImpl.exportArticle(
        portletDataContext,
        layoutElement,
        layoutElement,
        layoutElement,
        dlFileEntryTypesElement,
        dlFoldersElement,
        dlFilesElement,
        dlFileRanksElement,
        article,
        false);
  }
Ejemplo n.º 4
0
  @Override
  public ActionForward render(
      ActionMapping mapping,
      ActionForm form,
      PortletConfig portletConfig,
      RenderRequest renderRequest,
      RenderResponse renderResponse)
      throws Exception {

    PortletPreferences preferences = renderRequest.getPreferences();

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

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

    if (groupId <= 0) {
      groupId = GetterUtil.getLong(preferences.getValue("groupId", StringPool.BLANK));
    }

    String articleId = ParamUtil.getString(renderRequest, "articleId");
    String templateId = ParamUtil.getString(renderRequest, "templateId");

    if (Validator.isNull(articleId)) {
      articleId = GetterUtil.getString(preferences.getValue("articleId", StringPool.BLANK));
      templateId = GetterUtil.getString(preferences.getValue("templateId", StringPool.BLANK));
    }

    String viewMode = ParamUtil.getString(renderRequest, "viewMode");
    String languageId = LanguageUtil.getLanguageId(renderRequest);
    int page = ParamUtil.getInteger(renderRequest, "page", 1);
    String xmlRequest = PortletRequestUtil.toXML(renderRequest, renderResponse);

    JournalArticle article = null;
    JournalArticleDisplay articleDisplay = null;

    if ((groupId > 0) && Validator.isNotNull(articleId)) {
      try {
        article =
            JournalArticleLocalServiceUtil.getLatestArticle(
                groupId, articleId, WorkflowConstants.STATUS_ANY);

        double version = article.getVersion();

        articleDisplay =
            JournalContentUtil.getDisplay(
                groupId,
                articleId,
                version,
                templateId,
                viewMode,
                languageId,
                themeDisplay,
                page,
                xmlRequest);
      } catch (Exception e) {
        renderRequest.removeAttribute(WebKeys.JOURNAL_ARTICLE);

        articleDisplay =
            JournalContentUtil.getDisplay(
                groupId,
                articleId,
                templateId,
                viewMode,
                languageId,
                themeDisplay,
                page,
                xmlRequest);
      }
    }

    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);
    }

    return mapping.findForward("portlet.journal_content.view");
  }
  protected String doExportData(
      PortletDataContext context, String portletId, PortletPreferences preferences)
      throws Exception {

    context.addPermissions("com.liferay.portlet.journal", context.getScopeGroupId());

    String articleId = preferences.getValue("article-id", null);

    if (articleId == null) {
      if (_log.isWarnEnabled()) {
        _log.warn("No article id found in preferences of portlet " + portletId);
      }

      return StringPool.BLANK;
    }

    long articleGroupId = GetterUtil.getLong(preferences.getValue("group-id", StringPool.BLANK));

    if (articleGroupId <= 0) {
      if (_log.isWarnEnabled()) {
        _log.warn("No group id found in preferences of portlet " + portletId);
      }

      return StringPool.BLANK;
    }

    JournalArticle article = null;

    try {
      article =
          JournalArticleLocalServiceUtil.getLatestArticle(
              articleGroupId, articleId, WorkflowConstants.STATUS_APPROVED);
    } catch (NoSuchArticleException nsae) {
      if (_log.isWarnEnabled()) {
        _log.warn(
            "No approved article found with group id "
                + articleGroupId
                + " and article id "
                + articleId);
      }
    }

    if (article == null) {
      return StringPool.BLANK;
    }

    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("journal-content-data");

    String path = JournalPortletDataHandlerImpl.getArticlePath(context, article);

    Element articleElement = rootElement.addElement("article");

    articleElement.addAttribute("path", path);

    Element dlFoldersElement = rootElement.addElement("dl-folders");
    Element dlFilesElement = rootElement.addElement("dl-file-entries");
    Element dlFileRanksElement = rootElement.addElement("dl-file-ranks");
    Element igFoldersElement = rootElement.addElement("ig-folders");
    Element igImagesElement = rootElement.addElement("ig-images");

    JournalPortletDataHandlerImpl.exportArticle(
        context,
        rootElement,
        dlFoldersElement,
        dlFilesElement,
        dlFileRanksElement,
        igFoldersElement,
        igImagesElement,
        article,
        false);

    String structureId = article.getStructureId();

    if (Validator.isNotNull(structureId)) {
      JournalStructure structure =
          JournalStructureUtil.findByG_S(article.getGroupId(), structureId);

      JournalPortletDataHandlerImpl.exportStructure(context, rootElement, structure);
    }

    String templateId = article.getTemplateId();

    if (Validator.isNotNull(templateId)) {
      JournalTemplate template = JournalTemplateUtil.findByG_T(article.getGroupId(), templateId);

      JournalPortletDataHandlerImpl.exportTemplate(
          context,
          rootElement,
          dlFoldersElement,
          dlFilesElement,
          dlFileRanksElement,
          igFoldersElement,
          igImagesElement,
          template);
    }

    return document.formattedString();
  }
Ejemplo n.º 6
0
  @RequestMapping
  public String ver(
      RenderRequest request,
      RenderResponse response,
      @RequestParam(required = false) Integer dias,
      Model model) {
    log.debug("Viendo el versiculo");
    TimeZone tz = null;
    DateTimeZone zone = null;
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    try {
      tz = themeDisplay.getTimeZone();
      zone = DateTimeZone.forID(tz.getID());
    } catch (IllegalArgumentException e) {
      zone = DateTimeZone.forID(ZonaHorariaUtil.getConvertedId(tz.getID()));
    }
    try {
      long scopeGroupId = themeDisplay.getScopeGroupId();

      AssetEntryQuery assetEntryQuery = new AssetEntryQuery();

      DateTime hoy =
          (DateTime)
              request.getPortletSession().getAttribute("hoy", PortletSession.APPLICATION_SCOPE);
      if (hoy == null) {
        hoy = new DateTime(zone);
        log.debug("Subiendo atributo hoy({}) a la sesion", hoy);
        request.getPortletSession().setAttribute("hoy", hoy, PortletSession.APPLICATION_SCOPE);
      }

      // Busca el contenido del dia
      String[] tags = TagsUtil.getTags(new String[4], hoy);
      tags[3] = "versiculo";

      long[] assetTagIds = AssetTagLocalServiceUtil.getTagIds(scopeGroupId, tags);

      assetEntryQuery.setAllTagIds(assetTagIds);

      List<AssetEntry> results = AssetEntryServiceUtil.getEntries(assetEntryQuery);

      log.debug("Buscando el versiculo de la semana {}", hoy);
      for (AssetEntry asset : results) {
        if (asset.getClassName().equals(JournalArticle.class.getName())) {
          JournalArticle ja = JournalArticleLocalServiceUtil.getLatestArticle(asset.getClassPK());
          String contenido =
              JournalArticleLocalServiceUtil.getArticleContent(
                  ja.getGroupId(),
                  ja.getArticleId(),
                  "view",
                  "" + themeDisplay.getLocale(),
                  themeDisplay);
          model.addAttribute("contenido", contenido);
        }
      }

    } catch (Exception e) {
      log.error("No se pudo cargar el contenido", e);
      throw new RuntimeException("No se pudo cargar el contenido", e);
    }

    return "versiculo/ver";
  }