Question about own custom anonymizers
annajode opened this issue · 4 comments
Anonimatron version: 1.10.0
Operating system and version: Windows 7
Java runtime (java -version
): 1.8.0_05
I have no idea how I can use two or more own custom anonymizers?
For example: I like to use two anonymizers "ToLowerAnonymizer" and "ToUpperAnonymizer"
-
Case: For each anonymizer an own .jar file
ToLowerAnonymizer.jar
ToUpperAnonymizer.jar
In the config.xml I use two xml-tags
my.package.ToLowerAnonymizer
my.package.ToUpperAnonymizer
But this does't work! -
Case: Two Classes in one jar-file
MyAnonymizer.jar that includes the two classes: "ToLowerAnonymizer.jave" and "ToUpperAnonymizer.jave"
In the config.xml I use two xml-tags
my.package.MyAnonymizer
But this does't work!
Where is my mistake?
What ist going wrong?
Thanks!
Without your config or log file it is hard to tell, but here are some pointers:
- Your
ToUpperAnonymizer
class needs to implement the interfacecom.rolfje.anonimatron.anonymizer.Anonymizer
. - The column configurations need to refer to the string returned by
getType()
, which is a method you need to implement as part of the interface. - In the configuration, you need to list the classes correctly in the anonymizerclass tag at the start of the configuration, like so:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <anonymizerclass>my.package.ToUpperAnonymizer</anonymizerclass> ...
- You need to use the
anonimatron.sh
oranonimatron.bat
scripts to start anonimatron. They will build the classpath for you. If you start anonimatron with thejava
command, you need to manually add the jar files to your classpath with the-cp
option.
I hope this helps.
Hi realrolfie,
thank you for your answer.
I have used your example from the README.txt in the 'anonymizers' director.
In the code are three errors:
-
We need a third import
import com.rolfje.anonimatron.anonymizer.Anonymizer;
-
'Synonym' has three parameter instead of two
public Synonym anonymize(Object from, int size, boolean bln)
-
The 'from' parameter needs the cast (string)
s.setFrom( (String) from);
As I have fixed this, my own anonymizer works fine.
Here my config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration jdbcurl="jdbc:postgresql://localhost:5432/postgres"
userid="usr" password="pw">
<anonymizerclass>de.kohlpharma.kpanonymizer.ToLowerAnonymizer</anonymizerclass>
<table name="mandant">
<column name="pharmacyname" type="ROMAN_NAME" />
<column name="pharmacyaddress1" type="STRING" />
<column name="pharmacyaddress2" type="STRING" />
<column name="pharmacycity" type="STRING" />
<column name="pharmacyzip" type="RANDOMDIGITS" />
<column name="pharmacyphoneNo" type="RANDOMDIGITS" />
<column name="pharmacyfaxNo" type="RANDOMDIGITS" />
<column name="pharmacyemail" type="EMAIL_ADDRESS" />
<column name="ownerfistname" type="ROMAN_NAME" />
<column name="ownerlastname" type="TO_LOWER_CASE" />
<column name="ownerphoneNo" type="RANDOMDIGITS" />
<column name="owneremail" type="EMAIL_ADDRESS" />
<column name="deliveryfirstlastname" type="ROMAN_NAME" />
<column name="deliveryaddress1" type="STRING" />
<column name="deliveryaddress2" type="STRING" />
<column name="deliverycity" type="STRING" />
<column name="deliveryzip" type="DUTCH_ZIP_CODE" />
</table>
</configuration>
Now, I need a second own anonymizer, for example: ToUpperAnonymizer.
Now I have no solution, how I can do that?
1st opportunity
Two .jar files,
one 'ToLowerAnonymizer.jar' for the 'ToLowerAnonymizer.java' class
and
one 'ToUpperAnonymizer.jar' for the 'ToUpperAnonymizer.java' class
The config file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration jdbcurl="jdbc:postgresql://localhost:5432/postgres"
userid="usr" password="pw">
<anonymizerclass>de.kohlpharma.kpanonymizer.ToLowerAnonymizer</anonymizerclass>
<anonymizerclass>de.kohlpharma.kpanonymizer.ToUpperAnonymizer</anonymizerclass>
<table name="mandant">
[...]
</configuration>
2nd opportunity
One .jar file for example 'MyAnonymizers' with the two classes:
'ToLowerAnonymizer.java' and 'ToUpperAnonymizer.java'.
The config file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration jdbcurl="jdbc:postgresql://localhost:5432/postgres"
userid="usr" password="pw">
<anonymizerclass>de.kohlpharma.kpanonymizer.MyAnonymizers</anonymizerclass>
<table name="mandant">
[...]
</configuration>
**But both opportunities doesn't work.
Where is my mistake?**
Thanks, Edwin
Thanks for mentioning the README.TXT, I'll check it for errors.
The second anonymizer can go into the same jar file, but you still need to add the class to the config. So you have one file /lib/MyAnonymizers.jar
, containing both classes ToLowerAnonymizer and ToUpperAnonymizer. Then in the config file you add the class names:
<?xml version="1.0" encoding="UTF-8"?>
<configuration jdbcurl="jdbc:postgresql://localhost:5432/postgres"
userid="usr" password="pw">
<anonymizerclass>de.kohlpharma.kpanonymizer.ToLowerAnonymizer</anonymizerclass>
<anonymizerclass>de.kohlpharma.kpanonymizer.ToUpperAnonymizer</anonymizerclass>
<table name="mandant">
[...]
</configuration>
realrolfje,
thank you for your support -now it works fine.