| author | Angel Avila | 2012-09-04 16:02:01 (EDT) |
|---|---|---|
| committer | Roberto E. Escobar | 2012-09-04 16:02:01 (EDT) |
| commit | d3ae65268d66e05d0ae732427b9d76543a035500 (patch) (side-by-side diff) | |
| tree | b6205fe63283c051731b4d1daab33124ff92994f | |
| parent | 31256b4f5b5f67ba5c8b09fc0107927b4e62d8c2 (diff) | |
| download | org.eclipse.osee-d3ae65268d66e05d0ae732427b9d76543a035500.zip org.eclipse.osee-d3ae65268d66e05d0ae732427b9d76543a035500.tar.gz org.eclipse.osee-d3ae65268d66e05d0ae732427b9d76543a035500.tar.bz2 | |
feature[bgz_388785]: Clean-up duplicate enumerated attributes
8 files changed, 557 insertions, 3 deletions
diff --git a/plugins/org.eclipse.osee.client.integration.tests/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.client.integration.tests/META-INF/MANIFEST.MF index 2c7045f..8e23874 100644 --- a/plugins/org.eclipse.osee.client.integration.tests/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.client.integration.tests/META-INF/MANIFEST.MF @@ -8,7 +8,6 @@ Bundle-Vendor: Eclipse Open System Engineering Environment Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Import-Package: org.eclipse.core.runtime, org.eclipse.osee.ats, - org.eclipse.osee.ats.config.demo, org.eclipse.osee.ats.config.demo.config, org.eclipse.osee.ats.core, @@ -28,6 +27,7 @@ Import-Package: org.eclipse.core.runtime, org.eclipse.osee.coverage.model, org.eclipse.osee.coverage.navigate, org.eclipse.osee.define, + org.eclipse.osee.define.blam.operation, org.eclipse.osee.framework.access.test, org.eclipse.osee.framework.core.client, org.eclipse.osee.framework.core.data, diff --git a/plugins/org.eclipse.osee.define.test/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.define.test/META-INF/MANIFEST.MF index 240d4cf..47397fe 100644 --- a/plugins/org.eclipse.osee.define.test/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.define.test/META-INF/MANIFEST.MF @@ -6,10 +6,14 @@ Bundle-Version: 0.10.2.qualifier Bundle-Vendor: Eclipse Open System Engineering Environment Fragment-Host: org.eclipse.osee.define Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Require-Bundle: org.junit +Require-Bundle: org.junit, + org.mockito;bundle-version="1.9.0", + org.hamcrest.core, + org.objenesis Export-Package: org.eclipse.osee.define, org.eclipse.osee.define.blam.operation Import-Package: org.eclipse.osee.framework.core.data, org.eclipse.osee.framework.database.core, org.eclipse.osee.framework.skynet.core.artifact, + org.eclipse.osee.framework.skynet.core.conflict, org.eclipse.osee.support.test.util diff --git a/plugins/org.eclipse.osee.define.test/src/org/eclipse/osee/define/blam/operation/BlamTestSuite.java b/plugins/org.eclipse.osee.define.test/src/org/eclipse/osee/define/blam/operation/BlamTestSuite.java index 6f812a4..a6458b6 100644 --- a/plugins/org.eclipse.osee.define.test/src/org/eclipse/osee/define/blam/operation/BlamTestSuite.java +++ b/plugins/org.eclipse.osee.define.test/src/org/eclipse/osee/define/blam/operation/BlamTestSuite.java @@ -14,7 +14,7 @@ import org.junit.runner.RunWith; import org.junit.runners.Suite; @RunWith(Suite.class) -@Suite.SuiteClasses({TestPlanComplianceReportTest.class}) +@Suite.SuiteClasses({FixAttributeOperationTest.class, TestPlanComplianceReportTest.class}) public class BlamTestSuite { // } diff --git a/plugins/org.eclipse.osee.define.test/src/org/eclipse/osee/define/blam/operation/FixAttributeOperationTest.java b/plugins/org.eclipse.osee.define.test/src/org/eclipse/osee/define/blam/operation/FixAttributeOperationTest.java new file mode 100644 index 0000000..aee04c8 --- a/dev/null +++ b/plugins/org.eclipse.osee.define.test/src/org/eclipse/osee/define/blam/operation/FixAttributeOperationTest.java @@ -0,0 +1,209 @@ +/******************************************************************************* + * 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.define.blam.operation; + +import static junit.framework.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import java.util.Collections; +import java.util.List; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.osee.define.blam.operation.FixAttributeOperation.Display; +import org.eclipse.osee.framework.core.enums.BranchType; +import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; +import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; +import org.eclipse.osee.framework.core.exception.OseeArgumentException; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.model.Branch; +import org.eclipse.osee.framework.core.operation.IOperation; +import org.eclipse.osee.framework.core.operation.OperationLogger; +import org.eclipse.osee.framework.core.operation.Operations; +import org.eclipse.osee.framework.skynet.core.artifact.Artifact; +import org.eclipse.osee.framework.skynet.core.artifact.BranchManager; +import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery; +import org.eclipse.osee.framework.skynet.core.conflict.ConflictManagerExternal; +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.DemoSawBuilds; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; + +//.mockito.MockitoAnnotations; + +/** + * @author Angel Avila + */ + +public class FixAttributeOperationTest { + + private static final String WORKING_BRANCH_NAME = "BranchWorking"; + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + // @formatter:off + @Mock private OperationLogger logger; + @Mock private Display display; + + @Captor private ArgumentCaptor<List<String[]>> captor; + @Captor private ArgumentCaptor<List<String[]>> captor2; + + // @formatter:on + + private Branch branchWorking; + private String itemId; + + @Before + public void setUp() throws OseeCoreException { + MockitoAnnotations.initMocks(this); + + branchWorking = BranchManager.createWorkingBranch(DemoSawBuilds.SAW_Bld_1, WORKING_BRANCH_NAME); + Branch branch1 = editBranch(branchWorking, "branch1"); + Branch branch2 = editBranch(branchWorking, "branch2"); + + commit(branch1, branchWorking); + commit(branch2, branchWorking); + } + + private Branch editBranch(Branch parentBranch, String workingBranchName) throws OseeCoreException { + String branchName = String.format("%s_%s", FixAttributeOperationTest.class.getSimpleName(), workingBranchName); + Branch branch = BranchManager.createWorkingBranch(parentBranch, branchName); + + Artifact robotAPI = + ArtifactQuery.getArtifactFromTypeAndName(CoreArtifactTypes.SoftwareRequirement, "Robot API", branch); + robotAPI.addAttribute(CoreAttributeTypes.Partition, "Navigation"); + + itemId = robotAPI.getGuid(); + + SkynetTransaction transaction = TransactionManager.createTransaction(branch, "Adding Attribute"); + transaction.addArtifact(robotAPI); + transaction.execute(); + return branch; + } + + private void commit(Branch source, Branch destination) throws OseeCoreException { + boolean archiveSourceBranch = false; + boolean overwriteUnresolvedConflicts = true; + ConflictManagerExternal conflictManager = new ConflictManagerExternal(destination, source); + BranchManager.commitBranch(new NullProgressMonitor(), conflictManager, archiveSourceBranch, + overwriteUnresolvedConflicts); + } + + @After + public void tearDown() throws OseeCoreException { + for (Branch child : branchWorking.getChildBranches()) { + BranchManager.purgeBranch(child); + } + BranchManager.purgeBranch(branchWorking); + } + + @Test + public void testNullBranchCheck() throws OseeCoreException { + thrown.expect(OseeArgumentException.class); + thrown.expectMessage("branch cannot be null"); + + executeOp(null, false); + } + + @Test + public void testNonWorkingBranchCheck() throws OseeCoreException { + Branch mockBranch = Mockito.mock(Branch.class); + when(mockBranch.toString()).thenReturn("mock branch"); + when(mockBranch.getBranchType()).thenReturn(BranchType.BASELINE); + + thrown.expect(OseeArgumentException.class); + thrown.expectMessage("Invalid branch selected [mock branch]. Only working branches are allowed."); + + executeOp(mockBranch, false); + } + + @Test + public void testDetectDuplicatesButDontFix() throws OseeCoreException { + // test multiple runs without committing fixes + for (int i = 0; i < 2; i++) { + reset(display); + + executeOp(branchWorking, false); + + verify(display).displayReport(eq("Fix Duplicate Report"), captor.capture()); + + List<String[]> data = captor.getValue(); + assertRow(data, 0, branchWorking.getName(), itemId, "Robot API", CoreAttributeTypes.Partition.getName(), + "Unspecified, Navigation, Navigation", "Unspecified, Navigation"); + + Artifact testRobotAPI = + ArtifactQuery.getArtifactFromTypeAndName(CoreArtifactTypes.SoftwareRequirement, "Robot API", branchWorking); + + List<String> values = testRobotAPI.getAttributesToStringList(CoreAttributeTypes.Partition); + Collections.sort(values); + assertEquals("Navigation", values.get(0)); + assertEquals("Navigation", values.get(1)); + assertEquals("Unspecified", values.get(2)); + } + } + + @Test + public void testTestFix() throws OseeCoreException { + executeOp(branchWorking, true); + + verify(display).displayReport(eq("Fix Duplicate Report"), captor.capture()); + + //@formatter:off + assertRow(captor.getValue(), 0, branchWorking.getName(), itemId, "Robot API", CoreAttributeTypes.Partition.getName(), "Unspecified, Navigation, Navigation", "Unspecified, Navigation"); + //@formatter: on + + Artifact testRobotAPI = + ArtifactQuery.getArtifactFromTypeAndName(CoreArtifactTypes.SoftwareRequirement, "Robot API", branchWorking); + + List<String> values = testRobotAPI.getAttributesToStringList(CoreAttributeTypes.Partition); + Collections.sort(values); + assertEquals("Navigation", values.get(0)); + assertEquals("Unspecified", values.get(1)); + + // Run Again Empty Report should result + reset(display); + executeOp(branchWorking, true); + + verify(display).displayReport(eq("Fix Duplicate Report"), captor2.capture()); + + String expectedString = "-- no duplicates found --"; + assertRow(captor2.getValue(), 0, expectedString, expectedString, expectedString, expectedString, expectedString, expectedString); + } + + private static void assertRow(List<String[]> data, int index, String... expecteds) { + assertNotNull(data); + assertTrue(data.size() > index); + String[] actuals = data.get(index); + assertEquals(expecteds.length, actuals.length); + + for (int i = 0; i < expecteds.length; i++) { + assertEquals(expecteds[i], actuals[i]); + } + } + + private void executeOp(Branch branch, boolean commitChangesBool) throws OseeCoreException { + IOperation operation = new FixAttributeOperation(logger, display, branch, commitChangesBool); + Operations.executeWorkAndCheckStatus(operation); + } + +} diff --git a/plugins/org.eclipse.osee.define/plugin.xml b/plugins/org.eclipse.osee.define/plugin.xml index 10d3851..9f764b4 100644 --- a/plugins/org.eclipse.osee.define/plugin.xml +++ b/plugins/org.eclipse.osee.define/plugin.xml @@ -250,4 +250,12 @@ className="org.eclipse.osee.define.traceability.blam.AddTraceMarksToTraceUnits"> </Operation> </extension> + <extension + id="FixDuplicateEnumeratedAttributes" + name="FixDuplicateEnumeratedAttributes" + point="org.eclipse.osee.framework.ui.skynet.BlamOperation"> + <Operation + className="org.eclipse.osee.define.blam.operation.FixDuplicateEnumeratedAttributes"> + </Operation> + </extension> </plugin> diff --git a/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/blam/operation/FixAttributeOperation.java b/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/blam/operation/FixAttributeOperation.java new file mode 100644 index 0000000..da3fabf --- a/dev/null +++ b/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/blam/operation/FixAttributeOperation.java @@ -0,0 +1,161 @@ +/******************************************************************************* + * 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.define.blam.operation; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Map.Entry; +import java.util.Set; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.nebula.widgets.xviewer.Activator; +import org.eclipse.osee.framework.core.data.IAttributeType; +import org.eclipse.osee.framework.core.enums.DeletionFlag; +import org.eclipse.osee.framework.core.enums.LoadLevel; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.model.Branch; +import org.eclipse.osee.framework.core.model.type.AttributeType; +import org.eclipse.osee.framework.core.operation.AbstractOperation; +import org.eclipse.osee.framework.core.operation.OperationLogger; +import org.eclipse.osee.framework.core.util.Conditions; +import org.eclipse.osee.framework.jdk.core.type.HashCollection; +import org.eclipse.osee.framework.jdk.core.util.Collections; +import org.eclipse.osee.framework.skynet.core.artifact.Artifact; +import org.eclipse.osee.framework.skynet.core.artifact.ArtifactCache; +import org.eclipse.osee.framework.skynet.core.artifact.Attribute; +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 Angel Avila + */ + +public class FixAttributeOperation extends AbstractOperation { + + public interface Display { + + void displayReport(String reportName, List<String[]> values); + + } + + private final Branch branch; + private final boolean commitChangesBool; + private final Display display; + + public FixAttributeOperation(OperationLogger logger, Display display, Branch branch, boolean commitChangesBool) { + super("FixAttributes", Activator.PLUGIN_ID, logger); + this.branch = branch; + this.commitChangesBool = commitChangesBool; + this.display = display; + } + + private void checkPreConditions() throws OseeCoreException { + Conditions.checkNotNull(branch, "branch"); + // only allow working branches + Conditions.checkExpressionFailOnTrue(!branch.getBranchType().isWorkingBranch(), + "Invalid branch selected [%s]. Only working branches are allowed.", branch); + } + + @Override + protected void doWork(IProgressMonitor monitor) throws Exception { + checkPreConditions(); + + monitor.subTask("Aquiring Artifacts"); + HashCollection<Artifact, IAttributeType> artifactAttributeMap = getArtifactsWithDuplicates(monitor); + + SkynetTransaction transaction = null; + if (commitChangesBool) { + transaction = TransactionManager.createTransaction(branch, "Fixing Duplicate Enumerated Types"); + } + List<String[]> rowData = new ArrayList<String[]>(); + + for (Entry<Artifact, Collection<IAttributeType>> entry : artifactAttributeMap.entrySet()) { + Artifact artifact = entry.getKey(); + for (IAttributeType attributeType : entry.getValue()) { + List<Object> attributeValues = artifact.getAttributeValues(attributeType); + if (hasDuplicates(attributeValues)) { + logf("duplicates found art[%s] attrType[%s] values[%s]", artifact, attributeType, attributeValues); + + artifact.setAttributeFromValues(attributeType, attributeValues); + List<Object> attributeValuesFixed = artifact.getAttributeValues(attributeType); + if (transaction != null) { + transaction.addArtifact(artifact); + } + + rowData.add(new String[] { + branch.getName(), + artifact.getGuid(), + artifact.getName(), + attributeType.getName(), + Collections.toString(", ", attributeValues), + Collections.toString(", ", attributeValuesFixed)}); + } + } + } + + if (rowData.isEmpty()) { + rowData.add(new String[] { + "-- no duplicates found --", + "-- no duplicates found --", + "-- no duplicates found --", + "-- no duplicates found --", + "-- no duplicates found --", + "-- no duplicates found --"}); + } + + display.displayReport("Fix Duplicate Report", rowData); + + if (transaction != null) { + transaction.execute(); + } else { + // Remove dirty artifacts from Cache so we can perform operation again and still get latest artifacts from database + for (Artifact artifact : artifactAttributeMap.keySet()) { + ArtifactCache.deCache(artifact); + } + } + } + + private HashCollection<Artifact, IAttributeType> getArtifactsWithDuplicates(IProgressMonitor monitor) throws OseeCoreException { + HashCollection<Artifact, IAttributeType> artifactAttributeMap = + new HashCollection<Artifact, IAttributeType>(false, HashSet.class); + + List<Artifact> artifacts = + ArtifactQuery.getArtifactListFromBranch(branch, LoadLevel.FULL, DeletionFlag.EXCLUDE_DELETED); + checkForCancelledStatus(monitor); + monitor.subTask("Mapping Enumerated Attributes"); + + for (Artifact artifact : artifacts) { + List<Attribute<?>> attributes = artifact.getAttributes(); + for (Attribute<?> attribute : attributes) { + checkForCancelledStatus(monitor); + AttributeType attributeType = attribute.getAttributeType(); + if (attributeType.isEnumerated()) { + artifactAttributeMap.put(artifact, attributeType); + } + } + } + return artifactAttributeMap; + } + + private boolean hasDuplicates(List<Object> attributeValues) { + boolean result = false; + Set<Object> set = new HashSet<Object>(); + for (Object object : attributeValues) { + if (!set.add(object)) { + result = true; + break; + } + } + return result; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/blam/operation/FixAttributesUIReport.java b/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/blam/operation/FixAttributesUIReport.java new file mode 100644 index 0000000..6d6509f --- a/dev/null +++ b/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/blam/operation/FixAttributesUIReport.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * 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.define.blam.operation; + +import java.util.ArrayList; +import java.util.List; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.nebula.widgets.xviewer.Activator; +import org.eclipse.nebula.widgets.xviewer.XViewerColumn; +import org.eclipse.nebula.widgets.xviewer.XViewerColumn.SortDataType; +import org.eclipse.osee.define.blam.operation.FixAttributeOperation.Display; +import org.eclipse.osee.framework.core.operation.Operations; +import org.eclipse.osee.framework.ui.skynet.results.IResultsEditorProvider; +import org.eclipse.osee.framework.ui.skynet.results.IResultsEditorTab; +import org.eclipse.osee.framework.ui.skynet.results.ResultsEditor; +import org.eclipse.osee.framework.ui.skynet.results.table.IResultsXViewerRow; +import org.eclipse.osee.framework.ui.skynet.results.table.ResultsEditorTableTab; +import org.eclipse.osee.framework.ui.skynet.results.table.ResultsXViewerRow; +import org.eclipse.swt.SWT; +import org.eclipse.ui.progress.UIJob; + +/** + * @author Angel Avila + */ + +public class FixAttributesUIReport implements Display { + + @Override + public void displayReport(String reportName, List<String[]> values) { + List<XViewerColumn> columns = new ArrayList<XViewerColumn>(); + addColumn(columns, "Branch Name"); + addColumn(columns, "Artifact Guid"); + addColumn(columns, "Artifact Name"); + addColumn(columns, "Attribute Type"); + addColumn(columns, "Was Value"); + addColumn(columns, "Fixed Value"); + + List<IResultsXViewerRow> rows = new ArrayList<IResultsXViewerRow>(); + for (String[] row : values) { + rows.add(new ResultsXViewerRow(row)); + } + + List<IResultsEditorTab> tabs = new ArrayList<IResultsEditorTab>(); + tabs.add(new ResultsEditorTableTab("Results", columns, rows)); + + ReportProvider report = new ReportProvider(reportName, tabs); + openReport(report); + } + + private void addColumn(List<XViewerColumn> columns, String name) { + columns.add(new XViewerColumn(name, name, 120, SWT.LEFT, true, SortDataType.String, false, "")); + } + + private void openReport(final ReportProvider report) { + Job job = new UIJob(report.getEditorName()) { + @Override + public IStatus runInUIThread(IProgressMonitor monitor) { + IStatus status; + try { + ResultsEditor.open(report); + status = Status.OK_STATUS; + } catch (Exception ex) { + String message = String.format("Error creating [%s] Report", getName()); + status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, message, ex); + } + return status; + } + }; + Operations.scheduleJob(job, true, Job.SHORT, null); + } + + private static final class ReportProvider implements IResultsEditorProvider { + private final List<IResultsEditorTab> resultsTabs; + private final String editorName; + + public ReportProvider(String editorName, List<IResultsEditorTab> resultsTabs) { + this.resultsTabs = resultsTabs; + this.editorName = editorName; + } + + @Override + public String getEditorName() { + return editorName; + } + + @Override + public List<IResultsEditorTab> getResultsEditorTabs() { + return resultsTabs; + } + } +} diff --git a/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/blam/operation/FixDuplicateEnumeratedAttributes.java b/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/blam/operation/FixDuplicateEnumeratedAttributes.java new file mode 100644 index 0000000..73b2ecf --- a/dev/null +++ b/plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/blam/operation/FixDuplicateEnumeratedAttributes.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * 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.define.blam.operation; + +import java.util.Arrays; +import java.util.Collection; +import org.eclipse.osee.define.blam.operation.FixAttributeOperation.Display; +import org.eclipse.osee.framework.core.data.IOseeBranch; +import org.eclipse.osee.framework.core.model.Branch; +import org.eclipse.osee.framework.core.operation.IOperation; +import org.eclipse.osee.framework.core.operation.OperationLogger; +import org.eclipse.osee.framework.skynet.core.artifact.BranchManager; +import org.eclipse.osee.framework.ui.skynet.blam.AbstractBlam; +import org.eclipse.osee.framework.ui.skynet.blam.VariableMap; + +/** + * @author Angel Avila + */ +public class FixDuplicateEnumeratedAttributes extends AbstractBlam { + + public static String SELECT_BRANCH_LABEL = "Select Branch"; + public static String COMMIT_CHANGES_LABEL = "Commit Changes to Branch?"; + + @Override + public String getName() { + return "Fix Duplicate Enumerated Attributes"; + } + + @Override + public String getXWidgetsXml() { + StringBuilder builder = new StringBuilder(); + builder.append("<XWidgets>"); + builder.append("<XWidget xwidgetType=\"XBranchSelectWidget\" multiSelect=\"false\" displayName=\""); + builder.append(SELECT_BRANCH_LABEL); + builder.append("\" />"); + builder.append("<XWidget xwidgetType=\"XCheckBox\" displayName=\""); + builder.append(COMMIT_CHANGES_LABEL); + builder.append("\" labelAfter=\"true\" horizontalLabel=\"true\" />"); + builder.append("</XWidgets>"); + return builder.toString(); + } + + @Override + public IOperation createOperation(VariableMap variableMap, OperationLogger logger) throws Exception { + IOseeBranch branch = variableMap.getBranch(SELECT_BRANCH_LABEL); + boolean commitChangesBool = variableMap.getBoolean(COMMIT_CHANGES_LABEL); + + Branch fullBranch = BranchManager.getBranch(branch); + Display display = new FixAttributesUIReport(); + return new FixAttributeOperation(logger, display, fullBranch, commitChangesBool); + } + + @Override + public String getDescriptionUsage() { + return "Remove duplciate enumerated attributes"; + } + + @Override + public Collection<String> getCategories() { + return Arrays.asList("Define"); + } +}
\ No newline at end of file |

