You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by contactreji <co...@gmail.com> on 2014/12/03 09:52:22 UTC

Duplicate Elimination

Hi

I have a requirement where I need to omit duplicate records. Consider sample
below

*<ExchangeRates>
<Rate>
<SourceCurrency>INR<SourceCurrency>
<TargetCurrency>USD<TargetCurrency>
<ConversionFactor>60.2<ConversionFactor>
</Rate>
<Rate>
<SourceCurrency>INR<SourceCurrency>
<TargetCurrency>USD<TargetCurrency>
<ConversionFactor>58.2<ConversionFactor>
</Rate>
<Rate>
<SourceCurrency>YEN<SourceCurrency>
<TargetCurrency>INR<TargetCurrency>
<ConversionFactor>.52<ConversionFactor>
</Rate>
<Rate>
<SourceCurrency>SAR<SourceCurrency>
<TargetCurrency>INR<TargetCurrency>
<ConversionFactor>16.50<ConversionFactor>
</Rate>
</ExchangeRates>*



Now what i wanna do is remove all duplicates. As well as if there is same
pair of Source and TargetCurrency , I want to send ahead the first record
and drop others.

Output shud be like

*<ExchangeRates>
<Rate>
<SourceCurrency>INR<SourceCurrency>
<TargetCurrency>USD<TargetCurrency>
<ConversionFactor>60.2<ConversionFactor>
</Rate>
<Rate>
<SourceCurrency>YEN<SourceCurrency>
<TargetCurrency>INR<TargetCurrency>
<ConversionFactor>.52<ConversionFactor>
</Rate>
<Rate>
<SourceCurrency>SAR<SourceCurrency>
<TargetCurrency>INR<TargetCurrency>
<ConversionFactor>16.50<ConversionFactor>
</Rate>
</ExchangeRates>*

Is there any camel component which can help me achieve this??

Is there away I can use Idempotent Consumer. Cuz I saw that in idempotent
consumer, we can use only 1 unique value to verify duplicacy. Can i use 2
set of values to verify duplicacy? 
Ex - I want to allow only one set of USD->INR rate once in a day.

Cheers
Reji



--
View this message in context: http://camel.465427.n5.nabble.com/Duplicate-Elimination-tp5760020.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Duplicate Elimination

Posted by David Karlsen <da...@gmail.com>.
Sure - some XSLT will do it - and it becomes a string.
I opened an issue some time ago about having the possibility to make the
messageId a complex object, possibly holding several keys:
https://issues.apache.org/jira/browse/CAMEL-7461

2014-12-03 12:44 GMT+01:00 contactreji <co...@gmail.com>:

> Thanks David
>
> A littlemore cleaner way was to use XSLT transformation. I was just
> interested in knowing if there is any provisions in Camel itself. Was
> trying
> to explore if idempotent consumer can work with more than 1 parameters as
> identifier.
>
> Following XSL code did the magic!
>
> *<xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
> <xsl:key name="currencyPair" match="Rate" use="concat(SourceCurrency,'
> ',TargetCurrency)"/>
>
> <xsl:template match="ExchangeRates">
>     <xsl:copy>
>         <xsl:for-each select="Rate[count(. |
> key('currencyPair',concat(SourceCurrency,' ',TargetCurrency))[1]) = 1]">
>             <xsl:copy-of select="."/>
>         </xsl:for-each>
>     </xsl:copy>
> </xsl:template>
> </xsl:stylesheet>
> *
>
>
> Cheers
> Reji
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Duplicate-Elimination-tp5760020p5760047.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
--
David J. M. Karlsen - http://www.linkedin.com/in/davidkarlsen

Re: Duplicate Elimination

Posted by contactreji <co...@gmail.com>.
Thanks David

A littlemore cleaner way was to use XSLT transformation. I was just
interested in knowing if there is any provisions in Camel itself. Was trying
to explore if idempotent consumer can work with more than 1 parameters as
identifier.

Following XSL code did the magic!

*<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:key name="currencyPair" match="Rate" use="concat(SourceCurrency,'
',TargetCurrency)"/>

<xsl:template match="ExchangeRates">
    <xsl:copy>
        <xsl:for-each select="Rate[count(. |
key('currencyPair',concat(SourceCurrency,' ',TargetCurrency))[1]) = 1]">
            <xsl:copy-of select="."/>
        </xsl:for-each>
    </xsl:copy>
</xsl:template>
</xsl:stylesheet>
*


Cheers
Reji



--
View this message in context: http://camel.465427.n5.nabble.com/Duplicate-Elimination-tp5760020p5760047.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Duplicate Elimination

Posted by David Karlsen <da...@gmail.com>.
Just combine the two currencies into one string and use that as the unique
value...

2014-12-03 9:52 GMT+01:00 contactreji <co...@gmail.com>:

> Hi
>
> I have a requirement where I need to omit duplicate records. Consider
> sample
> below
>
> *<ExchangeRates>
> <Rate>
> <SourceCurrency>INR<SourceCurrency>
> <TargetCurrency>USD<TargetCurrency>
> <ConversionFactor>60.2<ConversionFactor>
> </Rate>
> <Rate>
> <SourceCurrency>INR<SourceCurrency>
> <TargetCurrency>USD<TargetCurrency>
> <ConversionFactor>58.2<ConversionFactor>
> </Rate>
> <Rate>
> <SourceCurrency>YEN<SourceCurrency>
> <TargetCurrency>INR<TargetCurrency>
> <ConversionFactor>.52<ConversionFactor>
> </Rate>
> <Rate>
> <SourceCurrency>SAR<SourceCurrency>
> <TargetCurrency>INR<TargetCurrency>
> <ConversionFactor>16.50<ConversionFactor>
> </Rate>
> </ExchangeRates>*
>
>
>
> Now what i wanna do is remove all duplicates. As well as if there is same
> pair of Source and TargetCurrency , I want to send ahead the first record
> and drop others.
>
> Output shud be like
>
> *<ExchangeRates>
> <Rate>
> <SourceCurrency>INR<SourceCurrency>
> <TargetCurrency>USD<TargetCurrency>
> <ConversionFactor>60.2<ConversionFactor>
> </Rate>
> <Rate>
> <SourceCurrency>YEN<SourceCurrency>
> <TargetCurrency>INR<TargetCurrency>
> <ConversionFactor>.52<ConversionFactor>
> </Rate>
> <Rate>
> <SourceCurrency>SAR<SourceCurrency>
> <TargetCurrency>INR<TargetCurrency>
> <ConversionFactor>16.50<ConversionFactor>
> </Rate>
> </ExchangeRates>*
>
> Is there any camel component which can help me achieve this??
>
> Is there away I can use Idempotent Consumer. Cuz I saw that in idempotent
> consumer, we can use only 1 unique value to verify duplicacy. Can i use 2
> set of values to verify duplicacy?
> Ex - I want to allow only one set of USD->INR rate once in a day.
>
> Cheers
> Reji
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Duplicate-Elimination-tp5760020.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
--
David J. M. Karlsen - http://www.linkedin.com/in/davidkarlsen