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.pluginwizard.service.generator;
35
36 import fr.paris.lutece.plugins.pluginwizard.business.model.BusinessClass;
37 import fr.paris.lutece.plugins.pluginwizard.business.model.Feature;
38 import fr.paris.lutece.plugins.pluginwizard.business.model.PluginModel;
39 import fr.paris.lutece.plugins.pluginwizard.service.ModelService;
40
41 import java.util.ArrayList;
42 import java.util.Collection;
43 import java.util.HashMap;
44 import java.util.List;
45 import java.util.Map;
46
47
48
49
50 public class AdminJspBeanGenerator extends AbstractGenerator
51 {
52 private static final String PATH_JAVA = "java/fr/paris/lutece/plugins/{plugin_name}/web/";
53 private static final String PATH_JAVA_WORKFLOW = "java/fr/paris/lutece/plugins/workflow/modules/{plugin_name}/web/";
54 private static final String PATH_KOTLIN = "kotlin/fr/paris/lutece/plugins/{plugin_name}/web/";
55 private static final String PREFIX_JSPBEAN = "Abstract";
56 private static final String PREFIX_JSPBEAN_PATH = "src/";
57
58 private static final String SUFFIX_JAVA_EXTENSION = ".java";
59 private static final String SUFFIX_KOTLIN_EXTENSION = ".kt";
60
61 private static final String SUFFIX_JSPBEAN_CLASS = "JspBean";
62
63 private String _strAbstractParentBeanTemplate = "/generators/default/jspbean/gt_jspbean_abstract.html";
64 private List<AdminJspBeanFileConfig> _listFiles;
65
66 public void setFiles( List<AdminJspBeanFileConfig> listFiles )
67 {
68 if ( listFiles != null )
69 {
70 _listFiles = (List<AdminJspBeanFileConfig>) ( ( (ArrayList<AdminJspBeanFileConfig>) listFiles ).clone( ) );
71 }
72 else
73 {
74 _listFiles = null;
75 }
76 }
77
78
79
80
81
82
83
84 public void setAbstractParentBeanTemplate( String strParent )
85 {
86 _strAbstractParentBeanTemplate = strParent;
87 }
88
89
90
91
92 public Map<String, String> generate( PluginModel pm, String generationSchemeName )
93 {
94 HashMap<String, String> map = new HashMap<>( );
95
96 String strFilesPath = ( isKotlin( ) ) ? PATH_KOTLIN : ( pm.isWorkflowTask( ) ? PATH_JAVA_WORKFLOW.replace( "{plugin_name}",pm.getPluginNameForRessource( ) ) : PATH_JAVA );
97 String strSuffix = SUFFIX_JSPBEAN_CLASS + ( ( isKotlin( ) ) ? SUFFIX_KOTLIN_EXTENSION : SUFFIX_JAVA_EXTENSION );
98
99 for ( Feature feature : pm.getFeatures( ) )
100 {
101 Collection<BusinessClass> listBusinessClasses = ModelService.getBusinessClassesByFeature( pm, feature.getId( ) );
102
103 if ( listBusinessClasses.isEmpty( ) )
104 {
105 for ( AdminJspBeanFileConfig file : _listFiles )
106 {
107 String strSuffixConfig = SUFFIX_JSPBEAN_CLASS + file.getSuffix( ) + ( ( isKotlin( ) ) ? SUFFIX_KOTLIN_EXTENSION : SUFFIX_JAVA_EXTENSION );
108 String strFilename = feature.getFeatureName( ) + strSuffixConfig;
109 String strPath = getFilePath( pm, file.getSourcePath( ) + ( isKotlin( ) ? PATH_KOTLIN : ( pm.isWorkflowTask( ) ? PATH_JAVA_WORKFLOW.replace( "{plugin_name}",pm.getPluginNameForRessource( ) ) : PATH_JAVA ) ), strFilename );
110 String strSourceCode = getJspBeanCode( pm, feature.getFeatureName( ), feature.getFeatureRight( ), file.getTemplate( ),
111 pm.getPluginNameAsRadicalPackage( ), pm.getPluginName( ) );
112 map.put( strPath, strSourceCode );
113 }
114 }
115 else
116 {
117 for ( BusinessClass business : listBusinessClasses )
118 {
119 for ( AdminJspBeanFileConfig file : _listFiles )
120 {
121 String strSuffixConfig = SUFFIX_JSPBEAN_CLASS + file.getSuffix( )
122 + ( ( isKotlin( ) ) ? SUFFIX_KOTLIN_EXTENSION : SUFFIX_JAVA_EXTENSION );
123 String strFilename = business.getBusinessClassCapsFirst( ) + strSuffixConfig;
124 String strPath = getFilePath( pm, file.getSourcePath( ) + ( isKotlin( ) ? PATH_KOTLIN : ( pm.isWorkflowTask( ) ? PATH_JAVA_WORKFLOW.replace( "{plugin_name}",pm.getPluginNameForRessource( ) ) : PATH_JAVA ) ), strFilename );
125 String strSourceCode = getJspBeanCode( pm, feature.getFeatureName( ), feature.getFeatureRight( ), business, file.getTemplate( ),
126 pm.getPluginNameAsRadicalPackage( ), pm.getPluginName( ) );
127 map.put( strPath, strSourceCode );
128 }
129 }
130 }
131 }
132
133 String strPath = getFilePath( pm, PREFIX_JSPBEAN_PATH + strFilesPath, PREFIX_JSPBEAN + strSuffix );
134 String strSourceCode = getAbstractJspBeanCode( pm, pm.getPluginNameAsRadicalPackage( ),
135 pm.getPluginName( ) );
136 map.put( strPath, strSourceCode );
137
138 return map;
139 }
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154 private String getJspBeanCode( PluginModel pm, String strFeatureName, String strFeatureRight, BusinessClass business, String strTemplate,
155 String strRadicalPackage, String strBeanName )
156 {
157 Map<String, Object> model = getModel( pm );
158
159 model.put( Markers.MARK_BUSINESS_CLASS, business );
160 model.put( Markers.MARK_FEATURE_NAME, strFeatureName );
161 model.put( Markers.MARK_FEATURE_RIGHT, strFeatureRight );
162
163 model.put( Markers.MARK_RADICAL_PACKAGE, strRadicalPackage );
164 model.put( Markers.MARK_BEAN_NAME, strBeanName );
165
166 return build( strTemplate, model );
167 }
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182 private String getJspBeanCode( PluginModel pm, String strFeatureName, String strFeatureRight, String strTemplate, String strRadicalPackage,
183 String strBeanName )
184 {
185 Map<String, Object> model = getModel( pm );
186
187 model.put( Markers.MARK_FEATURE_NAME, strFeatureName );
188 model.put( Markers.MARK_FEATURE_RIGHT, strFeatureRight );
189
190 model.put( Markers.MARK_RADICAL_PACKAGE, strRadicalPackage );
191 model.put( Markers.MARK_BEAN_NAME, strBeanName );
192
193 return build( strTemplate, model );
194 }
195
196
197
198
199
200
201
202
203
204
205
206
207 private String getAbstractJspBeanCode( PluginModel pm, String strRadicalPackage, String strBeanName )
208 {
209 Map<String, Object> model = getModel( pm );
210
211 model.put( Markers.MARK_RADICAL_PACKAGE, strRadicalPackage );
212 model.put( Markers.MARK_BEAN_NAME, strBeanName );
213
214 return build( _strAbstractParentBeanTemplate, model );
215 }
216 }