use of org.opennms.web.rest.v2.bsm.model.edge.ChildEdgeRequestDTO in project opennms by OpenNMS.
the class BusinessServiceRestService method update.
@PUT
@Path("{id}")
public Response update(@PathParam("id") final Long id, final BusinessServiceRequestDTO request) {
final BusinessService service = getManager().getBusinessServiceById(id);
service.setName(request.getName());
service.setAttributes(request.getAttributes());
service.setReduceFunction(transform(request.getReduceFunction()));
service.setReductionKeyEdges(Sets.newHashSet());
service.setIpServiceEdges(Sets.newHashSet());
service.setChildEdges(Sets.newHashSet());
request.getEdges().forEach(eachEdge -> eachEdge.accept(new EdgeRequestDTOVisitor() {
@Override
public void visit(IpServiceEdgeRequestDTO ipEdge) {
getManager().addIpServiceEdge(service, getManager().getIpServiceById(ipEdge.getIpServiceId()), transform(ipEdge.getMapFunction()), ipEdge.getWeight(), ipEdge.getFriendlyName());
}
@Override
public void visit(ChildEdgeRequestDTO childEdge) {
getManager().addChildEdge(service, getManager().getBusinessServiceById(childEdge.getChildId()), transform(childEdge.getMapFunction()), childEdge.getWeight());
}
@Override
public void visit(ReductionKeyEdgeRequestDTO rkEdge) {
getManager().addReductionKeyEdge(service, rkEdge.getReductionKey(), transform(rkEdge.getMapFunction()), rkEdge.getWeight(), rkEdge.getFriendlyName());
}
}));
getManager().saveBusinessService(service);
return Response.noContent().build();
}
use of org.opennms.web.rest.v2.bsm.model.edge.ChildEdgeRequestDTO in project opennms by OpenNMS.
the class BusinessServiceRestService method create.
@POST
public Response create(@Context final UriInfo uriInfo, final BusinessServiceRequestDTO request) {
final BusinessService service = getManager().createBusinessService();
service.setName(request.getName());
service.setAttributes(request.getAttributes());
service.setReduceFunction(transform(request.getReduceFunction()));
request.getEdges().forEach(eachEdge -> eachEdge.accept(new EdgeRequestDTOVisitor() {
@Override
public void visit(IpServiceEdgeRequestDTO ipEdge) {
service.addIpServiceEdge(getManager().getIpServiceById(ipEdge.getIpServiceId()), transform(ipEdge.getMapFunction()), ipEdge.getWeight(), ipEdge.getFriendlyName());
}
@Override
public void visit(ChildEdgeRequestDTO childEdge) {
service.addChildEdge(getManager().getBusinessServiceById(childEdge.getChildId()), transform(childEdge.getMapFunction()), childEdge.getWeight());
}
@Override
public void visit(ReductionKeyEdgeRequestDTO rkEdge) {
service.addReductionKeyEdge(rkEdge.getReductionKey(), transform(rkEdge.getMapFunction()), rkEdge.getWeight(), rkEdge.getFriendlyName());
}
}));
getManager().saveBusinessService(service);
return Response.created(RedirectHelper.getRedirectUri(uriInfo, service.getId())).build();
}
use of org.opennms.web.rest.v2.bsm.model.edge.ChildEdgeRequestDTO in project opennms by OpenNMS.
the class BusinessServiceRequestDTO method addChildService.
public void addChildService(long childId, MapFunctionDTO mapFunction, int weight) {
ChildEdgeRequestDTO edge = new ChildEdgeRequestDTO();
edge.setChildId(childId);
edge.setMapFunction(mapFunction);
edge.setWeight(weight);
getChildServices().add(edge);
}
use of org.opennms.web.rest.v2.bsm.model.edge.ChildEdgeRequestDTO in project opennms by OpenNMS.
the class AbstractBusinessServiceRestServiceIT method canAddChildServiceEdge.
@Test
public void canAddChildServiceEdge() throws Exception {
// Create a child and parent Business Service without any edges
BusinessServiceEntity childEntity = new BusinessServiceEntityBuilder().name("Child Service").reduceFunction(new HighestSeverityEntity()).toEntity();
BusinessServiceEntity parentEntity = new BusinessServiceEntityBuilder().name("Parent Service").reduceFunction(new HighestSeverityEntity()).toEntity();
final Long parentServiceId = m_businessServiceDao.save(parentEntity);
final Long childServiceId = m_businessServiceDao.save(childEntity);
m_businessServiceDao.flush();
// The Request to send to create the edge
ChildEdgeRequestDTO edgeRequestDTO = new ChildEdgeRequestDTO();
edgeRequestDTO.setMapFunction(new FunctionsManager().getMapFunctionDTO(new Identity()));
// verify adding of not existing ip parentEntity is not possible
edgeRequestDTO.setChildId(-1L);
sendData(POST, getMediaType(), buildChildServiceEdgeUrl(parentServiceId), marshal(edgeRequestDTO), 404);
// verify adding of existing ip parentEntity is possible
edgeRequestDTO.setChildId(childServiceId);
sendData(POST, getMediaType(), buildChildServiceEdgeUrl(parentServiceId), marshal(edgeRequestDTO), 200);
Assert.assertEquals(1, m_businessServiceDao.get(parentServiceId).getChildEdges().size());
// verify adding twice possible, but not modified
sendData(POST, getMediaType(), buildChildServiceEdgeUrl(parentServiceId), marshal(edgeRequestDTO), 304);
Assert.assertEquals(1, m_businessServiceDao.get(parentServiceId).getChildEdges().size());
}
Aggregations