Code Monkey home page Code Monkey logo

document-randomizer's Introduction

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.

document-randomizer's People

Contributors

davidopdebeeck avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.