1414import com .skyflow .utils .logger .LogUtil ;
1515import com .skyflow .utils .validations .Validations ;
1616import com .skyflow .vault .controller .ConnectionController ;
17+ import com .skyflow .vault .controller .DetectController ;
1718import com .skyflow .vault .controller .VaultController ;
1819
1920import java .util .LinkedHashMap ;
@@ -101,25 +102,57 @@ public VaultController vault(String vaultId) throws SkyflowException {
101102 return controller ;
102103 }
103104
104- public ConnectionController connection () {
105- String connectionId = (String ) this .builder .connectionsMap .keySet ().toArray ()[0 ];
105+
106+ public ConnectionController connection () throws SkyflowException {
107+ Object [] array = this .builder .connectionsMap .keySet ().toArray ();
108+ if (array .length < 1 ) {
109+ LogUtil .printErrorLog (ErrorLogs .CONNECTION_CONFIG_DOES_NOT_EXIST .getLog ());
110+ throw new SkyflowException (ErrorCode .INVALID_INPUT .getCode (), ErrorMessage .ConnectionIdNotInConfigList .getMessage ());
111+ }
112+ String connectionId = (String ) array [0 ];
106113 return this .connection (connectionId );
107114 }
108115
109- public ConnectionController connection (String connectionId ) {
110- return this .builder .connectionsMap .get (connectionId );
116+ public ConnectionController connection (String connectionId ) throws SkyflowException {
117+ ConnectionController controller = this .builder .connectionsMap .get (connectionId );
118+ if (controller == null ) {
119+ LogUtil .printErrorLog (ErrorLogs .CONNECTION_CONFIG_DOES_NOT_EXIST .getLog ());
120+ throw new SkyflowException (ErrorCode .INVALID_INPUT .getCode (), ErrorMessage .ConnectionIdNotInConfigList .getMessage ());
121+ }
122+ return controller ;
123+ }
124+
125+ public DetectController detect () throws SkyflowException {
126+ Object [] array = this .builder .detectClientsMap .keySet ().toArray ();
127+ if (array .length < 1 ) {
128+ LogUtil .printErrorLog (ErrorLogs .VAULT_CONFIG_DOES_NOT_EXIST .getLog ());
129+ throw new SkyflowException (ErrorCode .INVALID_INPUT .getCode (), ErrorMessage .VaultIdNotInConfigList .getMessage ());
130+ }
131+ String detectId = (String ) array [0 ];
132+ return this .detect (detectId );
133+ }
134+
135+ public DetectController detect (String vaultId ) throws SkyflowException {
136+ DetectController controller = this .builder .detectClientsMap .get (vaultId );
137+ if (controller == null ) {
138+ LogUtil .printErrorLog (ErrorLogs .VAULT_CONFIG_DOES_NOT_EXIST .getLog ());
139+ throw new SkyflowException (ErrorCode .INVALID_INPUT .getCode (), ErrorMessage .VaultIdNotInConfigList .getMessage ());
140+ }
141+ return controller ;
111142 }
112143
113144 public static final class SkyflowClientBuilder {
114145 private final LinkedHashMap <String , ConnectionController > connectionsMap ;
115146 private final LinkedHashMap <String , VaultController > vaultClientsMap ;
147+ private final LinkedHashMap <String , DetectController > detectClientsMap ;
116148 private final LinkedHashMap <String , VaultConfig > vaultConfigMap ;
117149 private final LinkedHashMap <String , ConnectionConfig > connectionConfigMap ;
118150 private Credentials skyflowCredentials ;
119151 private LogLevel logLevel ;
120152
121153 public SkyflowClientBuilder () {
122154 this .vaultClientsMap = new LinkedHashMap <>();
155+ this .detectClientsMap = new LinkedHashMap <>();
123156 this .vaultConfigMap = new LinkedHashMap <>();
124157 this .connectionsMap = new LinkedHashMap <>();
125158 this .connectionConfigMap = new LinkedHashMap <>();
@@ -139,8 +172,11 @@ public SkyflowClientBuilder addVaultConfig(VaultConfig vaultConfig) throws Skyfl
139172 } else {
140173 this .vaultConfigMap .put (vaultConfig .getVaultId (), vaultConfig );
141174 this .vaultClientsMap .put (vaultConfig .getVaultId (), new VaultController (vaultConfig , this .skyflowCredentials ));
175+ this .detectClientsMap .put (vaultConfig .getVaultId (), new DetectController (vaultConfig , this .skyflowCredentials ));
142176 LogUtil .printInfoLog (Utils .parameterizedString (
143177 InfoLogs .VAULT_CONTROLLER_INITIALIZED .getLog (), vaultConfig .getVaultId ()));
178+ LogUtil .printInfoLog (Utils .parameterizedString (
179+ InfoLogs .DETECT_CONTROLLER_INITIALIZED .getLog (), vaultConfig .getVaultId ()));
144180 }
145181 return this ;
146182 }
@@ -226,6 +262,9 @@ public SkyflowClientBuilder addSkyflowCredentials(Credentials credentials) throw
226262 for (VaultController vault : this .vaultClientsMap .values ()) {
227263 vault .setCommonCredentials (this .skyflowCredentials );
228264 }
265+ for (DetectController detect : this .detectClientsMap .values ()) {
266+ detect .setCommonCredentials (this .skyflowCredentials );
267+ }
229268 for (ConnectionController connection : this .connectionsMap .values ()) {
230269 connection .setCommonCredentials (this .skyflowCredentials );
231270 }
0 commit comments