Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormegumi.telles2018-02-21 14:31:00 +0000
committermegumi.telles2018-02-21 14:32:09 +0000
commitb362b4b72f5f50bb44c368b4ff25bc5dba9d9d7a (patch)
tree270621da091e5b76ce4333d505cba3d4ca8d1ace
parent6d8f81e917dcd3b939b9d33d309405bc8b385164 (diff)
downloadorg.eclipse.osee-b362b4b72f5f50bb44c368b4ff25bc5dba9d9d7a.tar.gz
org.eclipse.osee-b362b4b72f5f50bb44c368b4ff25bc5dba9d9d7a.tar.xz
org.eclipse.osee-b362b4b72f5f50bb44c368b4ff25bc5dba9d9d7a.zip
feature[ats_TW7429]: Create ChangeArtifactName Blam
-rw-r--r--plugins/org.eclipse.osee.framework.ui.skynet/plugin.xml8
-rw-r--r--plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/ChangeArtifactName.java57
-rw-r--r--plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/ChangeArtifactNameOperation.java74
3 files changed, 139 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/plugin.xml b/plugins/org.eclipse.osee.framework.ui.skynet/plugin.xml
index fcad84f9a98..36d285e6bdf 100644
--- a/plugins/org.eclipse.osee.framework.ui.skynet/plugin.xml
+++ b/plugins/org.eclipse.osee.framework.ui.skynet/plugin.xml
@@ -1633,4 +1633,12 @@
id="org.eclipse.osee.framework.ui.skynet.ArtifactEditorInputFactory">
</factory>
</extension>
+ <extension
+ id="ChangeArtifactName"
+ name="ChangeArtifactName"
+ point="org.eclipse.osee.framework.ui.skynet.BlamOperation">
+ <Operation
+ className="org.eclipse.osee.framework.ui.skynet.blam.operation.ChangeArtifactName">
+ </Operation>
+ </extension>
</plugin>
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/ChangeArtifactName.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/ChangeArtifactName.java
new file mode 100644
index 00000000000..8f5a6c4ad8b
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/ChangeArtifactName.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2018 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.ui.skynet.blam.operation;
+
+import java.util.Collection;
+import java.util.Collections;
+import org.eclipse.osee.framework.core.data.BranchId;
+import org.eclipse.osee.framework.core.operation.IOperation;
+import org.eclipse.osee.framework.core.operation.OperationLogger;
+import org.eclipse.osee.framework.ui.skynet.blam.AbstractBlam;
+import org.eclipse.osee.framework.ui.skynet.blam.VariableMap;
+
+/**
+ * @author Megumi Telles
+ */
+public class ChangeArtifactName extends AbstractBlam {
+
+ private final static String ID_NAME = "ID to New Name Pairs";
+ private static final String BRANCH = "Branch Input";
+
+ @Override
+ public IOperation createOperation(VariableMap variableMap, OperationLogger logger) throws Exception {
+ String pairs = variableMap.getString(ID_NAME);
+ BranchId branch = variableMap.getBranch(BRANCH);
+ return new ChangeArtifactNameOperation(logger, pairs, branch);
+ }
+
+ @Override
+ public Collection<String> getCategories() {
+ return Collections.singletonList("Define");
+ }
+
+ @Override
+ public String getXWidgetsXml() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("<xWidgets>");
+ sb.append("<XWidget xwidgetType=\"XText\" fill=\"Vertically\" displayName=\"");
+ sb.append(ID_NAME);
+ sb.append("\" />");
+ sb.append(String.format("<XWidget xwidgetType=\"XBranchSelectWidget\" displayName=\"%s\"/>", BRANCH));
+ sb.append("</xWidgets>");
+ return sb.toString();
+ }
+
+ @Override
+ public String getDescriptionUsage() {
+ return "Renames artifacts given list of \"art ids, new name\" pairs. Each rename should be separated by a return.";
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/ChangeArtifactNameOperation.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/ChangeArtifactNameOperation.java
new file mode 100644
index 00000000000..d0c74266ee8
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/ChangeArtifactNameOperation.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2018 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.ui.skynet.blam.operation;
+
+import java.util.HashMap;
+import java.util.Map.Entry;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.nebula.widgets.xviewer.Activator;
+import org.eclipse.osee.framework.core.data.BranchId;
+import org.eclipse.osee.framework.core.enums.DeletionFlag;
+import org.eclipse.osee.framework.core.operation.AbstractOperation;
+import org.eclipse.osee.framework.core.operation.OperationLogger;
+import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException;
+import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
+import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;
+import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction;
+import org.eclipse.osee.framework.skynet.core.transaction.TransactionManager;
+
+/**
+ * @author Megumi Telles
+ */
+public class ChangeArtifactNameOperation extends AbstractOperation {
+
+ private final String renamePairs;
+ private final BranchId branch;
+
+ public ChangeArtifactNameOperation(OperationLogger logger, String renamePairs, BranchId branch) {
+ super("Rename Artifact Name", Activator.PLUGIN_ID, logger);
+ this.renamePairs = renamePairs;
+ this.branch = branch;
+ }
+
+ @Override
+ protected void doWork(IProgressMonitor monitor) throws Exception {
+ if (renamePairs.isEmpty()) {
+ throw new OseeArgumentException("Must specify at least one pair.");
+ }
+ HashMap<String, String> pairs = getPairs();
+ SkynetTransaction tx = TransactionManager.createTransaction(branch, "Rename Artifact");
+ for (Entry<String, String> entry : pairs.entrySet()) {
+ Artifact artifact = ArtifactQuery.getArtifactFromIdOrNull(Integer.valueOf(entry.getKey()), branch,
+ DeletionFlag.EXCLUDE_DELETED);
+ if (artifact != null) {
+ if (!artifact.getName().equals(entry.getValue())) {
+ artifact.setName(entry.getValue());
+ artifact.persist(tx);
+ }
+ }
+ }
+ tx.execute();
+ }
+
+ private HashMap<String, String> getPairs() {
+ HashMap<String, String> pairs = new HashMap<>();
+ String[] splitPairs = renamePairs.split("[\n\r]+");
+ for (String pair : splitPairs) {
+ String[] splitPair = pair.split("[\\s,]+");
+ if (splitPair.length != 2) {
+ throw new OseeArgumentException("Invalid pairs");
+ }
+ pairs.put(splitPair[0], splitPair[1]);
+ }
+ return pairs;
+ }
+
+}

Back to the top