From d46e37b6739d340f94cec4555a027caa8fe8a2c3 Mon Sep 17 00:00:00 2001 From: Ryan D. Brooks Date: Tue, 14 Jun 2016 16:28:09 -0700 Subject: refactor: Remove unnecessary usage of TransactionReadable Change-Id: I253fb85c0c23445eeac173799adb51d7c541e932 --- .../orcs/rest/internal/BranchEndpointImpl.java | 50 +++++++++------------- 1 file changed, 21 insertions(+), 29 deletions(-) (limited to 'plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/BranchEndpointImpl.java') diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/BranchEndpointImpl.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/BranchEndpointImpl.java index ab8cce60daa..40eecb7c97b 100644 --- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/BranchEndpointImpl.java +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/BranchEndpointImpl.java @@ -14,7 +14,6 @@ import static org.eclipse.osee.framework.core.enums.CoreBranches.COMMON_ID; import static org.eclipse.osee.framework.jdk.core.util.Compare.isDifferent; import static org.eclipse.osee.orcs.rest.internal.OrcsRestUtil.asBranch; import static org.eclipse.osee.orcs.rest.internal.OrcsRestUtil.asBranches; -import static org.eclipse.osee.orcs.rest.internal.OrcsRestUtil.asIntegerList; import static org.eclipse.osee.orcs.rest.internal.OrcsRestUtil.asResponse; import static org.eclipse.osee.orcs.rest.internal.OrcsRestUtil.asTransaction; import static org.eclipse.osee.orcs.rest.internal.OrcsRestUtil.asTransactions; @@ -41,6 +40,8 @@ import org.eclipse.osee.activity.api.ActivityLog; import org.eclipse.osee.framework.core.data.BranchId; import org.eclipse.osee.framework.core.data.IOseeBranch; import org.eclipse.osee.framework.core.data.TokenFactory; +import org.eclipse.osee.framework.core.data.TransactionId; +import org.eclipse.osee.framework.core.data.TransactionToken; import org.eclipse.osee.framework.core.enums.BranchArchivedState; import org.eclipse.osee.framework.core.enums.BranchState; import org.eclipse.osee.framework.core.enums.BranchType; @@ -145,11 +146,6 @@ public class BranchEndpointImpl implements BranchEndpoint { return artifact; } - private BranchId getBranchFromTxId(int tx) { - TransactionQuery txQuery = newQuery().transactionQuery(); - return txQuery.andTxId(tx).getResults().getExactlyOne().getBranch(); - } - private BranchReadable getBranchById(long branchUuid) { ResultSet results = newBranchQuery().andUuids(branchUuid)// .includeArchived()// @@ -159,8 +155,7 @@ public class BranchEndpointImpl implements BranchEndpoint { } private TransactionReadable getTxByBranchAndId(long branchUuid, int txId) { - ResultSet results = newTxQuery().andBranchIds(branchUuid).andTxId(txId).getResults(); - return results.getExactlyOne(); + return newTxQuery().andBranchIds(branchUuid).andTxId(txId).getResults().getExactlyOne(); } private TransactionFactory newTxFactory() { @@ -258,20 +253,18 @@ public class BranchEndpointImpl implements BranchEndpoint { @Override public List getAllBranchTxs(long branchUuid) { - ResultSet results = newTxQuery().andBranchIds(branchUuid).getResults(); - return asTransactions(results); + return asTransactions(newTxQuery().andBranchIds(branchUuid).getResults()); } @Override public Transaction getBranchTx(long branchUuid, int txId) { - TransactionReadable tx = getTxByBranchAndId(branchUuid, txId); - return asTransaction(tx); + return asTransaction(getTxByBranchAndId(branchUuid, txId)); } @Override public CompareResults compareBranches(long branchUuid, long branchUuid2) { - TransactionReadable sourceTx = newTxQuery().andIsHead(branchUuid).getResults().getExactlyOne(); - TransactionReadable destinationTx = newTxQuery().andIsHead(branchUuid2).getResults().getExactlyOne(); + TransactionToken sourceTx = newTxQuery().andIsHead(branchUuid).getResults().getExactlyOne(); + TransactionToken destinationTx = newTxQuery().andIsHead(branchUuid2).getResults().getExactlyOne(); Callable> op = getBranchOps().compareBranch(sourceTx, destinationTx); List changes = executeCallable(op); @@ -309,7 +302,7 @@ public class BranchEndpointImpl implements BranchEndpoint { createData.setUserArtifact(getArtifactById(COMMON_ID, data.getAuthorId())); createData.setAssociatedArtifact(getArtifactById(COMMON_ID, data.getAssociatedArtifactId())); - createData.setFromTransaction(TokenFactory.createTransaction(data.getSourceTransactionId())); + createData.setFromTransaction(TransactionId.valueOf(data.getSourceTransactionId())); createData.setParentBranch(data.getParentBranch()); createData.setMergeDestinationBranchId(data.getMergeDestinationBranchId()); @@ -366,8 +359,8 @@ public class BranchEndpointImpl implements BranchEndpoint { BranchReadable destBranch = getBranchById(destinationBranchUuid); ArtifactReadable committer = getArtifactById(COMMON_ID, options.getCommitterId()); - Callable op = getBranchOps().commitBranch(committer, srcBranch, destBranch); - TransactionReadable tx = executeCallable(op); + Callable op = getBranchOps().commitBranch(committer, srcBranch, destBranch); + TransactionToken tx = executeCallable(op); if (options.isArchive()) { Callable op2 = getBranchOps().archiveUnarchiveBranch(srcBranch, ArchiveOperation.ARCHIVE); @@ -385,13 +378,12 @@ public class BranchEndpointImpl implements BranchEndpoint { } catch (OseeCoreException ex) { OseeLog.log(ActivityLog.class, OseeLevel.SEVERE_POPUP, ex); } - return Response.created(location).entity(asTransaction(tx)).build(); - + return Response.created(location).entity(asTransaction(orcsApi.getTransactionFactory().getTx(tx))).build(); } - private URI getTxLocation(UriInfo uriInfo, TransactionReadable tx) { + private URI getTxLocation(UriInfo uriInfo, TransactionToken tx) { UriBuilder builder = uriInfo.getRequestUriBuilder(); - URI location = builder.path("..").path("..").path("txs").path("{tx-id}").build(tx.getGuid()); + URI location = builder.path("..").path("..").path("txs").path("{tx-id}").build(tx); return location; } @@ -428,8 +420,8 @@ public class BranchEndpointImpl implements BranchEndpoint { //TODO: Integrate data with TxBuilder TransactionReadable tx = txBuilder.commit(); - if (tx != null) { - URI location = uriInfo.getRequestUriBuilder().path("{tx-id}").build(tx.getGuid()); + if (tx.isValid()) { + URI location = uriInfo.getRequestUriBuilder().path("{tx-id}").build(tx); return Response.created(location).entity(asTransaction(tx)).build(); } else { throw new OseeArgumentException("No Data Modified"); @@ -777,13 +769,13 @@ public class BranchEndpointImpl implements BranchEndpoint { @Override public Response purgeTxs(long branchUuid, String txIds) { boolean modified = false; - List txsToDelete = asIntegerList(txIds); + List txsToDelete = OrcsRestUtil.asIntegerList(txIds); if (!txsToDelete.isEmpty()) { - ResultSet results = + ResultSet results = newTxQuery().andBranchIds(branchUuid).andTxIds(txsToDelete).getResults(); if (!results.isEmpty()) { checkAllTxFoundAreOnBranch("Purge Transaction", branchUuid, txsToDelete, results); - List list = Lists.newArrayList(results); + List list = Lists.newArrayList(results); Callable op = newTxFactory().purgeTransaction(list); executeCallable(op); modified = true; @@ -802,11 +794,11 @@ public class BranchEndpointImpl implements BranchEndpoint { return asResponse(modified); } - private void checkAllTxFoundAreOnBranch(String opName, long branchUuid, List txIds, ResultSet result) { + private void checkAllTxFoundAreOnBranch(String opName, long branchUuid, List txIds, ResultSet result) { if (txIds.size() != result.size()) { Set found = new HashSet<>(); - for (TransactionReadable tx : result) { - found.add(tx.getGuid()); + for (TransactionId tx : result) { + found.add(tx.getId()); } SetView difference = Sets.difference(Sets.newHashSet(txIds), found); if (!difference.isEmpty()) { -- cgit v1.2.3