Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Find Layouts with the specific JournalArticle in AssetPublisher portlets

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 507
    Comment on it

    Hello Guys

    Here, We find all layouts with the specific JournalArticle in AssetPublisher portlets.

    With easy requirements someone publish a JournalArticle with specific Tags i.e TagA, TagB. On the other pages (Layouts) of the liferay portal, we have AssetPublisher portles using that display all JournalArticles with those Tags i.e TagA, TagB.

    Now, Using below example to get those layouts programmaticaly :

    public static Set<Layout> getLayoutsWithThisTags(SortedSet<String> tags) throws SystemException, PortalException {
        Set<Layout> layouts = new HashSet<Layout>();
        //build DynamicQuery that contains "assetTags" as "queryName0", see configuration of AssetPublisher
        DynamicQuery query = DynamicQueryFactoryUtil.forClass(com.liferay.portal.model.PortletPreferences.class, PortalClassLoaderUtil.getClassLoader())
        Set<PortletPreferences> preferences = new HashSet<PortletPreferences>(PortletPreferencesLocalServiceUtil.dynamicQuery(query));
        for (PortletPreferences portletPreferences : preferences) {
            long plid = portletPreferences.getPlid();
        return layouts;
    private static Criterion getTagConditions(SortedSet<String> tags) {
        //create recursive OR-Criterion that contains any of the tags
        Criterion criterion = RestrictionsFactoryUtil.or(
                PropertyFactoryUtil.forName("preferences").like("%<preference><name>queryValues0</name>%<value>" + tags.first() +"</value>%"),
                (tags.size() > 2) ? getTagConditions(tail(tags)) :
                    PropertyFactoryUtil.forName("preferences").like("%<preference><name>queryValues0</name>%<value>" + tags.last() +"</value>%"));
        return criterion;
    private static SortedSet<String> tail(SortedSet<String> tags) {
        return tags; 

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: