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