From 5337e9a434b3e77060a393135e95fabe2d1f7382 Mon Sep 17 00:00:00 2001 From: mbussolotto Date: Thu, 9 Jan 2025 11:04:14 +0100 Subject: [PATCH] fixup! refactor StateFactory --- .../redhat/rhn/domain/state/StateFactory.java | 37 +++++++------------ .../rhn/domain/state/StateRevision.java | 18 --------- 2 files changed, 14 insertions(+), 41 deletions(-) diff --git a/java/code/src/com/redhat/rhn/domain/state/StateFactory.java b/java/code/src/com/redhat/rhn/domain/state/StateFactory.java index 095e36a445ff..9430fcd339d6 100644 --- a/java/code/src/com/redhat/rhn/domain/state/StateFactory.java +++ b/java/code/src/com/redhat/rhn/domain/state/StateFactory.java @@ -99,10 +99,9 @@ public static Optional> latestPackageStates(MinionServer serve Query query = getSession().createNativeQuery(sql, ServerStateRevision.class); query.setParameter("server", server.getId(), LongType.INSTANCE); List servers = query.getResultList(); - Set packageStates = servers.stream().flatMap( + return Optional.ofNullable(servers.stream().flatMap( stateRevision -> stateRevision.getPackageStates().stream()) - .collect(Collectors.toSet()); - return Optional.of(packageStates); + .collect(Collectors.toSet())); } /** @@ -115,8 +114,7 @@ public static Optional> latestPackageStates(ServerGroup group) String sql = "SELECT * FROM suseServerGroupStateRevision WHERE group_id = :group"; Query query = getSession().createNativeQuery(sql, ServerGroupStateRevision.class); query.setParameter("group", group.getId(), LongType.INSTANCE); - ServerGroupStateRevision serverGroupState = query.getSingleResult(); - return Optional.of(serverGroupState.getPackageStates()); + return Optional.ofNullable(query.getSingleResult().getPackageStates()); } /** @@ -129,8 +127,7 @@ public static Optional> latestPackageStates(Org org) { String sql = "SELECT * FROM suseOrgStateRevision WHERE org_id = :org"; Query query = getSession().createNativeQuery(sql, OrgStateRevision.class); query.setParameter("org", org.getId(), LongType.INSTANCE); - OrgStateRevision orgStateRevision = query.getSingleResult(); - return Optional.of(orgStateRevision.getPackageStates()); + return Optional.ofNullable( query.getSingleResult().getPackageStates()); } /** @@ -142,8 +139,7 @@ public static Optional latestStateRevision(Org org) { String sql = "SELECT * FROM suseOrgStateRevision WHERE org_id = :org"; Query query = getSession().createNativeQuery(sql, OrgStateRevision.class); query.setParameter("org", org.getId(), LongType.INSTANCE); - OrgStateRevision orgStateRevision = query.getSingleResult(); - return Optional.of(orgStateRevision); + return Optional.ofNullable(query.getSingleResult()); } /** @@ -156,8 +152,7 @@ public static Optional latestStateRevision( String sql = "SELECT * FROM suseServerGroupStateRevision WHERE group_id = :group"; Query query = getSession().createNativeQuery(sql, ServerGroupStateRevision.class); query.setParameter("group", group.getId(), LongType.INSTANCE); - ServerGroupStateRevision serverGroupStates = query.getSingleResult(); - return Optional.of(serverGroupStates); + return Optional.ofNullable(query.getSingleResult()); } /** @@ -169,8 +164,7 @@ public static Optional latestStateRevision(MinionServer ser String sql = "SELECT * FROM suseServerStateRevision WHERE server_id = :server"; Query query = getSession().createNativeQuery(sql, ServerStateRevision.class); query.setParameter("server", server.getId(), LongType.INSTANCE); - ServerStateRevision serverStates = query.getSingleResult(); - return Optional.of(serverStates); + return Optional.ofNullable(query.getSingleResult()); } /** @@ -184,10 +178,9 @@ public static Optional> latestConfigChannels(MinionServer se Query query = getSession().createNativeQuery(sql, ServerStateRevision.class); query.setParameter("server", server.getId(), LongType.INSTANCE); List orgs = query.getResultList(); - List configChannels = orgs.stream().flatMap( + return Optional.ofNullable(orgs.stream().flatMap( stateRevision -> stateRevision.getConfigChannels().stream()) - .collect(Collectors.toList()); - return Optional.of(configChannels); + .collect(Collectors.toList())); } /** @@ -201,10 +194,9 @@ public static Optional> latestConfigChannels(ServerGroup gro Query query = getSession().createNativeQuery(sql, ServerGroupStateRevision.class); query.setParameter("group", group.getId(), LongType.INSTANCE); List orgs = query.getResultList(); - List configChannels = orgs.stream().flatMap( + return Optional.ofNullable(orgs.stream().flatMap( stateRevision -> stateRevision.getConfigChannels().stream()) - .collect(Collectors.toList()); - return Optional.of(configChannels); + .collect(Collectors.toList())); } /** @@ -218,10 +210,9 @@ public static Optional> latestConfigChannels(Org org) { Query query = getSession().createNativeQuery(sql, OrgStateRevision.class); query.setParameter("org", org.getId(), LongType.INSTANCE); List orgs = query.getResultList(); - List configChannels = orgs.stream().flatMap( - stateRevision -> stateRevision.getConfigChannels().stream()) - .collect(Collectors.toList()); - return Optional.of(configChannels); + return Optional.ofNullable(orgs.stream().flatMap( + stateRevision -> stateRevision.getConfigChannels().stream()) + .collect(Collectors.toList())); } /** diff --git a/java/code/src/com/redhat/rhn/domain/state/StateRevision.java b/java/code/src/com/redhat/rhn/domain/state/StateRevision.java index e084d7ef1ce3..3c4eb5a744b5 100644 --- a/java/code/src/com/redhat/rhn/domain/state/StateRevision.java +++ b/java/code/src/com/redhat/rhn/domain/state/StateRevision.java @@ -33,7 +33,6 @@ public class StateRevision { private long id; - private Date created; private User creator; private Set packageStates = new HashSet<>(); private List configChannels = new ArrayList<>(); @@ -52,20 +51,6 @@ public void setId(long idIn) { this.id = idIn; } - /** - * @return the created - */ - public Date getCreated() { - return created; - } - - /** - * @param createdIn the created to set - */ - public void setCreated(Date createdIn) { - this.created = createdIn; - } - /** * @return the creator */ @@ -124,7 +109,6 @@ public boolean equals(Object other) { return false; } return new EqualsBuilder() - .append(getCreated(), otherRevision.getCreated()) .append(getCreator(), otherRevision.getCreator()) .isEquals(); } @@ -135,7 +119,6 @@ public boolean equals(Object other) { @Override public int hashCode() { return new HashCodeBuilder() - .append(getCreated()) .append(getCreator()) .toHashCode(); } @@ -146,7 +129,6 @@ public int hashCode() { @Override public String toString() { return new ToStringBuilder(this) - .append("created", getCreated()) .append("creator", getCreator()) .toString(); }