Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorddunne2009-12-29 23:16:20 +0000
committerddunne2009-12-29 23:16:20 +0000
commit83cabd0ec9a442080a7eb7ba0b2aeac4899d64d0 (patch)
treeb374281bfda980c04582befd435e9ac8fc84b3fd
parent5f12c39489070631ec71ecce507e0eba8211a5b7 (diff)
downloadorg.eclipse.osee-83cabd0ec9a442080a7eb7ba0b2aeac4899d64d0.tar.gz
org.eclipse.osee-83cabd0ec9a442080a7eb7ba0b2aeac4899d64d0.tar.xz
org.eclipse.osee-83cabd0ec9a442080a7eb7ba0b2aeac4899d64d0.zip
fixed transaction comments; added junit test
-rw-r--r--org.eclipse.osee.ats/src/org/eclipse/osee/ats/util/DoesNotWorkItemAts.java72
-rw-r--r--org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/cases/TransactionManagerTest.java69
-rw-r--r--org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionManager.java24
3 files changed, 164 insertions, 1 deletions
diff --git a/org.eclipse.osee.ats/src/org/eclipse/osee/ats/util/DoesNotWorkItemAts.java b/org.eclipse.osee.ats/src/org/eclipse/osee/ats/util/DoesNotWorkItemAts.java
index f9022364711..43bae68947b 100644
--- a/org.eclipse.osee.ats/src/org/eclipse/osee/ats/util/DoesNotWorkItemAts.java
+++ b/org.eclipse.osee.ats/src/org/eclipse/osee/ats/util/DoesNotWorkItemAts.java
@@ -13,9 +13,12 @@ package org.eclipse.osee.ats.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
+import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -35,6 +38,8 @@ import org.eclipse.osee.framework.core.exception.MultipleArtifactsExist;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.exception.OseeDataStoreException;
import org.eclipse.osee.framework.core.model.Branch;
+import org.eclipse.osee.framework.database.core.ConnectionHandler;
+import org.eclipse.osee.framework.database.core.IOseeStatement;
import org.eclipse.osee.framework.jdk.core.util.AFile;
import org.eclipse.osee.framework.logging.OseeLevel;
import org.eclipse.osee.framework.logging.OseeLog;
@@ -58,7 +63,7 @@ import org.eclipse.swt.widgets.Display;
public class DoesNotWorkItemAts extends XNavigateItemAction {
public DoesNotWorkItemAts(XNavigateItem parent) {
- super(parent, "Does Not Work - ATS - Fix Branch Names", FrameworkImage.ADMIN);
+ super(parent, "Does Not Work - ATS - Fix Transaction Comments", FrameworkImage.ADMIN);
}
@Override
@@ -67,6 +72,7 @@ public class DoesNotWorkItemAts extends XNavigateItemAction {
return;
}
+ // renameTransactionComments();
// SkynetTransaction transaction = new SkynetTransaction(AtsUtil.getAtsBranch(), "Admin Cleanup");
// Artifact verArt =
// ArtifactQuery.getArtifactFromTypeAndName(AtsArtifactTypes.Version, "0.9.0", AtsUtil.getAtsBranch());
@@ -107,6 +113,70 @@ public class DoesNotWorkItemAts extends XNavigateItemAction {
AWorkbench.popup("Completed", "Complete");
}
+ private void renameTransactionComments() throws OseeCoreException {
+ List<String> notRenamed = new ArrayList<String>();
+ Map<String, Integer> commentToTransId = new HashMap<String, Integer>();
+ String SEARCH_TRANSACTION_COMMENTS =
+ "select transaction_id, osee_comment from osee_tx_details where osee_comment like '%Commit%'";
+
+ IOseeStatement chStmt = ConnectionHandler.getStatement();
+ try {
+ chStmt.runPreparedQuery(SEARCH_TRANSACTION_COMMENTS);
+ while (chStmt.next()) {
+ int transId = chStmt.getInt("transaction_id");
+ String comment = chStmt.getString("osee_comment");
+ commentToTransId.put(comment, transId);
+ }
+ } finally {
+ chStmt.close();
+ }
+
+ for (Entry<String, Integer> entry : commentToTransId.entrySet()) {
+ String comment = entry.getKey();
+ Pattern traxPattern = Pattern.compile("^(.*? - TRAX RPCR .*)( - TRAX RPCR .*)$");
+ Pattern shortPattern = Pattern.compile("^(.*? -) +(.*?) - +(.*?)$");
+ System.out.println("TransId " + entry.getValue() + " Comment = " + comment);
+
+ boolean renamed = false;
+ Matcher m = traxPattern.matcher(comment);
+ if (m.find()) {
+ String first = m.group(1);
+ String second = m.group(2);
+ String newComment = first;
+ if (!comment.equals(newComment)) {
+ renamed = true;
+ System.out.println("TransId " + entry.getValue() + " Rename1 = " + newComment);
+ // TransactionManager.setTransactionComment(TransactionManager.getTransactionId(entry.getValue()),
+ // newComment);
+ }
+ }
+ if (!renamed) {
+ m = shortPattern.matcher(comment);
+ if (m.find()) {
+ String prefix = m.group(1);
+ String first = m.group(2);
+ String second = m.group(3);
+ second = second.replaceFirst("...$", "");
+ String newComment = prefix + " " + first;
+ if (first.equals(second) || first.startsWith(second)) {
+ renamed = true;
+ System.out.println("TransId " + entry.getValue() + " Rename2 = " + newComment);
+ // TransactionManager.setTransactionComment(TransactionManager.getTransactionId(entry.getValue()),
+ // newComment);
+ }
+ }
+ }
+ if (!renamed) {
+ notRenamed.add(comment);
+ }
+
+ }
+ for (String branchName : notRenamed) {
+ System.out.println("Not Renamed " + branchName);
+ }
+
+ }
+
private void renameBranches() throws OseeCoreException {
List<String> notRenamed = new ArrayList<String>();
Pattern traxPattern = Pattern.compile("^(..... - TRAX RPCR .*)( - TRAX RPCR .*)$");
diff --git a/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/cases/TransactionManagerTest.java b/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/cases/TransactionManagerTest.java
new file mode 100644
index 00000000000..d2c16c66e08
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/cases/TransactionManagerTest.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * 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.skynet.core.test.cases;
+
+import static org.junit.Assert.assertFalse;
+import java.util.List;
+import junit.framework.Assert;
+import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
+import org.eclipse.osee.framework.core.model.TransactionRecord;
+import org.eclipse.osee.framework.jdk.core.util.GUID;
+import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
+import org.eclipse.osee.framework.skynet.core.artifact.ArtifactTypeManager;
+import org.eclipse.osee.framework.skynet.core.artifact.BranchManager;
+import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction;
+import org.eclipse.osee.framework.skynet.core.transaction.TransactionManager;
+import org.eclipse.osee.support.test.util.TestUtil;
+import org.junit.Before;
+
+/**
+ * @author Donald G. Dunne
+ */
+public class TransactionManagerTest {
+
+ @Before
+ public void setUp() throws Exception {
+ assertFalse(TestUtil.isProductionDb());
+ }
+
+ @org.junit.Test
+ public void testGetSetTransactionComment() throws Exception {
+
+ // Create new transaction
+ String guid = GUID.create();
+ String comment = "TransactionManagerTest-" + guid;
+ SkynetTransaction newTransaction = new SkynetTransaction(BranchManager.getCommonBranch(), comment);
+ Artifact art = ArtifactTypeManager.addArtifact(CoreArtifactTypes.Folder, BranchManager.getCommonBranch());
+ art.persist(newTransaction);
+ newTransaction.execute();
+
+ // Find transaction
+ List<TransactionRecord> transactions = TransactionManager.getTransaction(comment);
+ Assert.assertEquals(1, transactions.size());
+ TransactionRecord transaction = transactions.iterator().next();
+ Assert.assertEquals(comment, transaction.getComment());
+
+ String newComment = comment + "NEW";
+ // Set comment
+ TransactionManager.setTransactionComment(transaction, newComment);
+
+ // Find transaction
+ transactions = TransactionManager.getTransaction(comment);
+ // Shouldn't be a transaction with old name
+ Assert.assertEquals(0, transactions.size());
+
+ transactions = TransactionManager.getTransaction(newComment);
+ // Should be one transaction with new comment
+ Assert.assertEquals(1, transactions.size());
+
+ }
+
+}
diff --git a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionManager.java b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionManager.java
index dace224389c..121c8ddd7ab 100644
--- a/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionManager.java
+++ b/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionManager.java
@@ -57,12 +57,36 @@ public final class TransactionManager {
private static final String SELECT_COMMIT_TRANSACTIONS =
"SELECT transaction_id from osee_tx_details where commit_art_id = ?";
+ private static final String UPDATE_TRANSACTION_COMMENTS =
+ "update osee_tx_details set osee_comment = ? where transaction_id = ?";
+
+ private static final String SELECT_TRANSACTION_COMMENTS =
+ "select transaction_id from osee_tx_details where osee_comment like ?";
+
private static final HashMap<IArtifact, List<TransactionRecord>> commitArtifactMap =
new HashMap<IArtifact, List<TransactionRecord>>();
private TransactionManager() {
}
+ public static List<TransactionRecord> getTransaction(String comment) throws OseeCoreException {
+ ArrayList<TransactionRecord> transactions = new ArrayList<TransactionRecord>();
+ IOseeStatement chStmt = ConnectionHandler.getStatement();
+ try {
+ chStmt.runPreparedQuery(SELECT_TRANSACTION_COMMENTS, comment);
+ while (chStmt.next()) {
+ transactions.add(getTransactionId(chStmt.getInt("transaction_id"), chStmt));
+ }
+ } finally {
+ chStmt.close();
+ }
+ return transactions;
+ }
+
+ public static void setTransactionComment(TransactionRecord transaction, String comment) throws OseeDataStoreException {
+ ConnectionHandler.runPreparedUpdate(UPDATE_TRANSACTION_COMMENTS, comment, transaction.getId());
+ }
+
private static TransactionCache getTransactionCache() {
return Activator.getInstance().getOseeCacheService().getTransactionCache();
}

Back to the top