diff options
Diffstat (limited to 'plugins')
7 files changed, 161 insertions, 59 deletions
diff --git a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/navigate/AtsTest_Navigate_Suite.java b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/navigate/AtsTest_Navigate_Suite.java index 564d82ba6a3..22178819efa 100644 --- a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/navigate/AtsTest_Navigate_Suite.java +++ b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/navigate/AtsTest_Navigate_Suite.java @@ -22,6 +22,7 @@ import org.junit.runners.Suite; */ @RunWith(Suite.class) @Suite.SuiteClasses({ + SubscribeUtilityTest.class, AtsNavigateItemsToMassEditorTest.class, AtsNavigateItemsToTaskEditorTest.class, AtsNavigateItemsToWorldViewTest.class}) diff --git a/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/navigate/SubscribeUtilityTest.java b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/navigate/SubscribeUtilityTest.java new file mode 100644 index 00000000000..7110b1211dc --- /dev/null +++ b/plugins/org.eclipse.osee.ats.client.integration.tests/src/org/eclipse/osee/ats/client/integration/tests/ats/navigate/SubscribeUtilityTest.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2013 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.ats.client.integration.tests.ats.navigate; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import org.eclipse.osee.ats.api.data.AtsArtifactTypes; +import org.eclipse.osee.ats.client.demo.DemoArtifactToken; +import org.eclipse.osee.ats.client.demo.DemoUsers; +import org.eclipse.osee.ats.navigate.SubscribeUtility; +import org.eclipse.osee.ats.util.AtsUtil; +import org.eclipse.osee.framework.core.enums.CoreRelationTypes; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.skynet.core.artifact.Artifact; +import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Test case for {@link SubscribeUtility} + * + * @author Donald G. Dunne + */ +public class SubscribeUtilityTest { + + @BeforeClass + @AfterClass + public static void cleanup() throws OseeCoreException { + Artifact userArt = getAlexUserArtifact(); + userArt.deleteRelations(CoreRelationTypes.Users_Artifact); + userArt.persist(SubscribeUtilityTest.class.getSimpleName() + " - cleanup"); + } + + @Test + public void test() throws OseeCoreException { + Artifact alexUserArt = getAlexUserArtifact(); + Assert.assertEquals("Should be nothing subscribed by alex", 0, + alexUserArt.getRelatedArtifactsCount(CoreRelationTypes.Users_Artifact)); + + // Subscribe to 2 team definitions + Artifact cisCodeTeam = + ArtifactQuery.getArtifactFromToken(DemoArtifactToken.CIS_Code, AtsUtil.getAtsBranchToken()); + Artifact cisSwTeam = ArtifactQuery.getArtifactFromToken(DemoArtifactToken.CIS_SW, AtsUtil.getAtsBranchToken()); + + SubscribeUtility.setSubcriptionsAndPersist(alexUserArt, CoreRelationTypes.Users_Artifact, + Arrays.asList(cisCodeTeam, cisSwTeam), AtsArtifactTypes.TeamDefinition, getClass().getSimpleName()); + List<Artifact> subscribed = alexUserArt.getRelatedArtifacts(CoreRelationTypes.Users_Artifact); + Assert.assertTrue("CIS Code should be subscribed", subscribed.contains(cisCodeTeam)); + Assert.assertTrue("CIS SW should be subscribed", subscribed.contains(cisSwTeam)); + Assert.assertFalse("User artifact changes should be persisted", alexUserArt.isDirty()); + + // Remove one, add another + Artifact cisTestTeam = + ArtifactQuery.getArtifactFromToken(DemoArtifactToken.CIS_Test, AtsUtil.getAtsBranchToken()); + + SubscribeUtility.setSubcriptionsAndPersist(alexUserArt, CoreRelationTypes.Users_Artifact, + Arrays.asList(cisCodeTeam, cisTestTeam), AtsArtifactTypes.TeamDefinition, getClass().getSimpleName()); + subscribed = alexUserArt.getRelatedArtifacts(CoreRelationTypes.Users_Artifact); + Assert.assertTrue("CIS Code should be subscribed", subscribed.contains(cisCodeTeam)); + Assert.assertFalse("CIS SW should NOT be subscribed", subscribed.contains(cisSwTeam)); + Assert.assertTrue("CIS Test should be subscribed", subscribed.contains(cisTestTeam)); + Assert.assertFalse("User artifact changes should be persisted", alexUserArt.isDirty()); + + // Un-subscribe all + SubscribeUtility.setSubcriptionsAndPersist(alexUserArt, CoreRelationTypes.Users_Artifact, + new ArrayList<Artifact>(), AtsArtifactTypes.TeamDefinition, getClass().getSimpleName()); + subscribed = alexUserArt.getRelatedArtifacts(CoreRelationTypes.Users_Artifact); + Assert.assertTrue("No subscriptions remain", subscribed.isEmpty()); + Assert.assertFalse("User artifact changes should be persisted", alexUserArt.isDirty()); + } + + private static Artifact getAlexUserArtifact() throws OseeCoreException { + return ArtifactQuery.getArtifactFromToken(DemoUsers.Alex_Kay, AtsUtil.getAtsBranchToken()); + } + +} diff --git a/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/navigate/SubscribeByActionableItem.java b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/navigate/SubscribeByActionableItem.java index c7311ec6889..4a7cc46ba2f 100644 --- a/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/navigate/SubscribeByActionableItem.java +++ b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/navigate/SubscribeByActionableItem.java @@ -15,6 +15,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.eclipse.osee.ats.api.ai.IAtsActionableItem; +import org.eclipse.osee.ats.api.data.AtsArtifactTypes; import org.eclipse.osee.ats.api.data.AtsRelationTypes; import org.eclipse.osee.ats.internal.Activator; import org.eclipse.osee.ats.internal.AtsClientService; @@ -55,9 +56,8 @@ public class SubscribeByActionableItem extends XNavigateItemAction { Collection<IAtsActionableItem> selected = diag.getChecked(); Collection<Artifact> arts = AtsClientService.get().getConfigArtifacts(selected); - AtsClientService.get().getUserAdmin().getCurrentOseeUser().setRelationsOfTypeUseCurrentOrder( - AtsRelationTypes.SubscribedUser_Artifact, arts, IAtsActionableItem.class); - AtsClientService.get().getUserAdmin().getCurrentOseeUser().persist(getClass().getSimpleName()); + SubscribeUtility.setSubcriptionsAndPersist(AtsClientService.get().getUserAdmin().getCurrentOseeUser(), + AtsRelationTypes.SubscribedUser_Artifact, arts, AtsArtifactTypes.ActionableItem, getClass().getSimpleName()); AWorkbench.popup(getName(), "Subscriptions updated."); } catch (Exception ex) { OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex); diff --git a/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/navigate/SubscribeByTeamDefinition.java b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/navigate/SubscribeByTeamDefinition.java index 43ea621f684..95facfdfdd0 100644 --- a/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/navigate/SubscribeByTeamDefinition.java +++ b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/navigate/SubscribeByTeamDefinition.java @@ -14,6 +14,7 @@ package org.eclipse.osee.ats.navigate; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import org.eclipse.osee.ats.api.data.AtsArtifactTypes; import org.eclipse.osee.ats.api.data.AtsRelationTypes; import org.eclipse.osee.ats.api.team.IAtsTeamDefinition; import org.eclipse.osee.ats.internal.Activator; @@ -42,12 +43,16 @@ public class SubscribeByTeamDefinition extends XNavigateItemAction { public void run(TableLoadOption... tableLoadOptions) { final TeamDefinitionCheckTreeDialog diag = new TeamDefinitionCheckTreeDialog(getName(), - "Select Team Definition\n\nEmail will be sent for every Action created against these Teams.", Active.Active); + "Select Team Definition\n\nEmail will be sent for every Action created against these Teams.", + Active.Active, false); try { List<IAtsTeamDefinition> objs = new ArrayList<IAtsTeamDefinition>(); - objs.addAll(AtsClientService.get().getConfigObjects( - AtsClientService.get().getUserAdmin().getCurrentOseeUser().getRelatedArtifacts( - AtsRelationTypes.SubscribedUser_Artifact), IAtsTeamDefinition.class)); + for (Artifact art : AtsClientService.get().getUserAdmin().getCurrentOseeUser().getRelatedArtifacts( + AtsRelationTypes.SubscribedUser_Artifact)) { + if (art.isOfType(AtsArtifactTypes.TeamDefinition)) { + objs.add((IAtsTeamDefinition) AtsClientService.get().getConfigObject(art)); + } + } diag.setInitialTeamDefs(objs); if (diag.open() != 0) { return; @@ -55,9 +60,8 @@ public class SubscribeByTeamDefinition extends XNavigateItemAction { Collection<IAtsTeamDefinition> selected = diag.getChecked(); Collection<Artifact> arts = AtsClientService.get().getConfigArtifacts(selected); - AtsClientService.get().getUserAdmin().getCurrentOseeUser().setRelationsOfTypeUseCurrentOrder( - AtsRelationTypes.SubscribedUser_Artifact, arts, IAtsTeamDefinition.class); - AtsClientService.get().getUserAdmin().getCurrentOseeUser().persist(getClass().getSimpleName()); + SubscribeUtility.setSubcriptionsAndPersist(AtsClientService.get().getUserAdmin().getCurrentOseeUser(), + AtsRelationTypes.SubscribedUser_Artifact, arts, AtsArtifactTypes.TeamDefinition, getClass().getSimpleName()); AWorkbench.popup(getName(), "Subscriptions updated."); } catch (Exception ex) { OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex); diff --git a/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/navigate/SubscribeUtility.java b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/navigate/SubscribeUtility.java new file mode 100644 index 00000000000..52930b4de45 --- /dev/null +++ b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/navigate/SubscribeUtility.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2013 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.ats.navigate; + +import java.util.Collection; +import org.eclipse.osee.framework.core.data.IArtifactType; +import org.eclipse.osee.framework.core.data.IRelationTypeSide; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.skynet.core.artifact.Artifact; +import org.eclipse.osee.framework.skynet.core.relation.RelationManager; +import org.eclipse.osee.framework.skynet.core.relation.RelationTypeSideSorter; + +/** + * @author Donald G. Dunne + */ +public class SubscribeUtility { + + /** + * Creates new subscriptions that don't already exist and removes relations to subscriptions that are not in + * collection + * + * @param artifacts to subscribe or empty to remove all + */ + public static final void setSubcriptionsAndPersist(Artifact userArtifact, IRelationTypeSide relationSide, Collection<? extends Artifact> artifacts, IArtifactType artifactType, String persistComment) throws OseeCoreException { + RelationTypeSideSorter sorter = + RelationManager.createTypeSideSorter(userArtifact, relationSide, relationSide.getSide()); + Collection<Artifact> currentlyRelated = userArtifact.getRelatedArtifacts(relationSide, Artifact.class); + // Add new relations if don't exist + for (Artifact art : artifacts) { + if (art.isOfType(artifactType) && !currentlyRelated.contains(art)) { + userArtifact.addRelation(sorter.getSorterId(), relationSide, art); + } + } + // Remove relations that have been removed + for (Artifact artifact : currentlyRelated) { + if (artifact.isOfType(artifactType) && !artifacts.contains(artifact)) { + userArtifact.deleteRelation(relationSide, artifact); + } + } + userArtifact.persist(persistComment); + } +} diff --git a/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/util/widgets/dialog/TeamDefinitionCheckTreeDialog.java b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/util/widgets/dialog/TeamDefinitionCheckTreeDialog.java index 34147d505b0..019f1be22c6 100644 --- a/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/util/widgets/dialog/TeamDefinitionCheckTreeDialog.java +++ b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/util/widgets/dialog/TeamDefinitionCheckTreeDialog.java @@ -16,10 +16,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.osee.ats.api.team.IAtsTeamDefinition; -import org.eclipse.osee.ats.core.config.ActionableItems; import org.eclipse.osee.ats.core.config.TeamDefinitions; import org.eclipse.osee.ats.internal.Activator; import org.eclipse.osee.ats.util.AtsObjectLabelProvider; @@ -27,7 +24,6 @@ import org.eclipse.osee.framework.core.enums.Active; import org.eclipse.osee.framework.core.util.Result; import org.eclipse.osee.framework.logging.OseeLevel; import org.eclipse.osee.framework.logging.OseeLog; -import org.eclipse.osee.framework.ui.plugin.util.AWorkbench; import org.eclipse.osee.framework.ui.skynet.util.ArtifactNameSorter; import org.eclipse.osee.framework.ui.skynet.util.filteredTree.OSEECheckedFilteredTreeDialog; import org.eclipse.swt.widgets.Composite; @@ -40,11 +36,13 @@ public class TeamDefinitionCheckTreeDialog extends OSEECheckedFilteredTreeDialog private final Active active; private List<IAtsTeamDefinition> initialTeamDefs; + private final boolean requiredSelection; - public TeamDefinitionCheckTreeDialog(String title, String message, Active active) { + public TeamDefinitionCheckTreeDialog(String title, String message, Active active, boolean requiredSelection) { super(title, message, new TeamDefinitionTreeContentProvider(active), new AtsObjectLabelProvider(), new ArtifactNameSorter()); this.active = active; + this.requiredSelection = requiredSelection; } public Collection<IAtsTeamDefinition> getChecked() { @@ -63,20 +61,6 @@ public class TeamDefinitionCheckTreeDialog extends OSEECheckedFilteredTreeDialog Control comp = super.createDialogArea(container); try { getTreeViewer().getViewer().setInput(TeamDefinitions.getTopLevelTeamDefinitions(active)); - getTreeViewer().getViewer().addSelectionChangedListener(new ISelectionChangedListener() { - @Override - public void selectionChanged(SelectionChangedEvent event) { - try { - for (IAtsTeamDefinition teamDef : getChecked()) { - if (!teamDef.isActionable()) { - AWorkbench.popup("ERROR", ActionableItems.getNotActionableItemError(teamDef)); - } - } - } catch (Exception ex) { - OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex); - } - } - }); if (getInitialTeamDefs() != null) { getTreeViewer().setInitalChecked(getInitialTeamDefs()); } @@ -88,16 +72,15 @@ public class TeamDefinitionCheckTreeDialog extends OSEECheckedFilteredTreeDialog @Override protected Result isComplete() { + Result result = Result.TrueResult; try { - for (IAtsTeamDefinition aia : getChecked()) { - if (!aia.isActionable()) { - return Result.FalseResult; - } + if (requiredSelection && getChecked().isEmpty()) { + result = new Result("Must select Team Definition(s)"); } } catch (Exception ex) { OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex); } - return super.isComplete(); + return result; } /** diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/Artifact.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/Artifact.java index fa5767cf2ff..d2f3f7c9d12 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/Artifact.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/Artifact.java @@ -80,13 +80,14 @@ import org.eclipse.osee.framework.skynet.core.internal.ServiceUtil; import org.eclipse.osee.framework.skynet.core.relation.RelationLink; import org.eclipse.osee.framework.skynet.core.relation.RelationManager; import org.eclipse.osee.framework.skynet.core.relation.RelationTypeManager; -import org.eclipse.osee.framework.skynet.core.relation.RelationTypeSideSorter; import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction; import org.eclipse.osee.framework.skynet.core.transaction.TransactionManager; import org.eclipse.osee.framework.skynet.core.types.IArtifact; /** * {@link ArtifactTest} + * + * @author Ryan D. Brooks */ public class Artifact extends NamedIdentity<String> implements IArtifact, IAdaptable, IBasicGuidArtifact { @@ -284,7 +285,6 @@ public class Artifact extends NamedIdentity<String> implements IArtifact, IAdapt /** * @return Returns a list of parents starting with this Artifact and ending with the same Artifact that is returned * from getArtifactRoot(). - * @throws OseeCoreException */ public final List<Artifact> getAncestors() throws OseeCoreException { List<Artifact> ancestors = new ArrayList<Artifact>(); @@ -1183,9 +1183,6 @@ public class Artifact extends NamedIdentity<String> implements IArtifact, IAdapt * </pre> * * </p> - * - * @param managedTransaction - * @throws OseeCoreException */ public final void persist(SkynetTransaction managedTransaction) throws OseeCoreException { managedTransaction.addArtifact(this); @@ -1371,26 +1368,6 @@ public class Artifact extends NamedIdentity<String> implements IArtifact, IAdapt setRelations(RelationOrderBaseTypes.PREEXISTING, relationSide, artifacts); } - /** - * Creates new relations that don't already exist and removes relations to artifacts that are not in collection - */ - public final void setRelationsOfTypeUseCurrentOrder(IRelationTypeSide relationSide, Collection<? extends Artifact> artifacts, Class<?> clazz) throws OseeCoreException { - RelationTypeSideSorter sorter = RelationManager.createTypeSideSorter(this, relationSide, relationSide.getSide()); - Collection<Artifact> currentlyRelated = getRelatedArtifacts(relationSide, Artifact.class); - // Add new relations if don't exist - for (Artifact artifact : artifacts) { - if (clazz.isInstance(artifact) && !currentlyRelated.contains(artifact)) { - addRelation(sorter.getSorterId(), relationSide, artifact); - } - } - // Remove relations that have been removed - for (Artifact artifact : currentlyRelated) { - if (clazz.isInstance(artifact) && !artifacts.contains(artifact)) { - deleteRelation(relationSide, artifact); - } - } - } - public final boolean isLinksLoaded() { return linksLoaded; } |