33import static java .lang .String .format ;
44import static java .lang .System .getProperty ;
55import static java .util .Optional .ofNullable ;
6+ import static org .apache .commons .text .CaseUtils .toCamelCase ;
67
78import java .lang .reflect .Modifier ;
89import java .time .LocalDateTime ;
1516import javax .persistence .Id ;
1617import javax .persistence .Table ;
1718
18- import org .apache .commons .text .CaseUtils ;
1919import org .burningwave .core .classes .AnnotationSourceGenerator ;
2020import org .burningwave .core .classes .ClassSourceGenerator ;
2121import org .burningwave .core .classes .FunctionSourceGenerator ;
3434import lombok .NoArgsConstructor ;
3535import lombok .Setter ;
3636import lombok .ToString ;
37- import lombok .extern .slf4j .Slf4j ;
3837
39- @ Slf4j
4038public class BuilderEntity {
4139
4240 private static final String PACKAGE_DOMAIN_NAME = "domain" ;
@@ -62,32 +60,29 @@ public class BuilderEntity {
6260 private static final String PARAM_VALUE = "value" ;
6361 private static final String PARAM_NAME = "name" ;
6462
65- public void build (List <EntityModel > entityModel ) {
66- entityModel .forEach (e -> build (e ));
63+ public void build (List <EntityModel > entityModel , boolean isAutoGenerated ) {
64+ entityModel .forEach (e -> build (e , isAutoGenerated ));
6765 }
6866
69- private void build (EntityModel entityModel ) {
70- String nameClass = CaseUtils . toCamelCase (entityModel .getName (), true , '_' );
67+ private void build (EntityModel entityModel , boolean isAutoGenerated ) {
68+ String nameClass = toCamelCase (entityModel .getName (), true , '_' );
7169 String packageName = "dev.sassine.api.structure.delete" ;
72- boolean isAutoGenerated = true ;
73- String type = null ;
7470
75- createEntity (entityModel , type , isAutoGenerated , nameClass , packageName );
71+ createEntity (entityModel , isAutoGenerated , nameClass , packageName );
7672 createDTO (entityModel , nameClass , packageName );
77- createRepository (entityModel , type , nameClass , packageName );
78-
79- log .info ("Sucess ;)" );
73+ createRepository (entityModel , nameClass , packageName );
74+
8075 }
8176
82- private void createRepository (EntityModel entityModel , String nameClass , String packageName , String type ) {
77+ private void createRepository (EntityModel entityModel , String nameClass , String packageName ) {
8378
8479 UnitSourceGenerator gen = UnitSourceGenerator
8580 .create (format (FORMAT_PACKAGE_DOT_PACKAGE , packageName , PACKAGE_REPOSITORY_NAME ));
8681 ClassSourceGenerator interfaceClass = ClassSourceGenerator
8782 .createInterface (TypeDeclarationSourceGenerator .create (ENTITY_REPOSITORY ))
8883 .expands (TypeDeclarationSourceGenerator .create (CLASSNAME_JPAREPOSITORY )
8984 .addGeneric (GenericSourceGenerator .create (format (FORMAT_ENTITY_CLASSNAME , nameClass )))
90- .addGeneric (GenericSourceGenerator .create (getIdClassType (type ))))
85+ .addGeneric (GenericSourceGenerator .create (getIdClassType (entityModel ))))
9186 .addModifier (Modifier .PUBLIC ).addAnnotation (AnnotationSourceGenerator .create (Repository .class ));
9287
9388 importEntityClass (nameClass , packageName , gen );
@@ -98,12 +93,13 @@ private void createRepository(EntityModel entityModel, String nameClass, String
9893 store (gen );
9994 }
10095
101- private Class <?> getIdClassType (String type ) {
102- if (TypeConverter .TYPE_STRING .equalsIgnoreCase (type ))
96+ private Class <?> getIdClassType (EntityModel entityModel ) {
97+ String pkType = entityModel .getPkType ();
98+ if (TypeConverter .TYPE_STRING .equalsIgnoreCase (pkType ))
10399 return String .class ;
104- else if (TypeConverter .TYPE_UUID .equalsIgnoreCase (type ))
100+ else if (TypeConverter .TYPE_UUID .equalsIgnoreCase (pkType ))
105101 return UUID .class ;
106- else if (TypeConverter .TYPE_INTEGER .equalsIgnoreCase (type ))
102+ else if (TypeConverter .TYPE_INTEGER .equalsIgnoreCase (pkType ))
107103 return Integer .class ;
108104 else
109105 return Long .class ;
@@ -146,7 +142,7 @@ private void createDTO(EntityModel entityModel, String nameClass, String package
146142 store (gen );
147143 }
148144
149- private void createEntity (EntityModel entityModel , String type , boolean isAutoGenerated , String nameClass ,
145+ private void createEntity (EntityModel entityModel , boolean isAutoGenerated , String nameClass ,
150146 String packageName ) {
151147
152148 UnitSourceGenerator gen = UnitSourceGenerator
@@ -173,7 +169,7 @@ private void createEntity(EntityModel entityModel, String type, boolean isAutoGe
173169 VariableSourceGenerator .create (String .valueOf (fieldModel .getNullable ()))));
174170
175171 importLocalDateTime (gen , fieldModel );
176- generateEntityPK (isAutoGenerated , fieldModel , field , type );
172+ generateEntityPK (isAutoGenerated , fieldModel , field , entityModel );
177173
178174 clEntity .addField (field );
179175 }
@@ -183,11 +179,11 @@ private void createEntity(EntityModel entityModel, String type, boolean isAutoGe
183179 store (gen );
184180 }
185181
186- private void generateEntityPK (boolean isAutoGenerated , FieldModel fieldModel , VariableSourceGenerator field , String type ) {
182+ private void generateEntityPK (boolean isAutoGenerated , FieldModel fieldModel , VariableSourceGenerator field , EntityModel entityModel ) {
187183 if (ofNullable (fieldModel .getIsPrimaryKey ()).orElse (false )) {
188184 field .addAnnotation (AnnotationSourceGenerator .create (Id .class ));
189185 if (isAutoGenerated ) field .addAnnotation (AnnotationSourceGenerator .create (GeneratedValue .class ));
190- type = fieldModel .getType ();
186+ entityModel . setPkType ( fieldModel .getType () );
191187 }
192188 }
193189
0 commit comments