diff options
Diffstat (limited to 'plugins/org.eclipse.osee.orcs.account.admin/src/org/eclipse/osee/orcs/account/admin/internal/AbstractOrcsStorage.java')
-rw-r--r-- | plugins/org.eclipse.osee.orcs.account.admin/src/org/eclipse/osee/orcs/account/admin/internal/AbstractOrcsStorage.java | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.orcs.account.admin/src/org/eclipse/osee/orcs/account/admin/internal/AbstractOrcsStorage.java b/plugins/org.eclipse.osee.orcs.account.admin/src/org/eclipse/osee/orcs/account/admin/internal/AbstractOrcsStorage.java new file mode 100644 index 00000000000..32d078677fe --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.account.admin/src/org/eclipse/osee/orcs/account/admin/internal/AbstractOrcsStorage.java @@ -0,0 +1,100 @@ +/******************************************************************************* + * 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.IOseeBranch; +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.ApplicationContext; +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 IOseeBranch storageBranch; + private ApplicationContext context; + 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; + + String sessionId = SystemUser.OseeSystem.getGuid(); + context = newApplicationContext(sessionId); + } + + public void stop() { + logger.trace("Stopping [%s]...", getClass().getSimpleName()); + storageBranch = null; + context = null; + } + + private ApplicationContext newApplicationContext(final String sessionId) { + return new ApplicationContext() { + + @Override + public String getSessionId() { + return sessionId; + } + }; + } + + private IOseeBranch getBranch() { + return storageBranch; + } + + protected Log getLogger() { + return logger; + } + + protected AccountFactory getFactory() { + return factory; + } + + protected QueryBuilder newQuery() { + QueryFactory queryFactory = orcsApi.getQueryFactory(context); + 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(context); + return transactionFactory.createTransaction(getBranch(), getSystemUser(), comment); + } + +} |