Skip to content

DavidOpDeBeeck/document-randomizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project Usage

Gradle

repositories {
    jcenter()
}

dependencies {
    compile 'be.davidopdebeeck:document-randomizer:1.0'
}

Purpose

The purpose of this library is to provide an easy way to "randomize" fields in a XML or JSON document. A perfect use case would be the anonymization of production data used in development environments.

Library Usage

The randomizer can be configured with element mappings and element value providers.

Element mappings

An element mapping specifies which elements in the document will be randomized and how they will be randomized. Currently you can configure the following properties.

  • xpath: specifies which elements will be selected
  • unique: specifies if the new element value needs to be unique (unique in this mapping and all the other documents)
  • groupNodesWithSameText: specifies if nodes with the same value are given the same new element value
  • value provider: specifies how the new element value is generated

Element value providers

Providers define how the new element values are generated. The following providers are supplied by the library.

  • RandomNumberBetweenElementValueProvider
  • RandomValueElementValueProvider
  • FileValuesRandomElementValueProvider
  • FileValuesSequentialElementValueProvider
  • CollectionRandomElementValueProvider
  • CollectionSequentialElementValueProvider

Example

Input

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <name>David</name>
</root>

Java code

class Example {
    
    public static void main(String[] args){
        Randomizer randomizer = createXmlRandomizer();
        
        randomizer.randomize(new FileInputSource(new File("path/to/xml/file.xml")))
            .subscribe(System.out::println);
    }
    
    private static Randomizer createXmlRandomizer() {
        return Randomizers.xmlRandomizer(
                asList(new ElementValueMapping.Builder()
                        .withXpath("//*[local-name() = 'name']")
                        .withElementValueProvider(randomString(10))
                        .build()));
    }
}

Output

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <name>kofqwkshjf</name>
</root>

Supported documents

XML and JSON are the currently supported document languages. Feel free to contribute other document languages.

About

A library used to randomize elements inside a XML or JSON document

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages