protected void updateQueryLogic(ActionRequest actionRequest, PortletPreferences preferences)
      throws Exception {

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

    long userId = themeDisplay.getUserId();
    long groupId = themeDisplay.getScopeGroupId();

    int[] queryRulesIndexes =
        StringUtil.split(ParamUtil.getString(actionRequest, "queryLogicIndexes"), 0);

    int i = 0;

    for (int queryRulesIndex : queryRulesIndexes) {
      boolean contains = ParamUtil.getBoolean(actionRequest, "queryContains" + queryRulesIndex);
      boolean andOperator =
          ParamUtil.getBoolean(actionRequest, "queryAndOperator" + queryRulesIndex);
      String name = ParamUtil.getString(actionRequest, "queryName" + queryRulesIndex);

      String[] values = null;

      if (name.equals("assetTags")) {
        values =
            StringUtil.split(ParamUtil.getString(actionRequest, "queryTagNames" + queryRulesIndex));

        AssetTagLocalServiceUtil.checkTags(userId, groupId, values);
      } else {
        values =
            StringUtil.split(
                ParamUtil.getString(actionRequest, "queryCategoryIds" + queryRulesIndex));
      }

      preferences.setValue("queryContains" + i, String.valueOf(contains));
      preferences.setValue("queryAndOperator" + i, String.valueOf(andOperator));
      preferences.setValue("queryName" + i, name);
      preferences.setValues("queryValues" + i, values);

      i++;
    }

    // Clear previous preferences that are now blank

    String[] values = preferences.getValues("queryValues" + i, new String[0]);

    while (values.length > 0) {
      preferences.setValue("queryContains" + i, StringPool.BLANK);
      preferences.setValue("queryAndOperator" + i, StringPool.BLANK);
      preferences.setValue("queryName" + i, StringPool.BLANK);
      preferences.setValues("queryValues" + i, new String[0]);

      i++;

      values = preferences.getValues("queryValues" + i, new String[0]);
    }
  }
Ejemplo n.º 2
0
  protected void updatePreferencesClassPKs(PortletPreferences preferences, String key)
      throws Exception {

    String[] oldValues = preferences.getValues(key, null);

    if (oldValues == null) {
      return;
    }

    String[] newValues = new String[oldValues.length];

    for (int i = 0; i < oldValues.length; i++) {
      String oldValue = oldValues[i];

      String newValue = oldValue;

      String[] oldPrimaryKeys = StringUtil.split(oldValue);

      for (String oldPrimaryKey : oldPrimaryKeys) {
        if (!Validator.isNumber(oldPrimaryKey)) {
          break;
        }

        Long newPrimaryKey = _ddmStructurePKs.get(GetterUtil.getLong(oldPrimaryKey));

        if (Validator.isNotNull(newPrimaryKey)) {
          newValue = StringUtil.replace(newValue, oldPrimaryKey, String.valueOf(newPrimaryKey));
        }
      }

      newValues[i] = newValue;
    }

    preferences.setValues(key, newValues);
  }
  @Override
  public long[] getClassNameIds(
      PortletPreferences portletPreferences, long[] availableClassNameIds) {

    boolean anyAssetType =
        GetterUtil.getBoolean(portletPreferences.getValue("anyAssetType", Boolean.TRUE.toString()));

    if (anyAssetType) {
      return availableClassNameIds;
    }

    long defaultClassNameId = GetterUtil.getLong(portletPreferences.getValue("anyAssetType", null));

    if (defaultClassNameId > 0) {
      return new long[] {defaultClassNameId};
    }

    long[] classNameIds =
        GetterUtil.getLongValues(portletPreferences.getValues("classNameIds", null));

    if (classNameIds != null) {
      return classNameIds;
    } else {
      return availableClassNameIds;
    }
  }
  protected String updatePreferences(
      long companyId, long ownerId, int ownerType, long plid, String portletId, String xml)
      throws Exception {

    PortletPreferences preferences =
        PortletPreferencesFactoryUtil.fromXML(companyId, ownerId, ownerType, plid, portletId, xml);

    Map<String, String[]> preferencesMap = preferences.getMap();

    String rootPortletId = PortletConstants.getRootPortletId(portletId);

    for (String oldName : preferencesMap.keySet()) {
      String newName = getName(rootPortletId, oldName);
      String[] oldValues = preferencesMap.get(oldName);

      preferences.reset(oldName);

      if (newName != null) {
        preferences.setValues(newName, oldValues);
      }
    }

    Map<String, String> defaultPreferencesMap = getDefaultPreferencesMap(rootPortletId);

    for (String name : defaultPreferencesMap.keySet()) {
      if (preferences.getValues(name, null) == null) {
        preferences.setValues(name, StringUtil.split(defaultPreferencesMap.get(name)));
      }
    }

    return PortletPreferencesFactoryUtil.toXML(preferences);
  }
  @Override
  public void removeAndStoreSelection(
      List<String> assetEntryUuids, PortletPreferences portletPreferences) throws Exception {

    if (assetEntryUuids.size() == 0) {
      return;
    }

    String[] assetEntryXmls = portletPreferences.getValues("assetEntryXml", new String[0]);

    List<String> assetEntryXmlsList = ListUtil.fromArray(assetEntryXmls);

    Iterator<String> itr = assetEntryXmlsList.iterator();

    while (itr.hasNext()) {
      String assetEntryXml = itr.next();

      Document document = SAXReaderUtil.read(assetEntryXml);

      Element rootElement = document.getRootElement();

      String assetEntryUuid = rootElement.elementText("asset-entry-uuid");

      if (assetEntryUuids.contains(assetEntryUuid)) {
        itr.remove();
      }
    }

    portletPreferences.setValues(
        "assetEntryXml", assetEntryXmlsList.toArray(new String[assetEntryXmlsList.size()]));

    portletPreferences.store();
  }
  @Override
  public String[] getAssetTagNames(PortletPreferences portletPreferences, long scopeGroupId)
      throws Exception {

    String[] allAssetTagNames = new String[0];

    for (int i = 0; true; i++) {
      String[] queryValues = portletPreferences.getValues("queryValues" + i, null);

      if ((queryValues == null) || (queryValues.length == 0)) {
        break;
      }

      boolean queryContains =
          GetterUtil.getBoolean(portletPreferences.getValue("queryContains" + i, StringPool.BLANK));
      boolean queryAndOperator =
          GetterUtil.getBoolean(
              portletPreferences.getValue("queryAndOperator" + i, StringPool.BLANK));
      String queryName = portletPreferences.getValue("queryName" + i, StringPool.BLANK);

      if (!Validator.equals(queryName, "assetCategories") && queryContains && queryAndOperator) {

        allAssetTagNames = queryValues;
      }
    }

    return allAssetTagNames;
  }
  protected void copyPreferences(
      javax.portlet.PortletPreferences sourcePreferences,
      javax.portlet.PortletPreferences targetPreferences)
      throws SystemException {

    try {
      Iterator<String> itr = targetPreferences.getMap().keySet().iterator();

      while (itr.hasNext()) {
        try {
          String key = itr.next();

          targetPreferences.reset(key);
        } catch (ReadOnlyException roe) {
        }
      }

      itr = sourcePreferences.getMap().keySet().iterator();

      while (itr.hasNext()) {
        try {
          String key = itr.next();

          targetPreferences.setValues(key, sourcePreferences.getValues(key, new String[0]));
        } catch (ReadOnlyException roe) {
        }
      }

      targetPreferences.store();
    } catch (IOException ioe) {
      _log.error(ioe);
    } catch (ValidatorException ve) {
      throw new SystemException(ve);
    }
  }
Ejemplo n.º 8
0
  public void addEntry(ActionRequest request, ActionResponse response) {
    try {
      PortletPreferences prefs = request.getPreferences();

      String[] guestbookEntries = prefs.getValues("guestbook-entries", new String[1]);

      ArrayList<String> entries = new ArrayList<String>();

      if (guestbookEntries != null) {

        entries =
            new ArrayList<String>(
                Arrays.asList(prefs.getValues("guestbook-entries", new String[1])));
      }

      String userName = ParamUtil.getString(request, "name");
      String message = ParamUtil.getString(request, "message");
      String entry = userName + "^" + message;

      entries.add(entry);

      String[] array = entries.toArray(new String[entries.size()]);

      prefs.setValues("guestbook-entries", array);

      try {

        prefs.store();

      } catch (IOException ex) {

        Logger.getLogger(GuestbookPortlet.class.getName()).log(Level.SEVERE, null, ex);

      } catch (ValidatorException ex) {

        Logger.getLogger(GuestbookPortlet.class.getName()).log(Level.SEVERE, null, ex);
      }

    } catch (ReadOnlyException ex) {

      Logger.getLogger(GuestbookPortlet.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
 private Map<String, Long> createResourceRoles(
     String portletId, long communityId, PortletPreferences preferences) {
   String[] roleNames = preferences.getValues(ROLE_NAMES_PREF, new String[0]);
   Map<String, Long> newRoleIds = new HashMap<String, Long>(roleNames.length);
   for (String roleName : roleNames) {
     Long newId = configurationService.storeRoleResourceId(portletId, communityId, roleName);
     newRoleIds.put(roleName, newId);
     LOGGER.debug("Creating resource for role {}, newId: {}", roleName, newId);
   }
   return newRoleIds;
 }
  private void replaceClassNameId(PortletPreferences portletPreferences, String name)
      throws Exception {

    String[] values = GetterUtil.getStringValues(portletPreferences.getValues(name, null));

    ArrayUtil.replace(
        values,
        String.valueOf(PortalUtil.getClassNameId(CalEvent.class)),
        String.valueOf(PortalUtil.getClassNameId(CalendarBooking.class)));

    portletPreferences.setValues(name, values);
  }
Ejemplo n.º 11
0
  @Override
  public void render(RenderRequest renderRequest, RenderResponse renderResponse)
      throws PortletException, IOException {

    PortletPreferences prefs = renderRequest.getPreferences();
    String[] guestbookEntries = prefs.getValues("guestbook-entries", new String[1]);

    if (guestbookEntries != null) {

      List<Entry> entries = parseEntries(guestbookEntries);

      renderRequest.setAttribute("entries", entries);
    }

    super.render(renderRequest, renderResponse);
  }
  protected void moveSelectionDown(ActionRequest actionRequest, PortletPreferences preferences)
      throws Exception {

    int assetEntryOrder = ParamUtil.getInteger(actionRequest, "assetEntryOrder");

    String[] manualEntries = preferences.getValues("asset-entry-xml", new String[0]);

    if ((assetEntryOrder >= (manualEntries.length - 1)) || (assetEntryOrder < 0)) {

      return;
    }

    String temp = manualEntries[assetEntryOrder + 1];

    manualEntries[assetEntryOrder + 1] = manualEntries[assetEntryOrder];
    manualEntries[assetEntryOrder] = temp;

    preferences.setValues("asset-entry-xml", manualEntries);
  }
  @Override
  protected String upgradePreferences(
      long companyId, long ownerId, int ownerType, long plid, String portletId, String xml)
      throws Exception {

    PortletPreferences portletPreferences =
        PortletPreferencesFactoryUtil.fromXML(companyId, ownerId, ownerType, plid, portletId, xml);

    String selectionStyle = portletPreferences.getValue("selection-style", null);

    if (Validator.isNotNull(selectionStyle) && !selectionStyle.equals("dynamic")) {

      String[] assetEntryXmls = portletPreferences.getValues("asset-entry-xml", new String[0]);

      String[] newAssetEntryXmls = getAssetEntryXmls(assetEntryXmls);

      portletPreferences.setValues("asset-entry-xml", newAssetEntryXmls);
    }

    return PortletPreferencesFactoryUtil.toXML(portletPreferences);
  }
  @Override
  public void addSelection(
      ThemeDisplay themeDisplay,
      PortletPreferences portletPreferences,
      String portletId,
      long assetEntryId,
      int assetEntryOrder,
      String assetEntryType)
      throws Exception {

    AssetEntry assetEntry = AssetEntryLocalServiceUtil.getEntry(assetEntryId);

    String[] assetEntryXmls = portletPreferences.getValues("assetEntryXml", new String[0]);

    String assetEntryXml = _getAssetEntryXml(assetEntryType, assetEntry.getClassUuid());

    if (!ArrayUtil.contains(assetEntryXmls, assetEntryXml)) {
      if (assetEntryOrder > -1) {
        assetEntryXmls[assetEntryOrder] = assetEntryXml;
      } else {
        assetEntryXmls = ArrayUtil.append(assetEntryXmls, assetEntryXml);
      }

      portletPreferences.setValues("assetEntryXml", assetEntryXmls);
    }

    long plid = themeDisplay.getRefererPlid();

    if (plid == 0) {
      plid = themeDisplay.getPlid();
    }

    List<AssetEntry> assetEntries = new ArrayList<AssetEntry>();

    assetEntries.add(assetEntry);

    notifySubscribers(portletPreferences, plid, portletId, assetEntries);
  }
  @RequestMapping("VIEW")
  protected ModelAndView renderView(RenderRequest request, RenderResponse response)
      throws Exception {
    this.init(request);
    final PortletPreferences prefs = request.getPreferences();
    String defaultPortletView = prefs.getValue(PREF_PORTLET_VIEW, STANDARD_VIEW);
    String[] prefsDefaultPathes = prefs.getValues(PREF_DEFAULT_PATH, null);
    if (log.isDebugEnabled()) {
      log.debug(PREF_DEFAULT_PATH + " preference : ");
      for (String prefDefaultPath : prefsDefaultPathes) log.debug("- " + prefDefaultPath);
    }

    boolean showHiddenFiles = "true".equals(prefs.getValue(PREF_SHOW_HIDDEN_FILES, "false"));
    userParameters.setShowHiddenFiles(showHiddenFiles);

    UploadActionType uploadOption =
        UploadActionType.valueOf(
            prefs.getValue(PREF_UPLOAD_ACTION_EXIST_FILE, UploadActionType.OVERRIDE.toString()));
    userParameters.setUploadOption(uploadOption);

    serverAccess.initializeServices(userParameters);

    String defaultPath = serverAccess.getFirstAvailablePath(userParameters, prefsDefaultPathes);
    log.info("defaultPath will be : " + defaultPath);
    defaultPath = pathEncodingUtils.encodeDir(defaultPath);

    if (userAgentInspector.isMobile(request)) {
      return this.browseMobile(request, response, defaultPath);
    } else {
      if (MOBILE_VIEW.equals(defaultPortletView))
        return this.browseMobile(request, response, defaultPath);
      else if (WAI_VIEW.equals(defaultPortletView))
        return this.browseWai(request, response, defaultPath, null);
      else return this.browseStandard(request, response, defaultPath);
    }
  }
  @Override
  public long[] getGroupIds(
      PortletPreferences portletPreferences, long scopeGroupId, Layout layout) {

    String[] scopeIds =
        portletPreferences.getValues(
            "scopeIds", new String[] {SCOPE_ID_GROUP_PREFIX + scopeGroupId});

    long[] groupIds = new long[scopeIds.length];

    int i = 0;

    for (String scopeId : scopeIds) {
      try {
        groupIds[i] = getGroupIdFromScopeId(scopeId, scopeGroupId, layout.isPrivateLayout());

        i++;
      } catch (Exception e) {
        continue;
      }
    }

    return groupIds;
  }
  protected void removeSelection(ActionRequest actionRequest, PortletPreferences preferences)
      throws Exception {

    int assetEntryOrder = ParamUtil.getInteger(actionRequest, "assetEntryOrder");

    String[] manualEntries = preferences.getValues("asset-entry-xml", new String[0]);

    if (assetEntryOrder >= manualEntries.length) {
      return;
    }

    String[] newEntries = new String[manualEntries.length - 1];

    int i = 0;
    int j = 0;

    for (; i < manualEntries.length; i++) {
      if (i != assetEntryOrder) {
        newEntries[j++] = manualEntries[i];
      }
    }

    preferences.setValues("asset-entry-xml", newEntries);
  }
  protected void updatePortletPreferences(
      PortletDataContext portletDataContext,
      long ownerId,
      int ownerType,
      long plid,
      String portletId,
      String xml,
      boolean importData)
      throws Exception {

    Portlet portlet =
        _portletLocalService.getPortletById(portletDataContext.getCompanyId(), portletId);

    if (portlet == null) {
      if (_log.isDebugEnabled()) {
        _log.debug(
            "Do not update portlet preferences for "
                + portletId
                + " because the portlet does not exist");
      }

      return;
    }

    PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance();

    if (importData || !MergeLayoutPrototypesThreadLocal.isInProgress()) {
      _portletPreferencesLocalService.updatePreferences(ownerId, ownerType, plid, portletId, xml);

      return;
    }

    // Portlet preferences to be updated only when importing data

    String[] dataPortletPreferences = portletDataHandler.getDataPortletPreferences();

    // Current portlet preferences

    javax.portlet.PortletPreferences portletPreferences =
        _portletPreferencesLocalService.getPreferences(
            portletDataContext.getCompanyId(), ownerId, ownerType, plid, portletId);

    // New portlet preferences

    javax.portlet.PortletPreferences jxPortletPreferences =
        PortletPreferencesFactoryUtil.fromXML(
            portletDataContext.getCompanyId(), ownerId, ownerType, plid, portletId, xml);

    Enumeration<String> enu = jxPortletPreferences.getNames();

    while (enu.hasMoreElements()) {
      String name = enu.nextElement();

      String scopeLayoutUuid = portletDataContext.getScopeLayoutUuid();
      String scopeType = portletDataContext.getScopeType();

      if (!ArrayUtil.contains(dataPortletPreferences, name)
          || (Validator.isNull(scopeLayoutUuid) && scopeType.equals("company"))) {

        String[] values = jxPortletPreferences.getValues(name, null);

        portletPreferences.setValues(name, values);
      }
    }

    _portletPreferencesLocalService.updatePreferences(
        ownerId, ownerType, plid, portletId, portletPreferences);
  }
  @Override
  public AssetEntryQuery getAssetEntryQuery(
      PortletPreferences portletPreferences, long[] scopeGroupIds)
      throws PortalException, SystemException {

    AssetEntryQuery assetEntryQuery = new AssetEntryQuery();

    long[] allAssetCategoryIds = new long[0];
    long[] anyAssetCategoryIds = new long[0];
    long[] notAllAssetCategoryIds = new long[0];
    long[] notAnyAssetCategoryIds = new long[0];

    String[] allAssetTagNames = new String[0];
    String[] anyAssetTagNames = new String[0];
    String[] notAllAssetTagNames = new String[0];
    String[] notAnyAssetTagNames = new String[0];

    for (int i = 0; true; i++) {
      String[] queryValues = portletPreferences.getValues("queryValues" + i, null);

      if ((queryValues == null) || (queryValues.length == 0)) {
        break;
      }

      boolean queryContains =
          GetterUtil.getBoolean(portletPreferences.getValue("queryContains" + i, StringPool.BLANK));
      boolean queryAndOperator =
          GetterUtil.getBoolean(
              portletPreferences.getValue("queryAndOperator" + i, StringPool.BLANK));
      String queryName = portletPreferences.getValue("queryName" + i, StringPool.BLANK);

      if (Validator.equals(queryName, "assetCategories")) {
        long[] assetCategoryIds = GetterUtil.getLongValues(queryValues);

        if (queryContains && queryAndOperator) {
          allAssetCategoryIds = assetCategoryIds;
        } else if (queryContains && !queryAndOperator) {
          anyAssetCategoryIds = assetCategoryIds;
        } else if (!queryContains && queryAndOperator) {
          notAllAssetCategoryIds = assetCategoryIds;
        } else {
          notAnyAssetCategoryIds = assetCategoryIds;
        }
      } else {
        if (queryContains && queryAndOperator) {
          allAssetTagNames = queryValues;
        } else if (queryContains && !queryAndOperator) {
          anyAssetTagNames = queryValues;
        } else if (!queryContains && queryAndOperator) {
          notAllAssetTagNames = queryValues;
        } else {
          notAnyAssetTagNames = queryValues;
        }
      }
    }

    assetEntryQuery.setAllCategoryIds(allAssetCategoryIds);

    for (String assetTagName : allAssetTagNames) {
      long[] allAssetTagIds = AssetTagLocalServiceUtil.getTagIds(scopeGroupIds, assetTagName);

      assetEntryQuery.addAllTagIdsArray(allAssetTagIds);
    }

    assetEntryQuery.setAnyCategoryIds(anyAssetCategoryIds);

    long[] anyAssetTagIds = AssetTagLocalServiceUtil.getTagIds(scopeGroupIds, anyAssetTagNames);

    assetEntryQuery.setAnyTagIds(anyAssetTagIds);

    assetEntryQuery.setNotAllCategoryIds(notAllAssetCategoryIds);

    for (String assetTagName : notAllAssetTagNames) {
      long[] notAllAssetTagIds = AssetTagLocalServiceUtil.getTagIds(scopeGroupIds, assetTagName);

      assetEntryQuery.addNotAllTagIdsArray(notAllAssetTagIds);
    }

    assetEntryQuery.setNotAnyCategoryIds(notAnyAssetCategoryIds);

    long[] notAnyAssetTagIds =
        AssetTagLocalServiceUtil.getTagIds(scopeGroupIds, notAnyAssetTagNames);

    assetEntryQuery.setNotAnyTagIds(notAnyAssetTagIds);

    return assetEntryQuery;
  }
  @RequestMapping("EDIT")
  public ModelAndView renderEditView(RenderRequest request, RenderResponse response)
      throws Exception {

    ModelMap model = new ModelMap();
    final PortletPreferences prefs = request.getPreferences();
    String[] recupPrefDisplay_userTabs = prefs.getValues(WebController.PREF_TAB_USER, null);
    String[] recupPrefDisplay_managerTabs = prefs.getValues(WebController.PREF_TAB_MANAGER, null);
    String messageFile = prefs.getValue(WebController.PREF_MESSAGE_FILE, "_fr");
    String nbMaxTickets = prefs.getValue(WebController.PREF_MAX_TICKETS, "15");

    ArrayOfString managerFilters =
        domainService.getInvolvementFilters(
            (prefs.getValue(WebController.PREF_WSDL_LOCATION, null)), false);
    ArrayOfString userFilters =
        domainService.getInvolvementFilters(
            (prefs.getValue(WebController.PREF_WSDL_LOCATION, null)), true);

    ArrayList<String> userTabPrefs = new ArrayList<String>();
    ArrayList<String> managerTabPrefs = new ArrayList<String>();
    int i = 0;
    for (String userFilter : userFilters.getString()) {
      if (Arrays.asList(recupPrefDisplay_userTabs).contains(userFilter.toLowerCase())) {
        i++;
        userTabPrefs.add(String.valueOf(i).concat(".").concat(userFilter).toLowerCase());
      } else {
        userTabPrefs.add(userFilter.toLowerCase());
      }
    }
    Collections.sort(userTabPrefs);
    i = 0;
    for (String managerFilter : managerFilters.getString()) {
      if (Arrays.asList(recupPrefDisplay_managerTabs).contains(managerFilter.toLowerCase())) {
        i++;
        managerTabPrefs.add(String.valueOf(i).concat(".").concat(managerFilter).toLowerCase());
      } else {
        managerTabPrefs.add(managerFilter.toLowerCase());
      }
    }
    Collections.sort(managerTabPrefs);
    boolean userViewMode = true;
    boolean managerViewMode = false;
    boolean maxTicketsViewMode = false;
    String isManagerViewAble = "false";

    if (prefs.isReadOnly(WebController.PREF_TAB_USER)) {
      userViewMode = false;
    }
    PortletSession session = request.getPortletSession();
    if (session != null) {
      isManagerViewAble = session.getAttribute("isManagerViewAble").toString();
    }
    if ((isManagerViewAble.equalsIgnoreCase("true"))
        && (!prefs.isReadOnly(WebController.PREF_TAB_MANAGER))) {
      managerViewMode = true;
    }
    if (!prefs.isReadOnly(WebController.PREF_MAX_TICKETS)) {
      maxTicketsViewMode = true;
    }
    model.put("nbMaxTickets", nbMaxTickets);
    model.put("messageFile", messageFile);
    model.put("managerTabPrefs", managerTabPrefs);
    model.put("userTabPrefs", userTabPrefs);
    model.put("userViewMode", userViewMode);
    model.put("managerViewMode", managerViewMode);
    model.put("maxTicketsViewMode", maxTicketsViewMode);
    model.put("isManagerViewAble", isManagerViewAble);
    return new ModelAndView("edit-portlet", model);
  }
Ejemplo n.º 21
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);
  }
  protected PortletURL getKBArticleURL(
      long plid, boolean privateLayout, KBArticle kbArticle, HttpServletRequest request)
      throws Exception {

    PortletURL firstMatchPortletURL = null;

    List<Layout> layouts = getCandidateLayouts(plid, privateLayout, kbArticle);

    for (Layout layout : layouts) {
      LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

      List<Portlet> portlets = layoutTypePortlet.getAllPortlets();

      for (Portlet portlet : portlets) {
        String rootPortletId = PortletConstants.getRootPortletId(portlet.getPortletId());

        if (rootPortletId.equals(PortletKeys.KNOWLEDGE_BASE_DISPLAY)) {
          PortletPreferences portletPreferences =
              PortletPreferencesFactoryUtil.getPortletSetup(
                  layout, portlet.getPortletId(), StringPool.BLANK);

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

          long resourceClassNameId =
              GetterUtil.getLong(
                  portletPreferences.getValue("resourceClassNameId", null), kbFolderClassNameId);
          long resourcePrimKey =
              GetterUtil.getLong(
                  portletPreferences.getValue("resourcePrimKey", null),
                  KBFolderConstants.DEFAULT_PARENT_FOLDER_ID);

          if (resourceClassNameId == kbFolderClassNameId) {
            if (isParentFolder(resourcePrimKey, kbArticle.getKbFolderId())) {

              return getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request);
            }
          } else if (resourcePrimKey == kbArticle.getResourcePrimKey()) {

            return getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request);
          }

          if (firstMatchPortletURL == null) {
            firstMatchPortletURL =
                getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request);
          }
        }

        if (rootPortletId.equals(PortletKeys.KNOWLEDGE_BASE_SECTION)) {
          PortletPreferences portletPreferences =
              PortletPreferencesFactoryUtil.getPortletSetup(
                  layout, portlet.getPortletId(), StringPool.BLANK);

          String[] kbArticlesSections =
              portletPreferences.getValues("kbArticlesSections", new String[0]);

          KBArticle rootKBArticle =
              KBArticleLocalServiceUtil.fetchLatestKBArticle(
                  kbArticle.getRootResourcePrimKey(), WorkflowConstants.STATUS_APPROVED);

          if (rootKBArticle == null) {
            continue;
          }

          String[] sections = AdminUtil.unescapeSections(rootKBArticle.getSections());

          for (String section : sections) {
            if (!ArrayUtil.contains(kbArticlesSections, section)) {
              continue;
            }

            return getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request);
          }
        }

        if (rootPortletId.equals(PortletKeys.KNOWLEDGE_BASE_ARTICLE)) {
          PortletPreferences portletPreferences =
              PortletPreferencesFactoryUtil.getPortletSetup(
                  layout, portlet.getPortletId(), StringPool.BLANK);

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

          KBArticle selKBArticle =
              KBArticleLocalServiceUtil.fetchLatestKBArticle(
                  resourcePrimKey, WorkflowConstants.STATUS_APPROVED);

          if (selKBArticle == null) {
            continue;
          }

          long rootResourcePrimKey = kbArticle.getRootResourcePrimKey();
          long selRootResourcePrimKey = selKBArticle.getRootResourcePrimKey();

          if (rootResourcePrimKey == selRootResourcePrimKey) {
            return getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request);
          }

          if (firstMatchPortletURL == null) {
            firstMatchPortletURL =
                getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request);
          }
        }
      }
    }

    return firstMatchPortletURL;
  }
  private void _checkAssetEntries(com.liferay.portal.model.PortletPreferences portletPreferences)
      throws PortalException, SystemException {

    Layout layout = LayoutLocalServiceUtil.getLayout(portletPreferences.getPlid());

    PortletPreferences preferences =
        PortletPreferencesFactoryUtil.fromXML(
            layout.getCompanyId(),
            portletPreferences.getOwnerId(),
            portletPreferences.getOwnerType(),
            portletPreferences.getPlid(),
            portletPreferences.getPortletId(),
            portletPreferences.getPreferences());

    if (!getEmailAssetEntryAddedEnabled(preferences)) {
      return;
    }

    List<AssetEntry> assetEntries =
        getAssetEntries(
            preferences,
            layout,
            layout.getGroupId(),
            PropsValues.ASSET_PUBLISHER_DYNAMIC_SUBSCRIPTION_LIMIT,
            false);

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

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

    List<AssetEntry> newAssetEntries = new ArrayList<AssetEntry>();

    for (int i = 0; i < assetEntries.size(); i++) {
      AssetEntry assetEntry = assetEntries.get(i);

      if (!ArrayUtil.contains(notifiedAssetEntryIds, assetEntry.getEntryId())) {

        newAssetEntries.add(assetEntry);
      }
    }

    notifySubscribers(
        preferences,
        portletPreferences.getPlid(),
        portletPreferences.getPortletId(),
        newAssetEntries);

    try {
      preferences.setValues(
          "notifiedAssetEntryIds",
          StringUtil.split(ListUtil.toString(assetEntries, AssetEntry.ENTRY_ID_ACCESSOR)));

      preferences.store();
    } catch (IOException ioe) {
      throw new SystemException(ioe);
    } catch (PortletException pe) {
      throw new SystemException(pe);
    }
  }
  protected void updatePortletPreferences(
      PortletDataContext portletDataContext,
      long ownerId,
      int ownerType,
      long plid,
      String portletId,
      String xml,
      boolean importData)
      throws Exception {

    PortletDataHandler portletDataHandler =
        _portletDataHandlerProvider.provide(portletDataContext.getCompanyId(), portletId);

    // Current portlet preferences

    javax.portlet.PortletPreferences portletPreferences =
        _portletPreferencesLocalService.getPreferences(
            portletDataContext.getCompanyId(), ownerId, ownerType, plid, portletId);

    // New portlet preferences

    javax.portlet.PortletPreferences jxPortletPreferences =
        PortletPreferencesFactoryUtil.fromXML(
            portletDataContext.getCompanyId(), ownerId, ownerType, plid, portletId, xml);

    if (importData || !MergeLayoutPrototypesThreadLocal.isInProgress()) {
      String currentLastPublishDate = portletPreferences.getValue("last-publish-date", null);
      String newLastPublishDate = jxPortletPreferences.getValue("last-publish-date", null);

      if (Validator.isNotNull(currentLastPublishDate)) {
        jxPortletPreferences.setValue("last-publish-date", currentLastPublishDate);
      } else if (Validator.isNotNull(newLastPublishDate)) {
        jxPortletPreferences.reset("last-publish-date");
      }

      _portletPreferencesLocalService.updatePreferences(
          ownerId,
          ownerType,
          plid,
          portletId,
          PortletPreferencesFactoryUtil.toXML(jxPortletPreferences));

      return;
    }

    // Portlet preferences will be updated only when importing data

    String[] dataPortletPreferences = portletDataHandler.getDataPortletPreferences();

    Enumeration<String> enu = jxPortletPreferences.getNames();

    while (enu.hasMoreElements()) {
      String name = enu.nextElement();

      String scopeLayoutUuid = portletDataContext.getScopeLayoutUuid();
      String scopeType = portletDataContext.getScopeType();

      if (!ArrayUtil.contains(dataPortletPreferences, name)
          || (Validator.isNull(scopeLayoutUuid) && scopeType.equals("company"))) {

        String[] values = jxPortletPreferences.getValues(name, null);

        portletPreferences.setValues(name, values);
      }
    }

    _portletPreferencesLocalService.updatePreferences(
        ownerId, ownerType, plid, portletId, portletPreferences);
  }
  @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);
    }
  }