Skip to content

Commit

Permalink
fixup! refactor StateFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
mbussolotto committed Jan 9, 2025
1 parent c70f533 commit 5337e9a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 41 deletions.
37 changes: 14 additions & 23 deletions java/code/src/com/redhat/rhn/domain/state/StateFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,9 @@ public static Optional<Set<PackageState>> latestPackageStates(MinionServer serve
Query<ServerStateRevision> query = getSession().createNativeQuery(sql, ServerStateRevision.class);
query.setParameter("server", server.getId(), LongType.INSTANCE);
List<ServerStateRevision> servers = query.getResultList();
Set<PackageState> packageStates = servers.stream().flatMap(
return Optional.ofNullable(servers.stream().flatMap(
stateRevision -> stateRevision.getPackageStates().stream())
.collect(Collectors.toSet());
return Optional.of(packageStates);
.collect(Collectors.toSet()));
}

/**
Expand All @@ -115,8 +114,7 @@ public static Optional<Set<PackageState>> latestPackageStates(ServerGroup group)
String sql = "SELECT * FROM suseServerGroupStateRevision WHERE group_id = :group";
Query<ServerGroupStateRevision> 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());
}

/**
Expand All @@ -129,8 +127,7 @@ public static Optional<Set<PackageState>> latestPackageStates(Org org) {
String sql = "SELECT * FROM suseOrgStateRevision WHERE org_id = :org";
Query<OrgStateRevision> 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());
}

/**
Expand All @@ -142,8 +139,7 @@ public static Optional<OrgStateRevision> latestStateRevision(Org org) {
String sql = "SELECT * FROM suseOrgStateRevision WHERE org_id = :org";
Query<OrgStateRevision> 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());
}

/**
Expand All @@ -156,8 +152,7 @@ public static Optional<ServerGroupStateRevision> latestStateRevision(
String sql = "SELECT * FROM suseServerGroupStateRevision WHERE group_id = :group";
Query<ServerGroupStateRevision> 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());
}

/**
Expand All @@ -169,8 +164,7 @@ public static Optional<ServerStateRevision> latestStateRevision(MinionServer ser
String sql = "SELECT * FROM suseServerStateRevision WHERE server_id = :server";
Query<ServerStateRevision> 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());
}

/**
Expand All @@ -184,10 +178,9 @@ public static Optional<List<ConfigChannel>> latestConfigChannels(MinionServer se
Query<ServerStateRevision> query = getSession().createNativeQuery(sql, ServerStateRevision.class);
query.setParameter("server", server.getId(), LongType.INSTANCE);
List<ServerStateRevision> orgs = query.getResultList();
List<ConfigChannel> configChannels = orgs.stream().flatMap(
return Optional.ofNullable(orgs.stream().flatMap(
stateRevision -> stateRevision.getConfigChannels().stream())
.collect(Collectors.toList());
return Optional.of(configChannels);
.collect(Collectors.toList()));
}

/**
Expand All @@ -201,10 +194,9 @@ public static Optional<List<ConfigChannel>> latestConfigChannels(ServerGroup gro
Query<ServerGroupStateRevision> query = getSession().createNativeQuery(sql, ServerGroupStateRevision.class);
query.setParameter("group", group.getId(), LongType.INSTANCE);
List<ServerGroupStateRevision> orgs = query.getResultList();
List<ConfigChannel> configChannels = orgs.stream().flatMap(
return Optional.ofNullable(orgs.stream().flatMap(
stateRevision -> stateRevision.getConfigChannels().stream())
.collect(Collectors.toList());
return Optional.of(configChannels);
.collect(Collectors.toList()));
}

/**
Expand All @@ -218,10 +210,9 @@ public static Optional<List<ConfigChannel>> latestConfigChannels(Org org) {
Query<OrgStateRevision> query = getSession().createNativeQuery(sql, OrgStateRevision.class);
query.setParameter("org", org.getId(), LongType.INSTANCE);
List<OrgStateRevision> orgs = query.getResultList();
List<ConfigChannel> 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()));
}

/**
Expand Down
18 changes: 0 additions & 18 deletions java/code/src/com/redhat/rhn/domain/state/StateRevision.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
public class StateRevision {

private long id;
private Date created;
private User creator;
private Set<PackageState> packageStates = new HashSet<>();
private List<ConfigChannel> configChannels = new ArrayList<>();
Expand All @@ -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
*/
Expand Down Expand Up @@ -124,7 +109,6 @@ public boolean equals(Object other) {
return false;
}
return new EqualsBuilder()
.append(getCreated(), otherRevision.getCreated())
.append(getCreator(), otherRevision.getCreator())
.isEquals();
}
Expand All @@ -135,7 +119,6 @@ public boolean equals(Object other) {
@Override
public int hashCode() {
return new HashCodeBuilder()
.append(getCreated())
.append(getCreator())
.toHashCode();
}
Expand All @@ -146,7 +129,6 @@ public int hashCode() {
@Override
public String toString() {
return new ToStringBuilder(this)
.append("created", getCreated())
.append("creator", getCreator())
.toString();
}
Expand Down

0 comments on commit 5337e9a

Please sign in to comment.