Skip to content

Commit

Permalink
Add rule count in policies (API)
Browse files Browse the repository at this point in the history
  • Loading branch information
SCadilhac committed Dec 28, 2023
1 parent 9f62d91 commit 3f54579
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/main/java/onl/netfishers/netshot/compliance/Policy.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
Expand Down Expand Up @@ -111,6 +112,12 @@ public void addRule(Rule rule) {
rule.setPolicy(this);
}

@XmlElement
@Transient
public int getRuleCount() {
return this.rules.size();
}

/**
* Check all devices of the target groups against the policy.
*
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/onl/netfishers/netshot/rest/RestService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4158,8 +4158,9 @@ public List<Policy> getPolicies(@BeanParam PaginationParams paginationParams) th
log.debug("REST request, get policies.");
Session session = Database.getSession(true);
try {
// Join p.rules to get rule count... not optimal
Query<Policy> query = session
.createQuery("from Policy p left join fetch p.targetGroups", Policy.class);
.createQuery("select distinct p from Policy p left join fetch p.targetGroups left join fetch p.rules", Policy.class);
paginationParams.apply(query);
return query.list();
}
Expand Down

0 comments on commit 3f54579

Please sign in to comment.