1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.forms.modules.template.web;
35
36 import java.util.ArrayList;
37 import java.util.List;
38 import java.util.Locale;
39 import java.util.Map;
40
41 import javax.servlet.http.HttpServletRequest;
42
43 import org.apache.commons.lang3.StringUtils;
44
45 import fr.paris.lutece.plugins.forms.business.CompositeDisplayType;
46 import fr.paris.lutece.plugins.forms.business.Control;
47 import fr.paris.lutece.plugins.forms.business.FormDisplay;
48 import fr.paris.lutece.plugins.forms.business.FormQuestionResponse;
49 import fr.paris.lutece.plugins.forms.business.FormResponse;
50 import fr.paris.lutece.plugins.forms.business.Group;
51 import fr.paris.lutece.plugins.forms.business.Question;
52 import fr.paris.lutece.plugins.forms.modules.template.business.TemplateDisplayHome;
53 import fr.paris.lutece.plugins.forms.modules.template.business.TemplateGroupHome;
54 import fr.paris.lutece.plugins.forms.modules.template.service.ITemplateService;
55 import fr.paris.lutece.plugins.forms.modules.template.service.TemplateService;
56 import fr.paris.lutece.plugins.forms.web.ICompositeDisplay;
57 import fr.paris.lutece.plugins.forms.web.entrytype.DisplayType;
58 import fr.paris.lutece.portal.service.spring.SpringContextService;
59 import fr.paris.lutece.portal.service.util.AppPropertiesService;
60
61 public class CompositeTemplateGroupDisplay implements ICompositeDisplay
62 {
63
64 private static final String PROPERTY_COMPOSITE_GROUP_ICON = "forms.composite.group.icon";
65 private static final String DEFAULT_GROUP_ICON = "indent";
66
67 private ITemplateService _templateService = SpringContextService.getBean( TemplateService.BEAN_NAME );
68
69 private final List<ICompositeDisplay> _listChildren = new ArrayList<>( );
70 private final FormDisplay _templateDisplay;
71 private Group _group;
72 private String _strIconName;
73
74
75
76
77
78
79
80
81
82 public CompositeTemplateGroupDisplay( FormDisplay templateDisplay, int nIterationNumber )
83 {
84 _templateDisplay = templateDisplay;
85
86 initComposite( );
87 }
88
89
90
91
92
93
94
95
96
97 private void initComposite( )
98 {
99 if ( !StringUtils.isEmpty( _templateDisplay.getCompositeType( ) ) )
100 {
101 _group = TemplateGroupHome.findByPrimaryKey( _templateDisplay.getCompositeId( ) );
102 _strIconName = AppPropertiesService.getProperty( PROPERTY_COMPOSITE_GROUP_ICON, DEFAULT_GROUP_ICON );
103 }
104
105 List<FormDisplay> listTemplateDisplayChildren = TemplateDisplayHome.getFormDisplayListByParent( _templateDisplay.getStepId( ),
106 _templateDisplay.getId( ) );
107 int iterationNumber = _group.getIterationMin( ) - 1;
108
109 for ( int i = 0; i <= iterationNumber; i++ )
110 {
111 addChildren( listTemplateDisplayChildren, i );
112 }
113 }
114
115
116
117
118
119
120
121
122
123 private void addChildren( List<FormDisplay> listTemplateDisplayChildren, int nIterationNumber )
124 {
125 for ( FormDisplay templateDisplayChild : listTemplateDisplayChildren )
126 {
127 ICompositeDisplay composite = _templateService.templateDisplayToComposite( templateDisplayChild, nIterationNumber );
128 _listChildren.add( composite );
129 }
130 }
131
132 @Override
133 public String getCompositeHtml( HttpServletRequest request, List<FormQuestionResponse> listFormQuestionResponse, Locale locale, DisplayType displayType )
134 {
135
136 return null;
137 }
138
139 @Override
140 public void iterate( int nIdTemplateDisplay )
141 {
142
143 }
144
145 @Override
146 public void removeIteration( HttpServletRequest request, int nIdGroupParent, int nIndexIterationToRemove, FormResponse formResponse )
147 {
148
149 }
150
151 @Override
152 public List<ICompositeDisplay> getCompositeList( )
153 {
154 List<ICompositeDisplay> listCompositeDisplay = new ArrayList<>( );
155 listCompositeDisplay.add( this );
156
157 for ( FormDisplay child : TemplateDisplayHome.getFormDisplayListByParent( _templateDisplay.getStepId( ), _templateDisplay.getId( ) ) )
158 {
159 ICompositeDisplay compositeChild = _templateService.templateDisplayToComposite( child, 0 );
160 listCompositeDisplay.addAll( compositeChild.getCompositeList( ) );
161 }
162 return listCompositeDisplay;
163 }
164
165 @Override
166 public String getTitle( )
167 {
168 String strTitle = "";
169 if ( _group != null && StringUtils.isNotEmpty( _group.getTitle( ) ) )
170 {
171 strTitle = _group.getTitle( );
172 }
173 return strTitle;
174 }
175
176 @Override
177 public String getType( )
178 {
179 return _group != null ? CompositeDisplayType.GROUP.getLabel( ) : StringUtils.EMPTY;
180 }
181
182 @Override
183 public FormDisplay getFormDisplay( )
184 {
185 return _templateDisplay;
186 }
187
188 @Override
189 public List<Control> getAllDisplayControls( )
190 {
191 List<Control> listDisplayControls = new ArrayList<>( );
192
193 if ( _templateDisplay.getDisplayControl( ) != null )
194 {
195 listDisplayControls.add( _templateDisplay.getDisplayControl( ) );
196 }
197
198 for ( ICompositeDisplay child : _listChildren )
199 {
200 listDisplayControls.addAll( child.getAllDisplayControls( ) );
201 }
202
203 return listDisplayControls;
204 }
205
206 @Override
207 public void addQuestions( List<Question> listQuestion )
208 {
209 for ( ICompositeDisplay child : _listChildren )
210 {
211 child.addQuestions( listQuestion );
212 }
213 }
214
215 @Override
216 public String getIcon( )
217 {
218 return _strIconName;
219 }
220
221 @Override
222 public void addModel( Map<String, Object> model )
223 {
224
225 }
226
227 @Override
228 public boolean isVisible( )
229 {
230
231 return false;
232 }
233
234 @Override
235 public ICompositeDisplay filter( List<Integer> listQuestionIds )
236 {
237
238 return null;
239 }
240 }