Skip to content

NMS-19486: Support deletion of mibgroups,resourcetypes and systemdefs#8280

Merged
aurang-zeb313 merged 11 commits intofeatures/snmp-datacollection-dbfrom
akhan/jira/NMS-19486
Feb 26, 2026
Merged

NMS-19486: Support deletion of mibgroups,resourcetypes and systemdefs#8280
aurang-zeb313 merged 11 commits intofeatures/snmp-datacollection-dbfrom
akhan/jira/NMS-19486

Conversation

@aurang-zeb313
Copy link
Copy Markdown
Member

External References

…rces | Expose services to delete list of mibgroups,resourcetypes and systemdefs
@aurang-zeb313 aurang-zeb313 changed the base branch from develop to features/snmp-datacollection-db February 6, 2026 14:36
@aurang-zeb313 aurang-zeb313 marked this pull request as draft February 6, 2026 14:37
@aurang-zeb313 aurang-zeb313 requested a review from Copilot February 6, 2026 14:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds REST v2 delete endpoints and DAO support for bulk deletion of SNMP data collection sources and related entities (MIB groups, resource types, system defs).

Changes:

  • Introduces new REST payload models for bulk delete requests.
  • Adds REST API interface methods + REST service implementations for delete operations.
  • Extends DAOs with bulk-delete methods (HQL delete ... where id in (...)) for sources and child entities.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
opennms-webapp-rest/src/main/java/org/opennms/web/rest/v2/model/SnmpDataCollectionSystemDefDeletePayload.java Adds request payload for deleting system defs by ID list
opennms-webapp-rest/src/main/java/org/opennms/web/rest/v2/model/SnmpDataCollectionSourceDeletePayload.java Adds request payload for deleting collection sources by ID list
opennms-webapp-rest/src/main/java/org/opennms/web/rest/v2/model/SnmpDataCollectionResourceTypeDeletePayload.java Adds request payload for deleting resource types by ID list
opennms-webapp-rest/src/main/java/org/opennms/web/rest/v2/model/SnmpDataCollectionMibGroupDeletePayload.java Adds request payload for deleting MIB groups by ID list
opennms-webapp-rest/src/main/java/org/opennms/web/rest/v2/api/DataCollectionConfRestApi.java Exposes new DELETE endpoints for the above bulk deletions
opennms-webapp-rest/src/main/java/org/opennms/web/rest/v2/DataCollectionConfRestService.java Implements REST endpoints and delegates deletions to DAO/service layer
opennms-webapp-rest/src/main/java/org/opennms/web/rest/v2/DataCollectionConfPersistenceService.java Adds transactional delete operations with validation against DB state
opennms-dao/src/main/java/org/opennms/netmgt/dao/hibernate/SnmpCollectionSystemDefDaoHibernate.java Adds bulk delete by source + systemDef IDs
opennms-dao/src/main/java/org/opennms/netmgt/dao/hibernate/SnmpCollectionSourceDaoHibernate.java Adds bulk delete by source IDs
opennms-dao/src/main/java/org/opennms/netmgt/dao/hibernate/SnmpCollectionResourceTypeDaoHibernate.java Adds bulk delete by source + resourceType IDs
opennms-dao/src/main/java/org/opennms/netmgt/dao/hibernate/SnmpCollectionMibGroupDaoHibernate.java Adds bulk delete by source + mibGroup IDs
opennms-dao-api/src/main/java/org/opennms/netmgt/dao/api/SnmpCollectionSystemDefDao.java Adds DAO API for bulk systemDef deletion
opennms-dao-api/src/main/java/org/opennms/netmgt/dao/api/SnmpCollectionSourceDao.java Adds DAO API for bulk source deletion
opennms-dao-api/src/main/java/org/opennms/netmgt/dao/api/SnmpCollectionResourceTypeDao.java Adds DAO API for bulk resourceType deletion
opennms-dao-api/src/main/java/org/opennms/netmgt/dao/api/SnmpCollectionMibGroupDao.java Adds DAO API for bulk mibGroup deletion

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@aurang-zeb313 aurang-zeb313 marked this pull request as ready for review February 9, 2026 16:53
@cgorantla cgorantla changed the title NMS-19486: Expose rest end points to delete list of snmpCollectionSources | Expose services to delete list of mibgroups,resourcetypes and systemdefs NMS-19486: Support deletion of mibgroups,resourcetypes and systemdefs Feb 10, 2026
Comment on lines +230 to +240
final var mibGroupsIds = snmpCollectionMibGroupDao.findAllBySource(snmpDataCollectionSourceId);

final Set<Integer> databaseMibGroupIds = mibGroupsIds
.stream()
.map(SnmpCollectionMibGroup::getId)
.collect(Collectors.toSet());

final var requestMibGroupIds = payload.getMibGroupsIds();
final var existingMibGroupIds = requestMibGroupIds.stream()
.filter(databaseMibGroupIds::contains)
.toList();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to load all mibgroups to delete ?

Copy link
Copy Markdown
Contributor

@cgorantla cgorantla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are failing

Comment on lines 188 to 196
public void deleteByMibGroupIds(Integer snmpDataCollectionSourceId, List<Integer> snmpCollectionMibGroupIds) {
int deletedCount = getHibernateTemplate().execute(session ->
session.createQuery("delete from SnmpCollectionMibGroup g where g.collectionSource.id = :snmpCollectionSourceId and g.id in (:Ids)")
.setParameter("snmpCollectionSourceId", snmpDataCollectionSourceId)
.setParameterList("Ids", snmpCollectionMibGroupIds)
.executeUpdate()
);
LOG.info("Deleted {} SnmpCollectionMibGroup(g) with IDs: {} for snmpCollectionSourceId: {}", deletedCount, snmpCollectionMibGroupIds, snmpDataCollectionSourceId);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is already code to delete and deleteAll in AbstractDaoHibernate, no need to re-implement these custom HQL

}

try {
snmpCollectionSourceDao.deleteByIds(snmpDataCollectionSourceDeletePayload.getSnmpCollectionSourceIds());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we calling dao here directly, can use service.

}

@Override
public void deleteByIds(List<Integer> snmpDataCollectionIds) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to have cascade relations defined for child entities. That way the deletion of children happen in Hibernate session.

@ApiResponse(responseCode = "500", description = "Internal server error")
})
Response deleteSnmpDataCollectionSources(
SnmpDataCollectionSourceDeletePayload snmpDataCollectionSourceDeletePayload,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer to use simple query params with a list of ids here instead of using Payload

Comment on lines +144 to +148
int deletedCount = getHibernateTemplate().execute(session ->
session.createQuery("delete from SnmpCollectionSource s where s.id in (:ids)")
.setParameterList("ids", snmpDataCollectionIds)
.executeUpdate()
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need to write an actual SQL query or HQL. You can use entities,

something like this :
for (Integer id : ids) {
SnmpCollectionSource entity = get(id);
if (entity != null) {
delete(entity);
}
}


PageResponse<SnmpCollectionResourceType> findByDataCollectionGroupId(Integer snmpCollectionSourceId, String resourceTypeFilter, String sortBy, String order, Integer totalRecords, Integer offset, Integer limit);

void deleteByResourceTypeIds(Integer snmpDataCollectionSourceId,List<Integer> snmpCollectionResourceTypeIds);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some of these apis are unused now

# Conflicts:
#	opennms-dao-api/src/main/java/org/opennms/netmgt/dao/api/SnmpCollectionMibGroupDao.java
PageResponse<SnmpCollectionSource> filterDataCollectionSource(final String filter, final String sortBy, final String order, Integer totalRecords,
Integer offset, Integer limit);

void deleteByIds(List<Integer> snmpDataCollectionIds);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only used in tests ?


final T entity = finder.apply(sourceId, id);
if (entity == null) {
throw new EntityNotFoundException(entityLabel + " not found for sourceId=" + sourceId + ", id=" + id);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be continue would be better here ?

Comment on lines +543 to +552
return handleDelete(
() -> { dataCollectionConfPersistenceService.deleteSnmpDataCollectionSystemDefs(snmpDataCollectionSourceId, ids); return null; },
"Snmp Data Collection System Def deleted successfully"
);
}

private Response handleDelete(final Supplier<Void> action, final String successMessage) {
try {
action.get();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you revisit this code and avoid using Supplier kind of overhead ?

Copy link
Copy Markdown
Contributor

@cgorantla cgorantla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@aurang-zeb313 aurang-zeb313 merged commit afd4990 into features/snmp-datacollection-db Feb 26, 2026
3 of 5 checks passed
@aurang-zeb313 aurang-zeb313 deleted the akhan/jira/NMS-19486 branch February 26, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants