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.autopublication;
35
36 import fr.paris.lutece.plugins.document.business.spaces.DocumentSpace;
37 import fr.paris.lutece.portal.business.portlet.Portlet;
38 import fr.paris.lutece.portal.service.spring.SpringContextService;
39
40 import java.util.Collection;
41
42 /**
43 * This class provides instances management methods for DocumentAutoPublication objects
44 *
45 */
46 public class DocumentAutoPublicationHome
47 {
48 // Static variable pointed at the DAO instance
49 private static IDocumentAutoPublicationDAO _dao = SpringContextService.getBean( "document.documentAutoPublicationDAO" );
50
51 /* This class implements the Singleton design pattern. */
52
53 /**
54 * Constructor
55 */
56 private DocumentAutoPublicationHome( )
57 {
58 }
59
60 /**
61 * Insert a new document auto publication
62 *
63 * @param documentAutoPublication
64 * the instance of the DocumentAutoPublication object to insert
65 */
66 public static void add( DocumentAutoPublication documentAutoPublication )
67 {
68 _dao.insert( documentAutoPublication );
69 }
70
71 /**
72 * Loads all data Document Auto Publication
73 *
74 * @return The {@link Collection} of {@link DocumentAutoPublication} object
75 */
76 public static Collection<DocumentAutoPublication> findAll( )
77 {
78 return _dao.load( );
79 }
80
81 /**
82 * Loads the data of Document Auto Publication whose identifier is specified in parameter
83 *
84 * @param nPortletId
85 * The {@link Portlet} identifier
86 * @param nSpaceId
87 * The {@link DocumentSpace} identifier
88 * @return The {@link DocumentAutoPublication} object
89 */
90 public static DocumentAutoPublication findByPrimaryKey( int nPortletId, int nSpaceId )
91 {
92 return _dao.load( nPortletId, nSpaceId );
93 }
94
95 /**
96 * Load the list of Document Auto Publication whose portlet identifier is specified in parameter
97 *
98 * @param nPortletId
99 * The {@link Portlet} identifier
100 * @return The {@link Collection} of {@link DocumentAutoPublication} object
101 */
102 public static Collection<DocumentAutoPublication> findByPortletId( int nPortletId )
103 {
104 return _dao.selectByPortletId( nPortletId );
105 }
106
107 /**
108 * Load the list of Document Auto Publication whose {@link DocumentSpace} identifier is specified in parameter
109 *
110 * @param nSpaceId
111 * The {@link DocumentSpace} identifier
112 * @return The {@link Collection} of {@link DocumentAutoPublication} object
113 */
114 public static Collection<DocumentAutoPublication> findBySpaceId( int nSpaceId )
115 {
116 return _dao.selectBySpaceId( nSpaceId );
117 }
118
119 /**
120 * Update the document auto publication
121 *
122 * @param documentAutoPublication
123 * The DocumentAutoPublication to update
124 */
125 public static void update( DocumentAutoPublication documentAutoPublication )
126 {
127 _dao.store( documentAutoPublication );
128 }
129
130 /**
131 * Delete a document auto publication object
132 *
133 * @param nPortletId
134 * the portlet identifier
135 * @param nSpaceId
136 * the space identifier
137 */
138 public static void remove( int nPortletId, int nSpaceId )
139 {
140 _dao.delete( nPortletId, nSpaceId );
141 }
142
143 /**
144 * Delete All Space from a portlet
145 *
146 * @param nPortletId
147 * the portlet identifier
148 */
149 public static void removeAllSpaces( int nPortletId )
150 {
151 _dao.deleteAllSpaces( nPortletId );
152 }
153
154 /**
155 * Check if the specified portlet is auto published
156 *
157 * @param nPortletId
158 * The portlet id
159 * @return true if portlet is auto published, false else.
160 */
161 public static boolean isPortletAutoPublished( int nPortletId )
162 {
163 if ( _dao.selectByPortletId( nPortletId ).size( ) == 0 )
164 {
165 return false;
166 }
167
168 return true;
169 }
170
171 /**
172 * Check if the specified Space is auto published
173 *
174 * @param nSpaceId
175 * The space id
176 * @return true if Space is auto published, false else.
177 */
178 public static boolean isSpaceAutoPublished( int nSpaceId )
179 {
180 if ( _dao.selectBySpaceId( nSpaceId ).size( ) == 0 )
181 {
182 return false;
183 }
184
185 return true;
186 }
187 }