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.service.portlet;
35  
36  import fr.paris.lutece.plugins.whatsnew.business.PortletDocumentLink;
37  import fr.paris.lutece.plugins.whatsnew.business.portlet.WhatsNewPortlet;
38  import fr.paris.lutece.plugins.whatsnew.business.portlet.WhatsNewPortletHome;
39  import fr.paris.lutece.plugins.whatsnew.service.WhatsNewPlugin;
40  import fr.paris.lutece.portal.business.portlet.PortletHome;
41  import fr.paris.lutece.portal.service.plugin.Plugin;
42  import fr.paris.lutece.portal.service.plugin.PluginService;
43  
44  import java.util.List;
45  
46  
47  /**
48   *
49   * WhatsNewPortletService
50   *
51   */
52  public class WhatsNewPortletService
53  {
54      private static WhatsNewPortletService _singleton;
55  
56      /**
57       * Return the ThemeService singleton
58       *
59       * @return the ThemeService singleton
60       */
61      public static WhatsNewPortletService getInstance(  )
62      {
63          if ( _singleton == null )
64          {
65              _singleton = new WhatsNewPortletService(  );
66          }
67  
68          return _singleton;
69      }
70  
71      /**
72       * Init
73       */
74      public void init(  )
75      {
76      }
77  
78      /**
79       * Get the portlet with the given portlet id
80       * @param nPortletId the portlet id
81       * @return a {@link WhatsNewPortlet}
82       */
83      public WhatsNewPortlet getPortlet( int nPortletId )
84      {
85          return (WhatsNewPortlet) PortletHome.findByPrimaryKey( nPortletId );
86      }
87  
88      /**
89       * Get the portlet type id
90       * @return the portlet type id
91       */
92      public String getPortletTypeId(  )
93      {
94          return WhatsNewPortletHome.getInstance(  ).getPortletTypeId(  );
95      }
96  
97      /**
98       * Create a new {@link WhatsNewPortlet}
99       * @param portlet a {@link WhatsNewPortlet}
100      */
101     public void create( WhatsNewPortlet portlet )
102     {
103         WhatsNewPortletHome.getInstance(  ).create( portlet );
104     }
105 
106     /**
107      * Update a {@link WhatsNewPortlet}
108      * @param portlet a {@link WhatsNewPortlet}
109      */
110     public void update( WhatsNewPortlet portlet )
111     {
112         WhatsNewPortletHome.getInstance(  ).update( portlet );
113     }
114 
115     /**
116      * Remove a {@link WhatsNewPortlet}
117      * @param portlet a {@link WhatsNewPortlet}
118      */
119     public void remove( WhatsNewPortlet portlet )
120     {
121         Plugin plugin = PluginService.getPlugin( WhatsNewPlugin.PLUGIN_NAME );
122         WhatsNewPortletHome.getInstance(  ).remove( portlet );
123         removeModeratedElements( portlet, plugin );
124     }
125 
126     /**
127      * Select all WhatsNewPortlet
128      * @return a list of {@link WhatsNewPortlet}
129      */
130     public List<WhatsNewPortlet> selectAll(  )
131     {
132         return WhatsNewPortletHome.getInstance(  ).selectAll(  );
133     }
134 
135     /**
136      * Load all page IDs associated to the given whatNewPortletId
137      * @param nWhatsNewPortletId the ID of the portlet
138      * @param plugin {@link Plugin}
139      * @return a list of page IDs
140      */
141     public List<Integer> getPageIdsFromWhatsNewId( int nWhatsNewPortletId, Plugin plugin )
142     {
143         return WhatsNewPortletHome.getInstance(  ).getPageIdsFromWhatsNewId( nWhatsNewPortletId, plugin );
144     }
145 
146     /**
147      * Load all portlet IDs associated to the given whatsNewPortletId
148      * @param nWhatsNewPortletId the ID of the portlet
149      * @param plugin {@link Plugin}
150      * @return a list of portlet IDs
151      */
152     public List<Integer> getPortletIdsFromWhatsNewId( int nWhatsNewPortletId, Plugin plugin )
153     {
154         return WhatsNewPortletHome.getInstance(  ).getPortletIdsFromWhatsNewId( nWhatsNewPortletId, plugin );
155     }
156 
157     /**
158      * Load all the documents associated to the given whatsnewPortletId
159      * @param nWhatsNewPortletId the ID of the portlet
160      * @param plugin {@link Plugin}
161      * @return a list of {@link PortletDocumentLink}
162      */
163     public List<PortletDocumentLink> getDocumentsFromWhatsNewId( int nWhatsNewPortletId, Plugin plugin )
164     {
165         return WhatsNewPortletHome.getInstance(  ).getDocumentsFromWhatsNewId( nWhatsNewPortletId, plugin );
166     }
167 
168     /**
169      * Insert a link between a whatsnew portlet and a page
170      * @param nWhatsNewPortletId the ID of the portlet
171      * @param nPageId the page ID
172      * @param plugin {@link Plugin}
173      */
174     public void createModeratedPage( int nWhatsNewPortletId, int nPageId, Plugin plugin )
175     {
176         WhatsNewPortletHome.getInstance(  ).createModeratedPage( nWhatsNewPortletId, nPageId, plugin );
177     }
178 
179     /**
180      * Insert a link between a whatsnew portlet and a portlet
181      * @param nWhatsNewPortletId the ID of the whatsnew portlet
182      * @param nPortletId the ID of the portlet
183      * @param plugin {@link Plugin}
184      */
185     public void createModeratedPortlet( int nWhatsNewPortletId, int nPortletId, Plugin plugin )
186     {
187         WhatsNewPortletHome.getInstance(  ).createModeratedPortlet( nWhatsNewPortletId, nPortletId, plugin );
188     }
189 
190     /**
191      * Insert a link between a document and a whatsnew portlet
192      * @param nWhatsNewPortletId the ID of the whatsnew portlet
193      * @param pdLink {@link PortletDocumentLink}
194      * @param plugin {@link Plugin}
195      */
196     public void createModeratedDocument( int nWhatsNewPortletId, PortletDocumentLink pdLink, Plugin plugin )
197     {
198         WhatsNewPortletHome.getInstance(  ).createModeratedDocument( nWhatsNewPortletId, pdLink, plugin );
199     }
200 
201     /**
202      * Remove all the moderated elements from the given portlet
203      * @param portlet the WhatsNewPortlet
204      * @param plugin {@link Plugin}
205      */
206     public void removeModeratedElements( WhatsNewPortlet portlet, Plugin plugin )
207     {
208         removeModeratedPortlets( portlet, plugin );
209         removeModeratedPages( portlet, plugin );
210         removeModeratedDocuments( portlet, plugin );
211     }
212 
213     /**
214      * Delete all links of a whatsnew portlet to the pages
215      * @param whatsNewPortlet the portlet
216      * @param plugin {@link Plugin}
217      */
218     public void removeModeratedPages( WhatsNewPortlet whatsNewPortlet, Plugin plugin )
219     {
220         WhatsNewPortletHome.getInstance(  ).removeModeratedPages( whatsNewPortlet.getId(  ), plugin );
221     }
222 
223     /**
224      * Delete all links of a whatsnew portlet to the portlets
225      * @param whatsNewPortlet the portlet
226      * @param plugin {@link Plugin}
227      */
228     public void removeModeratedPortlets( WhatsNewPortlet whatsNewPortlet, Plugin plugin )
229     {
230         WhatsNewPortletHome.getInstance(  ).removeModeratedPortlets( whatsNewPortlet.getId(  ), plugin );
231     }
232 
233     /**
234      * Delete all links of a whatsnew portlet to the documents
235      * @param whatsNewPortlet the portlet
236      * @param plugin {@link Plugin}
237      */
238     public void removeModeratedDocuments( WhatsNewPortlet whatsNewPortlet, Plugin plugin )
239     {
240         WhatsNewPortletHome.getInstance(  ).removeModeratedDocuments( whatsNewPortlet.getId(  ), plugin );
241     }
242 
243     /**
244      * Delete a link between a whatsnew portlet and a page
245      * @param nWhatsNewPortletId the ID of the portlet
246      * @param nPageId the page ID
247      * @param plugin {@link Plugin}
248      */
249     public void removeModeratedPage( int nWhatsNewPortletId, int nPageId, Plugin plugin )
250     {
251         WhatsNewPortletHome.getInstance(  ).removeModeratedPage( nWhatsNewPortletId, nPageId, plugin );
252     }
253 
254     /**
255      * Delete a link between a whatsnew portlet and a portlet
256      * @param nWhatsNewPortletId the ID of the whatsnew portlet
257      * @param nPortletId the ID of the portlet
258      * @param plugin {@link Plugin}
259      */
260     public void removeModeratedPortlet( int nWhatsNewPortletId, int nPortletId, Plugin plugin )
261     {
262         WhatsNewPortletHome.getInstance(  ).removeModeratedPortlet( nWhatsNewPortletId, nPortletId, plugin );
263     }
264 
265     /**
266      * Delete a link between a whatsnew portlet and a document
267      * @param nWhatsNewPortletId the ID of the portlet
268      * @param pdLink {@link PortletDocumentLink}
269      * @param plugin {@link Plugin}
270      */
271     public void removeModeratedDocument( int nWhatsNewPortletId, PortletDocumentLink pdLink, Plugin plugin )
272     {
273         WhatsNewPortletHome.getInstance(  ).removeModeratedDocument( nWhatsNewPortletId, pdLink, plugin );
274     }
275 }