Skip to content

Commit b23a406

Browse files
committed
Added 'fail-on-set' of duplicate entry for GenericListCatalogConfig
1 parent 2715d19 commit b23a406

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

fj-core/src/main/java/org/fugerit/java/core/cfg/xml/GenericListCatalogConfig.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.fugerit.java.core.lang.helpers.ClassHelper;
2121
import org.fugerit.java.core.lang.helpers.StringUtils;
2222
import org.fugerit.java.core.util.collection.KeyObject;
23+
import org.fugerit.java.core.util.collection.ListMapStringKey;
2324
import org.fugerit.java.core.xml.config.XMLSchemaCatalogConfig;
2425
import org.fugerit.java.core.xml.dom.DOMIO;
2526
import org.fugerit.java.core.xml.dom.DOMUtils;
@@ -129,6 +130,11 @@ public GenericListCatalogConfig( String attTagDataList, String attTagData ) {
129130
* If 'check-duplicate-id' is se to fail, the duplicate will cause the configuration to fail
130131
*/
131132
public static final String CONFIG_CHECK_DUPLICATE_ID_FAIL = "fail";
133+
134+
/**
135+
* If 'check-duplicate-entry-id' is se to fail, the duplicate will cause the configuration to fail
136+
*/
137+
public static final String CONFIG_CHECK_DUPLICATE_ID_FAIL_ON_SET = "fail-on-set";
132138

133139
/**
134140
* If 'check-duplicate-id' is se to warn, the duplicate will only be logged
@@ -367,6 +373,14 @@ public void configure(Element tag) throws ConfigException {
367373
if ( !this.getEntryIdCheck().add( idSchema ) ) {
368374
throw new ConfigException( "Duplicate entry id found : "+idSchema );
369375
}
376+
} else if ( StringUtils.isNotEmpty( idSchema ) && CONFIG_CHECK_DUPLICATE_ID_FAIL_ON_SET.equalsIgnoreCase( checkDuplicateUniversalId ) ) {
377+
if ( listCurrent instanceof ListMapStringKey ) {
378+
ListMapStringKey<?> listCheck = ((ListMapStringKey<?>)listCurrent);
379+
if ( listCheck.getMap().containsKey( idSchema ) ) {
380+
throw new ConfigException( "Duplicate entry id on set found : "+idSchema );
381+
}
382+
}
383+
370384
}
371385
if ( ATT_TAG_TYPE_STRING.equals( type ) ) {
372386
if ( StringUtils.isEmpty( idSchema ) ) {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package test.org.fugerit.java.core.util.filterchain;
2+
3+
import static org.junit.Assert.fail;
4+
5+
import org.fugerit.java.core.util.filterchain.MiniFilterConfig;
6+
import org.junit.Test;
7+
import org.slf4j.Logger;
8+
import org.slf4j.LoggerFactory;
9+
10+
public class TestDuplicateFailOnSet {
11+
12+
private final static Logger logger = LoggerFactory.getLogger( TestDuplicateFailOnSet.class );
13+
14+
private static final String CONF_PATH_DUPLICATE_FAIL_ON_SET = "core/util/filterchain/minifilter-test-duplicate-fail-on-set.xml";
15+
16+
@Test
17+
public void testDuplicate() {
18+
logger.info( "**********************************************" );
19+
logger.info( "**********************************************" );
20+
logger.info( "* TEST DUPLICATE *" );
21+
boolean ok = false;
22+
try {
23+
MiniFilterConfig config = MiniFilterConfig.initFromClassLoaderWithRuntimeException( CONF_PATH_DUPLICATE_FAIL_ON_SET );
24+
logger.info( config.toString() );
25+
} catch (Exception e) {
26+
logger.info( e.getMessage() );
27+
if ( e.getMessage().toLowerCase().contains( "duplicate" ) ) {
28+
ok = true;
29+
}
30+
}
31+
if ( !ok ) {
32+
fail( "Test failed, duplicate exception non triggered" );
33+
}
34+
logger.info( "**********************************************" );
35+
logger.info( "**********************************************" );
36+
}
37+
38+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<data-catalog-config
2+
check-duplicate-entry-id="fail-on-set"
3+
type="org.fugerit.java.core.util.filterchain.MiniFilterConfigEntry">
4+
5+
<data-list id="chain-base-01" >
6+
<data id="step-01-01" defaultBehaviour="CONTINUE"
7+
description="Step 01 01 Continue (this one will be printed)"
8+
type="test.org.fugerit.java.core.util.filterchain.ContinueStep"/>
9+
<data id="step-01-02" defaultBehaviour="CONTINUE"
10+
description="Step 01 02 Continue (this one will be printed)"
11+
type="test.org.fugerit.java.core.util.filterchain.ContinueStep"/>
12+
</data-list>
13+
14+
<data-list id="chain-base-02">
15+
<data id="step-02-01" defaultBehaviour="CONTINUE"
16+
description="Step 02 01 Skip (this one will be printed)"
17+
type="test.org.fugerit.java.core.util.filterchain.SkipStep"/>
18+
<data id="step-02-02" defaultBehaviour="CONTINUE"
19+
description="Step 02 02 Skip (this one will be printed)"
20+
type="test.org.fugerit.java.core.util.filterchain.SkipStep"/>
21+
<!-- has the same id of first step in this set -->
22+
<data id="step-02-01" defaultBehaviour="CONTINUE"
23+
description="Step 02 03 Skip (this one will be printed)"
24+
type="test.org.fugerit.java.core.util.filterchain.SkipStep"/>
25+
</data-list>
26+
27+
</data-catalog-config>

0 commit comments

Comments
 (0)