View Javadoc
1   /*
2    * Copyright (c) 2002-2014, Mairie de Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.whatsnew.business.portlet;
35  
36  import fr.paris.lutece.plugins.whatsnew.business.PortletDocumentLink;
37  import fr.paris.lutece.portal.business.portlet.IPortletInterfaceDAO;
38  import fr.paris.lutece.portal.business.portlet.PortletHome;
39  import fr.paris.lutece.portal.business.portlet.PortletTypeHome;
40  import fr.paris.lutece.portal.service.plugin.Plugin;
41  import fr.paris.lutece.portal.service.spring.SpringContextService;
42  
43  import java.util.List;
44  
45  
46  /**
47   *
48   * WhatsNewPortletHome
49   *
50   */
51  public class WhatsNewPortletHome extends PortletHome
52  {
53      // Static variable pointed at the DAO instance
54      private static IWhatsNewPortletDAO _dao = (IWhatsNewPortletDAO) SpringContextService.getPluginBean( "whatsnew",
55              "whatsnew.whatsNewPortletDAO" );
56  
57      /** This class implements the Singleton design pattern. */
58      private static WhatsNewPortletHome _singleton;
59  
60      /**
61       * Constructor
62      */
63      public WhatsNewPortletHome(  )
64      {
65      }
66  
67      /**
68       * Returns the instance of the WhatsNewPortletHome singleton
69       * @return the WhatsNewPortletHome instance
70       */
71      public static WhatsNewPortletHome getInstance(  )
72      {
73          if ( _singleton == null )
74          {
75              _singleton = new WhatsNewPortletHome(  );
76          }
77  
78          return _singleton;
79      }
80  
81      /**
82       * Returns the type of the portlet
83       * @return The type of the portlet
84       */
85      public String getPortletTypeId(  )
86      {
87          String strCurrentClassName = this.getClass(  ).getName(  );
88          String strPortletTypeId = PortletTypeHome.getPortletTypeId( strCurrentClassName );
89  
90          return strPortletTypeId;
91      }
92  
93      /**
94       * Returns the instance of the WhatsNewPortletDAO singleton
95       * @return the instance of the WhatsNewPortletDAO
96       */
97      public IPortletInterfaceDAO getDAO(  )
98      {
99          return _dao;
100     }
101 
102     /**
103      * Select all WhatsNewPortlet
104      * @return a list of {@link WhatsNewPortlet}
105      */
106     public List<WhatsNewPortlet> selectAll(  )
107     {
108         return _dao.findAll(  );
109     }
110 
111     /**
112      * Load all page IDs associated to the given whatNewPortletId
113      * @param nWhatsNewPortletId the ID of the portlet
114      * @param plugin {@link Plugin}
115      * @return a list of page IDs
116      */
117     public List<Integer> getPageIdsFromWhatsNewId( int nWhatsNewPortletId, Plugin plugin )
118     {
119         return _dao.loadPageIdsFromWhatsNewPortletId( nWhatsNewPortletId, plugin );
120     }
121 
122     /**
123      * Load all portlet IDs associated to the given whatsNewPortletId
124      * @param nWhatsNewPortletId the ID of the portlet
125      * @param plugin {@link Plugin}
126      * @return a list of portlet IDs
127      */
128     public List<Integer> getPortletIdsFromWhatsNewId( int nWhatsNewPortletId, Plugin plugin )
129     {
130         return _dao.loadPortletIdsFromWhatsNewPortletId( nWhatsNewPortletId, plugin );
131     }
132 
133     /**
134      * Load all the documents associated to the given whatsnewPortletId
135      * @param nWhatsNewPortletId the ID of the portlet
136      * @param plugin {@link Plugin}
137      * @return a list of {@link PortletDocumentLink}
138      */
139     public List<PortletDocumentLink> getDocumentsFromWhatsNewId( int nWhatsNewPortletId, Plugin plugin )
140     {
141         return _dao.loadDocumentFromWhatsNewPortletId( nWhatsNewPortletId, plugin );
142     }
143 
144     /**
145      * Insert a link between a whatsnew portlet and a page
146      * @param nWhatsNewPortletId the ID of the portlet
147      * @param nPageId the page ID
148      * @param plugin {@link Plugin}
149      */
150     public void createModeratedPage( int nWhatsNewPortletId, int nPageId, Plugin plugin )
151     {
152         _dao.insertPageForWhatsNew( nWhatsNewPortletId, nPageId, plugin );
153     }
154 
155     /**
156      * Insert a link between a whatsnew portlet and a portlet
157      * @param nWhatsNewPortletId the ID of the whatsnew portlet
158      * @param nPortletId the ID of the portlet
159      * @param plugin {@link Plugin}
160      */
161     public void createModeratedPortlet( int nWhatsNewPortletId, int nPortletId, Plugin plugin )
162     {
163         _dao.insertPortletForWhatsNew( nWhatsNewPortletId, nPortletId, plugin );
164     }
165 
166     /**
167      * Insert a link between a document and a whatsnew portlet
168      * @param nWhatsNewPortletId the ID of the whatsnew portlet
169      * @param pdLink {@link PortletDocumentLink}
170      * @param plugin {@link Plugin}
171      */
172     public void createModeratedDocument( int nWhatsNewPortletId, PortletDocumentLink pdLink, Plugin plugin )
173     {
174         _dao.insertDocumentForWhatsNew( nWhatsNewPortletId, pdLink, plugin );
175     }
176 
177     /**
178      * Delete all links of a whatsnew portlet to the pages
179      * @param nWhatsNewPortletId the ID of the portlet
180      * @param plugin {@link Plugin}
181      */
182     public void removeModeratedPages( int nWhatsNewPortletId, Plugin plugin )
183     {
184         _dao.deletePagesFromWhatsNew( nWhatsNewPortletId, plugin );
185     }
186 
187     /**
188      * Delete all links of a whatsnew portlet to the portlets
189      * @param nWhatsNewPortletId the ID of the whatsnew portlet
190      * @param plugin {@link Plugin}
191      */
192     public void removeModeratedPortlets( int nWhatsNewPortletId, Plugin plugin )
193     {
194         _dao.deletePortletsFromWhatsNew( nWhatsNewPortletId, plugin );
195     }
196 
197     /**
198      * Delete all links of a whatsnew portlet to the documents
199      * @param nWhatsNewPortletId the ID of the portlet
200      * @param plugin {@link Plugin}
201      */
202     public void removeModeratedDocuments( int nWhatsNewPortletId, Plugin plugin )
203     {
204         _dao.deleteDocumentsFromWhatsNew( nWhatsNewPortletId, plugin );
205     }
206 
207     /**
208      * Delete a link between a whatsnew portlet and a page
209      * @param nWhatsNewPortletId the ID of the portlet
210      * @param nPageId the page ID
211      * @param plugin {@link Plugin}
212      */
213     public void removeModeratedPage( int nWhatsNewPortletId, int nPageId, Plugin plugin )
214     {
215         _dao.deleteLinkWhatsNewPortletToPage( nWhatsNewPortletId, nPageId, plugin );
216     }
217 
218     /**
219      * Delete a link between a whatsnew portlet and a portlet
220      * @param nWhatsNewPortletId the ID of the whatsnew portlet
221      * @param nPortletId the ID of the portlet
222      * @param plugin {@link Plugin}
223      */
224     public void removeModeratedPortlet( int nWhatsNewPortletId, int nPortletId, Plugin plugin )
225     {
226         _dao.deleteLinkWhatsNewPortletToPortlet( nWhatsNewPortletId, nPortletId, plugin );
227     }
228 
229     /**
230      * Delete a link between a whatsnew portlet and a document
231      * @param nWhatsNewPortletId the ID of the portlet
232      * @param pdLink {@link PortletDocumentLink}
233      * @param plugin {@link Plugin}
234      */
235     public void removeModeratedDocument( int nWhatsNewPortletId, PortletDocumentLink pdLink, Plugin plugin )
236     {
237         _dao.deleteLinkWhatsNewPortletToDocument( nWhatsNewPortletId, pdLink, plugin );
238     }
239 }