use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity in project opennms by OpenNMS.
the class BusinessServiceDaoIT method verifyDistinctObjectLoading.
@Test
@Transactional
public void verifyDistinctObjectLoading() {
BusinessServiceEntity entity = new BusinessServiceEntityBuilder().name("Parent Web Servers").addReductionKey("TestReductionKeyA", new IdentityEntity()).addReductionKey("TestReductionKeyB", new IdentityEntity()).addReductionKey("TestReductionKeyC", new IdentityEntity()).reduceFunction(m_highestSeverity).toEntity();
m_businessServiceDao.save(entity);
m_businessServiceDao.flush();
assertEquals(1, m_businessServiceDao.countAll());
assertEquals(3, m_edgeDao.countAll());
Criteria criteria = new CriteriaBuilder(BusinessServiceEntity.class).toCriteria();
// verify that root entity is merged
assertEquals(1, m_businessServiceDao.findMatching(criteria).size());
// verify that countMatching also works
assertEquals(1, m_businessServiceDao.countMatching(criteria));
}
use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity in project opennms by OpenNMS.
the class BusinessServiceDaoIT method verifyBeanValidation.
@Test(expected = ConstraintViolationException.class)
@Transactional
public void verifyBeanValidation() {
BusinessServiceEntity entity = new BusinessServiceEntityBuilder().name("Some Custom Name").addReductionKey("My Reduction Key", new IdentityEntity(), "so friendly").addReductionKey("Another Reduction Key", new IdentityEntity(), Strings.padEnd("too", 30, 'o') + " friendly").reduceFunction(m_highestSeverity).toEntity();
// Should throw a ConstraintViolationException (friendly name too long)
m_businessServiceDao.save(entity);
m_businessServiceDao.flush();
}
use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity in project opennms by OpenNMS.
the class AbstractBusinessServiceRestServiceIT method verifyHighestSeverityAboveReduceFunction.
@Test
public void verifyHighestSeverityAboveReduceFunction() throws Exception {
BusinessServiceEntity entity = new BusinessServiceEntityBuilder().name("Dummy Service").reduceFunction(new HighestSeverityAboveEntity(Status.CRITICAL.ordinal())).toEntity();
sendData(POST, getMediaType(), "/business-services", marshal(toRequestDto(entity)), 201);
entity.setId(findEntityByName("Dummy Service").getId());
verifyResponse(entity);
}
use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity in project opennms by OpenNMS.
the class BusinessServiceManagerImpl method addReductionKeyEdge.
@Override
public boolean addReductionKeyEdge(BusinessService businessService, String reductionKey, MapFunction mapFunction, int weight, String friendlyName) {
final BusinessServiceEntity parentEntity = getBusinessServiceEntity(businessService);
// Create the edge
final ReductionKeyEdgeImpl edge = (ReductionKeyEdgeImpl) createEdge(ReductionKeyEdge.class, businessService, mapFunction, weight);
edge.setReductionKey(reductionKey);
edge.setFriendlyName(friendlyName);
// if already exists, no update
final SingleReductionKeyEdgeEntity edgeEntity = getBusinessServiceEdgeEntity(edge);
long count = parentEntity.getReductionKeyEdges().stream().filter(e -> e.equalsDefinition(edgeEntity)).count();
if (count > 0) {
return false;
}
parentEntity.addEdge(edge.getEntity());
return true;
}
use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity in project opennms by OpenNMS.
the class BusinessServiceManagerImpl method setIpServiceEdges.
@Override
public void setIpServiceEdges(BusinessService businessService, Set<IpServiceEdge> ipServiceEdges) {
final BusinessServiceEntity entity = getBusinessServiceEntity(businessService);
for (final IPServiceEdgeEntity e : entity.getIpServiceEdges()) {
entity.removeEdge(e);
}
ipServiceEdges.forEach(e -> entity.addEdge(((IpServiceEdgeImpl) e).getEntity()));
}
Aggregations