Forums

Home » Liferay Portal » English » 2. Using Liferay » General

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Muradali Hasan
how to find Web Content currently attached with web content Display
May 13, 2013 11:13 PM
Answer

Muradali Hasan

Rank: Junior Member

Posts: 83

Join Date: July 26, 2010

Recent Posts

Hi,

I want to know is there any way to know the web content currently used buy web content display.

i.e. I have created lot of web content in my portal now some of them are now i am using to display using web content display.

now i want to delete or expire the web content which are not being display using web content display portlet.

Any Idea?

Thanks-
Muradali
Raja Seth
RE: how to find Web Content currently attached with web content Display
May 14, 2013 12:22 AM
Answer

Raja Seth

Rank: Regular Member

Posts: 123

Join Date: August 18, 2011

Recent Posts

HI Muradali,

I don't think there is any such way, but apart from that there is a table named as "JOURNALCONTENTSEARCH" which stores the entry for all the articles that are used buy web content display.

Regards,
Raja
Oliver Bayer
RE: how to find Web Content currently attached with web content Display
May 14, 2013 1:38 AM
Answer

Oliver Bayer

Rank: Liferay Master

Posts: 875

Join Date: February 18, 2009

Recent Posts

Hi Muradali,

you should be able to achieve it the following way but it will require some coding:

  • query the portletpreferences table to get all entries with portletid like "56_INSTANCE_%" and retrieve the plids
  • next check the layout table to see if all plids (page layout ids) are still existing
  • all other articles aren't placed on a page

You can use dynamic queries to run the above mentioned queries. If you have any further question feel free to ask again.

HTH Oli
Muradali Hasan
RE: how to find Web Content currently attached with web content Display
May 15, 2013 5:03 PM
Answer

Muradali Hasan

Rank: Junior Member

Posts: 83

Join Date: July 26, 2010

Recent Posts

Thanks Oliver,

I have followed the same approach as per your suggestion and i made one portlet which will do the cleanup of the web content and its working fine.
See below Code

  1
  2
  3DynamicQuery dq = DynamicQueryFactoryUtil.forClass(PortletPreferences.class,PortalClassLoaderUtil.getClassLoader()).add(PropertyFactoryUtil.forName("portletId").like("%56_INSTANCE%"));
  4            List<com.liferay.portal.model.PortletPreferences> portletpreferences = null;
  5            try {
  6                portletpreferences = PortletPreferencesLocalServiceUtil.dynamicQuery(dq);
  7            } catch (SystemException e1) {
  8                e1.printStackTrace();
  9            }
 10            System.out.println(" Portlet Preferences Web Content Display Count "+portletpreferences.size());
 11            StringBuffer usedArticleId = new StringBuffer("");
 12            for(int i =0; i<portletpreferences.size();i++)
 13            {
 14               
 15                javax.portlet.PortletPreferences pp = null;
 16                try {
 17                    pp = PortletPreferencesLocalServiceUtil.getPreferences(themeDisplay.getCompanyId(), portletpreferences.get(i).getOwnerId(), portletpreferences.get(i).getOwnerType(), portletpreferences.get(i).getPlid(), portletpreferences.get(i).getPortletId());
 18                } catch (SystemException e) {
 19                    // TODO Auto-generated catch block
 20                    e.printStackTrace();
 21                }
 22               
 23                if((pp.getValue("article-id", ""))!=null && (pp.getValue("article-id", "").length()>0 ))
 24                {
 25                    usedArticleId.append(pp.getValue("article-id", "")).append(",");
 26                }
 27               
 28            }
 29            // 1---------End This block of code will return the web content which are currently being used by Web content Display Portlet
 30            // 2--------- Start Remove the duplicate arcticles from string and converting into Array
 31       
 32            String [] UsedArticle = StringUtil.split(usedArticleId.toString(),",");
 33       
 34            List<String> list = Arrays.asList(UsedArticle);
 35            Set<String> set = new HashSet<String>(list);
 36            String[] result = new String[set.size()];
 37            set.toArray(result);
 38            System.out.println("Used Article Id String "+usedArticleId.toString());
 39            System.out.println("result  "+result.length);
 40            // 2--------- End Remove the duplicate arcticles from string and converting into Array
 41            
 42            
 43            DynamicQuery dqJournalArticleResource = DynamicQueryFactoryUtil.forClass(JournalArticleResource.class,PortalClassLoaderUtil.getClassLoader()).add(PropertyFactoryUtil.forName("articleId").in(result));
 44       
 45       
 46       
 47            List<JournalArticleResource> lstJournalArticleResource = null;
 48            try {
 49                lstJournalArticleResource = JournalArticleResourceLocalServiceUtil.dynamicQuery(dqJournalArticleResource);
 50            } catch (SystemException e) {
 51                // TODO Auto-generated catch block
 52                e.printStackTrace();
 53            }
 54            System.out.println("JournalArticleResource currently Used By Webcontent Display"+lstJournalArticleResource.size());
 55            dqJournalArticleResource.setProjection(ProjectionFactoryUtil.property("articleId"));
 56       
 57            DynamicQuery dqJournalArticleResourcenotused = DynamicQueryFactoryUtil.forClass(JournalArticleResource.class,PortalClassLoaderUtil.getClassLoader()).add(PropertyFactoryUtil.forName("articleId").notIn(dqJournalArticleResource));
 58            List<JournalArticleResource> lstJournalArticleResourcenotused = null;
 59            try {
 60                lstJournalArticleResourcenotused = JournalArticleResourceLocalServiceUtil.dynamicQuery(dqJournalArticleResourcenotused);
 61            } catch (SystemException e) {
 62               
 63                e.printStackTrace();
 64            }
 65            System.out.println("JournalArticleResource not currently Used By Webcontent Display"+lstJournalArticleResourcenotused.size());
 66            dqJournalArticleResourcenotused.setProjection(ProjectionFactoryUtil.property("resourcePrimKey"));
 67            //String status [] = {"0","1","2"};
 68            DynamicQuery dqJournalArticleNotUsed = DynamicQueryFactoryUtil.forClass(JournalArticle.class,PortalClassLoaderUtil.getClassLoader()).add(PropertyFactoryUtil.forName("resourcePrimKey").in(dqJournalArticleResourcenotused)).add(PropertyFactoryUtil.forName("status").between(0, 2));
 69            DynamicQuery dqJournalArticleUsed = DynamicQueryFactoryUtil.forClass(JournalArticle.class,PortalClassLoaderUtil.getClassLoader()).add(PropertyFactoryUtil.forName("resourcePrimKey").notIn(dqJournalArticleResourcenotused)).add(PropertyFactoryUtil.forName("status").between(0, 2));
 70            List<JournalArticle> jaNotUsed = null;
 71            List jaUsed = null;
 72            try {
 73                jaNotUsed = JournalArticleLocalServiceUtil.dynamicQuery(dqJournalArticleNotUsed);
 74                 jaUsed = JournalArticleLocalServiceUtil.dynamicQuery(dqJournalArticleUsed);
 75            } catch (SystemException e) {
 76                // TODO Auto-generated catch block
 77                e.printStackTrace();
 78            }
 79            List<JournalArticle> jaUsedtotal = null;
 80            System.out.println(" Journal Article Used Count "+jaUsed.size());
 81            System.out.println(" Journal Article NotUsed Count "+jaNotUsed.size());
 82            for(JournalArticle ja : jaNotUsed)
 83            {
 84                //ja.setExpirationDate(new Date());
 85                //ja.setStatus(3);
 86               
 87                try {
 88                    //System.out.println(ja.getArticleId());
 89                    ServiceContext serviceContext = ServiceContextFactory.getInstance(
 90                            JournalArticle.class.getName(), actionRequest);
 91                    JournalArticleServiceUtil.expireArticle(
 92                            ja.getGroupId(),ja.getArticleId(), ja.getVersion(), ja.getUrlTitle(), serviceContext);
 93                   
 94                   
 95                } catch (SystemException e) {
 96                    // TODO Auto-generated catch block
 97                    e.printStackTrace();
 98                } catch (PortalException e) {
 99                    // TODO Auto-generated catch block
100                    e.printStackTrace();
101                }
102               
103            }
Oliver Bayer
RE: how to find Web Content currently attached with web content Display
May 16, 2013 1:16 AM
Answer

Oliver Bayer

Rank: Liferay Master

Posts: 875

Join Date: February 18, 2009

Recent Posts

No problem, I'm glad I could help a bit.
Thanks for sharing your working code.