View Javadoc
1   /*
2    * Copyright (c) 2002-2017, 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.gru.web.actions.groups.builders.impl;
35  
36  import fr.paris.lutece.plugins.gru.web.Constants;
37  import fr.paris.lutece.plugins.gru.web.actions.groups.builders.AbstractActionGroupBuilder;
38  import fr.paris.lutece.plugins.grubusiness.business.demand.Demand;
39  import fr.paris.lutece.portal.service.util.AppPropertiesService;
40  
41  import java.util.List;
42  
43  /**
44   * AbstractDemandActionGroupBuilder
45   */
46  public abstract class AbstractDemandActionGroupBuilder extends AbstractActionGroupBuilder
47  {
48      protected static final String PROPERTY_COLOR_DEFAULT = "gru.color.default";
49      protected static final String PROPERTY_COLOR_PRIMARY = "gru.color.primary";
50      protected static final String PROPERTY_COLOR_DANGER = "gru.color.danger";
51      protected static final String COLOR_DEFAULT = AppPropertiesService.getProperty( PROPERTY_COLOR_DEFAULT, "default" );
52      protected static final String COLOR_PRIMARY = AppPropertiesService.getProperty( PROPERTY_COLOR_PRIMARY, "blue" );
53      protected static final String COLOR_DANGER = AppPropertiesService.getProperty( PROPERTY_COLOR_DANGER, "red" );
54  
55      private static final String BOOKMARK_ID = "{id}";
56      private static final String BOOKMARK_TYPE = "{type}";
57      private String _strDemandManagementUrl;
58      private List<String> _listExcludedTypes;
59      private List<String> _listIncludedTypes;
60  
61      /**
62       * Define the management url of the demand
63       * 
64       * @param strUrl
65       *            The url
66       */
67      public void setDemandManagementUrl( String strUrl )
68      {
69          _strDemandManagementUrl = strUrl;
70      }
71  
72      /**
73       * Gets the management url of the demand
74       * 
75       * @return strUrl The url
76       */
77      protected String getDemandManagementUrl( )
78      {
79          return _strDemandManagementUrl;
80      }
81  
82      /**
83       * Build the management link for a given demand
84       * 
85       * @param strDemandId
86       *            The demand
87       * @param strDemandTypeId
88       *            The demand type ID
89       * @param strCustomerId
90       *            The customer ID
91       * @return The RUL of the link
92       */
93      protected String buildDemandManagementLink( String strDemandId, String strDemandTypeId, String strCustomerId )
94      {
95          String strUrl = _strDemandManagementUrl.replace( BOOKMARK_ID, strDemandId );
96          strUrl = strUrl.replace( BOOKMARK_TYPE, strDemandTypeId );
97  
98          return new StringBuilder( strUrl ).append( '&' ).append( Constants.PARAMETER_ID_CUSTOMER ).append( '=' ).append( strCustomerId ).toString( );
99      }
100 
101     /**
102      * Define excluded types list
103      * 
104      * @param listExcludedTypes
105      *            The list
106      */
107     public void setExcludedTypesList( List<String> listExcludedTypes )
108     {
109         _listExcludedTypes = listExcludedTypes;
110     }
111 
112     /**
113      * Gets the excluded types list
114      * 
115      * @return The list
116      */
117     protected List<String> getExcludedTypesList( )
118     {
119         return _listExcludedTypes;
120     }
121 
122     /**
123      * Define excluded types list
124      * 
125      * @param listIncludedTypes
126      *            The list
127      */
128     public void setIncludedTypesList( List<String> listIncludedTypes )
129     {
130         _listIncludedTypes = listIncludedTypes;
131     }
132 
133     /**
134      * Gets the excluded types list
135      * 
136      * @return The list
137      */
138     protected List<String> getIncludedTypesList( )
139     {
140         return _listIncludedTypes;
141     }
142 
143     /**
144      * Process the badge color
145      * 
146      * @param demand
147      *            The Demand
148      * @param strCurrentBadgeColor
149      *            The current badge color
150      * @param strActiveBadgeColor
151      *            The active badge color
152      * @return the badge color
153      */
154     protected String processGroupBadgeColor( Demand demand, String strCurrentBadgeColor, String strActiveBadgeColor )
155     {
156         String strBadgeColor = strCurrentBadgeColor;
157 
158         if ( strCurrentBadgeColor == null )
159         {
160             strBadgeColor = COLOR_DEFAULT;
161         }
162 
163         if ( demand.getStatusId( ) != Demand.STATUS_CLOSED )
164         {
165             strBadgeColor = strActiveBadgeColor;
166         }
167 
168         return strBadgeColor;
169     }
170 
171     /**
172      * Process the item color
173      * 
174      * @param demand
175      *            The Demand
176      * @param strActiveColor
177      *            The active item color
178      * @return the item color
179      */
180     protected String processItemColor( Demand demand, String strActiveColor )
181     {
182         return ( demand.getStatusId( ) == Demand.STATUS_CLOSED ) ? COLOR_DEFAULT : strActiveColor;
183     }
184 }