org.hisp.dhis.rules.models.SupplementaryData Maven / Gradle / Ivy
package org.hisp.dhis.rules.models;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
public class SupplementaryData
{
private List userRoles;
private List androidVersion;
private Map> orgUnitGroups;
public enum SupplementaryDataKey
{
USER( "USER" ),
ANDROID_VERSION( "android_version" );
private String clientName;
SupplementaryDataKey( String clientName )
{
this.clientName = clientName;
}
public String getClientName() {
return clientName;
}
}
private SupplementaryData(List userRoles, List androidVersion, Map> orgUnitGroups) {
this.userRoles = userRoles;
this.androidVersion = androidVersion;
this.orgUnitGroups = orgUnitGroups;
}
public Integer getAndroidVersion()
{
return Integer.parseInt( androidVersion.get( 0 ) );
}
public List getUserRoles()
{
return userRoles;
}
public List getOrgUnitsInOrgUnitGroup( String orgUnitGroupCodeOrUid )
{
return orgUnitGroups.get( orgUnitGroupCodeOrUid );
}
public static class Builder {
private List userRoles;
private List androidVersion;
private Map> orgUnitGroups;
public Builder setUserRoles( List userRoleUids )
{
this.userRoles = userRoleUids;
return this;
}
public Builder setAndroidVersion( List androidVersion )
{
this.androidVersion = androidVersion;
return this;
}
public Builder setOrgUnitGroups( String orgUnitGroupUid, @Nullable String orgUnitGroupCode, List orgUnitUids ) {
if ( this.orgUnitGroups == null )
{
this.orgUnitGroups = new HashMap<>();
}
if ( orgUnitGroupCode != null )
{
this.orgUnitGroups.put( orgUnitGroupCode, orgUnitUids );
}
this.orgUnitGroups.put( orgUnitGroupUid, orgUnitUids );
return this;
}
public SupplementaryData build()
{
if(androidVersion == null){
androidVersion = new ArrayList<>();
androidVersion.add("-1");
}
if( userRoles == null ){
userRoles = new ArrayList<>();
}
if( orgUnitGroups == null )
{
orgUnitGroups = new HashMap<>();
}
return new SupplementaryData( userRoles, androidVersion, orgUnitGroups );
}
}
}