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.spaces;
35
36 import fr.paris.lutece.portal.service.spring.SpringContextService;
37 import fr.paris.lutece.util.ReferenceList;
38
39 import java.util.Collection;
40 import java.util.List;
41 import java.util.Locale;
42
43
44 /**
45 * This class provides instances management methods (create, find, ...) for
46 * DocumentSpace objects
47 */
48 public final class DocumentSpaceHome
49 {
50 // Static variable pointed at the DAO instance
51 private static IDocumentSpaceDAO _dao = SpringContextService.getBean( "document.documentSpaceDAO" );
52
53 /**
54 * Private constructor - this class need not be instantiated
55 */
56 private DocumentSpaceHome( )
57 {
58 }
59
60 /**
61 * Creation of an instance of documentSpace
62 *
63 * @param documentSpace The instance of the documentSpace which contains the
64 * informations to store
65 * @return The instance of documentSpace which has been created with its
66 * primary key.
67 */
68 public static DocumentSpace/../../../../../fr/paris/lutece/plugins/document/business/spaces/DocumentSpace.html#DocumentSpace">DocumentSpace create( DocumentSpace documentSpace )
69 {
70 _dao.insert( documentSpace );
71
72 return documentSpace;
73 }
74
75 /**
76 * Update of the documentSpace which is specified in parameter
77 *
78 * @param documentSpace The instance of the documentSpace which contains the
79 * data to store
80 * @return The instance of the documentSpace which has been updated
81 */
82 public static DocumentSpace/../../../../../fr/paris/lutece/plugins/document/business/spaces/DocumentSpace.html#DocumentSpace">DocumentSpace update( DocumentSpace documentSpace )
83 {
84 _dao.store( documentSpace );
85
86 return documentSpace;
87 }
88
89 /**
90 * Remove the DocumentSpace whose identifier is specified in parameter
91 *
92 * @param nDocumentSpaceId The id of the document space
93 */
94 public static void remove( int nDocumentSpaceId )
95 {
96 _dao.delete( nDocumentSpaceId );
97 }
98
99 ///////////////////////////////////////////////////////////////////////////
100 // Finders
101
102 /**
103 * Returns an instance of a documentSpace whose identifier is specified in
104 * parameter
105 *
106 * @param nKey The Primary key of the documentSpace
107 * @return An instance of documentSpace
108 */
109 public static DocumentSpace findByPrimaryKey( int nKey )
110 {
111 return _dao.load( nKey );
112 }
113
114 /**
115 * Returns a collection of documentSpaces objects
116 *
117 * @return A collection of documentSpaces
118 * @param nParentSpaceId The id of the parent document space
119 */
120 public static List<DocumentSpace> findChilds( int nParentSpaceId )
121 {
122 return _dao.selectChilds( nParentSpaceId, null );
123 }
124
125 /**
126 * Returns a collection of documentSpaces objects by type of document
127 *
128 * @return A collection of documentSpaces
129 * @param nParentSpaceId The id of the parent document space
130 * @param strCodeType the document type
131 */
132 public static List<DocumentSpace> findChildsByTypeOfDocument( int nParentSpaceId, String strCodeType )
133 {
134 return _dao.selectChilds( nParentSpaceId, strCodeType );
135 }
136
137 /**
138 * Returns a collection of documentSpaces objects by type of document
139 *
140 * @param strCodeType the document type filter
141 * @param createDocumentIsAllowed code to define if document creation is
142 * allowed or not
143 * @return The Collection of the DocumentSpaces
144 */
145 public static List<DocumentSpace> findSpacesAllowingDocumentCreationByDocumentType( String strCodeType,
146 int createDocumentIsAllowed )
147 {
148 return _dao.selectSpacesAllowingDocumentCreationByDocumentType( strCodeType, createDocumentIsAllowed );
149 }
150
151 /**
152 * Returns a ReferenceList of documentSpaces objects
153 * @return A ReferenceList of documentSpaces
154 */
155 public static ReferenceList getDocumentSpaceList( )
156 {
157 return _dao.getDocumentSpaceList( );
158 }
159
160 /**
161 * Returns a ReferenceList of documentSpaces objects
162 *
163 * @return A ReferenceList of documentSpaces
164 * @param locale The locale
165 */
166 public static ReferenceList getViewTypeList( Locale locale )
167 {
168 return _dao.getViewTypeList( locale );
169 }
170
171 /**
172 * Gets a list of icons available or space customization
173 * @return A list of icons
174 */
175 public static ReferenceList getIconsList( )
176 {
177 return _dao.getIconsList( );
178 }
179
180 /**
181 * Select all spaces
182 * @return A collection of all spaces.
183 */
184 public static Collection<DocumentSpace> findAll( )
185 {
186 return _dao.selectAll( );
187 }
188
189 /**
190 * Returns all allowed document types for a given space
191 * @param nSpaceId The space Id
192 * @return Allowed documents types as a ReferenceList
193 */
194 public static ReferenceList getAllowedDocumentTypes( int nSpaceId )
195 {
196 return _dao.getAllowedDocumentTypes( nSpaceId );
197 }
198 }