use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity in project opennms by OpenNMS.
the class BusinessServiceManagerImpl method setReduceFunction.
@Override
public void setReduceFunction(final BusinessService businessService, final ReductionFunction reductionFunction) {
// This is a workaround for a hibernate bug which does not remove
// orphan elements if the element is replaced using the setter. See:
// https://hibernate.atlassian.net/browse/HHH-6484
final BusinessServiceEntity entity = this.getBusinessServiceEntity(businessService);
final AbstractReductionFunctionEntity prevReduceFunctionEntity = entity.getReductionFunction();
if (prevReduceFunctionEntity != null && prevReduceFunctionEntity.getId() != null) {
this.reductionFunctionDao.delete(prevReduceFunctionEntity);
}
final AbstractReductionFunctionEntity reduceFunctionEntity = new ReduceFunctionMapper().toPersistenceFunction(reductionFunction);
entity.setReductionFunction(reduceFunctionEntity);
}
use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity in project opennms by OpenNMS.
the class BusinessServiceManagerImpl method setReductionKeyEdges.
@Override
public void setReductionKeyEdges(BusinessService businessService, Set<ReductionKeyEdge> reductionKeyEdges) {
final BusinessServiceEntity parentEntity = getBusinessServiceEntity(businessService);
for (final SingleReductionKeyEdgeEntity e : parentEntity.getReductionKeyEdges()) {
parentEntity.removeEdge(e);
}
reductionKeyEdges.forEach(e -> parentEntity.addEdge(((ReductionKeyEdgeImpl) e).getEntity()));
}
use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity in project opennms by OpenNMS.
the class BusinessServiceManagerImpl method getBusinessServiceEntity.
private BusinessServiceEntity getBusinessServiceEntity(Long serviceId) throws NoSuchElementException {
Objects.requireNonNull(serviceId);
final BusinessServiceEntity entity = getDao().get(serviceId);
if (entity == null) {
throw new NoSuchElementException("BusinessServiceEntity with id " + serviceId);
}
return entity;
}
use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity in project opennms by OpenNMS.
the class BusinessServiceManagerImpl method removeEdge.
@Override
public void removeEdge(final BusinessService businessService, final Edge edge) {
final BusinessServiceEntity businessServiceEntity = getBusinessServiceEntity(businessService);
final BusinessServiceEdgeEntity edgeEntity = getBusinessServiceEdgeEntity(edge);
businessServiceEntity.removeEdge(edgeEntity);
}
use of org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity in project opennms by OpenNMS.
the class BusinessServiceManagerImpl method addIpServiceEdge.
@Override
public boolean addIpServiceEdge(BusinessService businessService, IpService ipService, MapFunction mapFunction, int weight, String friendlyName) {
final BusinessServiceEntity parentEntity = getBusinessServiceEntity(businessService);
// Create the edge
final IpServiceEdge edge = createEdge(IpServiceEdge.class, businessService, mapFunction, weight);
edge.setIpService(ipService);
edge.setFriendlyName(friendlyName);
// if already exists, no update
final IPServiceEdgeEntity edgeEntity = getBusinessServiceEdgeEntity(edge);
long count = parentEntity.getIpServiceEdges().stream().filter(e -> e.equalsDefinition(edgeEntity)).count();
if (count > 0) {
return false;
}
parentEntity.addEdge(((IpServiceEdgeImpl) edge).getEntity());
return true;
}
Aggregations