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     /**
168      * Load all BlogPublication
169      * 
170      * @return list BlogPublication
171      */
172     public static List<BlogPublication> getAllDocPublication( )
173     {
174         return _dao.loadAllBlogsPublication( _plugin );
175 
176     }
177 
178     /**
179      * Find the list of {@link BlogPublication} objects specified the status and published at or after the specified date
180      * 
181      * @param datePublishing
182      *            The publication date
183      * @param dateEndPublishing
184      *            The end publication date
185      * @param nStatus
186      *            The status
187      * @return The {@link BlogPublication} objects {@link Collection} ordered by BlogOrder ascending. The list is empty if no objects found.
188      */
189     public static Collection<BlogPublication> findSinceDatePublishingAndStatus( Date datePublishing, Date dateEndPublishing, int nStatus )
190     {
191         return _dao.selectSinceDatePublishingAndStatus( datePublishing, dateEndPublishing, nStatus, _plugin );
192     }
193 
194     /**
195      * Get the list of id of published Blogs associated with a given collection of portlets.
196      * 
197      * @param nPortletsIds
198      *            The list of portlet ids.
199      * @param datePublishing
200      * @param dateEndPublishing
201      *            The end publication date
202      * @param plugin
203      *            The Blog plugin
204      * @return The list of Blogs id.
205      */
206     public static List<Integer> getPublishedBlogsIdsListByPortletIds( int [ ] nPortletsIds, Date datePublishing, Date dateEndPublishing, Plugin plugin )
207     {
208         return _dao.getPublishedBlogsIdsListByPortletIds( nPortletsIds, datePublishing, dateEndPublishing, plugin );
209     }
210 
211     /**
212      * Get the list of id of published Blogs, associated with a given collection of porlets, which has been updated since the dateUpdated
213      * 
214      * @param nPortletsIds
215      *            The list of portlet ids.
216      * @param dateUpdated
217      *            The date from the blogs had to be updated
218      * @param plugin
219      *            The plugin
220      * @return The list of Blogs id.
221      */
222     public static List<Integer> getLastPublishedDocumentsIdsListByPortletIds( int [ ] nPortletsIds, Date dateUpdated, Plugin plugin )
223     {
224         return _dao.getLastPublishedBlogsIdsListByPortletIds( nPortletsIds, dateUpdated, plugin );
225     }
226 
227     /**
228      * Counts the number of valid publication of a blog at a given date.
229      * 
230      * @param nIdBlog
231      *            The blog id
232      * @param date
233      *            The date
234      * @return The count
235      */
236     public static int countPublicationByIdBlogAndDate( int nIdBlog, Date date )
237     {
238         return _dao.countPublicationByIdBlogAndDate( nIdBlog, date, _plugin );
239     }
240 }