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.Configuration;
38 import fr.paris.lutece.plugins.pluginwizard.business.model.PluginModel;
39 import java.util.ArrayList;
40 import java.util.Collection;
41 import java.util.HashMap;
42 import java.util.List;
43 import java.util.Map;
44
45
46
47
48
49
50 public class BusinessClassGenerator extends AbstractGenerator
51 {
52 private static final String PATH = "SOURCE/java/fr/paris/lutece/plugins/";
53 private static final String PATH_SUFFIX = "/business/";
54 private static final String SUFFIX_FILE_NAME_ABSTRACT_FILTER_DAO = "abstractFilterDao.html";
55 private List<BusinessFileConfig> _listFiles;
56
57
58
59
60
61
62
63 public void setFiles( List<BusinessFileConfig> listFiles )
64 {
65 if ( listFiles != null )
66 {
67 _listFiles = (List<BusinessFileConfig>) ( ( (ArrayList<BusinessFileConfig>) listFiles ).clone( ) );
68 }
69 else
70 {
71 _listFiles = null;
72 }
73 }
74
75
76
77
78 @Override
79 public Map<String, String> generate( PluginModel pm, String generationSchemeName )
80 {
81 HashMap<String, String> map = new HashMap<>( );
82 Collection<BusinessClass> listAllBusinessClasses = pm.getBusinessClasses( );
83
84 String strPluginName = pm.getPluginNameAsPackage( );
85 String strRadicalPackage = pm.getPluginNameAsRadicalPackage( );
86 String strRadicalPath = pm.getPluginNameAsRadicalPath( );
87
88 int counterFilterDao = 0;
89
90 for ( BusinessClass businessClass : listAllBusinessClasses )
91 {
92 for ( BusinessFileConfig file : _listFiles )
93 {
94 String strClassName;
95
96
97 if ( file.getTemplate( ).endsWith( SUFFIX_FILE_NAME_ABSTRACT_FILTER_DAO ) && counterFilterDao < 1 )
98 {
99 strClassName = file.getPrefix( );
100 counterFilterDao = 1;
101
102 }
103 else
104 if ( file.getTemplate( ).endsWith( SUFFIX_FILE_NAME_ABSTRACT_FILTER_DAO ) && counterFilterDao >= 1 )
105 {
106 continue;
107
108 }
109 else
110 {
111 strClassName = file.getPrefix( ) + businessClass.getBusinessClass( ) + file.getSuffix( );
112 }
113
114 String strFilename = strClassName + ".java";
115 String strSourceCode;
116
117 if ( pm.isWorkflowTask( ) )
118 {
119 strSourceCode = getSourceCode( strPluginName, businessClass, file.getTemplate( ), strRadicalPackage, pm.getPluginName( ), pm.getType( ), pm.getConfiguration( ) );
120 }
121 else
122 {
123 strSourceCode = getSourceCode( strPluginName, businessClass, file.getTemplate( ), strRadicalPackage, pm.getPluginName( ), pm.getType( ) );
124 }
125
126 strSourceCode = strSourceCode.replace( "<", "<" );
127 strSourceCode = strSourceCode.replace( ">", ">" );
128 strSourceCode = strSourceCode.replace( "@i18n", "#i18n" );
129
130 String strPath = PATH.replace( "SOURCE", file.getSourcePath( ) ) + strRadicalPath + PATH_SUFFIX;
131
132 map.put( getFilePath( pm, strPath, strFilename ), strSourceCode );
133 }
134 }
135
136 return map;
137 }
138
139
140
141
142
143
144
145
146
147
148
149
150 private String getSourceCode( String strPluginName, BusinessClass businessClass, String strTemplate, String strRadicalPackage, String strBeanName, String strProjectType )
151 {
152 Map<String, Object> model = new HashMap<>( );
153 model.put( Markers.MARK_BUSINESS_CLASS, businessClass );
154 model.put( Markers.MARK_PLUGIN_NAME, strPluginName );
155 model.put( Markers.MARK_RADICAL_PACKAGE, strRadicalPackage );
156 model.put( Markers.MARK_BEAN_NAME, strBeanName );
157 model.put( Markers.MARK_PROJECT_TYPE , strProjectType );
158
159 return build( strTemplate, model );
160 }
161
162
163
164
165
166
167
168
169
170
171
172
173 private String getSourceCode( String strPluginName, BusinessClass businessClass, String strTemplate, String strRadicalPackage, String strBeanName, String strProjectType, Configuration configuration )
174 {
175 Map<String, Object> model = new HashMap<>( );
176 model.put( Markers.MARK_BUSINESS_CLASS, businessClass );
177 model.put( Markers.MARK_PLUGIN_NAME, strPluginName );
178 model.put( Markers.MARK_RADICAL_PACKAGE, strRadicalPackage );
179 model.put( Markers.MARK_BEAN_NAME, strBeanName );
180 model.put( Markers.MARK_PROJECT_TYPE , strProjectType );
181 model.put( Markers.MARK_CONFIGURATION, configuration );
182
183 return build( strTemplate, model );
184 }
185 }