diff --git a/fj-daogen-base/src/main/java/org/fugerit/java/daogen/base/gen/HelperGenerator.java b/fj-daogen-base/src/main/java/org/fugerit/java/daogen/base/gen/HelperGenerator.java index 88296ae..ba7251f 100644 --- a/fj-daogen-base/src/main/java/org/fugerit/java/daogen/base/gen/HelperGenerator.java +++ b/fj-daogen-base/src/main/java/org/fugerit/java/daogen/base/gen/HelperGenerator.java @@ -13,6 +13,7 @@ import org.fugerit.java.daogen.base.config.DaogenCatalogField; import org.fugerit.java.daogen.base.config.DaogenCatalogRelation; import org.fugerit.java.daogen.base.config.DaogenClassConfigHelper; +import org.fugerit.java.daogen.base.gen.util.HelperUtils; public class HelperGenerator extends DaogenBasicGenerator { @@ -41,12 +42,8 @@ public void init( DaogenCatalogConfig daogenConfig, DaogenCatalogEntity entity ) } else { throw new ConfigException( "Invalid "+DaogenCatalogConstants.GEN_PROP_DAO_HELPER_NG_MODE+" parameter : "+daoHelperNgMode ); } - this.getImportList().add( this.getDaogenConfig().getGeneralProp( DaogenCatalogConstants.GEN_PROP_PACKAGE_MODEL )+"."+this.getEntityModelName() ); this.setImplementsInterface( this.getEntityModelName() ); - for ( DaogenCatalogRelation relation : this.getCurrentEntity().getRelations() ) { - DaogenCatalogEntity entityTo = this.getDaogenConfig().getListMap( relation.getTo() ); - this.getImportList().add( this.getDaogenConfig().getGeneralProp( DaogenCatalogConstants.GEN_PROP_PACKAGE_MODEL )+"."+DaogenCatalogConstants.modelName( entityTo ) ); - } + HelperUtils.checkImportModel( this.getDaogenConfig(), this ); } private void generateRelations() { diff --git a/fj-daogen-base/src/main/java/org/fugerit/java/daogen/base/gen/util/HelperUtils.java b/fj-daogen-base/src/main/java/org/fugerit/java/daogen/base/gen/util/HelperUtils.java new file mode 100644 index 0000000..2b3e3e8 --- /dev/null +++ b/fj-daogen-base/src/main/java/org/fugerit/java/daogen/base/gen/util/HelperUtils.java @@ -0,0 +1,23 @@ +package org.fugerit.java.daogen.base.gen.util; + +import org.fugerit.java.daogen.base.config.DaogenCatalogConfig; +import org.fugerit.java.daogen.base.config.DaogenCatalogConstants; +import org.fugerit.java.daogen.base.config.DaogenCatalogEntity; +import org.fugerit.java.daogen.base.config.DaogenCatalogRelation; +import org.fugerit.java.daogen.base.gen.DaogenBasicGenerator; + +public class HelperUtils { + + private HelperUtils() {} + + public static void checkImportModel(DaogenCatalogConfig daogenConfig, DaogenBasicGenerator gen ) { + if ( !daogenConfig.getGeneralProp( DaogenCatalogConstants.GEN_PROP_PACKAGE_MODEL ).equals( daogenConfig.getGeneralProp( DaogenCatalogConstants.GEN_PROP_PACKAGE_HELPER ) ) ) { + gen.getImportList().add( gen.getDaogenConfig().getGeneralProp( DaogenCatalogConstants.GEN_PROP_PACKAGE_MODEL )+"."+gen.getEntityModelName() ); + for ( DaogenCatalogRelation relation : gen.getCurrentEntity().getRelations() ) { + DaogenCatalogEntity entityTo = gen.getDaogenConfig().getListMap( relation.getTo() ); + gen.getImportList().add( gen.getDaogenConfig().getGeneralProp( DaogenCatalogConstants.GEN_PROP_PACKAGE_MODEL )+"."+DaogenCatalogConstants.modelName( entityTo ) ); + } + } + } + +} diff --git a/fj-daogen-base/src/main/java/org/fugerit/java/daogen/base/gen/util/WrapperUtils.java b/fj-daogen-base/src/main/java/org/fugerit/java/daogen/base/gen/util/WrapperUtils.java index 367a793..57e122c 100644 --- a/fj-daogen-base/src/main/java/org/fugerit/java/daogen/base/gen/util/WrapperUtils.java +++ b/fj-daogen-base/src/main/java/org/fugerit/java/daogen/base/gen/util/WrapperUtils.java @@ -31,12 +31,8 @@ public static void init(DaogenCatalogConfig daogenConfig, DaogenCatalogEntity en } else { throw new ConfigException( "Invalid "+DaogenCatalogConstants.GEN_PROP_DAO_WRAPPER_NG_MODE+" parameter : "+daoWrapperNgMode ); } - gen.getImportList().add( gen.getDaogenConfig().getGeneralProp( DaogenCatalogConstants.GEN_PROP_PACKAGE_MODEL )+"."+gen.getEntityModelName() ); gen.setImplementsInterface( gen.getEntityModelName() ); - for ( DaogenCatalogRelation relation : gen.getCurrentEntity().getRelations() ) { - DaogenCatalogEntity entityTo = gen.getDaogenConfig().getListMap( relation.getTo() ); - gen.getImportList().add( gen.getDaogenConfig().getGeneralProp( DaogenCatalogConstants.GEN_PROP_PACKAGE_MODEL )+"."+DaogenCatalogConstants.modelName( entityTo ) ); - } + HelperUtils.checkImportModel( daogenConfig, gen ); } public static void generateRelations(DaogenBasicGenerator gen ) { diff --git a/fj-daogen-base/src/test/java/test/org/fugerit/java/daogen/base/config/TestDaogenRun.java b/fj-daogen-base/src/test/java/test/org/fugerit/java/daogen/base/config/TestDaogenRun.java index 80030dc..fafef17 100644 --- a/fj-daogen-base/src/test/java/test/org/fugerit/java/daogen/base/config/TestDaogenRun.java +++ b/fj-daogen-base/src/test/java/test/org/fugerit/java/daogen/base/config/TestDaogenRun.java @@ -37,7 +37,7 @@ private int testDaoGenerationWorker( File baseDir, Properties overrideProperties } @Test - public void testDaoGenerationJdk17SpringBoot() throws IOException, ConfigException { + public void testDaoGenerationJdk17SpringBoot() { File file = new File( "target/daogen-run-jdk17-sprint-boot" ); Properties overrideProperties = new Properties(); overrideProperties.setProperty( @@ -58,7 +58,7 @@ public void testDaoGenerationJdk17SpringBoot() throws IOException, ConfigExcepti } @Test - public void testDaoGenerationClassicalEntity() throws IOException, ConfigException { + public void testDaoGenerationClassicalEntity() { File file = new File( "target/daogen-run-classical-entity" ); Properties overrideProperties = new Properties(); overrideProperties.setProperty( @@ -82,7 +82,19 @@ public void testDaoGenerationClassicalEntity() throws IOException, ConfigExcepti } @Test - public void testDaoGenerationFailHelperNg() throws IOException, ConfigException { + public void testDaoModelAndHelperInTheSameFolder() { + File file = new File( "target/daogen-run-model-helper-coexists" ); + Properties overrideProperties = new Properties(); + overrideProperties.setProperty( + DaogenCatalogConstants.GEN_PROP_PACKAGE_HELPER , + "org.fugerit.java.daogen.sample.def.model"); + int result = this.testDaoGenerationWorker(file, overrideProperties); + Assert.assertTrue( file.exists() ); + Assert.assertEquals( Result.RESULT_CODE_OK, result ); + } + + @Test + public void testDaoGenerationFailHelperNg() { File file = new File( "target/daogen-run-fail-helper-ng" ); Properties overrideProperties = new Properties(); overrideProperties.setProperty( @@ -92,7 +104,7 @@ public void testDaoGenerationFailHelperNg() throws IOException, ConfigException } @Test - public void testDaoGenerationFailWrapperNg() throws IOException, ConfigException { + public void testDaoGenerationFailWrapperNg() { File file = new File( "target/daogen-run-fail-wrapper-ng" ); Properties overrideProperties = new Properties(); overrideProperties.setProperty( @@ -102,7 +114,7 @@ public void testDaoGenerationFailWrapperNg() throws IOException, ConfigException } @Test - public void testDaoGenerationFailFinderNg() throws IOException, ConfigException { + public void testDaoGenerationFailFinderNg() { File file = new File( "target/daogen-run-fail-finder-ng" ); Properties overrideProperties = new Properties(); overrideProperties.setProperty( @@ -112,7 +124,7 @@ public void testDaoGenerationFailFinderNg() throws IOException, ConfigException } @Test - public void testDaoGenerationDefault() throws IOException, ConfigException { + public void testDaoGenerationDefault() throws IOException, ConfigException { File file = new File( "target/daogen-run" ); try ( FileInputStream fis = new FileInputStream( new File( "src/test/resources/sample/daogenruntest-sample-daogen-config.xml" ) ) ) { log.info( "DAOGEN start!" );