Skip to content

Commit

Permalink
want to avoid useless imports
Browse files Browse the repository at this point in the history
  • Loading branch information
fugerit79 committed Nov 22, 2024
1 parent 56983a1 commit c72ae45
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 ) );
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ public void testDaoGenerationClassicalEntity() throws IOException, ConfigExcepti
Assert.assertEquals( Result.RESULT_CODE_OK, result );
}

@Test
public void testDaoModelAndHelperInTheSameFolder() throws IOException, ConfigException {
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() throws IOException, ConfigException {
File file = new File( "target/daogen-run-fail-helper-ng" );
Expand Down

0 comments on commit c72ae45

Please sign in to comment.