public void synchronizeTokens ( Endpoint tokenEndPoint ) { Integer subscriptionId = tokenEndPoint . getSubscriptionId ( ) ; String partnerAuthorizationToken = tokenEndPoint . getSubscription ( ) . getPartnerAuthorizationToken ( ) ; String lastSyncDate = getLastSyncDate ( subscriptionId ) ; int totalCount = 1 ; int numberRetrieved = 0 ; Date startOfSync = new Date ( ) ; while ( totalCount > numberRetrieved ) { String tokenUrl = tokenEndPoint . getUrl ( ) ; tokenUrl += "?offset=" + numberRetrieved + "&limit=" + PAGE_SIZE ; if ( lastSyncDate != null ) { tokenUrl += "&date_from=" + lastSyncDate ; } LOG . info ( "Get tokens at endpoint: " + tokenUrl ) ; TokenResponse tokenResponse = ( TokenResponse ) doRequest ( new HttpGet ( tokenUrl ) , partnerAuthorizationToken , TokenResponse . class ) ; if ( tokenResponse . totalCount == null ) { break ; } totalCount = tokenResponse . totalCount ; numberRetrieved += tokenResponse . data . size ( ) ; LOG . info ( "Inserting " + tokenResponse . data . size ( ) + " tokens" ) ; for ( io . motown . ocpi . dto . Token token : tokenResponse . data ) { insertOrUpdateToken ( token , subscriptionId ) ; } } updateLastSynchronizationDate ( startOfSync , subscriptionId ) ; LOG . info ( "Number of tokens retrieved: " + numberRetrieved ) ; }
Retrieves tokens from the enpoint passed as argument and stores these in the database