508 : sonar qube critical issue fixes (#852)
* 508 : sonar qube critical issue fixes * 508 : Sunar Qube Fixes Define a constant instead of duplicating this literal "user_accounts" 4 times. Define a constant instead of duplicating this literal "userID" 5 times Define a constant instead of duplicating this literal "additionalInfo" 4 times. Define a constant instead of duplicating this literal "userName" 4 times. * 508 : Sunar Qube Fixes Define a constant instead of duplicating this literal "user_accounts" 4 times. * 508 : Sonar Qube Fixes Define a constant instead of duplicating this literal "eEvans" 4 times Define a constant instead of duplicating this literal "jBloch" 6 times Define a constant instead of duplicating this literal "mFowler" 3 times * 508 : Sonar Qube FIxes Define a constant instead of duplicating this literal "username" 3 times. * 508: sonar qube issue fixes Define a constant instead of duplicating this literal "customerDao.getAllCustomers(): " 4 times. * 508 : sonar qube issue fixes Define a constant instead of duplicating this literal "App.main(), student : " 4 times. * 508 : sonar Qube issue fixes Define a constant instead of duplicating this literal "{} hits {}. {} is damaged!" 3 times. Define a constant instead of duplicating this literal "{} hits {}." 4 times. * 508 : Define a constant instead of duplicating this literal "{} hits {}." 4 times. * 508 : checkstyle fixes * 508: checkstyle fixes * 508: checkstyle fixes * 508: checkstyle fixes * 508: checkstyle fixes * 508: checkstyle fixes * 508: cqrs checkstyle fixes
This commit is contained in:
committed by
Ilkka Seppälä
parent
17bfc91f45
commit
c6ecf58687
@ -28,6 +28,7 @@ import java.util.Map;
|
||||
|
||||
import org.bson.Document;
|
||||
|
||||
import com.iluwatar.caching.constants.CachingConstants;
|
||||
import com.mongodb.MongoClient;
|
||||
import com.mongodb.client.FindIterable;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
@ -90,12 +91,12 @@ public final class DbManager {
|
||||
}
|
||||
}
|
||||
FindIterable<Document> iterable =
|
||||
db.getCollection("user_accounts").find(new Document("userID", userId));
|
||||
db.getCollection(CachingConstants.USER_ACCOUNT).find(new Document(CachingConstants.USER_ID, userId));
|
||||
if (iterable == null) {
|
||||
return null;
|
||||
}
|
||||
Document doc = iterable.first();
|
||||
return new UserAccount(userId, doc.getString("userName"), doc.getString("additionalInfo"));
|
||||
return new UserAccount(userId, doc.getString(CachingConstants.USER_NAME), doc.getString(CachingConstants.ADD_INFO));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -113,9 +114,9 @@ public final class DbManager {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
db.getCollection("user_accounts").insertOne(
|
||||
new Document("userID", userAccount.getUserId()).append("userName",
|
||||
userAccount.getUserName()).append("additionalInfo", userAccount.getAdditionalInfo()));
|
||||
db.getCollection(CachingConstants.USER_ACCOUNT).insertOne(
|
||||
new Document(CachingConstants.USER_ID ,userAccount.getUserId()).append(CachingConstants.USER_NAME,
|
||||
userAccount.getUserName()).append(CachingConstants.ADD_INFO, userAccount.getAdditionalInfo()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -133,10 +134,10 @@ public final class DbManager {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
db.getCollection("user_accounts").updateOne(
|
||||
new Document("userID", userAccount.getUserId()),
|
||||
new Document("$set", new Document("userName", userAccount.getUserName()).append(
|
||||
"additionalInfo", userAccount.getAdditionalInfo())));
|
||||
db.getCollection(CachingConstants.USER_ACCOUNT).updateOne(
|
||||
new Document(CachingConstants.USER_ID, userAccount.getUserId()),
|
||||
new Document("$set", new Document(CachingConstants.USER_NAME, userAccount.getUserName())
|
||||
.append(CachingConstants.ADD_INFO, userAccount.getAdditionalInfo())));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -155,10 +156,12 @@ public final class DbManager {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
db.getCollection("user_accounts").updateOne(
|
||||
new Document("userID", userAccount.getUserId()),
|
||||
new Document("$set", new Document("userID", userAccount.getUserId()).append("userName",
|
||||
userAccount.getUserName()).append("additionalInfo", userAccount.getAdditionalInfo())),
|
||||
db.getCollection(CachingConstants.USER_ACCOUNT).updateOne(
|
||||
new Document(CachingConstants.USER_ID, userAccount.getUserId()),
|
||||
new Document("$set",
|
||||
new Document(CachingConstants.USER_ID, userAccount.getUserId())
|
||||
.append(CachingConstants.USER_NAME, userAccount.getUserName()).append(CachingConstants.ADD_INFO,
|
||||
userAccount.getAdditionalInfo())),
|
||||
new UpdateOptions().upsert(true));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
package com.iluwatar.caching.constants;
|
||||
|
||||
/**
|
||||
*
|
||||
* Constant class for defining constants
|
||||
*
|
||||
*/
|
||||
public class CachingConstants {
|
||||
|
||||
public static final String USER_ACCOUNT = "user_accounts";
|
||||
public static final String USER_ID = "userID";
|
||||
public static final String USER_NAME = "userName";
|
||||
public static final String ADD_INFO = "additionalInfo";
|
||||
|
||||
}
|
Reference in New Issue
Block a user