public static List<AssetEntry> getAssetEntries(
      long[] groupIds,
      long[] classNameIds,
      long[] assetTagIds,
      long resourcePrimKey,
      int start,
      int end,
      String orderByColumn)
      throws PortalException {

    AssetEntryQuery assetEntryQuery = new AssetEntryQuery();

    assetEntryQuery.setAnyTagIds(assetTagIds);
    assetEntryQuery.setClassNameIds(classNameIds);
    assetEntryQuery.setEnd(end + 1);
    assetEntryQuery.setGroupIds(groupIds);
    assetEntryQuery.setOrderByCol1(orderByColumn);
    assetEntryQuery.setStart(start);

    List<AssetEntry> assetEntries =
        ListUtil.copy(AssetEntryServiceUtil.getEntries(assetEntryQuery));

    AssetEntry assetEntry = null;

    for (AssetEntry curAssetEntry : assetEntries) {
      if (curAssetEntry.getClassPK() == resourcePrimKey) {
        assetEntry = curAssetEntry;
      }
    }

    assetEntries.remove(assetEntry);

    return ListUtil.subList(assetEntries, 0, 10);
  }
Exemplo n.º 2
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";
  }
Exemplo n.º 3
0
  protected List<AssetEntry> getAssetEntries(
      PortletRequest portletRequest, PortletPreferences preferences) throws Exception {

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

    AssetEntryQuery assetEntryQuery =
        AssetPublisherUtil.getAssetEntryQuery(
            preferences, new long[] {themeDisplay.getScopeGroupId()});

    boolean anyAssetType = GetterUtil.getBoolean(preferences.getValue("anyAssetType", null), true);

    if (!anyAssetType) {
      long[] availableClassNameIds = AssetRendererFactoryRegistryUtil.getClassNameIds();

      long[] classNameIds = AssetPublisherUtil.getClassNameIds(preferences, availableClassNameIds);

      assetEntryQuery.setClassNameIds(classNameIds);
    }

    long[] classTypeIds = GetterUtil.getLongValues(preferences.getValues("classTypeIds", null));

    assetEntryQuery.setClassTypeIds(classTypeIds);

    boolean enablePermissions =
        GetterUtil.getBoolean(preferences.getValue("enablePermissions", null));

    assetEntryQuery.setEnablePermissions(enablePermissions);

    int rssDelta = GetterUtil.getInteger(preferences.getValue("rssDelta", "20"));

    assetEntryQuery.setEnd(rssDelta);

    boolean excludeZeroViewCount =
        GetterUtil.getBoolean(preferences.getValue("excludeZeroViewCount", null));

    assetEntryQuery.setExcludeZeroViewCount(excludeZeroViewCount);

    long[] groupIds =
        AssetPublisherUtil.getGroupIds(
            preferences, themeDisplay.getScopeGroupId(), themeDisplay.getLayout());

    assetEntryQuery.setGroupIds(groupIds);

    boolean showOnlyLayoutAssets =
        GetterUtil.getBoolean(preferences.getValue("showOnlyLayoutAssets", null));

    if (showOnlyLayoutAssets) {
      assetEntryQuery.setLayout(themeDisplay.getLayout());
    }

    String orderByColumn1 =
        GetterUtil.getString(preferences.getValue("orderByColumn1", "modifiedDate"));

    assetEntryQuery.setOrderByCol1(orderByColumn1);

    String orderByColumn2 = GetterUtil.getString(preferences.getValue("orderByColumn2", "title"));

    assetEntryQuery.setOrderByCol2(orderByColumn2);

    String orderByType1 = GetterUtil.getString(preferences.getValue("orderByType1", "DESC"));

    assetEntryQuery.setOrderByType1(orderByType1);

    String orderByType2 = GetterUtil.getString(preferences.getValue("orderByType2", "ASC"));

    assetEntryQuery.setOrderByType2(orderByType2);

    assetEntryQuery.setStart(0);

    return AssetEntryServiceUtil.getEntries(assetEntryQuery);
  }
  @Override
  public List<AssetEntry> getAssetEntries(
      PortletPreferences preferences,
      Layout layout,
      long scopeGroupId,
      int max,
      boolean checkPermission)
      throws PortalException, SystemException {

    AssetEntryQuery assetEntryQuery = getAssetEntryQuery(preferences, new long[] {scopeGroupId});

    boolean anyAssetType = GetterUtil.getBoolean(preferences.getValue("anyAssetType", null), true);

    if (!anyAssetType) {
      long[] availableClassNameIds =
          AssetRendererFactoryRegistryUtil.getClassNameIds(layout.getCompanyId());

      long[] classNameIds = getClassNameIds(preferences, availableClassNameIds);

      assetEntryQuery.setClassNameIds(classNameIds);
    }

    long[] classTypeIds = GetterUtil.getLongValues(preferences.getValues("classTypeIds", null));

    assetEntryQuery.setClassTypeIds(classTypeIds);

    boolean enablePermissions =
        GetterUtil.getBoolean(preferences.getValue("enablePermissions", null));

    assetEntryQuery.setEnablePermissions(enablePermissions);

    assetEntryQuery.setEnd(max);

    boolean excludeZeroViewCount =
        GetterUtil.getBoolean(preferences.getValue("excludeZeroViewCount", null));

    assetEntryQuery.setExcludeZeroViewCount(excludeZeroViewCount);

    long[] groupIds = getGroupIds(preferences, scopeGroupId, layout);

    assetEntryQuery.setGroupIds(groupIds);

    boolean showOnlyLayoutAssets =
        GetterUtil.getBoolean(preferences.getValue("showOnlyLayoutAssets", null));

    if (showOnlyLayoutAssets) {
      assetEntryQuery.setLayout(layout);
    }

    String orderByColumn1 =
        GetterUtil.getString(preferences.getValue("orderByColumn1", "modifiedDate"));

    assetEntryQuery.setOrderByCol1(orderByColumn1);

    String orderByColumn2 = GetterUtil.getString(preferences.getValue("orderByColumn2", "title"));

    assetEntryQuery.setOrderByCol2(orderByColumn2);

    String orderByType1 = GetterUtil.getString(preferences.getValue("orderByType1", "DESC"));

    assetEntryQuery.setOrderByType1(orderByType1);

    String orderByType2 = GetterUtil.getString(preferences.getValue("orderByType2", "ASC"));

    assetEntryQuery.setOrderByType2(orderByType2);

    assetEntryQuery.setStart(0);

    if (checkPermission) {
      return AssetEntryServiceUtil.getEntries(assetEntryQuery);
    } else {
      return AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);
    }
  }