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