View Javadoc
1   /*
2    * Copyright (c) 2002-2021, City of 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.blog.business.portlet;
35  
36  import java.util.Collection;
37  import java.util.Date;
38  import java.util.List;
39  
40  import fr.paris.lutece.plugins.blog.service.BlogPlugin;
41  import fr.paris.lutece.portal.service.plugin.Plugin;
42  import fr.paris.lutece.portal.service.plugin.PluginService;
43  import fr.paris.lutece.portal.service.spring.SpringContextService;
44  
45  public class BlogPublicationHome
46  {
47  
48      private static IBlogPublicationDAO _dao = SpringContextService.getBean( "blog.blogPublicationDAO" );
49      private static Plugin _plugin = PluginService.getPlugin( BlogPlugin.PLUGIN_NAME );
50  
51      /**
52       * Private constructor - this class need not be instantiated
53       */
54      private BlogPublicationHome( )
55      {
56      }
57  
58      /**
59       * Create an instance of the BlogPublication class
60       * 
61       * @param blogPub
62       *            The instance of the BlogPublication which contains the informations to store
63       * @return The instance of BlogPub which has been created.
64       */
65      public static BlogPublication./../../../../fr/paris/lutece/plugins/blog/business/portlet/BlogPublication.html#BlogPublication">BlogPublication create( BlogPublication blogPub )
66      {
67          _dao.insertBlogsId( blogPub, _plugin );
68  
69          return blogPub;
70      }
71  
72      /**
73       * Update an instance of the BlogPublication
74       * 
75       * @param blogPub
76       */
77      public static void update( BlogPublication blogPub )
78      {
79          _dao.store( blogPub, _plugin );
80  
81      }
82  
83      /**
84       * load a list BlogPublication by the Blog identifiant
85       * 
86       * @param nDocId
87       *            The Blog id
88       * @return list of BlogPublication
89       */
90      public static List<BlogPublication> getDocPublicationByIdDoc( int nDocId )
91      {
92          return _dao.loadBlogsId( nDocId, _plugin );
93  
94      }
95  
96      /**
97       * load a list BlogPublication by the portlet id
98       * 
99       * @param nIdPortlet
100      *            The protlet id
101      * @return list of BlogPublication
102      */
103     public static List<BlogPublication> getDocPublicationByPortlet( int nIdPortlet )
104     {
105         return _dao.loadBlogsByPortlet( nIdPortlet, _plugin );
106 
107     }
108 
109     /**
110      * Retrieve all blogs by Portlet and between publication dates.
111      *
112      * @param nIdPortlet
113      *            The portlet id
114      * @param datePublishing
115      *            The publication date
116      * @param dateEndPublishing
117      *            The end publication date
118      * @return list of BlogPublication
119      */
120     public static List<BlogPublication> getDocPublicationByPortletAndPlublicationDate( int nIdPortlet, Date datePublishing, Date dateEndPublishing )
121     {
122         return _dao.loadBlogsByPortletAndPublicationDate( nIdPortlet, datePublishing, dateEndPublishing, _plugin );
123 
124     }
125 
126     /**
127      * load a BlogPublication by Blog id and portlet id
128      * 
129      * @param nPortletId
130      *            The portlet id
131      * @param nDocId
132      *            The Blogs id
133      * @return BlogPublication
134      */
135     public static BlogPublication findDocPublicationByPimaryKey( int nPortletId, int nDocId )
136     {
137         return _dao.loadBlogsPublication( nPortletId, nDocId, _plugin );
138 
139     }
140 
141     /**
142      * Delete the BlogPublication by portlet id
143      * 
144      * @param nIdPortlet
145      *            The portlet id
146      */
147     public static void removeByIdPortlet( int nIdPortlet )
148     {
149         _dao.deleteBlogByIdPortlet( nIdPortlet, _plugin );
150 
151     }
152 
153     /**
154      * Delete the BlogPublication by the primary key
155      * 
156      * @param nIdDoc
157      *            The Blog id
158      * @param nIdPortlet
159      *            The portlet id
160      */
161     public static void remove( int nIdDoc, int nIdPortlet )
162     {
163         _dao.remove( nIdDoc, nIdPortlet, _plugin );
164 
165     }
166     /**
167      * Delete the BlogPublication by the blog id
168      *
169      * @param nIdDoc
170      *            The Blog id
171      */
172     public static void removeByBlogId( int nIdDoc )
173     {
174         _dao.deleteBlogsId( nIdDoc, _plugin );
175 
176     }
177 
178 
179     /**
180      * Load all BlogPublication
181      * 
182      * @return list BlogPublication
183      */
184     public static List<BlogPublication> getAllDocPublication( )
185     {
186         return _dao.loadAllBlogsPublication( _plugin );
187 
188     }
189 
190     /**
191      * Find the list of {@link BlogPublication} objects specified the status and published at or after the specified date
192      * 
193      * @param datePublishing
194      *            The publication date
195      * @param dateEndPublishing
196      *            The end publication date
197      * @param nStatus
198      *            The status
199      * @return The {@link BlogPublication} objects {@link Collection} ordered by BlogOrder ascending. The list is empty if no objects found.
200      */
201     public static Collection<BlogPublication> findSinceDatePublishingAndStatus( Date datePublishing, Date dateEndPublishing, int nStatus )
202     {
203         return _dao.selectSinceDatePublishingAndStatus( datePublishing, dateEndPublishing, nStatus, _plugin );
204     }
205 
206     /**
207      * Get the list of id of published Blogs associated with a given collection of portlets.
208      * 
209      * @param nPortletsIds
210      *            The list of portlet ids.
211      * @param datePublishing
212      * @param dateEndPublishing
213      *            The end publication date
214      * @param plugin
215      *            The Blog plugin
216      * @return The list of Blogs id.
217      */
218     public static List<Integer> getPublishedBlogsIdsListByPortletIds( int [ ] nPortletsIds, Date datePublishing, Date dateEndPublishing, Plugin plugin )
219     {
220         return _dao.getPublishedBlogsIdsListByPortletIds( nPortletsIds, datePublishing, dateEndPublishing, plugin );
221     }
222 
223     /**
224      * Get the list of id of published Blogs, associated with a given collection of porlets, which has been updated since the dateUpdated
225      * 
226      * @param nPortletsIds
227      *            The list of portlet ids.
228      * @param dateUpdated
229      *            The date from the blogs had to be updated
230      * @param plugin
231      *            The plugin
232      * @return The list of Blogs id.
233      */
234     public static List<Integer> getLastPublishedDocumentsIdsListByPortletIds( int [ ] nPortletsIds, Date dateUpdated, Plugin plugin )
235     {
236         return _dao.getLastPublishedBlogsIdsListByPortletIds( nPortletsIds, dateUpdated, plugin );
237     }
238 
239     /**
240      * Counts the number of valid publication of a blog at a given date.
241      * 
242      * @param nIdBlog
243      *            The blog id
244      * @param date
245      *            The date
246      * @return The count
247      */
248     public static int countPublicationByIdBlogAndDate( int nIdBlog, Date date )
249     {
250         return _dao.countPublicationByIdBlogAndDate( nIdBlog, date, _plugin );
251     }
252 
253 }