Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i find - which portlets are deployed on which pages in Liferay 6.1?

Tags:

liferay

In other words, Which Database tables do i need to look into for the mapping of a portlet to a page in an organization? If there is such a thing?! We are using Liferay 6.1.20

like image 432
dev_in_prog Avatar asked Dec 20 '22 10:12

dev_in_prog


1 Answers

Apart from the marketplace portlet.

If you have access to the Database you can fire a simple query on the Layout table to know in what all pages your portlet is added:

SELECT * FROM Layout WHERE typeSettings LIKE '%my_WAR_myportlet%';

Also you can build a FinderImpl with service-builder to execute this query through a portlet and add that portlet to page to display in whatever format you want.


Below is another solution without deploying any portlet and without having access to the DB (tested on MySQL DB):

  1. Go to Server Administration
  2. Go to Script tab
  3. Select Beanshell from the Language drop-down
  4. Paste the following script code in the textarea and press the button execute:

    import com.liferay.portal.kernel.dao.jdbc.DataAccess;
    import com.liferay.portal.kernel.log.Log;
    import com.liferay.portal.kernel.log.LogFactoryUtil;
    import com.liferay.portal.kernel.util.StringBundler;
    
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.ResultSetMetaData;
    
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Iterator;
    import java.util.List;
    
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    
    try {
        con = DataAccess.getUpgradeOptimizedConnection();
    
        // your custom query here
        String sqlQuery = "SELECT * FROM Layout WHERE typeSettings LIKE '%my_WAR_myportlet%'";
    
        out.println("SQL Query: "+ sqlQuery);
    
        ps = con.prepareStatement(sqlQuery);
    
        rs = ps.executeQuery();
    
        ResultSetMetaData rsmd = rs.getMetaData();
    
        int columnCount = rsmd.getColumnCount();
    
        List rows = new ArrayList();
    
        List columnLabels = new ArrayList();
    
        columnLabels.add("Sr. No.");
    
        for (int c = 1; c <= columnCount; c++) {
            String cl = rsmd.getColumnLabel(c);
            columnLabels.add(cl);
        }
    
        while (rs.next()) {
            List row = new ArrayList(columnCount);
    
            for (int c = 1; c <= columnCount; c++) {
                Object value = rs.getObject(c);
                row.add(value);
            }
    
            rows.add(row);
        }
    
        // --- formatting the results ---
    
        out.append("<div class=\"lfr-search-container \"><div class=\"results-grid\">");
        out.append("<table class=\"taglib-search-iterator\">");
        out.append("<thead>");
        out.append("<tr class=\"portlet-section-header results-header\">");
    
        for (String value : columnLabels) {
            out.append("<th>");
            out.append(value);
            out.append("</th>");
        }
    
        out.append("</tr>");
        out.append("</thead>");
        out.append("<tbody>");
    
        boolean alt = false;
    
        long resultsCount = 1;
    
        for (List line : rows) {
            out.append("<tr class=\"portlet-section-alternate results-row " + (alt ? "alt" : "") + "\">");
    
            // for sr. no.
            out.append("<td>");
            out.append(resultsCount + "");
            out.append("</td>");
    
            resultsCount = resultsCount + 1;
    
            for (Iterator iterator = line.iterator(); iterator.hasNext();) {
                Object value = (Object) iterator.next();
                out.append("<td>");
                if (value != null) {
                    out.append(value.toString());
                } else {
                    out.append("<span style=\"font-style:italic\">null</span>");
                }
                out.append("</td>");
            }
            out.append("</tr>");
            alt = !alt;
        }
    
        out.append("</tbody>");
    
        out.append("</table>");
        out.append("</div></div>");
    
    } catch (Exception exp) {
        out.println("ERROR: " + exp);
        throw exp;
    }
    finally {
        DataAccess.cleanUp(con, ps, rs);
    }
    
  5. Please remember to change the string my_WAR_myportlet to your portletId

  6. Needless to say you can modify the script to update the styles and can show selective columns. Also you can run any SQL query, just update String sqlQuery.

Hope this helps.

like image 112
Prakash K Avatar answered Jun 02 '23 06:06

Prakash K