View Javadoc
1   /*
2    * Copyright (c) 2002-2019, Mairie de 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.appcenter.business;
35  
36  import fr.paris.lutece.plugins.appcenter.business.organization.OrganizationManager;
37  import fr.paris.lutece.plugins.appcenter.business.resourcetype.ResourceTypeValue;
38  import fr.paris.lutece.plugins.appcenter.business.resourcetype.AbstractAppCenterResourceType;
39  import fr.paris.lutece.portal.business.file.File;
40  import fr.paris.lutece.portal.business.file.FileHome;
41  import fr.paris.lutece.portal.business.physicalfile.PhysicalFile;
42  import fr.paris.lutece.portal.business.physicalfile.PhysicalFileHome;
43  
44  import javax.validation.constraints.NotNull;
45  import javax.validation.constraints.Size;
46  import org.hibernate.validator.constraints.NotEmpty;
47  import org.apache.commons.codec.binary.Base64;
48  import java.io.Serializable;
49  import java.util.List;
50  
51  import javax.validation.constraints.NotNull;
52  import javax.validation.constraints.Size;
53  import org.hibernate.validator.constraints.NotEmpty;
54  
55  /**
56   * This is the business class for the object Application
57   */
58  public class Application implements Serializable
59  {
60      private static final long serialVersionUID = 1L;
61      private static final String EMPTY_JSON_OBJECT = "{}";
62  
63      // Variables declarations
64      private int _nId;
65  
66      @NotEmpty( message = "#i18n{appcenter.validation.application.Name.notEmpty}" )
67      @Size( max = 50, message = "#i18n{appcenter.validation.application.Name.size}" )
68      private String _strName;
69      private String _strCode;
70  
71      @Size( max = 255, message = "#i18n{appcenter.validation.application.Description.size}" )
72      private String _strDescription;
73  
74      @NotNull( message = "appcenter.validation.application.OrganizationManager.notNull" )
75      private OrganizationManager _organizationManager;
76      private String _strApplicationData;
77  
78      private List<UserApplicationRole> _listAuthorizations;
79  
80      private List<Environment> _listEnvironment;
81  
82      private int _lIdFileLogo;
83      
84      private boolean _bActive;
85      
86      /**
87       * Returns the Id
88       * 
89       * @return The Id
90       */
91      public int getId( )
92      {
93          return _nId;
94      }
95  
96      /**
97       * Sets the Id
98       * 
99       * @param nId
100      *            The Id
101      */
102     public void setId( int nId )
103     {
104         _nId = nId;
105     }
106 
107     /**
108      * Returns the Name
109      * 
110      * @return The Name
111      */
112     public String getName( )
113     {
114         return _strName;
115     }
116 
117     /**
118      * Sets the Name
119      * 
120      * @param strName
121      *            The Name
122      */
123     public void setName( String strName )
124     {
125         _strName = strName;
126     }
127 
128     /**
129      * Returns the Description
130      * 
131      * @return The Description
132      */
133     public String getDescription( )
134     {
135         return _strDescription;
136     }
137 
138     /**
139      * Sets the Description
140      * 
141      * @param strDescription
142      *            The Description
143      */
144     public void setDescription( String strDescription )
145     {
146         _strDescription = strDescription;
147     }
148 
149     /**
150      * Returns the organizationManager
151      * 
152      * @return The organizationManager
153      */
154     public OrganizationManager getOrganizationManager( )
155     {
156         return _organizationManager;
157     }
158 
159     /**
160      * Sets the organizationManager
161      * 
162      * @param organizationManager
163      *            The organizationManager
164      */
165     public void setOrganizationManager( OrganizationManager organizationManager )
166     {
167         _organizationManager = organizationManager;
168     }
169 
170     /**
171      * Returns the ApplicationData
172      * 
173      * @return The ApplicationData
174      */
175     public String getApplicationData( )
176     {
177         return ( _strApplicationData != null ) ? _strApplicationData : EMPTY_JSON_OBJECT;
178     }
179 
180     /**
181      * Sets the ApplicationData
182      * 
183      * @param strApplicationData
184      *            The ApplicationData
185      */
186     public void setApplicationData( String strApplicationData )
187     {
188         _strApplicationData = strApplicationData;
189     }
190 
191     /**
192      * Set authorizations
193      * 
194      * @param listAuthorizations
195      *            The authorization list
196      */
197     public void setAuthorizations( List<UserApplicationRole> listAuthorizations )
198     {
199         _listAuthorizations = listAuthorizations;
200     }
201 
202     /**
203      * Get authorizations
204      * 
205      * @return The authorization list
206      */
207     public List<UserApplicationRole> getAuthorizations( )
208     {
209         return _listAuthorizations;
210     }
211 
212     /**
213      * Get application Code
214      * 
215      * @return the application code
216      */
217     public String getCode( )
218     {
219         return _strCode;
220     }
221 
222     /**
223      * 
224      * @param _strCode
225      *            the application code
226      */
227     public void setCode( String _strCode )
228     {
229         this._strCode = ( _strCode != null ) ? _strCode.toUpperCase( ) : null;
230     }
231 
232     /**
233      * Get the environment list
234      * 
235      * @return the environment list
236      */
237     public List<Environment> getListEnvironment( )
238     {
239         return _listEnvironment;
240     }
241 
242     /**
243      * Set the environment list
244      * 
245      * @param listEnvironment
246      *            the environment list
247      */
248     public void setListEnvironment( List<Environment> listEnvironment )
249     {
250         _listEnvironment = listEnvironment;
251     }
252     
253     /**
254      * @return the _lIdFileLogo
255      */
256     public int getIdFileLogo( )
257     {
258         return _lIdFileLogo;
259     }
260 
261     /**
262      * @param lIdFileLogo the _lIdFileLogo to set
263      */
264     public void setIdFileLogo( int lIdFileLogo )
265     {
266         this._lIdFileLogo = lIdFileLogo;
267     }
268 
269     public String getLogoBase64() {
270         String imgAsBase64 = null;
271         if( this._lIdFileLogo != 0)
272         {
273             File file = FileHome.findByPrimaryKey( _lIdFileLogo );
274             PhysicalFile physicalFile =  PhysicalFileHome.findByPrimaryKey( file.getPhysicalFile( ).getIdPhysicalFile( ) );
275             file.setPhysicalFile( physicalFile );
276             byte[] imgBytesAsBase64 = Base64.encodeBase64( file.getPhysicalFile( ).getValue( ) );
277             String imgDataAsBase64 = new String( imgBytesAsBase64 );
278             imgAsBase64 = "data:image/png;base64," + imgDataAsBase64;
279         }
280         return imgAsBase64;
281     }
282 
283     /**
284      * @return the _bActive
285      */
286     public boolean isActive( )
287     {
288         return _bActive;
289     }
290 
291     /**
292      * @param bActive the _bActive to set
293      */
294     public void setActive( boolean bActive )
295     {
296         this._bActive = bActive;
297     }
298 
299     
300 }