diff options
author | donald.g.dunne | 2018-10-15 18:14:50 +0000 |
---|---|---|
committer | Donald Dunne | 2018-10-16 16:59:49 +0000 |
commit | b79cda0ca152396295adb542c4f01cfc43ecebe6 (patch) | |
tree | f3300dbffb0398032eab1ee514271736b9953b9b | |
parent | 9ce9317c54f95eb3efcd1ab3aadb5741c779519c (diff) | |
download | org.eclipse.osee-b79cda0ca152396295adb542c4f01cfc43ecebe6.tar.gz org.eclipse.osee-b79cda0ca152396295adb542c4f01cfc43ecebe6.tar.xz org.eclipse.osee-b79cda0ca152396295adb542c4f01cfc43ecebe6.zip |
bug[ats_TW11431]: Artifact Editor relation order not showing correctly
Change-Id: Ic8a85de310dd8ae44c0f766556cb0be48e0e0863
13 files changed, 218 insertions, 48 deletions
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/AbstractArtifactNameComparator.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/AbstractArtifactNameComparator.java new file mode 100644 index 00000000000..3f0e08b975a --- /dev/null +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/AbstractArtifactNameComparator.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2018 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.artifact; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @author Donald G. Dunne + */ +public abstract class AbstractArtifactNameComparator { + private static final Pattern numberPattern = Pattern.compile("[+-]?\\d+"); + private final Matcher numberMatcher = numberPattern.matcher(""); + private boolean descending = false; + private static final int NUMBER_STRING_LIMIT = 19; + + public AbstractArtifactNameComparator(boolean descending) { + this.descending = descending; + } + + public int compareNames(String name1, String name2) { + numberMatcher.reset(name1); + if (numberMatcher.matches()) { + numberMatcher.reset(name2); + if (numberMatcher.matches()) { + if (name1.length() < NUMBER_STRING_LIMIT && name2.length() < NUMBER_STRING_LIMIT) { + if (descending) { + return Long.valueOf(name2).compareTo(Long.valueOf(name1)); + } else { + return Long.valueOf(name1).compareTo(Long.valueOf(name2)); + } + } + } + } + if (descending) { + return name2.compareTo(name1); + } else { + return name1.compareTo(name2); + } + } + +} diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/ArtifactNameComparator.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/ArtifactNameComparator.java index 47ffa896c95..ffd7c23ded5 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/ArtifactNameComparator.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/ArtifactNameComparator.java @@ -11,18 +11,12 @@ package org.eclipse.osee.framework.skynet.core.artifact; import java.util.Comparator; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.eclipse.osee.framework.core.data.ArtifactToken; -public class ArtifactNameComparator implements Comparator<ArtifactToken> { - private static final Pattern numberPattern = Pattern.compile("[+-]?\\d+"); - private final Matcher numberMatcher = numberPattern.matcher(""); - private boolean descending = false; - private static final int NUMBER_STRING_LIMIT = 19; +public class ArtifactNameComparator extends AbstractArtifactNameComparator implements Comparator<ArtifactToken> { public ArtifactNameComparator(boolean descending) { - this.descending = descending; + super(descending); } @Override @@ -30,23 +24,6 @@ public class ArtifactNameComparator implements Comparator<ArtifactToken> { String name1 = artifact1.getName(); String name2 = artifact2.getName(); - numberMatcher.reset(name1); - if (numberMatcher.matches()) { - numberMatcher.reset(name2); - if (numberMatcher.matches()) { - if (name1.length() < NUMBER_STRING_LIMIT && name2.length() < NUMBER_STRING_LIMIT) { - if (descending) { - return Long.valueOf(name2).compareTo(Long.valueOf(name1)); - } else { - return Long.valueOf(name1).compareTo(Long.valueOf(name2)); - } - } - } - } - if (descending) { - return name2.compareTo(name1); - } else { - return name1.compareTo(name2); - } + return compareNames(name1, name2); } }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/ArtifactNameRelationLinkComparator.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/ArtifactNameRelationLinkComparator.java new file mode 100644 index 00000000000..f26945a4564 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/ArtifactNameRelationLinkComparator.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2018 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.artifact; + +import java.util.Comparator; +import org.eclipse.osee.framework.skynet.core.relation.RelationLink; + +/** + * @author Donald G. Dunne + */ +public class ArtifactNameRelationLinkComparator extends AbstractArtifactNameComparator implements Comparator<RelationLink> { + + public ArtifactNameRelationLinkComparator(boolean descending) { + super(descending); + } + + @Override + public int compare(RelationLink link1, RelationLink link2) { + String name1 = link1.getArtifactB().getName(); + String name2 = link2.getArtifactB().getName(); + + return compareNames(name1, name2); + } +}
\ No newline at end of file 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 c8ed92fb9bf..212fc21b14e 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 @@ -277,8 +277,9 @@ public class RelationLink implements HasBranch { @Override public String toString() { - return String.format("type[%s] id[%d] modType[%s] [%s]: aId[%d] <--> bId[%s]", relationType.getName(), relationId, - getModificationType(), isDirty() ? "dirty" : "not dirty", aArtifactId, bArtifactId); + return String.format("type[%s] id[%d] modType[%s] [%s]: a%s <--> b%s", relationType.getName(), relationId, + getModificationType(), isDirty() ? "dirty" : "not dirty", artifactA.toStringWithId(), + artifactB.toStringWithId()); } public void setNotDirty() { 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 5e998094723..8bfe1acd774 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 @@ -365,7 +365,15 @@ public class RelationManager { return null; } + public static List<RelationLink> getRelationsUnordered(Artifact artifact, IRelationType relationType, RelationSide relationSide) throws OseeCoreException { + return getRelations(artifact, relationType, relationSide, false); + } + public static List<RelationLink> getRelations(Artifact artifact, IRelationType relationType, RelationSide relationSide) throws OseeCoreException { + return getRelations(artifact, relationType, relationSide, true); + } + + public static List<RelationLink> getRelations(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", artifact); @@ -392,6 +400,9 @@ public class RelationManager { } } } + if (sort) { + sortRelations(artifact, relationType, relationSide, relations); + } return relations; } @@ -576,6 +587,14 @@ public class RelationManager { sorter.sort(listToOrder); } + private static void sortRelations(Artifact artifact, IRelationType type, RelationSide side, List<RelationLink> listToOrder) throws OseeCoreException { + if (type == null || side == null || listToOrder.size() <= 1) { + return; + } + RelationTypeSideSorter sorter = createTypeSideSorter(artifact, type, side); + sorter.sortRelations(listToOrder); + } + private static void updateOrderListOnDelete(Artifact artifact, IRelationType relationType, RelationSide relationSide, List<Artifact> relatives) throws OseeCoreException { RelationTypeSideSorter sorter = createTypeSideSorter(artifact, relationType, relationSide); sorter.setOrder(relatives, sorter.getSorterId()); 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 28746a6fdec..ef5833758f9 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 @@ -78,6 +78,12 @@ public class RelationTypeSideSorter extends RelationTypeSide { order.sort(listToOrder, relativeOrder); } + public void sortRelations(List<? extends RelationLink> listToOrder) throws OseeCoreException { + IRelationSorter order = sorterProvider.getRelationOrder(getSorterId()); + List<String> relativeOrder = orderData.getOrderList(getRelationType(), getSide()); + order.sortRelations(listToOrder, relativeOrder); + } + public RelationLink getRelation(Artifact artifact) { return artToRelation.get(artifact); } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/order/IRelationSorter.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/order/IRelationSorter.java index fa5fdc6ddea..00ba6dd57d1 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/order/IRelationSorter.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/order/IRelationSorter.java @@ -13,6 +13,7 @@ package org.eclipse.osee.framework.skynet.core.relation.order; import java.util.List; import org.eclipse.osee.framework.core.data.ArtifactToken; import org.eclipse.osee.framework.core.enums.RelationSorter; +import org.eclipse.osee.framework.skynet.core.relation.RelationLink; /** * @author Andrew M. Finkbeiner @@ -22,4 +23,6 @@ public interface IRelationSorter { RelationSorter getSorterId(); void sort(List<? extends ArtifactToken> relatives, List<String> relativeSequence); + + void sortRelations(List<? extends RelationLink> listToOrder, List<String> relativeOrder); } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/sorters/AbstractUserDefinedOrderComparator.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/sorters/AbstractUserDefinedOrderComparator.java new file mode 100644 index 00000000000..bc4e487f083 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/sorters/AbstractUserDefinedOrderComparator.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2018 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.sorters; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author Donald G. Dunne + */ +public abstract class AbstractUserDefinedOrderComparator { + + protected final Map<String, Integer> value; + + public AbstractUserDefinedOrderComparator(List<String> guidOrder) { + value = new HashMap<>(guidOrder.size()); + for (int i = 0; i < guidOrder.size(); i++) { + value.put(guidOrder.get(i), i); + } + } + + public int compareIntegers(Integer val1, Integer val2) { + if (val1 == null) { + val1 = Integer.MAX_VALUE - 1; + } + if (val2 == null) { + val2 = Integer.MAX_VALUE; + } + return val1 - val2; + } + +} diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/sorters/LexicographicalRelationSorter.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/sorters/LexicographicalRelationSorter.java index 6ec342b0ab9..457903535a7 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/sorters/LexicographicalRelationSorter.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/sorters/LexicographicalRelationSorter.java @@ -17,6 +17,8 @@ import java.util.List; import org.eclipse.osee.framework.core.data.ArtifactToken; import org.eclipse.osee.framework.core.enums.RelationSorter; import org.eclipse.osee.framework.skynet.core.artifact.ArtifactNameComparator; +import org.eclipse.osee.framework.skynet.core.artifact.ArtifactNameRelationLinkComparator; +import org.eclipse.osee.framework.skynet.core.relation.RelationLink; import org.eclipse.osee.framework.skynet.core.relation.order.IRelationSorter; /** @@ -29,12 +31,11 @@ public class LexicographicalRelationSorter implements IRelationSorter { ASCENDING, DESCENDING; } - private final ArtifactNameComparator comparator; private final RelationSorter id; + private final boolean isDescending; public LexicographicalRelationSorter(SortMode sortMode) { - boolean isDescending = SortMode.DESCENDING == sortMode; - this.comparator = new ArtifactNameComparator(isDescending); + isDescending = SortMode.DESCENDING == sortMode; this.id = isDescending ? LEXICOGRAPHICAL_DESC : LEXICOGRAPHICAL_ASC; } @@ -45,6 +46,13 @@ public class LexicographicalRelationSorter implements IRelationSorter { @Override public void sort(List<? extends ArtifactToken> relatives, List<String> relativeSequence) { + ArtifactNameComparator comparator = new ArtifactNameComparator(isDescending); + Collections.sort(relatives, comparator); + } + + @Override + public void sortRelations(List<? extends RelationLink> relatives, List<String> relativeSequence) { + ArtifactNameRelationLinkComparator comparator = new ArtifactNameRelationLinkComparator(isDescending); Collections.sort(relatives, comparator); } } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/sorters/UnorderedRelationSorter.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/sorters/UnorderedRelationSorter.java index a4b90332b14..309c5239acc 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/sorters/UnorderedRelationSorter.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/sorters/UnorderedRelationSorter.java @@ -14,6 +14,7 @@ import static org.eclipse.osee.framework.core.enums.RelationSorter.UNORDERED; import java.util.List; import org.eclipse.osee.framework.core.data.ArtifactToken; import org.eclipse.osee.framework.core.enums.RelationSorter; +import org.eclipse.osee.framework.skynet.core.relation.RelationLink; import org.eclipse.osee.framework.skynet.core.relation.order.IRelationSorter; /** @@ -30,4 +31,9 @@ public class UnorderedRelationSorter implements IRelationSorter { public void sort(List<? extends ArtifactToken> relatives, List<String> relativeSequence) { // do nothing } + + @Override + public void sortRelations(List<? extends RelationLink> listToOrder, List<String> relativeOrder) { + // do nothing + } } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/sorters/UserDefinedOrderComparator.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/sorters/UserDefinedOrderComparator.java index 83146d98d0d..6518f2c0907 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/sorters/UserDefinedOrderComparator.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/sorters/UserDefinedOrderComparator.java @@ -11,35 +11,22 @@ package org.eclipse.osee.framework.skynet.core.relation.sorters; import java.util.Comparator; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.eclipse.osee.framework.core.data.ArtifactToken; /** * @author Andrew M. Finkbeiner */ -class UserDefinedOrderComparator implements Comparator<ArtifactToken> { +class UserDefinedOrderComparator extends AbstractUserDefinedOrderComparator implements Comparator<ArtifactToken> { - private final Map<String, Integer> value; - - UserDefinedOrderComparator(List<String> guidOrder) { - value = new HashMap<>(guidOrder.size()); - for (int i = 0; i < guidOrder.size(); i++) { - value.put(guidOrder.get(i), i); - } + public UserDefinedOrderComparator(List<String> guidOrder) { + super(guidOrder); } @Override public int compare(ArtifactToken artifact1, ArtifactToken artifact2) { Integer val1 = value.get(artifact1.getGuid()); Integer val2 = value.get(artifact2.getGuid()); - if (val1 == null) { - val1 = Integer.MAX_VALUE - 1; - } - if (val2 == null) { - val2 = Integer.MAX_VALUE; - } - return val1 - val2; + return compareIntegers(val1, val2); } } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/sorters/UserDefinedRelationOrderComparator.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/sorters/UserDefinedRelationOrderComparator.java new file mode 100644 index 00000000000..f55e84d8b42 --- /dev/null +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/sorters/UserDefinedRelationOrderComparator.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2018 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.sorters; + +import java.util.Comparator; +import java.util.List; +import org.eclipse.osee.framework.skynet.core.relation.RelationLink; + +/** + * @author Donald G. Dunne + */ +class UserDefinedRelationOrderComparator extends AbstractUserDefinedOrderComparator implements Comparator<RelationLink> { + + public UserDefinedRelationOrderComparator(List<String> guidOrder) { + super(guidOrder); + } + + @Override + public int compare(RelationLink link1, RelationLink link2) { + Integer val1 = value.get(link1.getArtifactB().getGuid()); + Integer val2 = value.get(link2.getArtifactB().getGuid()); + return compareIntegers(val1, val2); + } +} diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/sorters/UserDefinedRelationSorter.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/sorters/UserDefinedRelationSorter.java index 572fdaa0989..ebf01465774 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/sorters/UserDefinedRelationSorter.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/relation/sorters/UserDefinedRelationSorter.java @@ -15,6 +15,7 @@ import java.util.Collections; import java.util.List; import org.eclipse.osee.framework.core.data.ArtifactToken; import org.eclipse.osee.framework.core.enums.RelationSorter; +import org.eclipse.osee.framework.skynet.core.relation.RelationLink; import org.eclipse.osee.framework.skynet.core.relation.order.IRelationSorter; /** @@ -33,4 +34,11 @@ public class UserDefinedRelationSorter implements IRelationSorter { Collections.sort(relatives, new UserDefinedOrderComparator(relativeSequence)); } } + + @Override + public void sortRelations(List<? extends RelationLink> relatives, List<String> relativeSequence) { + if (relatives.size() > 1) { + Collections.sort(relatives, new UserDefinedRelationOrderComparator(relativeSequence)); + } + } } |