summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid W. Miller2012-05-14 19:34:31 (EDT)
committerRoberto E. Escobar2012-05-14 19:34:31 (EDT)
commitbab28cec762a90c075a17f07ba00ae1b7b730b07 (patch)
tree6431568aa756f431c505118eb9d72ec42cd7552e
parent3ea748c1c57c1e373452b123c67ac717402836b8 (diff)
downloadorg.eclipse.osee-bab28cec762a90c075a17f07ba00ae1b7b730b07.zip
org.eclipse.osee-bab28cec762a90c075a17f07ba00ae1b7b730b07.tar.gz
org.eclipse.osee-bab28cec762a90c075a17f07ba00ae1b7b730b07.tar.bz2
feature[ats_MCQKT]: Add branch copy with transaction
-rw-r--r--plugins/org.eclipse.osee.display.presenter.mocks/src/org/eclipse/osee/display/presenter/mocks/MockArtifact.java5
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/BranchDataStore.java2
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/OrcsBranchImpl.java5
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/branch/BranchDataStoreImpl.java13
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/BranchCopyTxCallable.java167
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/CreateBranchDatabaseCallable.java2
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/CreateBranchDatabaseTxCallable.java29
-rw-r--r--plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/OrcsBranch.java2
-rw-r--r--plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/data/CreateBranchData.java44
9 files changed, 252 insertions, 17 deletions
diff --git a/plugins/org.eclipse.osee.display.presenter.mocks/src/org/eclipse/osee/display/presenter/mocks/MockArtifact.java b/plugins/org.eclipse.osee.display.presenter.mocks/src/org/eclipse/osee/display/presenter/mocks/MockArtifact.java
index 74c78d1..b460435 100644
--- a/plugins/org.eclipse.osee.display.presenter.mocks/src/org/eclipse/osee/display/presenter/mocks/MockArtifact.java
+++ b/plugins/org.eclipse.osee.display.presenter.mocks/src/org/eclipse/osee/display/presenter/mocks/MockArtifact.java
@@ -201,4 +201,9 @@ public class MockArtifact implements ReadableArtifact {
return false;
}
+ @Override
+ public <T> T getSoleAttributeValue(IAttributeType attributeType) {
+ return null;
+ }
+
} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/BranchDataStore.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/BranchDataStore.java
index 6e81c4f..6342029 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/BranchDataStore.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/BranchDataStore.java
@@ -29,6 +29,8 @@ public interface BranchDataStore {
Callable<Branch> createBranch(String sessionId, CreateBranchData branchData);
+ Callable<Branch> createBranchCopyTx(String sessionId, CreateBranchData branchData);
+
Callable<Branch> purgeBranch(String sessionId, Branch branch);
Callable<TransactionRecord> commitBranch(String sessionId, ReadableArtifact committer, Branch source, Branch destination);
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/OrcsBranchImpl.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/OrcsBranchImpl.java
index 958026e..3bf2af9 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/OrcsBranchImpl.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/OrcsBranchImpl.java
@@ -65,6 +65,11 @@ public class OrcsBranchImpl implements OrcsBranch {
}
@Override
+ public Callable<ReadableBranch> createBranchFromTx(CreateBranchData newBranchData) {
+ return new CreateBranchCallable(logger, sessionContext, branchStore, newBranchData);
+ }
+
+ @Override
public Callable<ReadableBranch> archiveUnarchiveBranch(IOseeBranch branch, ArchiveOperation archiveOp) {
return new ArchiveUnarchiveBranchCallable(logger, sessionContext, branchStore, branchCache, branch, archiveOp);
}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/branch/BranchDataStoreImpl.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/branch/BranchDataStoreImpl.java
index 6ce8cbc..a0b9533 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/branch/BranchDataStoreImpl.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/branch/BranchDataStoreImpl.java
@@ -31,10 +31,11 @@ import org.eclipse.osee.orcs.core.SystemPreferences;
import org.eclipse.osee.orcs.core.ds.BranchDataStore;
import org.eclipse.osee.orcs.data.CreateBranchData;
import org.eclipse.osee.orcs.data.ReadableArtifact;
+import org.eclipse.osee.orcs.db.internal.callable.BranchCopyTxCallable;
import org.eclipse.osee.orcs.db.internal.callable.CheckBranchExchangeIntegrityCallable;
import org.eclipse.osee.orcs.db.internal.callable.CommitBranchDatabaseCallable;
import org.eclipse.osee.orcs.db.internal.callable.CompareDatabaseCallable;
-import org.eclipse.osee.orcs.db.internal.callable.CreateBranchDatabaseCallable;
+import org.eclipse.osee.orcs.db.internal.callable.CreateBranchDatabaseTxCallable;
import org.eclipse.osee.orcs.db.internal.callable.DeleteRelationDatabaseCallable;
import org.eclipse.osee.orcs.db.internal.callable.ExportBranchDatabaseCallable;
import org.eclipse.osee.orcs.db.internal.callable.ImportBranchDatabaseCallable;
@@ -95,7 +96,14 @@ public class BranchDataStoreImpl implements BranchDataStore {
@Override
public Callable<Branch> createBranch(String sessionId, CreateBranchData branchData) {
- return new CreateBranchDatabaseCallable(logger, dbService, cachingService.getBranchCache(),
+ return new CreateBranchDatabaseTxCallable(logger, dbService, cachingService.getBranchCache(),
+ cachingService.getTransactionCache(), modelFactory.getBranchFactory(), modelFactory.getTransactionFactory(),
+ branchData);
+ }
+
+ @Override
+ public Callable<Branch> createBranchCopyTx(String sessionId, CreateBranchData branchData) {
+ return new BranchCopyTxCallable(logger, dbService, cachingService.getBranchCache(),
cachingService.getTransactionCache(), modelFactory.getBranchFactory(), modelFactory.getTransactionFactory(),
branchData);
}
@@ -142,4 +150,5 @@ public class BranchDataStoreImpl implements BranchDataStore {
return new DeleteRelationDatabaseCallable(logger, dbService, identityService, cachingService.getBranchCache(),
branch, relationType, aArtId, bArtId, artUserId, comment);
}
+
}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/BranchCopyTxCallable.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/BranchCopyTxCallable.java
new file mode 100644
index 0000000..874eedd
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/BranchCopyTxCallable.java
@@ -0,0 +1,167 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.db.internal.callable;
+
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.concurrent.Callable;
+import org.eclipse.osee.database.schema.DatabaseTxCallable;
+import org.eclipse.osee.framework.core.enums.ModificationType;
+import org.eclipse.osee.framework.core.enums.TransactionDetailsType;
+import org.eclipse.osee.framework.core.enums.TxChange;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.exception.OseeExceptions;
+import org.eclipse.osee.framework.core.model.Branch;
+import org.eclipse.osee.framework.core.model.BranchFactory;
+import org.eclipse.osee.framework.core.model.TransactionRecord;
+import org.eclipse.osee.framework.core.model.TransactionRecordFactory;
+import org.eclipse.osee.framework.core.model.cache.BranchCache;
+import org.eclipse.osee.framework.core.model.cache.TransactionCache;
+import org.eclipse.osee.framework.database.IOseeDatabaseService;
+import org.eclipse.osee.framework.database.core.IOseeStatement;
+import org.eclipse.osee.framework.database.core.OseeConnection;
+import org.eclipse.osee.framework.jdk.core.util.GUID;
+import org.eclipse.osee.framework.jdk.core.util.time.GlobalTime;
+import org.eclipse.osee.logger.Log;
+import org.eclipse.osee.orcs.data.CreateBranchData;
+
+/**
+ * @author David Miller the behavior of this class - it needs to: have a branch
+ */
+public final class BranchCopyTxCallable extends DatabaseTxCallable<Branch> {
+
+ private final BranchCache branchCache;
+ private final TransactionCache txCache;
+ private final BranchFactory branchFactory;
+ private final TransactionRecordFactory txFactory;
+ private final CreateBranchData branchData;
+ private boolean wasSuccessful;
+ private Branch internalBranch;
+
+ private static final String INSERT_TX_DETAILS =
+ "INSERT INTO osee_tx_details (branch_id, transaction_id, osee_comment, time, author, tx_type) VALUES (?,?,?,?,?,?)";
+
+ private static final String INSERT_ADDRESSING =
+ "INSERT INTO osee_txs (transaction_id, gamma_id, mod_type, tx_current, branch_id) VALUES (?,?,?,?,?)";
+
+ private static final String SELECT_ADDRESSING =
+ "SELECT gamma_id, mod_type FROM osee_txs txs WHERE txs.branch_id = ? AND txs.transaction_id = ?";
+
+ public BranchCopyTxCallable(Log logger, IOseeDatabaseService databaseService, BranchCache branchCache, TransactionCache txCache, BranchFactory branchFactory, TransactionRecordFactory txFactory, CreateBranchData branchData) {
+ super(logger, databaseService, String.format("Create Branch %s", branchData.getName()));
+ this.branchCache = branchCache;
+ this.txCache = txCache;
+ this.branchFactory = branchFactory;
+ this.txFactory = txFactory;
+ this.branchData = branchData;
+ this.wasSuccessful = false;
+ //this.systemUserId = -1;
+ }
+
+ private TransactionCache getTxCache() {
+ return txCache;
+ }
+
+ private BranchCache getBranchCache() {
+ return branchCache;
+ }
+
+ @Override
+ public Branch handleTxWork(OseeConnection connection) throws OseeCoreException {
+ // get the previous transaction, if there is one
+ // TODO figure out what happens when there isn't one
+ TransactionRecord savedTx = txCache.getOrLoad(branchData.getSourceTransactionId(txCache));
+
+ TransactionRecord priorTx = txCache.getPriorTransaction(savedTx);
+ // copy the branch up to the prior transaction - the goal is to have the provided
+ // transaction available on the new branch for merging or comparison purposes
+ // first set aside the transaction
+
+ branchData.setFromTransaction(priorTx);
+
+ Callable<Branch> callable =
+ new CreateBranchDatabaseTxCallable(getLogger(), getDatabaseService(), getBranchCache(), getTxCache(),
+ branchFactory, txFactory, branchData);
+
+ try {
+ internalBranch = callable.call();
+ // TODO figure out if this call is "stackable", is the data passed in above
+ // still valid after the branch creation, or do I need to get it all from the new branch???
+
+ String guid = branchData.getGuid();
+ if (!GUID.isValid(guid)) {
+ guid = GUID.create();
+ }
+
+ Timestamp timestamp = GlobalTime.GreenwichMeanTimestamp();
+ int nextTransactionId = getDatabaseService().getSequence().getNextTransactionId();
+
+ String creationComment = branchData.getCreationComment() + " and copied transaction " + savedTx.getId();
+
+ getDatabaseService().runPreparedUpdate(connection, INSERT_TX_DETAILS, internalBranch.getId(),
+ nextTransactionId, creationComment, timestamp, branchData.getUserArtifactId(),
+ TransactionDetailsType.NonBaselined.getId());
+
+ TransactionRecord record =
+ txFactory.create(nextTransactionId, internalBranch.getId(), creationComment, timestamp,
+ branchData.getUserArtifactId(), -1, TransactionDetailsType.Baselined, branchCache);
+
+ txCache.cache(record);
+
+ populateTransaction(0.30, connection, record.getId(), internalBranch, savedTx);
+
+ wasSuccessful = true;
+
+ } catch (Exception ex) {
+ OseeExceptions.wrapAndThrow(ex);
+ }
+ return internalBranch;
+ }
+
+ private void populateTransaction(double workAmount, OseeConnection connection, int intoTx, Branch branch, TransactionRecord copyTx) throws OseeCoreException {
+ List<Object[]> data = new ArrayList<Object[]>();
+ HashSet<Integer> gammas = new HashSet<Integer>(100000);
+ int parentBranchId = -1;
+ if (branch.hasParentBranch()) {
+ parentBranchId = branch.getParentBranch().getId();
+ }
+ int copyTxId = copyTx.getId();
+
+ populateAddressingToCopy(connection, data, intoTx, gammas, SELECT_ADDRESSING, parentBranchId, copyTxId);
+
+ if (!data.isEmpty()) {
+ getDatabaseService().runBatchUpdate(connection, INSERT_ADDRESSING, data);
+ }
+
+ checkForCancelled();
+ }
+
+ private void populateAddressingToCopy(OseeConnection connection, List<Object[]> data, int baseTxId, HashSet<Integer> gammas, String query, Object... parameters) throws OseeCoreException {
+ IOseeStatement chStmt = getDatabaseService().getStatement(connection);
+ try {
+ chStmt.runPreparedQuery(10000, query, parameters);
+ while (chStmt.next()) {
+ checkForCancelled();
+ Integer gamma = chStmt.getInt("gamma_id");
+ if (!gammas.contains(gamma)) {
+ ModificationType modType = ModificationType.getMod(chStmt.getInt("mod_type"));
+ TxChange txCurrent = TxChange.getCurrent(modType);
+ data.add(new Object[] {baseTxId, gamma, modType.getValue(), txCurrent.getValue(), internalBranch.getId()});
+ gammas.add(gamma);
+ }
+ }
+ } finally {
+ chStmt.close();
+ }
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/CreateBranchDatabaseCallable.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/CreateBranchDatabaseCallable.java
index 34a0174..4de38f9 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/CreateBranchDatabaseCallable.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/CreateBranchDatabaseCallable.java
@@ -97,7 +97,7 @@ public class CreateBranchDatabaseCallable extends DatabaseCallable<Branch> {
Callable<Branch> callable =
new CreateBranchDatabaseTxCallable(getLogger(), getDatabaseService(), getBranchCache(), getTxCache(),
- branchFactory, txFactory, createBranchData);
+ branchFactory, txFactory, branchData);
return callAndCheckForCancel(callable);
}
}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/CreateBranchDatabaseTxCallable.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/CreateBranchDatabaseTxCallable.java
index e3ba0fe..4620b0f 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/CreateBranchDatabaseTxCallable.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/CreateBranchDatabaseTxCallable.java
@@ -37,7 +37,7 @@ import org.eclipse.osee.framework.database.core.OseeConnection;
import org.eclipse.osee.framework.jdk.core.util.GUID;
import org.eclipse.osee.framework.jdk.core.util.time.GlobalTime;
import org.eclipse.osee.logger.Log;
-import org.eclipse.osee.orcs.db.internal.branch.CreateDatabaseBranch;
+import org.eclipse.osee.orcs.data.CreateBranchData;
/**
* @author Roberto E. Escobar
@@ -73,17 +73,16 @@ public class CreateBranchDatabaseTxCallable extends DatabaseTxCallable<Branch> {
private final TransactionCache txCache;
private final BranchFactory branchFactory;
private final TransactionRecordFactory txFactory;
- private final CreateDatabaseBranch newBranchData;
+ private final CreateBranchData newBranchData;
private Branch branch;
- public CreateBranchDatabaseTxCallable(Log logger, IOseeDatabaseService databaseService, BranchCache branchCache, TransactionCache txCache, BranchFactory branchFactory, TransactionRecordFactory txFactory, CreateDatabaseBranch newBranchData) {
- super(logger, databaseService, String.format("Create Branch: [%s from %s]", newBranchData.getBranchName(),
- newBranchData.getParentBranchId()));
+ public CreateBranchDatabaseTxCallable(Log logger, IOseeDatabaseService databaseService, BranchCache branchCache, TransactionCache txCache, BranchFactory branchFactory, TransactionRecordFactory txFactory, CreateBranchData branchData) {
+ super(logger, databaseService, String.format("Create Branch %s", branchData.getName()));
this.branchCache = branchCache;
this.txCache = txCache;
this.branchFactory = branchFactory;
this.txFactory = txFactory;
- this.newBranchData = newBranchData;
+ this.newBranchData = branchData;
this.wasSuccessful = false;
this.systemUserId = -1;
}
@@ -117,7 +116,7 @@ public class CreateBranchDatabaseTxCallable extends DatabaseTxCallable<Branch> {
newBranchData.getAssociatedArtifactId(), BranchState.DELETED.getValue(),
BranchState.REBASELINED.getValue());
if (count > 0) {
- throw new OseeStateException("Existing branch creation detected for [%s]", newBranchData.getBranchName());
+ throw new OseeStateException("Existing branch creation detected for [%s]", newBranchData.getName());
}
}
}
@@ -126,20 +125,20 @@ public class CreateBranchDatabaseTxCallable extends DatabaseTxCallable<Branch> {
@SuppressWarnings("unchecked")
@Override
protected Branch handleTxWork(OseeConnection connection) throws OseeCoreException {
- Branch parentBranch = branchCache.getById(newBranchData.getParentBranchId());
+ Branch parentBranch = branchCache.getById(newBranchData.getParentBranchId(txCache));
Branch destinationBranch = branchCache.getById(newBranchData.getMergeDestinationBranchId());
passedPreConditions = false;
checkPreconditions(parentBranch, destinationBranch);
passedPreConditions = true;
- String guid = newBranchData.getBranchGuid();
+ String guid = newBranchData.getGuid();
if (!GUID.isValid(guid)) {
guid = GUID.create();
}
branch =
- branchFactory.create(guid, newBranchData.getBranchName(), newBranchData.getBranchType(),
+ branchFactory.create(guid, newBranchData.getName(), newBranchData.getBranchType(),
BranchState.CREATION_IN_PROGRESS, false);
branch.setParentBranch(parentBranch);
@@ -151,10 +150,12 @@ public class CreateBranchDatabaseTxCallable extends DatabaseTxCallable<Branch> {
if (branch.getBranchType().isSystemRootBranch()) {
TransactionRecord systemTx =
txFactory.create(nextTransactionId, branch.getId(), newBranchData.getCreationComment(), timestamp,
- newBranchData.getAuthorId(), -1, TransactionDetailsType.Baselined, branchCache);
+ newBranchData.getUserArtifactId(), -1, TransactionDetailsType.Baselined, branchCache);
branch.setSourceTransaction(systemTx);
} else {
- branch.setSourceTransaction(txCache.getOrLoad(newBranchData.getSourceTransactionId()));
+ int srcTx = newBranchData.getSourceTransactionId(txCache);
+
+ branch.setSourceTransaction(txCache.getOrLoad(srcTx));
}
if (branch.getBranchType().isMergeBranch()) {
@@ -166,12 +167,12 @@ public class CreateBranchDatabaseTxCallable extends DatabaseTxCallable<Branch> {
branchCache.storeItems(branch);
getDatabaseService().runPreparedUpdate(connection, INSERT_TX_DETAILS, branch.getId(), nextTransactionId,
- newBranchData.getCreationComment(), timestamp, newBranchData.getAuthorId(),
+ newBranchData.getCreationComment(), timestamp, newBranchData.getUserArtifactId(),
TransactionDetailsType.Baselined.getId());
TransactionRecord record =
txFactory.create(nextTransactionId, branch.getId(), newBranchData.getCreationComment(), timestamp,
- newBranchData.getAuthorId(), -1, TransactionDetailsType.Baselined, branchCache);
+ newBranchData.getUserArtifactId(), -1, TransactionDetailsType.Baselined, branchCache);
if (branch.getBranchType().isSystemRootBranch()) {
branch.setSourceTransaction(record);
diff --git a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/OrcsBranch.java b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/OrcsBranch.java
index 99adb29..c211d64 100644
--- a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/OrcsBranch.java
+++ b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/OrcsBranch.java
@@ -33,6 +33,8 @@ public interface OrcsBranch {
Callable<ReadableBranch> createBranch(CreateBranchData branchData);
+ Callable<ReadableBranch> createBranchFromTx(CreateBranchData branchData);
+
Callable<ReadableBranch> archiveUnarchiveBranch(IOseeBranch branch, ArchiveOperation archiveOp);
Callable<ReadableBranch> deleteBranch(IOseeBranch branch);
diff --git a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/data/CreateBranchData.java b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/data/CreateBranchData.java
index abac323..5975d2a 100644
--- a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/data/CreateBranchData.java
+++ b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/data/CreateBranchData.java
@@ -14,12 +14,19 @@ import org.eclipse.osee.framework.core.data.ITransaction;
import org.eclipse.osee.framework.core.data.Identifiable;
import org.eclipse.osee.framework.core.data.Identity;
import org.eclipse.osee.framework.core.enums.BranchType;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.model.TransactionRecord;
+import org.eclipse.osee.framework.core.model.cache.TransactionCache;
/**
* @author Roberto E. Escobar
*/
public class CreateBranchData implements Identifiable {
+ private static final int NULL_PARENT_BRANCH_ID = -1;
+ private static final int NULL_SOURCE_TRANSACTION_ID = -1;
+ private static final int NULL_ARTIFACT_ID = -1;
+
private String branchUuid;
private String branchName;
private BranchType branchType;
@@ -37,6 +44,23 @@ public class CreateBranchData implements Identifiable {
return branchUuid;
}
+ public int getAssociatedArtifactId() {
+
+ int result = NULL_ARTIFACT_ID;
+ if (associatedArtifact != null) {
+ result = associatedArtifact.getId();
+ }
+ return result;
+ }
+
+ public int getUserArtifactId() {
+ int result = NULL_ARTIFACT_ID;
+ if (userArtifact != null) {
+ result = userArtifact.getId();
+ }
+ return result;
+ }
+
public void setGuid(String branchUuid) {
this.branchUuid = branchUuid;
}
@@ -106,6 +130,26 @@ public class CreateBranchData implements Identifiable {
this.mergeDestinationBranchId = destinationBranchId;
}
+ public int getParentBranchId(TransactionCache txCache) throws OseeCoreException {
+
+ int parentBranchId = NULL_PARENT_BRANCH_ID;
+
+ if (BranchType.SYSTEM_ROOT != branchType) {
+ TransactionRecord sourceTx = txCache.getOrLoad(fromTransaction.getGuid());
+ parentBranchId = sourceTx.getBranchId();
+ }
+ return parentBranchId;
+ }
+
+ public int getSourceTransactionId(TransactionCache txCache) throws OseeCoreException {
+ int sourceTransactionId = NULL_SOURCE_TRANSACTION_ID;
+
+ if (BranchType.SYSTEM_ROOT != branchType) {
+ TransactionRecord sourceTx = txCache.getOrLoad(fromTransaction.getGuid());
+ sourceTransactionId = sourceTx.getId();
+ }
+ return sourceTransactionId;
+ }
@Override
public int hashCode() {