use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.
the class AccessPointMonitordTest method addNewAccessPoint.
@Transactional(propagation = Propagation.MANDATORY)
public void addNewAccessPoint(String name, String mac, String pkg) {
NetworkBuilder nb = new NetworkBuilder();
nb.addNode(name).setForeignSource("apmd").setForeignId(name);
nb.addInterface("169.254.0.1");
m_nodeDao.save(nb.getCurrentNode());
final OnmsAccessPoint ap1 = new OnmsAccessPoint(mac, nb.getCurrentNode().getId(), pkg);
ap1.setStatus(AccessPointStatus.UNKNOWN);
m_accessPointDao.save(ap1);
m_nodeDao.flush();
m_accessPointDao.flush();
}
use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.
the class KscRestService method addGraph.
@PUT
@Path("{kscReportId}")
@Transactional
public Response addGraph(@PathParam("kscReportId") final Integer kscReportId, @QueryParam("title") final String title, @QueryParam("reportName") final String reportName, @QueryParam("resourceId") final String resourceId, @QueryParam("timespan") String timespan) {
writeLock();
try {
if (kscReportId == null || reportName == null || reportName == "" || resourceId == null || resourceId == "") {
throw getException(Status.BAD_REQUEST, "Invalid request: reportName and resourceId cannot be empty!");
}
final Report report = m_kscReportFactory.getReportByIndex(kscReportId);
if (report == null) {
throw getException(Status.NOT_FOUND, "Invalid request: No KSC report found with ID: {}.", Integer.toString(kscReportId));
}
final Graph graph = new Graph();
if (title != null) {
graph.setTitle(title);
}
boolean found = false;
for (final String valid : KSC_PerformanceReportFactory.TIMESPAN_OPTIONS) {
if (valid.equals(timespan)) {
found = true;
break;
}
}
if (!found) {
LOG.debug("invalid timespan ('{}'), setting to '7_day' instead.", timespan);
timespan = "7_day";
}
graph.setGraphtype(reportName);
graph.setResourceId(resourceId);
graph.setTimespan(timespan);
report.addGraph(graph);
m_kscReportFactory.setReport(kscReportId, report);
try {
m_kscReportFactory.saveCurrent();
} catch (final Exception e) {
throw getException(Status.INTERNAL_SERVER_ERROR, "Cannot save report with Id {} : {} ", kscReportId.toString(), e.getMessage());
}
return Response.noContent().build();
} finally {
writeUnlock();
}
}
use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.
the class MinionRestService method getMinions.
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
@Transactional
public OnmsMinionCollection getMinions(@Context final UriInfo uriInfo) throws ParseException {
final CriteriaBuilder builder = getCriteriaBuilder(uriInfo.getQueryParameters());
final OnmsMinionCollection coll = new OnmsMinionCollection(m_minionDao.findMatching(builder.toCriteria()));
coll.setTotalCount(m_minionDao.countMatching(builder.clearOrder().toCriteria()));
return coll;
}
use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.
the class GraphRestService method getGraphResourcesForNode.
@GET
@Path("fornode/{nodeCriteria}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
@Transactional(readOnly = true)
public GraphResourceDTO getGraphResourcesForNode(@PathParam("nodeCriteria") final String nodeCriteria, @DefaultValue("-1") @QueryParam("depth") final int depth) {
OnmsNode node = m_nodeDao.get(nodeCriteria);
if (node == null) {
throw getException(Status.NOT_FOUND, "No node found with criteria '{}'.", nodeCriteria);
}
OnmsResource resource = m_resourceDao.getResourceForNode(node);
if (resource == null) {
throw getException(Status.NOT_FOUND, "No resource found for node with id {}.", "" + node.getId());
}
final ResourceVisitor visitor = new ResourceVisitor(this);
final ResourceDTO resourceDTO = ResourceDTO.fromResource(resource, depth);
visitor.visit(resourceDTO);
return new GraphResourceDTO(resourceDTO, visitor.getGraphs());
}
use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.
the class GraphRestService method getGraphNames.
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
@Transactional(readOnly = true)
public GraphNameCollection getGraphNames() {
List<String> graphNames = Lists.newLinkedList();
for (PrefabGraph prefabGraph : m_graphDao.getAllPrefabGraphs()) {
graphNames.add(prefabGraph.getName());
}
Collections.sort(graphNames);
return new GraphNameCollection(graphNames);
}
Aggregations