2121package password .pwm .svc .version ;
2222
2323import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
24+ import lombok .AccessLevel ;
2425import lombok .Builder ;
2526import lombok .Value ;
2627import password .pwm .AppAttribute ;
5354import password .pwm .util .java .TimeDuration ;
5455import password .pwm .util .localdb .LocalDB ;
5556import password .pwm .util .logging .PwmLogger ;
56- import password .pwm .ws .server .RestResultBean ;
5757
5858import java .io .Serializable ;
5959import java .lang .reflect .ParameterizedType ;
@@ -161,6 +161,10 @@ private void scheduleNextCheck()
161161 return ;
162162 }
163163
164+ this .nextScheduledCheck = Instant .now ().plus ( 1 , ChronoUnit .MINUTES );
165+ executorService .schedule ( new PeriodicCheck (), 1 , TimeUnit .MINUTES );
166+
167+ /*
164168 final VersionCheckInfoCache localCache = cacheHolder.getVersionCheckInfoCache();
165169
166170 final TimeDuration idealDurationUntilNextCheck = localCache.getLastError() != null && localCache.getCurrentVersion() == null
@@ -185,6 +189,8 @@ private void scheduleNextCheck()
185189
186190 LOGGER.trace( SessionLabel.VERSIONCHECK_SESSION_LABEL, () -> "scheduled next check execution at " + JavaHelper.toIsoDate( nextScheduledCheck )
187191 + " in " + delayUntilNextExecution.asCompactString() );
192+
193+ */
188194 }
189195
190196 private class PeriodicCheck implements Runnable
@@ -247,16 +253,17 @@ private PublishVersionBean executeFetch()
247253
248254 if ( response .getStatusCode () == 200 )
249255 {
250- final Type restResultBeanType = newParameterizedType ( RestResultBean .class , PublishVersionBean .class );
256+ final Type restResultBeanType = newParameterizedType ( RestObjectBean .class , PublishVersionBean .class );
251257
252258 final String body = response .getBody ();
253- final RestResultBean restResultBean = JsonUtil .deserialize ( body , restResultBeanType );
254- return ( PublishVersionBean ) restResultBean .getData ();
259+ final RestObjectBean < PublishVersionBean > restResultBean = JsonUtil .deserialize ( body , restResultBeanType );
260+ return restResultBean .getData ();
255261 }
256262 else
257263 {
258264 LOGGER .debug ( SessionLabel .VERSIONCHECK_SESSION_LABEL , () -> "error reading cloud current version information: " + response );
259- final String msg = "error reading cloud current version information: " + response .getStatusCode () + " " + response .getStatusPhrase ();
265+ final String msg = "error reading cloud current version information: " + response .getStatusCode ()
266+ + " " + ( response .getStatusPhrase () == null ? "" : response .getStatusPhrase () );
260267 throw PwmUnrecoverableException .newException ( PwmError .ERROR_UNREACHABLE_CLOUD_SERVICE , msg );
261268 }
262269 }
@@ -444,4 +451,29 @@ public Type getOwnerType()
444451 }
445452 };
446453 }
454+
455+ @ Value
456+ @ Builder ( toBuilder = true , access = AccessLevel .PACKAGE )
457+ private static class RestObjectBean <T > implements Serializable
458+ {
459+ private static final long serialVersionUID = 1L ;
460+
461+ private final T data ;
462+ private final boolean error ;
463+ private final int errorCode ;
464+ private final String errorMessage ;
465+ private final String errorDetail ;
466+ private final String successMessage ;
467+
468+ @ SuppressFBWarnings ( "SE_TRANSIENT_FIELD_NOT_RESTORED" )
469+ private final transient Class <T > classOfT ;
470+
471+ public static <T > RestObjectBean <T > withData ( final T data , final Class <T > classOfT )
472+ {
473+ return RestObjectBean .<T >builder ()
474+ .data ( data )
475+ .classOfT ( classOfT )
476+ .build ();
477+ }
478+ }
447479}
0 commit comments