mardi 22 septembre 2015

elegant solution for mapping one string value to another

I am working with multiple external systems all of which return a state property.

This state property can be different values between the external systems but must be mapped to a particular state value on my system.

I have a separate class (adapter) to process each external system

e.g

the state values for my system are

{ Pending, Booked, Arrived, InProgress, Complete }

Now External System A may have the following values

{ Unknown, Pending, Booked, Accepted, Arrived, POB, Complete }

External System B may have the following values

{ Waiting, Booked, Arrived, InProgress, Complete }

etc, etc

Now I need to map the external system values to my system values.

eg.

For External System A

Unknown, Pending -> Pending

Booked, Accepted -> Booked

Arrived, POB -> InProgress

Complete -> Complete

For External System B

Waiting -> Pending

Booked -> Booked,

Arrived, InProgress -> InProgress

Complete -> Complete

Now I have abstracted this out to a helper method MapState that each adapter uses to get the state value. This method has string parameters externalsystem, and externalsystemstate and uses switch statements to map the external system state to my system state.

I think this is pretty naff and am sure there is a more elegant solution

Any suggestions?

Aucun commentaire:

Enregistrer un commentaire