Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7f4aab423c418764aca04e376f03ca5a76840b18 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*******************************************************************************
 * Copyright (c) 2014 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.orcs.account.admin.internal;

import org.eclipse.osee.framework.core.data.BranchId;
import org.eclipse.osee.framework.core.enums.CoreBranches;
import org.eclipse.osee.framework.core.enums.SystemUser;
import org.eclipse.osee.logger.Log;
import org.eclipse.osee.orcs.OrcsAdmin;
import org.eclipse.osee.orcs.OrcsApi;
import org.eclipse.osee.orcs.data.ArtifactReadable;
import org.eclipse.osee.orcs.search.QueryBuilder;
import org.eclipse.osee.orcs.search.QueryFactory;
import org.eclipse.osee.orcs.transaction.TransactionBuilder;
import org.eclipse.osee.orcs.transaction.TransactionFactory;

/**
 * @author Roberto E. Escobar
 */
public abstract class AbstractOrcsStorage {

   private Log logger;
   private OrcsApi orcsApi;

   private BranchId storageBranch;
   private AccountFactory factory;

   public void setLogger(Log logger) {
      this.logger = logger;
   }

   public void setOrcsApi(OrcsApi orcsApi) {
      this.orcsApi = orcsApi;
   }

   public void setAccountFactory(AccountFactory factory) {
      this.factory = factory;
   }

   public void start() {
      logger.trace("Starting [%s]...", getClass().getSimpleName());
      storageBranch = CoreBranches.COMMON;
   }

   public void stop() {
      logger.trace("Stopping [%s]...", getClass().getSimpleName());
      storageBranch = null;
   }

   private BranchId getBranch() {
      return storageBranch;
   }

   protected Log getLogger() {
      return logger;
   }

   protected AccountFactory getFactory() {
      return factory;
   }

   protected QueryBuilder newQuery() {
      QueryFactory queryFactory = orcsApi.getQueryFactory();
      return queryFactory.fromBranch(getBranch());
   }

   @SuppressWarnings("unchecked")
   protected ArtifactReadable getSystemUser() {
      return newQuery().andIds(SystemUser.OseeSystem).getResults().getExactlyOne();
   }

   protected TransactionBuilder newTransaction(String comment) {
      TransactionFactory transactionFactory = orcsApi.getTransactionFactory();
      return transactionFactory.createTransaction(getBranch(), getSystemUser(), comment);
   }

   protected boolean isInitialized() {
      OrcsAdmin adminOps = orcsApi.getAdminOps();
      return adminOps.isDataStoreInitialized();
   }

}

Back to the top