Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6c775f1ead75b9fed35ba46b6dfa423cf670b1c6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.core.server;

import java.util.logging.Level;
import org.eclipse.osee.framework.core.data.IUserToken;
import org.eclipse.osee.framework.core.data.TokenFactory;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.enums.CoreBranches;
import org.eclipse.osee.framework.core.enums.TxChange;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.server.internal.ServerActivator;
import org.eclipse.osee.framework.core.server.internal.ServiceProvider;
import org.eclipse.osee.framework.core.services.IOseeCachingService;
import org.eclipse.osee.framework.database.core.ConnectionHandler;
import org.eclipse.osee.framework.database.core.IOseeStatement;
import org.eclipse.osee.framework.logging.OseeLog;

/**
 * @author Roberto E. Escobar
 */
public final class UserDataStore {
   private static final String LOAD_OSEE_USER =
      "select att.value as user_id from osee_attribute att, osee_txs txs where att.attr_type_id = ? and txs.branch_id = ? and att.gamma_id = txs.gamma_id and txs.tx_current = ? and att.value = ?";

   private UserDataStore() {
      // private constructor
   }

   public static IUserToken getUserTokenFromOseeDb(String userId) {
      IUserToken toReturn = null;
      IOseeStatement chStmt = null;
      IOseeCachingService cachingService = ServiceProvider.getCachingService();
      try {
         int attributeTypeId = cachingService.getAttributeTypeCache().getLocalId(CoreAttributeTypes.UserId);
         int branchId = cachingService.getBranchCache().get(CoreBranches.COMMON).getId();

         chStmt = ConnectionHandler.getStatement();
         chStmt.runPreparedQuery(LOAD_OSEE_USER, attributeTypeId, branchId, TxChange.CURRENT.getValue(), userId);
         if (chStmt.next()) {
            // Only need the userId all other fields will be loaded by the client
            toReturn = TokenFactory.createUserToken(null, "-", "-", chStmt.getString("user_id"), true, false, false);
         }
      } catch (OseeCoreException ex) {
         OseeLog.logf(ServerActivator.class, Level.SEVERE, ex, "Unable to find userId [%s] in OSEE database.", userId);
      } finally {
         chStmt.close();
      }
      return toReturn;
   }

   public static IUserToken createUserToken(boolean isCreationRequired, String userName, String userId, String userEmail, boolean isActive) {
      return TokenFactory.createUserToken(null, userName, userEmail, userId, isActive, false, isCreationRequired);
   }

}

Back to the top