View Javadoc
1   /*
2    * Copyright (c) 2002-2017, 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.links.business.portlet;
35  
36  import fr.paris.lutece.plugins.links.business.Link;
37  import fr.paris.lutece.portal.business.portlet.IPortletInterfaceDAO;
38  import fr.paris.lutece.portal.business.portlet.Portlet;
39  import fr.paris.lutece.portal.business.portlet.PortletHome;
40  import fr.paris.lutece.portal.business.portlet.PortletTypeHome;
41  import fr.paris.lutece.portal.service.spring.SpringContextService;
42  import fr.paris.lutece.util.ReferenceList;
43  
44  import java.util.Collection;
45  
46  
47  /**
48   * This class provides instances management methods for LinkPortlet objects
49   */
50  public class LinksPortletHome extends PortletHome
51  {
52      /////////////////////////////////////////////////////////////////////////////////
53      // Constantes
54  
55      /* This class implements the Singleton design pattern. */
56      private static LinksPortletHome _singleton = null;
57  
58      // Static variable pointed at the DAO instance
59      private static ILinksPortletDAO/../../../../fr/paris/lutece/plugins/links/business/portlet/ILinksPortletDAO.html#ILinksPortletDAO">ILinksPortletDAO _dao = (ILinksPortletDAO) SpringContextService.getPluginBean( "links",
60              "linksPortletDAO" );
61  
62      /**
63       * Constructor
64       */
65      public LinksPortletHome(  )
66      {
67          if ( _singleton == null )
68          {
69              _singleton = this;
70          }
71      }
72  
73      /**
74       * Returns The type of the portlet
75       *
76       * @return The type of the portlet (integer)
77       */
78      public String getPortletTypeId(  )
79      {
80          String strCurrentClassName = this.getClass(  ).getName(  );
81          String strPortletTypeId = PortletTypeHome.getPortletTypeId( strCurrentClassName );
82  
83          return strPortletTypeId;
84      }
85  
86      /**
87       * Returns the instance of LinksPortletHome
88       *
89       * @return the LinksPortletHome instance
90       */
91      public static PortletHome getInstance(  )
92      {
93          if ( _singleton == null )
94          {
95              _singleton = new LinksPortletHome(  );
96          }
97  
98          return _singleton;
99      }
100 
101     /**
102      * Returns the instance of the Link portlet DAO singleton
103      *
104      * @return the instance of the DAO singleton
105      */
106     public IPortletInterfaceDAO getDAO(  )
107     {
108         //        return LinksPortletDAO.getInstance(  );
109         return _dao;
110     }
111 
112     /**
113      * Returns a list of all the links
114      *
115      * @return a list of links
116      */
117     public static ReferenceList getLinksList(  )
118     {
119         return _dao.selectLinksList(  );
120     }
121 
122     /**
123      * Returns the list of links in a specified portlet
124      *
125      * @param nPortletId The identifier of the portlet to check
126      * @return A collection of links objects
127      */
128     public static Collection<Link> getLinksInPortletList( int nPortletId )
129     {
130         return _dao.selectLinksInPortletList( nPortletId );
131     }
132 
133     /**
134      * Insert a specified link in a specified Links portlet with a specified order
135      *
136      * @param nPortletId The identifier of the portlet to be inserted
137      * @param nLinkId The identifier of the link to insert
138      * @param nOrder The order of the inserted link
139      */
140     public static void insertLink( int nPortletId, int nLinkId, int nOrder )
141     {
142         _dao.insertLink( nPortletId, nLinkId, nOrder );
143 
144         // Invalidate portlet
145         invalidate( nPortletId );
146     }
147 
148     /**
149      * Remove a link from a portlet
150      *
151      * @param nPortletId The identifier of the portlet from wich the link is removed
152      * @param nLinkId The identifier of the link to remove
153      */
154     public static void removeLink( int nPortletId, int nLinkId )
155     {
156         _dao.deleteLink( nPortletId, nLinkId );
157 
158         // Invalidate portlet
159         invalidate( nPortletId );
160     }
161 
162     /**
163      * Removes a link from all the portlets
164          * @param nLinkId The identifier of the link
165      */
166     public static void removeLinkFromPortlets( int nLinkId )
167     {
168         _dao.removeLinkFromPortlets( nLinkId );
169     }
170 
171     /**
172      * Verify if an link is already in a portlet
173      *
174      * @param nPortletId The identifier of the portlet to check
175      * @param nLinkId The identifier of the link to inscribe
176      * @return A boolean of the result
177      */
178     public static boolean testDuplicate( int nPortletId, int nLinkId )
179     {
180         return _dao.testDuplicate( nPortletId, nLinkId );
181     }
182 
183     /**
184      * Return the order of an link in a specified portlet
185      *
186      * @param nPortletId The identifier of the portlet to check
187      * @param nLinkId The identifier of the link
188      * @return The order of the link
189      */
190     public static int getLinkOrder( int nPortletId, int nLinkId )
191     {
192         return _dao.selectLinkOrder( nPortletId, nLinkId );
193     }
194 
195     /**
196      * Return the max order of a portlet
197      *
198      * @param nPortletId The identifier of the portlet
199      * @return The max order
200      */
201     public static int getMaxOrder( int nPortletId )
202     {
203         return _dao.selectMaxOrder( nPortletId );
204     }
205 
206     /**
207      * Returns the maximum order of the portlets in the links page
208      *
209      * @return the maximum order
210      */
211     public static int getPortletMaxOrder(  )
212     {
213         return _dao.selectPortletMaxOrder(  );
214     }
215 
216     /**
217      * Update the order of a specified link in a specified portlet
218      *
219      * @param nOrder The new order of the link
220      * @param nPortletId The identifier of the portlet to update
221      * @param nLinkId The identifier of the link who has a new order
222      */
223     public static void updateLinkOrder( int nOrder, int nPortletId, int nLinkId )
224     {
225         _dao.storeLinkOrder( nOrder, nPortletId, nLinkId );
226         invalidate( nPortletId );
227     }
228 
229     /**
230      * Return the Id of an link by is order in a portlet
231      *
232      * @param nPortletId The identifier of the portlet in wich the link is inscribed
233      * @param nOrder The  order of the link
234      * @return The identifier of the link
235      */
236     public static int getLinkIdByOrder( int nPortletId, int nOrder )
237     {
238         return _dao.selectLinkIdByOrder( nPortletId, nOrder );
239     }
240 
241     /**
242      * Returns Links portlet list
243      *
244      * @return the list of the links portlets in the database as a links portlets Collection object
245      */
246     public static ReferenceList findUnselectedPortlets(  )
247     {
248         return _dao.findUnselectedPortlets(  );
249     }
250 
251     /**
252      * Returns a Collection of all the portlets of the links page
253      *
254      * @return collection
255      */
256     public static Collection<Portlet> getPortletsInLinksPage(  )
257     {
258         return _dao.selectPortletsInLinksPage(  );
259     }
260 
261     /**
262      * Returns the order of a portlet in the links page
263      *
264      * @param nPortletId The identifier of the portlet
265      * @return order
266      */
267     public static int getPortletOrder( int nPortletId )
268     {
269         return _dao.selectPortletOrder( nPortletId );
270     }
271 
272     /**
273      * Removes a portlet from the links page
274      *
275          * @param nPortletId The identifier of the portlet
276      */
277     public static void removePortlet( int nPortletId )
278     {
279         _dao.removePortlet( nPortletId );
280     }
281 
282     /**
283      * Inserts a portlet in the links page
284      *
285          * @param nPortletId The identifier of the portlet
286      * @param nOrder The order of the portlet
287      */
288     public static void insertPortlet( int nPortletId, int nOrder )
289     {
290         _dao.insertPortlet( nPortletId, nOrder );
291     }
292 
293     /**
294      * Returns the Id of a portlet from its order in the links page
295      *
296          * @param nOrder The order of the portlet
297      * @return the portlet Id
298      */
299     public static int getPortletIdByOrder( int nOrder )
300     {
301         return _dao.selectPortletIdByOrder( nOrder );
302     }
303 
304     /**
305      * Updates the order of a portlet in the links page
306      *
307          * @param nOrder The order of the portlet
308          * @param nPortletId The identifier of the portlet
309      */
310     public static void updatePortletOrder( int nOrder, int nPortletId )
311     {
312         _dao.storePortletOrder( nOrder, nPortletId );
313     }
314 }