@ -100,7 +100,7 @@ public class EnhancedDailyNotificationFetcher extends DailyNotificationFetcher {
* /
* /
public CompletableFuture < OffersResponse > fetchEndorserOffers ( String recipientDid , String afterId , String beforeId ) {
public CompletableFuture < OffersResponse > fetchEndorserOffers ( String recipientDid , String afterId , String beforeId ) {
try {
try {
Log . d ( TAG , "Fetching Endorser offers for recipient: " + recipientDid ) ;
Log . i ( TAG , "ENH|FETCH_OFFERS_TO_PERSON_START recipient= " + recipientDid ) ;
// Validate parameters
// Validate parameters
if ( recipientDid = = null | | recipientDid . isEmpty ( ) ) {
if ( recipientDid = = null | | recipientDid . isEmpty ( ) ) {
@ -113,12 +113,22 @@ public class EnhancedDailyNotificationFetcher extends DailyNotificationFetcher {
// Build URL with query parameters
// Build URL with query parameters
String url = buildOffersUrl ( recipientDid , afterId , beforeId ) ;
String url = buildOffersUrl ( recipientDid , afterId , beforeId ) ;
Log . d ( TAG , "ENH|URL_BUILD url=" + url . substring ( 0 , Math . min ( 100 , url . length ( ) ) ) + "..." ) ;
// Make authenticated request
// Make authenticated request
return makeAuthenticatedRequest ( url , OffersResponse . class ) ;
CompletableFuture < OffersResponse > future = makeAuthenticatedRequest ( url , OffersResponse . class ) ;
future . thenAccept ( response - > {
Log . i ( TAG , "ENH|FETCH_OFFERS_TO_PERSON_OK count=" + ( response ! = null & & response . data ! = null ? response . data . size ( ) : 0 ) ) ;
} ) . exceptionally ( e - > {
Log . e ( TAG , "ENH|FETCH_OFFERS_TO_PERSON_ERR err=" + e . getMessage ( ) ) ;
return null ;
} ) ;
return future ;
} catch ( Exception e ) {
} catch ( Exception e ) {
Log . e ( TAG , "Error fetching Endorser offers" , e ) ;
Log . e ( TAG , "ENH|FETCH_OFFERS_TO_PERSON_ERR err=" + e . getMessage ( ) , e ) ;
CompletableFuture < OffersResponse > errorFuture = new CompletableFuture < > ( ) ;
CompletableFuture < OffersResponse > errorFuture = new CompletableFuture < > ( ) ;
errorFuture . completeExceptionally ( e ) ;
errorFuture . completeExceptionally ( e ) ;
return errorFuture ;
return errorFuture ;
@ -135,15 +145,25 @@ public class EnhancedDailyNotificationFetcher extends DailyNotificationFetcher {
* /
* /
public CompletableFuture < OffersToPlansResponse > fetchOffersToMyPlans ( String afterId ) {
public CompletableFuture < OffersToPlansResponse > fetchOffersToMyPlans ( String afterId ) {
try {
try {
Log . d ( TAG , "Fetching offers to user's plans" ) ;
Log . i ( TAG , "ENH|FETCH_OFFERS_TO_PLANS_START afterId=" + ( afterId ! = null ? afterId . substring ( 0 , Math . min ( 20 , afterId . length ( ) ) ) : "null" ) ) ;
String url = buildOffersToPlansUrl ( afterId ) ;
String url = buildOffersToPlansUrl ( afterId ) ;
Log . d ( TAG , "ENH|URL_BUILD url=" + url . substring ( 0 , Math . min ( 100 , url . length ( ) ) ) + "..." ) ;
// Make authenticated request
// Make authenticated request
return makeAuthenticatedRequest ( url , OffersToPlansResponse . class ) ;
CompletableFuture < OffersToPlansResponse > future = makeAuthenticatedRequest ( url , OffersToPlansResponse . class ) ;
future . thenAccept ( response - > {
Log . i ( TAG , "ENH|FETCH_OFFERS_TO_PLANS_OK count=" + ( response ! = null & & response . data ! = null ? response . data . size ( ) : 0 ) ) ;
} ) . exceptionally ( e - > {
Log . e ( TAG , "ENH|FETCH_OFFERS_TO_PLANS_ERR err=" + e . getMessage ( ) ) ;
return null ;
} ) ;
return future ;
} catch ( Exception e ) {
} catch ( Exception e ) {
Log . e ( TAG , "Error fetching offers to plans" , e ) ;
Log . e ( TAG , "ENH|FETCH_OFFERS_TO_PLANS_ERR err=" + e . getMessage ( ) , e ) ;
CompletableFuture < OffersToPlansResponse > errorFuture = new CompletableFuture < > ( ) ;
CompletableFuture < OffersToPlansResponse > errorFuture = new CompletableFuture < > ( ) ;
errorFuture . completeExceptionally ( e ) ;
errorFuture . completeExceptionally ( e ) ;
return errorFuture ;
return errorFuture ;
@ -161,9 +181,10 @@ public class EnhancedDailyNotificationFetcher extends DailyNotificationFetcher {
* /
* /
public CompletableFuture < PlansLastUpdatedResponse > fetchProjectsLastUpdated ( List < String > planIds , String afterId ) {
public CompletableFuture < PlansLastUpdatedResponse > fetchProjectsLastUpdated ( List < String > planIds , String afterId ) {
try {
try {
Log . d ( TAG , "Fetching project updates for " + planIds . size ( ) + " plans" ) ;
Log . i ( TAG , "ENH|FETCH_PROJECT_UPDATES_START planCount=" + ( planIds ! = null ? planIds . size ( ) : 0 ) + " afterId=" + ( afterId ! = null ? afterId . substring ( 0 , Math . min ( 20 , afterId . length ( ) ) ) : "null" ) ) ;
String url = apiServerUrl + ENDPOINT_PLANS_UPDATED ;
String url = apiServerUrl + ENDPOINT_PLANS_UPDATED ;
Log . d ( TAG , "ENH|URL_BUILD url=" + url . substring ( 0 , Math . min ( 100 , url . length ( ) ) ) + "..." ) ;
// Create POST request body
// Create POST request body
Map < String , Object > requestBody = new HashMap < > ( ) ;
Map < String , Object > requestBody = new HashMap < > ( ) ;
@ -173,10 +194,19 @@ public class EnhancedDailyNotificationFetcher extends DailyNotificationFetcher {
}
}
// Make authenticated POST request
// Make authenticated POST request
return makeAuthenticatedPostRequest ( url , requestBody , PlansLastUpdatedResponse . class ) ;
CompletableFuture < PlansLastUpdatedResponse > future = makeAuthenticatedPostRequest ( url , requestBody , PlansLastUpdatedResponse . class ) ;
future . thenAccept ( response - > {
Log . i ( TAG , "ENH|FETCH_PROJECT_UPDATES_OK count=" + ( response ! = null & & response . data ! = null ? response . data . size ( ) : 0 ) ) ;
} ) . exceptionally ( e - > {
Log . e ( TAG , "ENH|FETCH_PROJECT_UPDATES_ERR err=" + e . getMessage ( ) ) ;
return null ;
} ) ;
return future ;
} catch ( Exception e ) {
} catch ( Exception e ) {
Log . e ( TAG , "Error fetching project updates" , e ) ;
Log . e ( TAG , "ENH|FETCH_PROJECT_UPDATES_ERR err=" + e . getMessage ( ) , e ) ;
CompletableFuture < PlansLastUpdatedResponse > errorFuture = new CompletableFuture < > ( ) ;
CompletableFuture < PlansLastUpdatedResponse > errorFuture = new CompletableFuture < > ( ) ;
errorFuture . completeExceptionally ( e ) ;
errorFuture . completeExceptionally ( e ) ;
return errorFuture ;
return errorFuture ;
@ -193,15 +223,17 @@ public class EnhancedDailyNotificationFetcher extends DailyNotificationFetcher {
* /
* /
public CompletableFuture < TimeSafariNotificationBundle > fetchAllTimeSafariData ( TimeSafariUserConfig userConfig ) {
public CompletableFuture < TimeSafariNotificationBundle > fetchAllTimeSafariData ( TimeSafariUserConfig userConfig ) {
try {
try {
Log . d ( TAG , "Starting comprehensive TimeSafari data fetch" ) ;
Log . i ( TAG , "ENH|FETCH_ALL_START activeDid=" + ( userConfig . activeDid ! = null ? userConfig . activeDid . substring ( 0 , Math . min ( 30 , userConfig . activeDid . length ( ) ) ) : "null" ) ) ;
// Validate configuration
// Validate configuration
if ( userConfig . activeDid = = null ) {
if ( userConfig . activeDid = = null ) {
Log . e ( TAG , "ENH|FETCH_ALL_ERR activeDid required" ) ;
throw new IllegalArgumentException ( "activeDid is required" ) ;
throw new IllegalArgumentException ( "activeDid is required" ) ;
}
}
// Set activeDid for authentication
// Set activeDid for authentication
jwtManager . setActiveDid ( userConfig . activeDid ) ;
jwtManager . setActiveDid ( userConfig . activeDid ) ;
Log . d ( TAG , "ENH|JWT_ENHANCE_START activeDid set for authentication" ) ;
// Create list of parallel requests
// Create list of parallel requests
List < CompletableFuture < ? > > futures = new ArrayList < > ( ) ;
List < CompletableFuture < ? > > futures = new ArrayList < > ( ) ;
@ -228,6 +260,8 @@ public class EnhancedDailyNotificationFetcher extends DailyNotificationFetcher {
futures . add ( projectUpdates ) ;
futures . add ( projectUpdates ) ;
}
}
Log . d ( TAG , "ENH|PARALLEL_REQUESTS count=" + futures . size ( ) ) ;
// Wait for all requests to complete
// Wait for all requests to complete
CompletableFuture < Void > allFutures = CompletableFuture . allOf (
CompletableFuture < Void > allFutures = CompletableFuture . allOf (
futures . toArray ( new CompletableFuture [ 0 ] )
futures . toArray ( new CompletableFuture [ 0 ] )
@ -253,11 +287,11 @@ public class EnhancedDailyNotificationFetcher extends DailyNotificationFetcher {
bundle . fetchTimestamp = System . currentTimeMillis ( ) ;
bundle . fetchTimestamp = System . currentTimeMillis ( ) ;
bundle . success = true ;
bundle . success = true ;
Log . i ( TAG , "TimeSafari data fetch completed successfully" ) ;
Log . i ( TAG , "ENH|FETCH_ALL_OK timestamp=" + bundle . fetchTimestamp ) ;
return bundle ;
return bundle ;
} catch ( Exception e ) {
} catch ( Exception e ) {
Log . e ( TAG , "Error processing TimeSafari data" , e ) ;
Log . e ( TAG , "ENH|FETCH_ALL_ERR processing err=" + e . getMessage ( ) , e ) ;
TimeSafariNotificationBundle errorBundle = new TimeSafariNotificationBundle ( ) ;
TimeSafariNotificationBundle errorBundle = new TimeSafariNotificationBundle ( ) ;
errorBundle . success = false ;
errorBundle . success = false ;
errorBundle . error = e . getMessage ( ) ;
errorBundle . error = e . getMessage ( ) ;
@ -266,7 +300,7 @@ public class EnhancedDailyNotificationFetcher extends DailyNotificationFetcher {
} ) ;
} ) ;
} catch ( Exception e ) {
} catch ( Exception e ) {
Log . e ( TAG , "Error starting TimeSafari data fetch" , e ) ;
Log . e ( TAG , "ENH|FETCH_ALL_ERR start err=" + e . getMessage ( ) , e ) ;
CompletableFuture < TimeSafariNotificationBundle > errorFuture = new CompletableFuture < > ( ) ;
CompletableFuture < TimeSafariNotificationBundle > errorFuture = new CompletableFuture < > ( ) ;
errorFuture . completeExceptionally ( e ) ;
errorFuture . completeExceptionally ( e ) ;
return errorFuture ;
return errorFuture ;
@ -320,7 +354,7 @@ public class EnhancedDailyNotificationFetcher extends DailyNotificationFetcher {
private < T > CompletableFuture < T > makeAuthenticatedRequest ( String url , Class < T > responseClass ) {
private < T > CompletableFuture < T > makeAuthenticatedRequest ( String url , Class < T > responseClass ) {
return CompletableFuture . supplyAsync ( ( ) - > {
return CompletableFuture . supplyAsync ( ( ) - > {
try {
try {
Log . d ( TAG , "Making authenticated GET request to: " + url ) ;
Log . d ( TAG , "ENH|HTTP_GET_START url=" + url . substring ( 0 , Math . min ( 100 , url . length ( ) ) ) + "..." ) ;
// Create HTTP connection
// Create HTTP connection
HttpURLConnection connection = ( HttpURLConnection ) new URL ( url ) . openConnection ( ) ;
HttpURLConnection connection = ( HttpURLConnection ) new URL ( url ) . openConnection ( ) ;
@ -330,19 +364,23 @@ public class EnhancedDailyNotificationFetcher extends DailyNotificationFetcher {
// Enhance with JWT authentication
// Enhance with JWT authentication
jwtManager . enhanceHttpClientWithJWT ( connection ) ;
jwtManager . enhanceHttpClientWithJWT ( connection ) ;
Log . d ( TAG , "ENH|JWT_ENHANCE_GET JWT authentication applied" ) ;
// Execute request
// Execute request
int responseCode = connection . getResponseCode ( ) ;
int responseCode = connection . getResponseCode ( ) ;
Log . d ( TAG , "ENH|HTTP_GET_STATUS code=" + responseCode ) ;
if ( responseCode = = 200 ) {
if ( responseCode = = 200 ) {
String responseBody = readResponseBody ( connection ) ;
String responseBody = readResponseBody ( connection ) ;
Log . d ( TAG , "ENH|HTTP_GET_OK bodySize=" + ( responseBody ! = null ? responseBody . length ( ) : 0 ) ) ;
return parseResponse ( responseBody , responseClass ) ;
return parseResponse ( responseBody , responseClass ) ;
} else {
} else {
Log . e ( TAG , "ENH|HTTP_GET_ERR code=" + responseCode ) ;
throw new IOException ( "HTTP error: " + responseCode ) ;
throw new IOException ( "HTTP error: " + responseCode ) ;
}
}
} catch ( Exception e ) {
} catch ( Exception e ) {
Log . e ( TAG , "Error in authenticated request" , e ) ;
Log . e ( TAG , "ENH|HTTP_GET_ERR exception err=" + e . getMessage ( ) , e ) ;
throw new RuntimeException ( e ) ;
throw new RuntimeException ( e ) ;
}
}
} ) ;
} ) ;
@ -359,7 +397,7 @@ public class EnhancedDailyNotificationFetcher extends DailyNotificationFetcher {
private < T > CompletableFuture < T > makeAuthenticatedPostRequest ( String url , Map < String , Object > requestBody , Class < T > responseChallass ) {
private < T > CompletableFuture < T > makeAuthenticatedPostRequest ( String url , Map < String , Object > requestBody , Class < T > responseChallass ) {
return CompletableFuture . supplyAsync ( ( ) - > {
return CompletableFuture . supplyAsync ( ( ) - > {
try {
try {
Log . d ( TAG , "Making authenticated POST request to: " + url ) ;
Log . d ( TAG , "ENH|HTTP_POST_START url=" + url . substring ( 0 , Math . min ( 100 , url . length ( ) ) ) + "..." ) ;
// Create HTTP connection
// Create HTTP connection
HttpURLConnection connection = ( HttpURLConnection ) new URL ( url ) . openConnection ( ) ;
HttpURLConnection connection = ( HttpURLConnection ) new URL ( url ) . openConnection ( ) ;
@ -371,23 +409,28 @@ public class EnhancedDailyNotificationFetcher extends DailyNotificationFetcher {
// Enhance with JWT authentication
// Enhance with JWT authentication
connection . setRequestProperty ( "Content-Type" , "application/json" ) ;
connection . setRequestProperty ( "Content-Type" , "application/json" ) ;
jwtManager . enhanceHttpClientWithJWT ( connection ) ;
jwtManager . enhanceHttpClientWithJWT ( connection ) ;
Log . d ( TAG , "ENH|JWT_ENHANCE_POST JWT authentication applied" ) ;
// Write POST body
// Write POST body
String jsonBody = mapToJson ( requestBody ) ;
String jsonBody = mapToJson ( requestBody ) ;
Log . d ( TAG , "ENH|HTTP_POST_BODY bodySize=" + jsonBody . length ( ) ) ;
connection . getOutputStream ( ) . write ( jsonBody . getBytes ( StandardCharsets . UTF_8 ) ) ;
connection . getOutputStream ( ) . write ( jsonBody . getBytes ( StandardCharsets . UTF_8 ) ) ;
// Execute request
// Execute request
int responseCode = connection . getResponseCode ( ) ;
int responseCode = connection . getResponseCode ( ) ;
Log . d ( TAG , "ENH|HTTP_POST_STATUS code=" + responseCode ) ;
if ( responseCode = = 200 ) {
if ( responseCode = = 200 ) {
String responseBody = readResponseBody ( connection ) ;
String responseBody = readResponseBody ( connection ) ;
Log . d ( TAG , "ENH|HTTP_POST_OK bodySize=" + ( responseBody ! = null ? responseBody . length ( ) : 0 ) ) ;
return parseResponse ( responseBody , responseChallass ) ;
return parseResponse ( responseBody , responseChallass ) ;
} else {
} else {
Log . e ( TAG , "ENH|HTTP_POST_ERR code=" + responseCode ) ;
throw new IOException ( "HTTP error: " + responseCode ) ;
throw new IOException ( "HTTP error: " + responseCode ) ;
}
}
} catch ( Exception e ) {
} catch ( Exception e ) {
Log . e ( TAG , "Error in authenticated POST request" , e ) ;
Log . e ( TAG , "ENH|HTTP_POST_ERR exception err=" + e . getMessage ( ) , e ) ;
throw new RuntimeException ( e ) ;
throw new RuntimeException ( e ) ;
}
}
} ) ;
} ) ;