4444import java .io .IOException ;
4545import java .io .InputStream ;
4646import java .net .URI ;
47- import java .net .http .HttpHeaders ;
4847import java .util .ArrayList ;
4948import java .util .Arrays ;
5049import java .util .Collection ;
@@ -89,13 +88,9 @@ public static class OlogClientBuilder {
8988 private final String protocol ;
9089 private String username = null ;
9190 private String password = null ;
92- private String connectTimeoutAsString = null ;
93- private Boolean permissiveHostnameVerifier ;
94-
95- private final OlogProperties properties = new OlogProperties ();
9691
9792 private OlogClientBuilder () {
98- this .ologURI = URI .create (this . properties . getPreferenceValue ( " olog_url" ) );
93+ this .ologURI = URI .create (Preferences . olog_url );
9994 this .protocol = this .ologURI .getScheme ();
10095 }
10196
@@ -157,45 +152,29 @@ public OlogClient create() {
157152 this .clientConfig = new DefaultClientConfig ();
158153 }
159154 }
160- if (this .username == null || this .password == null ){
155+ if (this .username == null || this .password == null ) {
161156 ScopedAuthenticationToken scopedAuthenticationToken = getCredentialsFromSecureStore ();
162- if (scopedAuthenticationToken != null ){
157+ if (scopedAuthenticationToken != null ) {
163158 this .username = scopedAuthenticationToken .getUsername ();
164159 this .password = scopedAuthenticationToken .getPassword ();
160+ } else {
161+ this .username = Preferences .username != null ? Preferences .username : this .username ;
162+ this .password = Preferences .password != null ? Preferences .password : this .password ;
165163 }
166- else {
167- this .username = ifNullReturnPreferenceValue (this .username , "username" );
168- this .password = ifNullReturnPreferenceValue (this .password , "password" );
169- }
170- }
171- this .connectTimeoutAsString = ifNullReturnPreferenceValue (this .connectTimeoutAsString , "connectTimeout" );
172- int connectTimeout = 0 ;
173- try {
174- connectTimeout = Integer .parseInt (connectTimeoutAsString );
175- } catch (NumberFormatException e ) {
176- Logger .getLogger (OlogClientBuilder .class .getPackageName ())
177- .warning ("connectTimeout preference not set or invalid, using 0 (=infinite)" );
178164 }
165+
166+ int connectTimeout = Preferences .connectTimeout ;
179167 this .clientConfig .getProperties ().put (ClientConfig .PROPERTY_CONNECT_TIMEOUT , connectTimeout );
180168
181- this .permissiveHostnameVerifier = Boolean .parseBoolean (this .properties .getPreferenceValue ("permissive_hostname_verifier" ));
182- if (this .permissiveHostnameVerifier ) {
169+ if (Preferences .permissive_hostname_verifier ) {
183170 HostnameVerifier allHostsValid = (hostname , session ) -> true ;
184171 HttpsURLConnection .setDefaultHostnameVerifier (allHostsValid );
185172 }
186173
187174 return new OlogClient (this .ologURI , this .clientConfig , this .withHTTPAuthentication , this .username , this .password );
188175 }
189176
190- private String ifNullReturnPreferenceValue (String value , String key ) {
191- if (value == null ) {
192- return this .properties .getPreferenceValue (key );
193- } else {
194- return value ;
195- }
196- }
197-
198- private ScopedAuthenticationToken getCredentialsFromSecureStore (){
177+ private ScopedAuthenticationToken getCredentialsFromSecureStore () {
199178 try {
200179 SecureStore secureStore = new SecureStore ();
201180 return secureStore .getScopedAuthenticationToken (AuthenticationScope .LOGBOOK );
@@ -405,24 +384,9 @@ public List<LogEntry> listLogs() {
405384 return new ArrayList <>();
406385 }
407386
408- /**
409- * List of level values as defined in the properties file.
410- */
411- private List <String > levels ;
412-
413- /**
414- * Service URL as configured by properties.
415- */
416- private String serviceUrl ;
417-
418387 @ Override
419388 public Collection <String > listLevels () {
420- if (levels == null ) {
421- OlogProperties ologProperties = new OlogProperties ();
422- String [] levelList = ologProperties .getPreferenceValue ("levels" ).split ("," );
423- levels = Arrays .asList (levelList );
424- }
425- return levels ;
389+ return Arrays .stream (Preferences .levels ).toList ();
426390 }
427391
428392 @ Override
@@ -466,11 +430,7 @@ public Collection<Tag> listTags() {
466430
467431 @ Override
468432 public String getServiceUrl () {
469- if (serviceUrl == null ) {
470- OlogProperties ologProperties = new OlogProperties ();
471- serviceUrl = ologProperties .getPreferenceValue ("olog_url" );
472- }
473- return serviceUrl ;
433+ return Preferences .olog_url ;
474434 }
475435
476436 @ Override
@@ -549,7 +509,7 @@ public String serviceInfo() {
549509 }
550510
551511 @ Override
552- public SearchResult getArchivedEntries (long id ){
512+ public SearchResult getArchivedEntries (long id ) {
553513 try {
554514 final OlogSearchResult ologSearchResult = OlogObjectMappers .logEntryDeserializer .readValue (
555515 service .path ("logs/archived/" + id )
@@ -566,7 +526,7 @@ public SearchResult getArchivedEntries(long id){
566526 }
567527
568528 @ Override
569- public Collection <LogTemplate > getTemplates (){
529+ public Collection <LogTemplate > getTemplates () {
570530 try {
571531 return OlogObjectMappers .logEntryDeserializer .readValue (
572532 service .path ("templates" ).accept (MediaType .APPLICATION_JSON ).get (String .class ),
@@ -579,7 +539,7 @@ public Collection<LogTemplate> getTemplates(){
579539 }
580540
581541 @ Override
582- public LogTemplate saveTemplate (LogTemplate template ) throws LogbookException {
542+ public LogTemplate saveTemplate (LogTemplate template ) throws LogbookException {
583543 ClientResponse clientResponse = service .path ("templates" ).accept (MediaType .APPLICATION_JSON_TYPE )
584544 .header ("Content-Type" , MediaType .APPLICATION_JSON_TYPE )
585545 .put (ClientResponse .class , template );
0 commit comments