diff options
author | Ryan D. Brooks | 2016-09-23 22:38:47 +0000 |
---|---|---|
committer | donald.g.dunne | 2016-09-23 22:38:47 +0000 |
commit | 9e46573b0b4306613a9edd0a24dca2d5c8a2132f (patch) | |
tree | 4c73e81b2eb828cf4c061456962123d77f9efa89 /plugins | |
parent | 99be5120bad092995cbc715d602a34e96ccc7157 (diff) | |
download | org.eclipse.osee-9e46573b0b4306613a9edd0a24dca2d5c8a2132f.tar.gz org.eclipse.osee-9e46573b0b4306613a9edd0a24dca2d5c8a2132f.tar.xz org.eclipse.osee-9e46573b0b4306613a9edd0a24dca2d5c8a2132f.zip |
refactor: Convert RelationSorter to an enum
- RelationOrderBaseTypes was in the enums package
- org.eclipse.osee.framework.core.enums but was not actually an enum
- and depended upon RelationSorter and RelationSorterIdComparator and
- other unnecessary code to create the effect of an enum. This commit
- replaces all this by making RelationSorter a true enum. The final
- step of moving RelationSorter to the enum pakcage and removing
- RelationOrderBaseTypes will be done in a future commit to keep that
- automated refactor separate.
Change-Id: I6f36b30f02ba94f5af97ab3fb999a7588700ecb2
Diffstat (limited to 'plugins')
44 files changed, 281 insertions, 637 deletions
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 53a7bd14e96..84b66d69cde 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 @@ -43,7 +43,7 @@ import org.junit.Test; /** * Test Case for {@link RelationCache} - * + * * @author Roberto E. Escobar */ public class RelationCacheTest { @@ -144,7 +144,7 @@ public class RelationCacheTest { * When RelationCache.cache() is changed to throw an exception for a duplicate relation, <br/> * then this test should fail and severeLoggingMonitor should not be paused. * </p> - * + * * @throws Exception */ @Test @@ -369,7 +369,7 @@ public class RelationCacheTest { IArtifact artifactB = createArtifact(55, testBranch); RelationType type = new RelationType(0x00L, "type name", artifactA.getName(), artifactB.getName(), - CoreArtifactTypes.Artifact, CoreArtifactTypes.Artifact, RelationTypeMultiplicity.MANY_TO_MANY, ""); + CoreArtifactTypes.Artifact, CoreArtifactTypes.Artifact, RelationTypeMultiplicity.MANY_TO_MANY, null); RelationLink link = new RelationLink(new MockLinker("linker"), artifactA.getArtId(), artifactB.getArtId(), testBranch, type, 77, 88, "", ModificationType.MODIFIED, ApplicabilityId.BASE); relCache.cache(artifactA, link); diff --git a/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/RelationOrderMergeUtilityTest.java b/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/RelationOrderMergeUtilityTest.java index c89126cfddf..38f64d1b958 100644 --- a/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/RelationOrderMergeUtilityTest.java +++ b/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/RelationOrderMergeUtilityTest.java @@ -19,8 +19,8 @@ import org.eclipse.osee.client.test.framework.OseeClientIntegrationRule; import org.eclipse.osee.client.test.framework.OseeHousekeepingRule; import org.eclipse.osee.client.test.framework.OseeLogMonitorRule; import org.eclipse.osee.framework.core.data.IOseeBranch; -import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.data.IRelationTypeSide; +import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.enums.CoreBranches; import org.eclipse.osee.framework.core.enums.CoreRelationTypes; import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; @@ -91,8 +91,8 @@ public class RelationOrderMergeUtilityTest { RelationOrderData mergedOrder = RelationOrderMergeUtility.mergeRelationOrder(parent, parent); Assert.assertNotNull(mergedOrder); - String sorter = mergedOrder.getCurrentSorterGuid(hierType, hierSide); - Assert.assertEquals(ascOrder.getGuid(), sorter); + RelationSorter sorter = mergedOrder.getCurrentSorterGuid(hierType, hierSide); + Assert.assertEquals(ascOrder, sorter); } @Test diff --git a/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/utils/TestUtil.java b/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/utils/TestUtil.java index bd50ffe4bb0..f879403e3dd 100644 --- a/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/utils/TestUtil.java +++ b/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/utils/TestUtil.java @@ -19,12 +19,12 @@ import java.util.Random; import org.eclipse.osee.framework.core.data.ApplicabilityId; import org.eclipse.osee.framework.core.data.BranchId; import org.eclipse.osee.framework.core.data.IArtifactType; +import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.enums.BranchState; import org.eclipse.osee.framework.core.enums.BranchType; import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; import org.eclipse.osee.framework.core.enums.CoreRelationTypes; import org.eclipse.osee.framework.core.enums.ModificationType; -import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; import org.eclipse.osee.framework.core.enums.RelationTypeMultiplicity; import org.eclipse.osee.framework.core.model.Branch; import org.eclipse.osee.framework.core.model.type.ArtifactType; @@ -144,7 +144,7 @@ public final class TestUtil { private static RelationType createRelationType(int index, IArtifactType artTypeA, IArtifactType artTypeB) { RelationTypeMultiplicity multiplicity = RelationTypeMultiplicity.values()[Math.abs(index % RelationTypeMultiplicity.values().length)]; - String order = RelationOrderBaseTypes.values()[index % RelationTypeMultiplicity.values().length].getGuid(); + RelationSorter order = RelationSorter.values()[index % RelationTypeMultiplicity.values().length]; return new RelationType(randomGenerator.nextLong(), "relType_" + index, "sideA_" + index, "sideB_" + index, artTypeA, artTypeB, multiplicity, order); } diff --git a/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/ui/skynet/ArtifactPasteOperationTest.java b/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/ui/skynet/ArtifactPasteOperationTest.java index bf8a1bf68ab..f1823e4e161 100644 --- a/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/ui/skynet/ArtifactPasteOperationTest.java +++ b/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/ui/skynet/ArtifactPasteOperationTest.java @@ -44,7 +44,7 @@ import org.junit.Test; /** * Test case for {@link ArtifactPasteOperation}. - * + * * @author Roberto E. Escobar */ public class ArtifactPasteOperationTest { @@ -179,15 +179,15 @@ public class ArtifactPasteOperationTest { List<Artifact> childArtifacts = artifactToCheck.getChildren(); Assert.assertEquals(hasChildren, !childArtifacts.isEmpty()); - for (Entry<Pair<String, String>, Pair<String, List<String>>> entry : data.entrySet()) { + for (Entry<Pair<String, String>, Pair<RelationSorter, List<String>>> entry : data.entrySet()) { String relationType = entry.getKey().getFirst(); String relationSide = entry.getKey().getSecond(); - String orderGuid = entry.getValue().getFirst(); + RelationSorter orderGuid = entry.getValue().getFirst(); List<String> guids = entry.getValue().getSecond(); Assert.assertEquals(CoreRelationTypes.Default_Hierarchical__Child.getName(), relationType); Assert.assertEquals(RelationSide.SIDE_B.name(), relationSide); - Assert.assertEquals(expectedOrderType.getGuid(), orderGuid); + Assert.assertEquals(expectedOrderType, orderGuid); if (hasChildren && expectedOrderType == RelationOrderBaseTypes.USER_DEFINED) { Assert.assertEquals(childArtifacts.size(), guids.size()); for (int index = 0; index < guids.size(); index++) { diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/internal/OseeUtilTest.java b/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/internal/OseeUtilTest.java index beb6db9dbed..d742daf0a7e 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/internal/OseeUtilTest.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/internal/OseeUtilTest.java @@ -10,9 +10,6 @@ *******************************************************************************/ package org.eclipse.osee.framework.core.dsl.integration.internal; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; import org.eclipse.osee.framework.core.data.IArtifactType; import org.eclipse.osee.framework.core.data.IAttributeType; import org.eclipse.osee.framework.core.data.IRelationType; @@ -28,7 +25,6 @@ import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; import org.eclipse.osee.framework.core.enums.CoreRelationTypes; import org.eclipse.osee.framework.core.enums.PermissionEnum; -import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; import org.eclipse.osee.framework.core.enums.RelationSide; import org.eclipse.osee.framework.jdk.core.type.Id; import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException; @@ -123,64 +119,6 @@ public class OseeUtilTest { Assert.assertFalse(expected.equals(actual)); } - @Test(expected = OseeArgumentException.class) - public void testGetRelationOrderTypeNullCheck() throws OseeCoreException { - OseeUtil.getRelationOrderType(null); - } - - @Test(expected = OseeArgumentException.class) - public void testGetRelationOrderTypeEmptyCheck() throws OseeCoreException { - OseeUtil.getRelationOrderType(""); - } - - @Test(expected = OseeArgumentException.class) - public void testGetRelationOrderTypeNotFoundCheck() throws OseeCoreException { - OseeUtil.getRelationOrderType("a"); - } - - @Test - public void testGetRelationOrderType() throws OseeCoreException { - Map<String, String> testData = new HashMap<>(); - testData.put(RelationOrderBaseTypes.LEXICOGRAPHICAL_ASC.getGuid(), "Lexicographical_Ascending"); - testData.put(RelationOrderBaseTypes.LEXICOGRAPHICAL_DESC.getGuid(), "Lexicographical_Descending"); - testData.put(RelationOrderBaseTypes.UNORDERED.getGuid(), "Unordered"); - testData.put(RelationOrderBaseTypes.USER_DEFINED.getGuid(), "User_Defined"); - for (Entry<String, String> entry : testData.entrySet()) { - String actualName = OseeUtil.getRelationOrderType(entry.getKey()); - String expectedName = entry.getValue(); - Assert.assertEquals(expectedName, actualName); - } - } - - @Test(expected = OseeArgumentException.class) - public void testOrderTypeNameToGuidNullCheck() throws OseeCoreException { - OseeUtil.orderTypeNameToGuid(null); - } - - @Test(expected = OseeArgumentException.class) - public void testOrderTypeNameToGuidEmptyCheck() throws OseeCoreException { - OseeUtil.orderTypeNameToGuid(""); - } - - @Test(expected = OseeArgumentException.class) - public void testOrderTypeNameToGuidNotFoundCheck() throws OseeCoreException { - OseeUtil.orderTypeNameToGuid("a"); - } - - @Test - public void testOrderTypeNameToGuid() throws OseeCoreException { - Map<String, String> testData = new HashMap<>(); - testData.put("Lexicographical_Ascending", RelationOrderBaseTypes.LEXICOGRAPHICAL_ASC.getGuid()); - testData.put("Lexicographical_Descending", RelationOrderBaseTypes.LEXICOGRAPHICAL_DESC.getGuid()); - testData.put("Unordered", RelationOrderBaseTypes.UNORDERED.getGuid()); - testData.put("User_Defined", RelationOrderBaseTypes.USER_DEFINED.getGuid()); - for (Entry<String, String> entry : testData.entrySet()) { - String actualGuid = OseeUtil.orderTypeNameToGuid(entry.getKey()); - String expectedGuid = entry.getValue(); - Assert.assertEquals(expectedGuid, actualGuid); - } - } - private static void setupToToken(OseeType typeToCheck, Id expected) throws OseeCoreException { String name = "bogus name"; // This should not affect equality typeToCheck.setName(name); diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/internal/RelationTypeRestrictionHandlerTest.java b/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/internal/RelationTypeRestrictionHandlerTest.java index ba5a98ecf3f..fc530f932b5 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/internal/RelationTypeRestrictionHandlerTest.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.integration.test/src/org/eclipse/osee/framework/core/dsl/integration/internal/RelationTypeRestrictionHandlerTest.java @@ -360,6 +360,6 @@ public class RelationTypeRestrictionHandlerTest extends BaseRestrictionHandlerTe private static RelationType getTestRelationType(IRelationType relationType, IArtifactType aArtTypeToken, IArtifactType bArtTypeToken) { return new RelationType(relationType.getId(), relationType.getName(), "sideA_" + aArtTypeToken.getName(), "sideB_" + bArtTypeToken.getName(), aArtTypeToken, bArtTypeToken, RelationTypeMultiplicity.MANY_TO_MANY, - RelationOrderBaseTypes.LEXICOGRAPHICAL_ASC.getGuid()); + RelationOrderBaseTypes.LEXICOGRAPHICAL_ASC); } } diff --git a/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/OseeUtil.java b/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/OseeUtil.java index 9b6ad463061..410578f1432 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/OseeUtil.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.integration/src/org/eclipse/osee/framework/core/dsl/integration/internal/OseeUtil.java @@ -12,7 +12,6 @@ package org.eclipse.osee.framework.core.dsl.integration.internal; import org.eclipse.osee.framework.core.data.IArtifactType; import org.eclipse.osee.framework.core.data.IAttributeType; -import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.data.IRelationType; import org.eclipse.osee.framework.core.data.TokenFactory; import org.eclipse.osee.framework.core.dsl.oseeDsl.AccessPermissionEnum; @@ -23,7 +22,6 @@ import org.eclipse.osee.framework.core.dsl.oseeDsl.XAttributeType; import org.eclipse.osee.framework.core.dsl.oseeDsl.XRelationSideEnum; import org.eclipse.osee.framework.core.dsl.oseeDsl.XRelationType; import org.eclipse.osee.framework.core.enums.PermissionEnum; -import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; import org.eclipse.osee.framework.core.enums.RelationSide; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; import org.eclipse.osee.framework.jdk.core.util.Conditions; @@ -90,14 +88,4 @@ public final class OseeUtil { } return toReturn; } - - public static String getRelationOrderType(String guid) throws OseeCoreException { - RelationSorter type = RelationOrderBaseTypes.getFromGuid(guid); - return type.getName().replaceAll(" ", "_"); - } - - public static String orderTypeNameToGuid(String orderTypeName) throws OseeCoreException { - Conditions.checkNotNull(orderTypeName, "orderTypeName"); - return RelationOrderBaseTypes.getFromOrderTypeName(orderTypeName.replaceAll("_", " ")).getGuid(); - } -} +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/mocks/MockDataFactory.java b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/mocks/MockDataFactory.java index 782c395c211..25540c15003 100644 --- a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/mocks/MockDataFactory.java +++ b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/mocks/MockDataFactory.java @@ -15,10 +15,10 @@ import java.util.Random; import org.eclipse.osee.framework.core.data.IAccessContextId; import org.eclipse.osee.framework.core.data.IArtifactType; import org.eclipse.osee.framework.core.data.IOseeBranch; +import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.data.TokenFactory; import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; import org.eclipse.osee.framework.core.enums.PermissionEnum; -import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; import org.eclipse.osee.framework.core.enums.RelationTypeMultiplicity; import org.eclipse.osee.framework.core.enums.TransactionDetailsType; import org.eclipse.osee.framework.core.model.OseeEnumEntry; @@ -119,9 +119,8 @@ public final class MockDataFactory { public static RelationType createRelationType(int index, IArtifactType artTypeA, IArtifactType artTypeB, Long id) { RelationTypeMultiplicity multiplicity = RelationTypeMultiplicity.values()[Math.abs(index % RelationTypeMultiplicity.values().length)]; - String order = RelationOrderBaseTypes.values()[index % RelationTypeMultiplicity.values().length].getGuid(); + RelationSorter order = RelationSorter.values()[index % RelationTypeMultiplicity.values().length]; return new RelationType(id, "relType_" + index, "sideA_" + index, "sideB_" + index, artTypeA, artTypeB, multiplicity, order); } - -} +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/type/RelationType.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/type/RelationType.java index b75b26e1b19..ad631b8daae 100644 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/type/RelationType.java +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/type/RelationType.java @@ -12,7 +12,7 @@ package org.eclipse.osee.framework.core.model.type; import org.eclipse.osee.framework.core.data.IArtifactType; import org.eclipse.osee.framework.core.data.IRelationType; -import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; +import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.enums.RelationSide; import org.eclipse.osee.framework.core.enums.RelationTypeMultiplicity; import org.eclipse.osee.framework.core.model.AbstractOseeIdType; @@ -32,11 +32,11 @@ public final class RelationType extends AbstractOseeIdType implements IRelationT "osee.relation.type.default.order.type.guid.field"; private static final String RELATION_MULTIPLICITY_FIELD_KEY = "osee.relation.type.multiplicity.field"; - public RelationType(Long guid, String relationTypeName, String sideAName, String sideBName, IArtifactType artifactTypeSideA, IArtifactType artifactTypeSideB, RelationTypeMultiplicity multiplicity, String defaultOrderTypeGuid) { + public RelationType(Long guid, String relationTypeName, String sideAName, String sideBName, IArtifactType artifactTypeSideA, IArtifactType artifactTypeSideB, RelationTypeMultiplicity multiplicity, RelationSorter defaultRelationSorter) { super(guid, relationTypeName); initializeFields(); setFields(relationTypeName, sideAName, sideBName, artifactTypeSideA, artifactTypeSideB, multiplicity, - defaultOrderTypeGuid); + defaultRelationSorter); } protected void initializeFields() { @@ -44,17 +44,17 @@ public final class RelationType extends AbstractOseeIdType implements IRelationT addField(RELATION_SIDE_B_NAME_FIELD_KEY, new OseeField<String>()); addField(RELATION_SIDE_A_ART_TYPE_FIELD_KEY, new OseeField<ArtifactType>()); addField(RELATION_SIDE_B_ART_TYPE_FIELD_KEY, new OseeField<ArtifactType>()); - addField(RELATION_DEFAULT_ORDER_TYPE_GUID_FIELD_KEY, new OseeField<String>()); + addField(RELATION_DEFAULT_ORDER_TYPE_GUID_FIELD_KEY, new OseeField<RelationSorter>()); addField(RELATION_MULTIPLICITY_FIELD_KEY, new OseeField<RelationTypeMultiplicity>()); } - public void setFields(String relationTypeName, String sideAName, String sideBName, IArtifactType artifactTypeSideA, IArtifactType artifactTypeSideB, RelationTypeMultiplicity multiplicity, String defaultOrderTypeGuid) { + public void setFields(String relationTypeName, String sideAName, String sideBName, IArtifactType artifactTypeSideA, IArtifactType artifactTypeSideB, RelationTypeMultiplicity multiplicity, RelationSorter defaultRelationSorter) { setName(relationTypeName); setFieldLogException(RELATION_SIDE_A_NAME_FIELD_KEY, sideAName); setFieldLogException(RELATION_SIDE_B_NAME_FIELD_KEY, sideBName); setFieldLogException(RELATION_SIDE_A_ART_TYPE_FIELD_KEY, artifactTypeSideA); setFieldLogException(RELATION_SIDE_B_ART_TYPE_FIELD_KEY, artifactTypeSideB); - setFieldLogException(RELATION_DEFAULT_ORDER_TYPE_GUID_FIELD_KEY, defaultOrderTypeGuid); + setFieldLogException(RELATION_DEFAULT_ORDER_TYPE_GUID_FIELD_KEY, defaultRelationSorter); setFieldLogException(RELATION_MULTIPLICITY_FIELD_KEY, multiplicity); } @@ -110,11 +110,11 @@ public final class RelationType extends AbstractOseeIdType implements IRelationT } public boolean isOrdered() { - return !RelationOrderBaseTypes.UNORDERED.getGuid().equals(getDefaultOrderTypeGuid()); + return !RelationSorter.UNORDERED.equals(getDefaultOrderTypeGuid()); } - public String getDefaultOrderTypeGuid() { - return getFieldValueLogException("", RELATION_DEFAULT_ORDER_TYPE_GUID_FIELD_KEY); + public RelationSorter getDefaultOrderTypeGuid() { + return getFieldValueLogException(null, RELATION_DEFAULT_ORDER_TYPE_GUID_FIELD_KEY); } @Override diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/type/RelationTypeFactory.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/type/RelationTypeFactory.java index 9dc956d51d6..c3ad27f2584 100644 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/type/RelationTypeFactory.java +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/type/RelationTypeFactory.java @@ -11,6 +11,7 @@ package org.eclipse.osee.framework.core.model.type; import org.eclipse.osee.framework.core.data.IArtifactType; +import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.enums.RelationTypeMultiplicity; import org.eclipse.osee.framework.core.model.cache.IOseeTypeFactory; import org.eclipse.osee.framework.core.model.cache.RelationTypeCache; @@ -22,7 +23,7 @@ import org.eclipse.osee.framework.jdk.core.util.Conditions; */ public class RelationTypeFactory implements IOseeTypeFactory { - public RelationType create(Long guid, String name, String sideAName, String sideBName, IArtifactType artifactTypeSideA, IArtifactType artifactTypeSideB, RelationTypeMultiplicity multiplicity, String defaultOrderTypeGuid) throws OseeCoreException { + public RelationType create(Long guid, String name, String sideAName, String sideBName, IArtifactType artifactTypeSideA, IArtifactType artifactTypeSideB, RelationTypeMultiplicity multiplicity, RelationSorter defaultRelationSorter) throws OseeCoreException { Conditions.checkNotNullOrEmpty(name, "relation type name"); Conditions.checkNotNullOrEmpty(sideAName, "side A name"); Conditions.checkNotNullOrEmpty(sideBName, "side B name"); @@ -30,19 +31,19 @@ public class RelationTypeFactory implements IOseeTypeFactory { Conditions.checkNotNull(artifactTypeSideB, "relation type B"); Conditions.checkNotNull(multiplicity, "multiplicity"); return new RelationType(guid, name, sideAName, sideBName, artifactTypeSideA, artifactTypeSideB, multiplicity, - defaultOrderTypeGuid); + defaultRelationSorter); } - public RelationType createOrUpdate(RelationTypeCache cache, Long guid, String typeName, String sideAName, String sideBName, IArtifactType artifactTypeSideA, IArtifactType artifactTypeSideB, RelationTypeMultiplicity multiplicity, String defaultOrderTypeGuid) throws OseeCoreException { + public RelationType createOrUpdate(RelationTypeCache cache, Long guid, String typeName, String sideAName, String sideBName, IArtifactType artifactTypeSideA, IArtifactType artifactTypeSideB, RelationTypeMultiplicity multiplicity, RelationSorter defaultRelationSorter) throws OseeCoreException { Conditions.checkNotNull(cache, "RelationTypeCache"); RelationType relationType = cache.getByGuid(guid); if (relationType == null) { relationType = create(guid, typeName, sideAName, sideBName, artifactTypeSideA, artifactTypeSideB, multiplicity, - defaultOrderTypeGuid); + defaultRelationSorter); cache.cache(relationType); } else { relationType.setFields(typeName, sideAName, sideBName, artifactTypeSideA, artifactTypeSideB, multiplicity, - defaultOrderTypeGuid); + defaultRelationSorter); } return relationType; } diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/RelationSorter.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/RelationSorter.java index 1f4ef24e5c2..bc092642dc2 100644 --- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/RelationSorter.java +++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/RelationSorter.java @@ -10,20 +10,52 @@ *******************************************************************************/ package org.eclipse.osee.framework.core.data; -import org.eclipse.osee.framework.jdk.core.type.Identifiable; -import org.eclipse.osee.framework.jdk.core.type.NamedIdentity; +import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException; /** + * Defines built-in relation sorting type including unordered + * * @author Andrew M. Finkbeiner */ -public interface RelationSorter extends Identifiable<String> { +public enum RelationSorter { + + USER_DEFINED("AAT0xogoMjMBhARkBZQA", "User Defined"), + LEXICOGRAPHICAL_ASC("AAT1QW4eVE+YuzsoHFAA", "Lexicographical_Ascending"), + LEXICOGRAPHICAL_DESC("AAmATn6R9m7VCXQQwuQA", "Lexicographical_Descending"), + UNORDERED("AAT1uKZpeDQExlygoIAA", "Unordered"), + PREEXISTING("AE2ypryqoVzNl6EjpgAA", "Preexisting"); + + private final String guid; + private final String name; + + private RelationSorter(String guid, String name) { + this.guid = guid; + this.name = name; + } + + public boolean equals(String guid) { + return this.guid.equals(guid); + } - public static RelationSorter create(String id, String name) { - final class RelationSorterIdImpl extends NamedIdentity<String> implements RelationSorter { - public RelationSorterIdImpl(String guid, String name) { - super(guid, name); + public static RelationSorter valueOfName(String name) { + for (RelationSorter sorter : values()) { + if (sorter.name.equals(name)) { + return sorter; } } - return new RelationSorterIdImpl(id, name); + throw new OseeArgumentException("Order type guid does not map to an enum [%s]", name); + } + + public static RelationSorter valueOfGuid(String guid) { + for (RelationSorter sorter : values()) { + if (sorter.guid.equals(guid)) { + return sorter; + } + } + throw new OseeArgumentException("Order type guid does not map to an enum [%s]", guid); + } + + public String getGuid() { + return guid; } }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/TokenFactory.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/TokenFactory.java index 54af2491a2c..c872138a5a9 100644 --- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/TokenFactory.java +++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/data/TokenFactory.java @@ -94,22 +94,6 @@ public final class TokenFactory { return new BranchToken(Lib.generateUuid(), null); } - public static RelationSorter createSorterId(String guid, String name) { - return new SorterIdToken(guid, name); - } - - private final static class SorterIdToken extends NamedIdentity<String> implements RelationSorter { - - public SorterIdToken(String guid, String name) { - super(guid, name); - } - - @Override - public String toString() { - return String.format("[%s:%s]", getName(), getGuid()); - } - } - private final static class ArtifactTypeToken extends NamedId implements IArtifactType { public ArtifactTypeToken(Long id, String name) { super(id, name); diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/RelationOrderBaseTypes.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/RelationOrderBaseTypes.java index e0d993c72aa..d220ffacbba 100644 --- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/RelationOrderBaseTypes.java +++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/RelationOrderBaseTypes.java @@ -11,52 +11,14 @@ package org.eclipse.osee.framework.core.enums; import org.eclipse.osee.framework.core.data.RelationSorter; -import org.eclipse.osee.framework.core.data.TokenFactory; -import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException; -import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; -import org.eclipse.osee.framework.jdk.core.util.Conditions; /** * @author Andrew M. Finkbeiner */ public class RelationOrderBaseTypes { - - //@formatter:off - public static final RelationSorter USER_DEFINED = TokenFactory.createSorterId("AAT0xogoMjMBhARkBZQA", "User Defined"); - public static final RelationSorter LEXICOGRAPHICAL_ASC = TokenFactory.createSorterId("AAT1QW4eVE+YuzsoHFAA", "Lexicographical Ascending"); - public static final RelationSorter LEXICOGRAPHICAL_DESC = TokenFactory.createSorterId("AAmATn6R9m7VCXQQwuQA", "Lexicographical Descending"); - public static final RelationSorter UNORDERED = TokenFactory.createSorterId("AAT1uKZpeDQExlygoIAA", "Unordered"); - public static final RelationSorter PREEXISTING = TokenFactory.createSorterId("AE2ypryqoVzNl6EjpgAA", "Preexisting"); - //@formatter:on - - private static final RelationSorter[] values = - new RelationSorter[] {USER_DEFINED, LEXICOGRAPHICAL_ASC, LEXICOGRAPHICAL_DESC, UNORDERED}; - - private RelationOrderBaseTypes() { - // Constants - } - - public static RelationSorter[] values() { - return values; - } - - public static RelationSorter getFromGuid(String guid) throws OseeCoreException { - Conditions.checkNotNullOrEmpty(guid, "guid"); - for (RelationSorter type : values()) { - if (type.getGuid().equals(guid)) { - return type; - } - } - throw new OseeArgumentException("Order type guid does not map to an enum"); - } - - public static RelationSorter getFromOrderTypeName(String orderTypeName) throws OseeCoreException { - Conditions.checkNotNullOrEmpty(orderTypeName, "orderTypeName"); - for (RelationSorter type : values()) { - if (type.getName().equals(orderTypeName)) { - return type; - } - } - throw new OseeArgumentException("Order type name does not map to an enum"); - } -} + public static final RelationSorter USER_DEFINED = RelationSorter.USER_DEFINED; + public static final RelationSorter LEXICOGRAPHICAL_ASC = RelationSorter.LEXICOGRAPHICAL_ASC; + public static final RelationSorter LEXICOGRAPHICAL_DESC = RelationSorter.LEXICOGRAPHICAL_DESC; + public static final RelationSorter UNORDERED = RelationSorter.UNORDERED; + public static final RelationSorter PREEXISTING = RelationSorter.PREEXISTING; +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/RelationTypeSideSorterTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/RelationTypeSideSorterTest.java index 09eda236c54..2e35ff05b2f 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/RelationTypeSideSorterTest.java +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/RelationTypeSideSorterTest.java @@ -20,10 +20,10 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Random; -import org.eclipse.osee.framework.core.data.IArtifactType; import org.eclipse.osee.framework.core.data.BranchId; -import org.eclipse.osee.framework.core.data.RelationSorter; +import org.eclipse.osee.framework.core.data.IArtifactType; import org.eclipse.osee.framework.core.data.IRelationType; +import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.enums.BranchState; import org.eclipse.osee.framework.core.enums.BranchType; import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; @@ -109,20 +109,12 @@ public class RelationTypeSideSorterTest { @Test public void test05GetSorterId() throws OseeCoreException { - String sorterGuid = orderData.getCurrentSorterGuid(relationType, relationSide); - RelationSorter expected = sorterProvider.getRelationOrder(sorterGuid).getSorterId(); - Assert.assertNotNull(sorterGuid); + RelationSorter sorterId = orderData.getCurrentSorterGuid(relationType, relationSide); + RelationSorter expected = sorterProvider.getRelationOrder(sorterId).getSorterId(); + Assert.assertNotNull(sorterId); Assert.assertEquals(expected, sorter.getSorterId()); - Assert.assertEquals(expected.getGuid(), sorter.getSorterId().getGuid()); - Assert.assertEquals(expected.getName(), sorter.getSorterId().getName()); - } - - @Test - public void test06SorterName() throws OseeCoreException { - String sorterGuid = orderData.getCurrentSorterGuid(relationType, relationSide); - RelationSorter expected = sorterProvider.getRelationOrder(sorterGuid).getSorterId(); - Assert.assertNotNull(sorterGuid); - Assert.assertEquals(expected.getName(), sorter.getSorterName()); + Assert.assertEquals(expected, sorter.getSorterId()); + Assert.assertEquals(expected.toString(), sorter.getSorterId().toString()); } @Test @@ -146,22 +138,6 @@ public class RelationTypeSideSorterTest { } @Test - public void test08Sort() { - // sorter.sort(listToOrder) - // RelationSorter sorter = null; - // List<IArtifact> sorted = sorter.getSortedRelatives(relatives); - - } - - @Test - public void test09Equals() { - // RelationSorter a = new RelationSorter(RelationTypeManager.getType(6), RelationSide.SIDE_A); - // RelationSorter b = new RelationSorter(RelationTypeManager.getType(7), RelationSide.SIDE_B); - // assertFalse(a.equals(b)); - // assertTrue(a.equals(a)); - } - - @Test public void test10AddItem() throws OseeCoreException { IArtifact itemToAdd = createArtifact("Item to Add", GUID.create()); @@ -175,9 +151,8 @@ public class RelationTypeSideSorterTest { MockArtifactWithRelations artifactMock = (MockArtifactWithRelations) sorter.getIArtifact(); artifactMock.setRelatedArtifacts(sorter.getRelationType(), startingArtifacts); - for (RelationSorter sorterId : sorterProvider.getAllRelationOrderIds()) { - IRelationSorter relationSorter = sorterProvider.getRelationOrder(sorterId.getGuid()); - + for (IRelationSorter relationSorter : sorterProvider.getSorters()) { + RelationSorter sorterId = relationSorter.getSorterId(); List<IArtifact> itemsToOrder = new ArrayList<>(startingArtifacts); itemsToOrder.add(itemToAdd); if (RelationOrderBaseTypes.USER_DEFINED != sorterId) { @@ -201,7 +176,7 @@ public class RelationTypeSideSorterTest { @Test public void test11ToString() throws OseeCoreException { String artGuid = sorter.getIArtifact().getGuid(); - String sorterGuid = orderData.getCurrentSorterGuid(relationType, relationSide); + RelationSorter sorterGuid = orderData.getCurrentSorterGuid(relationType, relationSide); RelationSorter expectedId = sorterProvider.getRelationOrder(sorterGuid).getSorterId(); String expectedToString = String.format("Relation Sorter {relationType=%s, relationSide=[%s], artifact=[%s], sorterId=%s}", relationType, @@ -216,10 +191,8 @@ public class RelationTypeSideSorterTest { RelationTypeCache cache = new RelationTypeCache(); - RelationType relationType1 = - createRelationType(cache, "Rel 1", RelationOrderBaseTypes.LEXICOGRAPHICAL_ASC.getGuid()); - RelationType relationType2 = - createRelationType(cache, "Rel 2", RelationOrderBaseTypes.LEXICOGRAPHICAL_DESC.getGuid()); + RelationType relationType1 = createRelationType(cache, "Rel 1", RelationOrderBaseTypes.LEXICOGRAPHICAL_ASC); + RelationType relationType2 = createRelationType(cache, "Rel 2", RelationOrderBaseTypes.LEXICOGRAPHICAL_DESC); IArtifact art1 = createArtifact("a", GUID.create()); IArtifact art2 = createArtifact("b", GUID.create()); @@ -245,7 +218,7 @@ public class RelationTypeSideSorterTest { return new MockArtifactWithRelations(uniqueId, name, guid, branch, CoreArtifactTypes.Artifact); } - private static RelationType createRelationType(RelationTypeCache cache, String name, String delationRelationOrderGuid) throws OseeCoreException { + private static RelationType createRelationType(RelationTypeCache cache, String name, RelationSorter delationRelationOrderGuid) throws OseeCoreException { IArtifactType type1 = new ArtifactType(0x01L, "1", false); IArtifactType type2 = new ArtifactType(0x02L, "2", false); RelationType relationType = new RelationType(0x03L, name, name + "_A", name + "_B", type1, type2, @@ -257,9 +230,9 @@ public class RelationTypeSideSorterTest { private static void addData(RelationTypeCache cache, RelationOrderData data, List<Object[]> expected) throws OseeCoreException { addData(data, expected, cache.getUniqueByName("Rel 1"), RelationSide.SIDE_A, // - RelationOrderBaseTypes.LEXICOGRAPHICAL_ASC.getGuid(), "1", "2", "3"); + RelationOrderBaseTypes.LEXICOGRAPHICAL_ASC, "1", "2", "3"); addData(data, expected, cache.getUniqueByName("Rel 2"), RelationSide.SIDE_B, // - RelationOrderBaseTypes.UNORDERED.getGuid(), "4", "5", "6"); + RelationOrderBaseTypes.UNORDERED, "4", "5", "6"); checkData(data, expected); } @@ -267,7 +240,7 @@ public class RelationTypeSideSorterTest { private static void checkData(RelationOrderData orderData, List<Object[]> expectedValues) { int index = 0; Assert.assertEquals(expectedValues.size(), orderData.size()); - for (Entry<Pair<String, String>, Pair<String, List<String>>> entry : orderData.getOrderedEntrySet()) { + for (Entry<Pair<String, String>, Pair<RelationSorter, List<String>>> entry : orderData.getOrderedEntrySet()) { Object[] actual = new Object[] { entry.getKey().getFirst(), entry.getKey().getSecond(), @@ -281,13 +254,13 @@ public class RelationTypeSideSorterTest { } } - private static void addData(RelationOrderData orderData, List<Object[]> expectedData, RelationType relationType, RelationSide side, String relationOrderIdGuid, String... guids) { + private static void addData(RelationOrderData orderData, List<Object[]> expectedData, RelationType relationType, RelationSide side, RelationSorter sorterId, String... guids) { List<String> artGuids = new ArrayList<>(); if (guids != null && guids.length > 0) { artGuids.addAll(Arrays.asList(guids)); } - orderData.addOrderList(relationType.getName(), side.name(), relationOrderIdGuid, artGuids); - expectedData.add(new Object[] {relationType.getName(), side.name(), relationOrderIdGuid, artGuids}); + orderData.addOrderList(relationType.getName(), side.name(), sorterId, artGuids); + expectedData.add(new Object[] {relationType.getName(), side.name(), sorterId, artGuids}); } private static final class MockArtifactWithRelations extends MockIArtifact { diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderDataTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderDataTest.java index 1ba82a0d495..38667182ef7 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderDataTest.java +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderDataTest.java @@ -16,6 +16,7 @@ import java.util.List; import java.util.Map.Entry; import java.util.Random; import org.eclipse.osee.framework.core.data.IArtifactType; +import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.enums.BranchState; import org.eclipse.osee.framework.core.enums.BranchType; import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; @@ -60,9 +61,9 @@ public class RelationOrderDataTest { RelationTypeCache cache = new RelationTypeCache(); - relationType1 = createRelationType(cache, "Rel 1", RelationOrderBaseTypes.USER_DEFINED.getGuid()); - relationType2 = createRelationType(cache, "Rel 2", RelationOrderBaseTypes.UNORDERED.getGuid()); - relationType3 = createRelationType(cache, "Rel 3", RelationOrderBaseTypes.LEXICOGRAPHICAL_ASC.getGuid()); + relationType1 = createRelationType(cache, "Rel 1", RelationOrderBaseTypes.USER_DEFINED); + relationType2 = createRelationType(cache, "Rel 2", RelationOrderBaseTypes.UNORDERED); + relationType3 = createRelationType(cache, "Rel 3", RelationOrderBaseTypes.LEXICOGRAPHICAL_ASC); Assert.assertFalse(data.hasEntries()); Assert.assertEquals(0, data.size()); @@ -88,8 +89,7 @@ public class RelationOrderDataTest { Assert.assertTrue(accessor.wasLoadCalled()); List<Object[]> expected = new ArrayList<>(); - addData(data, expected, relationType1, RelationSide.SIDE_A, // - RelationOrderBaseTypes.LEXICOGRAPHICAL_ASC.getGuid(), "1", "2", "3"); + addData(data, expected, relationType1, RelationSide.SIDE_A, RelationSorter.LEXICOGRAPHICAL_ASC, "1", "2", "3"); checkData(data, expected); accessor.clearLoadCalled(); @@ -129,11 +129,11 @@ public class RelationOrderDataTest { Assert.assertTrue(ex instanceof OseeArgumentException); } - String actualGuid = data.getCurrentSorterGuid(relationType1, RelationSide.SIDE_A); - Assert.assertEquals(RelationOrderBaseTypes.LEXICOGRAPHICAL_ASC.getGuid(), actualGuid); + RelationSorter actualGuid = data.getCurrentSorterGuid(relationType1, RelationSide.SIDE_A); + Assert.assertEquals(RelationOrderBaseTypes.LEXICOGRAPHICAL_ASC, actualGuid); actualGuid = data.getCurrentSorterGuid(relationType2, RelationSide.SIDE_B); - Assert.assertEquals(RelationOrderBaseTypes.UNORDERED.getGuid(), actualGuid); + Assert.assertEquals(RelationOrderBaseTypes.UNORDERED, actualGuid); // Pair does not exist actualGuid = data.getCurrentSorterGuid(relationType2, RelationSide.SIDE_A); @@ -216,8 +216,7 @@ public class RelationOrderDataTest { // Store accessor.clearStoreCalled(); - data.store(relationType1, RelationSide.SIDE_A, - RelationOrderBaseTypes.getFromGuid(relationType1.getDefaultOrderTypeGuid()), emptyList); + data.store(relationType1, RelationSide.SIDE_A, relationType1.getDefaultOrderTypeGuid(), emptyList); Assert.assertTrue(accessor.wasStoreCalled()); // Store @@ -232,19 +231,15 @@ public class RelationOrderDataTest { } private void addData(List<Object[]> expected) { - addData(data, expected, relationType1, RelationSide.SIDE_A, // - RelationOrderBaseTypes.LEXICOGRAPHICAL_ASC.getGuid(), "1", "2", "3"); - - addData(data, expected, relationType2, RelationSide.SIDE_B, // - RelationOrderBaseTypes.UNORDERED.getGuid(), "4", "5", "6"); - + addData(data, expected, relationType1, RelationSide.SIDE_A, RelationSorter.LEXICOGRAPHICAL_ASC, "1", "2", "3"); + addData(data, expected, relationType2, RelationSide.SIDE_B, RelationSorter.UNORDERED, "4", "5", "6"); checkData(data, expected); } private void checkData(RelationOrderData orderData, List<Object[]> expectedValues) { int index = 0; Assert.assertEquals(expectedValues.size(), orderData.size()); - for (Entry<Pair<String, String>, Pair<String, List<String>>> entry : orderData.getOrderedEntrySet()) { + for (Entry<Pair<String, String>, Pair<RelationSorter, List<String>>> entry : orderData.getOrderedEntrySet()) { Object[] actual = new Object[] { entry.getKey().getFirst(), entry.getKey().getSecond(), @@ -258,11 +253,8 @@ public class RelationOrderDataTest { } } - private void addData(RelationOrderData orderData, List<Object[]> expectedData, RelationType relationType, RelationSide side, String relationOrderIdGuid, String... guids) { - List<String> artGuids = new ArrayList<>(); - if (guids != null && guids.length > 0) { - artGuids.addAll(Arrays.asList(guids)); - } + private void addData(RelationOrderData orderData, List<Object[]> expectedData, RelationType relationType, RelationSide side, RelationSorter relationOrderIdGuid, String... guids) { + List<String> artGuids = Arrays.asList(guids); orderData.addOrderList(relationType.getName(), side.name(), relationOrderIdGuid, artGuids); expectedData.add(new Object[] {relationType.getName(), side.name(), relationOrderIdGuid, artGuids}); } @@ -274,7 +266,7 @@ public class RelationOrderDataTest { return DataFactory.createArtifact(uniqueId, name, guid, branch); } - private static RelationType createRelationType(RelationTypeCache cache, String name, String delationRelationOrderGuid) throws OseeCoreException { + private static RelationType createRelationType(RelationTypeCache cache, String name, RelationSorter delationRelationOrderGuid) throws OseeCoreException { IArtifactType type1 = new ArtifactType(0x01L, "1", false); IArtifactType type2 = new ArtifactType(0x02L, "2", false); RelationType relationType = new RelationType(0x03L, name, name + "_A", name + "_B", type1, type2, diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderParserTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderParserTest.java index 0d9048787f1..8b83093b591 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderParserTest.java +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderParserTest.java @@ -10,15 +10,16 @@ *******************************************************************************/ package org.eclipse.osee.framework.skynet.core.relation.order; +import static org.eclipse.osee.framework.core.data.RelationSorter.USER_DEFINED; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map.Entry; +import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.enums.RelationSide; import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; import org.eclipse.osee.framework.jdk.core.type.Pair; -import org.eclipse.osee.framework.skynet.core.types.IArtifact; import org.junit.Assert; import org.junit.Test; @@ -33,7 +34,7 @@ public class RelationOrderParserTest { "<OrderList>\n<Order relType=\"Default Hierarchical\" side=\"SIDE_B\" orderType=\"AAT0xogoMjMBhARkBZQA\" list=\"AAABDEJ_mIQBf8VXVtGqvA\"/>\n</OrderList>"; private static String twoEntries = - "<OrderList>\n<Order relType=\"Default Hierarchical\" side=\"SIDE_B\" orderType=\"AAT0xogoMjMBhARkBZQA\" list=\"AAABDEJ_mIQBf8VXVtGqvA,AAABDEJ_oQ8Bf8VXLX7U_g\"/>\n" + "<Order relType=\"Some Type\" side=\"SIDE_A\" orderType=\"AAABDEJ_mIQBf8VXVtGqvA\" list=\"AAABDEJ_mIQXf8VXVtGqvA,AAABDEJ_oQVBf8VXLX7U_g\"/>\n</OrderList>"; + "<OrderList>\n<Order relType=\"Default Hierarchical\" side=\"SIDE_B\" orderType=\"AAT0xogoMjMBhARkBZQA\" list=\"AAABDEJ_mIQBf8VXVtGqvA,AAABDEJ_oQ8Bf8VXLX7U_g\"/>\n" + "<Order relType=\"Some Type\" side=\"SIDE_A\" orderType=\"AAT0xogoMjMBhARkBZQA\" list=\"AAABDEJ_mIQXf8VXVtGqvA,AAABDEJ_oQVBf8VXLX7U_g\"/>\n</OrderList>"; private static String oneEntryEmptyList = "<OrderList>\n<Order relType=\"X\" side=\"SIDE_B\" orderType=\"AAT0xogoMjMBhARkBZQA\"/>\n</OrderList>"; @@ -64,7 +65,7 @@ public class RelationOrderParserTest { public void testWithData1Parser() throws OseeCoreException { RelationOrderParser parser = new RelationOrderParser(); - RelationOrderData data = new MockRelationOrderData(null); + RelationOrderData data = new RelationOrderData(null, null); checkEmptyEntries(data, parser); parser.loadFromXml(data, oneEntry); @@ -73,8 +74,8 @@ public class RelationOrderParserTest { Assert.assertEquals(1, data.size()); List<Object[]> expectedData = new ArrayList<>(); - addData(expectedData, "Default Hierarchical", RelationSide.SIDE_B, "AAT0xogoMjMBhARkBZQA", - "AAABDEJ_mIQBf8VXVtGqvA", "AAABDEJ_nMkBf8VXVXptpg", "AAABDEJ_oQ8Bf8VXLX7U_g"); + addData(expectedData, "Default Hierarchical", RelationSide.SIDE_B, USER_DEFINED, "AAABDEJ_mIQBf8VXVtGqvA", + "AAABDEJ_nMkBf8VXVXptpg", "AAABDEJ_oQ8Bf8VXLX7U_g"); checkData(data, expectedData); Assert.assertEquals(oneEntry, parser.toXml(data)); @@ -95,7 +96,7 @@ public class RelationOrderParserTest { public void testWithData2Parser() throws OseeCoreException { RelationOrderParser parser = new RelationOrderParser(); - RelationOrderData data = new MockRelationOrderData(null); + RelationOrderData data = new RelationOrderData(null, null); checkEmptyEntries(data, parser); parser.loadFromXml(data, twoEntries); @@ -103,9 +104,9 @@ public class RelationOrderParserTest { Assert.assertEquals(2, data.size()); List<Object[]> expectedData = new ArrayList<>(); - addData(expectedData, "Default Hierarchical", RelationSide.SIDE_B, "AAT0xogoMjMBhARkBZQA", - "AAABDEJ_mIQBf8VXVtGqvA", "AAABDEJ_oQ8Bf8VXLX7U_g"); - addData(expectedData, "Some Type", RelationSide.SIDE_A, "AAABDEJ_mIQBf8VXVtGqvA", "AAABDEJ_mIQXf8VXVtGqvA", + addData(expectedData, "Default Hierarchical", RelationSide.SIDE_B, USER_DEFINED, "AAABDEJ_mIQBf8VXVtGqvA", + "AAABDEJ_oQ8Bf8VXLX7U_g"); + addData(expectedData, "Some Type", RelationSide.SIDE_A, USER_DEFINED, "AAABDEJ_mIQXf8VXVtGqvA", "AAABDEJ_oQVBf8VXLX7U_g"); checkData(data, expectedData); @@ -116,7 +117,7 @@ public class RelationOrderParserTest { public void testOneEntryEmptyList() throws OseeCoreException { RelationOrderParser parser = new RelationOrderParser(); - RelationOrderData data = new MockRelationOrderData(null); + RelationOrderData data = new RelationOrderData(null, null); checkEmptyEntries(data, parser); parser.loadFromXml(data, oneEntryEmptyList); @@ -124,7 +125,7 @@ public class RelationOrderParserTest { Assert.assertEquals(1, data.size()); List<Object[]> expectedData = new ArrayList<>(); - addData(expectedData, "X", RelationSide.SIDE_B, "AAT0xogoMjMBhARkBZQA"); + addData(expectedData, "X", RelationSide.SIDE_B, USER_DEFINED); checkData(data, expectedData); Assert.assertEquals(oneEntryEmptyList, parser.toXml(data)); } @@ -133,7 +134,7 @@ public class RelationOrderParserTest { public void testNullDataParser() throws OseeCoreException { RelationOrderParser parser = new RelationOrderParser(); - RelationOrderData data = new MockRelationOrderData(null); + RelationOrderData data = new RelationOrderData(null, null); checkEmptyEntries(data, parser); parser.loadFromXml(data, null); @@ -159,7 +160,7 @@ public class RelationOrderParserTest { public void testBadDataParser() throws OseeCoreException { RelationOrderParser parser = new RelationOrderParser(); - RelationOrderData data = new MockRelationOrderData(null); + RelationOrderData data = new RelationOrderData(null, null); checkEmptyEntries(data, parser); try { @@ -176,18 +177,14 @@ public class RelationOrderParserTest { Assert.assertEquals("<OrderList>\n</OrderList>", parser.toXml(data)); } - private void addData(List<Object[]> expectedData, String relationType, RelationSide side, String relationOrderIdGuid, String... guids) { - List<String> artGuids = new ArrayList<>(); - if (guids != null && guids.length > 0) { - artGuids.addAll(Arrays.asList(guids)); - } - expectedData.add(new Object[] {relationType, side.name(), relationOrderIdGuid, artGuids}); + private void addData(List<Object[]> expectedData, String relationType, RelationSide side, RelationSorter relationOrderIdGuid, String... guids) { + expectedData.add(new Object[] {relationType, side.name(), relationOrderIdGuid, Arrays.asList(guids)}); } private void checkData(RelationOrderData orderData, List<Object[]> expectedValues) { int index = 0; Assert.assertEquals(expectedValues.size(), orderData.size()); - for (Entry<Pair<String, String>, Pair<String, List<String>>> entry : orderData.getOrderedEntrySet()) { + for (Entry<Pair<String, String>, Pair<RelationSorter, List<String>>> entry : orderData.getOrderedEntrySet()) { Object[] actual = new Object[] { entry.getKey().getFirst(), entry.getKey().getSecond(), @@ -200,10 +197,4 @@ public class RelationOrderParserTest { } } } - - private final static class MockRelationOrderData extends RelationOrderData { - public MockRelationOrderData(IArtifact artifact) { - super(null, artifact); - } - } -} +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationSorterProviderTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationSorterProviderTest.java index 527aeb7d049..ed115d7eb87 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationSorterProviderTest.java +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationSorterProviderTest.java @@ -10,84 +10,57 @@ *******************************************************************************/ package org.eclipse.osee.framework.skynet.core.relation.order; -import static org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes.LEXICOGRAPHICAL_ASC; -import static org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes.LEXICOGRAPHICAL_DESC; -import static org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes.UNORDERED; -import static org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes.USER_DEFINED; +import static org.eclipse.osee.framework.core.data.RelationSorter.LEXICOGRAPHICAL_ASC; +import static org.eclipse.osee.framework.core.data.RelationSorter.LEXICOGRAPHICAL_DESC; +import static org.eclipse.osee.framework.core.data.RelationSorter.UNORDERED; +import static org.eclipse.osee.framework.core.data.RelationSorter.USER_DEFINED; import java.util.Arrays; import java.util.List; import org.eclipse.osee.framework.core.data.RelationSorter; -import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; import org.eclipse.osee.framework.jdk.core.util.Collections; -import org.eclipse.osee.framework.jdk.core.util.GUID; import org.eclipse.osee.framework.skynet.core.relation.sorters.LexicographicalRelationSorter; import org.eclipse.osee.framework.skynet.core.relation.sorters.UnorderedRelationSorter; import org.eclipse.osee.framework.skynet.core.relation.sorters.UserDefinedRelationSorter; import org.junit.Assert; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; /** * @author Roberto E. Escobar */ public class RelationSorterProviderTest { + @Rule + public ExpectedException thrown = ExpectedException.none(); @Test public void testGetAllRelationOrderIds() { RelationSorterProvider provider = new RelationSorterProvider(); List<RelationSorter> actual = provider.getAllRelationOrderIds(); - List<RelationSorter> expected = - Collections.castAll(RelationSorter.class, Arrays.asList(RelationOrderBaseTypes.values())); + List<RelationSorter> expected = Arrays.asList(LEXICOGRAPHICAL_ASC, LEXICOGRAPHICAL_DESC, UNORDERED, USER_DEFINED); Assert.assertTrue(Collections.isEqual(expected, actual)); } @Test public void testGetRelationOrder() throws OseeCoreException { RelationSorterProvider provider = new RelationSorterProvider(); - for (RelationSorter baseType : RelationOrderBaseTypes.values()) { - IRelationSorter actual = provider.getRelationOrder(baseType.getGuid()); - Assert.assertEquals(baseType, actual.getSorterId()); - boolean matches = false; - if (baseType == LEXICOGRAPHICAL_ASC) { - matches = actual instanceof LexicographicalRelationSorter; - } else if (baseType == LEXICOGRAPHICAL_DESC) { - matches = actual instanceof LexicographicalRelationSorter; + testSorter(provider, RelationSorter.LEXICOGRAPHICAL_ASC, LexicographicalRelationSorter.class); + testSorter(provider, RelationSorter.LEXICOGRAPHICAL_DESC, LexicographicalRelationSorter.class); + testSorter(provider, RelationSorter.UNORDERED, UnorderedRelationSorter.class); + testSorter(provider, RelationSorter.USER_DEFINED, UserDefinedRelationSorter.class); - } else if (baseType == UNORDERED) { - matches = actual instanceof UnorderedRelationSorter; - - } else if (baseType == USER_DEFINED) { - matches = actual instanceof UserDefinedRelationSorter; - } else { - Assert.assertNull("This line should not be reached"); - } - Assert.assertTrue(matches); - } + thrown.expect(OseeArgumentException.class); + thrown.expectMessage("No sorted is defined for preexisting (nor should there be)."); + testSorter(provider, RelationSorter.PREEXISTING, UserDefinedRelationSorter.class); } - @Test - public void testArgumentExceptions() { - RelationSorterProvider provider = new RelationSorterProvider(); - try { - provider.getRelationOrder("ABC"); - Assert.assertNull("This line should not be reached"); - } catch (Exception ex) { - Assert.assertTrue(ex instanceof OseeArgumentException); - } - } - - @Test - public void testNotFoundExceptions() { - RelationSorterProvider provider = new RelationSorterProvider(); - String randomGuid = GUID.create(); - try { - provider.getRelationOrder(randomGuid); - Assert.assertNull("This line should not be reached"); - } catch (Exception ex) { - Assert.assertTrue(ex instanceof OseeCoreException); - } + private void testSorter(RelationSorterProvider provider, RelationSorter sorterId, Class<? extends IRelationSorter> clazz) { + IRelationSorter actual = provider.getRelationOrder(sorterId); + Assert.assertEquals(sorterId, actual.getSorterId()); + Assert.assertEquals(clazz, actual.getClass()); } -} +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/sorters/RelationSorterTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/sorters/RelationSorterTest.java index dcac289e7e6..070c828ba28 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/sorters/RelationSorterTest.java +++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/sorters/RelationSorterTest.java @@ -53,8 +53,7 @@ public class RelationSorterTest { @Test public void testSorterId() { Assert.assertNotNull(message, sorter.getSorterId()); - Assert.assertEquals(message, expectedOrderId.getGuid(), sorter.getSorterId().getGuid()); - Assert.assertEquals(message, expectedOrderId.getName(), sorter.getSorterId().getName()); + Assert.assertEquals(message, expectedOrderId, sorter.getSorterId()); } @Test 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 c8d27a61b9a..58db429cb3a 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 @@ -57,7 +57,7 @@ public class ArtifactTypeEventFilter implements IEventFilter { return true; } for (IArtifactType matchArtType : artifactTypes) { - if (matchArtType.getGuid().equals(artType.getGuid())) { + if (matchArtType.equals(artType)) { return true; } } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/DslToTypeLoader.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/DslToTypeLoader.java index 8223f77763f..aa1ff0246d9 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/DslToTypeLoader.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/DslToTypeLoader.java @@ -23,6 +23,7 @@ import java.util.Set; import java.util.logging.Level; import org.eclipse.emf.common.util.EList; import org.eclipse.osee.framework.core.data.BranchId; +import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.data.TokenFactory; import org.eclipse.osee.framework.core.dsl.OseeDslResource; import org.eclipse.osee.framework.core.dsl.OseeDslResourceUtil; @@ -45,7 +46,6 @@ import org.eclipse.osee.framework.core.dsl.oseeDsl.XOseeEnumType; import org.eclipse.osee.framework.core.dsl.oseeDsl.XRelationType; import org.eclipse.osee.framework.core.dsl.oseeDsl.util.OseeDslSwitch; import org.eclipse.osee.framework.core.enums.CoreBranches; -import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; import org.eclipse.osee.framework.core.enums.RelationTypeMultiplicity; import org.eclipse.osee.framework.core.model.IOseeStorable; import org.eclipse.osee.framework.core.model.OseeEnumEntry; @@ -64,7 +64,6 @@ import org.eclipse.osee.framework.core.model.type.OseeEnumTypeFactory; import org.eclipse.osee.framework.core.model.type.RelationTypeFactory; import org.eclipse.osee.framework.core.services.IOseeCachingService; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; -import org.eclipse.osee.framework.jdk.core.util.Conditions; import org.eclipse.osee.framework.jdk.core.util.HexUtil; import org.eclipse.osee.framework.jdk.core.util.Lib; import org.eclipse.osee.framework.jdk.core.util.Strings; @@ -166,8 +165,7 @@ public class DslToTypeLoader implements TypesLoader { } private Map<BranchId, Collection<AttributeType>> getOseeAttributes(TypeBuffer buffer, BranchCache branchCache, XArtifactType xArtifactType) throws OseeCoreException { - Map<BranchId, Collection<AttributeType>> validAttributes = - new HashMap<BranchId, Collection<AttributeType>>(); + Map<BranchId, Collection<AttributeType>> validAttributes = new HashMap<BranchId, Collection<AttributeType>>(); for (XAttributeTypeRef xAttributeTypeRef : xArtifactType.getValidAttributeTypes()) { XAttributeType xAttributeType = xAttributeTypeRef.getValidAttributeType(); BranchId branch = getAttributeBranch(branchCache, xAttributeTypeRef); @@ -375,13 +373,7 @@ public class DslToTypeLoader implements TypesLoader { sideAType, // sideBType, // multiplicity, // - orderTypeNameToGuid(xRelationType.getDefaultOrderType()) // - ); - } - - private String orderTypeNameToGuid(String orderTypeName) throws OseeCoreException { - Conditions.checkNotNull(orderTypeName, "orderTypeName"); - return RelationOrderBaseTypes.getFromOrderTypeName(orderTypeName.replaceAll("_", " ")).getGuid(); + RelationSorter.valueOfName(xRelationType.getDefaultOrderType())); } private static final class TypeBuffer { diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationLink.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationLink.java index 35a68d418b5..2042dee5616 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationLink.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationLink.java @@ -15,12 +15,11 @@ import java.util.logging.Level; import org.eclipse.osee.framework.core.data.ApplicabilityId; import org.eclipse.osee.framework.core.data.BranchId; import org.eclipse.osee.framework.core.data.HasBranch; -import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.data.IRelationType; +import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; import org.eclipse.osee.framework.core.enums.DeletionFlag; import org.eclipse.osee.framework.core.enums.ModificationType; -import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; import org.eclipse.osee.framework.core.enums.RelationSide; import org.eclipse.osee.framework.core.model.type.RelationType; import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException; @@ -393,10 +392,8 @@ public class RelationLink implements HasBranch { RelationOrderData leftData = factory.createRelationOrderData(aArtifact); RelationOrderData rightData = factory.createRelationOrderData(bArtifact); - RelationSorter leftSorter = - RelationOrderBaseTypes.getFromGuid(leftData.getCurrentSorterGuid(getRelationType(), getSide(aArtifact))); - RelationSorter rightSorter = - RelationOrderBaseTypes.getFromGuid(rightData.getCurrentSorterGuid(getRelationType(), getSide(bArtifact))); + RelationSorter leftSorter = leftData.getCurrentSorterGuid(getRelationType(), getSide(aArtifact)); + RelationSorter rightSorter = rightData.getCurrentSorterGuid(getRelationType(), getSide(bArtifact)); return rightSorter.equals(USER_DEFINED) && leftSorter.equals(USER_DEFINED); } 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 0ac6a311c09..7f232020670 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 @@ -24,9 +24,9 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.logging.Level; import org.eclipse.osee.framework.core.data.ApplicabilityId; import org.eclipse.osee.framework.core.data.BranchId; -import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.data.IRelationType; import org.eclipse.osee.framework.core.data.IRelationTypeSide; +import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.enums.DeletionFlag; import org.eclipse.osee.framework.core.enums.ModificationType; import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; @@ -84,9 +84,9 @@ public class RelationManager { // Need to do this check before to catch the relations that are .equal but not == for (RelationLink relation : artifactsRelations) { if (relation.getAArtifactId() == newRelation.getAArtifactId() && // - relation.getBArtifactId() == newRelation.getBArtifactId() && // - relation.getRelationType() == newRelation.getRelationType() && // - relation != newRelation) { + relation.getBArtifactId() == newRelation.getBArtifactId() && // + relation.getRelationType() == newRelation.getRelationType() && // + relation != newRelation) { OseeLog.logf(Activator.class, Level.WARNING, "Duplicate relation objects for same relation for RELATION 1 [%s] RELATION 2 [%s]", relation, newRelation); @@ -111,7 +111,6 @@ public class RelationManager { return getRelatedArtifacts(artifact, relationType, relationSide, true); } - @SuppressWarnings("unused") private static List<Artifact> getRelatedArtifacts(Artifact artifact, IRelationType relationType, RelationSide relationSide, boolean sort) throws OseeCoreException { if (artifact.isHistorical()) { throw new OseeCoreException("Artifact [%s] is historical. Historical relations are only supported on server", @@ -552,10 +551,6 @@ public class RelationManager { relationType.getName(), artifactA.getName(), artifactB.getName()); } - public static RelationSorterProvider getSorterProvider() { - return relationSorterProvider; - } - public static List<RelationSorter> getRelationOrderTypes() { return relationSorterProvider.getAllRelationOrderIds(); } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationTypeSideSorter.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationTypeSideSorter.java index 7e752340af9..0dc386c959a 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationTypeSideSorter.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/RelationTypeSideSorter.java @@ -77,26 +77,12 @@ public class RelationTypeSideSorter extends RelationTypeSide { return hashCode; } - public RelationType getRelationTypeHard() { - return relationType; - } - - private IRelationSorter getSorter() throws OseeCoreException { - String guid = orderData.getCurrentSorterGuid(getRelationTypeHard(), getSide()); - return sorterProvider.getRelationOrder(guid); - } - public RelationSorter getSorterId() throws OseeCoreException { - return getSorter().getSorterId(); - } - - public String getSorterName() throws OseeCoreException { - RelationSorter id = getSorterId(); - return id.getName(); + return orderData.getCurrentSorterGuid(relationType, getSide()); } public void sort(List<? extends IArtifact> listToOrder) throws OseeCoreException { - IRelationSorter order = getSorter(); + IRelationSorter order = sorterProvider.getRelationOrder(getSorterId()); List<String> relativeOrder = orderData.getOrderList(getRelationType(), getSide()); order.sort(listToOrder, relativeOrder); } @@ -137,7 +123,7 @@ public class RelationTypeSideSorter extends RelationTypeSide { } public void setOrder(List<? extends IArtifact> relatives, RelationSorter sorterId) throws OseeCoreException { - orderData.store(getRelationTypeHard(), getSide(), sorterId, relatives); + orderData.store(relationType, getSide(), sorterId, relatives); } @Override diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderData.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderData.java index 46987560031..0a7473eb2fb 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderData.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderData.java @@ -18,8 +18,8 @@ import java.util.Comparator; import java.util.List; import java.util.Map.Entry; import org.eclipse.osee.framework.core.data.BranchId; -import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.data.IRelationType; +import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; import org.eclipse.osee.framework.core.enums.RelationSide; import org.eclipse.osee.framework.core.model.event.DefaultBasicGuidArtifact; @@ -38,7 +38,7 @@ import org.eclipse.osee.framework.skynet.core.utility.Artifacts; */ public class RelationOrderData { - private final CompositeKeyHashMap<String, String, Pair<String, List<String>>> lists; + private final CompositeKeyHashMap<String, String, Pair<RelationSorter, List<String>>> lists; private final IRelationOrderAccessor accessor; private final IArtifact artifact; @@ -61,39 +61,38 @@ public class RelationOrderData { accessor.load(getIArtifact(), this); } - public Collection<Entry<Pair<String, String>, Pair<String, List<String>>>> entrySet() { + public Collection<Entry<Pair<String, String>, Pair<RelationSorter, List<String>>>> entrySet() { return lists.entrySet(); } - public Collection<Entry<Pair<String, String>, Pair<String, List<String>>>> getOrderedEntrySet() { - List<Entry<Pair<String, String>, Pair<String, List<String>>>> entries = - new ArrayList<Entry<Pair<String, String>, Pair<String, List<String>>>>(entrySet()); + public Collection<Entry<Pair<String, String>, Pair<RelationSorter, List<String>>>> getOrderedEntrySet() { + List<Entry<Pair<String, String>, Pair<RelationSorter, List<String>>>> entries = new ArrayList<>(entrySet()); Collections.sort(entries, new EntryComparator()); return entries; } public List<String> getOrderList(IRelationType type, RelationSide side) throws OseeCoreException { - Pair<String, List<String>> currentOrder = getTypeSideEntry(type, side); + Pair<RelationSorter, List<String>> currentOrder = getTypeSideEntry(type, side); return currentOrder != null ? currentOrder.getSecond() : new ArrayList<String>(); } - public String getCurrentSorterGuid(RelationType type, RelationSide side) throws OseeCoreException { - Pair<String, List<String>> currentOrder = getTypeSideEntry(type, side); + public RelationSorter getCurrentSorterGuid(RelationType type, RelationSide side) throws OseeCoreException { + Pair<RelationSorter, List<String>> currentOrder = getTypeSideEntry(type, side); return currentOrder != null ? currentOrder.getFirst() : type.getDefaultOrderTypeGuid(); } - private Pair<String, List<String>> getTypeSideEntry(IRelationType type, RelationSide side) throws OseeCoreException { + private Pair<RelationSorter, List<String>> getTypeSideEntry(IRelationType type, RelationSide side) throws OseeCoreException { Conditions.checkNotNull(type, "relationType"); Conditions.checkNotNull(side, "relationSide"); return lists.get(type.getName(), side.name()); } public void addOrderList(IRelationType type, RelationSide side, RelationSorter sorterId, List<String> guidList) { - addOrderList(type.getName(), side.name(), sorterId.getGuid(), guidList); + addOrderList(type.getName(), side.name(), sorterId, guidList); } - public void addOrderList(String relationType, String relationSide, String sorterGuid, List<String> guidList) { - lists.put(relationType, relationSide, new Pair<String, List<String>>(sorterGuid, guidList)); + public void addOrderList(String relationType, String relationSide, RelationSorter sorterId, List<String> guidList) { + lists.put(relationType, relationSide, new Pair<RelationSorter, List<String>>(sorterId, guidList)); } public void removeOrderList(IRelationType type, RelationSide side) throws OseeCoreException { @@ -138,8 +137,7 @@ public class RelationOrderData { } protected boolean isRevertingToDefaultTypeOrder(RelationType type, RelationSide side, RelationSorter sorterId) throws OseeCoreException { - String defaultOrderGuid = type.getDefaultOrderTypeGuid(); - return sorterId.getGuid().equals(defaultOrderGuid) && isDifferentSorterId(type, side, sorterId); + return sorterId.equals(type.getDefaultOrderTypeGuid()) && isDifferentSorterId(type, side, sorterId); } protected boolean isRelativeOrderChange(IRelationType type, RelationSide side, RelationSorter sorterId, List<String> relativeSequence) throws OseeCoreException { @@ -147,8 +145,8 @@ public class RelationOrderData { } protected boolean isDifferentSorterId(RelationType type, RelationSide side, RelationSorter sorterId) throws OseeCoreException { - String currentSorterGuid = getCurrentSorterGuid(type, side); - return !sorterId.getGuid().equals(currentSorterGuid); + RelationSorter currentSorterGuid = getCurrentSorterGuid(type, side); + return !sorterId.equals(currentSorterGuid); } @Override @@ -160,11 +158,11 @@ public class RelationOrderData { return lists.getEnumeratedKeys(); } - private final static class EntryComparator implements Serializable, Comparator<Entry<Pair<String, String>, Pair<String, List<String>>>> { + private final static class EntryComparator implements Serializable, Comparator<Entry<Pair<String, String>, Pair<RelationSorter, List<String>>>> { private static final long serialVersionUID = 5242452476694174988L; @Override - public int compare(Entry<Pair<String, String>, Pair<String, List<String>>> o1, Entry<Pair<String, String>, Pair<String, List<String>>> o2) { + public int compare(Entry<Pair<String, String>, Pair<RelationSorter, List<String>>> o1, Entry<Pair<String, String>, Pair<RelationSorter, List<String>>> o2) { int result = o1.getKey().getFirst().compareTo(o2.getKey().getFirst()); if (result == 0) { result = o1.getKey().getSecond().compareTo(o2.getKey().getSecond()); diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderMergeUtility.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderMergeUtility.java index a4d232ae508..74d5933063a 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderMergeUtility.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderMergeUtility.java @@ -15,10 +15,9 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; -import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.data.IRelationTypeSide; +import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.enums.DeletionFlag; -import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; import org.eclipse.osee.framework.core.enums.RelationSide; import org.eclipse.osee.framework.core.model.RelationTypeSide; import org.eclipse.osee.framework.core.model.type.RelationType; @@ -41,8 +40,8 @@ public class RelationOrderMergeUtility { RelationType type = RelationTypeManager.getType(typeSide.getFirst()); RelationSide side = RelationSide.fromString(typeSide.getSecond()); RelationTypeSide rts = new RelationTypeSide(type, side); - RelationSorter leftSorter = RelationOrderBaseTypes.getFromGuid(leftData.getCurrentSorterGuid(type, side)); - RelationSorter rightSorter = RelationOrderBaseTypes.getFromGuid(rightData.getCurrentSorterGuid(type, side)); + RelationSorter leftSorter = leftData.getCurrentSorterGuid(type, side); + RelationSorter rightSorter = rightData.getCurrentSorterGuid(type, side); List<String> order = null; if (rightSorter.equals(USER_DEFINED) && leftSorter.equals(USER_DEFINED)) { diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderParser.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderParser.java index f8092bede3f..2f957579f99 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderParser.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderParser.java @@ -16,6 +16,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map.Entry; +import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; import org.eclipse.osee.framework.jdk.core.type.Pair; @@ -71,7 +72,7 @@ public class RelationOrderParser { StringBuilder sb = new StringBuilder(); openRoot(sb); - for (Entry<Pair<String, String>, Pair<String, List<String>>> entry : data.getOrderedEntrySet()) { + for (Entry<Pair<String, String>, Pair<RelationSorter, List<String>>> entry : data.getOrderedEntrySet()) { writeEntry(sb, entry); sb.append("\n"); } @@ -91,7 +92,7 @@ public class RelationOrderParser { sb.append(">"); } - private void writeEntry(StringBuilder sb, Entry<Pair<String, String>, Pair<String, List<String>>> entry) { + private void writeEntry(StringBuilder sb, Entry<Pair<String, String>, Pair<RelationSorter, List<String>>> entry) { Pair<String, String> key = entry.getKey(); sb.append("<"); sb.append("Order "); @@ -101,8 +102,8 @@ public class RelationOrderParser { sb.append(key.getSecond()); sb.append("\" orderType=\""); - Pair<String, List<String>> value = entry.getValue(); - sb.append(value.getFirst()); + Pair<RelationSorter, List<String>> value = entry.getValue(); + sb.append(value.getFirst().getGuid()); List<String> guids = value.getSecond(); if (guids != null) { if (guids.size() > 0) { @@ -145,7 +146,7 @@ public class RelationOrderParser { guidsList = new ArrayList<>(); Collections.addAll(guidsList, guids); } - data.addOrderList(relationType, relationSide, orderType, guidsList); + data.addOrderList(relationType, relationSide, RelationSorter.valueOfGuid(orderType), guidsList); } } } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationSorterIdComparator.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationSorterIdComparator.java deleted file mode 100644 index 1001d568d1d..00000000000 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationSorterIdComparator.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 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.skynet.core.relation.order; - -import java.io.Serializable; -import java.util.Comparator; -import org.eclipse.osee.framework.core.data.RelationSorter; - -/** - * @author Andrew M. Finkbeiner - */ -public class RelationSorterIdComparator implements Serializable, Comparator<RelationSorter> { - private static final long serialVersionUID = -8364743688821990429L; - - @Override - public int compare(RelationSorter o1, RelationSorter o2) { - return o1.getName().compareToIgnoreCase(o2.getName()); - } - -} diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationSorterProvider.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationSorterProvider.java index 38eb104d76a..9cacee14517 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationSorterProvider.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationSorterProvider.java @@ -31,7 +31,7 @@ import org.eclipse.osee.framework.skynet.core.relation.sorters.UserDefinedRelati */ public class RelationSorterProvider { - private final Map<String, IRelationSorter> orderMap; + private final Map<RelationSorter, IRelationSorter> orderMap; public RelationSorterProvider() { orderMap = new ConcurrentHashMap<>(); @@ -43,7 +43,7 @@ public class RelationSorterProvider { } private void registerOrderType(IRelationSorter order) { - orderMap.put(order.getSorterId().getGuid(), order); + orderMap.put(order.getSorterId(), order); } public boolean exists(String orderGuid) throws OseeCoreException { @@ -53,24 +53,28 @@ public class RelationSorterProvider { return orderMap.get(orderGuid) != null; } - public IRelationSorter getRelationOrder(String orderGuid) throws OseeCoreException { - if (!GUID.isValid(orderGuid)) { - throw new OseeArgumentException("Error invalid guid argument"); + public IRelationSorter getRelationOrder(RelationSorter sorterId) throws OseeCoreException { + if (sorterId.equals(RelationSorter.PREEXISTING)) { + throw new OseeArgumentException("No sorted is defined for preexisting (nor should there be)."); } - IRelationSorter order = orderMap.get(orderGuid); + IRelationSorter order = orderMap.get(sorterId); if (order == null) { - throw new OseeCoreException("Unable to locate RelationOrder for guid[%s].", orderGuid); + throw new OseeCoreException("Unable to locate RelationSorter[%s].", sorterId); } return order; } + public Collection<IRelationSorter> getSorters() { + return orderMap.values(); + } + public List<RelationSorter> getAllRelationOrderIds() { Collection<IRelationSorter> relationOrder = orderMap.values(); List<RelationSorter> ids = new ArrayList<>(); for (IRelationSorter order : relationOrder) { ids.add(order.getSorterId()); } - Collections.sort(ids, new RelationSorterIdComparator()); + Collections.sort(ids); return ids; } } diff --git a/plugins/org.eclipse.osee.framework.ui.skynet.test/src/org/eclipse/osee/framework/ui/skynet/renderer/RelationOrderRendererTest.java b/plugins/org.eclipse.osee.framework.ui.skynet.test/src/org/eclipse/osee/framework/ui/skynet/renderer/RelationOrderRendererTest.java index 9dd63861eea..238792bacef 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet.test/src/org/eclipse/osee/framework/ui/skynet/renderer/RelationOrderRendererTest.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet.test/src/org/eclipse/osee/framework/ui/skynet/renderer/RelationOrderRendererTest.java @@ -14,8 +14,9 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; -import org.eclipse.osee.framework.core.data.IArtifactType; import org.eclipse.osee.framework.core.data.BranchId; +import org.eclipse.osee.framework.core.data.IArtifactType; +import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; import org.eclipse.osee.framework.core.enums.RelationSide; import org.eclipse.osee.framework.core.enums.RelationTypeMultiplicity; @@ -25,15 +26,11 @@ import org.eclipse.osee.framework.core.model.cache.RelationTypeCache; import org.eclipse.osee.framework.core.model.type.ArtifactType; import org.eclipse.osee.framework.core.model.type.RelationType; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; -import org.eclipse.osee.framework.jdk.core.util.GUID; import org.eclipse.osee.framework.skynet.core.linking.OseeLinkBuilder; -import org.eclipse.osee.framework.skynet.core.relation.order.IRelationSorter; import org.eclipse.osee.framework.skynet.core.relation.order.RelationOrderData; -import org.eclipse.osee.framework.skynet.core.relation.order.RelationSorterProvider; import org.eclipse.osee.framework.ui.skynet.render.ArtifactGuidToWordML; import org.eclipse.osee.framework.ui.skynet.render.RelationOrderRenderer; import org.eclipse.osee.framework.ui.skynet.render.word.WordMLProducer; -import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -44,7 +41,6 @@ import org.junit.Test; public class RelationOrderRendererTest { private static RelationOrderRenderer renderer; - private static RelationSorterProvider sorterProvider; @BeforeClass public static void prepareTest() throws Exception { @@ -52,14 +48,7 @@ public class RelationOrderRendererTest { AbstractOseeCache<RelationType> typeCache = new RelationTypeCache(); addRelationTypeData(typeCache); - sorterProvider = new RelationSorterProvider(); - renderer = new RelationOrderRenderer(typeCache, resolver, sorterProvider); - } - - @AfterClass - public static void cleanupTest() throws Exception { - sorterProvider = null; - renderer = null; + renderer = new RelationOrderRenderer(typeCache, resolver); } @Test @@ -68,31 +57,23 @@ public class RelationOrderRendererTest { List<Object[]> expectedData = new ArrayList<>(); addData(orderData, expectedData, "Relation 1", "Relation 1_A", RelationSide.SIDE_A, - RelationOrderBaseTypes.LEXICOGRAPHICAL_ASC.getGuid(), "1", "2", "3"); + RelationOrderBaseTypes.LEXICOGRAPHICAL_ASC, "1", "2", "3"); addData(orderData, expectedData, "Relation 2", "Relation 2_B", RelationSide.SIDE_B, // - RelationOrderBaseTypes.UNORDERED.getGuid(), "4", "5", "6"); + RelationOrderBaseTypes.UNORDERED, "4", "5", "6"); addData(orderData, expectedData, "Relation 3", "Relation 3_B", RelationSide.SIDE_B, // - RelationOrderBaseTypes.USER_DEFINED.getGuid(), "7", "8", "9"); + RelationOrderBaseTypes.USER_DEFINED, "7", "8", "9"); checkRelationOrderRenderer(getExpected(expectedData), orderData); } - @Test(expected = OseeCoreException.class) - public void testRenderingOrderTypeNotFound() throws OseeCoreException { - RelationOrderData orderData = new MockRelationOrderData(); - List<Object[]> expectedData = new ArrayList<>(); - addData(orderData, expectedData, "Relation 1", "Relation 1_A", RelationSide.SIDE_A, GUID.create(), "0", "1", "2"); - checkRelationOrderRenderer(getExpected(expectedData), orderData); - } - @Test public void testRenderingEmptyGuids() throws OseeCoreException { RelationOrderData orderData = new MockRelationOrderData(); List<Object[]> expectedData = new ArrayList<>(); addData(orderData, expectedData, "Relation 1", "Relation 1_A", RelationSide.SIDE_A, - RelationOrderBaseTypes.USER_DEFINED.getGuid()); + RelationOrderBaseTypes.USER_DEFINED); checkRelationOrderRenderer(getExpected(expectedData), orderData); } @@ -103,19 +84,12 @@ public class RelationOrderRendererTest { checkRelationOrderRenderer(getExpected(expectedData), orderData); } - private void addData(RelationOrderData orderData, List<Object[]> expectedData, String relationType, String relationSideName, RelationSide side, String relationOrderIdGuid, String... guids) throws OseeCoreException { - List<String> artGuids = new ArrayList<>(); - if (guids != null && guids.length > 0) { - artGuids.addAll(Arrays.asList(guids)); - } - orderData.addOrderList(relationType, side.name(), relationOrderIdGuid, artGuids); - - String expectedOrderId = relationOrderIdGuid; - IRelationSorter sorter = sorterProvider.getRelationOrder(relationOrderIdGuid); - expectedOrderId = sorter.getSorterId().getName(); + private void addData(RelationOrderData orderData, List<Object[]> expectedData, String relationType, String relationSideName, RelationSide side, RelationSorter expectedSorterId, String... guids) throws OseeCoreException { + List<String> guidList = Arrays.asList(guids); + orderData.addOrderList(relationType, side.name(), expectedSorterId, guidList); expectedData.add( - new Object[] {relationType, relationSideName, side.name().toLowerCase(), expectedOrderId, artGuids}); + new Object[] {relationType, relationSideName, side.name().toLowerCase(), expectedSorterId, guidList}); } private String getExpected(List<Object[]> data) { @@ -202,7 +176,7 @@ public class RelationOrderRendererTest { private final static void createRelationType(AbstractOseeCache<RelationType> cache, String name, IArtifactType artifactType1, IArtifactType artifactType2) throws OseeCoreException { RelationType type = new RelationType(0x00L, name, name + "_A", name + "_B", artifactType1, artifactType2, - RelationTypeMultiplicity.MANY_TO_MANY, ""); + RelationTypeMultiplicity.MANY_TO_MANY, null); cache.cache(type); } private final static class MockRelationOrderData extends RelationOrderData { diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/RelationOrderContributionItem.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/RelationOrderContributionItem.java index 5ab9026fd38..87a59479701 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/RelationOrderContributionItem.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/RelationOrderContributionItem.java @@ -91,13 +91,11 @@ public class RelationOrderContributionItem extends ContributionItem { public void widgetArmed(ArmEvent e) { RelationSorter sorterId = getSelectedSorterId(); if (sorterId != null) { - String orderGuid = sorterId.getGuid(); for (MenuItem item : subMenu.getItems()) { Object data = item.getData(); - if (data instanceof String) { - String itemGuid = (String) data; - boolean matches = orderGuid.equals(itemGuid); - item.setSelection(matches); + if (data instanceof RelationSorter) { + RelationSorter itemSorterId = (RelationSorter) data; + item.setSelection(sorterId.equals(itemSorterId)); } } } @@ -163,8 +161,8 @@ public class RelationOrderContributionItem extends ContributionItem { private void createMenuItem(final Menu menu, final RelationSorter id) { final MenuItem menuItem = new MenuItem(menu, SWT.CHECK); - menuItem.setText(id.getName()); - menuItem.setData(id.getGuid()); + menuItem.setText(id.toString()); + menuItem.setData(id); menuItem.setSelection(false); menuItem.addSelectionListener(new SelectionAdapter() { @@ -174,7 +172,7 @@ public class RelationOrderContributionItem extends ContributionItem { if (sorter != null) { try { RelationSorter sorterId = sorter.getSorterId(); - if (!id.getGuid().equals(sorterId.getGuid())) { + if (!id.equals(sorterId)) { Artifact artifact = sorter.getArtifact(); artifact.setRelationOrder(sorter, id); notifyListeners(sorter, sorterId, id); diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/artifact/ArtifactPasteOperation.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/artifact/ArtifactPasteOperation.java index 34e3d9d50ce..d975c752103 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/artifact/ArtifactPasteOperation.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/artifact/ArtifactPasteOperation.java @@ -16,6 +16,7 @@ import java.util.List; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.osee.framework.core.data.IRelationTypeSide; +import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.enums.CoreRelationTypes; import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; import org.eclipse.osee.framework.core.operation.AbstractOperation; @@ -26,7 +27,6 @@ import org.eclipse.osee.framework.skynet.core.User; 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.RelationTypeManager; -import org.eclipse.osee.framework.skynet.core.relation.order.IRelationSorter; import org.eclipse.osee.framework.skynet.core.relation.order.RelationOrderData; import org.eclipse.osee.framework.ui.skynet.internal.Activator; import org.eclipse.osee.framework.ui.skynet.util.ArtifactPasteConfiguration; @@ -89,13 +89,12 @@ public class ArtifactPasteOperation extends AbstractOperation { if (config.isKeepRelationOrderSettings()) { IRelationTypeSide relationTypeSide = CoreRelationTypes.Default_Hierarchical__Child; RelationOrderData data = RelationManager.createRelationOrderData(source); - String order = + RelationSorter order = data.getCurrentSorterGuid(RelationTypeManager.getType(relationTypeSide), relationTypeSide.getSide()); - IRelationSorter sorter = RelationManager.getSorterProvider().getRelationOrder(order); - if (RelationOrderBaseTypes.USER_DEFINED == sorter.getSorterId()) { + if (RelationOrderBaseTypes.USER_DEFINED == order) { newArtifact.setRelationOrder(relationTypeSide, copiedChildren); } else { - newArtifact.setRelationOrder(relationTypeSide, sorter.getSorterId()); + newArtifact.setRelationOrder(relationTypeSide, order); } } } diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/RelationOrderRepairBlam.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/RelationOrderRepairBlam.java index 0de045d3828..05cc97569d8 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/RelationOrderRepairBlam.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/RelationOrderRepairBlam.java @@ -16,6 +16,7 @@ import java.util.Collections; import java.util.List; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.osee.framework.core.data.BranchId; +import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; import org.eclipse.osee.framework.core.enums.RelationSide; import org.eclipse.osee.framework.core.exception.OseeTypeDoesNotExist; @@ -96,9 +97,9 @@ public class RelationOrderRepairBlam extends AbstractBlam { return; } RelationSide side = RelationSide.fromString(typeSide.getSecond()); - String sorterGuid = currentData.getCurrentSorterGuid(type, side); + RelationSorter sorterGuid = currentData.getCurrentSorterGuid(type, side); - if (sorterGuid.equals(RelationOrderBaseTypes.USER_DEFINED.getGuid())) { + if (sorterGuid.equals(RelationOrderBaseTypes.USER_DEFINED)) { List<String> orderList = currentData.getOrderList(type, side); List<String> actualOrder = Artifacts.toGuids(RelationManager.getRelatedArtifacts(art, type, side)); if (!orderList.equals(actualOrder)) { diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/DefaultArtifactRenderer.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/DefaultArtifactRenderer.java index 7eb7e13835f..a20d7704d8e 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/DefaultArtifactRenderer.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/DefaultArtifactRenderer.java @@ -177,8 +177,8 @@ public class DefaultArtifactRenderer implements IRenderer { private String renderRelationOrder(Artifact artifact) throws OseeCoreException { StringBuilder builder = new StringBuilder(); ArtifactGuidToWordML guidResolver = new ArtifactGuidToWordML(new OseeLinkBuilder()); - RelationOrderRenderer renderer = new RelationOrderRenderer( - ServiceUtil.getOseeCacheService().getRelationTypeCache(), guidResolver, RelationManager.getSorterProvider()); + RelationOrderRenderer renderer = + new RelationOrderRenderer(ServiceUtil.getOseeCacheService().getRelationTypeCache(), guidResolver); WordMLProducer producer = new WordMLProducer(builder); RelationOrderData relationOrderData = RelationManager.createRelationOrderData(artifact); diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/RelationOrderRenderer.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/RelationOrderRenderer.java index f83278aeeed..2098c2c1c54 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/RelationOrderRenderer.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/render/RelationOrderRenderer.java @@ -14,15 +14,14 @@ import java.util.List; import java.util.Map.Entry; import java.util.logging.Level; import org.eclipse.osee.framework.core.data.BranchId; +import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.enums.RelationSide; import org.eclipse.osee.framework.core.model.cache.AbstractOseeCache; import org.eclipse.osee.framework.core.model.type.RelationType; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; import org.eclipse.osee.framework.jdk.core.type.Pair; import org.eclipse.osee.framework.logging.OseeLog; -import org.eclipse.osee.framework.skynet.core.relation.order.IRelationSorter; import org.eclipse.osee.framework.skynet.core.relation.order.RelationOrderData; -import org.eclipse.osee.framework.skynet.core.relation.order.RelationSorterProvider; import org.eclipse.osee.framework.ui.skynet.internal.Activator; import org.eclipse.osee.framework.ui.skynet.render.word.Producer; import org.eclipse.osee.framework.ui.skynet.render.word.WordMLProducer; @@ -33,24 +32,11 @@ import org.eclipse.osee.framework.ui.skynet.render.word.WordMLProducer; public class RelationOrderRenderer { private static final String NO_DATA_TAG = "None"; private final ArtifactGuidToWordML guidResolver; - private final RelationSorterProvider sorterProvider; private final AbstractOseeCache<RelationType> relationCache; - public RelationOrderRenderer(AbstractOseeCache<RelationType> relationCache, ArtifactGuidToWordML guidResolver, RelationSorterProvider sorterProvider) { + public RelationOrderRenderer(AbstractOseeCache<RelationType> relationCache, ArtifactGuidToWordML guidResolver) { this.relationCache = relationCache; this.guidResolver = guidResolver; - this.sorterProvider = sorterProvider; - } - - private String resolveSorter(String sorterGuid) { - String toReturn = sorterGuid; - try { - IRelationSorter sorter = sorterProvider.getRelationOrder(toReturn); - toReturn = sorter.getSorterId().getName(); - } catch (OseeCoreException ex) { - OseeLog.log(Activator.class, Level.SEVERE, ex); - } - return toReturn; } private void writeTableRow(WordMLProducer writer, RelationType relationType, RelationSide side, String sorterName, List<String> orderedData) throws OseeCoreException { @@ -81,17 +67,17 @@ public class RelationOrderRenderer { writer.addTableRow(NO_DATA_TAG); } else { writer.addTableRow("Relation Type", "Side Name", "Side", "Order Type", "Related Artifacts"); - for (Entry<Pair<String, String>, Pair<String, List<String>>> entry : relationOrderData.getOrderedEntrySet()) { + for (Entry<Pair<String, String>, Pair<RelationSorter, List<String>>> entry : relationOrderData.getOrderedEntrySet()) { String relationTypeName = entry.getKey().getFirst(); String relationSide = entry.getKey().getSecond(); - String sorterGuid = entry.getValue().getFirst(); + RelationSorter sorterGuid = entry.getValue().getFirst(); List<String> guidList = entry.getValue().getSecond(); List<String> mlLinks = guidResolver.resolveAsOseeLinks(branch, guidList); RelationType relationType = relationCache.getUniqueByName(relationTypeName); RelationSide side = RelationSide.fromString(relationSide); try { - writeTableRow(writer, relationType, side, resolveSorter(sorterGuid), mlLinks); + writeTableRow(writer, relationType, side, sorterGuid.toString(), mlLinks); } catch (Exception ex) { OseeLog.log(Activator.class, Level.SEVERE, ex); } diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/RelationManagerTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/RelationManagerTest.java index 6a97c33c928..8e7bc8df9f0 100644 --- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/RelationManagerTest.java +++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/RelationManagerTest.java @@ -205,7 +205,7 @@ public class RelationManagerTest { setupAdjacencies(node5, relation4); setupAdjacencies(node6); - when(types.getDefaultOrderTypeGuid(DEFAULT_HIERARCHY)).thenReturn(LEXICOGRAPHICAL_DESC.getGuid()); + when(types.getDefaultOrderTypeGuid(DEFAULT_HIERARCHY)).thenReturn(LEXICOGRAPHICAL_DESC); when(types.getAll()).thenReturn(new ArrayList( Arrays.asList(CoreRelationTypes.Default_Hierarchical__Child, CoreRelationTypes.Default_Hierarchical__Parent))); } diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/order/OrderManagerTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/order/OrderManagerTest.java index bd15ad13e22..a6f49c860e0 100644 --- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/order/OrderManagerTest.java +++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/order/OrderManagerTest.java @@ -26,8 +26,8 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map.Entry; -import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.data.IRelationTypeSide; +import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; import org.eclipse.osee.framework.core.enums.RelationSide; import org.eclipse.osee.framework.jdk.core.type.Identifiable; @@ -44,7 +44,7 @@ import org.mockito.MockitoAnnotations; /** * Test Case for {@link OrderManager} - * + * * @author Roberto E. Escobar */ public class OrderManagerTest { @@ -59,11 +59,11 @@ public class OrderManagerTest { @Mock private IRelationTypeSide typeSide1; @Mock private IRelationTypeSide typeSide2; @Mock private IRelationTypeSide typeSide3; - + @Mock private OrderData orderData1; @Mock private OrderData orderData2; @Mock private OrderData orderData3; - + @Mock private Identifiable<String> mock1; @Mock private Identifiable<String> mock2; @Mock private Identifiable<String> mock3; @@ -91,9 +91,9 @@ public class OrderManagerTest { when(typeSide2.getSide()).thenReturn(RelationSide.SIDE_B); when(typeSide3.getSide()).thenReturn(RelationSide.SIDE_A); - when(relationTypeCache.getDefaultOrderTypeGuid(typeSide1)).thenReturn(USER_DEFINED.getGuid()); - when(relationTypeCache.getDefaultOrderTypeGuid(typeSide2)).thenReturn(UNORDERED.getGuid()); - when(relationTypeCache.getDefaultOrderTypeGuid(typeSide3)).thenReturn(LEXICOGRAPHICAL_ASC.getGuid()); + when(relationTypeCache.getDefaultOrderTypeGuid(typeSide1)).thenReturn(USER_DEFINED); + when(relationTypeCache.getDefaultOrderTypeGuid(typeSide2)).thenReturn(UNORDERED); + when(relationTypeCache.getDefaultOrderTypeGuid(typeSide3)).thenReturn(LEXICOGRAPHICAL_ASC); } @Test diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/sorter/SorterProviderTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/sorter/SorterProviderTest.java index 64e3bed2439..d0035365e9c 100644 --- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/sorter/SorterProviderTest.java +++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/sorter/SorterProviderTest.java @@ -10,23 +10,15 @@ *******************************************************************************/ package org.eclipse.osee.orcs.core.internal.relation.sorter; -import static org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes.LEXICOGRAPHICAL_ASC; -import static org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes.LEXICOGRAPHICAL_DESC; -import static org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes.UNORDERED; -import static org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes.USER_DEFINED; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; -import java.util.List; import org.eclipse.osee.framework.core.data.RelationSorter; -import org.eclipse.osee.framework.core.data.TokenFactory; import org.eclipse.osee.framework.core.enums.CoreRelationTypes; import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; -import org.eclipse.osee.framework.jdk.core.util.GUID; import org.eclipse.osee.orcs.data.RelationTypes; +import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -36,7 +28,7 @@ import org.mockito.MockitoAnnotations; /** * Test Case for {@link SorterProvider} - * + * * @author Roberto E. Escobar */ public class SorterProviderTest { @@ -60,13 +52,13 @@ public class SorterProviderTest { @Test public void testGetDefaultSorterId() throws OseeCoreException { when(relationTypeCache.getDefaultOrderTypeGuid(CoreRelationTypes.Default_Hierarchical__Child)).thenReturn( - RelationOrderBaseTypes.USER_DEFINED.getGuid()); + RelationOrderBaseTypes.USER_DEFINED); RelationSorter actual1 = provider.getDefaultSorterId(CoreRelationTypes.Default_Hierarchical__Child); assertEquals(RelationOrderBaseTypes.USER_DEFINED, actual1); when(relationTypeCache.getDefaultOrderTypeGuid(CoreRelationTypes.Users_User)).thenReturn( - RelationOrderBaseTypes.LEXICOGRAPHICAL_DESC.getGuid()); + RelationOrderBaseTypes.LEXICOGRAPHICAL_DESC); RelationSorter actual2 = provider.getDefaultSorterId(CoreRelationTypes.Users_User); assertEquals(RelationOrderBaseTypes.LEXICOGRAPHICAL_DESC, actual2); @@ -81,63 +73,20 @@ public class SorterProviderTest { } @Test - public void testGetDefaultSorterIdTypeNotfound() throws OseeCoreException { - thrown.expect(OseeArgumentException.class); - thrown.expectMessage( - String.format("defaultOrderTypeGuid cannot be null - Invalid default order type uuid for [%s]", - CoreRelationTypes.Allocation__Component)); - - provider.getDefaultSorterId(CoreRelationTypes.Allocation__Component); - } - - @Test - public void testGetAllRelationOrderIds() { - List<RelationSorter> actual = provider.getSorterIds(); - - int index = 0; - assertEquals(RelationOrderBaseTypes.LEXICOGRAPHICAL_ASC, actual.get(index++)); - assertEquals(RelationOrderBaseTypes.LEXICOGRAPHICAL_DESC, actual.get(index++)); - assertEquals(RelationOrderBaseTypes.UNORDERED, actual.get(index++)); - assertEquals(RelationOrderBaseTypes.USER_DEFINED, actual.get(index++)); - } + public void testGetRelationOrder() { + testSorter(provider, RelationSorter.LEXICOGRAPHICAL_ASC, LexicographicalSorter.class); + testSorter(provider, RelationSorter.LEXICOGRAPHICAL_DESC, LexicographicalSorter.class); + testSorter(provider, RelationSorter.UNORDERED, UnorderedSorter.class); + testSorter(provider, RelationSorter.USER_DEFINED, UserDefinedSorter.class); - @Test - public void testGetRelationOrder() throws OseeCoreException { - for (RelationSorter sorterId : RelationOrderBaseTypes.values()) { - Sorter actual = provider.getSorter(sorterId); - assertEquals(sorterId, actual.getId()); - boolean matches = false; - - if (sorterId == LEXICOGRAPHICAL_ASC) { - matches = actual instanceof LexicographicalSorter; - } else if (sorterId == LEXICOGRAPHICAL_DESC) { - matches = actual instanceof LexicographicalSorter; - } else if (sorterId == UNORDERED) { - matches = actual instanceof UnorderedSorter; - } else if (sorterId == USER_DEFINED) { - matches = actual instanceof UserDefinedSorter; - } else { - assertNull("This line should not be reached"); - } - assertTrue(matches); - } - } - - @Test - public void testArgumentExceptions() throws OseeCoreException { thrown.expect(OseeArgumentException.class); - thrown.expectMessage("sorterId cannot be null"); - provider.getSorter(null); + thrown.expectMessage("No sorted is defined for preexisting"); + testSorter(provider, RelationSorter.PREEXISTING, UserDefinedSorter.class); } - @Test - public void testNotFoundExceptions() throws OseeCoreException { - String randomGuid = GUID.create(); - String idName = "TestSorterId"; - RelationSorter sorterId = TokenFactory.createSorterId(randomGuid, "TestSorterId"); - thrown.expect(OseeArgumentException.class); - thrown.expectMessage( - String.format("sorter cannot be null - Unable to locate sorter with sorterId [%s:%s]", idName, randomGuid)); - provider.getSorter(sorterId); + private void testSorter(SorterProvider provider, RelationSorter sorterId, Class<? extends Sorter> clazz) { + Sorter actual = provider.getSorter(sorterId); + Assert.assertEquals(sorterId, actual.getId()); + Assert.assertEquals(clazz, actual.getClass()); } -} +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/sorter/SorterTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/sorter/SorterTest.java index 18ad7689e3c..aeb4d4b763a 100644 --- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/sorter/SorterTest.java +++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/sorter/SorterTest.java @@ -29,7 +29,7 @@ import org.junit.runners.Parameterized.Parameters; /** * Test Case for {@link LexicographicalSorter}, {@link UnorderedSorter}, {@link UserDefinedSorter}, and * {@link UserDefinedComparator} - * + * * @author Roberto E. Escobar */ @RunWith(Parameterized.class) @@ -54,8 +54,7 @@ public class SorterTest { @Test public void testSorterId() { Assert.assertNotNull(message, sorter.getId()); - Assert.assertEquals(message, expectedOrderId.getGuid(), sorter.getId().getGuid()); - Assert.assertEquals(message, expectedOrderId.getName(), sorter.getId().getName()); + Assert.assertEquals(message, expectedOrderId, sorter.getId()); } @Test diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/types/OrcsTypesTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/types/OrcsTypesTest.java index 825f51cb7f0..fc2c6ce6474 100644 --- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/types/OrcsTypesTest.java +++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/types/OrcsTypesTest.java @@ -799,8 +799,8 @@ public class OrcsTypesTest { RelationTypes relTypes = orcsTypes.getRelationTypes(); //@formatter:off - assertEquals(RelationOrderBaseTypes.LEXICOGRAPHICAL_ASC.getGuid(), relTypes.getDefaultOrderTypeGuid(REQUIREMENT_REL)); - assertEquals(RelationOrderBaseTypes.UNORDERED.getGuid(), relTypes.getDefaultOrderTypeGuid(ANOTHER_REL)); + assertEquals(RelationOrderBaseTypes.LEXICOGRAPHICAL_ASC, relTypes.getDefaultOrderTypeGuid(REQUIREMENT_REL)); + assertEquals(RelationOrderBaseTypes.UNORDERED, relTypes.getDefaultOrderTypeGuid(ANOTHER_REL)); //@formatter:on } @@ -928,7 +928,7 @@ public class OrcsTypesTest { assertEquals(OTHER_ARTIFACT, relTypes.getArtifactType(relation, SIDE_B)); assertEquals(ARTIFACT, relTypes.getArtifactTypeSideA(relation)); assertEquals(OTHER_ARTIFACT, relTypes.getArtifactTypeSideB(relation)); - assertEquals(RelationOrderBaseTypes.LEXICOGRAPHICAL_DESC.getGuid(), relTypes.getDefaultOrderTypeGuid(relation)); + assertEquals(RelationOrderBaseTypes.LEXICOGRAPHICAL_DESC, relTypes.getDefaultOrderTypeGuid(relation)); assertEquals(RelationTypeMultiplicity.MANY_TO_ONE, relTypes.getMultiplicity(relation)); assertEquals("dynamic-sideA", relTypes.getSideName(relation, SIDE_A)); assertEquals("dynamic-sideB", relTypes.getSideName(relation, SIDE_B)); diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/relation/order/OrderEntryComparator.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/relation/order/OrderEntryComparator.java index 3cfdbaecfdb..1b61b5febec 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/relation/order/OrderEntryComparator.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/relation/order/OrderEntryComparator.java @@ -34,7 +34,7 @@ public class OrderEntryComparator implements Comparator<Entry<IRelationTypeSide, result = typeSide1.getSide().compareTo(typeSide2.getSide()); } if (result == 0) { - result = orderData1.getSorterId().getGuid().compareTo(orderData2.getSorterId().getGuid()); + result = orderData1.getSorterId().compareTo(orderData2.getSorterId()); } if (result == 0) { List<String> guids1 = new ArrayList<>(orderData1.getOrderIds()); diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/relation/order/OrderParser.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/relation/order/OrderParser.java index ef5a3338749..01305126691 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/relation/order/OrderParser.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/relation/order/OrderParser.java @@ -26,11 +26,10 @@ import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; -import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.data.IRelationType; import org.eclipse.osee.framework.core.data.IRelationTypeSide; +import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.data.TokenFactory; -import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; import org.eclipse.osee.framework.core.enums.RelationSide; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; import org.eclipse.osee.framework.jdk.core.util.Conditions; @@ -121,8 +120,7 @@ public class OrderParser { RelationSide side = RelationSide.fromString(relationSide); IRelationTypeSide typeSide = TokenFactory.createRelationTypeSide(side, type.getId(), type.getName()); - RelationSorter sorterId = RelationOrderBaseTypes.getFromGuid(orderType); - OrderData orderData = new OrderData(sorterId, list); + OrderData orderData = new OrderData(RelationSorter.valueOfGuid(orderType), list); hasOrderData.add(typeSide, orderData); } } diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/relation/sorter/SorterProvider.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/relation/sorter/SorterProvider.java index 012b3f3f295..99d4dbfa6a7 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/relation/sorter/SorterProvider.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/relation/sorter/SorterProvider.java @@ -10,17 +10,11 @@ *******************************************************************************/ package org.eclipse.osee.orcs.core.internal.relation.sorter; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; import java.util.HashMap; -import java.util.List; import java.util.Map; -import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.data.IRelationType; -import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; -import org.eclipse.osee.framework.jdk.core.type.Named; +import org.eclipse.osee.framework.core.data.RelationSorter; +import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; import org.eclipse.osee.framework.jdk.core.util.Conditions; import org.eclipse.osee.orcs.data.RelationTypes; @@ -33,7 +27,6 @@ import org.eclipse.osee.orcs.utility.SortOrder; public class SorterProvider { private final Map<RelationSorter, Sorter> orderMap = new HashMap<>(); - private final List<RelationSorter> ids = new ArrayList<>(); private final RelationTypes typeCache; @@ -44,12 +37,6 @@ public class SorterProvider { registerOrderType(new LexicographicalSorter(SortOrder.DESCENDING)); registerOrderType(new UnorderedSorter()); registerOrderType(new UserDefinedSorter()); - - Collection<Sorter> sorters = orderMap.values(); - for (Sorter sorter : sorters) { - ids.add(sorter.getId()); - } - Collections.sort(ids, new CaseInsensitiveNameComparator()); } private void registerOrderType(Sorter order) { @@ -58,14 +45,7 @@ public class SorterProvider { public RelationSorter getDefaultSorterId(IRelationType relationType) throws OseeCoreException { Conditions.checkNotNull(relationType, "type"); - String orderTypeGuid = typeCache.getDefaultOrderTypeGuid(relationType); - Conditions.checkNotNullOrEmpty(orderTypeGuid, "defaultOrderTypeGuid", "Invalid default order type uuid for [%s]", - relationType); - return RelationOrderBaseTypes.getFromGuid(orderTypeGuid); - } - - public List<RelationSorter> getSorterIds() { - return ids; + return typeCache.getDefaultOrderTypeGuid(relationType); } public boolean exists(RelationSorter sorterId) throws OseeCoreException { @@ -74,16 +54,11 @@ public class SorterProvider { } public Sorter getSorter(RelationSorter sorterId) throws OseeCoreException { - Conditions.checkNotNull(sorterId, "sorterId"); + if (sorterId.equals(RelationSorter.PREEXISTING)) { + throw new OseeArgumentException("No sorted is defined for preexisting (nor should there be)."); + } Sorter sorter = orderMap.get(sorterId); Conditions.checkNotNull(sorter, "sorter", "Unable to locate sorter with sorterId %s", sorterId); return sorter; } - - private static final class CaseInsensitiveNameComparator implements Comparator<Named> { - @Override - public int compare(Named o1, Named o2) { - return o1.getName().compareToIgnoreCase(o2.getName()); - } - } -} +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/types/impl/RelationTypesImpl.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/types/impl/RelationTypesImpl.java index 1f34786780f..15cb138ba7e 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/types/impl/RelationTypesImpl.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/types/impl/RelationTypesImpl.java @@ -13,8 +13,8 @@ package org.eclipse.osee.orcs.core.internal.types.impl; import java.util.Collection; import org.eclipse.osee.framework.core.data.IArtifactType; import org.eclipse.osee.framework.core.data.IRelationType; +import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.dsl.oseeDsl.XRelationType; -import org.eclipse.osee.framework.core.enums.RelationOrderBaseTypes; import org.eclipse.osee.framework.core.enums.RelationSide; import org.eclipse.osee.framework.core.enums.RelationTypeMultiplicity; import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException; @@ -91,19 +91,13 @@ public class RelationTypesImpl implements RelationTypes { @Override public boolean isOrdered(IRelationType relation) { - String defaultOrderTypeGuid = null; - try { - defaultOrderTypeGuid = getDefaultOrderTypeGuid(relation); - } catch (OseeCoreException ex) { - // Do nothing - } - return !RelationOrderBaseTypes.UNORDERED.getGuid().equals(defaultOrderTypeGuid); + return !RelationSorter.UNORDERED.equals(getDefaultOrderTypeGuid(relation)); } @Override - public String getDefaultOrderTypeGuid(IRelationType relation) throws OseeCoreException { + public RelationSorter getDefaultOrderTypeGuid(IRelationType relation) throws OseeCoreException { XRelationType type = getType(relation); - return orderTypeNameToGuid(type.getDefaultOrderType()); + return RelationSorter.valueOfName(type.getDefaultOrderType()); } @Override @@ -131,12 +125,6 @@ public class RelationTypesImpl implements RelationTypes { return provider.getRelationTypeIndex().isArtifactTypeAllowed(relation, relationSide, artifactType); } - private static String orderTypeNameToGuid(String orderTypeName) throws OseeCoreException { - Conditions.checkNotNull(orderTypeName, "orderTypeName"); - String orderType = orderTypeName.replaceAll("_", " "); - return RelationOrderBaseTypes.getFromOrderTypeName(orderType).getGuid(); - } - @Override public boolean isEmpty() throws OseeCoreException { return provider.getRelationTypeIndex().isEmpty(); diff --git a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/data/RelationTypes.java b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/data/RelationTypes.java index ed4150aeb36..84bc3a70345 100644 --- a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/data/RelationTypes.java +++ b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/data/RelationTypes.java @@ -12,6 +12,7 @@ package org.eclipse.osee.orcs.data; import org.eclipse.osee.framework.core.data.IArtifactType; import org.eclipse.osee.framework.core.data.IRelationType; +import org.eclipse.osee.framework.core.data.RelationSorter; import org.eclipse.osee.framework.core.enums.RelationSide; import org.eclipse.osee.framework.core.enums.RelationTypeMultiplicity; import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException; @@ -42,5 +43,5 @@ public interface RelationTypes extends IdCollection<IRelationType> { boolean isOrdered(IRelationType relation) throws OseeCoreException; - String getDefaultOrderTypeGuid(IRelationType relation) throws OseeCoreException; + RelationSorter getDefaultOrderTypeGuid(IRelationType relation); }
\ No newline at end of file |