Skip to content

Conversation

@mariusmarin-dev
Copy link

No description provided.

# 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={}, " +

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={}, " +

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);

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);

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 {} - " +

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={}, " +

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);

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);

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",

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",

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") ||

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") ||

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 {}. " +

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;

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={}",

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());

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());

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());

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() ||

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",

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") ||

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, "

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;

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();

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.coding.VariableDeclarationUsageDistanceCheck> reported by reviewdog 🐶
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).

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
5.9% Duplication on New Code (required ≤ 3%)
E Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

// 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

This calls 'Thread.sleep()' with a lock held.
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

This calls 'Thread.sleep()' with a lock held.
*/
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

The variable 'userId' is only assigned values of primitive type and is never 'null', but it is declared with the boxed type 'Long'.

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.

Suggested changeset 1
src/main/java/uk/ac/cam/cl/dtg/segue/dao/users/PgExternalAccountPersistenceManager.java

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/main/java/uk/ac/cam/cl/dtg/segue/dao/users/PgExternalAccountPersistenceManager.java b/src/main/java/uk/ac/cam/cl/dtg/segue/dao/users/PgExternalAccountPersistenceManager.java
--- a/src/main/java/uk/ac/cam/cl/dtg/segue/dao/users/PgExternalAccountPersistenceManager.java
+++ b/src/main/java/uk/ac/cam/cl/dtg/segue/dao/users/PgExternalAccountPersistenceManager.java
@@ -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
EOF
@@ -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
Copilot is powered by AI and may make mistakes. Always verify output.
throws SegueDatabaseException, MailjetException {

Long userId = userRecord.getUserId();
String accountEmail = userRecord.getAccountEmail();

Check notice

Code scanning / CodeQL

Unread local variable Note

Variable 'String accountEmail' is never read.

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.

Suggested changeset 1
src/main/java/uk/ac/cam/cl/dtg/segue/api/managers/ExternalAccountManager.java

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/main/java/uk/ac/cam/cl/dtg/segue/api/managers/ExternalAccountManager.java b/src/main/java/uk/ac/cam/cl/dtg/segue/api/managers/ExternalAccountManager.java
--- a/src/main/java/uk/ac/cam/cl/dtg/segue/api/managers/ExternalAccountManager.java
+++ b/src/main/java/uk/ac/cam/cl/dtg/segue/api/managers/ExternalAccountManager.java
@@ -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();
EOF
@@ -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();
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
Comment on lines +182 to +183
boolean accountEmailDeliveryFailed =
EmailVerificationStatus.DELIVERY_FAILED.equals(userRecord.getEmailVerificationStatus());

Check notice

Code scanning / CodeQL

Unread local variable Note

Variable 'boolean accountEmailDeliveryFailed' is never read.

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.


Suggested changeset 1
src/main/java/uk/ac/cam/cl/dtg/segue/api/managers/ExternalAccountManager.java

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/main/java/uk/ac/cam/cl/dtg/segue/api/managers/ExternalAccountManager.java b/src/main/java/uk/ac/cam/cl/dtg/segue/api/managers/ExternalAccountManager.java
--- a/src/main/java/uk/ac/cam/cl/dtg/segue/api/managers/ExternalAccountManager.java
+++ b/src/main/java/uk/ac/cam/cl/dtg/segue/api/managers/ExternalAccountManager.java
@@ -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
EOF
@@ -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
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants