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.modules.identitystore.business;
35  
36  import com.fasterxml.jackson.annotation.JsonIgnore;
37  import fr.paris.lutece.plugins.appcenter.business.Application;
38  import fr.paris.lutece.plugins.appcenter.business.ApplicationHome;
39  import fr.paris.lutece.plugins.appcenter.business.Demand;
40  import fr.paris.lutece.plugins.appcenter.service.ApplicationService;
41  import fr.paris.lutece.plugins.appcenter.web.Constants;
42  import fr.paris.lutece.portal.service.template.AppTemplateService;
43  import fr.paris.lutece.portal.service.util.AppLogService;
44  import java.io.IOException;
45  import java.util.HashMap;
46  import java.util.Locale;
47  import java.util.Map;
48  import org.hibernate.validator.constraints.NotEmpty;
49  
50  /**
51   * Identitystore Demand
52   */
53  public class IdentitystoreDemand extends Demand
54  {
55      @NotEmpty( message = "#i18n{module.appcenter.identitystore.validation.environment.notEmpty}" )
56      private Map<String, AttributeRight> _mapAttributeRights;
57  
58      public static final String ID_DEMAND_TYPE = "identitystore";
59      public static final String DEMAND_TYPE = "identitystore";
60  
61      private static final String TEMPLATE_IDENTITYSTORE_DEMAND_INFOS = "skin/plugins/appcenter/modules/identitystore/identitystore_demand_infos.html";
62  
63      // Markers
64      private static final String MARK_MAP_ATTRIBUTES = "mapAttributes";
65  
66      /**
67       * Get the attribute rights
68       * 
69       * @return the attribute rights
70       */
71      public Map<String, AttributeRight> getAttributeRights( )
72      {
73          return _mapAttributeRights;
74      }
75  
76      /**
77       * Set the attribute rights
78       * 
79       * @param mapAttributeRights
80       *            the attribute rights map
81       */
82      public void setAttributeRights( Map<String, AttributeRight> mapAttributeRights )
83      {
84          _mapAttributeRights = mapAttributeRights;
85      }
86  
87      @Override
88      public String getComplementaryInfos( )
89      {
90          Map<String, Attribute> mapAttributes = AttributeHome.getAttributesMap( );
91          Map<String, Object> model = new HashMap<String, Object>( );
92  
93          model.put( MARK_MAP_ATTRIBUTES, mapAttributes );
94          model.put( MARK_DEMAND, this );
95  
96          if ( this.getIdApplicationData( ) != null )
97          {
98              Application application = ApplicationHome.findByPrimaryKey( this.getIdApplication( ) );
99  
100             try
101             {
102                 IdentitystoreData../../../../../fr/paris/lutece/plugins/appcenter/modules/identitystore/business/IdentitystoreData.html#IdentitystoreData">IdentitystoreData data = (IdentitystoreData) ApplicationService.loadApplicationDataById( this.getIdApplicationData( ), application,
103                         IdentitystoreDatas.class );
104                 model.put( Constants.MARK_DATA, data );
105             }
106             catch( IOException e )
107             {
108                 AppLogService.error( e );
109             }
110         }
111 
112         return AppTemplateService.getTemplate( TEMPLATE_IDENTITYSTORE_DEMAND_INFOS, Locale.FRENCH, model ).getHtml( );
113     }
114 
115     /**
116      * Get the demand type id
117      * 
118      * @return the demand type id
119      */
120     @JsonIgnore
121     @Override
122     public String getIdDemandType( )
123     {
124         return ID_DEMAND_TYPE;
125     }
126 
127     /**
128      * Get the demand type id
129      * 
130      * @return the demand type id
131      */
132     @JsonIgnore
133     @Override
134     public String getDemandType( )
135     {
136         return DEMAND_TYPE;
137     }
138 
139     @JsonIgnore
140     @Override
141     public boolean isDependingOfEnvironment( )
142     {
143         return true;
144     }
145 }