-
Notifications
You must be signed in to change notification settings - Fork 1
Mailjet patch 1 #394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Mailjet patch 1 #394
Conversation
# Conflicts: # src/main/java/uk/ac/cam/cl/dtg/isaac/api/EventsFacade.java # src/main/java/uk/ac/cam/cl/dtg/isaac/api/managers/EventBookingManager.java # src/main/java/uk/ac/cam/cl/dtg/isaac/dos/eventbookings/PgEventBooking.java # src/main/java/uk/ac/cam/cl/dtg/isaac/dos/eventbookings/PgEventBookings.java # src/main/java/uk/ac/cam/cl/dtg/isaac/dto/eventbookings/ProjectTitlesResponseDTO.java
| String accountEmail = userRecord.getAccountEmail(); | ||
|
|
||
| log.info("MMAILJETT - [User {}] Starting sync for email: {}", userId, sanitiseEmailForLogging(accountEmail)); | ||
| log.debug("MMAILJETT - [User {}] Full user record: deleted={}, emailVerificationStatus={}, providerUserId={}, " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 120 characters (found 121).
| String accountEmail = userRecord.getAccountEmail(); | ||
|
|
||
| log.info("MMAILJETT - [User {}] Starting sync for email: {}", userId, sanitiseEmailForLogging(accountEmail)); | ||
| log.debug("MMAILJETT - [User {}] Full user record: deleted={}, emailVerificationStatus={}, providerUserId={}, " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck> reported by reviewdog 🐶
'+' should be on a new line.
| } catch (SegueDatabaseException e) { | ||
| log.error(String.format("Error storing record of MailJet update to user (%s)!", userId)); | ||
| failedSyncs++; | ||
| log.error(String.format("MMAILJETT - [User %s] Database error during sync - will retry on next run", userId), e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 120 characters (found 123).
| mailjetId = mailjetApi.addNewUserOrGetUserIfExists(accountEmail); | ||
|
|
||
| if (mailjetId == null) { | ||
| log.error("MMAILJETT - [User {}] Failed to create Mailjet contact - addNewUserOrGetUserIfExists returned null", userId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 120 characters (found 130).
| updateSucceeded = true; | ||
| } finally { | ||
| if (!updateSucceeded) { | ||
| log.error("MMAILJETT - [User {}] Failed to update properties/subscriptions for Mailjet ID {} - " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck> reported by reviewdog 🐶
'+' should be on a new line.
| String accountEmail = userRecord.getAccountEmail(); | ||
|
|
||
| log.info("MMAILJETT - [User {}] Starting sync for email: {}", userId, sanitiseEmailForLogging(accountEmail)); | ||
| log.info("MMAILJETT - [User {}] Full user record: deleted={}, emailVerificationStatus={}, providerUserId={}, " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck> reported by reviewdog 🐶
'+' should be on a new line.
| + "WHERE (users.last_updated >= provider_last_updated OR news_prefs.last_updated >= provider_last_updated " | ||
| + " OR events_prefs.last_updated >= provider_last_updated OR provider_last_updated IS NULL)"; | ||
|
|
||
| log.info("QUERY :{}", query); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck> reported by reviewdog 🐶
'method def' child has incorrect indentation level 6, expected level should be 4.
| + "WHERE (users.last_updated >= provider_last_updated OR news_prefs.last_updated >= provider_last_updated " | ||
| + " OR events_prefs.last_updated >= provider_last_updated OR provider_last_updated IS NULL)"; | ||
|
|
||
| log.info("MMAILJETT - QUERY :{}", query); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck> reported by reviewdog 🐶
'method def' child has incorrect indentation level 6, expected level should be 4.
| } catch (MailjetException e) { | ||
| // Check if this is a 404 - contact was deleted from Mailjet but we still have the ID | ||
| if (is404Error(e)) { | ||
| log.warn("MMAILJETT - [User {}] Contact with Mailjet ID {} not found (404) during property update - clearing stale ID", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 120 characters (found 127).
| } catch (MailjetException e) { | ||
| // Check if this is a 404 - contact was deleted from Mailjet but we still have the ID | ||
| if (is404Error(e)) { | ||
| log.warn("MMAILJETT - [User {}] Contact with Mailjet ID {} not found (404) during subscription update - clearing stale ID", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 120 characters (found 131).
| } | ||
|
|
||
| // Check for 404 status code in the error message | ||
| return message.contains("\"StatusCode\" : 404") || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck> reported by reviewdog 🐶
'||' should be on a new line.
|
|
||
| // Check for 404 status code in the error message | ||
| return message.contains("\"StatusCode\" : 404") || | ||
| message.contains("\"StatusCode\": 404") || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck> reported by reviewdog 🐶
'||' should be on a new line.
| try { | ||
| // Clear the Mailjet ID from the database by setting it to null | ||
| database.updateExternalAccount(userId, null); | ||
| log.info("MMAILJETT - [User {}] Successfully cleared stale Mailjet ID {}. " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck> reported by reviewdog 🐶
'+' should be on a new line.
| import java.io.StringWriter; | ||
| import java.util.List; | ||
|
|
||
| import org.json.JSONException; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck> reported by reviewdog 🐶
Extra separation in import group before 'org.json.JSONException'
| String accountEmail = userRecord.getAccountEmail(); | ||
|
|
||
| log.debug("MAILJET - [User {}] Starting sync for email: {}", userId, sanitiseEmailForLogging(accountEmail)); | ||
| log.debug("MAILJET - [User {}] Details: deleted={}, emailStatus={}, mailjetId={}, allowsNews={}, allowsEvents={}, role={}, stage={}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 120 characters (found 141).
| } catch (SegueDatabaseException e) { | ||
| log.error(String.format("Error storing record of MailJet update to user (%s)!", userId)); | ||
| failedSyncs++; | ||
| log.error("MAILJET - [User {}] Database error during sync - will retry on next run: {}", userId, e.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 120 characters (found 123).
| log.error(e.getMessage()); | ||
| throw new ExternalAccountSynchronisationException(e.getMessage()); | ||
| failedSyncs++; | ||
| log.error("MAILJET - [User {}] Mailjet API error: {} - {}", userId, e.getClass().getSimpleName(), e.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 120 characters (found 124).
|
|
||
| } catch (Exception e) { | ||
| failedSyncs++; | ||
| log.error("MAILJET - [User {}] Unexpected error: {} - {}", userId, e.getClass().getSimpleName(), e.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 120 characters (found 123).
| */ | ||
| private boolean shouldSyncToMailjet(UserExternalAccountChanges userRecord) { | ||
| // Don't sync deleted users or users with delivery failures | ||
| if (userRecord.isDeleted() || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck> reported by reviewdog 🐶
'||' should be on a new line.
| updateSucceeded = true; | ||
| } finally { | ||
| if (!updateSucceeded) { | ||
| log.error("MAILJET - [User {}] Failed to update properties/subscriptions for Mailjet ID {} - contact exists but may have incomplete data", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 120 characters (found 146).
| String message = e.getMessage(); | ||
| return message.contains("\"StatusCode\" : 404") || | ||
| message.contains("\"StatusCode\": 404") || | ||
| message.contains("Object not found") || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck> reported by reviewdog 🐶
'||' should be on a new line.
| + " LEFT OUTER JOIN external_accounts ON users.id=external_accounts.user_id AND provider_name='MailJet' " | ||
| + "WHERE (users.last_updated >= provider_last_updated OR news_prefs.last_updated >= provider_last_updated " | ||
| + " OR events_prefs.last_updated >= provider_last_updated OR provider_last_updated IS NULL)"; | ||
| String query = "SELECT users.id, provider_user_identifier, email, role, given_name, deleted, email_verification_status, " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 120 characters (found 125).
| } | ||
|
|
||
| boolean hasGcse = false; | ||
| boolean hasALevel = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.naming.AbbreviationAsWordInNameCheck> reported by reviewdog 🐶
Abbreviation in name 'hasALevel' must contain no more than '1' consecutive capital letters.
| */ | ||
| @Override | ||
| public synchronized void synchroniseChangedUsers() throws ExternalAccountSynchronisationException { | ||
| long startTime = System.currentTimeMillis(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Distance between variable 'startTime' declaration and its first usage is 8, but allowed 3. Consider making that variable final if you still need to store its value in advance (before method calls that might have side effects on the original value).
|
| // Rate limiting: 2 second delay between each user | ||
| if (totalUsersProcessed > 1) { | ||
| try { | ||
| Thread.sleep(2000); // 2 seconds between users |
Check failure
Code scanning / CodeQL
Sleep with lock held Error
| if (totalUsersProcessed % 100 == 0) { | ||
| try { | ||
| log.info("MAILJET - Processed {} users, pausing 10 seconds to avoid rate limits", totalUsersProcessed); | ||
| Thread.sleep(10000); // 10 seconds every 100 users |
Check failure
Code scanning / CodeQL
Sleep with lock held Error
| */ | ||
| private UserExternalAccountChanges buildUserExternalAccountChanges(final ResultSet results) throws SQLException { | ||
| String registeredContextsJson = results.getString("registered_contexts"); | ||
| Long userId = results.getLong("id"); |
Check warning
Code scanning / CodeQL
Boxed variable is never null Warning
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 12 days ago
To fix the problem, we should change the type of userId from Long (the boxed type) to long (the primitive type) at its declaration in the buildUserExternalAccountChanges function (line 127).
Additionally, if downstream code (such as the constructor for UserExternalAccountChanges) requires a Long, we should either keep the boxed type at that point or explicitly box the value as needed.
However, based on the code shown, the userId value is being passed as an argument to UserExternalAccountChanges, and it would be more efficient and idiomatic to keep it as long—the Java compiler will auto-box as required for the constructor.
No additional imports or methods are needed for this fix; only the type declaration for the local variable needs to change.
-
Copy modified line R127
| @@ -124,7 +124,7 @@ | ||
| * @throws SQLException if database access fails | ||
| */ | ||
| private UserExternalAccountChanges buildUserExternalAccountChanges(final ResultSet results) throws SQLException { | ||
| Long userId = results.getLong("id"); | ||
| long userId = results.getLong("id"); | ||
|
|
||
| try { | ||
| // Extract basic fields |
| throws SegueDatabaseException, MailjetException { | ||
|
|
||
| Long userId = userRecord.getUserId(); | ||
| String accountEmail = userRecord.getAccountEmail(); |
Check notice
Code scanning / CodeQL
Unread local variable Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 12 days ago
The general fix for this kind of error is to remove the declaration and assignment of the unused local variable. In this particular instance, String accountEmail = userRecord.getAccountEmail(); on line 181 in processSingleUser is unused; it is declared and assigned, but never referenced after. To fix the error, simply delete this line. No further code changes (such as moving logic elsewhere or keeping the call for side-effects) are needed, as the getAccountEmail method almost certainly does not have side effects. No method signatures or imports need to be changed.
| @@ -178,7 +178,6 @@ | ||
| throws SegueDatabaseException, MailjetException { | ||
|
|
||
| Long userId = userRecord.getUserId(); | ||
| String accountEmail = userRecord.getAccountEmail(); | ||
| boolean accountEmailDeliveryFailed = | ||
| EmailVerificationStatus.DELIVERY_FAILED.equals(userRecord.getEmailVerificationStatus()); | ||
| String mailjetId = userRecord.getProviderUserId(); |
| boolean accountEmailDeliveryFailed = | ||
| EmailVerificationStatus.DELIVERY_FAILED.equals(userRecord.getEmailVerificationStatus()); |
Check notice
Code scanning / CodeQL
Unread local variable Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 12 days ago
The best way to fix this problem is to remove the declaration and assignment of the unused local variable accountEmailDeliveryFailed from the processSingleUser method in ExternalAccountManager.java, as it serves no purpose and its removal has no side effects. Only lines relating to the declaration of accountEmailDeliveryFailed should be touched. No additional code, imports, or definitions are necessary since its removal does not affect other logic.
| @@ -179,8 +179,6 @@ | ||
|
|
||
| Long userId = userRecord.getUserId(); | ||
| String accountEmail = userRecord.getAccountEmail(); | ||
| boolean accountEmailDeliveryFailed = | ||
| EmailVerificationStatus.DELIVERY_FAILED.equals(userRecord.getEmailVerificationStatus()); | ||
| String mailjetId = userRecord.getProviderUserId(); | ||
|
|
||
| // Validate user data before attempting sync |




No description provided.