diff options
author | Ryan D. Brooks | 2016-10-21 18:11:44 +0000 |
---|---|---|
committer | Ryan D. Brooks | 2019-08-22 22:02:57 +0000 |
commit | d8b45899c24b4e99e7158ed1966ce2c6b731e69f (patch) | |
tree | 2595e2476aec80ff9146e69de33ebd3a27bb8fe4 | |
parent | eea65e59762fc0df423b98c104083f9492f0514c (diff) | |
download | org.eclipse.osee-d8b45899c24b4e99e7158ed1966ce2c6b731e69f.tar.gz org.eclipse.osee-d8b45899c24b4e99e7158ed1966ce2c6b731e69f.tar.xz org.eclipse.osee-d8b45899c24b4e99e7158ed1966ce2c6b731e69f.zip |
refactor: Use ArtifactId in RelationCache 2
5 files changed, 48 insertions, 51 deletions
diff --git a/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/LoadDeletedRelationTest.java b/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/LoadDeletedRelationTest.java index f8fb6a5aa85..6adb0eb82f9 100644 --- a/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/LoadDeletedRelationTest.java +++ b/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/LoadDeletedRelationTest.java @@ -62,7 +62,7 @@ public class LoadDeletedRelationTest { public void loadDeletedRelationTest() { RelationManager.addRelation(type, left, right, ""); left.persist(getClass().getSimpleName()); - RelationLink loaded = RelationManager.getLoadedRelation(type, left, right, SAW_Bld_2); + RelationLink loaded = RelationManager.getLoadedRelation(type, left, right); GammaId oldGammaId = loaded.getGammaId(); RelationManager.deleteRelation(type, left, right); left.persist(getClass().getSimpleName()); diff --git a/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/RelationCacheTest.java b/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/RelationCacheTest.java index a40c804182e..620aade972e 100644 --- a/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/RelationCacheTest.java +++ b/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/RelationCacheTest.java @@ -19,6 +19,7 @@ import org.eclipse.osee.client.test.framework.OseeClientIntegrationRule; import org.eclipse.osee.client.test.framework.OseeLogMonitor; import org.eclipse.osee.client.test.framework.OseeLogMonitorRule; import org.eclipse.osee.framework.core.data.ApplicabilityId; +import org.eclipse.osee.framework.core.data.ArtifactToken; import org.eclipse.osee.framework.core.data.BranchId; import org.eclipse.osee.framework.core.data.GammaId; import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; @@ -54,6 +55,9 @@ public class RelationCacheTest { private final Artifact artifact1 = new Artifact(branch1); private final Artifact artifact2 = new Artifact(branch2); + private final ArtifactToken art22 = ArtifactToken.valueOf(22, branch1); + private final ArtifactToken art44 = ArtifactToken.valueOf(44, branch1); + private final ArtifactToken art77 = ArtifactToken.valueOf(77, branch2); private List<RelationLink> sourceLinksRelType1; private List<RelationLink> sourceLinksRelType2; @@ -204,40 +208,36 @@ public class RelationCacheTest { relCache.cache(artifact2, link22); RelationLink actual = null; + ArtifactToken art1WrongBranch = ArtifactToken.valueOf(artifact1, branch2); + ArtifactToken art2WrongBranch = ArtifactToken.valueOf(artifact2, branch1); // Find Relation Link Id 1 - - actual = relCache.getByRelIdOnArtifact(1, artifact1.getArtId(), 0, artifact1.getBranch()); + actual = relCache.getByRelIdOnArtifact(1, artifact1, ArtifactToken.SENTINEL); Assert.assertNull(actual); - actual = relCache.getByRelIdOnArtifact(1, artifact1.getArtId(), 0, artifact2.getBranch()); + actual = relCache.getByRelIdOnArtifact(1, art1WrongBranch, ArtifactToken.SENTINEL); Assert.assertNull(actual); - actual = relCache.getByRelIdOnArtifact(1, artifact2.getArtId(), 0, artifact1.getBranch()); + actual = relCache.getByRelIdOnArtifact(1, art2WrongBranch, ArtifactToken.SENTINEL); Assert.assertNull(actual); - actual = relCache.getByRelIdOnArtifact(1, artifact2.getArtId(), 0, artifact2.getBranch()); + actual = relCache.getByRelIdOnArtifact(1, artifact2, ArtifactToken.SENTINEL); Assert.assertEquals(link21, actual); Assert.assertFalse(link22.equals(actual)); - actual = relCache.getByRelIdOnArtifact(1, 0, artifact2.getArtId(), artifact2.getBranch()); + actual = relCache.getByRelIdOnArtifact(1, ArtifactToken.SENTINEL, artifact2); Assert.assertEquals(link21, actual); Assert.assertFalse(link22.equals(actual)); // Find Relation Link Id 0 - - actual = relCache.getByRelIdOnArtifact(0, 0, artifact2.getArtId(), artifact2.getBranch()); + actual = relCache.getByRelIdOnArtifact(0, ArtifactToken.SENTINEL, artifact2); Assert.assertNull(actual); - actual = relCache.getByRelIdOnArtifact(0, 0, artifact2.getArtId(), artifact1.getBranch()); - Assert.assertNull(actual); - - actual = relCache.getByRelIdOnArtifact(0, 0, artifact1.getArtId(), artifact2.getBranch()); - Assert.assertNull(actual); - - actual = relCache.getByRelIdOnArtifact(0, 0, artifact1.getArtId(), artifact1.getBranch()); + actual = relCache.getByRelIdOnArtifact(0, ArtifactToken.SENTINEL, artifact1); Assert.assertEquals(link11, actual); Assert.assertFalse(link12.equals(actual)); - actual = relCache.getByRelIdOnArtifact(0, artifact1.getArtId(), 0, artifact1.getBranch()); + actual = relCache.getByRelIdOnArtifact(0, artifact1, ArtifactToken.SENTINEL); Assert.assertEquals(link11, actual); Assert.assertFalse(link12.equals(actual)); } @@ -264,17 +264,17 @@ public class RelationCacheTest { RelationLink actual = null; // Find relation link 11 - actual = relCache.getLoadedRelation(artifact1, art1Id, 44, relType1, DeletionFlag.INCLUDE_DELETED); + actual = relCache.getLoadedRelation(artifact1, artifact1, art44, relType1, DeletionFlag.INCLUDE_DELETED); Assert.assertNull(actual); - actual = relCache.getLoadedRelation(artifact1, art1Id, 22, relType1, DeletionFlag.INCLUDE_DELETED); + actual = relCache.getLoadedRelation(artifact1, artifact1, art22, relType1, DeletionFlag.INCLUDE_DELETED); Assert.assertEquals(link11, actual); // Find relation link 22 - actual = relCache.getLoadedRelation(artifact2, 77, art2Id, relType2, DeletionFlag.EXCLUDE_DELETED); + actual = relCache.getLoadedRelation(artifact2, art77, artifact2, relType2, DeletionFlag.EXCLUDE_DELETED); Assert.assertNull(actual); - actual = relCache.getLoadedRelation(artifact2, 77, art2Id, relType2, DeletionFlag.INCLUDE_DELETED); + actual = relCache.getLoadedRelation(artifact2, art77, artifact2, relType2, DeletionFlag.INCLUDE_DELETED); Assert.assertEquals(link22, actual); } @@ -282,6 +282,13 @@ public class RelationCacheTest { public void testGetLoadedRelationNoId() { RelationCache relCache = new RelationCache(); + ArtifactToken art11 = ArtifactToken.valueOf(11, branch1); + + ArtifactToken art22WrongBranch = ArtifactToken.valueOf(22, branch2); + ArtifactToken art551 = ArtifactToken.valueOf(551, branch2); + ArtifactToken art661 = ArtifactToken.valueOf(661, branch2); + ArtifactToken art661WrongBranch = ArtifactToken.valueOf(661, branch1); + RelationLink link11 = TestUtil.createRelationLink(0, 11, 22, branch1, relType1); RelationLink link12 = TestUtil.createRelationLink(1, 11, 22, branch1, relType1); RelationLink link13 = TestUtil.createRelationLink(3, 22, 11, branch1, relType1); @@ -301,34 +308,34 @@ public class RelationCacheTest { RelationLink actual = null; // Must match branch - actual = relCache.getLoadedRelation(relType1, artifact1.getArtId(), 22, artifact2.getBranch()); + actual = relCache.getLoadedRelation(relType1, artifact1, art22WrongBranch); Assert.assertNull(actual); - actual = relCache.getLoadedRelation(relType2, artifact1.getArtId(), 22, artifact1.getBranch()); + actual = relCache.getLoadedRelation(relType2, artifact1, art22); Assert.assertNull(actual); - actual = relCache.getLoadedRelation(relType1, artifact1.getArtId(), 22, artifact1.getBranch()); + actual = relCache.getLoadedRelation(relType1, artifact1, art22); Assert.assertEquals(link11, actual); Assert.assertFalse(link12.equals(actual)); - actual = relCache.getLoadedRelation(relType1, 22, artifact1.getArtId(), artifact1.getBranch()); + actual = relCache.getLoadedRelation(relType1, art22, artifact1); Assert.assertEquals(link13, actual); - actual = relCache.getLoadedRelation(relType1, artifact1.getArtId(), 11, artifact1.getBranch()); + actual = relCache.getLoadedRelation(relType1, artifact1, art11); Assert.assertEquals(link13, actual); // Find Must match branch - actual = relCache.getLoadedRelation(relType2, artifact2.getArtId(), 661, artifact1.getBranch()); + actual = relCache.getLoadedRelation(relType2, artifact2, art661WrongBranch); Assert.assertNull(actual); - actual = relCache.getLoadedRelation(relType2, artifact2.getArtId(), 661, artifact2.getBranch()); + actual = relCache.getLoadedRelation(relType2, artifact2, art661); Assert.assertEquals(link21, actual); Assert.assertFalse(link22.equals(actual)); - actual = relCache.getLoadedRelation(relType2, 661, artifact2.getArtId(), artifact2.getBranch()); + actual = relCache.getLoadedRelation(relType2, art661, artifact2); Assert.assertEquals(link23, actual); - actual = relCache.getLoadedRelation(relType2, artifact2.getArtId(), 551, artifact2.getBranch()); + actual = relCache.getLoadedRelation(relType2, artifact2, art551); Assert.assertEquals(link23, actual); } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationCache.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationCache.java index e02345e95ec..1f00a21550a 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationCache.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationCache.java @@ -19,7 +19,6 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.logging.Level; import org.eclipse.osee.framework.core.data.ArtifactId; import org.eclipse.osee.framework.core.data.ArtifactToken; -import org.eclipse.osee.framework.core.data.BranchId; import org.eclipse.osee.framework.core.data.RelationTypeId; import org.eclipse.osee.framework.core.enums.DeletionFlag; import org.eclipse.osee.framework.core.enums.RelationSide; @@ -102,21 +101,17 @@ public class RelationCache { /** * Find RelationById Related On ArtA or ArtB */ - public RelationLink getByRelIdOnArtifact(int relLinkId, int aArtifactId, int bArtifactId, BranchId branch) { + public RelationLink getByRelIdOnArtifact(int relLinkId, ArtifactToken artifactA, ArtifactToken artifactB) { RelationMatcher relIdMatcher = RelationFilterUtil.createFindFirstRelationLinkIdMatcher(relLinkId); List<RelationLink> links = new ArrayList<>(); - findRelations(links, ArtifactToken.valueOf(aArtifactId, branch), relIdMatcher); + findRelations(links, artifactA, relIdMatcher); if (links.isEmpty()) { - findRelations(links, ArtifactToken.valueOf(bArtifactId, branch), relIdMatcher); + findRelations(links, artifactB, relIdMatcher); } return links.isEmpty() ? null : links.iterator().next(); } public RelationLink getLoadedRelation(ArtifactToken artifact, ArtifactId aArtifactId, ArtifactId bArtifactId, RelationTypeId relationType, DeletionFlag deletionFlag) { - return getLoadedRelation(artifact, aArtifactId.getId(), bArtifactId.getId(), relationType, deletionFlag); - } - - public RelationLink getLoadedRelation(ArtifactToken artifact, long aArtifactId, long bArtifactId, RelationTypeId relationType, DeletionFlag deletionFlag) { Set<RelationLink> itemsFound = new HashSet<>(); RelationMatcher artIdMatcher = new RelationMatcher() { @@ -150,18 +145,15 @@ public class RelationCache { return size != 0 ? relations.iterator().next() : null; } - public RelationLink getLoadedRelation(RelationTypeId relationType, int aArtifactId, int bArtifactId, BranchId branch) { - ArtifactId artifactA = ArtifactId.valueOf(aArtifactId); - ArtifactId artifactB = ArtifactId.valueOf(bArtifactId); - + public RelationLink getLoadedRelation(RelationTypeId relationType, ArtifactToken artifactA, ArtifactToken artifactB) { RelationMatcher bArtIdMatcher = RelationFilterUtil.createFindFirstRelatedArtIdMatcher(artifactB, RelationSide.SIDE_B); List<RelationLink> links = new ArrayList<>(); - findRelations(links, ArtifactToken.valueOf(aArtifactId, branch), relationType, bArtIdMatcher); + findRelations(links, artifactA, relationType, bArtIdMatcher); if (links.isEmpty()) { RelationMatcher aArtIdMatcher = RelationFilterUtil.createFindFirstRelatedArtIdMatcher(artifactA, RelationSide.SIDE_A); - findRelations(links, ArtifactToken.valueOf(bArtifactId, branch), relationType, aArtIdMatcher); + findRelations(links, artifactB, relationType, aArtIdMatcher); } return links.isEmpty() ? null : links.iterator().next(); } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationFilterUtil.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationFilterUtil.java index 7164b1f353e..bc393dce8b6 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationFilterUtil.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationFilterUtil.java @@ -31,8 +31,8 @@ public class RelationFilterUtil { public static final RelationMatcher EXCLUDE_DELETED = new ExcludeDeletedRelationFilter(); public static final RelationMatcher INCLUDE_ALL = new DefaultRelationFilter(); - public static RelationMatcher createFindFirstRelatedArtIdMatcher(ArtifactId aArtifactId, RelationSide side) { - return new FirstSideRelatedArtIdMatcher(aArtifactId, side.isSideA()); + public static RelationMatcher createFindFirstRelatedArtIdMatcher(ArtifactId artifactId, RelationSide side) { + return new FirstSideRelatedArtIdMatcher(artifactId, side.isSideA()); } public static RelationMatcher createFindFirstRelationLinkIdMatcher(int relLinkId) { diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationManager.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationManager.java index 4575a0a5f4b..ed60a27b9e4 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationManager.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationManager.java @@ -609,7 +609,7 @@ public class RelationManager { if (relationId != 0) { relation = getLoadedRelationById(relationId, aArtifactId, bArtifactId, branch); } else { - relation = getLoadedRelation(relationType, aArtifactId, bArtifactId, branch); + relation = getLoadedRelation(relationType, aArtifactId, bArtifactId); } if (relation == null) { relation = new RelationLink(aArtifactId, bArtifactId, branch, relationType, relationId, gammaId, rationale, @@ -621,14 +621,12 @@ public class RelationManager { return relation; } - public static RelationLink getLoadedRelation(IRelationType relationType, ArtifactToken aArtifactId, ArtifactToken bArtifactId, BranchId branch) { - return relationCache.getLoadedRelation(relationType, aArtifactId.getId().intValue(), - bArtifactId.getId().intValue(), branch); + public static RelationLink getLoadedRelation(IRelationType relationType, ArtifactToken aArtifactId, ArtifactToken bArtifactId) { + return relationCache.getLoadedRelation(relationType, aArtifactId, bArtifactId); } - public static RelationLink getLoadedRelationById(int relLinkId, ArtifactId aArtifactId, ArtifactId bArtifactId, BranchId branch) { - return relationCache.getByRelIdOnArtifact(relLinkId, aArtifactId.getId().intValue(), - bArtifactId.getId().intValue(), branch); + public static RelationLink getLoadedRelationById(int relLinkId, ArtifactToken aArtifactId, ArtifactToken bArtifactId, BranchId branch) { + return relationCache.getByRelIdOnArtifact(relLinkId, aArtifactId, bArtifactId); } public static List<RelationLink> getRelationsAll(Artifact artifact, DeletionFlag deletionFlag) { |