From fdae82ede570698d9ef192982ef845a06e7a4119 Mon Sep 17 00:00:00 2001
From: "Matteo Franci a.k.a. Fugerit"
Date: Fri, 15 Sep 2023 21:38:00 +0200
Subject: [PATCH] Sonar cloud issue fix
---
CHANGELOG.md | 5 +
fj-core-jvfs/pom.xml | 2 +-
.../cfg/xml/GenericListCatalogConfig.java | 2 +-
.../db/connect/ConnectionFactoryImpl.java | 52 +++-----
.../db/connect/DbcpConnectionFactory.java | 42 +++----
.../fugerit/java/core/db/helpers/DbUtils.java | 1 -
.../fixed/parser/FixedFieldFileConfig.java | 116 ++++++++++--------
.../core/lang/annotate/DefineImplFinder.java | 4 +-
.../lang/binding/BindingHelperDefault.java | 12 +-
.../lang/helpers/reflect/FieldHelper.java | 18 ++-
.../core/lang/helpers/reflect/ImplFinder.java | 4 +-
.../org/fugerit/java/core/log/LogUtils.java | 7 +-
.../checkpoint/CheckpointFormatHelper.java | 14 +--
.../java/core/util/collection/OptionItem.java | 14 +--
.../util/filterchain/MiniFilterConfig.java | 45 +++++--
.../util/filterchain/MiniFilterDebug.java | 32 ++---
.../db/connect/TestConnectionFactory.java | 9 +-
.../lang/helpers/reflect/TestFieldHelper.java | 32 +++++
.../core/util/filterchain/TestMiniFilter.java | 31 +++++
.../tool/fixed/ExtractFixedConfigHandler.java | 4 +-
20 files changed, 258 insertions(+), 188 deletions(-)
create mode 100644 fj-core/src/test/java/test/org/fugerit/java/core/lang/helpers/reflect/TestFieldHelper.java
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ab66e4e9..f5ce4fb2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+### Changed
+
+- fj-daogen-version set to 1.2.1 in module fj-core-jvfs
+- ImplFinder interface methods does not throw any exception now
+
## [8.3.1] - 2023-09-15
### Changed
diff --git a/fj-core-jvfs/pom.xml b/fj-core-jvfs/pom.xml
index e930288e..724a7fd5 100644
--- a/fj-core-jvfs/pom.xml
+++ b/fj-core-jvfs/pom.xml
@@ -30,7 +30,7 @@
- 1.1.9
+ 1.2.1
${project.basedir}
target/generated-sources/daogen
diff --git a/fj-core/src/main/java/org/fugerit/java/core/cfg/xml/GenericListCatalogConfig.java b/fj-core/src/main/java/org/fugerit/java/core/cfg/xml/GenericListCatalogConfig.java
index a7a548b6..2db95af8 100644
--- a/fj-core/src/main/java/org/fugerit/java/core/cfg/xml/GenericListCatalogConfig.java
+++ b/fj-core/src/main/java/org/fugerit/java/core/cfg/xml/GenericListCatalogConfig.java
@@ -279,7 +279,7 @@ public GenericListCatalogConfig( String attTagDataList, String attTagData ) {
*
* @param the type of the elements in catalog
* @param is the input stream to load from
- * @param config the instance to be configured
+ * @param config the instance to be configured (will be configured by side effect too)
* @return the configured instance
* @throws ConfigRuntimeException in case of issues during loading
*/
diff --git a/fj-core/src/main/java/org/fugerit/java/core/db/connect/ConnectionFactoryImpl.java b/fj-core/src/main/java/org/fugerit/java/core/db/connect/ConnectionFactoryImpl.java
index 0941f675..ce68b94e 100644
--- a/fj-core/src/main/java/org/fugerit/java/core/db/connect/ConnectionFactoryImpl.java
+++ b/fj-core/src/main/java/org/fugerit/java/core/db/connect/ConnectionFactoryImpl.java
@@ -34,8 +34,10 @@
import org.fugerit.java.core.db.dao.DAOException;
import org.fugerit.java.core.db.metadata.DataBaseInfo;
import org.fugerit.java.core.function.UnsafeSupplier;
+import org.fugerit.java.core.lang.helpers.BooleanUtils;
import org.fugerit.java.core.lang.helpers.StringUtils;
import org.fugerit.java.core.log.BasicLogObject;
+import org.fugerit.java.core.util.PropsIO;
import org.fugerit.java.core.xml.dom.DOMUtils;
import org.fugerit.java.core.xml.dom.SearchDOM;
import org.w3c.dom.Element;
@@ -175,11 +177,11 @@ public Connection getConnection() throws DAOException {
/**
* Parse a configuration Element looking for ConnectionFactory configuration
*
- * @param cfConfig the Element
- * @return the CfConfig
- * @throws Exception in case of issues
+ * @param cfConfig the Element
+ * @return the CfConfig
+ * @throws DAOException in case of issues
*/
- public static CfConfig parseCfConfig( Element cfConfig ) throws Exception {
+ public static CfConfig parseCfConfig( Element cfConfig ) throws DAOException {
CfConfig config = new CfConfig();
SearchDOM searchDOM = SearchDOM.newInstance( true , true );
List cfConfigEntryList = searchDOM.findAllTags( cfConfig , "cf-config-entry" );
@@ -215,21 +217,6 @@ public static String getDriverInfo( ConnectionFactory cf ) throws DAOException {
});
}
- /**
- * Helper method to create a property with prefix
- *
- * @param prefix the prefix
- * @param name the property base name
- * @return the property full name ( prefix-name, or name if prefix == null)
- */
- private static String getParamName( String prefix, String name ) {
- String res = name;
- if ( StringUtils.isNotEmpty( prefix ) ) {
- res = prefix+"-"+name;
- }
- return res;
- }
-
/**
* Creates a ConnectionFactory from a property object
*
@@ -256,25 +243,24 @@ public static ConnectionFactory newInstance( Properties props, String propsPrefi
}
ConnectionFactory cf = null;
String prefix = props.getProperty( PROP_CF_MODE_DC_PREFIX, propsPrefix );
- String mode = props.getProperty( getParamName( prefix, PROP_CF_MODE ) );
+ Properties prefixProps = props;
+ if ( StringUtils.isNotEmpty( prefix ) ) {
+ prefixProps = PropsIO.subProps( props , prefix+"-" );
+ log.info( "subProps : {} -> {}", prefix, prefixProps );
+ }
+ String mode = prefixProps.getProperty( PROP_CF_MODE );
log.info( "ConnectionFactory.newInstance() mode : {}", mode );
if ( PROP_CF_MODE_DC.equalsIgnoreCase( mode ) ) {
- if ( "true".equalsIgnoreCase( props.getProperty( getParamName( prefix, PROP_CF_EXT_POOLED ) ) ) ) {
- int sc = Integer.parseInt( props.getProperty( getParamName( prefix, PROP_CF_EXT_POOLED_SC ), "3" ) );
- int ic = Integer.parseInt( props.getProperty( getParamName( prefix, PROP_CF_EXT_POOLED_IC ), "10" ) );
- int mc = Integer.parseInt( props.getProperty( getParamName( prefix, PROP_CF_EXT_POOLED_MC ), "30" ) );
- cf = new DbcpConnectionFactory( props.getProperty( getParamName( prefix, PROP_CF_MODE_DC_DRV ) ),
- props.getProperty( getParamName( prefix, PROP_CF_MODE_DC_URL ) ),
- props.getProperty( getParamName( prefix, PROP_CF_MODE_DC_USR ) ),
- props.getProperty( getParamName( prefix, PROP_CF_MODE_DC_PWD ) ), sc, ic, mc, cl );
+ if ( BooleanUtils.isTrue( prefixProps.getProperty(PROP_CF_EXT_POOLED ) ) ) {
+ cf = new DbcpConnectionFactory(prefixProps, cl);
} else {
- cf = newInstance( props.getProperty( getParamName( prefix, PROP_CF_MODE_DC_DRV ) ),
- props.getProperty( getParamName( prefix, PROP_CF_MODE_DC_URL ) ),
- props.getProperty( getParamName( prefix, PROP_CF_MODE_DC_USR ) ),
- props.getProperty( getParamName( prefix, PROP_CF_MODE_DC_PWD ) ), cl );
+ cf = newInstance( prefixProps.getProperty( PROP_CF_MODE_DC_DRV ),
+ prefixProps.getProperty(PROP_CF_MODE_DC_URL ),
+ prefixProps.getProperty(PROP_CF_MODE_DC_USR ),
+ prefixProps.getProperty(PROP_CF_MODE_DC_PWD ), cl );
}
} else if ( PROP_CF_MODE_DS.equalsIgnoreCase( mode ) || PROP_CF_MODE_DS2.equalsIgnoreCase( mode ) ) {
- String dsName = props.getProperty( PROP_CF_MODE_DS_NAME );
+ String dsName = prefixProps.getProperty( PROP_CF_MODE_DS_NAME );
log.info( "dsName -> {}", dsName );
cf = newInstance( dsName );
} else {
diff --git a/fj-core/src/main/java/org/fugerit/java/core/db/connect/DbcpConnectionFactory.java b/fj-core/src/main/java/org/fugerit/java/core/db/connect/DbcpConnectionFactory.java
index 6e11b75b..9f91c2a6 100644
--- a/fj-core/src/main/java/org/fugerit/java/core/db/connect/DbcpConnectionFactory.java
+++ b/fj-core/src/main/java/org/fugerit/java/core/db/connect/DbcpConnectionFactory.java
@@ -21,6 +21,7 @@
package org.fugerit.java.core.db.connect;
import java.sql.Connection;
+import java.util.Properties;
import org.apache.commons.dbcp2.BasicDataSource;
import org.fugerit.java.core.db.dao.DAOException;
@@ -36,41 +37,30 @@ public class DbcpConnectionFactory extends ConnectionFactoryImpl {
private BasicDataSource dataSource;
/**
- * Constructor
*
- * @param drv driver type
- * @param url jdbc url
- * @param usr user
- * @param pwd password
- * @param init initial connection
- * @param min minimum connection
- * @param max maximum connection
- * @throws DAOException in case of issues
+ * @param cfProps connections parameters
+ * @throws DAOException in case of issues
*/
- public DbcpConnectionFactory( String drv, String url, String usr, String pwd, int init, int min, int max ) throws DAOException {
- this(drv, url, usr, pwd, init, min, max, null);
+ public DbcpConnectionFactory( Properties cfProps ) throws DAOException {
+ this(cfProps, null);
}
/**
- * Constructor
*
- * @param drv driver type
- * @param url jdbc url
- * @param usr user
- * @param pwd password
- * @param init initial connection
- * @param min minimum connection
- * @param max maximum connection
- * @param cl the class loader
- * @throws DAOException in case of issues
+ * @param cfProps connections parameters
+ * @param cl to use for driver class loading
+ * @throws DAOException in case of issues
*/
- public DbcpConnectionFactory( String drv, String url, String usr, String pwd, int init, int min, int max, ClassLoader cl ) throws DAOException {
+ public DbcpConnectionFactory( Properties cfProps, ClassLoader cl ) throws DAOException {
DAOException.apply( () -> {
+ int init = Integer.parseInt( cfProps.getProperty( PROP_CF_EXT_POOLED_SC , "3" ) );
+ int min = Integer.parseInt( cfProps.getProperty( PROP_CF_EXT_POOLED_IC , "10" ) );
+ int max = Integer.parseInt( cfProps.getProperty( PROP_CF_EXT_POOLED_MC , "30" ) );
this.dataSource = new BasicDataSource();
- this.dataSource.setDriverClassName( drv );
- this.dataSource.setUrl( url );
- this.dataSource.setUsername( usr );
- this.dataSource.setPassword( pwd );
+ this.dataSource.setDriverClassName( cfProps.getProperty( PROP_CF_MODE_DC_DRV ) );
+ this.dataSource.setUrl( cfProps.getProperty( PROP_CF_MODE_DC_URL ) );
+ this.dataSource.setUsername( cfProps.getProperty( PROP_CF_MODE_DC_USR ) );
+ this.dataSource.setPassword( cfProps.getProperty( PROP_CF_MODE_DC_PWD ) );
this.dataSource.setMaxTotal( max );
this.dataSource.setMaxIdle( min );
this.dataSource.setInitialSize( init );
diff --git a/fj-core/src/main/java/org/fugerit/java/core/db/helpers/DbUtils.java b/fj-core/src/main/java/org/fugerit/java/core/db/helpers/DbUtils.java
index 541a6a4d..aa0ab331 100644
--- a/fj-core/src/main/java/org/fugerit/java/core/db/helpers/DbUtils.java
+++ b/fj-core/src/main/java/org/fugerit/java/core/db/helpers/DbUtils.java
@@ -60,7 +60,6 @@ public static int indentifyDB( String productName ) {
dbType = DB_POSTGRESQL;
log.info( "IdGenerator configured for : POSTGRESQL ({}) was ({})", dbType, name );
} else {
- dbType = DB_UNKNOWN;
log.info( "Unknown db type ({})", dbType );
}
return dbType;
diff --git a/fj-core/src/main/java/org/fugerit/java/core/fixed/parser/FixedFieldFileConfig.java b/fj-core/src/main/java/org/fugerit/java/core/fixed/parser/FixedFieldFileConfig.java
index 3469ef4d..37a48e88 100644
--- a/fj-core/src/main/java/org/fugerit/java/core/fixed/parser/FixedFieldFileConfig.java
+++ b/fj-core/src/main/java/org/fugerit/java/core/fixed/parser/FixedFieldFileConfig.java
@@ -8,6 +8,9 @@
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
+import org.fugerit.java.core.cfg.ConfigException;
+import org.fugerit.java.core.cfg.ConfigRuntimeException;
+import org.fugerit.java.core.function.SafeFunction;
import org.fugerit.java.core.lang.helpers.ClassHelper;
import org.fugerit.java.core.lang.helpers.StringUtils;
import org.fugerit.java.core.xml.dom.DOMIO;
@@ -22,20 +25,22 @@
*/
public class FixedFieldFileConfig {
- private static void handleValidatorList( FixedFieldFileDescriptor fileDescriptor, Element currentFileTag ) throws Exception {
- NodeList validatorListTagList = currentFileTag.getElementsByTagName( "validator-list" );
- for ( int k=0; k {
+ NodeList validatorListTagList = currentFileTag.getElementsByTagName( "validator-list" );
+ for ( int k=0; kParse fixed filed file configuration.
+ *
+ * NOTE: starting from version 8.4.X java.lang.Exception removed in favor of org.fugerit.java.core.cfg.ConfigRuntimeException.
+ *
+ * @see Define and throw a dedicated exception instead of using a generic one.
+ *
+ * @param is the configuration file to parse
+ * @return the parsed configuration
+ * @throws ConfigRuntimeException in case of issues
+ */
+ public static FixedFieldFileConfig parseConfig( InputStream is ) {
+ return SafeFunction.get( () -> {
+ FixedFieldFileConfig config = new FixedFieldFileConfig();
+ DocumentBuilderFactory dbf = DOMIO.newSafeDocumentBuilderFactory();
+ DocumentBuilder parser = dbf.newDocumentBuilder();
+ Document doc = parser.parse( is );
+ Element root = doc.getDocumentElement();
+ NodeList fileTagList = root.getElementsByTagName( "fixed-field-file" );
+ for ( int i=0; i findImplFor(Class> c) throws Exception {
+ public Class> findImplFor(Class> c) {
Class> ret = c;
if ( this.isFinderFor( c )) {
DefineImpl fug = c.getAnnotation( DefineImpl.class );
@@ -24,7 +24,7 @@ public Class> findImplFor(Class> c) throws Exception {
}
@Override
- public boolean isFinderFor(Class> c) throws Exception {
+ public boolean isFinderFor(Class> c) {
return c.isAnnotationPresent( DefineImpl.class );
}
diff --git a/fj-core/src/main/java/org/fugerit/java/core/lang/binding/BindingHelperDefault.java b/fj-core/src/main/java/org/fugerit/java/core/lang/binding/BindingHelperDefault.java
index 4c398710..d7024ea5 100644
--- a/fj-core/src/main/java/org/fugerit/java/core/lang/binding/BindingHelperDefault.java
+++ b/fj-core/src/main/java/org/fugerit/java/core/lang/binding/BindingHelperDefault.java
@@ -10,10 +10,10 @@
import org.fugerit.java.core.lang.helpers.StringUtils;
import org.fugerit.java.core.lang.helpers.reflect.PathHelper;
import org.fugerit.java.core.util.collection.KeyString;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;
+import lombok.extern.slf4j.Slf4j;
+
/**
* Default binding helper implementation
*
@@ -24,6 +24,7 @@
* @author Matteo a.k.a. Fugerit
*
*/
+@Slf4j
public class BindingHelperDefault extends XMLConfigurableObject implements Serializable, BindingHelper, IdConfigType, KeyString {
public static final BindingHelper DEFAULT = new BindingHelperDefault( BindingCatalogConfig.ID_DEFAULT_HELPER );
@@ -34,15 +35,14 @@ public BindingHelperDefault() {
public BindingHelperDefault( String id ) {
this.setId( id );
}
-
- private final static Logger logger = LoggerFactory.getLogger( BindingHelperDefault.class );
-
/**
*
*/
private static final long serialVersionUID = 1342342342323L;
public Object convertValue(BindingContext context, BindingConfig binding, BindingFieldConfig field, Object value) throws Exception {
+ log.trace( "convertValue() context {} , binding {}", context, binding );
+ log.trace( "convertValue() field {} , value {}", field, value );
return value;
}
@@ -82,7 +82,7 @@ public void bindingWorker(BindingContext context, BindingConfig binding, Binding
}
}
String messageTo = bindTo+" - "+bind;
- logger.debug( "bindFrom {} to {}", bindFrom, messageTo );
+ log.debug( "bindFrom {} to {}", bindFrom, messageTo );
}
@Override
diff --git a/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/reflect/FieldHelper.java b/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/reflect/FieldHelper.java
index 2ae2f631..b9ac25b2 100644
--- a/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/reflect/FieldHelper.java
+++ b/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/reflect/FieldHelper.java
@@ -8,21 +8,31 @@ public class FieldHelper {
private FieldHelper() {}
- public static void setField( Object target, String fieldName, Object value ) {
+ public static void setField( Object target, String fieldName, Object value, boolean setAccessible ) {
try {
Class> c = target.getClass();
Field field = c.getDeclaredField( fieldName );
+ if ( setAccessible ) {
+ field.setAccessible( true );
+ }
field.set( target , value );
} catch (Exception e) {
throw ConfigRuntimeException.convertExMethod( "setField", e );
}
}
- public static Object getField( Object target, String fieldName ) {
+ public static void setField( Object target, String fieldName, Object value ) {
+ setField(target, fieldName, value, false);
+ }
+
+ public static Object getField( Object target, String fieldName, boolean setAccessible ) {
Object res = null;
try {
Class> c = target.getClass();
Field field = c.getDeclaredField( fieldName );
+ if ( setAccessible ) {
+ field.setAccessible( true );
+ }
res = field.get( target );
} catch (Exception e) {
throw ConfigRuntimeException.convertExMethod( "getField", e );
@@ -30,4 +40,8 @@ public static Object getField( Object target, String fieldName ) {
return res;
}
+ public static Object getField( Object target, String fieldName ) {
+ return getField(target, fieldName, false);
+ }
+
}
diff --git a/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/reflect/ImplFinder.java b/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/reflect/ImplFinder.java
index 276ff7c0..b51c36c7 100644
--- a/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/reflect/ImplFinder.java
+++ b/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/reflect/ImplFinder.java
@@ -2,8 +2,8 @@
public interface ImplFinder {
- Class> findImplFor( Class> c ) throws Exception;
+ Class> findImplFor( Class> c );
- boolean isFinderFor( Class> c ) throws Exception;
+ boolean isFinderFor( Class> c );
}
diff --git a/fj-core/src/main/java/org/fugerit/java/core/log/LogUtils.java b/fj-core/src/main/java/org/fugerit/java/core/log/LogUtils.java
index 0ebb92d8..ba825ead 100644
--- a/fj-core/src/main/java/org/fugerit/java/core/log/LogUtils.java
+++ b/fj-core/src/main/java/org/fugerit/java/core/log/LogUtils.java
@@ -41,12 +41,7 @@ public static void appendPropDefault( StringBuilder buffer, String key, String v
}
public static LogObject wrap( final Logger logger ) {
- return new LogObject() {
- @Override
- public Logger getLogger() {
- return logger;
- }
- };
+ return () -> logger;
}
}
diff --git a/fj-core/src/main/java/org/fugerit/java/core/util/checkpoint/CheckpointFormatHelper.java b/fj-core/src/main/java/org/fugerit/java/core/util/checkpoint/CheckpointFormatHelper.java
index ed7dc57b..bc018fb5 100644
--- a/fj-core/src/main/java/org/fugerit/java/core/util/checkpoint/CheckpointFormatHelper.java
+++ b/fj-core/src/main/java/org/fugerit/java/core/util/checkpoint/CheckpointFormatHelper.java
@@ -27,21 +27,11 @@ private void readObject(java.io.ObjectInputStream in) throws IOException, ClassN
// code added to setup a basic conditional serialization - END
- public static final StringFormat FORMAT_TIME_DEFAULT = new StringFormat() {
- @Override
- public String convert(Number input) {
- return String.valueOf( input.longValue() );
- }
- };
+ public static final StringFormat FORMAT_TIME_DEFAULT = input -> String.valueOf( input.longValue() );
public static final StringFormat FORMAT_TIME_NICE = FormatTime.DEFAULT;
- public static final StringFormat FORMAT_DURATION_DEFAULT = new StringFormat() {
- @Override
- public String convert(Number input) {
- return String.valueOf( input.longValue() )+"ms";
- }
- };
+ public static final StringFormat FORMAT_DURATION_DEFAULT = input -> String.valueOf( input.longValue() )+"ms";
public static final StringFormat FORMAT_DURATION_NICE = MillisToSecondsFormat.INSTANCE_APPEND_SECOND;
diff --git a/fj-core/src/main/java/org/fugerit/java/core/util/collection/OptionItem.java b/fj-core/src/main/java/org/fugerit/java/core/util/collection/OptionItem.java
index 6a4922cb..13371c6e 100644
--- a/fj-core/src/main/java/org/fugerit/java/core/util/collection/OptionItem.java
+++ b/fj-core/src/main/java/org/fugerit/java/core/util/collection/OptionItem.java
@@ -40,23 +40,13 @@ public class OptionItem implements KeyObject, Serializable {
* Comparator to sort OptionItem by label String value
*
*/
- public final static Comparator LABEL_SORTER = new Comparator() {
- @Override
- public int compare(OptionItem object1, OptionItem object2) {
- return object1.getLabel().compareTo( object2.getLabel() );
- }
- };
+ public final static Comparator LABEL_SORTER = (object1, object2) -> object1.getLabel().compareTo( object2.getLabel() );
/**
* Comparator to sort OptionItem by value String value
*
*/
- public final static Comparator VALUE_SORTER = new Comparator() {
- @Override
- public int compare(OptionItem object1, OptionItem object2) {
- return object1.getValue().compareTo( object2.getValue() );
- }
- };
+ public final static Comparator VALUE_SORTER = (object1, object2) -> object1.getValue().compareTo( object2.getValue() );
private String value;
diff --git a/fj-core/src/main/java/org/fugerit/java/core/util/filterchain/MiniFilterConfig.java b/fj-core/src/main/java/org/fugerit/java/core/util/filterchain/MiniFilterConfig.java
index b113dfcf..10afe55b 100644
--- a/fj-core/src/main/java/org/fugerit/java/core/util/filterchain/MiniFilterConfig.java
+++ b/fj-core/src/main/java/org/fugerit/java/core/util/filterchain/MiniFilterConfig.java
@@ -11,6 +11,7 @@
import org.fugerit.java.core.cfg.ConfigRuntimeException;
import org.fugerit.java.core.cfg.xml.CustomListCatalogConfig;
import org.fugerit.java.core.cfg.xml.ListMapConfig;
+import org.fugerit.java.core.function.SafeFunction;
import org.fugerit.java.core.io.helper.StreamHelper;
import org.fugerit.java.core.lang.helpers.ClassHelper;
import org.fugerit.java.core.lang.helpers.StringUtils;
@@ -57,18 +58,42 @@ public MiniFilterConfig(String attTagDataList, String attTagData) {
this.getGeneralProps().setProperty( ATT_TYPE , MiniFilterConfigEntry.class.getName() );
}
- public static MiniFilterConfig loadConfig( InputStream is, MiniFilterConfig config ) throws Exception {
- Document doc = DOMIO.loadDOMDoc( is );
- Element root = doc.getDocumentElement();
- config.configure( root );
- return config;
+ /**
+ * Configure a MiniFilterConfig instance.
+ *
+ * NOTE: starting from version 8.4.X java.lang.Exception removed in favor of org.fugerit.java.core.cfg.ConfigRuntimeException.
+ *
+ * @see Define and throw a dedicated exception instead of using a generic one.
+ *
+ * @param is the configuration stream
+ * @param config the item to configure (will be configured by side effect too)
+ * @return the configured item
+ * @throws ConfigRuntimeException in case of issues during loading
+ */
+ public static MiniFilterConfig loadConfig( InputStream is, MiniFilterConfig config ) {
+ return SafeFunction.get( () -> {
+ Document doc = DOMIO.loadDOMDoc( is );
+ Element root = doc.getDocumentElement();
+ config.configure( root );
+ return config;
+ });
+
}
- public static MiniFilterMap loadConfigMap( InputStream is, MiniFilterConfig config ) throws Exception {
- Document doc = DOMIO.loadDOMDoc( is );
- Element root = doc.getDocumentElement();
- config.configure( root );
- return config;
+ /**
+ * Configure a MiniFilterConfig instance as a MiniFilterMap.
+ *
+ * NOTE: starting from version 8.4.X java.lang.Exception removed in favor of org.fugerit.java.core.cfg.ConfigRuntimeException.
+ *
+ * @see Define and throw a dedicated exception instead of using a generic one.
+ *
+ * @param is the configuration stream
+ * @param config the item to configure (will be configured by side effect too)
+ * @return the configured item
+ * @throws ConfigRuntimeException in case of issues during loading
+ */
+ public static MiniFilterMap loadConfigMap( InputStream is, MiniFilterConfig config ) {
+ return loadConfig(is, config);
}
@Override
diff --git a/fj-core/src/main/java/org/fugerit/java/core/util/filterchain/MiniFilterDebug.java b/fj-core/src/main/java/org/fugerit/java/core/util/filterchain/MiniFilterDebug.java
index 53b877a7..7d9667b3 100644
--- a/fj-core/src/main/java/org/fugerit/java/core/util/filterchain/MiniFilterDebug.java
+++ b/fj-core/src/main/java/org/fugerit/java/core/util/filterchain/MiniFilterDebug.java
@@ -8,31 +8,25 @@ public class MiniFilterDebug {
private MiniFilterDebug() {}
- public static void dumpConfig( PrintWriter writer, InputStream is ) throws Exception {
+ public static void dumpConfig( PrintWriter writer, InputStream is ) {
MiniFilterConfig config = new MiniFilterConfig();
MiniFilterConfig.loadConfig( is , config );
dumpConfig(writer, config);
}
- public static void dumpConfig( PrintWriter writer, MiniFilterConfig config ) throws Exception {
- try {
- writer.println( "General config properties : "+config.getGeneralProps().toString() );
- Iterator itConfig = config.getIdSet().iterator();
- while ( itConfig.hasNext() ) {
- String currentId = itConfig.next();
- writer.println( "***********************************************" );
- writer.println( "AnprOperationBase.getChain() id='"+currentId+"'" );
- writer.println( "***********************************************" );
- Iterator itEntry = config.getDataList( currentId ).iterator();
- while ( itEntry.hasNext() ) {
- MiniFilterConfigEntry entry = itEntry.next();
- writer.println( "entry chain : "+entry.getId()+" - "+entry.getType() );
- }
+ public static void dumpConfig( PrintWriter writer, MiniFilterConfig config ) {
+ writer.println( "General config properties : "+config.getGeneralProps().toString() );
+ Iterator itConfig = config.getIdSet().iterator();
+ while ( itConfig.hasNext() ) {
+ String currentId = itConfig.next();
+ writer.println( "***********************************************" );
+ writer.println( "AnprOperationBase.getChain() id='"+currentId+"'" );
+ writer.println( "***********************************************" );
+ Iterator itEntry = config.getDataList( currentId ).iterator();
+ while ( itEntry.hasNext() ) {
+ MiniFilterConfigEntry entry = itEntry.next();
+ writer.println( "entry chain : "+entry.getId()+" - "+entry.getType() );
}
- } catch (Exception e) {
- writer.println( "Error dumping config "+e );
- e.printStackTrace( writer );
- throw e;
}
}
diff --git a/fj-core/src/test/java/test/org/fugerit/java/core/db/connect/TestConnectionFactory.java b/fj-core/src/test/java/test/org/fugerit/java/core/db/connect/TestConnectionFactory.java
index fa73f81f..16265ddf 100644
--- a/fj-core/src/test/java/test/org/fugerit/java/core/db/connect/TestConnectionFactory.java
+++ b/fj-core/src/test/java/test/org/fugerit/java/core/db/connect/TestConnectionFactory.java
@@ -40,6 +40,7 @@ private boolean worker( ConnectionFactory wrapped ) throws Exception {
try ( ConnectionFactoryCloseable cf = ConnectionFactoryImpl.wrap( wrapped );
Connection conn = cf.getConnection() ) {
log.info( "db info : {}", cf.getDataBaseInfo() );
+ log.info( "db info second time : {}", cf.getDataBaseInfo() );
log.info( "driver info : {}", ConnectionFactoryImpl.getDriverInfo( cf ) );
}
ok = (wrapped != null);
@@ -50,15 +51,15 @@ private boolean worker( ConnectionFactory wrapped ) throws Exception {
public void testCFProps() throws Exception {
String name = "wrapped";
Properties props= PropsIO.loadFromClassLoaderSafe( BasicDBHelper.DEFAULT_DB_CONN_PATH );
+ props.setProperty( ConnectionFactoryImpl.PROP_CF_EXT_POOLED_IC , "1" );
+ props.setProperty( ConnectionFactoryImpl.PROP_CF_EXT_POOLED_SC , "1" );
+ props.setProperty( ConnectionFactoryImpl.PROP_CF_EXT_POOLED_MC , "3" );
ConnectionFactory wrapped = ConnectionFactoryImpl.newInstance( props );
ConnectionFacade.registerFactory( name , wrapped );
boolean ok = this.worker( ConnectionFacade.getFactory( name ) );
Assert.assertTrue(ok);
// pooled
- ok = this.worker( new DbcpConnectionFactory( props.getProperty( ConnectionFactoryImpl.PROP_CF_MODE_DC_DRV ),
- props.getProperty( ConnectionFactoryImpl.PROP_CF_MODE_DC_URL ),
- props.getProperty( ConnectionFactoryImpl.PROP_CF_MODE_DC_USR ),
- props.getProperty( ConnectionFactoryImpl.PROP_CF_MODE_DC_PWD ), 1, 1, 3 ) );
+ ok = this.worker( new DbcpConnectionFactory( props ) );
Assert.assertTrue(ok);
}
diff --git a/fj-core/src/test/java/test/org/fugerit/java/core/lang/helpers/reflect/TestFieldHelper.java b/fj-core/src/test/java/test/org/fugerit/java/core/lang/helpers/reflect/TestFieldHelper.java
new file mode 100644
index 00000000..49f857eb
--- /dev/null
+++ b/fj-core/src/test/java/test/org/fugerit/java/core/lang/helpers/reflect/TestFieldHelper.java
@@ -0,0 +1,32 @@
+package test.org.fugerit.java.core.lang.helpers.reflect;
+
+import org.fugerit.java.core.cfg.ConfigRuntimeException;
+import org.fugerit.java.core.lang.helpers.reflect.FieldHelper;
+import org.junit.Assert;
+import org.junit.Test;
+
+import lombok.Getter;
+import lombok.Setter;
+
+public class TestFieldHelper {
+
+ private static final String TEST_VALUE = "test1";
+
+ public class CheckBean {
+ @Getter @Setter private String field1;
+ public String field2;
+ }
+
+ @Test
+ public void testSetField() {
+ CheckBean bean = new CheckBean();
+ Assert.assertNull( bean.getField1() );
+ FieldHelper.setField(bean, "field1", TEST_VALUE, true);
+ Assert.assertEquals( TEST_VALUE , FieldHelper.getField(bean, "field1", true) );
+ FieldHelper.setField(bean, "field2", TEST_VALUE);
+ Assert.assertEquals( TEST_VALUE , FieldHelper.getField(bean, "field2") );
+ Assert.assertThrows( ConfigRuntimeException.class , () -> FieldHelper.setField(bean, "field1", TEST_VALUE) );
+ Assert.assertThrows( ConfigRuntimeException.class , () -> FieldHelper.getField(bean, "field1") );
+ }
+
+}
diff --git a/fj-core/src/test/java/test/org/fugerit/java/core/util/filterchain/TestMiniFilter.java b/fj-core/src/test/java/test/org/fugerit/java/core/util/filterchain/TestMiniFilter.java
index f9591766..ee8337bb 100644
--- a/fj-core/src/test/java/test/org/fugerit/java/core/util/filterchain/TestMiniFilter.java
+++ b/fj-core/src/test/java/test/org/fugerit/java/core/util/filterchain/TestMiniFilter.java
@@ -4,13 +4,19 @@
import static org.junit.Assert.fail;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
import java.util.Iterator;
+import org.fugerit.java.core.lang.helpers.ClassHelper;
import org.fugerit.java.core.util.filterchain.MiniFilterChain;
import org.fugerit.java.core.util.filterchain.MiniFilterConfig;
import org.fugerit.java.core.util.filterchain.MiniFilterContext;
import org.fugerit.java.core.util.filterchain.MiniFilterData;
+import org.fugerit.java.core.util.filterchain.MiniFilterDebug;
import org.fugerit.java.core.util.filterchain.MiniFilterMap;
+import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -108,6 +114,31 @@ public void testSerialization() {
}
}
+ @Test
+ public void testLoadMap() {
+ runTestEx( () -> {
+ try ( InputStream is = ClassHelper.loadFromDefaultClassLoader(CONF_PATH) ) {
+ MiniFilterConfig config = new MiniFilterConfig();
+ MiniFilterMap map = MiniFilterConfig.loadConfigMap( is , config );
+ Assert.assertNotNull( map );
+ }
+ } );
+ }
+
+ @Test
+ public void testDebug() {
+ runTestEx( () -> {
+ try ( InputStream is = ClassHelper.loadFromDefaultClassLoader(CONF_PATH);
+ StringWriter buffer = new StringWriter();
+ PrintWriter writer = new PrintWriter(buffer)) {
+ MiniFilterDebug.dumpConfig( writer , is );
+ String debugText = buffer.toString();
+ Assert.assertNotEquals( 0 , debugText.length() );
+ logger.info( "debug {}", debugText );
+ }
+ } );
+ }
+
@Test
public void testPrintConfig() {
logger.info( "**********************************************" );
diff --git a/fj-tool/src/main/java/org/fugerit/java/tool/fixed/ExtractFixedConfigHandler.java b/fj-tool/src/main/java/org/fugerit/java/tool/fixed/ExtractFixedConfigHandler.java
index b7a08b2f..e7fd3b8c 100644
--- a/fj-tool/src/main/java/org/fugerit/java/tool/fixed/ExtractFixedConfigHandler.java
+++ b/fj-tool/src/main/java/org/fugerit/java/tool/fixed/ExtractFixedConfigHandler.java
@@ -52,9 +52,9 @@ public class ExtractFixedConfigHandler extends ToolHandlerHelper {
private int handleRow( int start, String length, String name, List listFields, int rowCount ) {
Integer len = Integer.valueOf( length );
FixedFieldDescriptor ffd = new FixedFieldDescriptor( name, start, len );
- logger.info( "field descriptor : {}", ffd );
+ logger.info( "field descriptor : {}, rowCount : {}", ffd, rowCount );
listFields.add( ffd );
- return (start+= len);
+ return (start+len);
}
@Override