diff options
5 files changed, 78 insertions, 42 deletions
diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/event/ArtifactEventFiltersTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/event/ArtifactEventFiltersTest.java index bee74098ac5..cebd579adde 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/event/ArtifactEventFiltersTest.java +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/test/event/ArtifactEventFiltersTest.java @@ -13,8 +13,7 @@ package org.eclipse.osee.framework.skynet.core.test.event; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.junit.Assert; -import org.eclipse.osee.framework.core.data.IOseeBranch; +import junit.framework.Assert; import org.eclipse.osee.framework.core.data.TokenFactory; import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; import org.eclipse.osee.framework.jdk.core.util.GUID; @@ -73,27 +72,27 @@ public class ArtifactEventFiltersTest { EventBasicGuidArtifact guidArt = new EventBasicGuidArtifact(EventModType.Added, GUID.create(), CoreArtifactTypes.Requirement.getGuid(), GUID.create()); + List<EventBasicGuidArtifact> guidArts = Arrays.asList(guidArt); - Assert.assertTrue("Should match cause same artifact type", typeFilter.isMatch(guidArt)); + Assert.assertTrue("Should match cause same artifact type", typeFilter.isMatchArtifacts(guidArts)); guidArt.setArtTypeGuid(CoreArtifactTypes.SoftwareRequirement.getGuid()); Assert.assertTrue("Should match cause SoftwareRequirement is subclass of Requirement", - typeFilter.isMatch(guidArt)); + typeFilter.isMatchArtifacts(guidArts)); typeFilter = new ArtifactTypeEventFilter(CoreArtifactTypes.SoftwareRequirement); guidArt.setArtTypeGuid(CoreArtifactTypes.Requirement.getGuid()); Assert.assertFalse("Should NOT match cause Requirement is NOT subclass of Software Requirement", - typeFilter.isMatch(guidArt)); + typeFilter.isMatchArtifacts(guidArts)); } private void testArtifactEventFilters__branchFilter() throws Exception { // Create dummy artifact event String branchGuid = GUID.create(); - IOseeBranch branchToken = TokenFactory.createBranch(branchGuid, "test branch"); - ArtifactEvent testArtifactEvent = new ArtifactEvent(branchToken); + ArtifactEvent testArtifactEvent = new ArtifactEvent(TokenFactory.createBranch(branchGuid, "test branch")); testArtifactEvent.setNetworkSender(getDummyRemoteNetworkSender()); // Register set filters to null to see if event comes through @@ -139,18 +138,18 @@ public class ArtifactEventFiltersTest { private void testArtifactEventFilters__branchFilterArtifactType() throws Exception { // Create dummy artifact event String branchGuid = GUID.create(); - IOseeBranch branchToken = TokenFactory.createBranch(branchGuid, "test branch 2"); - ArtifactEvent testArtifactEvent = new ArtifactEvent(branchToken); + ArtifactEvent testArtifactEvent = new ArtifactEvent(TokenFactory.createBranch(branchGuid, "test branch 2")); testArtifactEvent.setNetworkSender(getDummyRemoteNetworkSender()); testArtifactEvent.getArtifacts().add( new EventBasicGuidArtifact(EventModType.Added, branchGuid, CoreArtifactTypes.GeneralDocument.getGuid(), GUID.create())); + testArtifactEvent.getArtifacts().add( + new EventBasicGuidArtifact(EventModType.Added, branchGuid, CoreArtifactTypes.Component.getGuid(), + GUID.create())); // Reset event filters only allow events from this branch eventFilters = new ArrayList<IEventFilter>(); - - IOseeBranch branchToken2 = TokenFactory.createBranch(branchGuid, "Test Branch"); - eventFilters.add(new BranchGuidEventFilter(branchToken2)); + eventFilters.add(new BranchGuidEventFilter(TokenFactory.createBranch(branchGuid, "Test Branch"))); eventFilters.add(new ArtifactTypeEventFilter(CoreArtifactTypes.GeneralDocument)); resultArtifactEvent = null; resultSender = null; @@ -165,9 +164,7 @@ public class ArtifactEventFiltersTest { // Reset event filters to only send other artifact type of this branch eventFilters = new ArrayList<IEventFilter>(); - - IOseeBranch branchToken3 = TokenFactory.createBranch(branchGuid, "Test Branch"); - eventFilters.add(new BranchGuidEventFilter(branchToken3)); + eventFilters.add(new BranchGuidEventFilter(TokenFactory.createBranch(branchGuid, "Test Branch"))); eventFilters.add(new ArtifactTypeEventFilter(CoreArtifactTypes.Folder)); resultArtifactEvent = null; resultSender = null; @@ -180,9 +177,7 @@ public class ArtifactEventFiltersTest { // Reset event filters to only send OTHER branch events eventFilters = new ArrayList<IEventFilter>(); - - IOseeBranch branchToken4 = TokenFactory.createBranch(GUID.create(), "Other Test Branch"); - eventFilters.add(new BranchGuidEventFilter(branchToken4)); + eventFilters.add(new BranchGuidEventFilter(TokenFactory.createBranch(GUID.create(), "Other Test Branch"))); eventFilters.add(new ArtifactTypeEventFilter(CoreArtifactTypes.GeneralDocument)); resultArtifactEvent = null; resultSender = null; diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/filter/ArtifactTypeEventFilter.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/filter/ArtifactTypeEventFilter.java index bfee2107dbe..faea47d359c 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/filter/ArtifactTypeEventFilter.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/filter/ArtifactTypeEventFilter.java @@ -10,7 +10,9 @@ *******************************************************************************/ package org.eclipse.osee.framework.skynet.core.event.filter; +import java.util.Arrays; import java.util.Collection; +import java.util.List; import java.util.logging.Level; import org.eclipse.osee.framework.core.data.IArtifactType; import org.eclipse.osee.framework.core.model.event.IBasicGuidArtifact; @@ -35,16 +37,25 @@ public class ArtifactTypeEventFilter implements IEventFilter { this.artifactTypes = Collections.getAggregate(artifactTypes); } + /** + * Return true if any artifact matches any of the desired artifact types + */ @Override - public boolean isMatch(IBasicGuidArtifact guidArt) { + public boolean isMatchArtifacts(List<? extends IBasicGuidArtifact> guidArts) { try { - ArtifactType artType = ArtifactTypeManager.getTypeByGuid(guidArt.getArtTypeGuid()); - for (IArtifactType artifactType : artifactTypes) { - if (artType.inheritsFrom(artifactType)) { - return true; + for (IBasicGuidArtifact guidArt : guidArts) { + ArtifactType artType = ArtifactTypeManager.getTypeByGuid(guidArt.getArtTypeGuid()); + for (IArtifactType artifactType : artifactTypes) { + if (artType.inheritsFrom(artifactType)) { + return true; + } + for (IArtifactType matchArtType : artifactTypes) { + if (matchArtType.getGuid().equals(artType.getGuid())) { + return true; + } + } } } - return this.artifactTypes.contains(guidArt.getArtTypeGuid()); } catch (Exception ex) { OseeLog.log(Activator.class, Level.SEVERE, ex); @@ -52,9 +63,17 @@ public class ArtifactTypeEventFilter implements IEventFilter { return false; } + /** + * Return true if any artifact on either side of relation matches any of the desired artifact types + */ @Override - public boolean isMatch(IBasicGuidRelation relArt) { - return isMatch(relArt.getArtA()) || isMatch(relArt.getArtB()); + public boolean isMatchRelationArtifacts(List<? extends IBasicGuidRelation> relations) { + for (IBasicGuidRelation relation : relations) { + if (isMatchArtifacts(Arrays.asList(relation.getArtA(), relation.getArtB()))) { + return true; + } + } + return false; } @Override diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/filter/BranchGuidEventFilter.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/filter/BranchGuidEventFilter.java index d6d1fea02c3..5ba9c7e4eb0 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/filter/BranchGuidEventFilter.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/filter/BranchGuidEventFilter.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.osee.framework.skynet.core.event.filter; +import java.util.List; import org.eclipse.osee.framework.core.data.IOseeBranch; import org.eclipse.osee.framework.core.model.event.IBasicGuidArtifact; import org.eclipse.osee.framework.core.model.event.IBasicGuidRelation; @@ -39,15 +40,31 @@ public class BranchGuidEventFilter implements IEventFilter { } @Override - public boolean isMatch(IBasicGuidArtifact guidArt) { - return branchToken.getGuid().equals(guidArt.getBranchGuid()); + public boolean isMatchArtifacts(List<? extends IBasicGuidArtifact> guidArts) { + if (guidArts.isEmpty()) { + return true; + } + for (IBasicGuidArtifact guidArt : guidArts) { + if (branchToken.getGuid().equals(guidArt.getBranchGuid())) { + return true; + } + } + return false; } @Override - public boolean isMatch(IBasicGuidRelation relArt) { - return branchToken.getGuid().equals(relArt.getArtA().getBranchGuid()) || - // - branchToken.getGuid().equals(relArt.getArtB().getBranchGuid()); + public boolean isMatchRelationArtifacts(List<? extends IBasicGuidRelation> relations) { + if (relations.isEmpty()) { + return true; + } + for (IBasicGuidRelation rel : relations) { + if (branchToken.getGuid().equals(rel.getArtA().getBranchGuid()) || + // + branchToken.getGuid().equals(rel.getArtB().getBranchGuid())) { + return true; + } + } + return false; } @Override diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/filter/IEventFilter.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/filter/IEventFilter.java index 7e290e97f4b..361368e5a69 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/filter/IEventFilter.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/filter/IEventFilter.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.osee.framework.skynet.core.event.filter; +import java.util.List; import org.eclipse.osee.framework.core.model.event.IBasicGuidArtifact; import org.eclipse.osee.framework.core.model.event.IBasicGuidRelation; @@ -26,11 +27,11 @@ public interface IEventFilter { /** * return true if events for this this guid artifact should be passed through to listeners */ - public boolean isMatch(IBasicGuidArtifact guidArt); + public boolean isMatchArtifacts(List<? extends IBasicGuidArtifact> guidArts); /** * return true if events for this guid relation should be passed through to listeners */ - public boolean isMatch(IBasicGuidRelation relArt); + public boolean isMatchRelationArtifacts(List<? extends IBasicGuidRelation> relations); } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/systems/InternalEventManager.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/systems/InternalEventManager.java index 26eeca09624..22852d16f99 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/systems/InternalEventManager.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/systems/InternalEventManager.java @@ -40,8 +40,6 @@ import org.eclipse.osee.framework.skynet.core.event.model.ArtifactEvent; import org.eclipse.osee.framework.skynet.core.event.model.BranchEvent; import org.eclipse.osee.framework.skynet.core.event.model.BranchEventType; import org.eclipse.osee.framework.skynet.core.event.model.BroadcastEvent; -import org.eclipse.osee.framework.skynet.core.event.model.EventBasicGuidArtifact; -import org.eclipse.osee.framework.skynet.core.event.model.EventBasicGuidRelation; import org.eclipse.osee.framework.skynet.core.event.model.RemoteEventServiceEventType; import org.eclipse.osee.framework.skynet.core.event.model.Sender; import org.eclipse.osee.framework.skynet.core.event.model.TransactionEvent; @@ -171,13 +169,19 @@ public class InternalEventManager { if (!eventFilter.isMatch(artifactEvent.getBranchGuid())) { return; } - for (EventBasicGuidArtifact guidArt : artifactEvent.getArtifacts()) { - if (!eventFilter.isMatch(guidArt)) { - return; + // Process artifacts and relations only if there were any in this ArtifactEvent + if (!artifactEvent.getArtifacts().isEmpty() || !artifactEvent.getRelations().isEmpty()) { + boolean matchFound = false; + // If artifacts are in event and one or more match, pass events through + if (!artifactEvent.getArtifacts().isEmpty() && eventFilter.isMatchArtifacts(artifactEvent.getArtifacts())) { + matchFound = true; } - } - for (EventBasicGuidRelation guidRel : artifactEvent.getRelations()) { - if (!eventFilter.isMatch(guidRel)) { + // If relations are in event and one or more artifacts of the relations match, pass events through + if (!matchFound && !artifactEvent.getRelations().isEmpty() && eventFilter.isMatchRelationArtifacts(artifactEvent.getRelations())) { + matchFound = true; + } + // If no match, don't pass events through + if (!matchFound) { return; } } |