Monday, 31 October 2016

This week 17/2016

SmartParam (v.1.1.2) is a powerful framework to parametrise an application.

1. Source of configuration
It is possible to load configuration from text file, database or create it dynamically.  Framework supports directly H2, MySql and Postgesql databases.


example of configuration file:

{
  name: "simpleCase",  inputLevels: 2,  cachable: true,  nullable: true,  arraySeparator: ";",
  levels: [
    {name: "registrationDate", type: "date",   matcher: "between/ie" },     
    {name: "name",                     type: "string" }, 
    {name: "value",                     type: "integer" }, 
    {name: "value2",                   type: "integer" }
  ]
}
registrationDate;name;value;value2
*: 2013-12-01;Adam;20*: 2013-12-01;Monia;5
 


2. Number of input/output parameters
At the beginning it is required to define structure of parameters:
  • name - name of configuration,
  • inputLevels - count of input parameters, which are used to wind exact output parameters,
  • nullable - by default it is false and if any rule match input parameters, it throws exception
  • levels - defines types of input and output parameters.
3. Supported parameters
Framework supports simple types of data, however it is possible to define your own type. There are two ways to do that: do converter or  type holder.
Type holder ex.
@ParamType("localdate")
public class LocalDateType implements Type<LocalDateHolder> {
.....
}
 
public class LocalDateHolder extends AbstractValueHolder {
    private final LocalDate date;
    public LocalDateHolder(LocalDate date) {
        this.date = date;    }
....
} 

4. Matcher
Framework provides all needed matchers but there is possible to create your own matcher.
ex.
@ParamMatcher("mymatcher")
public class MyMatcher implements Matcher {

    @Override    public <T extends ValueHolder> boolean matches(String s, String s1, Type<T> type) {

        return s.toString().equals(s1.toString());    }
}

One of useful matcher is BetweenMatcher. It supports defining a ranges of dates, numbers and defines default value by *

5. Other Notices
Framework presents itself great but project looks to be extinct.

No comments:

Post a Comment