The attribute "totalCount" for OnmsNodeList is not well calculated

Description

That means that the "pagination" feature used with data from NodeRestService will be wrong.

The problem is related to the criteria used to query node's table.

OnmsCriteria rootCriteria = new OnmsCriteria(OnmsNode.class);
rootCriteria.add(Subqueries.propertyIn("id", criteria.getDetachedCriteria()));
coll.setTotalCount(m_nodeDao.countMatching(rootCriteria));

That doesn't match with the "main" criteria used to create the node list object.

Acceptance / Success Criteria

None

Lucidchart Diagrams

Activity

Show:

Benjamin Reed April 6, 2011 at 10:45 AM

...and I merged it to master.

Alejandro Galue April 6, 2011 at 10:27 AM

I just committed the fix to r1d4fb564d6d9 on branch 1.8

Benjamin Reed April 6, 2011 at 10:18 AM

Have you committed this? If not, could you attach a patch, rather than cut & pasted in the comments?

Alejandro Galue April 6, 2011 at 10:05 AM

Ups.. I pasted part of the solution on the "initial" comment. The proposed solution is apply this patch to NodeRestService:

@@ -51,6 +51,8 @@
import javax.ws.rs.core.Response.Status;

import org.hibernate.criterion.CriteriaSpecification;
+import org.hibernate.criterion.Projections;
+import org.hibernate.criterion.Subqueries;
import org.opennms.netmgt.EventConstants;
import org.opennms.netmgt.dao.NodeDao;
import org.opennms.netmgt.model.OnmsCriteria;
@@ -110,7 +112,16 @@
addFiltersToCriteria(m_uriInfo.getQueryParameters(), criteria, OnmsNode.class);
criteria.createAlias("snmpInterfaces", "snmpInterface", CriteriaSpecification.LEFT_JOIN);
criteria.createAlias("ipInterfaces", "ipInterface", CriteriaSpecification.LEFT_JOIN);

  • coll.setTotalCount(m_nodeDao.countMatching(criteria));
    + criteria.setProjection(
    + Projections.distinct(
    + Projections.projectionList().add(
    + Projections.alias( Projections.property("id"), "id" )
    + )
    + )
    + );
    + OnmsCriteria rootCriteria = new OnmsCriteria(OnmsNode.class);
    + rootCriteria.add(Subqueries.propertyIn("id", criteria.getDetachedCriteria()));
    + coll.setTotalCount(m_nodeDao.countMatching(rootCriteria));


return coll;
}

Based on the current content of the method getDistinctIdCriteria from OnmsRestService.

I tested it and it works as expected.

Fixed

Details

Assignee

Reporter

Components

Fix versions

Affects versions

Priority

PagerDuty

Created April 6, 2011 at 10:01 AM
Updated January 27, 2017 at 4:20 PM
Resolved April 6, 2011 at 10:27 AM