Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrescobar2010-07-23 00:50:15 +0000
committerrescobar2010-07-23 00:50:15 +0000
commit50de6714dab8f2cc5a98acfb031c5cf1caee1495 (patch)
tree05c3184fe59c7b1fea82b3d5fc53b8709f2cc513 /plugins
parent63103fa019ff7ab9faca3814dd39fa06d50e4d48 (diff)
downloadorg.eclipse.osee-50de6714dab8f2cc5a98acfb031c5cf1caee1495.tar.gz
org.eclipse.osee-50de6714dab8f2cc5a98acfb031c5cf1caee1495.tar.xz
org.eclipse.osee-50de6714dab8f2cc5a98acfb031c5cf1caee1495.zip
DbInit fix regarding CommonBranch null while attempting to get User before branch is created
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.osee.framework.database.init/src/org/eclipse/osee/framework/database/init/DbBootstrapTask.java4
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/UserManager.java492
2 files changed, 249 insertions, 247 deletions
diff --git a/plugins/org.eclipse.osee.framework.database.init/src/org/eclipse/osee/framework/database/init/DbBootstrapTask.java b/plugins/org.eclipse.osee.framework.database.init/src/org/eclipse/osee/framework/database/init/DbBootstrapTask.java
index 5662cdf67d1..6f6cef90274 100644
--- a/plugins/org.eclipse.osee.framework.database.init/src/org/eclipse/osee/framework/database/init/DbBootstrapTask.java
+++ b/plugins/org.eclipse.osee.framework.database.init/src/org/eclipse/osee/framework/database/init/DbBootstrapTask.java
@@ -24,6 +24,7 @@ import org.eclipse.osee.framework.core.enums.CoreTranslatorId;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.exception.OseeStateException;
import org.eclipse.osee.framework.core.message.DatastoreInitRequest;
+import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.core.translation.IDataTranslationService;
import org.eclipse.osee.framework.core.util.Conditions;
import org.eclipse.osee.framework.core.util.HttpMessage;
@@ -49,7 +50,8 @@ public class DbBootstrapTask implements IDbInitializationTask {
DbUtil.setDbInit(true);
createOseeDatastore();
- BranchManager.getSystemRootBranch();
+ Branch systemRoot = BranchManager.getSystemRootBranch();
+ Conditions.checkNotNull(systemRoot, "System root was not created - ");
ClientSessionManager.authenticate(new BaseCredentialProvider() {
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/UserManager.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/UserManager.java
index b2e67138890..082c232bd2f 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/UserManager.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/UserManager.java
@@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.osee.framework.skynet.core;
-import static org.eclipse.osee.framework.skynet.core.artifact.DeletionFlag.EXCLUDE_DELETED;
+import static org.eclipse.osee.framework.skynet.core.artifact.DeletionFlag.EXCLUDE_DELETED;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -42,250 +42,250 @@ import org.eclipse.osee.framework.skynet.core.utility.DbUtil;
*/
public final class UserManager {
- private static final String CACHE_PREFIX = "userManager.";
- private static boolean userCacheIsLoaded = false;
- private static boolean duringMainUserCreation = false;
-
- private UserManager() {
-
- }
-
- /**
- * Returns the currently authenticated user
- *
- * @return User
- * @throws OseeCoreException
- */
- public static User getUser() throws OseeCoreException {
- if (duringMainUserCreation) {
- return BootStrapUser.getInstance();
- }
- return ClientUser.getMainUser();
- }
-
- /**
- * @return shallow copy of ArrayList of all active users in the datastore sorted by user name
- */
- public static List<User> getUsers() throws OseeCoreException {
- List<User> allUsers = getFromCache();
- List<User> activeUsers = new ArrayList<User>(allUsers.size());
- for (User user : allUsers) {
- if (user.isActive()) {
- activeUsers.add(user);
- }
- }
- return activeUsers;
- }
-
- public static List<User> getUsersAll() throws OseeCoreException {
- return getFromCache();
- }
-
- public static List<User> getUsersSortedByName() throws OseeCoreException {
- List<User> users = getUsers();
- Collections.sort(users);
- return users;
- }
-
- public static List<User> getUsersAllSortedByName() throws OseeCoreException {
- List<User> users = getFromCache();
- Collections.sort(users);
- return users;
- }
-
- private static List<User> getFromCache() throws OseeCoreException {
- ensurePopulated();
- return org.eclipse.osee.framework.jdk.core.util.Collections.castAll(ArtifactCache.getArtifactsByType(CoreArtifactTypes.User));
- }
-
- /**
- * Return sorted list of active User.getName() in database
- *
- * @return String[]
- */
- public static String[] getUserNames() throws OseeCoreException {
- List<User> allUsers = getFromCache();
- String[] userNames = new String[allUsers.size()];
- int index = 0;
- for (User user : allUsers) {
- userNames[index++] = user.getName();
- }
- return userNames;
- }
-
- public static String getUserNameById(int userArtifactId) {
- String name;
- try {
- User user = null;
- if (userArtifactId == 0) {
- user = UserManager.getUser(SystemUser.OseeSystem);
- userArtifactId = user.getArtId();
- } else {
- user = UserManager.getUserByArtId(userArtifactId);
- }
- name = user.getName();
- } catch (Exception ex) {
- name = "Could not resolve artId: " + userArtifactId;
- OseeLog.log(Activator.class, Level.SEVERE, ex);
- }
- return name;
- }
-
- public static User getUserByArtId(int userArtifactId) throws OseeCoreException {
- ensurePopulated();
- User user = (User) ArtifactCache.getActive(userArtifactId, BranchManager.getCommonBranch());
- if (user == null) {
- throw new UserNotInDatabase("User requested by artId \"" + userArtifactId + "\" was not found.");
- }
- return user;
- }
-
- public static boolean userExistsWithName(String name) throws OseeCoreException {
- for (User tempUser : getFromCache()) {
- if (tempUser.getName().equals(name)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * This is not the preferred way to get a user. Most likely getUserByUserId() or getUserByArtId() should be used
- *
- * @param name
- * @return the first user found with the given name
- * @throws OseeCoreException
- */
- public static User getUserByName(String name) throws OseeCoreException {
- for (User tempUser : getFromCache()) {
- if (tempUser.getName().equals(name)) {
- return tempUser;
- }
- }
- throw new UserNotInDatabase("User requested by name \"" + name + "\" was not found.");
- }
-
- private static User getFromCacheByUserId(String userId) throws OseeCoreException {
- return (User) ArtifactCache.getByTextId(CACHE_PREFIX + userId, BranchManager.getCommonBranch());
- }
-
- private static User cacheByUserId(User userToCache) throws OseeCoreException {
- return (User) ArtifactCache.cacheByTextId(CACHE_PREFIX + userToCache.getUserId(), userToCache);
- }
-
- public static User getUserByUserId(String userId) throws OseeCoreException {
- if (!Strings.isValid(userId)) {
- throw new OseeArgumentException("UserId can't be null or \"\"");
- }
-
- ensurePopulated();
- User user = getFromCacheByUserId(userId);
- if (user == null) {
- try {
- user = (User) ArtifactQuery.getArtifactFromAttribute("User Id", userId, BranchManager.getCommonBranch());
- } catch (ArtifactDoesNotExist ex) {
- throw new UserNotInDatabase(String.format("The user with id [%s] was not found.", userId));
- }
- }
- return user;
- }
-
- public static User getUser(IOseeUser userEnum) throws OseeCoreException {
- return getUserByUserId(userEnum.getUserID());
- }
-
- private static synchronized void ensurePopulated() throws OseeCoreException {
- if (!userCacheIsLoaded) {
- List<Artifact> artifactsFound =
- ArtifactQuery.getArtifactListFromType(CoreArtifactTypes.User, CoreBranches.COMMON, EXCLUDE_DELETED);
- for (Artifact artifact : artifactsFound) {
- User user = (User) artifact;
- User cachedUser = cacheByUserId(user);
- if (cachedUser != null) { // if duplicate user id found
- OseeCoreException ex =
- new UserInDatabaseMultipleTimes(
- "User of userId \"" + user.getUserId() + "\" in datastore more than once");
-
- // exception if I am the duplicate user otherwise just log
- if (user.getUserId().equals(ClientSessionManager.getSession().getId())) {
- throw ex;
- } else {
- OseeLog.log(Activator.class, Level.WARNING, ex);
- }
- }
- }
- userCacheIsLoaded = true;
- }
- }
-
- /**
- * @return whether the Authentication manager is in the middle of creating a user
- */
- public static boolean duringMainUserCreation() {
- return duringMainUserCreation;
- }
-
- public static synchronized User createMainUser(IOseeUser userEnum, SkynetTransaction transaction) throws OseeCoreException {
- duringMainUserCreation = true;
- User user = createUser(userEnum, transaction);
- duringMainUserCreation = false;
- return user;
- }
-
- public static synchronized User createUser(IOseeUser userEnum, SkynetTransaction transaction) throws OseeCoreException {
- ensurePopulated();
- // Determine if user with id has already been created; boot strap issue with dbInit
- User user = getFromCacheByUserId(userEnum.getUserID());
- if (user != null) {
- // Update user with this enum data
- user.setName(userEnum.getName());
- user.setEmail(userEnum.getEmail());
- user.setActive(userEnum.isActive());
- } else {
- user =
- (User) ArtifactTypeManager.addArtifact(CoreArtifactTypes.User.getName(),
- BranchManager.getCommonBranch(), userEnum.getName());
- user.setActive(userEnum.isActive());
- user.setUserID(userEnum.getUserID());
- user.setEmail(userEnum.getEmail());
- cacheByUserId(user);
-
- // this is here in case a user is created at an unexpected time
- if (!DbUtil.isDbInit()) {
- OseeLog.log(Activator.class, Level.INFO, "Created user " + user, new Exception(
- "just wanted the stack trace"));
- }
- }
-
- user.persist(transaction);
- return user;
- }
-
- public static boolean isUserInactive(Collection<User> users) throws OseeCoreException {
- for (User user : users) {
- if (!user.isActive()) {
- return true;
- }
- }
- return false;
- }
-
- public static boolean isUserSystem(Collection<User> users) throws OseeCoreException {
- for (User user : users) {
- if (user.isSystemUser()) {
- return true;
- }
- }
- return false;
- }
-
- public static boolean isUserCurrentUser(Collection<User> users) throws OseeCoreException {
- for (User user : users) {
- if (user.equals(UserManager.getUser())) {
- return true;
- }
- }
- return false;
- }
+ private static final String CACHE_PREFIX = "userManager.";
+ private static boolean userCacheIsLoaded = false;
+ private static boolean duringMainUserCreation = false;
+
+ private UserManager() {
+
+ }
+
+ /**
+ * Returns the currently authenticated user
+ *
+ * @return User
+ * @throws OseeCoreException
+ */
+ public static User getUser() throws OseeCoreException {
+ if (duringMainUserCreation || (DbUtil.isDbInit() && !BranchManager.branchExists(CoreBranches.COMMON))) {
+ return BootStrapUser.getInstance();
+ }
+ return ClientUser.getMainUser();
+ }
+
+ /**
+ * @return shallow copy of ArrayList of all active users in the datastore sorted by user name
+ */
+ public static List<User> getUsers() throws OseeCoreException {
+ List<User> allUsers = getFromCache();
+ List<User> activeUsers = new ArrayList<User>(allUsers.size());
+ for (User user : allUsers) {
+ if (user.isActive()) {
+ activeUsers.add(user);
+ }
+ }
+ return activeUsers;
+ }
+
+ public static List<User> getUsersAll() throws OseeCoreException {
+ return getFromCache();
+ }
+
+ public static List<User> getUsersSortedByName() throws OseeCoreException {
+ List<User> users = getUsers();
+ Collections.sort(users);
+ return users;
+ }
+
+ public static List<User> getUsersAllSortedByName() throws OseeCoreException {
+ List<User> users = getFromCache();
+ Collections.sort(users);
+ return users;
+ }
+
+ private static List<User> getFromCache() throws OseeCoreException {
+ ensurePopulated();
+ return org.eclipse.osee.framework.jdk.core.util.Collections.castAll(ArtifactCache.getArtifactsByType(CoreArtifactTypes.User));
+ }
+
+ /**
+ * Return sorted list of active User.getName() in database
+ *
+ * @return String[]
+ */
+ public static String[] getUserNames() throws OseeCoreException {
+ List<User> allUsers = getFromCache();
+ String[] userNames = new String[allUsers.size()];
+ int index = 0;
+ for (User user : allUsers) {
+ userNames[index++] = user.getName();
+ }
+ return userNames;
+ }
+
+ public static String getUserNameById(int userArtifactId) {
+ String name;
+ try {
+ User user = null;
+ if (userArtifactId == 0) {
+ user = UserManager.getUser(SystemUser.OseeSystem);
+ userArtifactId = user.getArtId();
+ } else {
+ user = UserManager.getUserByArtId(userArtifactId);
+ }
+ name = user.getName();
+ } catch (Exception ex) {
+ name = "Could not resolve artId: " + userArtifactId;
+ OseeLog.log(Activator.class, Level.SEVERE, ex);
+ }
+ return name;
+ }
+
+ public static User getUserByArtId(int userArtifactId) throws OseeCoreException {
+ ensurePopulated();
+ User user = (User) ArtifactCache.getActive(userArtifactId, BranchManager.getCommonBranch());
+ if (user == null) {
+ throw new UserNotInDatabase("User requested by artId \"" + userArtifactId + "\" was not found.");
+ }
+ return user;
+ }
+
+ public static boolean userExistsWithName(String name) throws OseeCoreException {
+ for (User tempUser : getFromCache()) {
+ if (tempUser.getName().equals(name)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * This is not the preferred way to get a user. Most likely getUserByUserId() or getUserByArtId() should be used
+ *
+ * @param name
+ * @return the first user found with the given name
+ * @throws OseeCoreException
+ */
+ public static User getUserByName(String name) throws OseeCoreException {
+ for (User tempUser : getFromCache()) {
+ if (tempUser.getName().equals(name)) {
+ return tempUser;
+ }
+ }
+ throw new UserNotInDatabase("User requested by name \"" + name + "\" was not found.");
+ }
+
+ private static User getFromCacheByUserId(String userId) throws OseeCoreException {
+ return (User) ArtifactCache.getByTextId(CACHE_PREFIX + userId, BranchManager.getCommonBranch());
+ }
+
+ private static User cacheByUserId(User userToCache) throws OseeCoreException {
+ return (User) ArtifactCache.cacheByTextId(CACHE_PREFIX + userToCache.getUserId(), userToCache);
+ }
+
+ public static User getUserByUserId(String userId) throws OseeCoreException {
+ if (!Strings.isValid(userId)) {
+ throw new OseeArgumentException("UserId can't be null or \"\"");
+ }
+
+ ensurePopulated();
+ User user = getFromCacheByUserId(userId);
+ if (user == null) {
+ try {
+ user = (User) ArtifactQuery.getArtifactFromAttribute("User Id", userId, BranchManager.getCommonBranch());
+ } catch (ArtifactDoesNotExist ex) {
+ throw new UserNotInDatabase(String.format("The user with id [%s] was not found.", userId));
+ }
+ }
+ return user;
+ }
+
+ public static User getUser(IOseeUser userEnum) throws OseeCoreException {
+ return getUserByUserId(userEnum.getUserID());
+ }
+
+ private static synchronized void ensurePopulated() throws OseeCoreException {
+ if (!userCacheIsLoaded) {
+ List<Artifact> artifactsFound =
+ ArtifactQuery.getArtifactListFromType(CoreArtifactTypes.User, CoreBranches.COMMON, EXCLUDE_DELETED);
+ for (Artifact artifact : artifactsFound) {
+ User user = (User) artifact;
+ User cachedUser = cacheByUserId(user);
+ if (cachedUser != null) { // if duplicate user id found
+ OseeCoreException ex =
+ new UserInDatabaseMultipleTimes(
+ "User of userId \"" + user.getUserId() + "\" in datastore more than once");
+
+ // exception if I am the duplicate user otherwise just log
+ if (user.getUserId().equals(ClientSessionManager.getSession().getId())) {
+ throw ex;
+ } else {
+ OseeLog.log(Activator.class, Level.WARNING, ex);
+ }
+ }
+ }
+ userCacheIsLoaded = true;
+ }
+ }
+
+ /**
+ * @return whether the Authentication manager is in the middle of creating a user
+ */
+ public static boolean duringMainUserCreation() {
+ return duringMainUserCreation;
+ }
+
+ public static synchronized User createMainUser(IOseeUser userEnum, SkynetTransaction transaction) throws OseeCoreException {
+ duringMainUserCreation = true;
+ User user = createUser(userEnum, transaction);
+ duringMainUserCreation = false;
+ return user;
+ }
+
+ public static synchronized User createUser(IOseeUser userEnum, SkynetTransaction transaction) throws OseeCoreException {
+ ensurePopulated();
+ // Determine if user with id has already been created; boot strap issue with dbInit
+ User user = getFromCacheByUserId(userEnum.getUserID());
+ if (user != null) {
+ // Update user with this enum data
+ user.setName(userEnum.getName());
+ user.setEmail(userEnum.getEmail());
+ user.setActive(userEnum.isActive());
+ } else {
+ user =
+ (User) ArtifactTypeManager.addArtifact(CoreArtifactTypes.User.getName(),
+ BranchManager.getCommonBranch(), userEnum.getName());
+ user.setActive(userEnum.isActive());
+ user.setUserID(userEnum.getUserID());
+ user.setEmail(userEnum.getEmail());
+ cacheByUserId(user);
+
+ // this is here in case a user is created at an unexpected time
+ if (!DbUtil.isDbInit()) {
+ OseeLog.log(Activator.class, Level.INFO, "Created user " + user, new Exception(
+ "just wanted the stack trace"));
+ }
+ }
+
+ user.persist(transaction);
+ return user;
+ }
+
+ public static boolean isUserInactive(Collection<User> users) throws OseeCoreException {
+ for (User user : users) {
+ if (!user.isActive()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static boolean isUserSystem(Collection<User> users) throws OseeCoreException {
+ for (User user : users) {
+ if (user.isSystemUser()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static boolean isUserCurrentUser(Collection<User> users) throws OseeCoreException {
+ for (User user : users) {
+ if (user.equals(UserManager.getUser())) {
+ return true;
+ }
+ }
+ return false;
+ }
} \ No newline at end of file

Back to the top