Make enum values configurable

Hi All,

Current scenario- I have one schema ( generated from xsd) and one document ( generated from schema).I am validating this document at run time (Schema:validate service).

Problem- In my schema there is one enum filed ( suppose city) and I have already define some values for this field, but the issue is when new value came, I need to change the schema which is kind of a code change.

Is there any way to make this enum value configurable without changing in schema (like reading from file , db etc.) ? if yes , then how can I achieve this?

Thank you in advance.

What I think to change enum field to normal string and read values from config file.
in flow service , I can compare the values.

Is this approach is good or is there any other way?

Hi Mohit,

using a config file might be the option you want to look for.

Just have one property (=key) in it and put the values to value part of the property.
Just use a semicolon as a separator between the different values and then use tokenize to split the values string into a list of strings.
You can the compare the data against this list.

If you have a database available you can create a table containing the allowed values and then do select with JDBC Adapter service to check if the value can be found (row count=0: missing; row count>1: configured).

Schema node and derived document types need to be regenerated when xsd changes.

Regards,
Holger

Thank you so much Holger for you reply.

Is there any other way/approach to achieve this?

Regards,
Mohit

I am not sure how is your xml schemas are managed and who owns it. From your information I would suggest you to have a blend of both database and cache (ehcache/terracotta) to hold your enum values.

The design approach is database will hold the source of truth and you will load the cache from the db so that the enum values will be retrieved from the cache and as a fallback you can retrieve from the db.

Hope it is clear if not get back to me.

Thank you Mahesh for your reply.
Correct me if I am wrong.

I have to check for max 6 values. If I used DB then I have to make additional call to DB rather than this i think reading from properties file be more fast.

For your use-case, I would recommend DB with Service Caching where you can cache the results of select adapter service. This approach will hit DB once and stores the values in the cache, further executions will not hit db and it will be retrieved from the service cache.

Refer “About Service Caching” from Service Development Help guide.

More questions?

1 Like

yes this make sense.

Thank you Mahesh for your help.

Hi All,

Current scenario- XML data comes to IS then transform to document and validate with the schema( generated from xsd using pub:schema:validate service).

Ques- We have xsd placed at one place ( file system) and when the xml data comes to IS, we want to validate that data with xml string coming as input.
Motive behind do this, If we want to add any enum value in xsd then it can be validate at first level ( no need to change in code).
Is there any way to achieve this?

note- document is not generated with schema. it is a flat document which used for mapping only.

Thanks in advance.