diff --git a/java/code/src/com/redhat/rhn/frontend/action/channel/ssm/BaseSubscribeAction.java b/java/code/src/com/redhat/rhn/frontend/action/channel/ssm/BaseSubscribeAction.java index 54c42204552c..35802b8d75f5 100644 --- a/java/code/src/com/redhat/rhn/frontend/action/channel/ssm/BaseSubscribeAction.java +++ b/java/code/src/com/redhat/rhn/frontend/action/channel/ssm/BaseSubscribeAction.java @@ -55,7 +55,6 @@ import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.Set; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -464,7 +463,7 @@ protected List setupList(User user, HttpServletRequest req // change the systems base channel Channel c = ChannelFactory.lookupById(spc.getId()); - Set compatibles = ChannelManager.listCompatibleBaseChannelsForChannel(user, c); + List compatibles = ChannelManager.listCompatibleBaseChannelsForChannel(user, c); log.debug("Sorting channels: {}", compatibles.size()); List rhn = new ArrayList<>(); List custom = new ArrayList<>(); diff --git a/java/code/src/com/redhat/rhn/frontend/action/systems/sdc/SystemChannelsAction.java b/java/code/src/com/redhat/rhn/frontend/action/systems/sdc/SystemChannelsAction.java index c73f68b3c2e7..e0663a9e8980 100644 --- a/java/code/src/com/redhat/rhn/frontend/action/systems/sdc/SystemChannelsAction.java +++ b/java/code/src/com/redhat/rhn/frontend/action/systems/sdc/SystemChannelsAction.java @@ -46,7 +46,6 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Set; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -121,7 +120,7 @@ public ActionForward unspecified(ActionMapping mapping, } - Set orgChannels = ChannelManager.listBaseChannelsForSystem(user, s); + List orgChannels = ChannelManager.listBaseChannelsForSystem(user, s); List rhnChannels = new LinkedList<>(); List customChannels = new LinkedList<>(); diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java index 02505f1ee61b..19c559e2ef43 100644 --- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java +++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java @@ -693,7 +693,7 @@ public Object[] listSubscribableBaseChannels(User loggedInUser, Integer sid) Channel baseChannel = server.getBaseChannel(); List> returnList = new ArrayList<>(); - Set list = ChannelManager.listBaseChannelsForSystem(loggedInUser, server); + List list = ChannelManager.listBaseChannelsForSystem(loggedInUser, server); for (EssentialChannelDto ch : list) { Boolean currentBase = (baseChannel != null) && baseChannel.getId().equals(ch.getId()); diff --git a/java/code/src/com/redhat/rhn/manager/channel/ChannelManager.java b/java/code/src/com/redhat/rhn/manager/channel/ChannelManager.java index 9fa3062ae598..0c5413078242 100644 --- a/java/code/src/com/redhat/rhn/manager/channel/ChannelManager.java +++ b/java/code/src/com/redhat/rhn/manager/channel/ChannelManager.java @@ -14,6 +14,7 @@ */ package com.redhat.rhn.manager.channel; +import static java.util.Comparator.comparing; import static java.util.Optional.empty; import static java.util.Optional.of; import static java.util.Optional.ofNullable; @@ -1687,9 +1688,9 @@ private static Channel getDefaultBaseChannel(Org org, String version, ChannelArc * * @param usr requesting list * @param s Server to check against - * @return Set of Channel objects that match + * @return List of Channel objects that match */ - public static Set listBaseChannelsForSystem(User usr, Server s) { + public static List listBaseChannelsForSystem(User usr, Server s) { Set channelDtos = new HashSet<>(); PackageEvr releaseEvr = PackageManager.lookupReleasePackageEvrFor(s); @@ -1726,7 +1727,7 @@ public static Set listBaseChannelsForSystem(User usr, Serve channelDtos.add(new EssentialChannelDto(dcm.getChannel())); } - return channelDtos; + return channelDtos.stream().sorted(comparing(EssentialChannelDto::getName)).toList(); } /** @@ -1800,9 +1801,10 @@ public static Set listCompatibleBaseChannelsForChannel(Chan * * @param u User of interest * @param inChan Base-channel of interest - * @return Set of channels that a system subscribed to "c" could be re-subscribed to + * @return List of channels that a system subscribed to "c" could be re-subscribed to */ - public static Set listCompatibleBaseChannelsForChannel(User u, Channel inChan) { + public static List listCompatibleBaseChannelsForChannel(User u, Channel inChan) { + // Get all the custom-channels owned by this org and add them Set retval = ChannelFactory.listCustomBaseChannelsForSSM(u, inChan) .stream() @@ -1843,7 +1845,7 @@ public static Set listCompatibleBaseChannelsForChannel(User } } - return retval; + return retval.stream().sorted(comparing(EssentialChannelDto::getName)).toList(); } /** diff --git a/java/code/src/com/redhat/rhn/manager/channel/test/ChannelManagerTest.java b/java/code/src/com/redhat/rhn/manager/channel/test/ChannelManagerTest.java index 1fd2ab8db80d..1dd10c805623 100644 --- a/java/code/src/com/redhat/rhn/manager/channel/test/ChannelManagerTest.java +++ b/java/code/src/com/redhat/rhn/manager/channel/test/ChannelManagerTest.java @@ -436,11 +436,31 @@ public void testBaseChannelsForSystem() throws Exception { ChannelTestUtils.createTestChannel(user); ChannelTestUtils.createTestChannel(user); - Set channels = ChannelManager.listBaseChannelsForSystem(user, s); + List channels = ChannelManager.listBaseChannelsForSystem(user, s); assertTrue(channels.size() >= 2); } + @Test + public void testBaseChannelsForSystemSorted() throws Exception { + Server s = ServerTestUtils.createTestSystem(user); + + Channel c = ChannelTestUtils.createTestChannel(user); + c.setName("A Channel"); + TestUtils.saveAndReload(c); + c = ChannelTestUtils.createTestChannel(user); + c.setName("C Channel"); + TestUtils.saveAndReload(c); + c = ChannelTestUtils.createTestChannel(user); + c.setName("B Channel"); + TestUtils.saveAndReload(c); + + List channelNames = ChannelManager.listBaseChannelsForSystem(user, s).stream() + .map(EssentialChannelDto::getName).toList(); + + assertTrue(channelNames.indexOf("A Channel") < channelNames.indexOf("B Channel")); + assertTrue(channelNames.indexOf("B Channel") < channelNames.indexOf("C Channel")); + } @Test public void testBaseChannelsForLiberty() throws Exception { @@ -464,7 +484,7 @@ public void testBaseChannelsForLiberty() throws Exception { // Test: list base channels for Liberty 7 SUSEProductTestUtils.installSUSEProductOnServer(resProduct, s); - Set channels = ChannelManager.listBaseChannelsForSystem(user, s); + List channels = ChannelManager.listBaseChannelsForSystem(user, s); assertEquals(2, channels.size()); List expectedNames = new ArrayList<>(List.of( @@ -525,7 +545,7 @@ public void testBaseChannelsForSystemIncludesEus() throws Exception { ChannelManager.RHEL_PRODUCT_NAME, version, release3); HibernateFactory.getSession().flush(); - Set channels = ChannelManager.listBaseChannelsForSystem(user, s); + List channels = ChannelManager.listBaseChannelsForSystem(user, s); assertTrue(channels.size() >= 2); } @@ -813,7 +833,7 @@ public void testListCompatibleBaseChannels() throws Exception { commitHappened(); // Ask for channels compatible with the new server's base - Set compatibles = ChannelManager.listCompatibleBaseChannelsForChannel(user, c); + List compatibles = ChannelManager.listCompatibleBaseChannelsForChannel(user, c); // There should be two - we now list ALL custom-channelsl assertNotNull(compatibles); diff --git a/java/code/src/com/redhat/rhn/manager/ssm/SsmManager.java b/java/code/src/com/redhat/rhn/manager/ssm/SsmManager.java index 84bdcea27676..8818c93bb63f 100644 --- a/java/code/src/com/redhat/rhn/manager/ssm/SsmManager.java +++ b/java/code/src/com/redhat/rhn/manager/ssm/SsmManager.java @@ -295,7 +295,7 @@ private static ChannelSelectionResult handleExplicitBaseChannelChange(Date earli boolean newBaseIsCompatible = true; if (baseChange) { if (currentBase.isPresent()) { - Set compatibleBaseChannels = ChannelManager + List compatibleBaseChannels = ChannelManager .listCompatibleBaseChannelsForChannel(user, currentBase.get()); newBaseIsCompatible = // new base is in the compatible channels list @@ -305,7 +305,7 @@ private static ChannelSelectionResult handleExplicitBaseChannelChange(Date earli } else { // system doesn't have a base - Set availableBaseChannels = ChannelManager.listBaseChannelsForSystem(user, srv); + List availableBaseChannels = ChannelManager.listBaseChannelsForSystem(user, srv); newBaseIsCompatible = availableBaseChannels.stream() .anyMatch(abc -> abc.getId().equals(srvChange.getNewBaseId().orElse(null))); } @@ -496,7 +496,7 @@ public static List computeAllowedChannelChanges(SsmB } else if (change.getNewBaseId() > 0) { // explicit base channel change - Set compatibleBases = ChannelManager + List compatibleBases = ChannelManager .listCompatibleBaseChannelsForChannel(user, currentBase); Channel newBase = compatibleBases.stream() .filter(cb -> cb.getId() == change.getNewBaseId()) diff --git a/java/code/src/com/suse/manager/webui/controllers/SsmController.java b/java/code/src/com/suse/manager/webui/controllers/SsmController.java index 29f1bc236aab..8d99250d2032 100644 --- a/java/code/src/com/suse/manager/webui/controllers/SsmController.java +++ b/java/code/src/com/suse/manager/webui/controllers/SsmController.java @@ -57,7 +57,6 @@ import java.util.Date; import java.util.List; import java.util.Optional; -import java.util.Set; import java.util.stream.Stream; import spark.Request; @@ -107,7 +106,7 @@ public static String getBaseChannels(Request request, Response response, User us SsmAllowedBaseChannelsJson allowedBaseJson = new SsmAllowedBaseChannelsJson(); allowedBaseJson.setBase(new SsmChannelDto(c.getId(), c.getName(), c.isCustom())); - Set compatibles = ChannelManager.listCompatibleBaseChannelsForChannel(user, c); + List compatibles = ChannelManager.listCompatibleBaseChannelsForChannel(user, c); allowedBaseJson.setAllowedBaseChannels( compatibles.stream().map(cc -> diff --git a/java/code/src/com/suse/manager/webui/controllers/SystemsController.java b/java/code/src/com/suse/manager/webui/controllers/SystemsController.java index d4fc98953e46..b99cc255cffb 100644 --- a/java/code/src/com/suse/manager/webui/controllers/SystemsController.java +++ b/java/code/src/com/suse/manager/webui/controllers/SystemsController.java @@ -499,7 +499,7 @@ public String getChannels(Request request, Response response, User user) { */ public String getAvailableBaseChannels(Request request, Response response, User user) { return withServer(request, response, user, server -> { - Set orgChannels = ChannelManager.listBaseChannelsForSystem(user, server); + List orgChannels = ChannelManager.listBaseChannelsForSystem(user, server); List baseChannels = orgChannels.stream().map(c -> new ChannelsJson.ChannelJson(c.getId(), c.getLabel(), diff --git a/java/spacewalk-java.changes.cbbayburt.bsc1233724 b/java/spacewalk-java.changes.cbbayburt.bsc1233724 new file mode 100644 index 000000000000..9059a925bfe2 --- /dev/null +++ b/java/spacewalk-java.changes.cbbayburt.bsc1233724 @@ -0,0 +1 @@ +- Ensure channel lists are reliably sorted by name (bsc#1233724)