use of org.opennms.netmgt.bsm.service.model.BusinessService 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;
}
use of org.opennms.netmgt.bsm.service.model.BusinessService in project opennms by OpenNMS.
the class BusinessServiceManagerImpl method deleteBusinessService.
@Override
public void deleteBusinessService(BusinessService businessService) {
BusinessServiceEntity entity = getBusinessServiceEntity(businessService);
// remove all parent -> child associations
for (BusinessServiceEntity parent : getDao().findParents(entity)) {
List<BusinessServiceChildEdgeEntity> collect = parent.getChildEdges().stream().filter(e -> entity.equals(e.getChild())).collect(Collectors.toList());
collect.forEach(x -> {
parent.removeEdge(x);
edgeDao.delete(x);
});
}
// edges of the entity are deleted automatically by hibernate
getDao().delete(entity);
}
use of org.opennms.netmgt.bsm.service.model.BusinessService in project opennms by OpenNMS.
the class BusinessServiceManagerImpl method addChildEdge.
@Override
public boolean addChildEdge(BusinessService parentService, BusinessService childService, MapFunction mapFunction, int weight) {
// verify that exists
final BusinessServiceEntity parentEntity = getBusinessServiceEntity(parentService);
final BusinessServiceEntity childEntity = getBusinessServiceEntity(childService);
// Create the edge
ChildEdge childEdge = createEdge(ChildEdge.class, parentService, mapFunction, weight);
childEdge.setChild(childService);
// Verify no loop
if (this.checkDescendantForLoop(parentEntity, childEntity)) {
throw new IllegalArgumentException("Service will form a loop");
}
// if already exists, no update
final BusinessServiceChildEdgeEntity edgeEntity = getBusinessServiceEdgeEntity(childEdge);
long count = parentEntity.getChildEdges().stream().filter(e -> e.equalsDefinition(edgeEntity)).count();
if (count > 0) {
return false;
}
parentEntity.addEdge(((ChildEdgeImpl) childEdge).getEntity());
return true;
}
use of org.opennms.netmgt.bsm.service.model.BusinessService in project opennms by OpenNMS.
the class BusinessServiceRestService method addIpServiceEdge.
@POST
@Path("{id}/ip-service-edge")
public // Add IpService
Response addIpServiceEdge(@PathParam("id") final Long serviceId, final IpServiceEdgeRequestDTO edgeRequest) {
final BusinessService businessService = getManager().getBusinessServiceById(serviceId);
final IpService ipService = getManager().getIpServiceById(edgeRequest.getIpServiceId());
boolean changed = getManager().addIpServiceEdge(businessService, ipService, transform(edgeRequest.getMapFunction()), edgeRequest.getWeight(), edgeRequest.getFriendlyName());
if (!changed) {
return Response.notModified().build();
}
businessService.save();
return Response.ok().build();
}
use of org.opennms.netmgt.bsm.service.model.BusinessService in project opennms by OpenNMS.
the class BusinessServiceRestService method addChildServiceEdge.
@POST
@Path("{id}/child-edge")
public // Add Child Service
Response addChildServiceEdge(@PathParam("id") final Long serviceId, final ChildEdgeRequestDTO edgeRequest) {
final BusinessService parentService = getManager().getBusinessServiceById(serviceId);
final BusinessService childService = getManager().getBusinessServiceById(edgeRequest.getChildId());
boolean changed = getManager().addChildEdge(parentService, childService, transform(edgeRequest.getMapFunction()), edgeRequest.getWeight());
if (!changed) {
return Response.notModified().build();
}
parentService.save();
return Response.ok().build();
}
Aggregations