2

We provide web services that'll return informations about a product like this (simplified)

<product>
<id>123</id>
<name>Mobil-home</name>
<pricing>
<price>12</price>
<adults>2</adults>
</pricing>
<pricing>
<price>15</price>
<adults>3</adults>
</pricing>
</product>

Our partner says "Our problem is that in our system we can have only 1 adult count per product". This partner is working with a huge system, and they say that it's a big problem and they can't change anything about it in their side.

So what did we decide ? to explode our results like this

<product>
    <id>123</id>
<virtualId>123@2</virtualId>
    <name>Mobil-home</name>
    <pricing>
    <price>12</price>
    <adults>2</adults>
    </pricing>    
    </product>
<product>
    <id>123</id>
<virtulId>123@3</virtualId>
    <name>Mobil-home</name>
    <pricing>
    <price>15</price>
    <adults>3</adults>
    </pricing>
    </product>

So we created a "virtualId" that concatenate the id and the adults with an @. Technically it's a mess, but we do software for a business, the target is not to make clean software, but to make money.

My solutions are :

  • I try to make a concept out of it : "In some call I have to call a service class that'll explode our results", and then add this functionality to my web service (even if I'm sure we'll use this only in the case of this partner).

  • I do 3 dirty lines of code with an ugly (if user == "thispartner")

  • I add a layer between my partner and my web service that'll do the ugly job

  • I'm stubborn and I say to my boss "We can't work with them, our systems are not compatible", and then I go to the Pole Emploi.

How do you deal in these cases ?

remi bourgarel
  • 9,231
  • 4
  • 40
  • 73

1 Answers1

0

I think the best technical solution will really depend on your implementation, so it isn't really language-agnostic.

For example, if you use a language with full reflection, like Python, my solution would be to add a database field to the partner list named something like TransformationClass. Then, your web service code would look something like:

output = do_normal_processing()
if partner.TransformationClass is not null:
    transformation = construct an instance of the partner.TransformationClass class
    output = transformation.transform(output)
return output

(Note: for Python, you can construct an instance based on a classname like this.)

You can then create a source code subdirectory 'clientSpecificTransformations' and dropper-client transformations in there; no need to even recompile or restart anything.

However, IMHO for languages that lack the reflection to do such a thing, you'll end up jumping through hoops, and I'd just write a specific proxy for that client and instruct him to use the proxy's URL. The proxy can just make the exact same request to the original service and then explode as required.

Community
  • 1
  • 1
nitwit
  • 1,745
  • 2
  • 17
  • 20