View Javadoc
1   /*
2    * Copyright (c) 2002-2020, 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.document.business.publication;
35  
36  import fr.paris.lutece.portal.business.portlet.Portlet;
37  import fr.paris.lutece.portal.service.spring.SpringContextService;
38  
39  import java.util.Collection;
40  import java.util.Date;
41  
42  
43  /**
44   * This class provides instances management methods for DocumentPublication objects
45   */
46  public class DocumentPublicationHome
47  {
48      /////////////////////////////////////////////////////////////////////////////////
49      // Constants
50      // Static variable pointed at the DAO instance
51      private static IDocumentPublicationDAO _dao = SpringContextService.getBean( "document.documentPublicationDAO" );
52  
53      /**
54       * Create the documentsPublication object
55       *
56       * @param documentPublication The document Publication object
57       */
58      public static void create( DocumentPublication documentPublication )
59      {
60          _dao.insert( documentPublication );
61  
62          /*IndexationService.getInstance().addIndexerAction( documentPublication.getDocumentId()
63                          , DocumentIndexer.INDEXER_NAME
64                          , IndexerAction.TASK_CREATE
65                          , documentPublication.getPortletId() );*/
66      }
67  
68      /**
69       * Update the {@link DocumentPublication} object
70       *
71       * @param documentPublication The {@link DocumentPublication} object
72       */
73      public static void update( DocumentPublication documentPublication )
74      {
75          _dao.store( documentPublication );
76      }
77  
78      /**
79       * Remove the {@link DocumentPublication} object specified by portlet id and document id
80       *
81       * @param nPortletId the portlet identifier
82       * @param nDocumentId the document identifier
83       */
84      public static void remove( int nPortletId, int nDocumentId )
85      {
86          _dao.delete( nPortletId, nDocumentId );
87      }
88  
89      /**
90       * Remove all {@link DocumentPublication} objects specified by portlet id
91       *
92       * @param nPortletId the portlet identifier
93       */
94      public static void removeFromPortletId( int nPortletId )
95      {
96          _dao.deleteFromPortletId( nPortletId );
97      }
98  
99      /**
100     * Remove all {@link DocumentPublication} objects specified by document id
101     *
102     * @param nDocumentId the document identifier
103     */
104     public static void removeFromDocumentId( int nDocumentId )
105     {
106         _dao.deleteFromDocumentId( nDocumentId );
107     }
108 
109     /**
110      * Find the {@link DocumentPublication} object specified by the portlet id and document id
111      * @param nPortletId The portlet identifier
112      * @param nDocumentId The document identifier
113      * @return The {@link DocumentPublication} object or null if the object does not exists
114      */
115     public static DocumentPublication findByPrimaryKey( int nPortletId, int nDocumentId )
116     {
117         return _dao.select( nPortletId, nDocumentId );
118     }
119 
120     /**
121      * Find the list of {@link DocumentPublication} objects specified by the portlet id
122      * @param nPortletId The portlet identifier
123      * @return The {@link DocumentPublication} objects {@link Collection} ordered by documentOrder ascending. The list is empty if no objects found.
124      */
125     public static Collection<DocumentPublication> findByPortletId( int nPortletId )
126     {
127         return _dao.selectByPortletId( nPortletId );
128     }
129 
130     /**
131      * Find the list of {@link DocumentPublication} objects specified by the document id
132      * @param nDocumentId The document identifier
133      * @return The {@link DocumentPublication} objects {@link Collection} ordered by documentOrder ascending. The list is empty if no objects found.
134      */
135     public static Collection<DocumentPublication> findByDocumentId( int nDocumentId )
136     {
137         return _dao.selectByDocumentId( nDocumentId );
138     }
139 
140     /**
141      * Find the list of {@link DocumentPublication} objects specified by the portlet id and the status
142      * @param nPortletId The portlet identifier
143      * @param nStatus The status
144      * @return The {@link DocumentPublication} objects {@link Collection} ordered by documentOrder ascending. The list is empty if no objects found.
145      */
146     public static Collection<DocumentPublication> findByPortletIdAndStatus( int nPortletId, int nStatus )
147     {
148         return _dao.selectByPortletIdAndStatus( nPortletId, nStatus );
149     }
150 
151     /**
152      * Find the list of {@link DocumentPublication} objects specified by the document id and the status
153      * @param nDocumentId The document identifier
154      * @param nStatus The status
155      * @return The {@link DocumentPublication} objects {@link Collection} ordered by documentOrder ascending. The list is empty if no objects found.
156      */
157     public static Collection<DocumentPublication> findByDocumentIdAndStatus( int nDocumentId, int nStatus )
158     {
159         return _dao.selectByDocumentIdAndStatus( nDocumentId, nStatus );
160     }
161 
162     /**
163      * Find the list of {@link DocumentPublication} objects specified the status and published at or after the specified date
164      * @param datePublishing The publication date
165      * @param nStatus The status
166      * @return The {@link DocumentPublication} objects {@link Collection} ordered by documentOrder ascending. The list is empty if no objects found.
167      */
168     public static Collection<DocumentPublication> findSinceDatePublishingAndStatus( Date datePublishing, int nStatus )
169     {
170         return _dao.selectSinceDatePublishingAndStatus( datePublishing, nStatus );
171     }
172 
173     /**
174      * Find the max document order from a {@link Portlet} id
175      * @param nPortletId the {@link Portlet} identifer
176      * @return The max document order
177      */
178     public static int findMaxDocumentOrderByPortletId( int nPortletId )
179     {
180         return _dao.selectMaxDocumentOrder( nPortletId );
181     }
182 }