Skip to content

Commit 7589c4b

Browse files
Added :
custom entry handling universal entry id check
1 parent ceee8ca commit 7589c4b

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.ArrayList;
55
import java.util.Collection;
66
import java.util.HashMap;
7+
import java.util.HashSet;
78
import java.util.Map;
89
import java.util.Properties;
910
import java.util.Set;
@@ -104,13 +105,19 @@ public GenericListCatalogConfig( String attTagDataList, String attTagData ) {
104105
this.attTagData = attTagData;
105106
this.generalProps = new Properties();
106107
this.orderedId = new ConcurrentSkipListSet<String>();
108+
this.entryIdCheck = new HashSet<String>();
107109
}
108110

109111
/**
110-
* General configurazion property for checking duplicate id
112+
* General configurazion property for checking duplicate catalog id
111113
*/
112114
public static final String CONFIG_CHECK_DUPLICATE_ID = "check-duplicate-id";
113115

116+
/**
117+
* General configurazion property for checking duplicate entry id
118+
*/
119+
public static final String CONFIG_CHECK_ENTRY_DUPLICATE_ID = "check-duplicate-entry-id";
120+
114121
/**
115122
* If 'check-duplicate-id' is se to fail, the duplicate will cause the configuration to fail
116123
*/
@@ -194,13 +201,19 @@ public GenericListCatalogConfig( String attTagDataList, String attTagData ) {
194201
protected String attTagDataList;
195202
protected String attTagData;
196203

204+
private Set<String> entryIdCheck;
205+
197206
public static <T> GenericListCatalogConfig<T> load( InputStream is, GenericListCatalogConfig<T> config ) throws Exception {
198207
Document doc = DOMIO.loadDOMDoc( is );
199208
Element root = doc.getDocumentElement();
200209
config.configure( root );
201210
return config;
202211
}
203-
212+
213+
protected Set<String> getEntryIdCheck() {
214+
return entryIdCheck;
215+
}
216+
204217
@SuppressWarnings("unchecked")
205218
protected Collection<T> newCollection( Object typeSample, String listType, Element tag, Element current ) throws ConfigException {
206219
Collection<T> c = null;
@@ -225,13 +238,18 @@ protected Collection<T> newCollection( Object typeSample, String listType, Eleme
225238
return c;
226239
}
227240

241+
protected T customEntryHandling( T current ) {
242+
return current;
243+
}
244+
228245
@Override
229246
public void configure(Element tag) throws ConfigException {
230247

231248
DOMUtils.attributesToProperties( tag, this.getGeneralProps() );
232249
logger.info( "general props : "+this.getGeneralProps() );
233250

234251
String checkDuplicateId = this.getGeneralProps().getProperty( CONFIG_CHECK_DUPLICATE_ID , CONFIG_CHECK_DUPLICATE_ID_DEFAULT );
252+
String checkDuplicateUniversalId = this.getGeneralProps().getProperty( CONFIG_CHECK_ENTRY_DUPLICATE_ID , CONFIG_CHECK_DUPLICATE_ID_DEFAULT );
235253

236254
String listType = this.getGeneralProps().getProperty( ATT_LIST_TYPE );
237255

@@ -284,18 +302,25 @@ public void configure(Element tag) throws ConfigException {
284302
}
285303
for ( int i=0; i<schemaIt.getLength(); i++ ) {
286304
Element currentSchemaTag = (Element) schemaIt.item( i );
305+
String idSchema = currentSchemaTag.getAttribute( "id" );
306+
if ( StringUtils.isNotEmpty( idSchema ) && CONFIG_CHECK_DUPLICATE_ID_FAIL.equalsIgnoreCase( checkDuplicateUniversalId ) ) {
307+
if ( !this.getEntryIdCheck().add( idSchema ) ) {
308+
throw new ConfigException( "Duplicate entry id found : "+idSchema );
309+
}
310+
}
287311
if ( ATT_TAG_TYPE_STRING.equals( type ) ) {
288-
String idSchema = currentSchemaTag.getAttribute( "id" );
289312
if ( StringUtils.isEmpty( idSchema ) ) {
290313
throw new ConfigException( "No schema id definied" );
291314
} else {
292315
@SuppressWarnings("unchecked")
293316
T id = ((T)idSchema);
317+
id = this.customEntryHandling( id );
294318
listCurrent.add( id );
295319
}
296320
} else {
297321
try {
298322
T t = XmlBeanHelper.setFromElement(type, currentSchemaTag );
323+
t = this.customEntryHandling( t );
299324
listCurrent.add( t );
300325
} catch (Exception e) {
301326
throw new ConfigException( "Error configuring type : "+e, e );

0 commit comments

Comments
 (0)