Managing Global Properties (AppStateToken)

OpenSRP allows to manage Global Properties or Tokens reflecting Application State at any given point of time as AppStateToken. You can also register your own tokens by using ConfigService. Some examples of AppStateTokens could be

  • Last time when form submissions were synced with OpenMRS
  • Last time when data was cleaned up
  • Admin email where critical errors should be notified
  • Flag whether SMS alert should be sent to admin for data push failure errors
  • Batch size that should be synced at once

The convertable data types for token are int, long, float, double, boolean (true/false), string, object, datetime (org.joda.time.LocalDate).

To register a new token to manage your own global properties just call ConfigService.registerAppStateToken as following

Prior to V2:

 

Prior to V2
public class MyClass{

    private ConfigService config;

	@Autowired
	public MyClass(ConfigService config)
        AppStateToken at = this.config.getAppStateTokenByName(MyEnum.my_token_variable_name);
        if(at == null){
            this.config.registerAppStateToken(MyEnum.my_token_variable_name,  0L, "My token description");
        }
	}


	public void myMethodRequiringTokenUsage(){
		AppStateToken at= config.getAppStateTokenByName(MyEnum.my_token_variable_name);
		long val = at.longValue();
// .....
	}
}

V2:

V2
public class MyClass{
    private ConfigService config;

	@Autowired
	public MyClass(ConfigService config)
        this.config.registerAppStateToken(MyEnum.my_token_variable_name,  0L, "My token description", true /*Suppress exception if exists*/);
	}

	public void myMethodRequiringTokenUsage(){
		AppStateToken at= config.getAppStateTokenByName(MyEnum.my_token_variable_name);
		long val = at.longValue();
// .....
	}
}