use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.
the class EnhancedLinkdServiceImpl method store.
@Override
@Transactional
public void store(int nodeId, LldpElement element) {
if (element == null)
return;
final OnmsNode node = m_nodeDao.get(nodeId);
if (node == null)
return;
LldpElement dbelement = node.getLldpElement();
if (dbelement != null) {
dbelement.merge(element);
node.setLldpElement(dbelement);
} else {
element.setNode(node);
element.setLldpNodeLastPollTime(element.getLldpNodeCreateTime());
node.setLldpElement(element);
}
m_nodeDao.saveOrUpdate(node);
m_nodeDao.flush();
}
use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.
the class AccessPointDaoTest method testFindByPhysAddr.
@Test
@Transactional
public void testFindByPhysAddr() {
addNewAccessPoint("ap1", AP1_MAC, "default-package");
addNewAccessPoint("ap2", AP2_MAC, "not-default-package");
OnmsAccessPoint ap1 = m_accessPointDao.get(AP1_MAC);
assertEquals("default-package", ap1.getPollingPackage());
OnmsAccessPoint ap2 = m_accessPointDao.get(AP2_MAC);
assertEquals("not-default-package", ap2.getPollingPackage());
}
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;
}
Aggregations